def parse_postscript(fullString):
    '''
    Takes the usable part of the ps file (without newlines) and chops it up.

    intput: takes full string from get_postscript function
    output: generates 2 lists primary and secondary commands (filled and non filled objects)

    it seems we can split by f, and if any member of the newly created array contains Q's
    that means we are already deep intside primitive territory. this may be a poor assumption.
    '''

    fullString = fullString.replace('\n', ' ')
    collectedCommands = fullString.split("f")

    primaryCommands = []
    secondaryCommands = []
    for command in collectedCommands:
        if command.find('Q') is -1:
            primaryCommands.append(command + "f")
        else:
            tempString = command + "f"
            tempList = tempString.split("Q")
            for i in tempList:
                if len(i) > 2:
                    secondaryCommands.append(i)

    print("primaryCommands " + str(len(primaryCommands)))
    print("secondaryCommands " + str(len(secondaryCommands)))

    # cleanup before returning:
    primaryCommands = strip_strings_in_list(primaryCommands)
    secondaryCommands = strip_strings_in_list(secondaryCommands)
    return primaryCommands, secondaryCommands    
def create_file(commandList, plotList, fileName):
    """
    Takes a List of paths found in the .ps and makes js compatible syntax

    input:  Multidimensional list of strings similar to .ps commands
    output: Similar to input but formatted to be paperpJS readable.
    """

    writefile = open(fileName, "w")

    if fileName.endswith(".html"):
        write_html_header(writefile, fileName)

    # add the auto sorting functions for the compound path array, and empty path remover.
    write_sorting_functions(writefile)
    write_empty_path_removal_function(writefile)

    # add postscript functions written in javascript
    glyphCounter = 0
    for newPath in commandList:
        if len(newPath) > 4:
            functionName = "draw_glyph_" + str(glyphCounter)
            write_postscript_functions(newPath, functionName, writefile)
            glyphCounter += 1

    primitiveCounter = 0
    if len(plotList) is not 0:
        # user info
        print(str(len(plotList)) + " primitives to plot")

        for primitive in plotList:
            primitive = strip_strings_in_list(primitive)
            functionName = "draw_primitive_" + str(primitiveCounter)
            write_primitive_postScript(primitive, functionName, writefile)
            primitiveCounter += 1

    if fileName.endswith(".html"):
        write_html_footer(writefile, rectWidth, rectHeight)

    # done.
    writefile.close()