def _RunBuiltin(self, builtin_id, argv, span_id): # NOTE: Builtins don't need to know their own name. argv = argv[1:] # TODO: figure out a quicker dispatch mechanism. Just make a table of # builtins I guess. if builtin_id == builtin_e.EXEC: status = self._Exec(argv) # may never return # But if it returns, then we want to permanently apply the redirects # associated with it. self.fd_state.MakePermanent() elif builtin_id == builtin_e.READ: status = builtin.Read(argv, self.splitter, self.mem) elif builtin_id == builtin_e.ECHO: status = builtin.Echo(argv) elif builtin_id == builtin_e.SHIFT: status = builtin.Shift(argv, self.mem) elif builtin_id == builtin_e.CD: status = builtin.Cd(argv, self.mem, self.dir_stack) elif builtin_id == builtin_e.SET: status = builtin.Set(argv, self.exec_opts, self.mem) elif builtin_id == builtin_e.SHOPT: status = builtin.Shopt(argv, self.exec_opts) elif builtin_id == builtin_e.UNSET: status = builtin.Unset(argv, self.mem, self.funcs) elif builtin_id == builtin_e.EXPORT: status = builtin.Export(argv, self.mem) elif builtin_id == builtin_e.WAIT: status = builtin.Wait(argv, self.waiter, self.job_state, self.mem) elif builtin_id == builtin_e.JOBS: status = builtin.Jobs(argv, self.job_state) elif builtin_id == builtin_e.PUSHD: status = builtin.Pushd(argv, self.mem.GetVar('HOME'), self.dir_stack) elif builtin_id == builtin_e.POPD: status = builtin.Popd(argv, self.mem.GetVar('HOME'), self.dir_stack) elif builtin_id == builtin_e.DIRS: status = builtin.Dirs(argv, self.mem.GetVar('HOME'), self.dir_stack) elif builtin_id == builtin_e.PWD: status = builtin.Pwd(argv, self.mem) elif builtin_id in (builtin_e.SOURCE, builtin_e.DOT): status = self._Source(argv) elif builtin_id == builtin_e.TRAP: status = builtin.Trap(argv, self.traps, self.nodes_to_run, self) elif builtin_id == builtin_e.UMASK: status = builtin.Umask(argv) elif builtin_id == builtin_e.EVAL: status = self._Eval(argv, span_id) elif builtin_id == builtin_e.COMPLETE: status = comp_builtins.Complete(argv, self, self.comp_lookup) elif builtin_id == builtin_e.COMPGEN: status = comp_builtins.CompGen(argv, self) elif builtin_id == builtin_e.COMPOPT: status = comp_builtins.CompOpt(argv) elif builtin_id == builtin_e.COLON: # special builtin like 'true' status = 0 elif builtin_id == builtin_e.TRUE: status = 0 elif builtin_id == builtin_e.FALSE: status = 1 elif builtin_id == builtin_e.TEST: status = test_builtin.Test(argv, False) elif builtin_id == builtin_e.BRACKET: status = test_builtin.Test(argv, True) # need_right_bracket elif builtin_id == builtin_e.GETOPTS: status = builtin.GetOpts(argv, self.mem) elif builtin_id == builtin_e.COMMAND: path = self.mem.GetVar('PATH') status = builtin.Command(argv, self.funcs, path) elif builtin_id == builtin_e.TYPE: path = self.mem.GetVar('PATH') status = builtin.Type(argv, self.funcs, path) elif builtin_id in (builtin_e.DECLARE, builtin_e.TYPESET): # These are synonyms status = builtin.DeclareTypeset(argv, self.mem, self.funcs) elif builtin_id == builtin_e.ALIAS: status = builtin.Alias(argv, self.aliases) elif builtin_id == builtin_e.UNALIAS: status = builtin.UnAlias(argv, self.aliases) elif builtin_id == builtin_e.HELP: loader = util.GetResourceLoader() status = builtin.Help(argv, loader) elif builtin_id == builtin_e.REPR: status = builtin.Repr(argv, self.mem) else: raise AssertionError('Unhandled builtin: %s' % builtin_id) assert isinstance(status, int) return status
def _RunBuiltin(self, builtin_id, argv): restore_fd_state = True # NOTE: Builtins don't need to know their own name. argv = argv[1:] # TODO: figure out a quicker dispatch mechanism. Just make a table of # builtins I guess. if builtin_id == EBuiltin.EXEC: status = self._Exec(argv) # may never return # But if it returns, then we want to permanently apply the redirects # associated with it. self.fd_state.MakePermanent() elif builtin_id == EBuiltin.READ: status = builtin.Read(argv, self.mem) elif builtin_id == EBuiltin.ECHO: status = builtin.Echo(argv) elif builtin_id == EBuiltin.SHIFT: status = builtin.Shift(argv, self.mem) elif builtin_id == EBuiltin.CD: status = builtin.Cd(argv, self.mem) elif builtin_id == EBuiltin.SET: status = builtin.Set(argv, self.exec_opts, self.mem) elif builtin_id == EBuiltin.SHOPT: status = builtin.Shopt(argv, self.exec_opts) elif builtin_id == EBuiltin.UNSET: status = builtin.Unset(argv, self.mem, self.funcs) elif builtin_id == EBuiltin.EXPORT: status = builtin.Export(argv, self.mem) elif builtin_id == EBuiltin.EXIT: status = builtin.Exit(argv) elif builtin_id == EBuiltin.WAIT: status = builtin.Wait(argv, self.waiter, self.job_state, self.mem) elif builtin_id == EBuiltin.JOBS: status = builtin.Jobs(argv, self.job_state) elif builtin_id == EBuiltin.PUSHD: status = builtin.Pushd(argv, self.dir_stack) elif builtin_id == EBuiltin.POPD: status = builtin.Popd(argv, self.dir_stack) elif builtin_id == EBuiltin.DIRS: status = builtin.Dirs(argv, self.dir_stack) elif builtin_id in (EBuiltin.SOURCE, EBuiltin.DOT): status = self._Source(argv) elif builtin_id == EBuiltin.TRAP: status = builtin.Trap(argv, self.traps) elif builtin_id == EBuiltin.UMASK: status = builtin.Umask(argv) elif builtin_id == EBuiltin.EVAL: status = self._Eval(argv) elif builtin_id == EBuiltin.COMPLETE: status = self._Complete(argv) elif builtin_id == EBuiltin.COMPGEN: status = self._CompGen(argv) elif builtin_id == EBuiltin.COLON: # special builtin like 'true' status = 0 elif builtin_id == EBuiltin.TRUE: status = 0 elif builtin_id == EBuiltin.FALSE: status = 1 elif builtin_id == EBuiltin.HELP: loader = util.GetResourceLoader() status = builtin.Help(argv, loader) elif builtin_id == EBuiltin.DEBUG_LINE: status = builtin.DebugLine(argv, self.status_lines) else: raise AssertionError('Unhandled builtin: %d' % builtin_id) assert isinstance(status, int) return status