topt.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. /*
  2. File autogenerated by gengetopt version 2.22.6
  3. generated with the following command:
  4. gengetopt -S --no-help --no-version --unamed-opts=FILE -i /home/mike/folder/studium_ms/semester_5/master_thesis/scm-ssi-probe-response/attack_implementation/zmap/src/topt.ggo -F /home/mike/folder/studium_ms/semester_5/master_thesis/scm-ssi-probe-response/attack_implementation/zmap/src/topt
  5. The developers of gengetopt consider the fixed text that goes in all
  6. gengetopt output files to be in the public domain:
  7. we make no copyright claims on it.
  8. */
  9. /* If we use autoconf. */
  10. #ifdef HAVE_CONFIG_H
  11. #include "config.h"
  12. #endif
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #ifndef FIX_UNUSED
  17. #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
  18. #endif
  19. #include <getopt.h>
  20. #include "/home/mike/folder/studium_ms/semester_5/master_thesis/scm-ssi-probe-response/attack_implementation/zmap/src/topt.h"
  21. const char *gengetopt_args_info_purpose = "A buffering output splitter";
  22. const char *gengetopt_args_info_usage = "Usage: ztee [OPTIONS]... [FILE]...";
  23. const char *gengetopt_args_info_versiontext = "";
  24. const char *gengetopt_args_info_description = "";
  25. const char *gengetopt_args_info_help[] = {
  26. "Basic arguments:",
  27. " --success-only Only write to stdout rows where success=1 or\n success=true",
  28. " -m, --monitor Print monitor output to stdout",
  29. " -u, --status-updates-file=monitor.csv\n File to write status updates in CSV format",
  30. " -l, --log-file=STRING File to log to",
  31. " -r, --raw Ignore input formatting",
  32. "\nAdditional options:",
  33. " -h, --help Print help and exit",
  34. " -V, --version Print version and exit",
  35. "\nExamples:\n zmap -p 80 -o - | ztee zmap.csv (save zmap output to zmap.csv and output\nall rows to stdout)\n zmap -p 80 --output-fields=* -o - | ztee -S zmap.csv (save all zmap output\nto zmap.csv, print successful rows to stdout)\n zmap -p 80 -o - | ztee -s status.csv zmap.csv (save zmap output to\nzmap.csv, write status updates to status.csv)",
  36. 0
  37. };
  38. typedef enum {ARG_NO
  39. , ARG_STRING
  40. } cmdline_parser_arg_type;
  41. static
  42. void clear_given (struct gengetopt_args_info *args_info);
  43. static
  44. void clear_args (struct gengetopt_args_info *args_info);
  45. static int
  46. cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
  47. struct cmdline_parser_params *params, const char *additional_error);
  48. struct line_list
  49. {
  50. char * string_arg;
  51. struct line_list * next;
  52. };
  53. static struct line_list *cmd_line_list = 0;
  54. static struct line_list *cmd_line_list_tmp = 0;
  55. static void
  56. free_cmd_list(void)
  57. {
  58. /* free the list of a previous call */
  59. if (cmd_line_list)
  60. {
  61. while (cmd_line_list) {
  62. cmd_line_list_tmp = cmd_line_list;
  63. cmd_line_list = cmd_line_list->next;
  64. free (cmd_line_list_tmp->string_arg);
  65. free (cmd_line_list_tmp);
  66. }
  67. }
  68. }
  69. static char *
  70. gengetopt_strdup (const char *s);
  71. static
  72. void clear_given (struct gengetopt_args_info *args_info)
  73. {
  74. args_info->success_only_given = 0 ;
  75. args_info->monitor_given = 0 ;
  76. args_info->status_updates_file_given = 0 ;
  77. args_info->log_file_given = 0 ;
  78. args_info->raw_given = 0 ;
  79. args_info->help_given = 0 ;
  80. args_info->version_given = 0 ;
  81. }
  82. static
  83. void clear_args (struct gengetopt_args_info *args_info)
  84. {
  85. FIX_UNUSED (args_info);
  86. args_info->status_updates_file_arg = NULL;
  87. args_info->status_updates_file_orig = NULL;
  88. args_info->log_file_arg = NULL;
  89. args_info->log_file_orig = NULL;
  90. }
  91. static
  92. void init_args_info(struct gengetopt_args_info *args_info)
  93. {
  94. args_info->success_only_help = gengetopt_args_info_help[1] ;
  95. args_info->monitor_help = gengetopt_args_info_help[2] ;
  96. args_info->status_updates_file_help = gengetopt_args_info_help[3] ;
  97. args_info->log_file_help = gengetopt_args_info_help[4] ;
  98. args_info->raw_help = gengetopt_args_info_help[5] ;
  99. args_info->help_help = gengetopt_args_info_help[7] ;
  100. args_info->version_help = gengetopt_args_info_help[8] ;
  101. }
  102. void
  103. cmdline_parser_print_version (void)
  104. {
  105. printf ("%s %s\n",
  106. (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
  107. CMDLINE_PARSER_VERSION);
  108. if (strlen(gengetopt_args_info_versiontext) > 0)
  109. printf("\n%s\n", gengetopt_args_info_versiontext);
  110. }
  111. static void print_help_common(void) {
  112. cmdline_parser_print_version ();
  113. if (strlen(gengetopt_args_info_purpose) > 0)
  114. printf("\n%s\n", gengetopt_args_info_purpose);
  115. if (strlen(gengetopt_args_info_usage) > 0)
  116. printf("\n%s\n", gengetopt_args_info_usage);
  117. printf("\n");
  118. if (strlen(gengetopt_args_info_description) > 0)
  119. printf("%s\n\n", gengetopt_args_info_description);
  120. }
  121. void
  122. cmdline_parser_print_help (void)
  123. {
  124. int i = 0;
  125. print_help_common();
  126. while (gengetopt_args_info_help[i])
  127. printf("%s\n", gengetopt_args_info_help[i++]);
  128. }
  129. void
  130. cmdline_parser_init (struct gengetopt_args_info *args_info)
  131. {
  132. clear_given (args_info);
  133. clear_args (args_info);
  134. init_args_info (args_info);
  135. args_info->inputs = 0;
  136. args_info->inputs_num = 0;
  137. }
  138. void
  139. cmdline_parser_params_init(struct cmdline_parser_params *params)
  140. {
  141. if (params)
  142. {
  143. params->override = 0;
  144. params->initialize = 1;
  145. params->check_required = 1;
  146. params->check_ambiguity = 0;
  147. params->print_errors = 1;
  148. }
  149. }
  150. struct cmdline_parser_params *
  151. cmdline_parser_params_create(void)
  152. {
  153. struct cmdline_parser_params *params =
  154. (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
  155. cmdline_parser_params_init(params);
  156. return params;
  157. }
  158. static void
  159. free_string_field (char **s)
  160. {
  161. if (*s)
  162. {
  163. free (*s);
  164. *s = 0;
  165. }
  166. }
  167. static void
  168. cmdline_parser_release (struct gengetopt_args_info *args_info)
  169. {
  170. unsigned int i;
  171. free_string_field (&(args_info->status_updates_file_arg));
  172. free_string_field (&(args_info->status_updates_file_orig));
  173. free_string_field (&(args_info->log_file_arg));
  174. free_string_field (&(args_info->log_file_orig));
  175. for (i = 0; i < args_info->inputs_num; ++i)
  176. free (args_info->inputs [i]);
  177. if (args_info->inputs_num)
  178. free (args_info->inputs);
  179. clear_given (args_info);
  180. }
  181. static void
  182. write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
  183. {
  184. FIX_UNUSED (values);
  185. if (arg) {
  186. fprintf(outfile, "%s=\"%s\"\n", opt, arg);
  187. } else {
  188. fprintf(outfile, "%s\n", opt);
  189. }
  190. }
  191. int
  192. cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
  193. {
  194. int i = 0;
  195. if (!outfile)
  196. {
  197. fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
  198. return EXIT_FAILURE;
  199. }
  200. if (args_info->success_only_given)
  201. write_into_file(outfile, "success-only", 0, 0 );
  202. if (args_info->monitor_given)
  203. write_into_file(outfile, "monitor", 0, 0 );
  204. if (args_info->status_updates_file_given)
  205. write_into_file(outfile, "status-updates-file", args_info->status_updates_file_orig, 0);
  206. if (args_info->log_file_given)
  207. write_into_file(outfile, "log-file", args_info->log_file_orig, 0);
  208. if (args_info->raw_given)
  209. write_into_file(outfile, "raw", 0, 0 );
  210. if (args_info->help_given)
  211. write_into_file(outfile, "help", 0, 0 );
  212. if (args_info->version_given)
  213. write_into_file(outfile, "version", 0, 0 );
  214. i = EXIT_SUCCESS;
  215. return i;
  216. }
  217. int
  218. cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
  219. {
  220. FILE *outfile;
  221. int i = 0;
  222. outfile = fopen(filename, "w");
  223. if (!outfile)
  224. {
  225. fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
  226. return EXIT_FAILURE;
  227. }
  228. i = cmdline_parser_dump(outfile, args_info);
  229. fclose (outfile);
  230. return i;
  231. }
  232. void
  233. cmdline_parser_free (struct gengetopt_args_info *args_info)
  234. {
  235. cmdline_parser_release (args_info);
  236. }
  237. /** @brief replacement of strdup, which is not standard */
  238. char *
  239. gengetopt_strdup (const char *s)
  240. {
  241. char *result = 0;
  242. if (!s)
  243. return result;
  244. result = (char*)malloc(strlen(s) + 1);
  245. if (result == (char*)0)
  246. return (char*)0;
  247. strcpy(result, s);
  248. return result;
  249. }
  250. int
  251. cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
  252. {
  253. return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
  254. }
  255. int
  256. cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
  257. struct cmdline_parser_params *params)
  258. {
  259. int result;
  260. result = cmdline_parser_internal (argc, argv, args_info, params, 0);
  261. if (result == EXIT_FAILURE)
  262. {
  263. cmdline_parser_free (args_info);
  264. exit (EXIT_FAILURE);
  265. }
  266. return result;
  267. }
  268. int
  269. cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
  270. {
  271. int result;
  272. struct cmdline_parser_params params;
  273. params.override = override;
  274. params.initialize = initialize;
  275. params.check_required = check_required;
  276. params.check_ambiguity = 0;
  277. params.print_errors = 1;
  278. result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
  279. if (result == EXIT_FAILURE)
  280. {
  281. cmdline_parser_free (args_info);
  282. exit (EXIT_FAILURE);
  283. }
  284. return result;
  285. }
  286. int
  287. cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
  288. {
  289. FIX_UNUSED (args_info);
  290. FIX_UNUSED (prog_name);
  291. return EXIT_SUCCESS;
  292. }
  293. static char *package_name = 0;
  294. /**
  295. * @brief updates an option
  296. * @param field the generic pointer to the field to update
  297. * @param orig_field the pointer to the orig field
  298. * @param field_given the pointer to the number of occurrence of this option
  299. * @param prev_given the pointer to the number of occurrence already seen
  300. * @param value the argument for this option (if null no arg was specified)
  301. * @param possible_values the possible values for this option (if specified)
  302. * @param default_value the default value (in case the option only accepts fixed values)
  303. * @param arg_type the type of this option
  304. * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
  305. * @param override @see cmdline_parser_params.override
  306. * @param no_free whether to free a possible previous value
  307. * @param multiple_option whether this is a multiple option
  308. * @param long_opt the corresponding long option
  309. * @param short_opt the corresponding short option (or '-' if none)
  310. * @param additional_error possible further error specification
  311. */
  312. static
  313. int update_arg(void *field, char **orig_field,
  314. unsigned int *field_given, unsigned int *prev_given,
  315. char *value, const char *possible_values[],
  316. const char *default_value,
  317. cmdline_parser_arg_type arg_type,
  318. int check_ambiguity, int override,
  319. int no_free, int multiple_option,
  320. const char *long_opt, char short_opt,
  321. const char *additional_error)
  322. {
  323. char *stop_char = 0;
  324. const char *val = value;
  325. int found;
  326. char **string_field;
  327. FIX_UNUSED (field);
  328. stop_char = 0;
  329. found = 0;
  330. if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
  331. {
  332. if (short_opt != '-')
  333. fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
  334. package_name, long_opt, short_opt,
  335. (additional_error ? additional_error : ""));
  336. else
  337. fprintf (stderr, "%s: `--%s' option given more than once%s\n",
  338. package_name, long_opt,
  339. (additional_error ? additional_error : ""));
  340. return 1; /* failure */
  341. }
  342. FIX_UNUSED (default_value);
  343. if (field_given && *field_given && ! override)
  344. return 0;
  345. if (prev_given)
  346. (*prev_given)++;
  347. if (field_given)
  348. (*field_given)++;
  349. if (possible_values)
  350. val = possible_values[found];
  351. switch(arg_type) {
  352. case ARG_STRING:
  353. if (val) {
  354. string_field = (char **)field;
  355. if (!no_free && *string_field)
  356. free (*string_field); /* free previous string */
  357. *string_field = gengetopt_strdup (val);
  358. }
  359. break;
  360. default:
  361. break;
  362. };
  363. /* store the original value */
  364. switch(arg_type) {
  365. case ARG_NO:
  366. break;
  367. default:
  368. if (value && orig_field) {
  369. if (no_free) {
  370. *orig_field = value;
  371. } else {
  372. if (*orig_field)
  373. free (*orig_field); /* free previous string */
  374. *orig_field = gengetopt_strdup (value);
  375. }
  376. }
  377. };
  378. return 0; /* OK */
  379. }
  380. int
  381. cmdline_parser_internal (
  382. int argc, char **argv, struct gengetopt_args_info *args_info,
  383. struct cmdline_parser_params *params, const char *additional_error)
  384. {
  385. int c; /* Character of the parsed option. */
  386. int error_occurred = 0;
  387. struct gengetopt_args_info local_args_info;
  388. int override;
  389. int initialize;
  390. int check_required;
  391. int check_ambiguity;
  392. package_name = argv[0];
  393. override = params->override;
  394. initialize = params->initialize;
  395. check_required = params->check_required;
  396. check_ambiguity = params->check_ambiguity;
  397. if (initialize)
  398. cmdline_parser_init (args_info);
  399. cmdline_parser_init (&local_args_info);
  400. optarg = 0;
  401. optind = 0;
  402. opterr = params->print_errors;
  403. optopt = '?';
  404. while (1)
  405. {
  406. int option_index = 0;
  407. static struct option long_options[] = {
  408. { "success-only", 0, NULL, 0 },
  409. { "monitor", 0, NULL, 'm' },
  410. { "status-updates-file", 1, NULL, 'u' },
  411. { "log-file", 1, NULL, 'l' },
  412. { "raw", 0, NULL, 'r' },
  413. { "help", 0, NULL, 'h' },
  414. { "version", 0, NULL, 'V' },
  415. { 0, 0, 0, 0 }
  416. };
  417. c = getopt_long (argc, argv, "mu:l:rhV", long_options, &option_index);
  418. if (c == -1) break; /* Exit from `while (1)' loop. */
  419. switch (c)
  420. {
  421. case 'm': /* Print monitor output to stdout. */
  422. if (update_arg( 0 ,
  423. 0 , &(args_info->monitor_given),
  424. &(local_args_info.monitor_given), optarg, 0, 0, ARG_NO,
  425. check_ambiguity, override, 0, 0,
  426. "monitor", 'm',
  427. additional_error))
  428. goto failure;
  429. break;
  430. case 'u': /* File to write status updates in CSV format. */
  431. if (update_arg( (void *)&(args_info->status_updates_file_arg),
  432. &(args_info->status_updates_file_orig), &(args_info->status_updates_file_given),
  433. &(local_args_info.status_updates_file_given), optarg, 0, 0, ARG_STRING,
  434. check_ambiguity, override, 0, 0,
  435. "status-updates-file", 'u',
  436. additional_error))
  437. goto failure;
  438. break;
  439. case 'l': /* File to log to. */
  440. if (update_arg( (void *)&(args_info->log_file_arg),
  441. &(args_info->log_file_orig), &(args_info->log_file_given),
  442. &(local_args_info.log_file_given), optarg, 0, 0, ARG_STRING,
  443. check_ambiguity, override, 0, 0,
  444. "log-file", 'l',
  445. additional_error))
  446. goto failure;
  447. break;
  448. case 'r': /* Ignore input formatting. */
  449. if (update_arg( 0 ,
  450. 0 , &(args_info->raw_given),
  451. &(local_args_info.raw_given), optarg, 0, 0, ARG_NO,
  452. check_ambiguity, override, 0, 0,
  453. "raw", 'r',
  454. additional_error))
  455. goto failure;
  456. break;
  457. case 'h': /* Print help and exit. */
  458. if (update_arg( 0 ,
  459. 0 , &(args_info->help_given),
  460. &(local_args_info.help_given), optarg, 0, 0, ARG_NO,
  461. check_ambiguity, override, 0, 0,
  462. "help", 'h',
  463. additional_error))
  464. goto failure;
  465. break;
  466. case 'V': /* Print version and exit. */
  467. if (update_arg( 0 ,
  468. 0 , &(args_info->version_given),
  469. &(local_args_info.version_given), optarg, 0, 0, ARG_NO,
  470. check_ambiguity, override, 0, 0,
  471. "version", 'V',
  472. additional_error))
  473. goto failure;
  474. break;
  475. case 0: /* Long option with no short option */
  476. /* Only write to stdout rows where success=1 or success=true. */
  477. if (strcmp (long_options[option_index].name, "success-only") == 0)
  478. {
  479. if (update_arg( 0 ,
  480. 0 , &(args_info->success_only_given),
  481. &(local_args_info.success_only_given), optarg, 0, 0, ARG_NO,
  482. check_ambiguity, override, 0, 0,
  483. "success-only", '-',
  484. additional_error))
  485. goto failure;
  486. }
  487. break;
  488. case '?': /* Invalid option. */
  489. /* `getopt_long' already printed an error message. */
  490. goto failure;
  491. default: /* bug: option not considered. */
  492. fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
  493. abort ();
  494. } /* switch */
  495. } /* while */
  496. cmdline_parser_release (&local_args_info);
  497. if ( error_occurred )
  498. return (EXIT_FAILURE);
  499. if (optind < argc)
  500. {
  501. int i = 0 ;
  502. int found_prog_name = 0;
  503. /* whether program name, i.e., argv[0], is in the remaining args
  504. (this may happen with some implementations of getopt,
  505. but surely not with the one included by gengetopt) */
  506. i = optind;
  507. while (i < argc)
  508. if (argv[i++] == argv[0]) {
  509. found_prog_name = 1;
  510. break;
  511. }
  512. i = 0;
  513. args_info->inputs_num = argc - optind - found_prog_name;
  514. args_info->inputs =
  515. (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
  516. while (optind < argc)
  517. if (argv[optind++] != argv[0])
  518. args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
  519. }
  520. return 0;
  521. failure:
  522. cmdline_parser_release (&local_args_info);
  523. return (EXIT_FAILURE);
  524. }
  525. static unsigned int
  526. cmdline_parser_create_argv(const char *cmdline_, char ***argv_ptr, const char *prog_name)
  527. {
  528. char *cmdline, *p;
  529. size_t n = 0, j;
  530. int i;
  531. if (prog_name) {
  532. cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
  533. cmd_line_list_tmp->next = cmd_line_list;
  534. cmd_line_list = cmd_line_list_tmp;
  535. cmd_line_list->string_arg = gengetopt_strdup (prog_name);
  536. ++n;
  537. }
  538. cmdline = gengetopt_strdup(cmdline_);
  539. p = cmdline;
  540. while (p && strlen(p))
  541. {
  542. j = strcspn(p, " \t");
  543. ++n;
  544. if (j && j < strlen(p))
  545. {
  546. p[j] = '\0';
  547. cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
  548. cmd_line_list_tmp->next = cmd_line_list;
  549. cmd_line_list = cmd_line_list_tmp;
  550. cmd_line_list->string_arg = gengetopt_strdup (p);
  551. p += (j+1);
  552. p += strspn(p, " \t");
  553. }
  554. else
  555. {
  556. cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
  557. cmd_line_list_tmp->next = cmd_line_list;
  558. cmd_line_list = cmd_line_list_tmp;
  559. cmd_line_list->string_arg = gengetopt_strdup (p);
  560. break;
  561. }
  562. }
  563. *argv_ptr = (char **) malloc((n + 1) * sizeof(char *));
  564. cmd_line_list_tmp = cmd_line_list;
  565. for (i = (n-1); i >= 0; --i)
  566. {
  567. (*argv_ptr)[i] = cmd_line_list_tmp->string_arg;
  568. cmd_line_list_tmp = cmd_line_list_tmp->next;
  569. }
  570. (*argv_ptr)[n] = 0;
  571. free(cmdline);
  572. return n;
  573. }
  574. int
  575. cmdline_parser_string(const char *cmdline, struct gengetopt_args_info *args_info, const char *prog_name)
  576. {
  577. return cmdline_parser_string2(cmdline, args_info, prog_name, 0, 1, 1);
  578. }
  579. int
  580. cmdline_parser_string2(const char *cmdline, struct gengetopt_args_info *args_info, const char *prog_name,
  581. int override, int initialize, int check_required)
  582. {
  583. struct cmdline_parser_params params;
  584. params.override = override;
  585. params.initialize = initialize;
  586. params.check_required = check_required;
  587. params.check_ambiguity = 0;
  588. params.print_errors = 1;
  589. return cmdline_parser_string_ext(cmdline, args_info, prog_name, &params);
  590. }
  591. int
  592. cmdline_parser_string_ext(const char *cmdline, struct gengetopt_args_info *args_info, const char *prog_name,
  593. struct cmdline_parser_params *params)
  594. {
  595. char **argv_ptr = 0;
  596. int result;
  597. unsigned int argc;
  598. argc = cmdline_parser_create_argv(cmdline, &argv_ptr, prog_name);
  599. result =
  600. cmdline_parser_internal (argc, argv_ptr, args_info, params, 0);
  601. if (argv_ptr)
  602. {
  603. free (argv_ptr);
  604. }
  605. free_cmd_list();
  606. if (result == EXIT_FAILURE)
  607. {
  608. cmdline_parser_free (args_info);
  609. exit (EXIT_FAILURE);
  610. }
  611. return result;
  612. }