static ModeMode run_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line ) { RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data; ModeMode retv = MODE_EXIT; gboolean run_in_term = ( ( mretv & MENU_CUSTOM_ACTION ) == MENU_CUSTOM_ACTION ); if ( mretv & MENU_NEXT ) { retv = NEXT_DIALOG; } else if ( mretv & MENU_PREVIOUS ) { retv = PREVIOUS_DIALOG; } else if ( mretv & MENU_QUICK_SWITCH ) { retv = ( mretv & MENU_LOWER_MASK ); } else if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line] != NULL ) { exec_cmd ( rmpd->cmd_list[selected_line], run_in_term ); } else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) { exec_cmd ( *input, run_in_term ); } else if ( ( mretv & MENU_ENTRY_DELETE ) && rmpd->cmd_list[selected_line] ) { delete_entry ( rmpd->cmd_list[selected_line] ); // Clear the list. retv = RELOAD_DIALOG; run_mode_destroy ( sw ); run_mode_init ( sw ); } return retv; }
void external_execute(char run_cmd, ...) { char cmd[128]; va_list args; va_start(args, run_cmd); switch(run_cmd){ case COMPILER_ICARUS: { /* Execute Icarus compiler */ string filename = string(va_arg(args, char*)); int skip_verilog_src = va_arg(args, int); if(filename == "(stdio)" || skip_verilog_src) { /* Generate temporary file and compile that file: */ string source_code = string(va_arg(args, char*)); int compile_and_run = va_arg(args, int); /* Prepare temporary (.v) file: */ ofstream f; string tmp_filename = filename == "(stdio)" ? TMP_FILE : strip_extension(filename); f.open((tmp_filename + ".v").c_str()); f << source_code; f.close(); /* Prepare command and build that .v file: */ sprintf(cmd, "iverilog -o %s.o %s.v", tmp_filename.c_str(), tmp_filename.c_str()); exec_cmd(cmd); if(compile_and_run) { sprintf(cmd, "vvp %s.o", tmp_filename.c_str()); exec_cmd(cmd); } /* Cleanup .v temporary files: */ remove((tmp_filename + ".v").c_str()); temp_objfiles.push_back(tmp_filename + ".o"); } else { /* Skip variadic arguments: */ va_arg(args, char*); int compile_and_run = va_arg(args, int); /* Compile given file */ char* output_filename = (char*)strip_extension(filename).c_str(); sprintf(cmd, "iverilog -o %s.o %s", output_filename, filename.c_str()); exec_cmd(cmd); if(compile_and_run) { sprintf(cmd, "vvp %s.o", output_filename); exec_cmd(cmd); } } break; }
static SwitcherMode drun_mode_result ( int mretv, char **input, unsigned int selected_line, Switcher *sw ) { DRunModePrivateData *rmpd = (DRunModePrivateData *) sw->private_data; SwitcherMode retv = MODE_EXIT; int shift = ( ( mretv & MENU_SHIFT ) == MENU_SHIFT ); if ( mretv & MENU_NEXT ) { retv = NEXT_DIALOG; } else if ( mretv & MENU_PREVIOUS ) { retv = PREVIOUS_DIALOG; } else if ( mretv & MENU_QUICK_SWITCH ) { retv = ( mretv & MENU_LOWER_MASK ); } else if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line] != NULL ) { exec_cmd_entry ( &( rmpd->entry_list[selected_line] ) ); } else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) { exec_cmd ( *input, shift ); } return retv; }
/* * Handle commands with flags and options, and ultimately run the command. */ uint8_t run_cmd(struct state *st) { char *new_cmd = NULL; new_cmd = strdup(st->cmd); if (st->flags) { if (st->shift_pressed) { new_cmd = fill_in_command(st->cmd, "", st->flags); if (new_cmd == NULL) { warnx("fill_in_command failed"); goto done; } } else if (!fill_in_flags(&new_cmd, st->flags)) goto done; } if (st->use_term) if (!add_terminal(&new_cmd)) goto done; exec_cmd(new_cmd); free(new_cmd); return 1; done: free(new_cmd); return 0; }
int main(){ // called at the start of shell, manages all other shell commands printf("\nWelcome to GoodShell!\nTotally not a ripoff of Bash.\n\n"); chdir(home() ); char input[MAX_INPUT]; char **cmds, **cmd_p, **args; while(1){ // new line with path for new command print_prompt(); // gets the command line argument read_line(input); // seperates commands cmds = separate_cmds(input); if (cmds){ for (cmd_p = cmds; *cmd_p; cmd_p++){ args = separate_args(*cmd_p); if (args){ exec_cmd(args, cmds); free_strlist(args); } } free_strlist(cmds); } } return EXIT_FAILURE; }
static ModeMode drun_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line ) { DRunModePrivateData *rmpd = (DRunModePrivateData *) mode_get_private_data ( sw ); ModeMode retv = MODE_EXIT; gboolean run_in_term = ( ( mretv & MENU_CUSTOM_ACTION ) == MENU_CUSTOM_ACTION ); if ( mretv & MENU_NEXT ) { retv = NEXT_DIALOG; } else if ( mretv & MENU_PREVIOUS ) { retv = PREVIOUS_DIALOG; } else if ( mretv & MENU_QUICK_SWITCH ) { retv = ( mretv & MENU_LOWER_MASK ); } else if ( ( mretv & MENU_OK ) ) { exec_cmd_entry ( &( rmpd->entry_list[selected_line] ) ); } else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) { exec_cmd ( *input, run_in_term ); } else if ( ( mretv & MENU_ENTRY_DELETE ) && selected_line < rmpd->cmd_list_length ) { if ( selected_line < rmpd->history_length ) { delete_entry_history ( &( rmpd->entry_list[selected_line] ) ); drun_entry_clear ( &( rmpd->entry_list[selected_line] ) ); memmove ( &( rmpd->entry_list[selected_line] ), &rmpd->entry_list[selected_line + 1], sizeof ( DRunModeEntry ) * ( rmpd->cmd_list_length - selected_line - 1 ) ); rmpd->cmd_list_length--; } retv = RELOAD_DIALOG; } return retv; }
int main (int argc, char **argv) { s_rules rr; if (argv[argc]) err(1, "bad argument list"); if (argc != 3) usage(argv[0]); if (strcmp(argv[1], "-c")) usage(argv[0]); openlog(argv[0], LOG_PID, LOG_AUTH); log_args("NEW", argc, (const char **)argv); init_package(); { const char *env_auth_id = getenv(ENV_AUTH_ID); t_sym id = sympackage_intern(&g_sympkg, env_auth_id ? env_auth_id : ""); s_symtable cmd; cmd_init(&cmd, id, argv[2]); rules_init(&rr); rules_read(&rr, "/etc/git-auth.conf"); { int auth_ok = auth(&rr, &cmd); rules_free(&rr); log_rule(auth_ok ? "ALLOW" : "DENY", &cmd); if (auth_ok) { exec_cmd(&cmd); // never reached } } log_rule("DENY", &cmd); } cleanup(); return 1; }
static void *extract_emergency_phr_main(void *arg) { char err_code[ERR_MSG_LENGTH + 1]; init_emergency_phr_extraction(); // Release heap allocated items even if this thread doesn't exit normally pthread_cleanup_push(uninit_emergency_phr_extraction, NULL); // Unarchive the emergency PHR sprintf(shell_cmd, "tar -xf %s -C \"%s\"", UNARCHIVED_EMERGENCY_PHR_TARGET_FILE_PATH, *ptr_phr_download_to_path); exec_cmd(shell_cmd, strlen(shell_cmd), err_code, sizeof(err_code)); if(strcmp(err_code, "") != 0) { fprintf(stderr, "Unarchieving the emergency PHR failed\n\"%s\"\n", err_code); send_error_msg_to_frontend("Unarchieving the emergency PHR failed"); transaction_success_status_flag = false; goto ERROR; } transaction_success_status_flag = true; ERROR: unlink(UNARCHIVED_EMERGENCY_PHR_TARGET_FILE_PATH); pthread_cleanup_pop(1); tell_emergency_phr_extraction_thread_terminates(); pthread_exit(NULL); return NULL; }
void ButtonPressEvent(XButtonEvent * xev) { char buf[256]; if (xev->type != ButtonPress) return; switch (xev->button) { case Button1: ifno++; break; case Button2: case Button3: if(ifinfo.state == 0) { sprintf(buf, exec_up, ifinfo.id); } else { sprintf(buf, exec_down, ifinfo.id); } exec_cmd(buf); break; } }
int check_cmd(t_shell *sh, t_node *tree) { int i; i = -1; number_reset(sh); sh->cmd = my_str_to_wordtab(tree->str); dollar(sh); check_point_slash(sh, sh->env); if (built_in(sh) == -1) return (-1); while (sh->path != NULL && sh->path[++i] != NULL && sh->ch == 0) if (access(strcat(sh->path[i], sh->cmd[0]), X_OK) == 0) exec_cmd(sh->path[i], sh->cmd, sh->env, sh); if (sh->ch == 0) exec_slah_bin(sh->cmd, sh); if (sh->ch == 0) { fprintf(stderr, "Error: '%s' command not found\n", sh->cmd[0]); sh->ok_cmd = -1; return (0); } my_free(sh->cmd); return (0); }
int process_command_line(t_parser **parserp, t_env *envs, int *status, char *redir) { pid_t pid; t_parser *tmp; tmp = *parserp; if (strcmp(tmp->data, "|") == 0 && pipe(tmp->command->pipefd) == -1) return (-1); if (tmp->command->is_builtin == 1) return (select_builtin(tmp->command->new_argv, envs, status)); if ((pid = fork()) == 0) { if (test_redir(&tmp, redir) == -1 || test_pipe(tmp, *redir) == -1 || exec_cmd(tmp, envs) == -1) return (-1); } else if (pid > 0) { get_only_cmd_custom(parserp); (*parserp)->command->pid = pid; return (0); } else perror("Fork Error"); return (0); }
BOOL exec_pipes(t_pipes *p, t_info *info, FLAG son, FD pi[3]) { STATUS status_quo; pid_t pid; FD w[2]; if (!(pid = -(!((unsigned long)(p->next != NULL))))) { if (pipe(w) == -1) return (FALSE); if ((pid = xfork()) < 0) return (FALSE); } if (!pid) { init_pipe(w, pi, W_IN); exec_pipes(p->next, info, SON, pi); return (FALSE); } if (p->next) init_pipe(w, pi, W_OUT); if (exec_cmd(p->cmd, info, info->son = (son | (2 * (pid > 0))), pi) == FALSE) return (FALSE); my_wait(pid, &status_quo); if (pid < 0) return (TRUE); return (get_status(info, status_quo)); }
static void hexedit_open (char *file, char *line) { char *argv[] = { hep, file, NULL }; // Avoid compiler warning if (line) {;} exec_cmd(argv); }
void OnCopyClick(wxCommandEvent&) { wxString gdbname, exepath, corepath; gdbname = m_gdb->GetValue(); exepath = m_img->GetValue(); corepath = m_corefile->GetValue(); if (gdbname.length()>0 && corepath.length()>0 && exepath.length()==0) return FindExectuable(corepath); if (gdbname.length() > 0 && corepath.length() > 0 && exepath.length() > 0) { wxString txtfile(&_binary_gdbcmd_txt_start, (int) &_binary_gdbcmd_txt_size); wxString cmdpattern; cmdpattern.Printf(txtfile, gdbname, exepath, corepath); m_coreinfo->SetValue(cmdpattern); m_coreinfo->SetValue(exec_cmd(cmdpattern.c_str())); } // cmdpattern.Printf(m_coreinfo->GetValue(), ) // wxClipboard cb; // if(cb.Open()){ // cb.Clear(); // cb.SetData(new wxTextDataObject(m_coreinfo->GetValue())); // cb.Flush(); // cb.Close(); // } }
int exec_fath(char *line, t_sh *t) { if (t->save_c) wait(0); t->pv = ++t->pv2; while (line[t->pv2] && !search_ope(&line[t->pv2], t->ope, 1)) t->pv2++; close(t->pipe_fd[1]); dup2(t->pipe_fd[0], 0); close(t->pipe_fd[1]); t->args = ft_strsplitsh(ft_strsub(line, t->pv, t->pv2 - t->pv)); if (line[t->pv2] == '|' || line[t->pv2] == '>') { if (line[t->pv2] != '|') return (ft_red(line, t)); else if (line[t->pv2 + 1] && !search_ope(&line[t->pv2 + 1], t->ope, 1)) return (exec_pipes(line, t)); else if (line[t->pv2 + 1] && line[t->pv2 + 1] != '|') return (parse_error(line, t, t->pv2 + 1)); t->flag = line[t->pv2]; } exec_cmd(t); return (t->pv2); }
int main(){ char input[100], c; int i, j, k; struct command_t cmd[100]; for(i = 0, k = 1; i < 101; i++){ scanf("%[^\n]%c", input, &c); cmd[i].code = exec_cmd(cmd, input, i); if(cmd[i].code == 0){ find_result(cmd, i); k++; } if(input[i] == '\n' && c == '\n'){ break; } } for(j = 0; j < k; j++){ if(cmd[j].code == 0 && cmd[j].result != 42) printf("%d", cmd[j].result); else if(cmd[j].code == 0 && cmd[j].result == 42) printf("the answer to life, the universe and everything else"); else if(cmd[j].code == -1) printf("operation not supported"); else if(cmd[j].code == -2) printf("invalid command argument count"); else if(cmd[j].code == -3) printf("invalid command arguments"); else if(cmd[j].code == -4) printf("invalid input"); else if(cmd[j].code == -5) printf("invalid arithmetic operation"); if(j != k-1) printf("\n"); } return 0; }
DrawToolBar::DrawToolBar(wxWindow *parent) : wxToolBar(parent,-1) { SetHelpText(_T("draw3-toolbar-items")); AddTool(drawTB_ABOUT, _T(""),help_xpm,_("About")); AddTool(drawTB_FIND, _T(""),find_xpm, _("Find")); AddTool(drawTB_SUMWIN, _T(""),plus_xpm, _("Summary Window")); AddTool(drawTB_SPLTCRS, _T(""),split_xpm, _("Split cursor"), wxITEM_CHECK); AddTool(drawTB_FILTER, _T(""),filter0_xpm, _("Filter")); AddTool(drawTB_REFRESH, _T(""),refresh_xpm, _("Refresh")); AddTool(drawTB_DRAWTREE, _T(""),draw_tree_xpm, _("Tree Set")); /** disable florence keyboard in windows builds */ #ifndef MINGW32 AddTool(drawTB_FLORENCE, _T(""), florence_xpm, _("Show screen keyboard")); #endif AddTool(drawTB_GOTOLATESTDATE, _T(""), flag_checkered_xpm, _("Go to latest date")); AddTool(drawTB_REMARK, _T(""), remark_xpm, _("Remarks")); AddTool(drawTB_EXIT, _T(""),exit_xpm, _("Quit")); if (VersionChecker::IsNewVersion()) NewDrawVersionAvailable(); else Realize(); #ifndef MINGW32 /* disable florence button if program is not present */ std::string path = exec_cmd("which florence"); path = path.substr(0, path.size()-1); if (access(path.c_str(), X_OK)) EnableTool(drawTB_FLORENCE, false); #endif VersionChecker::AddToolbar(this); }
/* ** Builtin env */ void env(char **my_env, char **cmd) { int tabsize; int nb; char **new_env; int i; tabsize = my_tab_size(cmd); if (tabsize < 2) { my_show_to_wordtab(my_env); } else { i = 1; nb = count_value(cmd); new_env = get_my_env(my_env); while (i <= nb) { new_env = exec_setenv(new_env, cmd[i]); i++; } cmd = cmd + nb + 1; if (*cmd != 0) exec_cmd(cmd, new_env); } }
int exec_env(t_struc *s, char **env2) { int i; int j; int option_i; char **new_env; i = 1; j = 1; option_i = 0; new_env = env2 ? copy_env(env2) : (char **)malloc(sizeof(char *) * 1); if (s->argc == 1) print_env(new_env); else { if (get_env_options(s, &i, &option_i) == -1) return (-1); if (option_i) new_env = (char **)malloc(sizeof(char *) * 1); s->cmd = NULL; new_env = exec_env2(s, i, j, new_env); if (s->cmd) !is_builtin(s) ? exec_cmd(s, new_env) : exec_builtin(s, new_env); else print_env(new_env); } return (0); }
int left_red(char *line, t_sh *t, int i) { int al; al = 0; i = srch_left(line, i, t); t->wf = ft_strsub(line, t->pv2 + 1, i - (t->pv2 + 1)); if ((t->fd1 = open(t->wf, O_RDONLY)) != -1) { al = ft_wh_not_ope(&line[i + 1], t) + 1; t->dupl = dup(0); dup2(t->fd1, 0); close(t->fd1); if (line[i + al] && (OPE2(line, i + al) || PIPOR(line, i + al))) return (left_red_next(i + al, t, &line)); else { exec_cmd(t); dup2(t->dupl, 0); close(t->dupl); } if (line[i + al]) t->flag = line[i + al]; return (t->pv2 = i + al); } return (0); }
int double_rightbis(char *line, t_sh *t, char *l_p, int i) { int d; int wak; d = dup(1); dup2(t->fd1, 1); while (read(t->fd1, &wak, 1) > 0) ; close(t->fd1); exec_cmd(t); dup2(d, 1); close(d); if (line[i] && (OPE2(line, i) || PIPOR(line, i))) { t->pv2 = i; if (OPE2(line, i) && have_pipe(line, i, t) == t->pv2) return (ft_red(line, t)); i = t->pv2; pre_parse(l_p, line, i, t); if (line[t->pv2] && line[t->pv2] == '>') return (ft_red(line, t)); return (t->pv2); } return (t->pv2 = i); }
int exec_cmds(t_param *param, t_cmd *cmds, t_pipeline *pipeline, int j) { int i; i = -1; while (++i < (pipeline->nb_pipe + 1)) { if (pipeline->cmd[i + 1]) pipe(pipeline->rp); cmds[i].arg = my_str_to_wordtab_light(pipeline->cmd[i], build_delimiters_tab(" ", "\t", 0)); cmds[i].error.type = NONE; cmds[i].error.fd = 2; set_cmd_io_fd(pipeline, cmds, i); open_file(&cmds[i].in); open_file(&cmds[i].out); exec_cmd(param, &cmds[i]); if (pipeline->cmd[i + 1]) close(pipeline->rp[1]); pipeline->lp[0] = pipeline->rp[0]; pipeline->lp[1] = pipeline->rp[1]; j = 1; while (cmds[i].arg[j]) xsfree(cmds[i].arg[j++]); xsfree(cmds[i].arg); } return (0); }
void read_write_client(t_client *c) { g_server = strdup(c->server); g_name = strdup("user"); while (42) { bzero(c->buf, 4096); g_servport = c->servport; printf("\n"); printf("\e[1;33m%s@%s:%d> \e[0m", g_name, g_server, g_servport); fflush(stdout); signal(SIGINT, handler_ctrl_c); c->rc = read(0, c->buf, 4096); if (c->buf[0] != '\n' && c->rc != 0 && c->buf[0] != EOF) { parser(c->buf, c); exec_cmd(c); if (c->username != NULL) g_name = strdup(c->username); c->rc = read(c->sd, c->buf, 4096); write(1, c->buf, c->rc); free_tab(c); } } }
static int make_nis (const char *ifname, const dhcp_t *dhcp) { FILE *f; address_t *address; char prefix[256] = {0}; logger (LOG_DEBUG, "writing "NISFILE); if (! (f = fopen(NISFILE, "w"))) { logger (LOG_ERR, "fopen `%s': %s", NISFILE, strerror (errno)); return -1; } fprintf (f, "# Generated by dhcpcd for interface %s\n", ifname); if (dhcp->nisdomain) { setdomainname (dhcp->nisdomain, strlen (dhcp->nisdomain)); if (dhcp->nisservers) snprintf (prefix, sizeof (prefix), "domain %s server", dhcp->nisdomain); else fprintf (f, "domain %s broadcast\n", dhcp->nisdomain); } else snprintf (prefix, sizeof (prefix), "%s", "ypserver"); for (address = dhcp->nisservers; address; address = address->next) fprintf (f, "%s %s\n", prefix, inet_ntoa (address->address)); fclose (f); exec_cmd (NISSERVICE, NISRESTARTARGS, NULL); return 0; }
static inline void get_stat(void) { cmd_t cmd = {c_get_status<<8, 0, 0, 0}; exec_cmd(cmd, 0); sat_result[0] = CDB_REG_CR1; sat_result[1] = CDB_REG_CR2; sat_result[2] = CDB_REG_CR3; sat_result[3] = CDB_REG_CR4; }
void FindExectuable(wxString corefile) { wxString cmdstr; cmdstr.Printf(wxT("%s -core \"%s\" -ex quit | grep \"Core was generated by\""), m_gdb->GetValue().c_str(), m_corefile->GetValue().c_str()); wxLogDebug(wxT("%s"), cmdstr); m_coreinfo->SetValue(exec_cmd(cmdstr.c_str())); }
static void parse_at(const char *ntype, const char *un, const char *cmd, const char *ca1, const char *ca2) { /* complain both ways in case we don't have a tty */ if (!cmdscript) { printf("CMDSCRIPT must be set before any ATs in the config file!\n"); fatalx(EXIT_FAILURE, "CMDSCRIPT must be set before any ATs in the config file!"); } if (!pipefn) { printf("PIPEFN must be set before any ATs in the config file!\n"); fatalx(EXIT_FAILURE, "PIPEFN must be set before any ATs in the config file!"); } if (!lockfn) { printf("LOCKFN must be set before any ATs in the config file!\n"); fatalx(EXIT_FAILURE, "LOCKFN must be set before any ATs in the config file!"); } /* check upsname: does this apply to us? */ if (strcmp(upsname, un) != 0) if (strcmp(un, "*") != 0) return; /* not for us, and not the wildcard */ /* see if the current notify type matches the one from the .conf */ if (strcasecmp(notify_type, ntype) != 0) return; /* if command is valid, send it to the daemon (which may start it) */ if (!strcmp(cmd, "START-TIMER")) { sendcmd("START", ca1, ca2); return; } if (!strcmp(cmd, "CANCEL-TIMER")) { sendcmd("CANCEL", ca1, ca2); return; } if (!strcmp(cmd, "EXECUTE")) { if (ca1 == '\0') { upslogx(LOG_ERR, "Empty EXECUTE command argument"); return; } if (verbose) upslogx(LOG_INFO, "Executing command: %s", ca1); exec_cmd(ca1); return; } upslogx(LOG_ERR, "Invalid command: %s", cmd); }
void exec_prompt(char * usr_name, char * host_name) { char cmd[50]; // declaring the string for command input MAX CHAR is 50. host_name = getHost(); // Stops the faulty hostname bug after echo command printf("%s::%s:%c ", usr_name, host_name, prompt); fgets(cmd, 50, stdin); // fgets() is used for standard input. strip_newline(cmd, 50); exec_cmd(cmd); exec_prompt(usr, host); }
void query_cmd() { char cmd[CMDLINE_LENGTH]; msg_cprintf(0, M_COMMAND); read_line(cmd, sizeof(cmd)); alltrim(cmd); if(cmd[0]!='\0') exec_cmd(cmd); }
static void restore_resolv(const char *ifname) { struct stat buf; if (stat (RESOLVCONF, &buf) < 0) return; logger (LOG_DEBUG, "removing information from resolvconf"); exec_cmd (RESOLVCONF, "-d", ifname, NULL); }