示例#1
0
文件: builtin.py 项目: gnprice/oil
def _ResolveNames(names, funcs, path_val):
    if path_val.tag == value_e.Str:
        path_list = path_val.s.split(':')
    else:
        path_list = []  # treat as empty path

    results = []
    for name in names:
        if name in funcs:
            kind = ('function', name)
        elif Resolve(name) != builtin_e.NONE:
            kind = ('builtin', name)
        elif ResolveSpecial(name) != builtin_e.NONE:
            kind = ('builtin', name)
        elif lex.IsOtherBuiltin(name):  # declare, continue, etc.
            kind = ('builtin', name)
        elif lex.IsKeyword(name):
            kind = ('keyword', name)
        else:
            # Now look for files.
            found = False
            for path_dir in path_list:
                full_path = os_path.join(path_dir, name)
                if os_path.exists(full_path):
                    kind = ('file', full_path)
                    found = True
                    break
            if not found:  # Nothing printed, but status is 1.
                kind = (None, None)
        results.append(kind)

    return results
示例#2
0
文件: builtin.py 项目: lheckemann/oil
def Type(argv, funcs, path_val):
    arg, i = TYPE_SPEC.Parse(argv)

    if path_val.tag == value_e.Str:
        path_list = path_val.s.split(':')
    else:
        path_list = []  # treat as empty path

    status = 0
    if not arg.t:
        util.warn("*** 'type' builtin called without -t ***")
        status = 1
        # Keep going anyway

    for name in argv[i:]:
        if name in funcs:
            print('function')
        elif Resolve(name) != EBuiltin.NONE:
            print('builtin')
        elif ResolveSpecial(name) != EBuiltin.NONE:
            print('builtin')
        elif lex.IsOtherBuiltin(name):  # declare, continue, etc.
            print('builtin')
        elif lex.IsKeyword(name):
            print('keyword')
        else:
            # Now look for files.
            found = False
            for path_dir in path_list:
                full_path = os.path.join(path_dir, name)
                if os.path.exists(full_path):
                    print('file')
                    found = True
                    break
            if not found:  # Nothing printed, but status is 1.
                status = 1

    return status