/***************************************************************************** Main program. *****************************************************************************/ int main (int argc, char* argv[]) { const char* usage0 = "usage: rtkgps [-h] [-v] [-d <dev> [-r <rate>] | -b <addr>]\n" " ([-e] status | date | list | [-y] erase |\n" " [-c <flg>] [-l <lgtp>] [-m <mfo>] [-s <int>] set |\n" " [-n] [-p] [-o <dest> [-u]] [-f <nstr>] read)\n\n" " -h display usage\n" " -v verbose mode\n" " -d <dev> specify serial device\n" " -r <rate> specify baud rate for serial device\n" " -b <addr> specify bluetooth address\n" " -e display extended status information\n"; const char* usage1 = " -c <flg> set real-time output (GPS mouse) mode " "(0=disable, 1=enable)\n" " -l <lgtp> set log record type (tl, tla, or tlav)\n" " -m <mfo> set memory overwrite behaviour (o=overwrite, s=stop)\n" " -s <int> set sampling interval in seconds\n" " -n output data in simple native text form\n" " -p display text progress bar\n" " -o <dest> specify destination file or directory\n" " -u skip downloading date for existing files\n"; const char* usage2 = " -f <nstr> string specifying index number(s) of log file(s) \n" " to retrieve as a single file number, or range of \n" " file numbers in the format -n, n-, or n-m\n" " -y don't ask for confirmation\n"; /* most Royalteks operate on 57600 baud, use that as the default */ cmdlnopts_t cmdopt = {0,0,0,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, NULL,NULL,-1,-1,-1,57600,""}; /* Initialise usage string */ strcpy(cmdopt.usgs, usage0); strcat(cmdopt.usgs, usage1); strcat(cmdopt.usgs, usage2); /* Scan command line options */ scan_cmdline(argc, argv, &cmdopt); /* Set up warning callback function */ gcwrnfp = warning; /* Perform requested task */ if (strcmp(cmdopt.cmds,"status") == 0) { cmd_status(&cmdopt); } else if (strcmp(cmdopt.cmds,"date") == 0) { cmd_date(&cmdopt); } else if (strcmp(cmdopt.cmds,"list") == 0) { cmd_list(&cmdopt); } else if (strcmp(cmdopt.cmds,"set") == 0) { cmd_set(&cmdopt); } else if (strcmp(cmdopt.cmds,"read") == 0) { cmd_read(&cmdopt); } else if (strcmp(cmdopt.cmds,"erase") == 0) { cmd_erase(&cmdopt); } exit(0); }
static int process_command(int serial, int cid, char *cmd) { /*char *opt, *opt2; */ char *p, *opt; int ret; if ((p = strchr(cmd, '\n'))) *p = '\0'; else return -1; if ((opt = strchr(cmd, ' '))) { *opt = '\0'; opt ++; } else { opt = NULL; } debug_printf(DEBUG_NOTE, "cmd: %s\n", cmd); if (strcmp(cmd, "RELEASE") == 0) ret = cmd_release(cid); else if (strcmp(cmd, "UNFOCUSED") == 0) ret = cmd_unfocused(cid); else if (strcmp(cmd, "FOCUSED") == 0) ret = cmd_focused(cid); else if (strcmp(cmd, "HIDE") == 0) ret = cmd_hide(cid); else if (strcmp(cmd, "SHOW") == 0) ret = cmd_show(cid); else if (strcmp(cmd, "NEW") == 0) ret = cmd_new(cid, opt); else if (strcmp(cmd, "RESET") == 0) ret = cmd_reset(cid); else if (strcmp(cmd, "CHANGE") == 0) ret = cmd_change(cid, opt); else if (strcmp(cmd, "PROP") == 0) ret = cmd_prop(cid, opt); else if (strcmp(cmd, "LABEL") == 0) ret = cmd_label(cid); else if (strcmp(cmd, "HELPER") == 0) ret = cmd_helper(cid, opt); else if (strcmp(cmd, "NOP") == 0) ret = cmd_nop(cid); else if (strcmp(cmd, "LIST") == 0) ret = cmd_list(); else if (strcmp(cmd, "SETENC") == 0) ret = cmd_setenc(opt); else if (strcmp(cmd, "GETENC") == 0) ret = cmd_getenc(opt); /* for debug */ else ret = cmd_error(); return ret; }
error_code _sys_ppu_thread_create(vm::ptr<u64> thread_id, vm::ptr<ppu_thread_param_t> param, u64 arg, u64 unk, s32 prio, u32 stacksize, u64 flags, vm::cptr<char> threadname) { sys_ppu_thread.warning("_sys_ppu_thread_create(thread_id=*0x%x, param=*0x%x, arg=0x%llx, unk=0x%llx, prio=%d, stacksize=0x%x, flags=0x%llx, threadname=%s)", thread_id, param, arg, unk, prio, stacksize, flags, threadname); if (prio < 0 || prio > 3071) { return CELL_EINVAL; } if ((flags & 3) == 3) // Check two flags: joinable + interrupt not allowed { return CELL_EPERM; } const u32 tid = idm::import<ppu_thread>([&]() { auto ppu = std::make_shared<ppu_thread>(threadname ? threadname.get_ptr() : "", prio, stacksize); if ((flags & SYS_PPU_THREAD_CREATE_JOINABLE) != 0) { ppu->joiner = 0; } ppu->gpr[13] = param->tls.value(); if ((flags & SYS_PPU_THREAD_CREATE_INTERRUPT) == 0) { // Initialize thread entry point ppu->cmd_list ({ { ppu_cmd::set_args, 2 }, arg, unk, // Actually unknown { ppu_cmd::lle_call, param->entry.value() }, }); } else { // Save entry for further use (workaround) ppu->gpr[2] = param->entry.value(); } return ppu; }); if (!tid) { return CELL_EAGAIN; } *thread_id = tid; return CELL_OK; }
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; }
int main(int argc, char **argv) { int ch, help = 0; while ((ch = getopt_long(argc, argv, "+d:", base_opts, NULL)) != -1) { switch (ch) { case 'd': btpd_dir = optarg; break; case 'H': help = 1; break; default: usage(); } } argc -= optind; argv += optind; if (btpd_dir == NULL) if ((btpd_dir = find_btpd_dir()) == NULL) diemsg("cannot find the btpd directory.\n"); if (argc == 0) { cmd_list(argc, argv); cmd_stat(argc, argv); return 0; } optind = 0; int found = 0; for (int i = 0; !found && i < ARRAY_COUNT(cmd_table); i++) { if (strcmp(argv[0], cmd_table[i].name) == 0) { found = 1; if (help) cmd_table[i].help(); else cmd_table[i].fun(argc, argv); } } if (!found) usage(); return 0; }
int main(int argc, char* argv[]) { str packet = {0,0,0}; const char* s; uid_t euid = -1; const struct passwd* pw; if (chdir_bcron() != 0) respond("ZCould not change directory"); if (argc > 1) fixup_argv = argv + 1; if ((s = ucspi_protocol()) == 0 || (strcmp(s, "UNIX") != 0 && strcmp(s, "LOCAL") != 0) || (s = ucspi_getenv("REMOTEEUID")) == 0 || (euid = strtoul(s, (char**)&s, 0)) == (unsigned)-1 || *s != 0) respond("DConfiguration error: must be run from unixserver"); if (!ibuf_getnetstring(&inbuf, &packet) || packet.len < 2) respond("ZInvalid input data or read error"); /* Look up and validate username */ username = packet.s + 1; if ((pw = getpwnam(username)) == 0) respond("DInvalid or unknown username"); if (euid != 0 && euid != pw->pw_uid) respond("DUsername does not match invoking UID"); if (!str_copy2s(&filename, CRONTAB_DIR "/", pw->pw_name)) respond("ZCould not produce filename"); logcmd(packet.s[0]); /* Execute the command. */ switch (packet.s[0]) { case 'S': cmd_store(&packet); break; case 'L': cmd_list(); break; case 'R': cmd_remove(); break; case 'Y': if (euid != 0 && euid != getuid()) respond("DOnly root or cron can list system crontabs"); cmd_listsys(); break; } respond("DInvalid command code"); return 0; }
int cmd_delete(int argc, char *argv[]) { storage_t storage; char *backup_name; char *unlink_path; if (!(argc == 3 || (argc == 2 && options_get()->interactive))) { int help_argc = 2; char *help_argv[] = { "help_err", "delete", NULL }; return cmd_help_err(help_argc, help_argv); } if ((storage = storage_new(argv[1], false, false)) == NULL) logger(LOG_ERROR, "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 delete: "); /* Cleanly exit if the user did not enter any backup to delete. */ if (backup_name == NULL || strlen(backup_name) == 0) return EXIT_SUCCESS; } unlink_path = path_concat("backups", backup_name); free(backup_name); if (!storage_unlink(storage, unlink_path)) logger(LOG_ERROR, "unable to delete the backup"); free(unlink_path); storage_delete(storage); return EXIT_SUCCESS; }
static int do_help(int argc, char *argv[]) { if (argc == 1) { return cmd_list(); } else { const struct shell_cmd *cmd; int i; for (i = 1; i < argc; ++i) { cmd = cmd_find(argv[i]); if (!cmd) { printf("no such command: %s\n", argv[i]); } else { printf("%s: %s\n", cmd->exe, cmd->usage ? : cmd->exe); } } } return 0; }
static int run_cmd(int argc, char **argv) { if (strncmp(argv[0], "help", 4) == 0) usage(stdout, 0); else if (strncmp(argv[0], "version", 8) == 0) { about(); return 0; } else if (strncmp(argv[0], "hate", 5) == 0) return cmd_hate(argc, argv); else if (strncmp(argv[0], "love", 5) == 0) return cmd_love(argc, argv); else if (strncmp(argv[0], "kill", 5) == 0) return cmd_kill(argc, argv); else if (strncmp(argv[0], "unkill", 7) == 0) return cmd_unkill(argc, argv); else if (strncmp(argv[0], "rate", 5) == 0) return cmd_rate(argc, argv); else if (strncmp(argv[0], "rateabs", 8) == 0) return cmd_rate_absolute(argc, argv); else if (strncmp(argv[0], "list", 5) == 0) return cmd_list(argc, argv); else if (strncmp(argv[0], "listinfo", 9) == 0) return cmd_listinfo(argc, argv); else if (strncmp(argv[0], "addtag", 7) == 0) return cmd_addtag(argc, argv); else if (strncmp(argv[0], "rmtag", 6) == 0) return cmd_rmtag(argc, argv); else if (strncmp(argv[0], "listtags", 9) == 0) return cmd_listtags(argc, argv); else if (strncmp(argv[0], "count", 6) == 0) return cmd_count(argc, argv); else if (strncmp(argv[0], "karma", 6) == 0) return cmd_karma(argc, argv); fprintf(stderr, "Unknown command `%s'\n", argv[0]); usage(stderr, 1); }
void my_cmd2(char **com, int const cfd) { if (strcmp(com[0], "/part") == 0) cmd_part(com, cfd); else if (strcmp(com[0], "/list") == 0) cmd_list(com, cfd); else if (strcmp(com[0], "/quit") == 0) cmd_quit(com, cfd); else if (strcmp(com[0], "/users") == 0) cmd_users(com, cfd); else if (strcmp(com[0], "/msg") == 0) cmd_mp(com, cfd); else if (strcmp(com[0], "/topic") == 0) cmd_topic(com, cfd); else if (strcmp(com[0], "/kick") == 0) cmd_kick(com, cfd); else if (strcmp(com[0], "/kill") == 0) cmd_kill(com, cfd); else if (strcmp(com[0], "/ping") == 0) dprintf(cfd, "PING \r\n"); else cmd_msg(com, cfd); }
int main(int argc, char **argv) { struct arguments args; int rc; rc = -1; memset(&args, 0, sizeof(args)); argp_parse(&argp, argc, argv, 0, 0, &args); switch (args.cmd) { case CMD_INIT: rc = cmd_init(&args); break; case CMD_LIST: rc = cmd_list(&args); break; case CMD_INSERT: rc = cmd_insert(&args); break; case CMD_RETRIEVE: rc = cmd_retrieve(&args); break; case CMD_KILL: rc = cmd_kill(&args); break; case CMD_INTERACTIVE: rc = cmd_interactive(&args); break; default: fprintf(stderr, "invalid command\n"); goto out; } out: return rc; }
static void _cdecl tar_cmd_main_thread(LPVOID param) { CTar32CmdInfo *pCmdInfo = (CTar32CmdInfo*)param; CTar32CmdInfo &cmdinfo = *pCmdInfo; CTar32StatusDialog dlg; try{ if(cmdinfo.b_display_dialog){ cmdinfo.hTar32StatusDialog = dlg.Create(cmdinfo.hParentWnd); } switch(cmdinfo.command){ case 'x': cmd_extract(cmdinfo); break; case 'c': cmd_create(cmdinfo); break; case 'l': cmd_list(cmdinfo); break; default: throw CTar32Exception("Command not specified.", ERROR_COMMAND_NAME); } // メッセージループの終了前にダイアログを閉じる! 2000/03/03 by tsuneo dlg.Destroy(); if(pCmdInfo->wm_main_thread_end)PostThreadMessage(pCmdInfo->idMessageThread, pCmdInfo->wm_main_thread_end, 0, 0); }catch(CTar32Exception &e){ dlg.Destroy(); if(pCmdInfo->wm_main_thread_end)PostThreadMessage(pCmdInfo->idMessageThread, pCmdInfo->wm_main_thread_end, 0, 0); cmdinfo.exception = e; // throw e; }catch(...){ dlg.Destroy(); } //return 0; }
int main(const int ac, const char* av[]) { poptContext optCon=0; gint rc; gint status = 0; const gchar* arg; struct error* err; #ifdef __DEBUG g_mem_set_vtable(glib_mem_profiler_table); #endif err = e_new(); /* check if we have enough privileges */ #ifndef __WIN32__ unsetenv("LD_LIBRARY_PATH"); #else putenv("LD_LIBRARY_PATH"); putenv("LD_LIBRARY_PATH="); #endif /* load blacklists from SPKG_CONFDIR */ gchar** bl_symopts = load_blacklist(SPKG_CONFDIR "/symopts_blacklist"); if (bl_symopts) cmd_opts.bl_symopts = bl_symopts; /* preset ROOT */ cmd_opts.root = getenv("ROOT"); /* initialize popt context */ optCon = poptGetContext("spkg", ac, av, opts, 0); poptSetOtherOptionHelp(optCon, "<command> [options] [packages...]"); /* parse options */ while ((rc = poptGetNextOpt(optCon)) != -1) { if (rc == 1) verbose++; else if (rc == 2) quiet++; if (rc < -1) { fprintf(stderr, "ERROR: Invalid argument: %s (%s)\n", poptStrerror(rc), poptBadOption(optCon, POPT_BADOPTION_NOALIAS)); goto err_1; } } /* these are help handlers */ if (help) { printf( PACKAGE_STRING "\n" "\n" "Written by Ondrej Jirman, 2005-2006.\n" "\n" "This is free software. Not like a beer or like in a \"freedom\",\n" "but like in \"I don't care what you are going to do with it.\"\n" "\n" ); poptPrintHelp(optCon, stdout, 0); printf( "\n" "Examples:\n" " spkg -i <packages> [--install]\n" " spkg -u <packages> [--upgrade]\n" " spkg -vd <packages> [--verbose --remove]\n" " spkg -l kde* [--list]\n" " spkg -vnu <packages> [--upgrade --verbose --dry-run]\n" "\n" "Official website: http://spkg.megous.com\n" "Bug reports can be sent to <*****@*****.**>.\n" ); goto out; } if (usage) { printf("Usage: spkg [-i|-u|-d|-l] [--root=ROOT] [-n] [-s] [-q] [-v] [packages...]\n"); goto out; } if (version) { printf("%s\n", PACKAGE_STRING); goto out; } /* check verbosity options */ if (verbose && quiet) { fprintf(stderr, "ERROR: Verbose or quiet?\n"); goto err_1; } cmd_opts.verbosity += verbose; cmd_opts.verbosity -= quiet; /* check command options */ switch (command) { case CMD_INSTALL: if (!cmd_opts.dryrun && !is_root()) goto err_noroot; if (poptPeekArg(optCon) == 0) goto err_nopackages; break; case CMD_UPGRADE: if (!cmd_opts.dryrun && !is_root()) goto err_noroot; if (poptPeekArg(optCon) == 0) goto err_nopackages; break; case CMD_REMOVE: if (!cmd_opts.dryrun && !is_root()) goto err_noroot; if (poptPeekArg(optCon) == 0) goto err_nopackages; break; case CMD_LIST: break; case 0: if (poptPeekArg(optCon) == 0) { printf("Usage: spkg [-i|-u|-d|-l] [--root=ROOT] [-n] [-s] [-q] [-v] [packages...]\n"); goto out; } if (!cmd_opts.dryrun && !is_root()) goto err_noroot; command = CMD_UPGRADE; install_new = TRUE; break; default: fprintf(stderr, "ERROR: Schizofrenic command usage.\n"); goto err_1; } /* init signal trap */ if (sig_trap(err)) goto err_2; /* open db */ gboolean readonly = cmd_opts.dryrun || !is_root(); if (db_open(cmd_opts.root, readonly, err)) goto err_2; switch (command) { case CMD_INSTALL: { while ((arg = poptGetArg(optCon)) != 0 && !sig_break) { if (cmd_install(arg, &cmd_opts, err)) { if (e_errno(err) & CMD_EXIST) { gchar* pkgname = parse_pkgname(arg, 5); _inform("Skipping package %s (package with same base name is already installed)...", pkgname ? pkgname : arg); g_free(pkgname); e_clean(err); } else { e_print(err); e_clean(err); status = 2; } } } } break; case CMD_UPGRADE: { while ((arg = poptGetArg(optCon)) != 0 && !sig_break) { if (cmd_upgrade(arg, &cmd_opts, err)) { if (install_new && (e_errno(err) & CMD_NOTEX)) { e_clean(err); if (cmd_install(arg, &cmd_opts, err)) { e_print(err); e_clean(err); status = 2; } } else if (e_errno(err) & CMD_NOTEX) { gchar* pkgname = parse_pkgname(arg, 5); _inform("Skipping package %s (package with same base name is NOT installed)...", pkgname ? pkgname : arg); g_free(pkgname); e_clean(err); } else if (e_errno(err) & CMD_EXIST) { gchar* pkgname = parse_pkgname(arg, 5); _inform("Skipping package %s (already uptodate)...", pkgname ? pkgname : arg); g_free(pkgname); e_clean(err); } else { e_print(err); e_clean(err); status = 2; } } } } break; case CMD_REMOVE: { while ((arg = poptGetArg(optCon)) != 0 && !sig_break) { if (cmd_remove(arg, &cmd_opts, err)) { e_print(err); e_clean(err); status = 2; } } } break; case CMD_LIST: { GSList* arglist = NULL; while ((arg = poptGetArg(optCon)) != 0) arglist = g_slist_append(arglist, g_strdup(arg)); if (cmd_list(arglist, &cmd_opts, err)) { e_print(err); e_clean(err); status = 2; } g_slist_foreach(arglist, (GFunc)g_free, 0); g_slist_free(arglist); } break; } db_close(); out: poptFreeContext(optCon); e_free(err); #ifdef __DEBUG g_mem_profile(); #endif /* 0 = all ok * 1 = command line error * 2 = package manager error */ return status; err_1: status = 1; goto out; err_2: status = 2; e_print(err); goto out; err_nopackages: fprintf(stderr, "ERROR: No packages specified.\n"); goto err_1; err_noroot: fprintf(stderr, "ERROR: You need root privileges to run this command. Try using --dry-run.\n"); goto err_1; }
int main(int argc, UCHAR **argv) { UCHAR *script0 = malloc(SIZ_SCRIPT); // fat_flags = malloc(65536); fat = malloc(65536 * 2); filebuf0 = malloc(SIZ_FILEBUF); imgbuf0 = malloc(SIZ_IMGBUF); UCHAR *p, *q, *r, *script1; int i; FILE *fp; if (imgbuf0 == NULL) errend(1); /* out of memory */ /* スクリプト準備 */ q = script0; while ((p = *++argv) != NULL) { if (*p != '@') { r = ++q; while ((*q++ = *p++) != '\0') { if (q - script0 >= SIZ_SCRIPT - 4) errend(2); /* script too long */ } if (q - r > 255 + 1) errend(3); /* script too long */ *(r - 1) = (q - r) - 1; continue; } p++; fp = fopen(p, "rb"); if (fp == NULL) errend(4); /* script file open error */ i = fread(filebuf0, 1, SIZ_FILEBUF, fp); if (i >= SIZ_FILEBUF) errend(5); /* script file open error */ script1 = filebuf0 + i; p = filebuf0; for (;;) { while (p < script1 && *p <= ' ') p++; if (p >= script1) break; r = ++q; while (p < script1 && *p > ' ') { if (q - script0 >= SIZ_SCRIPT - 4) errend(6); /* script too long */ *q++ = *p++; } if (q - r > 255) errend(7); /* script too long */ *(r - 1) = q - r; *q++ = '\0'; } } *q++ = '\0'; script1 = q; /* スクリプト解釈 */ p = script0; for (;;) { if (*p == '\0') break; if (cmdmatch(p, "copy")) { p = (UCHAR *) cmd_copy(p); continue; } if (cmdmatch(p, "ovrcopy")) { p = (UCHAR *) cmd_ovrcopy(p); continue; } if (cmdmatch(p, "create")) { p = (UCHAR *) cmd_create(p); continue; } if (cmdmatch(p, "ovrcreate")) { p = (UCHAR *) cmd_ovrcreate(p); continue; } if (cmdmatch(p, "delete")) { p = (UCHAR *) cmd_delete(p); continue; } if (cmdmatch(p, "setattr")) { p = (UCHAR *) cmd_setattr(p); continue; } if (cmdmatch(p, "wbinimg")) { p = (UCHAR *) cmd_wbinimg(p); continue; } if (cmdmatch(p, "release")) { p = (UCHAR *) cmd_release(p); continue; } if (cmdmatch(p, "writedata")) { p = (UCHAR *) cmd_writedata(p); continue; } if (cmdmatch(p, "list")) { p = (UCHAR *) cmd_list(p); continue; } if (cmdmatch(p, "copyall")) { p = (UCHAR *) cmd_copyall(p); continue; } if (cmdmatch(p, "exe2bin")) { p = (UCHAR *) cmd_exe2bin(p); continue; } if (cmdmatch(p, "opt")) { p += *p + 2; continue; } if (optmatch(p, "imgin")) { p = (UCHAR *) opt_imgin(p); continue; } if (optmatch(p, "vsiz")) { p = (UCHAR *) opt_vsiz(p); continue; } if (optmatch(p, "imgout")) { p = (UCHAR *) opt_imgout(p); continue; } if (optmatch(p, "binin")) { p = (UCHAR *) opt_binin(p); continue; } if (optmatch(p, "binout")) { p = (UCHAR *) opt_binout(p); continue; } if (optmatch(p, "_path")) { p = (UCHAR *) opt_bpath(p); continue; } if (optmatch(p, "bias")) { p = (UCHAR *) opt_bias(p); continue; } if (cmdmatch(p, "/*")) { i = 1; do { p += *p + 2; if (*p == '\0') errend(9); /* comment nesting error */ if (cmdmatch(p, "/*")) i++; if (cmdmatch(p, "*/")) i--; } while (i > 0); p += *p + 2; continue; } fputs("script syntax error. : ", stderr); fputs(p + 1, stderr); errend(8); /* script syntax error */ } return 0; }
int main (int argc, char *argv[]) { int result; char *config = NULL; int ch; progname = argv[0]; while ((ch = getopt(argc, argv, "c:vVh")) != -1) { switch (ch) { case 'c': config = strdup(optarg); break; case 'v': verbose++; break; case 'V': version(); exit(0); break; case 'h': usage(); exit(0); break; default: usage(); exit(1); } } argc -= optind; argv += optind; if (!argc) { usage(); exit(1); } if (!strcasecmp(argv[0], "logout")) { if (config) free(config); exit(cmd_logout()); } result = hsm_open(config, hsm_prompt_pin); if (result) { hsm_print_error(NULL); exit(-1); } openlog("hsmutil", LOG_PID, LOG_USER); if (!strcasecmp(argv[0], "login")) { argc --; argv ++; result = cmd_login(); } else if (!strcasecmp(argv[0], "list")) { argc --; argv ++; result = cmd_list(argc, argv); } else if (!strcasecmp(argv[0], "generate")) { argc --; argv ++; result = cmd_generate(argc, argv); } else if (!strcasecmp(argv[0], "remove")) { argc --; argv ++; result = cmd_remove(argc, argv); } else if (!strcasecmp(argv[0], "purge")) { argc --; argv ++; result = cmd_purge(argc, argv); } else if (!strcasecmp(argv[0], "dnskey")) { argc --; argv ++; result = cmd_dnskey(argc, argv); } else if (!strcasecmp(argv[0], "test")) { argc --; argv ++; result = cmd_test(argc, argv); } else if (!strcasecmp(argv[0], "info")) { argc --; argv ++; result = cmd_info(); } else if (!strcasecmp(argv[0], "debug")) { argc --; argv ++; result = cmd_debug(); } else { usage(); result = -1; } (void) hsm_close(); if (config) free(config); closelog(); exit(result); }