static void configure_ok_cb() { char *cmd, *cmd_after, *cmd_end, *cmd_ttc; cmd = g_strdup(config.cmd); cmd_after = g_strdup(config.cmd_after); cmd_end = g_strdup(config.cmd_end); cmd_ttc = g_strdup(config.cmd_ttc); if (check_command(cmd) < 0 || check_command(cmd_after) < 0 || check_command(cmd_end) < 0 || check_command(cmd_ttc) < 0) { gtk_widget_show(cmd_warn_img); gtk_widget_show(cmd_warn_label); } else { gtk_widget_hide(cmd_warn_img); gtk_widget_hide(cmd_warn_label); save_and_close(cmd, cmd_after, cmd_end, cmd_ttc); } g_free(cmd); g_free(cmd_after); g_free(cmd_end); g_free(cmd_ttc); }
void parseInput() { while (!feof(stdin)) { if (fgets(command_line,MAX_LINE_SIZE + 2,stdin) == NULL) break; if (strlen(command_line) > MAX_LINE_SIZE) { printf("Command too long, can not parse\n"); goto_next_line(stdin); } else { missing_argc = 0; sprintf(command_name,""); argc = sscanf(command_line,"%s %d,%d,%d",command_name,&(intv[0]),&(intv[1]),&(intv[2])); if (check_command(COMMAND_GET_POINTS,2)) getPoints(intv[0]); else if (check_command(COMMAND_NEW_MEMBER,3)) newMember(intv[0],intv[1]); else if (check_command(COMMAND_NEW_INVITED_MEMBER,4)) newInvitedMember(intv[0],intv[1],intv[2]); else if (check_command(COMMAND_FORBID_MEMBERSHIP,3)) forbidMembership(intv[0],intv[1]); else if (check_command(COMMAND_GET_TLC_PERSON,2)) getTlcPerson(intv[0]); else if (check_command(COMMAND_GET_FRIENDLIEST_PEOPLE,2)) getFriendliestPeople(intv[0]); else if (check_command(COMMAND_GET_MEMBERS_ADDRESSES,2)) getMembersAddresses(intv[0]); else if (check_command(COMMAND_PYRAMID_BONUS,2)) pyramidBonus(intv[0],intv[1]); else if (check_command(COMMAND_EXIT,1)) break; else if (missing_argc > 0) printf("Missing %d argument(s) in command %s!\n",missing_argc,command_name); else if (argc > 0) printf("Illegal command!\n"); } } }
static void configure_ok_cb(GtkWidget *w, gpointer data) { char *cmd, *cmd_after, *cmd_end; cmd = gtk_entry_get_text(GTK_ENTRY(cmd_entry)); cmd_after = gtk_entry_get_text(GTK_ENTRY(cmd_after_entry)); cmd_end = gtk_entry_get_text(GTK_ENTRY(cmd_end_entry)); if (check_command(cmd) < 0 || check_command(cmd_after) < 0 || check_command(cmd_end) < 0) warn_user(); else save_and_close(NULL, NULL); }
WmcResult * wmc_cmd_init_result (const char *buf, size_t buflen, int wmc2) { wmc_return_val_if_fail (buf != NULL, NULL); if (wmc2) { if (check_command (buf, buflen, WMC_CMD_INIT, sizeof (WmcCmdInit2Rsp)) < 0) return NULL; } else { if (check_command (buf, buflen, WMC_CMD_INIT, sizeof (WmcCmdHeader)) < 0) return NULL; } return wmc_result_new (); }
static int ft_get_fd(fd_set *fd_read, int sock) { char *line; char *line2; line = NULL; if (sock != -1) { FD_ZERO(fd_read); FD_SET(sock, fd_read); FD_SET(0, fd_read); select(sock + 1, fd_read, NULL, NULL, NULL); if (FD_ISSET(sock, fd_read)) if (ft_send_fd(sock) == -1) return (-1); if (FD_ISSET(0, fd_read)) { if (ft_get_next_line(0, &line) > 0 && check_command(line, &sock)) { line2 = ft_strjoin(line, "\n"); ft_putstr_fd(line2, sock); ft_strdel(&line); ft_strdel(&line2); } } } return (1); }
int command( const cmdinfo_t *ct, int argc, char **argv) { char *cmd = argv[0]; if (!check_command(ct)) return 0; if (argc-1 < ct->argmin || (ct->argmax != -1 && argc-1 > ct->argmax)) { if (ct->argmax == -1) fprintf(stderr, _("bad argument count %d to %s, expected at least %d arguments\n"), argc-1, cmd, ct->argmin); else if (ct->argmin == ct->argmax) fprintf(stderr, _("bad argument count %d to %s, expected %d arguments\n"), argc-1, cmd, ct->argmin); else fprintf(stderr, _("bad argument count %d to %s, expected between %d and %d arguments\n"), argc-1, cmd, ct->argmin, ct->argmax); return 0; } platform_getoptreset(); return ct->cfunc(argc, argv); }
int deal_with_command(t_lst *node, char **arg) { char **path; char *right_path; char **env; env = get_env(node); path = (char **)malloc(sizeof(char *) * 7); if (!path) return (-1); path = split_path(node); if (path && *arg && env) { right_path = check_path(path, *arg); if (right_path) { exec_right_path(node, arg, env, right_path); return (-1); } } if (*arg && env) { right_path = ""; check_command(node, arg, right_path, env); ft_strdel(arg); } return (-1); }
void Program_Options::check_options() { bool loop = true; int verify = main_options(); if(verify != 0) { while(loop) { if (command == "help") { for (auto c : *command_container) { if ( subcommand == c.first) { cout << get_help(c.first, c.second).str(); loop = false; } } if(loop){ cout << get_main_help() << endl ; loop = false; } } else if (check_command() == true && loop == true) { loop = false; } if(loop){ cout << get_main_help() << endl ; loop = false; } } } }
int cd_built(char **command, t_shell *shell) { int i; char dir[128]; i = 0; if (command[1] && command[0]) ft_putendl("cd: Too many arguments."); else { if (*command && !ft_strcmp(*command, "-")) replace(command, shell); if (*command && !check_command(*command)) return (-1); modify_pwd(*command, shell); while (shell->char_env[i]) { if (!ft_strncmp(shell->char_env[i], "PWD", 3)) { free(shell->char_env[i]); shell->char_env[i] = ft_strjoin("PWD=", getcwd(dir, 128)); break ; } i++; } } return (1); }
int main() { check_mem(); check_reg(); check_command(); return 0; }
char *levenshtein(char *str, UNUSED char **env) { char **dic; char **command; int i; int pos; i = 0; pos = 0; command = cut_command(str); if ((dic = gen_data(save_my_env(NULL))) == NULL) return (str); while (command && command[i] != NULL) { if (i == 0 || is_separator_ext(command[i - 1][0]) == 0) { if (check_command(command[i], save_my_env(NULL)) == -1) { pos = where_is_space(command[i]); command[i] = change_command(command[i], leven(dic, po_s(command[i], pos))); } } i++; } free_array_char(dic); return (tab_string(command)); }
/********************************************************************* * Function: void APP_DeviceCustomHIDTasks(void); * * Overview: Keeps the Custom HID demo running. * * PreCondition: The demo should have been initialized and started via * the APP_DeviceCustomHIDInitialize() and APP_DeviceCustomHIDStart() demos * respectively. * * Input: None * * Output: None * ********************************************************************/ void APP_DeviceCustomHIDTasks() { //Check if we have received an OUT data packet from the host if(HIDRxHandleBusy(USBOutHandle) == false) { //We just received a packet of data from the USB host. //Check the first uint8_t of the packet to see what command the host //application software wants us to fulfill. if (ReceivedDataBuffer[0] == COMMAND_TOGGLE_LED) //Look at the data the host sent, to see what kind of application specific command it sent. { //Toggle LEDs command LED_Toggle(LED_GREEN); } else { if (!check_command()) { // strcpypgm2ram((char *) ToSendDataBuffer, (farchar *) "null"); *ToSendDataBuffer = 0xFF; } if (!HIDTxHandleBusy(USBInHandle)) { USBInHandle = HIDTxPacket(CUSTOM_DEVICE_HID_EP, (uint8_t*) & ToSendDataBuffer[0], 64); } } //Re-arm the OUT endpoint, so we can receive the next OUT data packet //that the host may try to send us. USBOutHandle = HIDRxPacket(CUSTOM_DEVICE_HID_EP, (uint8_t*)&ReceivedDataBuffer, 64); } }
void check_command(SymTab *st, Command* c) { if(!c) return; switch(c->tag) { case COMMAND_IF: { check_exp(st, c->u.cif.exp); check_type_int(c->u.cif.exp); check_command(st, c->u.cif.comm); check_command(st, c->u.cif.celse); break; } case COMMAND_WHILE: { check_exp(st, c->u.cwhile.exp); check_type_int(c->u.cwhile.exp); check_command(st, c->u.cwhile.comm); break; } case COMMAND_ATTR: { check_var(st, c->u.attr.lvalue); check_exp(st, c->u.attr.rvalue); check_type_compatible(c->u.attr.lvalue->type, &(c->u.attr.rvalue), c->line); break; } case COMMAND_RET: { if(c->u.ret) { check_exp(st, c->u.ret); check_type_compatible(return_type, &(c->u.ret), c->line); } break; } case COMMAND_FUNCALL: { check_exp(st, c->u.funcall); break; } case COMMAND_BLOCK: { check_block(st, c->u.block); break; } } }
int check_and_run(char* input) { char** cmd; if(!check_command(input)) { cmd = parse_command(input); exec_command(cmd); } return 0; }
static int exFAT_boot_sector_command(char **current_cmd, const char *options) { skip_comma_in_command(current_cmd); if(check_command(current_cmd,"dump",4)==0) { return 'D'; } else if(check_command(current_cmd,"originalexFAT",13)==0) { if(strchr(options,'O')!=NULL) return 'O'; } else if(check_command(current_cmd,"backupexFAT",11)==0) { if(strchr(options,'B')!=NULL) return 'B'; } return 0; }
bool parse_message(t_parser *parser, char *message) { if (message == NULL) return (false); if (check_prefixe(parser, message) == true && check_command(parser, message) == true && check_params(parser, message) == true && check_crlf(parser, message) == true) return (true); return (false); }
int interpret_command(char *cmd_buffer) { int i; for(i = 0; i < cmds_len; ++i) { if(check_command(&cmds[i], cmd_buffer)) return 1; } return 0; }
void execute_job(job_t* job) { /*Check commandline for built-in commands*/ if (check_command(job, "cd")) { //change directory - alter current directory and remove completed job chdir(job->first_process->argv[1]); remove_job(job); } else if (check_command(job, "jobs")) { //display current jobs and their statuses (stati?) remove_job(job); builtin_jobs(); } else if (check_command(job, "bg")) { //resume background job with specified number resume_background_job(atoi(job->first_process->argv[1])); //atoi interprets string as integer value remove_job(job); } else if (check_command(job, "fg")) { //continue foreground job with specified number resume_foreground_job(atoi(job->first_process->argv[1])); remove_job(job); } else { //Default case, not built in command - spawn the new job spawn_job(job, !job->bg); } }
void parse_line(t_parser *parser, int indent_level, char *line, int line_number) { char **splited; line = line + indent_level; splited = ft_strsplit(line, ':'); if (*splited) { check_command(indent_level, parser, splited, line_number); free(splited); } }
t_bool my_select(t_lexem *node, t_shell *shell) { unsigned int idx; if (!(node->av = wtab(node->str))) return (FALSE); idx = 0; while ((idx < BUILT_SIZE) && (strcmp(node->av[0], g_built[idx].str) != MATCH)) ++idx; if (idx < BUILT_SIZE) return (g_built[idx].fct(node, shell)); return (check_command(node, shell)); }
long shell_cmd::execute(const string cmd, int &exit_status) { // Check if command exists bool cmd_found; long rc = check_command(cmd, cmd_found); if (rc != SHELL_CMD_SUCCESS) { return rc; } if (!cmd_found) { return SHELL_CMD_NOT_FOUND; } return execute_shell_cmd(cmd, exit_status); }
WmcResult * wmc_cmd_get_global_mode_result (const char *buf, size_t buflen) { WmcResult *r = NULL; WmcCmdGetGlobalModeRsp *rsp = (WmcCmdGetGlobalModeRsp *) buf; wmc_return_val_if_fail (buf != NULL, NULL); if (check_command (buf, buflen, WMC_CMD_GET_GLOBAL_MODE, sizeof (WmcCmdGetGlobalModeRsp)) < 0) return NULL; r = wmc_result_new (); wmc_result_add_u8 (r, WMC_CMD_GET_GLOBAL_MODE_ITEM_MODE, rsp->mode); return r; }
/* Set up fd for output redirection */ void output_red(char** cmd){ if( is_iored(cmd)){ int k = 0; while( cmd[k] != NULL ) k++; // k->cmd.end(). find end of cmd. char filename[strlen(cmd[k-1])]; if( strcpy( filename, cmd[k-1]) == NULL){ printf("strcpy filename failed!\n"); exit(1); } char path[256]; strcpy( path, getenv("PWD") ); strcat( path, "/" ); strcat( path, filename ); // make char[] path int fd = open( path, O_RDWR|O_CREAT|O_TRUNC); pid_t fpid = fork(); if (fpid < 0){ perror("io fork failed!\n"); exit(1); } if( fpid == 0 ){ // child close(STDOUT_FILENO); dup(fd); close(fd); int end=0; while( cmd[end]!=NULL ) end++; cmd[end-2] = cmd[end]; // remove "> file" in end of cmd! Otherwise as argu in ls! and shown in file! check_command(cmd); _exit(0); //better not use exit(). buffer issue. look it up. } else{ close(fd); waitpid(fpid, NULL, 0); } } else printf("Undefined output_red cmd format!\n"); //if wrong io format }
void obstacle_dodge() { while (!check_command(RETURNTOMAIN)) { if(!Object(front2, DISTANCE_WALL)) Motors_Forward(PWM, PWM); else while (Object(front1, DISTANCE_WALL) || Object(front2, DISTANCE_WALL) || Object(front3, DISTANCE_WALL)) { if (milliseconds % 2 == 0) Rotate_Left(20); else Rotate_Right(20); } } Motors_Stop(); }
void follow() { while (!check_command(RETURNTOMAIN)) { while(!Object(front2, DISTANCE_WALL)) Motors_Forward(PWM, PWM); while (Object(front2, DISTANCE_WALL)) Motors_Stop(); delay_ms(250); if (Object(front1, DISTANCE_WALL)) while (!Object(front2, DISTANCE_WALL)) Motors_Left(PWM, PWM); else if (Object(front3, DISTANCE_WALL)) while (!Object(front2, DISTANCE_WALL)) Motors_Right(PWM, PWM); } Motors_Stop(); }
long shell_cmd::execute(const string cmd, string &output) { long rc; string the_cmd; FILE *pipe; char buf[MAX_CHARS_PER_LINE]; output.clear(); // Check if command exists bool cmd_found; rc = check_command(cmd, cmd_found); if (rc != SHELL_CMD_SUCCESS) { return rc; } if (!cmd_found) { return SHELL_CMD_NOT_FOUND; } // Redirect stderr to stdout the_cmd = cmd; the_cmd.append(" 2>&1"); // Open pipe, invoke command pipe = popen(cmd.c_str(), "r"); if (!pipe) { return SHELL_CMD_FORK_FAILED; } // Read command standard output while (!feof(pipe)) { if (fgets(buf, MAX_CHARS_PER_LINE, pipe) != NULL) { output.append(buf); } } // Close pipe if (pclose(pipe) == -1) { return SHELL_CMD_WAIT_FAILED; } return SHELL_CMD_SUCCESS; }
int read_cmd(t_client *client) { char buffer[BUFFER_SIZE]; memset(buffer, 0, BUFFER_SIZE); fgets(buffer, 512, stdin); clean_buffer(buffer); if (!strlen(buffer)) { return (-1); } else if (strlen(buffer) > 0 && (client->tab = my_str_to_wordtab(buffer))) { client->buffer_in = buffer; check_command(client, client->tab); free_wordtab(&(client->tab)); } return (0); }
int main(void) { Timer_Init(); //Initialize timers Ultrasonic_Init(); //Initialize sensors LED_Init(); //Initialize LEDs UART_Init(); //Initialize UART Motors_Init(); //Initialize motors sei(); //Enable interrupts while(1) //Main loop { state = 1; if (check_command(REMOTECONTROLMODE)) { state = 0; manual(); } else if (check_command(LATERALPARKINGMODE)) { state = 0; lateral_parking(); } else if (check_command(MAINPARKINGMODE)) { state = 0; random_parking(); } else if (check_command(FIXEDPARKINGMODE)) { state = 0; fixed_parking(); } else if (check_command(OBSTACLEDODGEMODE)) { state = 0; obstacle_dodge(); } else if (check_command(FOLLOWMODE)) { state = 0; follow(); }/* else if (confirm_input(DANCE)) { state = 4; dance(); }*/ } }
void do_the_thing(t_shell *sh, char ***cmd, int flag) { int ret_check; int ret_exclam; if (flag) { *cmd = insert_str_in_tab(*cmd, "\"", 0, 0); *cmd = insert_str_in_tab(*cmd, "\"", tab_len(*cmd), 0); } if (!(ret_check = check_command(*cmd)) && (ret_exclam = replace_exclam_dot(cmd, sh)) == 1 && !man_couver(*cmd, sh)) { backquote(cmd, sh); the_execution(*cmd, sh); del_quote(*cmd); } else if (ret_check || !ret_exclam) sh->ret = 1; }
int main(int argc, char** argv, char** env) { int status; /* sanity check arguments */ if (argc < 2) fatal(logident, MAIL_USAGE_ERROR, "Usage: %s program [args...]", argv[0]); if (!check_command(argv[1])) fatal(logident, MAIL_ILLEGAL_COMMAND, "Illegal command: %s", argv[1]); check_caller(logident, parentgroup); /* If we got here, everything must be OK */ status = run_script(argv[1], argc, argv, env); fatal(logident, status, "%s", strerror(errno)); return status; }