Exemple #1
0
def add(hpath, filedir):
    global counter
    global sources

    hpath = hpath[1:-1]  # Removing ""
    if hpath is None:
        print "Error"
        sys.exit(0)

    # if no dir in the path, the path of the main file
    # if added to, as it is presumed to be the location
    # when compiling the project

    hpath = wstring.localize(hpath)
    filedir = wstring.localize(filedir)

    p, n = os.path.split(hpath)
    if p == "":
        hpath = os.path.join(filedir, n)  # adding the default path

    hpath = decrease(hpath, filedir)

    Windows = (os.name == "nt") | (os.name == "dos")

    if Windows:
        hname = string.lower(hpath)
    if hpath in sources:
        return  # already here

    sources.append(hpath)
    counter = counter + 1
    return
Exemple #2
0
def addc(hpath, filedir):
    global counter
    global notexist
    global sources

    if hpath is None:
        return None
    if len(hpath) < 3:
        return None
    hpath = hpath[1:-1]  # removing markers, quotes or angles

    # if filedir not in the path, the path of the main file
    # if added to, as it is presumed to be the location
    # when compiling the project

    hpath = wstring.localize(hpath)  # converting antislash or slash
    filedir = wstring.localize(filedir)

    p, n = os.path.split(hpath)
    if p == "":
        hpath = os.path.join(filedir, n)  # adding the default path

    hpath = decrease(hpath, filedir)

    node, ext = os.path.splitext(hpath)
    if lexer.iswindows():
        ext = string.lower(ext)
    if ext == ".h":
        if lexer.iswindows():
            node = string.lower(node)
        hpath = node + ".c"
        # Converting local relative path into absolute path
        if string.find(hpath, mainpath) == -1:  # path not in include
            hpath = os.path.join(mainpath, hpath)  # add it
            # print hpath
        if hpath in sources:
            return None  # Already here
        if os.path.exists(hpath):
            sources.append(hpath)
            counter = counter + 1
            # print "added", hpath
            return hpath
        else:
            if hpath not in notexist:
                notexist.append(hpath)
    return None
Exemple #3
0
def update(line, abspath):
    i = string.find(line, "#include ")
    if i == -1:
        print "which?"
        sys.exit(0)

    i = i + 9
    lindex = i
    rindex = i
    sline = line[i:]
    first = FALSE
    second = FALSE

    # scanning the line for delimiters
    for c in sline:
        if c == "<":  # test for left delimiter
            lindex = i
            first = TRUE
            return line  # standard libraries include unchanged
        if c == '"':
            if first:  # test for right delimiter
                rindex = i
                second = TRUE
                break
            lindex = i + 1  # test for left delimiter
            first = TRUE
        i = i + 1

    if (rindex <= lindex) | (not first) | (not second):
        print "error, unrecognized statenent", line
        sys.exit(0)

    # extracting the header filename
    sline = line[lindex:rindex]
    sline = wstring.localize(sline)  # change separators for the os

    # occurence of header with the old path replaced by
    # the header with the new path found in the dictionary

    oldpath, name = os.path.split(sline)
    if oldpath == "":
        return line  # simple filename without path

    oldpath = decrease(oldpath, abspath)  # replace ../

    if dico.has_key(oldpath):
        newpath = os.path.join(dico[oldpath], name)
    else:
        print oldpath, "not in dictionary of paths"
        newpath = oldpath

    line = line[:lindex] + newpath + line[rindex:]
    return line