/* Read the user's supplied command line options. */ static int read_option_args (int argc, char **argv) { int o, idx = 0; while ((o = getopt_long (argc, argv, short_options, long_opts, &idx)) >= 0) { if (-1 == o || EOF == o) break; switch (o) { case 'p': ws_set_config_port (optarg); break; case 'h': cmd_help (); return 1; case 'V': fprintf (stdout, "GWSocket %s\n", GW_VERSION); return 1; case 0: parse_long_opt (long_opts[idx].name, optarg); break; case '?': return 1; default: return 1; } } for (idx = optind; idx < argc; idx++) cmd_help (); return 0; }
static void parse_cmd_line (int argc, char **argv) { read_option_args (argc, argv); if (!isatty (STDOUT_FILENO) || conf.output_format != NULL) conf.output_html = 1; if (conf.ifile != NULL && !isatty (STDIN_FILENO) && !conf.output_html) cmd_help (); if (conf.ifile == NULL && isatty (STDIN_FILENO) && conf.output_format == NULL) cmd_help (); }
int cmd_list(int argc, char *argv[]) { storage_t storage; const char *elem; if (argc != 2) { int help_argc = 2; char *help_argv[] = { "help_err", "list", NULL }; return cmd_help(help_argc, help_argv); } if ((storage = storage_new(argv[1], 0)) == NULL) errx(EXIT_FAILURE, "unable to open storage: %s", argv[1]); elem = storage_list(storage, "backups"); while (elem != NULL) { printf("%s\n", elem); elem = storage_list(storage, NULL); } storage_delete(storage); return EXIT_SUCCESS; }
static void handle_command(char *cmd) { char *argv[MAX_ARGC]; int argc = 1; char *temp, *rover; memset((void*) argv, 0, sizeof(argv)); argv[0] = cmd; rover = cmd; // Split string "<command> <argument 1> <argument 2> ... <argument N>" // into argv, argc style while(argc < MAX_ARGC && (temp = strstr(rover, ":"))) { rover = &(temp[1]); argv[argc++] = rover; *temp = 0; } if (strlen(argv[0]) > 0) { if (strcmp(argv[0], "help") == 0) cmd_help(argc, argv); else if (strcmp(argv[0], "motion") == 0) cmd_motion(argc, argv); else if (strcmp(argv[0], "size") == 0) cmd_set_size(argc, argv); else if (strcmp(argv[0], "capture") == 0) cmd_capture(argc, argv); else if (strcmp(argv[0], "upload") == 0) cmd_capture_upload(argc, argv); else if (strcmp(argv[0], "on") == 0) cmd_on(argc, argv); else if (strcmp(argv[0], "off") == 0) cmd_off(argc, argv); else printf("Unknown command %s, try 'help'\n", argv[0]); } }
/** * @brief shell_func * @param[in] void * @param[in,out] void * @return void */ void shell_func (void) { cursor_blink(); while(1) { PRINT("\r\nBOS# "); UART0_AsyncReceive(64, g_rx_buffer, &rx_complete); BOS_WaitEvent(EVT_UART_RECEIVE); BOS_ClearEvent(EVT_UART_RECEIVE); if(check_cmd((char *)g_rx_buffer, "help")) { cmd_help(); } else if(check_cmd((char *)g_rx_buffer, "info")) { cmd_info(); } else if(check_cmd((char *)g_rx_buffer, "ps")) { cmd_ps(); } else if(check_cmd((char *)g_rx_buffer, "mbx")) { cmd_mbx(); } else { PRINT("\r\nCommand not found, type help for more details\r\n"); } } }
void handle_cli_commands(const std::string& line) { SWSS_LOG_ENTER(); SWSS_LOG_NOTICE("cli: %s", line.c_str()); // TODO this must be more smart, to split multiple spaces auto tokens = swss::tokenize(trim(line), ' '); if (tokens.size() < 1) { return; } const std::string& cmd = tokens[0]; if (cmd == "exit" || cmd == "quit") { cmd_exit(); } else if (cmd == "loglevel") { cmd_loglevel(tokens); } else if (cmd == "help") { cmd_help(tokens); } else { sendtoclient("unknown command: " + line + "\n"); } }
static gboolean parse_params (int *argcp, char ***argvp, GError **err) { GOptionContext *context; GOptionGroup *group; gboolean rv; context = g_option_context_new("- mu general options"); g_option_context_set_help_enabled (context, TRUE); err = NULL; rv = TRUE; g_option_context_set_main_group(context, config_options_group_mu()); switch (MU_CONFIG.cmd) { case MU_CONFIG_CMD_NONE: show_usage(); break; case MU_CONFIG_CMD_HELP: /* 'help' is special; sucks in the options of the * command after it */ rv = g_option_context_parse (context, argcp, argvp, err) && cmd_help (); break; default: group = get_option_group (MU_CONFIG.cmd); if (group) g_option_context_add_group(context, group); rv = g_option_context_parse (context, argcp, argvp, err); } g_option_context_free (context); return rv ? TRUE : FALSE; }
void verify_global_config (int argc, char **argv) { int o, idx = 0; conf.load_global_config = 1; while ((o = getopt_long (argc, argv, short_options, long_opts, &idx)) >= 0) { if (-1 == o || EOF == o) break; switch (o) { case 'p': conf.iconfigfile = optarg; break; case 0: if (!strcmp ("no-global-config", long_opts[idx].name)) conf.load_global_config = 0; break; case '?': exit (EXIT_FAILURE); } } for (idx = optind; idx < argc; idx++) cmd_help (); /* reset it to 1 */ optind = 1; }
/* * handle_command * * Handle the full argv list of a first level command. Will find the command * in the global commands array and call the function callback associated. * * If command not found, return -1 * else, return function command error code. */ static int handle_command(int argc, char **argv) { int i = 0, ret; struct cmd_struct *cmd; if (*argv == NULL) { ret = CMD_SUCCESS; goto end; } /* Special case for help command which needs the commands array */ if (strcmp(argv[0], "help") == 0) { ret = cmd_help(argc, (const char**) argv, commands); goto end; } cmd = &commands[i]; while (cmd->name != NULL) { /* Find command */ if (strcmp(argv[0], cmd->name) == 0) { ret = cmd->func(argc, (const char**) argv); goto end; } i++; cmd = &commands[i]; } /* Command not found */ ret = CMD_UNDEFINED; end: return ret; }
void debug_cmd_loop(struct ldb_context *lctx) { int cmd_ret; struct lua_program *lp = lctx->lprog; if (!lp) { printf("lprog is NULL\n"); return; } while(!lctx->bquit) { char *readbuff = readline("(ldb test.lua)"); int len = strlen(readbuff); if (len == 0) { continue; } char *cmdbuffer = readbuff; char *token = strsep(&cmdbuffer, " "); if (token == NULL) { token = cmdbuffer; } add2cmd_history(lctx->cmd_history, token, len); cmd_handler fn = _get_cmd_handler(token); if(fn) { cmd_ret = fn(lctx, cmdbuffer); } else { printf("\"%s\" unknown command\n", readbuff); cmd_help(lctx, NULL); } if(cmd_ret == CMD_QUIT) { break; } printf("\n"); } }
void command_loop(struct ldb_context *lctx) { int cmd_handler_ret; //struct lua_program *lp; while(!lctx->bquit) { char *readbuff = readline(lctx->prompt); int len = strlen(readbuff); if (len == 0) { continue; } char *cmdbuffer = readbuff; char *token = strsep(&cmdbuffer, " "); if (token == NULL) { token = cmdbuffer; } add2cmd_history(lctx->cmd_history, token, len); cmd_handler fn = _get_cmd_handler(token); if (fn) { cmd_handler_ret = fn(lctx, cmdbuffer); } else { printf("\"%s\" unknown command\n", readbuff); cmd_help(lctx, NULL); } printf("\n"); if(cmd_handler_ret == CMD_QUIT) { break; } } ldb_uninit(lctx); }
static void parse_cmd_line (int argc, char **argv) { read_option_args (argc, argv); /* Not outputting to a terminal */ if (!isatty (STDOUT_FILENO) || conf.output_format != NULL) conf.output_html = 1; /* Log piped, and a file is in used */ if (conf.ifile != NULL && !isatty (STDIN_FILENO) && !conf.output_html) cmd_help (); /* No data piped and no file was used */ if (conf.ifile == NULL && isatty (STDIN_FILENO) && conf.output_format == NULL) cmd_help (); set_default_static_files (); }
static void parse_cmd_line (int argc, char **argv) { read_option_args (argc, argv); /* Not outputting to a terminal */ if (!isatty (STDOUT_FILENO) || conf.output_format != NULL) conf.output_html = 1; /* Log piped, and log file passed */ if (conf.ifile && !isatty (STDIN_FILENO) && !conf.output_html) cmd_help (); /* No data piped, no file was used and not loading from disk */ if (!conf.ifile && isatty (STDIN_FILENO) && !conf.load_from_disk) cmd_help (); set_default_static_files (); }
static int red_cmd(char *cmd) { char *arg = cmd+1; SKIPSPACES(arg); switch(*cmd) { case 'q': return 0; case ';': case '#': break; // comment case '>': return cmd_dump(arg); break; case '<': return cmd_load(arg); break; case '.': return red_interpret(arg); break; case 's': return cmd_seek(arg); break; case 'b': return cmd_bsize(arg); break; case '/': return cmd_search(arg); break; case 'd': return cmd_system ("echo X | ired -n $BLOCK | rasm2 -o $OFFSET -D - |head -n $(($LINES-1))"); case 'p': return cmd_print(arg); break; case 'r': return cmd_resize(arg); break; case 'x': return cmd_hexdump(arg); break; case 'X': return cmd_bytedump(arg); break; case 'w': return cmd_write(arg); break; case '!': return cmd_system(arg); break; case 'V': return cmd_system("vired $FILE"); break; case '?': return cmd_help(arg); break; default: fprintf(stderr, "? %s\n", cmd); } return 1; }
void parse_cmd_enc( const int argc, char * argv[]) { int argvIndex; char tmpcmd[80]; struct ap_Option *pOption; if(argc<2) { cmd_help(); exit(1); } argvIndex =1; while(1) { pOption = g_cmd_enc_opts; strcpy(tmpcmd,argv[argvIndex]); //strupr(tmpcmd); while(pOption->name!=NULL ) { if(0==strcmp(tmpcmd,pOption->name)) break; else pOption++; } if(!pOption->name) { printf("error param input %s\n",argv[argvIndex]); exit(1); } if(argvIndex == argc) { printf("miss param value\n"); exit(1); } switch(pOption->OPTYPE) { case OPT_INT: *(int *)(pOption->param) = strtol(argv[argvIndex+1],NULL,0); argvIndex +=2; break; case OPT_STRING: strcpy((char *)pOption->param,argv[argvIndex+1]); argvIndex +=2; break; default: printf("Error option type %d \n",pOption->OPTYPE); exit(1); break; } if(argvIndex== argc) break; } }
// 运行客户端 void run(char* ip, char* pt) { int sockfd = connectToHost(ip, pt); if (getReplyCode(sockfd) != SERVICE_READY) errorReport("Service Connect Error!"); while (userLogin(sockfd) != 0) // 调用登录函数userLogin printf("Please try again.\n"); int isQuit = 0; char buf[BUF_SIZE]; while (!isQuit) { printf("[Client command] "); fgets(buf, sizeof(buf), stdin); switch (cmdToNum(buf)) { case GET: cmd_get(sockfd, buf); break; case PUT: cmd_put(sockfd, buf); break; case PWD: cmd_pwd(sockfd); break; case DIR: cmd_dir(sockfd); break; case CD: cmd_cd(sockfd, buf); break; case HELP: cmd_help(); break; case QUIT: cmd_quit(sockfd); isQuit = 1; break; default: cmd_help(); break; } } close(sockfd); }
static gboolean init_cmd_help (GError **err) { MuConfigCmd cmd; GOptionContext *ctx; GOptionGroup *group; char *cleanhelp; if (!MU_CONFIG.params || !MU_CONFIG.params[0] || !MU_CONFIG.params[1] || MU_CONFIG.params[2]) goto errexit; cmd = cmd_from_string (MU_CONFIG.params[1]); if (cmd == MU_CONFIG_CMD_UNKNOWN) goto errexit; ctx = g_option_context_new (""); g_option_context_set_main_group (ctx, config_options_group_mu()); group = get_option_group (cmd); if (group) g_option_context_add_group (ctx, group); g_option_context_set_description (ctx, cmd_help (cmd, TRUE)); cleanhelp = massage_help (g_option_context_get_help (ctx, TRUE, group)); g_print ("Usage:\n\t%s\n%s", cmd_help (cmd, FALSE), cleanhelp); g_free (cleanhelp); return TRUE; errexit: mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS, "usage: mu help <command>"); return FALSE; }
int cmd_restore(int argc, char *argv[]) { storage_t storage; FILE *backup; char *backup_name; char *download_path; char buf[4096]; if (!(argc == 3 || (argc == 2 && options['i']))) { int help_argc = 2; char *help_argv[] = { "help_err", "restore", NULL }; return cmd_help(help_argc, help_argv); } if ((storage = storage_new(argv[1], 0)) == NULL) errx(EXIT_FAILURE, "unable to open storage: %s", argv[1]); if (argc == 3) { backup_name = estrdup(argv[2]); } else { printf("Available backups:\n"); if (cmd_list(argc, argv) == EXIT_FAILURE) return EXIT_FAILURE; backup_name = readline("Enter the backup name to restore: "); /* Cleanly exit if the user did not enter any backup to restore. */ if (backup_name == NULL || strlen(backup_name) == 0) return EXIT_SUCCESS; } download_path = path_concat("backups", backup_name); free(backup_name); if ((backup = storage_retrieve_file(storage, download_path)) == NULL) errx(EXIT_FAILURE, "unable to retrieve the backup description file"); free(download_path); while (fgets(buf, 4096, backup) != NULL) unhash_dispatch(storage, "", buf); if (ferror(backup)) errx(EXIT_FAILURE, "unable to restore the backup"); fclose(backup); storage_delete(storage); return EXIT_SUCCESS; }
static gboolean parse_params (int *argcp, char ***argvp, GError **err) { GOptionContext *context; GOptionGroup *group; gboolean rv; context = g_option_context_new("- mu general options"); g_option_context_set_help_enabled (context, TRUE); rv = TRUE; g_option_context_set_main_group(context, config_options_group_mu()); g_option_context_set_ignore_unknown_options (context, FALSE); switch (MU_CONFIG.cmd) { case MU_CONFIG_CMD_NONE: show_usage(); break; case MU_CONFIG_CMD_HELP: /* 'help' is special; sucks in the options of the * command after it */ rv = g_option_context_parse (context, argcp, argvp, err) && cmd_help (); break; case MU_CONFIG_CMD_SCRIPT: /* all unknown commands are passed to 'script' */ g_option_context_set_ignore_unknown_options (context, TRUE); group = get_option_group (MU_CONFIG.cmd); g_option_context_add_group (context, group); rv = g_option_context_parse (context, argcp, argvp, err); MU_CONFIG.script = g_strdup (MU_CONFIG.cmdstr); /* argvp contains the script parameters */ MU_CONFIG.script_params = (const char**)&((*argvp)[1]); break; default: group = get_option_group (MU_CONFIG.cmd); if (group) g_option_context_add_group (context, group); rv = g_option_context_parse (context, argcp, argvp, err); break; } g_option_context_free (context); return rv ? TRUE : FALSE; }
static void prompt_read_cb(int fd, uint32_t events, void *user_data) { ssize_t read; size_t len = 0; char *line = NULL; char *cmd = NULL, *args; struct server *server = user_data; int i; if (events & (EPOLLRDHUP | EPOLLHUP | EPOLLERR)) { mainloop_quit(); return; } read = getline(&line, &len, stdin); if (read < 0) return; if (read <= 1) { cmd_help(server, NULL); print_prompt(); return; } line[read-1] = '\0'; args = line; while ((cmd = strsep(&args, " \t"))) if (*cmd != '\0') break; if (!cmd) goto failed; for (i = 0; command[i].cmd; i++) { if (strcmp(command[i].cmd, cmd) == 0) break; } if (command[i].cmd) command[i].func(server, args); else fprintf(stderr, "Unknown command: %s\n", line); failed: print_prompt(); free(line); }
void cmd_process( const char* cmd ) { switch( cmd[0] ) { case WELCOME: cmd_welcome(); break; case 'b': cmd_reboot(); break; case 'e': cmd_eeprom(cmd); break; case 'i': cmd_current(); break; case 'l': cmd_line_voltage(); break; case 'm': cmd_stack_memory(); break; case 'p': cmd_power(cmd); break; case 'q': cmd_capacity(); break; case 'r': cmd_reset(); break; case 't': cmd_temperatur(); break; case 'u': cmd_voltage(); break; case 'x': eMode = eTwike; plc_force_busy(0); break; case '?': cmd_help(); break; default: strcpy_P(cmd_line, PSTR("<Unknown command, try ? for help.")); } cmd_flush(); }
/* encoder - decoder cbr or cq ppinloop rebuild.yuv size.txt ssim.txt */ void run_codec_test(char argc, char** argv) { CX264Encoder e; set_default_cmd(); parse_cmd_enc( argc, argv); if(1==verfy_cmd()) { cmd_help(); } init_encoder( &e ); encoder( &e, &gCmd); }
int main(int argc, char *argv[]){ int i; if(strcmp("help", argv[1]) == 0){ cmd_help(argc, argv); return 0; } mdio_open_local(&g_mdio_bus); for(i = 0; i < sizeof(g_cmd_table)/sizeof(g_cmd_table[0])-1; ++i){ if(strcmp(g_cmd_table[i].cmd, argv[1]) == 0){ return g_cmd_table[i].func(argc, argv); } } mdio_close(); return 1; }
void exec_command(char cmd, char *param) { switch(cmd){ case'Q':cmd_quit(); break; case'C':cmd_check(); break; case'P':cmd_print(atoi(param)); break; case'R':cmd_read(param); break; case'W':cmd_write(param); break; case'F':cmd_find(param); break; case'S':cmd_sort(atoi(param)); break; case'E':cmd_edit(); break; case'H':cmd_help(); break; default:fprintf(stderr,"error\n\n"); } printf(":"); }
void reader_loop(void) { int old = in_reader_loop; in_reader_loop = 1; if (!opdb_get_boolean("quiet")) { printc("\n"); cmd_help(NULL); printc("\n"); } do { want_exit = 0; for (;;) { char *buf = readline("(mspdebug) "); char tmpbuf[MAX_READER_LINE]; if (!buf) { printc("\n"); break; } /* Copy into our local buffer and free */ strncpy(tmpbuf, buf, sizeof(tmpbuf)); tmpbuf[sizeof(tmpbuf) - 1] = 0; free(buf); buf = tmpbuf; if (*buf) { add_history(buf); repeat_buf[0] = 0; } else { memcpy(tmpbuf, repeat_buf, sizeof(tmpbuf)); } do_command(buf, 1); if (want_exit) break; } } while (prompt_abort(MODIFY_SYMS)); in_reader_loop = old; }
void cmd_exec(const char *buf) { char cmdbuf[CMDBUF_SIZE]; char *argp[CMDARG_MAX]; struct cmd *cmd; char *p; char *q; int i, argc, sep; strncpy(cmdbuf, buf, CMDBUF_SIZE); printf("%s\n", cmdbuf); /* find command */ for (cmd = cmdtab; cmd->name; cmd++) { for (q = cmdbuf, p = cmd->name; *p; p++, q++) { if (*p != *q) break; } if (*p == 0 && (*q == '\0' || *q == ' ')) goto found; } printf("***ERROR*** %s\n", cmdbuf); cmd_help(0, 0, 0); return; found: /* setup argument */ p = cmdbuf; argc = 0; argp[argc++] = p; sep = 0; for (i = 0; (i < CMDBUF_SIZE) && (argc < CMDARG_MAX); i++, p++) { if (*p == ' ') { *p = 0; sep = 1; } else if (sep && (*p != ' ' || *p == '\0')) { sep = 0; argp[argc++] = p; } } *--p = 0; cmd->func (argc, argp, 1); }
int main(int argc, char *argv[]) { try{ arg_parser cmd(argc, argv); if(cmd.has_option("help")){ return cmd_help(); } if(cmd.has_option("create-hex")){ return cmd_create_hex(cmd); } }catch(std::exception &e){ std::printf("%s\n", e.what()); return -1; } return 0; }
int main(int argc, char **argv) { char *line = (char *)NULL; while (1) { line = rl_gets(); // show help text if (strcmp(line, "help") == 0) { cmd_help(line); continue; } // quit if (strcmp(line, "exit") == 0) return 0; } return 0; }
static int input_help(int arg, int key UNUSED) { int i, in_string, in_bracket; if (arg != 1) return rl_insert(arg, '?'); in_string = in_bracket = 0; for (i = 0; i < rl_point; i++) { if (rl_line_buffer[i] == '"') in_string = ! in_string; else if (! in_string) { if (rl_line_buffer[i] == '[') in_bracket++; else if (rl_line_buffer[i] == ']') in_bracket--; } } /* `?' inside string or path -> insert */ if (in_string || in_bracket) return rl_insert(1, '?'); rl_begin_undo_group(); /* HACK: We want to display `?' at point position */ rl_insert_text("?"); rl_redisplay(); rl_end_undo_group(); input_start_list(); cmd_help(rl_line_buffer, rl_point); rl_undo_command(1, 0); input_stop_list(); return 0; }
void GameEvent(CORE_DATA *cd) { switch (cd->event) { case EVENT_START: RegisterPlugin(OPENCORE_VERSION, CORE_NAME, "cycad", OPENCORE_VERSION, __DATE__, __TIME__, "core handler", 0, 0); register_commands(); break; case EVENT_COMMAND: switch (cd->cmd_id) { case CMD_DIE: cmd_die(cd); break; case CMD_STOPBOT: cmd_stopbot(cd); break; case CMD_GETFILE: cmd_getfile(cd); break; case CMD_PUTFILE: cmd_putfile(cd); break; case CMD_LISTBOTS: cmd_listbots(cd); break; case CMD_TYPES: cmd_types(cd); break; case CMD_LOADTYPES: cmd_loadtypes(cd); break; case CMD_LOG: cmd_log(cd); break; case CMD_CMDLOG: cmd_cmdlog(cd); break; case CMD_ABOUT: cmd_about(cd); break; case CMD_INSLIB: cmd_inslib(cd); break; case CMD_RMLIB: cmd_rmlib(cd); break; case CMD_HELP: cmd_help(cd); break; case CMD_SYSINFO: cmd_sysinfo(cd); break; case CMD_LOADOPS: cmd_loadops(cd); break; case CMD_LISTOPS: cmd_listops(cd); break; case CMD_EXEC: cmd_exec(cd); break; case CMD_STARTBOT: cmd_startbot(cd); break; case CMD_GO: cmd_go(cd); break; default: break; } break; default: break; } }