int main(int argc, char **argv) { struct arg_xxx *scalar = arg_xxx1(NULL, NULL, "<scalar>", 0.0, 1.0, "<double> value in range [0.0, 1.0]"); struct arg_xxx *x = arg_xxx0("x", NULL, "<double>", -1.0, 1.0, "x coeff in range [-1.0, 1.0]"); struct arg_xxx *y = arg_xxxn("y", NULL, "<double>", 0,argc+2, 0.5, 0.9, "y coeff in range [0.5, 0.9]"); struct arg_lit *help = arg_lit0(NULL,"help", "print this help and exit"); struct arg_end *end = arg_end(20); void* argtable[] = {scalar,x,y,help,end}; const char* progname = "argcustom"; int nerrors; int exitcode=0; int i; /* verify the argtable[] entries were allocated sucessfully */ if (arg_nullcheck(argtable) != 0) { /* NULL entries were detected, some allocations must have failed */ printf("%s: insufficient memory\n",progname); exitcode=1; goto exit; } /* Parse the command line as defined by argtable[] */ nerrors = arg_parse(argc,argv,argtable); /* special case: '--help' takes precedence over error reporting */ if (help->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout,argtable,"\n"); printf("This program demonstrates the use of the argtable2 library\n"); printf("for parsing command line arguments.\n"); arg_print_glossary(stdout,argtable," %-25s %s\n"); exitcode=0; goto exit; } /* If the parser returned any errors then display them and exit */ if (nerrors > 0) { /* Display the error details contained in the arg_end struct.*/ arg_print_errors(stdout,end,progname); printf("Try '%s --help' for more information.\n",progname); exitcode=1; goto exit; } /* only get here is command line arguments were parsed sucessfully */ printf("scalar = %f\n", scalar->data[0]); if (x->count > 0) printf("x = %f\n", x->data[0]); for (i=0; i<y->count; i++) printf("y[%d] = %f\n", i, y->data[i]); exit: /* deallocate each non-null entry in argtable[] */ arg_freetable(argtable,sizeof(argtable)/sizeof(argtable[0])); return exitcode; }
int main(int argc, char **argv) { struct netns_entry *root; int netns_ok, err; arg_register_batch(options, ARRAY_SIZE(options)); register_frontends(); register_handlers(); if ((err = arg_parse(argc, argv))) exit(err); if (!check_caps()) { fprintf(stderr, "Must be run under root (or with enough capabilities).\n"); exit(1); } netns_ok = netns_switch_root(); if (netns_ok > 0) { fprintf(stderr, "Cannot change to the root name space: %s\n", strerror(netns_ok)); exit(1); } global_handler_init(); if ((err = netns_list(&root, netns_ok == 0))) { fprintf(stderr, "ERROR: %s\n", strerror(err)); exit(1); } if ((err = frontend_output(root))) { fprintf(stderr, "Invalid output format specified.\n"); exit(1); } global_handler_cleanup(root); netns_list_free(root); return 0; }
static int eth_cmd_control(int argc, char **argv) { int nerrors = arg_parse(argc, argv, (void **)ð_control_args); if (nerrors != 0) { arg_print_errors(stderr, eth_control_args.end, argv[0]); return 1; } if (!strncmp(eth_control_args.control->sval[0], "start", 5) && !started) { ESP_ERROR_CHECK(esp_eth_enable()); started = true; } if (!strncmp(eth_control_args.control->sval[0], "stop", 4) && started) { ESP_ERROR_CHECK(esp_eth_disable()); started = false; } if (!strncmp(eth_control_args.control->sval[0], "info", 4)) { uint8_t mac_addr[6]; esp_eth_get_mac(mac_addr); printf("HW ADDR: " MACSTR "\r\n", MAC2STR(mac_addr)); tcpip_adapter_get_ip_info(ESP_IF_ETH, &ip); printf("ETHIP: " IPSTR "\r\n", IP2STR(&ip.ip)); printf("ETHMASK: " IPSTR "\r\n", IP2STR(&ip.netmask)); printf("ETHGW: " IPSTR "\r\n", IP2STR(&ip.gw)); } return 0; }
/** * Parse the input and output parameters against this argtable. * @param argc A count of the number of parameters. * @param argv An array of string parameters. * @return The number of errors detected. */ int ArgTable::parse(int argc, char* argv[]) { if (m_argtable == nullptr) { // If we don't have an argtable, build it. build(); } int nErrors = arg_parse(argc, argv, m_argtable); return nErrors; } // ArgTable#parse
bool Application::initArgtable() { const char* progname = "revisor"; struct arg_str* l = arg_str0("l", NULL, "<interface>", "Interface to listen, default '127.0.0.1'"); struct arg_int* p = arg_int0("p", NULL, "<port number>", "Port to listen, default 8080"); struct arg_lit* h = arg_lit0("h", "help", "This help message"); struct arg_end* end = arg_end(20); void *argtable[] = {l, p, h, end}; int nerrors = arg_parse(argc, argv, argtable); // special case: '--help' takes precedence over error reporting if (h->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout, argtable, "\n"); arg_print_glossary(stdout, argtable, " %-25s %s\n"); return false; } if (nerrors > 0) { arg_print_errors(stdout, end, progname); return false; } if (l->count > 0) { listeningInterface = l->sval[0]; } if (p->count > 0) { portNumber = *p->ival; } arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return true; }
int main (int argc, char **argv) { void *argtable[] = { help = arg_lit0("h","help","print this screen"), verbose = arg_lit0("v","verbose","tell me everything"), fsyslog = arg_lit0(NULL,"syslog","use syslog"), cachepath = arg_file1(NULL,NULL,"cachepath","directory or .cdb database file"), netaddress0 = arg_file1(NULL,NULL,"read_address","zmq read network address"), netaddress1 = arg_file1(NULL,NULL,"write_address","zmq write network address"), end = arg_end(20), }; int32_t nerrors = arg_parse(argc,argv,argtable); if (help->count) { fprintf(stdout,"tmpcache %s - version 0\n",__FUNCTION__); arg_print_syntaxv(stdout,argtable,"\n\n"); arg_print_glossary (stdout,argtable,"%-25s %s\n"); goto finish; } if (verbose->count) { fprintf(stdout,"tmpcache host - version 0\n"); int32_t major,minor,patch; zmq_version (&major,&minor,&patch); fprintf(stdout,"compiled with zmq support %d.%d.%d\n",major,minor,patch); goto finish; } if (nerrors) { arg_print_errors (stdout,end,""); arg_print_syntaxv(stdout,argtable,"\n\n"); goto finish; } u_term = 0; signal (SIGINT,signalhandler); signal (SIGTERM,signalhandler); if (fsyslog->count) openlog (NULL,LOG_PID|LOG_NDELAY,LOG_USER); void *read (void *arg) { tc_readconfig_t *config = (tc_readconfig_t *)arg; if (fsyslog->count) syslog (LOG_INFO,"reading cache from %s @ %s",btocstr(config->cachepath),btocstr(config->address)); tc_readfromcache (config); if (fsyslog->count) syslog (LOG_INFO,"closing cache %s @ %s for reading",btocstr(config->cachepath),btocstr(config->address)); }
int main( int argc, char** argv ) { IplImage* img; struct feature* features; int n = 0; arg_parse( argc, argv ); fprintf( stderr, "Finding SIFT features...\n" ); img = cvLoadImage( img_file_name, 1 ); if( ! img ) fatal_error( "unable to load image from %s", img_file_name ); n = _sift_features( img, &features, intvls, sigma, contr_thr, curv_thr, img_dbl, descr_width, descr_hist_bins ); fprintf( stderr, "Found %d features.\n", n ); if( display ) { draw_features( img, features, n ); display_big_img( img, img_file_name ); cvWaitKey( 0 ); } if( out_file_name != NULL ) export_features( out_file_name, features, n ); if( out_img_name != NULL ) cvSaveImage( out_img_name, img, NULL ); return 0; }
int main(int argc, char* argv[]) { // Setup. AppLib::Logging::setApplicationName(std::string("apputil")); struct arg_file *script = arg_file1(NULL, NULL, "script", "the path of the script to execute"); struct arg_end *end = arg_end(20); void *argtable[] = { script, end }; script->filename[0] = NULL; // Check to see if the argument definitions were allocated // correctly. if (arg_nullcheck(argtable)) { AppLib::Logging::showErrorW("Insufficient memory."); return 1; } // Now parse the arguments. int nerrors = arg_parse(argc, argv, argtable); // Check to see if there were errors. if (nerrors > 0 && script->filename[0] == NULL) { printf("Usage: apputil"); arg_print_syntax(stdout, argtable, "\n"); arg_print_errors(stdout, end, "apputil"); printf("AppUtil - The application scripting utility.\n\n"); arg_print_glossary(stdout, argtable, " %-25s %s\n"); return 1; } // Execute. return runPython(script->filename[0], argc, argv); }
void test_argstr_basic_003(CuTest* tc) { struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none"); struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none"); struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C"); struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences"); struct arg_end* end = arg_end(20); void* argtable[] = {a, b, c, d, end}; int nerrors; char* argv[] = {"program", "-Cstring1", "--delta=string2", "--delta=string3", NULL}; int argc = sizeof(argv) / sizeof(char*) - 1; CuAssertTrue(tc, arg_nullcheck(argtable) == 0); nerrors = arg_parse(argc, argv, argtable); if (nerrors > 0) arg_print_errors(stdout, end, argv[0]); CuAssertTrue(tc, nerrors == 0); CuAssertTrue(tc, a->count == 0); CuAssertTrue(tc, b->count == 0); CuAssertTrue(tc, c->count == 1); CuAssertStrEquals(tc, c->sval[0], "string1"); CuAssertTrue(tc, d->count == 2); CuAssertStrEquals(tc, d->sval[0], "string2"); CuAssertStrEquals(tc, d->sval[1], "string3"); arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); }
int main (void) { printf("TEST #1\n"); arg_parse((char *)"Testing trailing spaces "); printf("\n\nTEST #2\n"); arg_parse((char *)" Testing leading spaces"); printf("\n\nTEST #3\n"); arg_parse((char *)" Testing both leading and trailing spaces "); printf("\n\nTEST #4\n"); arg_parse((char *)" "); return 0; }
nz_rc midimelody_block_create(const struct nz_context * context_p, const char * string, nz_block_state ** state_pp, struct nz_block_info * info_p) { nz_rc result = arg_parse(NULL, string, NULL); if(result != NZ_SUCCESS) return result; nz_rc rc = midimelody_block_create_args(state_pp, info_p, context_p); return rc; }
static int dslink_parse_opts(int argc, char **argv, DSLinkConfig *config) { int ret = 0; struct arg_lit *help; struct arg_str *broker, *log; struct arg_end *end; void *argTable[] = { help = arg_lit0("h", "help", "Displays this help menu"), broker = arg_str1("b", "broker", "url", "Sets the broker URL to connect to"), log = arg_str0("l", "log", "log type", "Sets the logging level"), end = arg_end(5) }; if (arg_nullcheck(argTable) != 0) { return DSLINK_ALLOC_ERR; } int errs = arg_parse(argc, argv, argTable); if (help->count > 0) { printf("Usage: <opts>\n"); arg_print_glossary(stdout, argTable, " %-25s %s\n"); ret = 1; goto exit; } if (errs > 0) { dslink_print_help(); arg_print_errors(stdout, end, ":"); ret = 1; goto exit; } config->broker_url = broker->sval[0]; if (log->count > 0) { char lvl[8]; const char *src = log->sval[0]; size_t len = strlen(src); if (len > sizeof(lvl)) { len = sizeof(lvl); } memcpy(lvl, src, len); if (dslink_log_set_lvl(lvl, len) != 0) { printf("Invalid log level: %s\n", lvl); dslink_print_help(); ret = 1; goto exit; } } exit: arg_freetable(argTable, sizeof(argTable) / sizeof(argTable[0])); return ret; }
int main (int argc, char **argv) { ARGPARSE_ARGS pargs; int cmd = 0; const char *keygrip = NULL; set_strusage (my_strusage); log_set_prefix ("gpg-preset-passphrase", 1); /* Make sure that our subsystems are ready. */ i18n_init (); init_common_subsystems (&argc, &argv); opt_homedir = default_homedir (); pargs.argc = &argc; pargs.argv = &argv; pargs.flags= 1; /* (do not remove the args) */ while (arg_parse (&pargs, opts) ) { switch (pargs.r_opt) { case oVerbose: opt.verbose++; break; case oHomedir: opt_homedir = pargs.r.ret_str; break; case oPreset: cmd = oPreset; break; case oForget: cmd = oForget; break; case oPassphrase: opt_passphrase = pargs.r.ret_str; break; default : pargs.err = 2; break; } } if (log_get_errorcount(0)) exit(2); if (argc == 1) keygrip = *argv; else usage (1); /* Tell simple-pwquery about the the standard socket name. */ { char *tmp = make_filename (opt_homedir, GPG_AGENT_SOCK_NAME, NULL); simple_pw_set_socket (tmp); xfree (tmp); } if (cmd == oPreset) preset_passphrase (keygrip); else if (cmd == oForget) forget_passphrase (keygrip); else log_error ("one of the options --preset or --forget must be given\n"); agent_exit (0); return 8; /*NOTREACHED*/ }
int main(int argc, char **argv) { struct arg_int *val = arg_intn(NULL,NULL,NULL,2,100,"must be an even number of non-zero integer values that sum to 100"); struct arg_end *end = arg_end(20); void* argtable[] = {val,end}; const char* progname = "callbacks"; int nerrors; int exitcode=0; int i; /* verify the argtable[] entries were allocated sucessfully */ if (arg_nullcheck(argtable) != 0) { /* NULL entries were detected, some allocations must have failed */ printf("%s: insufficient memory\n",progname); exitcode=1; goto exit; } /* replace the default arg_int parsing and error validation routines with our own custom routines */ val->hdr.scanfn = (arg_scanfn*)myscanfn; val->hdr.checkfn = (arg_checkfn*)mycheckfn; val->hdr.errorfn = (arg_errorfn*)myerrorfn; /* special case: no command line options induces brief help */ if (argc==1) { printf("Usage: %s ", progname); arg_print_syntax(stdout,argtable,"\n"); arg_print_glossary(stdout,argtable,"where: %s %s\n"); exitcode=0; goto exit; } /* Parse the command line as defined by argtable[] */ nerrors = arg_parse(argc,argv,argtable); /* If the parser returned any errors then display them and exit */ if (nerrors > 0) { /* Display the error details contained in the arg_end struct.*/ arg_print_errors(stdout,end,progname); exitcode=1; goto exit; } /* parsing was succesful, print the values obtained */ for (i=0; i<val->count; i++) printf("val->ival[%d] = %d\n",i, val->ival[i]); exit: /* deallocate each non-null entry in argtable[] */ arg_freetable(argtable,sizeof(argtable)/sizeof(argtable[0])); return exitcode; }
/****************************************************************************** * * main * ******************************************************************************/ gint main (gint argc, gchar *argv[]) { GimvThumbWin *tw = NULL; gint remaining; gboolean open_thumbwin = FALSE; FilesLoader *files = NULL; gimageview_init (&argc, argv); if (argc == 1) { open_thumbwin = TRUE; } /* override config by argument while start up*/ arg_parse (argc, argv, &remaining); #ifdef ENABLE_SPLASH show_splash (); #endif /* open window if specified by config or argument */ if (args_val.open_thumbwin || open_thumbwin) { tw = gimv_thumb_win_open_window (); } if (args_val.open_imagewin) { gimv_image_win_open_window (NULL); } /* set FilesLoader struct data for opening files */ files = get_files_from_argument (argc, argv, remaining); if (!files && !gimv_thumb_win_get_list() && !gimv_image_win_get_list()) { exit (1); } else if (tw && files && files->dirlist) { GList *list = g_list_last (files->dirlist); gchar *dirname = NULL; if (list) dirname = list->data; if (dirname) gimv_dir_view_chroot (tw->dv, dirname); } /* exec slide show if specified by argument */ if (args_val.exec_slideshow) { startup_slideshow (files); /* check filelist & dirlist and open image files */ } else { gtk_init_add (idle_open_image_startup, files); } /* main roop */ gtk_main (); return 0; }
void parse_command_line(int argc, char* argv[]) { // if the parsing of the arguments was unsuccessful int nerrors; // Define argument table structs python_folder = arg_file0 ( NULL, "py-folder", "<path to file>", "Path to folder (relative or absolute) that contains python script (default: lpfw-pygui)" ); log_debug = arg_int0 ( NULL, "log-debug", "<1/0 for yes/no>", "Enable debug messages logging" ); struct arg_lit *help = arg_lit0 ( NULL, "help", "Display this help screen" ); struct arg_lit *version = arg_lit0 ( NULL, "version", "Display the current version" ); struct arg_end *end = arg_end ( 10 ); void *argtable[] = {python_folder, log_debug, help, version, end}; // Set default values char *python_folder_pointer = malloc(strlen("lpfw-pygui")+1); strcpy (python_folder_pointer, "lpfw-pygui"); python_folder->filename[0] = python_folder_pointer; * ( log_debug->ival ) = 0; if ( arg_nullcheck ( argtable ) != 0 ) { printf ( "Error: insufficient memory\n" ); exit(0); } nerrors = arg_parse ( argc, argv, argtable ); if ( nerrors == 0 ) { if ( help->count == 1 ) { printf ( "Leopard Flower frontend :\n Syntax and help:\n" ); arg_print_glossary ( stdout, argtable, "%-43s %s\n" ); exit (0); } else if ( version->count == 1 ) { printf ( "%s\n", VERSION ); exit (0); } } else if ( nerrors > 0 ) { arg_print_errors ( stdout, end, "Leopard Flower frontend" ); printf ( "Leopard Flower frontend:\n Syntax and help:\n" ); arg_print_glossary ( stdout, argtable, "%-43s %s\n" ); exit (1); } // Free memory - don't do this cause args needed later on // arg_freetable(argtable, sizeof (argtable) / sizeof (argtable[0])); }
void lua_args_init(lua_State* lua, gint argc, gchar* argv[]) { DEBUG("Creating mud.args table."); lua_getglobal(lua, "mud"); lua_newtable(lua); struct arg_parse_funcs funcs = { .on_flag = lua_args_on_flag, .on_option = lua_args_on_option, .on_positional = lua_args_on_positional }; arg_parse(argc, argv, &funcs, lua); lua_setfield(lua, -2, "args"); lua_pop(lua, 1); }
static int wifi_cmd_sta(int argc, char** argv) { int nerrors = arg_parse(argc, argv, (void**) &sta_args); if (nerrors != 0) { arg_print_errors(stderr, sta_args.end, argv[0]); return 1; } ESP_LOGI(TAG, "sta connecting to '%s'", sta_args.ssid->sval[0]); wifi_cmd_sta_join(sta_args.ssid->sval[0], sta_args.password->sval[0]); return 0; }
int main(int argc, char *argv[]) { /* Name of the programme */ char progname[] = "sesh"; char progversion[] = "0.4.0"; /* Arguments table */ void *argtable[] = { help = arg_litn("h", "help", 0, 1, "Display this help and exit"), version = arg_litn("v", "version", 0, 1, "Display version info and exit"), end = arg_end(20), }; /* Number of errors analysing arguments */ int nerrors = arg_parse(argc, argv, argtable); /* If help needed we don't care about the errors */ if (help->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout, argtable, "\n"); arg_print_glossary(stdout, argtable, " %-25s %s\n"); arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return 0; } /* If errors occured */ if (nerrors > 0) { /* Displaying the error information */ arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return 1; } if (version->count > 0) { printf("Version: %s %s\n", progname, progversion); arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return 0; } history_init(); term_set_driver(); repl(); term_reset_driver(); arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return 0; }
/*! * @brief プログラムのエントリポイント * @param [in] argc コマンドライン引数の個数(プログラム名も含む) * @param [in] argv コマンドライン引数の配列 * @return 終了コード */ int main(int argc, char *argv[]) { int sock_new; /* ソケットのディスクリプタ */ int port_num; /* ポート番号 */ /* 引数解析を行う */ if (arg_parse(argc, argv, &port_num) == -1) { return EXIT_FAILURE; } /* クライアントとの接続を行い、クライアントのソケットディスクリプタを得る */ if ((sock_new = make_socket(port_num)) == -1) { return EXIT_FAILURE; } return play_game_server(sock_new); /* ゲームのメインループ */ }
int main(int argc, char *argv[]) { /* the global arg_xxx structs are initialised within the argtable */ void *argtable[] = { help = arg_lit0(NULL, "help", "display this help and exit"), version = arg_lit0(NULL, "version", "display version info and exit"), a = arg_lit0("a", NULL,"the -a option"), b = arg_lit0("b", NULL, "the -b option"), c = arg_lit0("c", NULL, "the -c option"), scal = arg_int0(NULL, "scalar", "<n>", "foo value"), verb = arg_lit0("v", "verbose", "verbose output"), o = arg_file0("o", NULL, "myfile", "output file"), file = arg_filen(NULL, NULL, "<file>", 0, 100, "input files"), end = arg_end(20), }; int exitcode = 0; char progname[] = "testargtable3.exe"; int nerrors; nerrors = arg_parse(argc,argv,argtable); /* special case: '--help' takes precedence over error reporting */ if (help->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout, argtable, "\n"); printf("List information about the FILE(s) " "(the current directory by default).\n\n"); arg_print_glossary(stdout, argtable, " %-25s %s\n"); exitcode = 0; goto exit; } /* If the parser returned any errors then display them and exit */ if (nerrors > 0) { /* Display the error details contained in the arg_end struct.*/ arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); exitcode = 1; goto exit; } exit: /* deallocate each non-null entry in argtable[] */ arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return exitcode; }
int main(int argc, char * argv[]) { void* argtable[] = { input = arg_filen( "i", "input", "<string>", 0, 100, "input file") , o_validate = arg_strn( "v", "validate", "<string>", 0, 10, "validate operations") , o_h = arg_file0( NULL, "output-h", "<string>", "output h file dir") , o_lib_c = arg_file0( NULL, "output-lib-c", "<string>", "output c lib file") , o_lib_c_arg = arg_str0( NULL, "output-lib-c-arg", "<string>", "output c lib file") , o_lib_bin = arg_file0( NULL, "output-lib-bin", "<string>", "output c lib file") , help = arg_lit0( NULL, "help", "print this help and exit") , end = arg_end(20) }; struct error_monitor em_buf; error_monitor_t em; int rv; int nerrors; cpe_error_monitor_init(&em_buf, cpe_error_log_to_consol, 0); em = &em_buf; rv = -1; if (arg_nullcheck(argtable) != 0) { CPE_ERROR(em, "init arg table fail!"); goto exit; } nerrors = arg_parse(argc,argv,argtable); if (help->count > 0) { printf("Usage: %s", argv[0]); arg_print_syntax(stdout,argtable,"\n"); rv = 0; goto exit; } if (nerrors > 0) { arg_print_errors(stdout, end, argv[0]); printf("Try '%s --help' for more information.\n", argv[0]); goto exit; } rv = tools_main(em); exit: arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return rv; }
nz_rc debug_block_create(const struct nz_context * context_p, const char * string, nz_block_state ** state_pp, struct nz_block_info * info_p) { nz_arg * args[1]; nz_rc rc = arg_parse("required generic type", string, args); if(rc != NZ_SUCCESS) return rc; char * type_str = (char *)args[0]; const struct nz_typeclass * typeclass_p; nz_type * type_p; rc = nz_context_create_type(context_p, &typeclass_p, &type_p, type_str); free(type_str); if(rc != NZ_SUCCESS) return rc; return debug_block_create_args(typeclass_p, type_p, state_pp, info_p); }
static nz_rc wavefileout_block_create_args(nz_block_state ** state_pp, struct nz_block_info * info_p, const char * filename) { struct state * state = calloc(1, sizeof(struct state)); if(state == NULL) NZ_RETURN_ERR(NZ_NOT_ENOUGH_MEMORY); nz_rc rc; rc = nz_block_info_set_n_io(info_p, 1, 0); if (rc != NZ_SUCCESS) goto fail; rc = nz_block_info_set_input(info_p, 0, strdup("in"), &nz_chunk_typeclass, NULL); if (rc != NZ_SUCCESS) goto fail; SF_INFO fdata = { //.frames = nz_vector_get_size(sample), .samplerate = nz_frame_rate, .channels = 1, .format = SF_FORMAT_WAV | SF_FORMAT_PCM_16, //.sections = 1, //.seekable = 0, }; state->file = sf_open(filename, SFM_WRITE, &fdata); if (state->file == NULL) { rc = NZ_INTERNAL_ERROR; //int err = sf_error(NULL); // Get error code goto fail; } *(struct state **)(state_pp) = state; return NZ_SUCCESS; fail: free(state); return rc; } static nz_rc wavfileout_block_create(const struct nz_context * context_p, const char * string, nz_block_state ** state_pp, struct nz_block_info * info_p) { nz_arg * args[1]; nz_rc rc = arg_parse("required string filename", string, args); if(rc != NZ_SUCCESS) return rc; char * filename = (char *) args[0]; rc = wavefileout_block_create_args(state_pp, info_p, filename); free(filename); return rc; }
void processline (char *line) { pid_t cpid; int status, n_args; char **argv; // Contains the line data char newline [LINELEN]; memset(newline, 0, LINELEN); if (expand (line, newline, LINELEN) == -1) { return; } n_args = arg_parse(newline, &argv); if (n_args == 0) return; if (try_builtin(n_args, argv)) { free(argv); last_exit = 0; return; } /* Start a new process to do the job. */ cpid = fork(); if (cpid < 0) { perror ("fork"); return; } /* Check for who we are! */ if (cpid == 0) { /* We are the child! */ execvp(argv[0], argv); perror("exec"); exit (127); } free(argv); // Parent frees the malloc /* Have the parent wait for child to complete */ if (wait (&status) < 0) perror ("wait"); }
int cargs_parse(int argc, char *argv[], bstring *input_fn, bstring *output_fn, bstring *log_fn) { struct arg_lit *help, *version; struct arg_file *arg_input_fn, *arg_output_fn, *arg_log_fn; struct arg_end *end; void *argtable[] = { help = arg_litn("h", "help", 0, 100, "display this help and exit"), version = arg_litn("v", "version", 0, 100, "display version info and exit"), arg_input_fn = arg_filen("i", "input", "input_file", 1, 1, "input file (required)"), arg_output_fn = arg_filen("o", "output", "output_file", 0, 1, "output file (optional)"), arg_log_fn = arg_filen("l", "log", "log_file", 0, 1, "log file (optional)"), end = arg_end(20), }; int rc = 0; int nerrors = 0; nerrors = arg_parse(argc, argv, argtable); // special case: help and version take precedence over error reporting if(help->count >= 1) { rc = cargs_print_help(argtable, help); goto exit; } if(version->count >= 1) { rc = cargs_print_version(version); goto exit; } // If the parser returned any errors, then display them and exit. if(nerrors > 0) { rc = cargs_print_error(end); goto exit; } cargs_export_file_name(arg_input_fn, arg_output_fn, arg_log_fn, input_fn, output_fn, log_fn); exit: arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); return rc; }
/* * All code below is "unimportant", it's only argument and file handling */ int main(int argc, char *argv[]) { struct arg_file *ifile = arg_file1("i", "input-file", "INPUT_FILE", "Set Input File"); struct arg_file *ofile = arg_file0("o", "output-file", "OUTPUT_FILE", "Set Output File"); struct arg_str *pass = arg_str0("p", "password", "PASSWORD", "Set Encryption Password"); struct arg_int *pas = arg_int0("c", "passes", "PASSES", "Set number of passes (To decrypt you'll need the same number of passes)"); struct arg_int *buf = arg_int0("b", "buffer-size", "BUFFER_SIZE", "Set Buffer Size"); struct arg_end *end = arg_end(20); void *argtable[] = { ifile, ofile, pass, pas, buf, end}; int nerrors = arg_parse(argc, argv, argtable); if (nerrors > 0) { arg_print_errors(stdout, end, "rxe"); printf("\nUsage: rxe"); arg_print_syntax(stdout, argtable, "\n"); arg_print_glossary(stdout, argtable, " %-10s %s\n"); } else { if (buf->count > 0) { BUFFER_SIZE = buf->ival[0]; } FILE *outfile, *infile = fopen(ifile->filename[0], "rb"); if (ofile->count > 0) outfile = fopen(ofile->filename[0], "wb"); else { char farr[2048]; char *ptr; strcpy(farr, ifile->filename[0]); if ((ptr = strstr(farr, ".rxe")) != NULL) { farr[0] = '\0'; farr[1] = '\0'; farr[2] = '\0'; farr[3] = '\0'; } else strcat(farr, ".rxe"); outfile = fopen(farr, "wb"); } if(pas->count > 0) PASSES = pas->ival[0]; if(pass->count > 0) RXE_Main(infile, outfile, (char *)pass->sval[0]); else RXE_Main(infile, outfile, "DEFAULT"); fclose(outfile); fclose(infile); } return 0; }
void test_argfile_basic_003(CuTest* tc) { struct arg_file* a = arg_file1(NULL, NULL, "<file>", "filename to test"); struct arg_end* end = arg_end(20); void* argtable[] = {a, end}; int nerrors; char* argv[] = {"program", "./foo.bar", NULL}; int argc = sizeof(argv) / sizeof(char*) - 1; CuAssertTrue(tc, arg_nullcheck(argtable) == 0); nerrors = arg_parse(argc, argv, argtable); CuAssertTrue(tc, nerrors == 0); CuAssertTrue(tc, a->count == 1); CuAssertStrEquals(tc, a->filename[0], "./foo.bar"); CuAssertStrEquals(tc, a->basename[0], "foo.bar"); CuAssertStrEquals(tc, a->extension[0], ".bar"); arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0])); }
/* global functions */ int main(int argc, char **argv){ int r; char *tmp_file_name; if(arg_parse(argc, argv) < 0) return 1; tmp_file_name = malloc(strlen(arg.ofile_name) + 5); if(tmp_file_name == 0x0) return 1; sprintf(tmp_file_name, "%s.tmp", arg.ofile_name); tmp_file = fopen(tmp_file_name, "w"); if(tmp_file == 0x0) fprintf(stderr, "open temporary file failed \"%s\"\n", strerror(errno)); if(arg.verbose) printf("generating temporary avr config header \"%s\"\n", tmp_file_name); /* compute config variables */ r = 0; r |= config_watchdog(); /* close tmp file */ fclose(tmp_file); if(diff(tmp_file_name, arg.ofile_name) == 0) goto end; printf("generating avr config header \"%s\"\n", arg.ofile_name); r |= rename(tmp_file_name, arg.ofile_name); end: unlink(tmp_file_name); return r; }
nz_rc constant_block_create(const struct nz_context * context_p, const char * string, nz_block_state ** state_pp, struct nz_block_info * info_p) { nz_arg * args[2]; nz_rc rc = arg_parse("required generic type, required generic value", string, args); if(rc != NZ_SUCCESS) return rc; char * type_str = (char *)args[0]; char * value_str = (char *)args[1]; const struct nz_typeclass * typeclass_p; nz_type * type_p; nz_obj * obj_p; rc = nz_context_create_type(context_p, &typeclass_p, &type_p, type_str); if(rc != NZ_SUCCESS) { free(type_str); free(value_str); return rc; } rc = typeclass_p->type_create_obj(type_p, &obj_p); if(rc != NZ_SUCCESS) { free(type_str); free(value_str); typeclass_p->type_destroy(type_p); return rc; } rc = typeclass_p->type_init_obj(type_p, obj_p, value_str); if(rc != NZ_SUCCESS) { free(type_str); free(value_str); typeclass_p->type_destroy_obj(type_p, obj_p); typeclass_p->type_destroy(type_p); return rc; } free(type_str); free(value_str); return constant_block_create_args(typeclass_p, type_p, obj_p, state_pp, info_p); }