int main(int argc, char *argv[]) { // mount if (argc < 4) { usage(argv[0]); return 1; } // argv[1] mountpoint, argv[2] mount uri if(mount(argv[1], argv[2])) return 1; // find command struct cmd *cmd; if ((cmd = find_command(argv[3])) == NULL) return 1; return cmd->cmd(argc-3, argv+3); }
static char* _getPnutsHome(char* cmd) { char* p0, *p, p1[MAX_PATH]; static char p2[MAX_PATH]; p0 = find_command(cmd, getenv("PATH")); p = strrchr(p0, '/'); if (p){ *p = 0; } p = strrchr(p0, '/'); if (p){ *p = 0; } strcpy(p1, p0); return (char*)realpath(p1, p2); }
static int process_line(char *linebuf) { command_fn fn; int ret = 0; char *t; const char *p = linebuf; char *com = strchr(linebuf, COMMENT_CHAR); if (com) *com = 0; t = get_token(linebuf); if (t) { fn = find_command(t); if (fn != cmd_invalid) p = skip_token(linebuf); ret = fn(p); free(t); } return ret; }
void handle_line(char *line) { if (line != NULL) { char *cpy = calloc(1, strlen(line) + 1), *tok; strcpy(cpy, line); tok = strtok(line, DELIMS); if (tok != NULL) { Command *c = find_command(tok); if (c != NULL) c->callback(); else printf("Command not found: %s\n", tok); add_history(cpy); } free(cpy); free(line); } }
int main(int argc, char** argv) { if (argc < 2) { usage(argv[0]); return -1; } const command_t* command = find_command(argv[1]); if (!command) { printf("Unrecognized command '%s'.\n", argv[1]); return -2; } if (!command->handler) { printf("Unhandled command '%s'.\n", argv[1]); return -3; } return command->handler(argc - 2, &argv[2]); }
static int help_f( int argc, char **argv) { const cmdinfo_t *ct; if (argc == 1) { help_all(); return 0; } ct = find_command(argv[1]); if (ct == NULL) { printf(_("command %s not found\n"), argv[1]); return 0; } help_onecmd(argv[1], ct); return 0; }
int start_shell() { int argc; while (1) { fb_prompt(); sem_up(&cmd_buffer_sem); sem_down(&shell_sem); // wait until shell is ready char** args = parse_command(cmd_buffer, &argc); command_t* command = find_command(args[0]); if (command == NULL) { fb_print_text("Command not found\n"); } else { /*fb_print_text("BEFORE FORK\n"); int pid = sys_fork(); fb_print_text("AFTER FORK\n"); if (pid == 0) { command(argc-1, args+1); // skip command name sys_exit(0); } else { int cmd_status; sys_waitpid(pid, &cmd_status); fb_print_char('\n'); // TODO fill shell variable of last return code: $? }*/ command(argc-1, args+1); fb_print_char('\n'); } } return 0; }
int run_command(int argc, char *argv[]) /* * The only public interface of this module. Searches the command name * and if found executes it. * Parameters: * o int argc- number of arguments * o char *argv[] - array of arguments * Return : exit status of command handler functions, otherwise 1 * sets my_errno to BAD_COMMAND_NAME if unsupported command is run */ { const char* cmdName = argv[0]; commandfunc_t func = find_command(cmdName);//search command name if(func != NULL)//run command if found { return func(argc,argv); } my_errno = BAD_COMMAND_NAME;//sets errno if command not found return 1; }
static int command(int argc, char *argv[]) { int i; os::String command = find_command(); if (!command.length()) { return 1; } std::vector<const char *> args; args.push_back("python"); args.push_back(command.str()); for (i = 1; i < argc; i++) { args.push_back(argv[i]); } args.push_back(NULL); return os::execute((char * const *)&args[0]); }
void load_disabled( ) { FILE *fp; DISABLED_DATA *disabled; CMDTYPE *cmd; char *word; fp = fopen( DISABLE_FILE, "r" ); if( !fp ) { bug( "Unable to open disabled commands list." ); return; } for( ;; ) { word = fread_word( fp ); if( !str_cmp( word, "End" ) ) break; cmd = find_command( word ); if( !cmd ) { bug( "Unknown command in disabled list." ); fread_number( fp ); fread_word( fp ); continue; } CREATE( disabled, DISABLED_DATA, 1 ); disabled->command = cmd; disabled->level = fread_number( fp ); disabled->who = STRALLOC( fread_word( fp ) ); disabled->next = first_disabled; first_disabled = disabled; } fclose( fp ); }
void ex_input(Keyarg *ca) { log_msg("EXCMD", "input"); if (menu_hints_enabled(ex.menu)) { if (menu_input(ex.menu, ca->key)) ex_car(); } int idx = find_command(&key_tbl, ca->key); ca->arg = key_defaults[idx].cmd_arg; if (idx >= 0) key_defaults[idx].cmd_func(NULL, ca); else ex_getchar(ca); if (ex.state & EX_QUIT) stop_ex_cmd(); else ex_onkey(); }
static int command(int argc, char *argv[]) { int i; os::String command = find_command(); os::String apitracePath = os::getProcessName(); std::vector<const char *> args; args.push_back(APITRACE_PYTHON_EXECUTABLE); args.push_back(command.str()); args.push_back("--apitrace"); args.push_back(apitracePath.str()); for (i = 1; i < argc; i++) { args.push_back(argv[i]); } args.push_back(NULL); return os::execute((char * const *)&args[0]); }
int main( int argc, char **argv ) { int cmd = -1; HWND hwnd = NULL; print_license(); printf( "\n" ); if( argc < 2 ) show_usage_and_exit(); cmd = find_command( argv[ 1 ] ); if( cmd == -1 ) show_usage_and_exit(); hwnd = FindWindowEx( NULL, NULL, "gdkWindowToplevel", "Workrave" ); if( !hwnd ) { printf( "Error: Workrave window not found!\n" ); return 1; } printf( "Sending Workrave command %s...\n", command[ cmd ] ); fflush( stdout ); SetLastError( 0 ); if( SendMessageTimeout( hwnd, WM_USER, cmd, 0, SMTO_BLOCK, 15000, NULL ) ) { printf( "Command sent.\n" ); return 0; } if( GetLastError() == ERROR_TIMEOUT ) printf( "Error: SendMessageTimeout() timed out!\n" ); else printf( "Error: SendMessageTimeout() failed!\n" ); return 1; }
/* * start_cmd_processing - main command processing loop. * */ void pagentd_cli_start ( void ) { char *cmdline; COMMAND *theCmd; BOOL retb; char cmdl[100]; puts(menuMsg); /* * the main command loop. */ while (1) { cmdline = rl_gets(); strcpy(cmdl, cmdline); theCmd = find_command(cmdline); if (!theCmd) printf("%s: No such command!\n", cmdline); else { retb = theCmd->cmdHandler(cmdl); } } }
int run_commands( cmd_node_t * head , char ** cvec ) { int ret; if(!head || !cvec ) error_ret("null args",-1); cmd_node_t * next; /* XXX: what if an argument to a command is also a command itself? */ if(!(next = find_command( head->opts , cvec[0] ))) /* we're here */ { if( head->cmd ) ret = head->cmd->func( cvec ); else error_ret("no command",-1); } else ret = run_commands( next , ++cvec ); return(ret); }
static int execute_line(char* line) { int rv, us; char *cmdstr; shell_cmd* cmd; struct timeval start, end; cmdstr = strsep(&line, " "); cmd = find_command(cmdstr); if (cmd == NULL) { fprintf (stderr, "%s: command not found.\n", cmdstr); return -1; } gettimeofday(&start, NULL); rv = cmd->func(line); gettimeofday(&end, NULL); us = timeval_diff(&start, &end); if ((rv == 0) && (cmd->time)) printf("took %.2f ms\n", (us / (double)1000)); return rv; }
static int execute_line(const char *line) { struct command *command; char *argv[MAX_ARGS]; char *buf, *cmd; int i, ret; if (*line == '\0') return -1; memset(argv, 0, sizeof(argv)); if ((buf = strdup(line)) == NULL) { fprintf(stderr, "No memory for strdup err:%d\n", errno); return (-1); } /* * Readline gives us an array in buf seperated by tabs. * Lets break it into pieces to fit our argv[n] strings. */ cmd = strtok(buf, " \t"); for (i=0; i<MAX_ARGS; i++) { argv[i] = strtok(NULL, " \t"); if (argv[i] == NULL) { break; } } /* Since the line may have been generated by command completion * or by the user, we cannot be sure that it is a valid command name. */ command = find_command(cmd); if (command == NULL) { printf("%s: No such command.\n", cmd); return -1; } ret = command->co_func(argv, i); free(buf); return ret; }
void assign_the_quests(void) { qst_rnum rnum; mob_rnum mrnum; cmd_tell = find_command("tell"); for (rnum = 0; rnum < total_quests; rnum ++) { if (QST_MASTER(rnum) == NOBODY) { log("SYSERR: Quest #%d has no questmaster specified.", QST_NUM(rnum)); continue; } if ((mrnum = real_mobile(QST_MASTER(rnum))) == NOBODY) { log("SYSERR: Quest #%d has an invalid questmaster.", QST_NUM(rnum)); continue; } if (mob_index[QST_MASTER(rnum)].func && mob_index[(mrnum)].func != questmaster) QST_FUNC(rnum) = mob_index[(mrnum)].func; mob_index[(mrnum)].func = questmaster; } }
/** * Verify that some programs can be found in the PATH. */ void checkpath(void) { static const char *const prog_list[] = { DEFAULTSHELL, RM, TAR, DIFF, BACKEND, /* Mac OS X uses dyld (Mach-O) instead of ld.so (ELF), and does not have * an ldconfig. */ #if defined(__APPLE__) && defined(__MACH__) "update_dyld_shared_cache", #else "ldconfig", #endif #if BUILD_START_STOP_DAEMON "start-stop-daemon", #endif NULL }; const char *const *prog; int warned= 0; for (prog = prog_list; *prog; prog++) { if (!find_command(*prog)) { warning(_("'%s' not found in PATH or not executable"), *prog); warned++; } } if (warned) forcibleerr(fc_badpath, P_("%d expected program not found in PATH or not executable\n%s", "%d expected programs not found in PATH or not executable\n%s", warned), warned, _("Note: root's PATH should usually contain " "/usr/local/sbin, /usr/sbin and /sbin")); }
static int parse_command(char *Str) { int len; char *S, *S1; Com_enum_t com; S = Str; while (*S != 0) { if ((*S == '\t') || (*S == '\n')) *S = ' '; S++; }; S = Str; while (*S == ' ') S++; len = strlen(S); if (len == 0) return(0); S1 = S; while ((*S1 != 0) && (*S1 != ' ')) S1++; if (*S1 != 0) *S1++ = 0; com = find_command(S); switch (com) { case COM_UNDEF: printf("Invalid command: %s\n", S); help(); break; case COM_EXIT: return(-1); case COM_RPT: show_rpts(S1); break; case COM_RDR: show_rdrs(S1); break; case COM_SENS: show_sens(S1); break; case COM_MOD: mod_sen(); break; case COM_UNDO: undo(); break; case COM_HELP: help(); break; }; return(0); }
static int do_help(int argc, char *argv[]) { const struct futil_cmd_t *cmd; const char *vstr = ""; /* Help about a known command? */ if (argc > 1) { cmd = find_command(argv[1]); if (cmd) { /* Let the command provide its own help */ argv[0] = argv[1]; argv[1] = "--help"; return run_command(cmd, argc, argv); } } fputs(usage, stdout); if (vboot_version == VBOOT_VERSION_ALL) fputs(options, stdout); switch (vboot_version) { case VBOOT_VERSION_1_0: vstr = "version 1.0 "; break; case VBOOT_VERSION_2_1: vstr = "version 2.1 "; break; case VBOOT_VERSION_ALL: vstr = ""; break; } printf("The following %scommands are built-in:\n\n", vstr); list_commands(); printf("\nUse \"" MYNAME " help COMMAND\" for more information.\n\n"); return 0; }
/* Execute a command line. */ int execute_line (char *line) { register int i; command *command; char *word; /* Isolate the command word. */ i = 0; while (line[i] && whitespace (line[i])) i++; word = line + i; while (line[i] && !whitespace (line[i])) i++; if (line[i]) line[i++] = '\0'; command = find_command(word); if (!command) { sprintf(buffer, "%s: %s \n", word, NOCOMMAND_MSG); send(cli_cfg->cfd, buffer, strlen(buffer), 0); printf("[CLI] commnad %s does not exist !\n", word); return (-1); } /* Get argument to command, if any. */ while (whitespace (line[i])) i++; word = line + i; /* Call the function. */ return ((*(command->func)) (word)); }
static int execute_line(char *line) { int i = 0; char *word; command_t *command; while (line[i] && isspace(line[i])) ++i; word = line + i; while (line[i] && !isspace(line[i])) ++i; if (line[i]) line[i++] = '\0'; if ((command = find_command(word)) == NULL) { fprintf(stdout, "%s: No such command for xcb-cli\n", word); return -1; } while (isspace(line[i])) ++i; word = line + i; return command->func(word); }
/** * A função main é um ciclo que apenas termina quando o utilizador insere o comando "q". * Esta função vai então ser responsável iniciar o programa e receber os comandos que o utilizador lhe introduz. * Vai imprimir os resultados do jogo enquanto este decorrer. */ int main() { char *cmd = NULL; FUNCTION *fun = NULL; BOARD * brd = NULL; srand(time(NULL)); brd = initialize_state(); while(rl_gets() != NULL) { int i, j; /* Ignorar os espacos no inicio do comando */ for(i = 0; line_read[i] && whitespace(line_read[i]); i++); /* Saltar a primeira palavra da linha */ for(j = i; line_read[j] && !whitespace(line_read[j]); j++); /* Delimitar o nome do comando */ if(line_read[j]) line_read[j++] = 0; /* Saltar os espacos mais uma vez */ for(; line_read[j] && whitespace(line_read[j]); j++); cmd = line_read + i; fun = find_command(cmd); if(fun != NULL) { brd = fun(line_read + j, brd); print_state(brd); } else { mensagem_de_erro(E_COMMAND); } } return 0; }
static int do_help(int argc, char *argv[]) { const struct futil_cmd_t *cmd; const char *vstr; if (argc >= 2) { cmd = find_command(argv[1]); if (cmd) { printf("\n%s - %s\n", argv[1], cmd->shorthelp); if (cmd->longhelp) cmd->longhelp(argv[1]); return 0; } } fputs(usage, stdout); if (vboot_version == VBOOT_VERSION_ALL) fputs(options, stdout); switch (vboot_version) { case VBOOT_VERSION_1_0: vstr = "version 1.0 "; break; case VBOOT_VERSION_2_1: vstr = "version 2.1 "; break; case VBOOT_VERSION_ALL: vstr = ""; break; } printf("The following %scommands are built-in:\n\n", vstr); list_commands(); printf("\nUse \"" MYNAME " help COMMAND\" for more information.\n\n"); return 0; }
/* Execute a command line. */ int execute_line (char *line) { register int i; COMMAND *command; char *word; /* Isolate the command word. */ i = 0; while (line[i] && isspace (line[i])) i++; word = line + i; while (line[i] && !isspace (line[i])) i++; if (line[i]) line[i++] = '\0'; command = find_command (word); if (!command) { fprintf (stderr, "%s: No such command for FileMan.\n", word); return (-1); } /* Get argument to command, if any. */ while (isspace (line[i])) i++; word = line + i; /* Call the function. */ return ((*(command->func)) (word)); }
static int help(int argc, char *argv[]) { struct cmd *cmd; if(argc == 1) { printf("available commands:\n"); for (int i=0; i < ENTRIES(commands); i++) { printf("%-15s", commands[i].name); if (((i + 1) % 5) == 0) { printf("\n"); } } printf("\n"); return 0; } if((cmd = find_command(argv[1])) != NULL) { printf("%s: %s\n", argv[1], cmd->usage); return 0; } else { printf("%s: %s: command not found\n", argv[0], argv[1]); return 1; } }
int cmd_help(char *argv[], int argc) { int i, printed; char *cmdname; struct command *cmd; if (argc > 0) { cmdname = argv[0]; if ( (cmd = find_command(cmdname)) != NULL) { printf("%s\n", cmd->co_desc); } else { printf("help: no match for `%s'. Command\n", cmdname); printf("Use one of:\n"); goto dump_all; } } else { dump_all: for (i = 0; commands[i].co_name != NULL; i++) { printf("%s\n", commands[i].co_desc); } } return(0); }
int execute_line(const char *cmd,csString *buffer) { ConsoleOut::SetStringBuffer(buffer); char line[1000]; strcpy (line, cmd); int i; const COMMAND *command; char *word; i = 0; while (line[i] && whitespace (line[i])) i++; word = line + i; while (line[i] && !whitespace (line[i])) i++; if (line[i]) line[i++]='\0'; command = find_command(word); if (!command) { CPrintf (CON_CMDOUTPUT, "No such command: %s\n", word); return -1; } while (whitespace (line[i])) i++; word = line + i; return ((*(command->func)) (word)); }
static void evalcommand(union node *cmd, int flags, struct backcmd *backcmd) { union node *argp; struct arglist arglist; struct arglist varlist; char **argv; int argc; char **envp; int varflag; struct strlist *sp; int mode; int pip[2]; struct cmdentry cmdentry; struct job *jp; struct jmploc jmploc; struct jmploc *savehandler; char *savecmdname; struct shparam saveparam; struct localvar *savelocalvars; struct parsefile *savetopfile; volatile int e; char *lastarg; int realstatus; int do_clearcmdentry; const char *path = pathval(); /* First expand the arguments. */ TRACE(("evalcommand(%p, %d) called\n", (void *)cmd, flags)); arglist.lastp = &arglist.list; varlist.lastp = &varlist.list; varflag = 1; jp = NULL; do_clearcmdentry = 0; oexitstatus = exitstatus; exitstatus = 0; for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) { if (varflag && isassignment(argp->narg.text)) { expandarg(argp, varflag == 1 ? &varlist : &arglist, EXP_VARTILDE); continue; } else if (varflag == 1) varflag = isdeclarationcmd(&argp->narg) ? 2 : 0; expandarg(argp, &arglist, EXP_FULL | EXP_TILDE); } *arglist.lastp = NULL; *varlist.lastp = NULL; expredir(cmd->ncmd.redirect); argc = 0; for (sp = arglist.list ; sp ; sp = sp->next) argc++; /* Add one slot at the beginning for tryexec(). */ argv = stalloc(sizeof (char *) * (argc + 2)); argv++; for (sp = arglist.list ; sp ; sp = sp->next) { TRACE(("evalcommand arg: %s\n", sp->text)); *argv++ = sp->text; } *argv = NULL; lastarg = NULL; if (iflag && funcnest == 0 && argc > 0) lastarg = argv[-1]; argv -= argc; /* Print the command if xflag is set. */ if (xflag) { char sep = 0; const char *p, *ps4; ps4 = expandstr(ps4val()); out2str(ps4 != NULL ? ps4 : ps4val()); for (sp = varlist.list ; sp ; sp = sp->next) { if (sep != 0) out2c(' '); p = strchr(sp->text, '='); if (p != NULL) { p++; outbin(sp->text, p - sp->text, out2); out2qstr(p); } else out2qstr(sp->text); sep = ' '; } for (sp = arglist.list ; sp ; sp = sp->next) { if (sep != 0) out2c(' '); /* Disambiguate command looking like assignment. */ if (sp == arglist.list && strchr(sp->text, '=') != NULL && strchr(sp->text, '\'') == NULL) { out2c('\''); out2str(sp->text); out2c('\''); } else out2qstr(sp->text); sep = ' '; } out2c('\n'); flushout(&errout); } /* Now locate the command. */ if (argc == 0) { /* Variable assignment(s) without command */ cmdentry.cmdtype = CMDBUILTIN; cmdentry.u.index = BLTINCMD; cmdentry.special = 0; } else { static const char PATH[] = "PATH="; int cmd_flags = 0, bltinonly = 0; /* * Modify the command lookup path, if a PATH= assignment * is present */ for (sp = varlist.list ; sp ; sp = sp->next) if (strncmp(sp->text, PATH, sizeof(PATH) - 1) == 0) { path = sp->text + sizeof(PATH) - 1; /* * On `PATH=... command`, we need to make * sure that the command isn't using the * non-updated hash table of the outer PATH * setting and we need to make sure that * the hash table isn't filled with items * from the temporary setting. * * It would be better to forbit using and * updating the table while this command * runs, by the command finding mechanism * is heavily integrated with hash handling, * so we just delete the hash before and after * the command runs. Partly deleting like * changepatch() does doesn't seem worth the * bookinging effort, since most such runs add * directories in front of the new PATH. */ clearcmdentry(); do_clearcmdentry = 1; } for (;;) { if (bltinonly) { cmdentry.u.index = find_builtin(*argv, &cmdentry.special); if (cmdentry.u.index < 0) { cmdentry.u.index = BLTINCMD; argv--; argc++; break; } } else find_command(argv[0], &cmdentry, cmd_flags, path); /* implement the bltin and command builtins here */ if (cmdentry.cmdtype != CMDBUILTIN) break; if (cmdentry.u.index == BLTINCMD) { if (argc == 1) break; argv++; argc--; bltinonly = 1; } else if (cmdentry.u.index == COMMANDCMD) { if (argc == 1) break; if (!strcmp(argv[1], "-p")) { if (argc == 2) break; if (argv[2][0] == '-') { if (strcmp(argv[2], "--")) break; if (argc == 3) break; argv += 3; argc -= 3; } else { argv += 2; argc -= 2; } path = _PATH_STDPATH; clearcmdentry(); do_clearcmdentry = 1; } else if (!strcmp(argv[1], "--")) { if (argc == 2) break; argv += 2; argc -= 2; } else if (argv[1][0] == '-') break; else { argv++; argc--; } cmd_flags |= DO_NOFUNC; bltinonly = 0; } else break; } /* * Special builtins lose their special properties when * called via 'command'. */ if (cmd_flags & DO_NOFUNC) cmdentry.special = 0; } /* Fork off a child process if necessary. */ if (((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN) && ((flags & EV_EXIT) == 0 || have_traps())) || ((flags & EV_BACKCMD) != 0 && (cmdentry.cmdtype != CMDBUILTIN || !safe_builtin(cmdentry.u.index, argc, argv)))) { jp = makejob(cmd, 1); mode = FORK_FG; if (flags & EV_BACKCMD) { mode = FORK_NOJOB; if (pipe(pip) < 0) error("Pipe call failed: %s", strerror(errno)); } if (cmdentry.cmdtype == CMDNORMAL && cmd->ncmd.redirect == NULL && varlist.list == NULL && (mode == FORK_FG || mode == FORK_NOJOB) && !disvforkset() && !iflag && !mflag) { vforkexecshell(jp, argv, environment(), path, cmdentry.u.index, flags & EV_BACKCMD ? pip : NULL); goto parent; } if (forkshell(jp, cmd, mode) != 0) goto parent; /* at end of routine */ if (flags & EV_BACKCMD) { FORCEINTON; close(pip[0]); if (pip[1] != 1) { dup2(pip[1], 1); close(pip[1]); } flags &= ~EV_BACKCMD; } flags |= EV_EXIT; } /* This is the child process if a fork occurred. */ /* Execute the command. */ if (cmdentry.cmdtype == CMDFUNCTION) { #ifdef DEBUG trputs("Shell function: "); trargs(argv); #endif saveparam = shellparam; shellparam.malloc = 0; shellparam.reset = 1; shellparam.nparam = argc - 1; shellparam.p = argv + 1; shellparam.optnext = NULL; INTOFF; savelocalvars = localvars; localvars = NULL; reffunc(cmdentry.u.func); savehandler = handler; if (setjmp(jmploc.loc)) { freeparam(&shellparam); shellparam = saveparam; popredir(); unreffunc(cmdentry.u.func); poplocalvars(); localvars = savelocalvars; funcnest--; handler = savehandler; longjmp(handler->loc, 1); } handler = &jmploc; funcnest++; redirect(cmd->ncmd.redirect, REDIR_PUSH); INTON; for (sp = varlist.list ; sp ; sp = sp->next) mklocal(sp->text); exitstatus = oexitstatus; evaltree(getfuncnode(cmdentry.u.func), flags & (EV_TESTED | EV_EXIT)); INTOFF; unreffunc(cmdentry.u.func); poplocalvars(); localvars = savelocalvars; freeparam(&shellparam); shellparam = saveparam; handler = savehandler; funcnest--; popredir(); INTON; if (evalskip == SKIPFUNC) { evalskip = 0; skipcount = 0; } if (jp) exitshell(exitstatus); } else if (cmdentry.cmdtype == CMDBUILTIN) { #ifdef DEBUG trputs("builtin command: "); trargs(argv); #endif mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH; if (flags == EV_BACKCMD) { memout.nleft = 0; memout.nextc = memout.buf; memout.bufsize = 64; mode |= REDIR_BACKQ; } savecmdname = commandname; savetopfile = getcurrentfile(); cmdenviron = varlist.list; e = -1; savehandler = handler; if (setjmp(jmploc.loc)) { e = exception; if (e == EXINT) exitstatus = SIGINT+128; else if (e != EXEXIT) exitstatus = 2; goto cmddone; } handler = &jmploc; redirect(cmd->ncmd.redirect, mode); outclearerror(out1); /* * If there is no command word, redirection errors should * not be fatal but assignment errors should. */ if (argc == 0) cmdentry.special = 1; listsetvar(cmdenviron, cmdentry.special ? 0 : VNOSET); if (argc > 0) bltinsetlocale(); commandname = argv[0]; argptr = argv + 1; nextopt_optptr = NULL; /* initialize nextopt */ builtin_flags = flags; exitstatus = (*builtinfunc[cmdentry.u.index])(argc, argv); flushall(); if (outiserror(out1)) { warning("write error on stdout"); if (exitstatus == 0 || exitstatus == 1) exitstatus = 2; } cmddone: if (argc > 0) bltinunsetlocale(); cmdenviron = NULL; out1 = &output; out2 = &errout; freestdout(); handler = savehandler; commandname = savecmdname; if (jp) exitshell(exitstatus); if (flags == EV_BACKCMD) { backcmd->buf = memout.buf; backcmd->nleft = memout.nextc - memout.buf; memout.buf = NULL; } if (cmdentry.u.index != EXECCMD) popredir(); if (e != -1) { if ((e != EXERROR && e != EXEXEC) || cmdentry.special) exraise(e); popfilesupto(savetopfile); if (flags != EV_BACKCMD) FORCEINTON; } } else { #ifdef DEBUG trputs("normal command: "); trargs(argv); #endif redirect(cmd->ncmd.redirect, 0); for (sp = varlist.list ; sp ; sp = sp->next) setvareq(sp->text, VEXPORT|VSTACK); envp = environment(); shellexec(argv, envp, path, cmdentry.u.index); /*NOTREACHED*/ } goto out; parent: /* parent process gets here (if we forked) */ if (mode == FORK_FG) { /* argument to fork */ INTOFF; exitstatus = waitforjob(jp, &realstatus); INTON; if (iflag && loopnest > 0 && WIFSIGNALED(realstatus)) { evalskip = SKIPBREAK; skipcount = loopnest; } } else if (mode == FORK_NOJOB) { backcmd->fd = pip[0]; close(pip[1]); backcmd->jp = jp; } out: if (lastarg) setvar("_", lastarg, 0); if (do_clearcmdentry) clearcmdentry(); }