2 * File automatically generated by
3 * gengen 1.4.1 by Lorenzo Bettini
4 * http://www.gnu.org/software/gengen
10 c_source_gen_class::generate_c_source(ostream &stream, unsigned int indent)
12 string indent_str (indent, ' ');
18 stream << " File autogenerated by gengetopt ";
19 generate_string (generator_version, stream, indent + indent_str.length ());
22 stream << " generated with the following command:";
27 generate_string (command_line, stream, indent + indent_str.length ());
33 stream << " The developers of gengetopt consider the fixed text that goes in all";
36 stream << " gengetopt output files to be in the public domain:";
39 stream << " we make no copyright claims on it.";
47 stream << "/* If we use autoconf. */";
50 stream << "#ifdef HAVE_CONFIG_H";
53 stream << "#include \"config.h\"";
61 stream << "#include <stdio.h>";
64 stream << "#include <stdlib.h>";
67 stream << "#include <string.h>";
72 stream << "#ifndef FIX_UNUSED";
75 stream << "#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */";
83 if (( ! include_getopt ))
85 stream << "#include <getopt.h>";
91 stream << "#include \"";
92 generate_string (source_name, stream, indent + indent_str.length ());
94 generate_string (header_file_ext, stream, indent + indent_str.length ());
100 stream << "const char *";
101 generate_string (args_info, stream, indent + indent_str.length ());
102 stream << "_purpose = \"";
103 generate_string (purpose, stream, indent + indent_str.length ());
106 stream << indent_str;
108 stream << indent_str;
109 stream << "const char *";
110 generate_string (args_info, stream, indent + indent_str.length ());
111 stream << "_usage = \"Usage: ";
115 generate_string (package_var_name, stream, indent + indent_str.length ());
118 generate_string (usage_string, stream, indent + indent_str.length ());
121 stream << indent_str;
123 stream << indent_str;
124 stream << "const char *";
125 generate_string (args_info, stream, indent + indent_str.length ());
126 stream << "_description = \"";
127 generate_string (description, stream, indent + indent_str.length ());
130 stream << indent_str;
132 stream << indent_str;
133 if (( has_hidden || has_details ))
137 stream << "const char *";
138 generate_string (args_info, stream, indent + indent_str.length ());
139 stream << "_detailed_help[] = {";
141 stream << indent_str;
144 if (detailed_help_option_print.size () > 0)
145 generate_string (detailed_help_option_print, stream, indent + indent_str.length ());
147 generate_detailed_help_option_print (stream, indent + indent_str.length ());
151 stream << indent_str;
154 stream << indent_str;
157 stream << "static void";
159 stream << indent_str;
160 stream << "init_full_help_array(void)";
162 stream << indent_str;
165 stream << indent_str;
168 if (full_help_option_print.size () > 0)
169 generate_string (full_help_option_print, stream, indent + indent_str.length ());
171 generate_full_help_option_print (stream, indent + indent_str.length ());
174 stream << indent_str;
177 stream << indent_str;
179 stream << indent_str;
180 stream << "const char *";
181 generate_string (args_info, stream, indent + indent_str.length ());
182 stream << "_full_help[";
183 generate_string (help_string_num, stream, indent + indent_str.length ());
186 stream << indent_str;
193 stream << "const char *";
194 generate_string (args_info, stream, indent + indent_str.length ());
195 stream << "_full_help[] = {";
197 stream << indent_str;
200 if (full_help_option_print.size () > 0)
201 generate_string (full_help_option_print, stream, indent + indent_str.length ());
203 generate_full_help_option_print (stream, indent + indent_str.length ());
207 stream << indent_str;
210 stream << indent_str;
214 stream << indent_str;
215 stream << "static void";
217 stream << indent_str;
218 stream << "init_help_array(void)";
220 stream << indent_str;
223 stream << indent_str;
226 if (help_option_print.size () > 0)
227 generate_string (help_option_print, stream, indent + indent_str.length ());
229 generate_help_option_print (stream, indent + indent_str.length ());
232 stream << indent_str;
235 stream << indent_str;
237 stream << indent_str;
238 stream << "const char *";
239 generate_string (args_info, stream, indent + indent_str.length ());
241 generate_string (help_string_num, stream, indent + indent_str.length ());
244 stream << indent_str;
248 stream << "const char *";
249 generate_string (args_info, stream, indent + indent_str.length ());
250 stream << "_help[] = {";
252 stream << indent_str;
255 if (help_option_print.size () > 0)
256 generate_string (help_option_print, stream, indent + indent_str.length ());
258 generate_help_option_print (stream, indent + indent_str.length ());
262 stream << indent_str;
265 stream << indent_str;
268 stream << indent_str;
269 stream << "typedef enum {ARG_NO";
271 stream << indent_str;
274 stream << " , ARG_FLAG";
276 stream << indent_str;
280 stream << " , ARG_STRING";
282 stream << indent_str;
286 stream << " , ARG_INT";
288 stream << indent_str;
292 stream << " , ARG_SHORT";
294 stream << indent_str;
298 stream << " , ARG_LONG";
300 stream << indent_str;
304 stream << " , ARG_FLOAT";
306 stream << indent_str;
310 stream << " , ARG_DOUBLE";
312 stream << indent_str;
314 if (has_arg_longdouble)
316 stream << " , ARG_LONGDOUBLE";
318 stream << indent_str;
320 if (has_arg_longlong)
322 stream << " , ARG_LONGLONG";
324 stream << indent_str;
328 stream << " , ARG_ENUM";
330 stream << indent_str;
333 generate_string (parser_name, stream, indent + indent_str.length ());
334 stream << "_arg_type;";
336 stream << indent_str;
338 stream << indent_str;
341 stream << indent_str;
342 stream << "void clear_given (struct ";
343 generate_string (args_info, stream, indent + indent_str.length ());
344 stream << " *args_info);";
346 stream << indent_str;
349 stream << indent_str;
350 stream << "void clear_args (struct ";
351 generate_string (args_info, stream, indent + indent_str.length ());
352 stream << " *args_info);";
354 stream << indent_str;
356 stream << indent_str;
357 stream << "static int";
359 stream << indent_str;
360 generate_string (parser_name, stream, indent + indent_str.length ());
361 stream << "_internal (int argc, char **argv, struct ";
362 generate_string (args_info, stream, indent + indent_str.length ());
363 stream << " *args_info,";
365 stream << indent_str;
366 stream << " struct ";
367 generate_string (parser_name, stream, indent + indent_str.length ());
368 stream << "_params *params, const char *additional_error);";
370 stream << indent_str;
372 stream << indent_str;
373 if (check_required_options)
375 stream << "static int";
377 stream << indent_str;
378 generate_string (parser_name, stream, indent + indent_str.length ());
379 stream << "_required2 (struct ";
380 generate_string (args_info, stream, indent + indent_str.length ());
381 stream << " *args_info, const char *prog_name, const char *additional_error);";
383 stream << indent_str;
387 stream << "struct line_list";
389 stream << indent_str;
392 stream << indent_str;
393 stream << " char * string_arg;";
395 stream << indent_str;
396 stream << " struct line_list * next;";
398 stream << indent_str;
401 stream << indent_str;
403 stream << indent_str;
404 stream << "static struct line_list *cmd_line_list = 0;";
406 stream << indent_str;
407 stream << "static struct line_list *cmd_line_list_tmp = 0;";
409 stream << indent_str;
411 stream << indent_str;
412 stream << "static void";
414 stream << indent_str;
415 stream << "free_cmd_list(void)";
417 stream << indent_str;
420 stream << indent_str;
421 stream << " /* free the list of a previous call */";
423 stream << indent_str;
424 stream << " if (cmd_line_list)";
426 stream << indent_str;
429 stream << indent_str;
430 stream << " while (cmd_line_list) {";
432 stream << indent_str;
433 stream << " cmd_line_list_tmp = cmd_line_list;";
435 stream << indent_str;
436 stream << " cmd_line_list = cmd_line_list->next;";
438 stream << indent_str;
439 stream << " free (cmd_line_list_tmp->string_arg);";
441 stream << indent_str;
442 stream << " free (cmd_line_list_tmp);";
444 stream << indent_str;
447 stream << indent_str;
450 stream << indent_str;
453 stream << indent_str;
455 stream << indent_str;
458 stream << indent_str;
459 if (option_values.size () > 0)
460 generate_string (option_values, stream, indent + indent_str.length ());
462 generate_option_values (stream, indent + indent_str.length ());
463 stream << indent_str;
464 if (do_generate_strdup)
466 stream << "static char *";
468 stream << indent_str;
469 stream << "gengetopt_strdup (const char *s);";
471 stream << indent_str;
473 stream << indent_str;
477 stream << indent_str;
478 stream << "void clear_given (struct ";
479 generate_string (args_info, stream, indent + indent_str.length ());
480 stream << " *args_info)";
482 stream << indent_str;
485 stream << indent_str;
487 if (given_init.size () > 0)
488 generate_string (given_init, stream, indent + indent_str.length ());
490 generate_given_init (stream, indent + indent_str.length ());
492 stream << indent_str;
495 stream << indent_str;
497 stream << indent_str;
500 stream << indent_str;
501 stream << "void clear_args (struct ";
502 generate_string (args_info, stream, indent + indent_str.length ());
503 stream << " *args_info)";
505 stream << indent_str;
508 stream << indent_str;
509 stream << " FIX_UNUSED (args_info);";
511 stream << indent_str;
514 if (clear_arg.size () > 0)
515 generate_string (clear_arg, stream, indent + indent_str.length ());
517 generate_clear_arg (stream, indent + indent_str.length ());
520 stream << indent_str;
523 stream << indent_str;
525 stream << indent_str;
528 stream << indent_str;
529 stream << "void init_args_info(struct ";
530 generate_string (args_info, stream, indent + indent_str.length ());
531 stream << " *args_info)";
533 stream << indent_str;
536 stream << indent_str;
537 if (( has_hidden && has_details ))
539 stream << " init_full_help_array(); ";
542 stream << indent_str;
543 if (( has_hidden || has_details ))
545 stream << " init_help_array(); ";
548 stream << indent_str;
551 if (init_args_info.size () > 0)
552 generate_string (init_args_info, stream, indent + indent_str.length ());
554 generate_init_args_info (stream, indent + indent_str.length ());
557 stream << indent_str;
560 stream << indent_str;
562 stream << indent_str;
565 stream << indent_str;
566 generate_string (parser_name, stream, indent + indent_str.length ());
567 stream << "_print_version (void)";
569 stream << indent_str;
572 stream << indent_str;
573 stream << " printf (\"%s %s\\n\",";
575 stream << indent_str;
576 stream << " (strlen(";
577 generate_string (package_var_name, stream, indent + indent_str.length ());
578 stream << "_NAME) ? ";
579 generate_string (package_var_name, stream, indent + indent_str.length ());
580 stream << "_NAME : ";
581 generate_string (package_var_name, stream, indent + indent_str.length ());
584 stream << indent_str;
587 generate_string (version_var_name, stream, indent + indent_str.length ());
591 stream << indent_str;
594 stream << indent_str;
596 stream << indent_str;
597 stream << "static void print_help_common(void) {";
599 stream << indent_str;
602 generate_string (parser_name, stream, indent + indent_str.length ());
603 stream << "_print_version ();";
606 stream << indent_str;
608 stream << indent_str;
609 stream << " if (strlen(";
610 generate_string (args_info, stream, indent + indent_str.length ());
611 stream << "_purpose) > 0)";
613 stream << indent_str;
614 stream << " printf(\"\\n%s\\n\", ";
615 generate_string (args_info, stream, indent + indent_str.length ());
616 stream << "_purpose);";
618 stream << indent_str;
620 stream << indent_str;
621 stream << " if (strlen(";
622 generate_string (args_info, stream, indent + indent_str.length ());
623 stream << "_usage) > 0)";
625 stream << indent_str;
626 stream << " printf(\"\\n%s\\n\", ";
627 generate_string (args_info, stream, indent + indent_str.length ());
628 stream << "_usage);";
630 stream << indent_str;
632 stream << indent_str;
633 stream << " printf(\"\\n\");";
635 stream << indent_str;
637 stream << indent_str;
638 stream << " if (strlen(";
639 generate_string (args_info, stream, indent + indent_str.length ());
640 stream << "_description) > 0)";
642 stream << indent_str;
643 stream << " printf(\"%s\\n\\n\", ";
644 generate_string (args_info, stream, indent + indent_str.length ());
645 stream << "_description);";
647 stream << indent_str;
650 stream << indent_str;
652 stream << indent_str;
655 stream << indent_str;
656 generate_string (parser_name, stream, indent + indent_str.length ());
657 stream << "_print_help (void)";
659 stream << indent_str;
662 stream << indent_str;
663 stream << " int i = 0;";
665 stream << indent_str;
666 stream << " print_help_common();";
668 stream << indent_str;
669 stream << " while (";
670 generate_string (args_info, stream, indent + indent_str.length ());
671 stream << "_help[i])";
673 stream << indent_str;
674 stream << " printf(\"%s\\n\", ";
675 generate_string (args_info, stream, indent + indent_str.length ());
676 stream << "_help[i++]);";
678 stream << indent_str;
681 stream << indent_str;
683 stream << indent_str;
688 stream << indent_str;
689 generate_string (parser_name, stream, indent + indent_str.length ());
690 stream << "_print_full_help (void)";
692 stream << indent_str;
695 stream << indent_str;
696 stream << " int i = 0;";
698 stream << indent_str;
699 stream << " print_help_common();";
701 stream << indent_str;
702 stream << " while (";
703 generate_string (args_info, stream, indent + indent_str.length ());
704 stream << "_full_help[i])";
706 stream << indent_str;
707 stream << " printf(\"%s\\n\", ";
708 generate_string (args_info, stream, indent + indent_str.length ());
709 stream << "_full_help[i++]);";
711 stream << indent_str;
714 stream << indent_str;
716 stream << indent_str;
722 stream << indent_str;
723 generate_string (parser_name, stream, indent + indent_str.length ());
724 stream << "_print_detailed_help (void)";
726 stream << indent_str;
729 stream << indent_str;
730 stream << " int i = 0;";
732 stream << indent_str;
733 stream << " print_help_common();";
735 stream << indent_str;
736 stream << " while (";
737 generate_string (args_info, stream, indent + indent_str.length ());
738 stream << "_detailed_help[i])";
740 stream << indent_str;
741 stream << " printf(\"%s\\n\", ";
742 generate_string (args_info, stream, indent + indent_str.length ());
743 stream << "_detailed_help[i++]);";
745 stream << indent_str;
748 stream << indent_str;
750 stream << indent_str;
754 stream << indent_str;
755 generate_string (parser_name, stream, indent + indent_str.length ());
756 stream << "_init (struct ";
757 generate_string (args_info, stream, indent + indent_str.length ());
758 stream << " *args_info)";
760 stream << indent_str;
763 stream << indent_str;
764 stream << " clear_given (args_info);";
766 stream << indent_str;
767 stream << " clear_args (args_info);";
769 stream << indent_str;
770 stream << " init_args_info (args_info);";
772 stream << indent_str;
776 stream << indent_str;
777 stream << " args_info->inputs = 0;";
779 stream << indent_str;
780 stream << " args_info->inputs_num = 0;";
782 stream << indent_str;
786 stream << indent_str;
788 stream << indent_str;
791 stream << indent_str;
792 generate_string (parser_name, stream, indent + indent_str.length ());
793 stream << "_params_init(struct ";
794 generate_string (parser_name, stream, indent + indent_str.length ());
795 stream << "_params *params)";
797 stream << indent_str;
800 stream << indent_str;
801 stream << " if (params)";
803 stream << indent_str;
806 stream << indent_str;
807 stream << " params->override = 0;";
809 stream << indent_str;
810 stream << " params->initialize = 1;";
812 stream << indent_str;
813 stream << " params->check_required = 1;";
815 stream << indent_str;
816 stream << " params->check_ambiguity = 0;";
818 stream << indent_str;
819 stream << " params->print_errors = 1;";
821 stream << indent_str;
824 stream << indent_str;
827 stream << indent_str;
829 stream << indent_str;
831 generate_string (parser_name, stream, indent + indent_str.length ());
832 stream << "_params *";
834 stream << indent_str;
835 generate_string (parser_name, stream, indent + indent_str.length ());
836 stream << "_params_create(void)";
838 stream << indent_str;
841 stream << indent_str;
842 stream << " struct ";
843 generate_string (parser_name, stream, indent + indent_str.length ());
844 stream << "_params *params = ";
846 stream << indent_str;
847 stream << " (struct ";
848 generate_string (parser_name, stream, indent + indent_str.length ());
849 stream << "_params *)malloc(sizeof(struct ";
850 generate_string (parser_name, stream, indent + indent_str.length ());
851 stream << "_params));";
853 stream << indent_str;
856 generate_string (parser_name, stream, indent + indent_str.length ());
857 stream << "_params_init(params); ";
860 stream << indent_str;
861 stream << " return params;";
863 stream << indent_str;
866 stream << indent_str;
868 stream << indent_str;
869 if (has_typed_options)
871 stream << "static void";
873 stream << indent_str;
874 stream << "free_string_field (char **s)";
876 stream << indent_str;
879 stream << indent_str;
880 stream << " if (*s)";
882 stream << indent_str;
885 stream << indent_str;
886 stream << " free (*s);";
888 stream << indent_str;
889 stream << " *s = 0;";
891 stream << indent_str;
894 stream << indent_str;
897 stream << indent_str;
900 stream << indent_str;
901 if (multiple_token_functions)
905 stream << "brief generic value variable */";
907 stream << indent_str;
908 stream << "union generic_value {";
910 stream << indent_str;
911 if (( has_arg_int || has_arg_enum ))
913 stream << " int int_arg;";
915 stream << indent_str;
919 stream << " short short_arg;";
921 stream << indent_str;
925 stream << " long long_arg;";
927 stream << indent_str;
931 stream << " float float_arg;";
933 stream << indent_str;
937 stream << " double double_arg;";
939 stream << indent_str;
941 if (has_arg_longdouble)
943 stream << " long double longdouble_arg;";
945 stream << indent_str;
947 if (has_arg_longlong)
949 stream << "#ifdef HAVE_LONG_LONG";
951 stream << indent_str;
952 stream << " long long int longlong_arg;";
954 stream << indent_str;
957 stream << indent_str;
958 stream << " long longlong_arg;";
960 stream << indent_str;
963 stream << indent_str;
965 stream << " char *string_arg;";
967 stream << indent_str;
968 stream << " const char *default_string_arg;";
970 stream << indent_str;
973 stream << indent_str;
975 stream << indent_str;
978 stream << "brief holds temporary values for multiple options */";
980 stream << indent_str;
981 stream << "struct generic_list";
983 stream << indent_str;
986 stream << indent_str;
987 stream << " union generic_value arg;";
989 stream << indent_str;
990 stream << " char *orig;";
992 stream << indent_str;
993 stream << " struct generic_list *next;";
995 stream << indent_str;
998 stream << indent_str;
1000 stream << indent_str;
1003 stream << indent_str;
1006 stream << "brief add a node at the head of the list ";
1008 stream << indent_str;
1011 stream << indent_str;
1012 stream << "static void add_node(struct generic_list **list) {";
1014 stream << indent_str;
1015 stream << " struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list));";
1017 stream << indent_str;
1018 stream << " new_node->next = *list;";
1020 stream << indent_str;
1021 stream << " *list = new_node;";
1023 stream << indent_str;
1024 stream << " new_node->arg.string_arg = 0;";
1026 stream << indent_str;
1027 stream << " new_node->orig = 0;";
1029 stream << indent_str;
1032 stream << indent_str;
1034 stream << indent_str;
1035 if (( ( ! multiple_options_all_string ) && multiple_token_functions ))
1039 stream << indent_str;
1040 stream << " * The passed arg parameter is NOT set to 0 from this function";
1042 stream << indent_str;
1045 stream << indent_str;
1046 stream << "static void";
1048 stream << indent_str;
1049 stream << "free_multiple_field(unsigned int len, void *arg, char ***orig)";
1051 stream << indent_str;
1054 stream << indent_str;
1055 stream << " unsigned int i;";
1057 stream << indent_str;
1058 stream << " if (arg) {";
1060 stream << indent_str;
1061 stream << " for (i = 0; i < len; ++i)";
1063 stream << indent_str;
1066 stream << indent_str;
1067 stream << " free_string_field(&((*orig)[i]));";
1069 stream << indent_str;
1072 stream << indent_str;
1074 stream << indent_str;
1075 stream << " free (arg);";
1077 stream << indent_str;
1078 stream << " free (*orig);";
1080 stream << indent_str;
1081 stream << " *orig = 0;";
1083 stream << indent_str;
1086 stream << indent_str;
1089 stream << indent_str;
1092 stream << indent_str;
1093 if (multiple_options_string)
1095 stream << "static void";
1097 stream << indent_str;
1098 stream << "free_multiple_string_field(unsigned int len, char ***arg, char ***orig)";
1100 stream << indent_str;
1103 stream << indent_str;
1104 stream << " unsigned int i;";
1106 stream << indent_str;
1107 stream << " if (*arg) {";
1109 stream << indent_str;
1110 stream << " for (i = 0; i < len; ++i)";
1112 stream << indent_str;
1115 stream << indent_str;
1116 stream << " free_string_field(&((*arg)[i]));";
1118 stream << indent_str;
1119 stream << " free_string_field(&((*orig)[i]));";
1121 stream << indent_str;
1124 stream << indent_str;
1125 stream << " free_string_field(&((*arg)[0])); /* free default string */";
1127 stream << indent_str;
1129 stream << indent_str;
1130 stream << " free (*arg);";
1132 stream << indent_str;
1133 stream << " *arg = 0;";
1135 stream << indent_str;
1136 stream << " free (*orig);";
1138 stream << indent_str;
1139 stream << " *orig = 0;";
1141 stream << indent_str;
1144 stream << indent_str;
1147 stream << indent_str;
1151 stream << indent_str;
1152 stream << "static void";
1154 stream << indent_str;
1155 generate_string (parser_name, stream, indent + indent_str.length ());
1156 stream << "_release (struct ";
1157 generate_string (args_info, stream, indent + indent_str.length ());
1158 stream << " *args_info)";
1160 stream << indent_str;
1163 stream << indent_str;
1166 stream << " unsigned int i;";
1169 stream << indent_str;
1172 if (free.size () > 0)
1173 generate_string (free, stream, indent + indent_str.length ());
1175 generate_free (stream, indent + indent_str.length ());
1178 stream << indent_str;
1183 stream << indent_str;
1186 stream << " for (i = 0; i < args_info->inputs_num; ++i)";
1188 stream << indent_str;
1189 stream << " free (args_info->inputs [i]);";
1191 stream << indent_str;
1193 stream << indent_str;
1194 stream << " if (args_info->inputs_num)";
1196 stream << indent_str;
1197 stream << " free (args_info->inputs);";
1199 stream << indent_str;
1202 stream << indent_str;
1203 stream << " clear_given (args_info);";
1205 stream << indent_str;
1208 stream << indent_str;
1210 stream << indent_str;
1211 if (check_possible_values)
1215 stream << indent_str;
1218 stream << "param val the value to check";
1220 stream << indent_str;
1223 stream << "param values the possible values";
1225 stream << indent_str;
1228 stream << "return the index of the matched value:";
1230 stream << indent_str;
1231 stream << " * -1 if no value matched,";
1233 stream << indent_str;
1234 stream << " * -2 if more than one value has matched";
1236 stream << indent_str;
1239 stream << indent_str;
1240 stream << "static int";
1242 stream << indent_str;
1243 stream << "check_possible_values(const char *val, const char *values[])";
1245 stream << indent_str;
1248 stream << indent_str;
1249 stream << " int i, found, last;";
1251 stream << indent_str;
1252 stream << " size_t len;";
1254 stream << indent_str;
1256 stream << indent_str;
1257 stream << " if (!val) /* otherwise strlen() crashes below */";
1259 stream << indent_str;
1260 stream << " return -1; /* -1 means no argument for the option */";
1262 stream << indent_str;
1264 stream << indent_str;
1265 stream << " found = last = 0;";
1267 stream << indent_str;
1269 stream << indent_str;
1270 stream << " for (i = 0, len = strlen(val); values[i]; ++i)";
1272 stream << indent_str;
1275 stream << indent_str;
1276 stream << " if (strncmp(val, values[i], len) == 0)";
1278 stream << indent_str;
1281 stream << indent_str;
1282 stream << " ++found;";
1284 stream << indent_str;
1285 stream << " last = i;";
1287 stream << indent_str;
1288 stream << " if (strlen(values[i]) == len)";
1290 stream << indent_str;
1291 stream << " return i; /* exact macth no need to check more */";
1293 stream << indent_str;
1296 stream << indent_str;
1299 stream << indent_str;
1301 stream << indent_str;
1302 stream << " if (found == 1) /* one match: OK */";
1304 stream << indent_str;
1305 stream << " return last;";
1307 stream << indent_str;
1309 stream << indent_str;
1310 stream << " return (found ? -2 : -1); /* return many values or none matched */";
1312 stream << indent_str;
1315 stream << indent_str;
1317 stream << indent_str;
1320 stream << indent_str;
1321 stream << "static void";
1323 stream << indent_str;
1324 stream << "write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])";
1326 stream << indent_str;
1329 stream << indent_str;
1330 if (check_possible_values)
1332 stream << " int found = -1;";
1334 stream << indent_str;
1338 stream << " FIX_UNUSED (values);";
1340 stream << indent_str;
1342 stream << " if (arg) {";
1344 stream << indent_str;
1345 if (check_possible_values)
1347 stream << " if (values) {";
1349 stream << indent_str;
1350 stream << " found = check_possible_values(arg, values); ";
1352 stream << indent_str;
1355 stream << indent_str;
1356 stream << " if (found >= 0)";
1358 stream << indent_str;
1359 stream << " fprintf(outfile, \"%s=\\\"%s\\\" # %s\\n\", opt, arg, values[found]);";
1361 stream << indent_str;
1364 stream << indent_str;
1365 stream << " fprintf(outfile, \"%s=\\\"%s\\\"\\n\", opt, arg);";
1367 stream << indent_str;
1371 stream << " fprintf(outfile, \"%s=\\\"%s\\\"\\n\", opt, arg);";
1373 stream << indent_str;
1375 stream << " } else {";
1377 stream << indent_str;
1378 stream << " fprintf(outfile, \"%s\\n\", opt);";
1380 stream << indent_str;
1383 stream << indent_str;
1386 stream << indent_str;
1388 stream << indent_str;
1389 if (multiple_options)
1391 stream << "static void";
1393 stream << indent_str;
1394 stream << "write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, const char *values[])";
1396 stream << indent_str;
1399 stream << indent_str;
1400 stream << " int i;";
1402 stream << indent_str;
1407 stream << indent_str;
1408 stream << " for (i = 0; i < len; ++i)";
1410 stream << indent_str;
1411 stream << " write_into_file(outfile, opt, (arg ? arg[i] : 0), values);";
1413 stream << indent_str;
1416 stream << indent_str;
1419 stream << indent_str;
1422 stream << indent_str;
1423 generate_string (parser_name, stream, indent + indent_str.length ());
1424 stream << "_dump(FILE *outfile, struct ";
1425 generate_string (args_info, stream, indent + indent_str.length ());
1426 stream << " *args_info)";
1428 stream << indent_str;
1431 stream << indent_str;
1432 stream << " int i = 0;";
1434 stream << indent_str;
1436 stream << indent_str;
1437 stream << " if (!outfile)";
1439 stream << indent_str;
1442 stream << indent_str;
1443 stream << " fprintf (stderr, \"%s: cannot dump options to stream\\n\", ";
1444 generate_string (package_var_name, stream, indent + indent_str.length ());
1447 stream << indent_str;
1448 stream << " return EXIT_FAILURE;";
1450 stream << indent_str;
1453 stream << indent_str;
1455 stream << indent_str;
1458 if (file_save_loop.size () > 0)
1459 generate_string (file_save_loop, stream, indent + indent_str.length ());
1461 generate_file_save_loop (stream, indent + indent_str.length ());
1464 stream << indent_str;
1466 stream << indent_str;
1467 stream << " i = EXIT_SUCCESS;";
1469 stream << indent_str;
1470 stream << " return i;";
1472 stream << indent_str;
1475 stream << indent_str;
1477 stream << indent_str;
1480 stream << indent_str;
1481 generate_string (parser_name, stream, indent + indent_str.length ());
1482 stream << "_file_save(const char *filename, struct ";
1483 generate_string (args_info, stream, indent + indent_str.length ());
1484 stream << " *args_info)";
1486 stream << indent_str;
1489 stream << indent_str;
1490 stream << " FILE *outfile;";
1492 stream << indent_str;
1493 stream << " int i = 0;";
1495 stream << indent_str;
1497 stream << indent_str;
1498 stream << " outfile = fopen(filename, \"w\");";
1500 stream << indent_str;
1502 stream << indent_str;
1503 stream << " if (!outfile)";
1505 stream << indent_str;
1508 stream << indent_str;
1509 stream << " fprintf (stderr, \"%s: cannot open file for writing: %s\\n\", ";
1510 generate_string (package_var_name, stream, indent + indent_str.length ());
1511 stream << ", filename);";
1513 stream << indent_str;
1514 stream << " return EXIT_FAILURE;";
1516 stream << indent_str;
1519 stream << indent_str;
1521 stream << indent_str;
1523 generate_string (parser_name, stream, indent + indent_str.length ());
1524 stream << "_dump(outfile, args_info);";
1526 stream << indent_str;
1527 stream << " fclose (outfile);";
1529 stream << indent_str;
1531 stream << indent_str;
1532 stream << " return i;";
1534 stream << indent_str;
1537 stream << indent_str;
1539 stream << indent_str;
1542 stream << indent_str;
1543 generate_string (parser_name, stream, indent + indent_str.length ());
1544 stream << "_free (struct ";
1545 generate_string (args_info, stream, indent + indent_str.length ());
1546 stream << " *args_info)";
1548 stream << indent_str;
1551 stream << indent_str;
1554 generate_string (parser_name, stream, indent + indent_str.length ());
1555 stream << "_release (args_info);";
1558 stream << indent_str;
1561 stream << indent_str;
1563 stream << indent_str;
1564 if (do_generate_strdup)
1568 stream << "brief replacement of strdup, which is not standard */";
1570 stream << indent_str;
1573 stream << indent_str;
1574 stream << "gengetopt_strdup (const char *s)";
1576 stream << indent_str;
1579 stream << indent_str;
1580 stream << " char *result = 0;";
1582 stream << indent_str;
1583 stream << " if (!s)";
1585 stream << indent_str;
1586 stream << " return result;";
1588 stream << indent_str;
1590 stream << indent_str;
1591 stream << " result = (char*)malloc(strlen(s) + 1);";
1593 stream << indent_str;
1594 stream << " if (result == (char*)0)";
1596 stream << indent_str;
1597 stream << " return (char*)0;";
1599 stream << indent_str;
1600 stream << " strcpy(result, s);";
1602 stream << indent_str;
1603 stream << " return result;";
1605 stream << indent_str;
1608 stream << indent_str;
1610 stream << indent_str;
1612 if (multiple_token_functions)
1614 stream << "static char *";
1616 stream << indent_str;
1617 stream << "get_multiple_arg_token(const char *arg)";
1619 stream << indent_str;
1622 stream << indent_str;
1623 stream << " const char *tok;";
1625 stream << indent_str;
1626 stream << " char *ret;";
1628 stream << indent_str;
1629 stream << " size_t len, num_of_escape, i, j;";
1631 stream << indent_str;
1633 stream << indent_str;
1634 stream << " if (!arg)";
1636 stream << indent_str;
1637 stream << " return 0;";
1639 stream << indent_str;
1641 stream << indent_str;
1642 stream << " tok = strchr (arg, ',');";
1644 stream << indent_str;
1645 stream << " num_of_escape = 0;";
1647 stream << indent_str;
1649 stream << indent_str;
1650 stream << " /* make sure it is not escaped */";
1652 stream << indent_str;
1653 stream << " while (tok)";
1655 stream << indent_str;
1658 stream << indent_str;
1659 stream << " if (*(tok-1) == '\\\\')";
1661 stream << indent_str;
1664 stream << indent_str;
1665 stream << " /* find the next one */";
1667 stream << indent_str;
1668 stream << " tok = strchr (tok+1, ',');";
1670 stream << indent_str;
1671 stream << " ++num_of_escape;";
1673 stream << indent_str;
1676 stream << indent_str;
1679 stream << indent_str;
1680 stream << " break;";
1682 stream << indent_str;
1685 stream << indent_str;
1687 stream << indent_str;
1688 stream << " if (tok)";
1690 stream << indent_str;
1691 stream << " len = (size_t)(tok - arg + 1);";
1693 stream << indent_str;
1696 stream << indent_str;
1697 stream << " len = strlen (arg) + 1;";
1699 stream << indent_str;
1701 stream << indent_str;
1702 stream << " len -= num_of_escape;";
1704 stream << indent_str;
1706 stream << indent_str;
1707 stream << " ret = (char *) malloc (len);";
1709 stream << indent_str;
1711 stream << indent_str;
1712 stream << " i = 0;";
1714 stream << indent_str;
1715 stream << " j = 0;";
1717 stream << indent_str;
1718 stream << " while (arg[i] && (j < len-1))";
1720 stream << indent_str;
1723 stream << indent_str;
1724 stream << " if (arg[i] == '\\\\' && ";
1726 stream << indent_str;
1727 stream << " arg[ i + 1 ] && ";
1729 stream << indent_str;
1730 stream << " arg[ i + 1 ] == ',')";
1732 stream << indent_str;
1735 stream << indent_str;
1737 stream << indent_str;
1738 stream << " ret[j++] = arg[i++];";
1740 stream << indent_str;
1743 stream << indent_str;
1745 stream << indent_str;
1746 stream << " ret[len-1] = '\\0';";
1748 stream << indent_str;
1750 stream << indent_str;
1751 stream << " return ret;";
1753 stream << indent_str;
1756 stream << indent_str;
1758 stream << indent_str;
1759 stream << "static const char *";
1761 stream << indent_str;
1762 stream << "get_multiple_arg_token_next(const char *arg)";
1764 stream << indent_str;
1767 stream << indent_str;
1768 stream << " const char *tok;";
1770 stream << indent_str;
1772 stream << indent_str;
1773 stream << " if (!arg)";
1775 stream << indent_str;
1776 stream << " return 0;";
1778 stream << indent_str;
1780 stream << indent_str;
1781 stream << " tok = strchr (arg, ',');";
1783 stream << indent_str;
1785 stream << indent_str;
1786 stream << " /* make sure it is not escaped */";
1788 stream << indent_str;
1789 stream << " while (tok)";
1791 stream << indent_str;
1794 stream << indent_str;
1795 stream << " if (*(tok-1) == '\\\\')";
1797 stream << indent_str;
1800 stream << indent_str;
1801 stream << " /* find the next one */";
1803 stream << indent_str;
1804 stream << " tok = strchr (tok+1, ',');";
1806 stream << indent_str;
1809 stream << indent_str;
1812 stream << indent_str;
1813 stream << " break;";
1815 stream << indent_str;
1818 stream << indent_str;
1820 stream << indent_str;
1821 stream << " if (! tok || strlen(tok) == 1)";
1823 stream << indent_str;
1824 stream << " return 0;";
1826 stream << indent_str;
1828 stream << indent_str;
1829 stream << " return tok+1;";
1831 stream << indent_str;
1834 stream << indent_str;
1836 stream << indent_str;
1838 if (multiple_options)
1840 stream << "static int";
1842 stream << indent_str;
1843 stream << "check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc);";
1845 stream << indent_str;
1847 stream << indent_str;
1850 stream << indent_str;
1851 stream << "check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, unsigned int min, unsigned int max, const char *option_desc)";
1853 stream << indent_str;
1856 stream << indent_str;
1857 stream << " int error = 0;";
1859 stream << indent_str;
1861 stream << indent_str;
1862 stream << " if (option_given && (min > 0 || max > 0))";
1864 stream << indent_str;
1867 stream << indent_str;
1868 stream << " if (min > 0 && max > 0)";
1870 stream << indent_str;
1873 stream << indent_str;
1874 stream << " if (min == max)";
1876 stream << indent_str;
1879 stream << indent_str;
1880 stream << " /* specific occurrences */";
1882 stream << indent_str;
1883 stream << " if (option_given != (unsigned int) min)";
1885 stream << indent_str;
1888 stream << indent_str;
1889 stream << " fprintf (stderr, \"%s: %s option occurrences must be %d\\n\",";
1891 stream << indent_str;
1892 stream << " prog_name, option_desc, min);";
1894 stream << indent_str;
1895 stream << " error = 1;";
1897 stream << indent_str;
1900 stream << indent_str;
1903 stream << indent_str;
1904 stream << " else if (option_given < (unsigned int) min";
1906 stream << indent_str;
1907 stream << " || option_given > (unsigned int) max)";
1909 stream << indent_str;
1912 stream << indent_str;
1913 stream << " /* range occurrences */";
1915 stream << indent_str;
1916 stream << " fprintf (stderr, \"%s: %s option occurrences must be between %d and %d\\n\",";
1918 stream << indent_str;
1919 stream << " prog_name, option_desc, min, max);";
1921 stream << indent_str;
1922 stream << " error = 1;";
1924 stream << indent_str;
1927 stream << indent_str;
1930 stream << indent_str;
1931 stream << " else if (min > 0)";
1933 stream << indent_str;
1936 stream << indent_str;
1937 stream << " /* at least check */";
1939 stream << indent_str;
1940 stream << " if (option_given < min)";
1942 stream << indent_str;
1945 stream << indent_str;
1946 stream << " fprintf (stderr, \"%s: %s option occurrences must be at least %d\\n\",";
1948 stream << indent_str;
1949 stream << " prog_name, option_desc, min);";
1951 stream << indent_str;
1952 stream << " error = 1;";
1954 stream << indent_str;
1957 stream << indent_str;
1960 stream << indent_str;
1961 stream << " else if (max > 0)";
1963 stream << indent_str;
1966 stream << indent_str;
1967 stream << " /* at most check */";
1969 stream << indent_str;
1970 stream << " if (option_given > max)";
1972 stream << indent_str;
1975 stream << indent_str;
1976 stream << " fprintf (stderr, \"%s: %s option occurrences must be at most %d\\n\",";
1978 stream << indent_str;
1979 stream << " prog_name, option_desc, max);";
1981 stream << indent_str;
1982 stream << " error = 1;";
1984 stream << indent_str;
1987 stream << indent_str;
1990 stream << indent_str;
1993 stream << indent_str;
1998 stream << indent_str;
1999 stream << " return error;";
2001 stream << indent_str;
2004 stream << indent_str;
2006 if (reset_groups.size () > 0)
2007 generate_string (reset_groups, stream, indent + indent_str.length ());
2009 generate_reset_groups (stream, indent + indent_str.length ());
2010 stream << indent_str;
2013 stream << indent_str;
2014 generate_string (parser_name, stream, indent + indent_str.length ());
2015 stream << " (int argc, char **argv, struct ";
2016 generate_string (args_info, stream, indent + indent_str.length ());
2017 stream << " *args_info)";
2019 stream << indent_str;
2022 stream << indent_str;
2023 stream << " return ";
2024 generate_string (parser_name, stream, indent + indent_str.length ());
2025 stream << "2 (argc, argv, args_info, 0, 1, 1);";
2027 stream << indent_str;
2030 stream << indent_str;
2032 stream << indent_str;
2035 stream << indent_str;
2036 generate_string (parser_name, stream, indent + indent_str.length ());
2037 stream << "_ext (int argc, char **argv, struct ";
2038 generate_string (args_info, stream, indent + indent_str.length ());
2039 stream << " *args_info,";
2041 stream << indent_str;
2042 stream << " struct ";
2043 generate_string (parser_name, stream, indent + indent_str.length ());
2044 stream << "_params *params)";
2046 stream << indent_str;
2049 stream << indent_str;
2050 stream << " int result;";
2052 stream << indent_str;
2053 stream << " result = ";
2054 generate_string (parser_name, stream, indent + indent_str.length ());
2055 stream << "_internal (argc, argv, args_info, params, 0);";
2057 stream << indent_str;
2059 stream << indent_str;
2062 generate_string (final_exit, stream, indent + indent_str.length ());
2065 stream << indent_str;
2068 stream << indent_str;
2070 stream << indent_str;
2073 stream << indent_str;
2074 generate_string (parser_name, stream, indent + indent_str.length ());
2075 stream << "2 (int argc, char **argv, struct ";
2076 generate_string (args_info, stream, indent + indent_str.length ());
2077 stream << " *args_info, int override, int initialize, int check_required)";
2079 stream << indent_str;
2082 stream << indent_str;
2083 stream << " int result;";
2085 stream << indent_str;
2086 stream << " struct ";
2087 generate_string (parser_name, stream, indent + indent_str.length ());
2088 stream << "_params params;";
2090 stream << indent_str;
2095 stream << indent_str;
2096 stream << " params.override = override;";
2098 stream << indent_str;
2099 stream << " params.initialize = initialize;";
2101 stream << indent_str;
2102 stream << " params.check_required = check_required;";
2104 stream << indent_str;
2105 stream << " params.check_ambiguity = 0;";
2107 stream << indent_str;
2108 stream << " params.print_errors = 1;";
2110 stream << indent_str;
2112 stream << indent_str;
2113 stream << " result = ";
2114 generate_string (parser_name, stream, indent + indent_str.length ());
2115 stream << "_internal (argc, argv, args_info, ¶ms, 0);";
2117 stream << indent_str;
2119 stream << indent_str;
2122 generate_string (final_exit, stream, indent + indent_str.length ());
2125 stream << indent_str;
2128 stream << indent_str;
2130 stream << indent_str;
2133 stream << indent_str;
2134 generate_string (parser_name, stream, indent + indent_str.length ());
2135 stream << "_required (struct ";
2136 generate_string (args_info, stream, indent + indent_str.length ());
2137 stream << " *args_info, const char *prog_name)";
2139 stream << indent_str;
2142 stream << indent_str;
2143 if (check_required_options)
2145 stream << " int result = EXIT_SUCCESS;";
2147 stream << indent_str;
2149 stream << indent_str;
2151 generate_string (parser_name, stream, indent + indent_str.length ());
2152 stream << "_required2(args_info, prog_name, 0) > 0)";
2154 stream << indent_str;
2155 stream << " result = EXIT_FAILURE;";
2157 stream << indent_str;
2159 stream << indent_str;
2162 generate_string (final_exit, stream, indent + indent_str.length ());
2165 stream << indent_str;
2169 stream << " FIX_UNUSED (args_info);";
2171 stream << indent_str;
2172 stream << " FIX_UNUSED (prog_name);";
2174 stream << indent_str;
2175 stream << " return EXIT_SUCCESS;";
2177 stream << indent_str;
2181 stream << indent_str;
2183 stream << indent_str;
2184 if (check_required_options)
2188 stream << indent_str;
2189 generate_string (parser_name, stream, indent + indent_str.length ());
2190 stream << "_required2 (struct ";
2191 generate_string (args_info, stream, indent + indent_str.length ());
2192 stream << " *args_info, const char *prog_name, const char *additional_error)";
2194 stream << indent_str;
2197 stream << indent_str;
2198 stream << " int error = 0;";
2200 stream << indent_str;
2201 stream << " FIX_UNUSED (additional_error);";
2203 stream << indent_str;
2205 stream << indent_str;
2206 stream << " /* checks for required options */";
2208 stream << indent_str;
2211 if (handle_required.size () > 0)
2212 generate_string (handle_required, stream, indent + indent_str.length ());
2214 generate_handle_required (stream, indent + indent_str.length ());
2217 stream << indent_str;
2218 stream << " /* checks for dependences among options */";
2220 stream << indent_str;
2222 if (handle_dependencies.size () > 0)
2223 generate_string (handle_dependencies, stream, indent + indent_str.length ());
2225 generate_handle_dependencies (stream, indent + indent_str.length ());
2227 stream << indent_str;
2229 stream << indent_str;
2230 stream << " return error;";
2232 stream << indent_str;
2235 stream << indent_str;
2237 stream << indent_str;
2241 if (custom_getopt.size () > 0)
2242 generate_string (custom_getopt, stream, indent + indent_str.length ());
2244 generate_custom_getopt (stream, indent + indent_str.length ());
2246 stream << indent_str;
2249 stream << indent_str;
2250 stream << "static char *package_name = 0;";
2252 stream << indent_str;
2254 stream << indent_str;
2255 if (( ! no_options ))
2259 stream << indent_str;
2262 stream << "brief updates an option";
2264 stream << indent_str;
2267 stream << "param field the generic pointer to the field to update";
2269 stream << indent_str;
2272 stream << "param orig_field the pointer to the orig field";
2274 stream << indent_str;
2277 stream << "param field_given the pointer to the number of occurrence of this option";
2279 stream << indent_str;
2282 stream << "param prev_given the pointer to the number of occurrence already seen";
2284 stream << indent_str;
2287 stream << "param value the argument for this option (if null no arg was specified)";
2289 stream << indent_str;
2292 stream << "param possible_values the possible values for this option (if specified)";
2294 stream << indent_str;
2297 stream << "param default_value the default value (in case the option only accepts fixed values)";
2299 stream << indent_str;
2302 stream << "param arg_type the type of this option";
2304 stream << indent_str;
2307 stream << "param check_ambiguity ";
2310 generate_string (parser_name, stream, indent + indent_str.length ());
2311 stream << "_params.check_ambiguity";
2313 stream << indent_str;
2316 stream << "param override ";
2319 generate_string (parser_name, stream, indent + indent_str.length ());
2320 stream << "_params.override";
2322 stream << indent_str;
2325 stream << "param no_free whether to free a possible previous value";
2327 stream << indent_str;
2330 stream << "param multiple_option whether this is a multiple option";
2332 stream << indent_str;
2335 stream << "param long_opt the corresponding long option";
2337 stream << indent_str;
2340 stream << "param short_opt the corresponding short option (or '-' if none)";
2342 stream << indent_str;
2345 stream << "param additional_error possible further error specification";
2347 stream << indent_str;
2350 stream << indent_str;
2353 stream << indent_str;
2354 stream << "int update_arg(void *field, char **orig_field,";
2356 stream << indent_str;
2357 stream << " unsigned int *field_given, unsigned int *prev_given, ";
2359 stream << indent_str;
2360 stream << " char *value, const char *possible_values[],";
2362 stream << indent_str;
2363 stream << " const char *default_value,";
2365 stream << indent_str;
2368 generate_string (parser_name, stream, indent + indent_str.length ());
2369 stream << "_arg_type arg_type,";
2372 stream << indent_str;
2373 stream << " int check_ambiguity, int override,";
2375 stream << indent_str;
2376 stream << " int no_free, int multiple_option,";
2378 stream << indent_str;
2379 stream << " const char *long_opt, char short_opt,";
2381 stream << indent_str;
2382 stream << " const char *additional_error)";
2384 stream << indent_str;
2387 stream << indent_str;
2388 stream << " char *stop_char = 0;";
2390 stream << indent_str;
2391 stream << " const char *val = value;";
2393 stream << indent_str;
2394 stream << " int found;";
2396 stream << indent_str;
2399 stream << " char **string_field;";
2401 stream << indent_str;
2403 stream << " FIX_UNUSED (field);";
2405 stream << indent_str;
2407 stream << indent_str;
2408 stream << " stop_char = 0;";
2410 stream << indent_str;
2411 stream << " found = 0;";
2413 stream << indent_str;
2415 stream << indent_str;
2416 stream << " if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))";
2418 stream << indent_str;
2421 stream << indent_str;
2422 stream << " if (short_opt != '-')";
2424 stream << indent_str;
2425 stream << " fprintf (stderr, \"%s: `--%s' (`-%c') option given more than once%s\\n\", ";
2427 stream << indent_str;
2428 stream << " package_name, long_opt, short_opt,";
2430 stream << indent_str;
2431 stream << " (additional_error ? additional_error : \"\"));";
2433 stream << indent_str;
2436 stream << indent_str;
2437 stream << " fprintf (stderr, \"%s: `--%s' option given more than once%s\\n\", ";
2439 stream << indent_str;
2440 stream << " package_name, long_opt,";
2442 stream << indent_str;
2443 stream << " (additional_error ? additional_error : \"\"));";
2445 stream << indent_str;
2446 stream << " return 1; /* failure */";
2448 stream << indent_str;
2451 stream << indent_str;
2453 stream << indent_str;
2454 if (check_possible_values)
2456 stream << " if (possible_values && (found = check_possible_values((value ? value : default_value), possible_values)) < 0)";
2458 stream << indent_str;
2461 stream << indent_str;
2462 stream << " if (short_opt != '-')";
2464 stream << indent_str;
2465 stream << " fprintf (stderr, \"%s: %s argument, \\\"%s\\\", for option `--%s' (`-%c')%s\\n\", ";
2467 stream << indent_str;
2468 stream << " package_name, (found == -2) ? \"ambiguous\" : \"invalid\", value, long_opt, short_opt,";
2470 stream << indent_str;
2471 stream << " (additional_error ? additional_error : \"\"));";
2473 stream << indent_str;
2476 stream << indent_str;
2477 stream << " fprintf (stderr, \"%s: %s argument, \\\"%s\\\", for option `--%s'%s\\n\", ";
2479 stream << indent_str;
2480 stream << " package_name, (found == -2) ? \"ambiguous\" : \"invalid\", value, long_opt,";
2482 stream << indent_str;
2483 stream << " (additional_error ? additional_error : \"\"));";
2485 stream << indent_str;
2486 stream << " return 1; /* failure */";
2488 stream << indent_str;
2491 stream << indent_str;
2495 stream << " FIX_UNUSED (default_value);";
2497 stream << indent_str;
2501 stream << indent_str;
2502 stream << " if (field_given && *field_given && ! override)";
2504 stream << indent_str;
2505 stream << " return 0;";
2507 stream << indent_str;
2508 stream << " if (prev_given)";
2510 stream << indent_str;
2511 stream << " (*prev_given)++;";
2513 stream << indent_str;
2514 stream << " if (field_given)";
2516 stream << indent_str;
2517 stream << " (*field_given)++;";
2519 stream << indent_str;
2520 stream << " if (possible_values)";
2522 stream << indent_str;
2523 stream << " val = possible_values[found];";
2525 stream << indent_str;
2527 stream << indent_str;
2528 stream << " switch(arg_type) {";
2530 stream << indent_str;
2533 stream << " case ARG_FLAG:";
2535 stream << indent_str;
2536 stream << " *((int *)field) = !*((int *)field);";
2538 stream << indent_str;
2539 stream << " break;";
2541 stream << indent_str;
2545 stream << " case ARG_INT:";
2547 stream << indent_str;
2548 stream << " if (val) *((int *)field) = strtol (val, &stop_char, 0);";
2550 stream << indent_str;
2551 stream << " break;";
2553 stream << indent_str;
2557 stream << " case ARG_SHORT:";
2559 stream << indent_str;
2560 stream << " if (val) *((short *)field) = (short)strtol (val, &stop_char, 0);";
2562 stream << indent_str;
2563 stream << " break;";
2565 stream << indent_str;
2569 stream << " case ARG_LONG:";
2571 stream << indent_str;
2572 stream << " if (val) *((long *)field) = (long)strtol (val, &stop_char, 0);";
2574 stream << indent_str;
2575 stream << " break;";
2577 stream << indent_str;
2581 stream << " case ARG_FLOAT:";
2583 stream << indent_str;
2584 stream << " if (val) *((float *)field) = (float)strtod (val, &stop_char);";
2586 stream << indent_str;
2587 stream << " break;";
2589 stream << indent_str;
2593 stream << " case ARG_DOUBLE:";
2595 stream << indent_str;
2596 stream << " if (val) *((double *)field) = strtod (val, &stop_char);";
2598 stream << indent_str;
2599 stream << " break;";
2601 stream << indent_str;
2603 if (has_arg_longdouble)
2605 stream << " case ARG_LONGDOUBLE:";
2607 stream << indent_str;
2608 stream << " if (val) *((long double *)field) = (long double)strtod (val, &stop_char);";
2610 stream << indent_str;
2611 stream << " break;";
2613 stream << indent_str;
2615 if (has_arg_longlong)
2617 stream << " case ARG_LONGLONG:";
2619 stream << indent_str;
2620 stream << "#ifdef HAVE_LONG_LONG";
2622 stream << indent_str;
2623 stream << " if (val) *((long long int*)field) = (long long int) strtol (val, &stop_char, 0);";
2625 stream << indent_str;
2628 stream << indent_str;
2629 stream << " if (val) *((long *)field) = (long)strtol (val, &stop_char, 0);";
2631 stream << indent_str;
2634 stream << indent_str;
2635 stream << " break;";
2637 stream << indent_str;
2641 stream << " case ARG_ENUM:";
2643 stream << indent_str;
2644 stream << " if (val) *((int *)field) = found;";
2646 stream << indent_str;
2647 stream << " break;";
2649 stream << indent_str;
2653 stream << " case ARG_STRING:";
2655 stream << indent_str;
2656 stream << " if (val) {";
2658 stream << indent_str;
2659 stream << " string_field = (char **)field;";
2661 stream << indent_str;
2662 stream << " if (!no_free && *string_field)";
2664 stream << indent_str;
2665 stream << " free (*string_field); /* free previous string */";
2667 stream << indent_str;
2668 stream << " *string_field = gengetopt_strdup (val);";
2670 stream << indent_str;
2673 stream << indent_str;
2674 stream << " break;";
2676 stream << indent_str;
2678 stream << " default:";
2680 stream << indent_str;
2681 stream << " break;";
2683 stream << indent_str;
2686 stream << indent_str;
2688 stream << indent_str;
2689 if (( ( ( ( ( ( has_arg_int || has_arg_short ) || has_arg_long ) || has_arg_float ) || has_arg_double ) || has_arg_longdouble ) || has_arg_longlong ))
2691 stream << " /* check numeric conversion */";
2693 stream << indent_str;
2694 stream << " switch(arg_type) {";
2696 stream << indent_str;
2699 stream << " case ARG_INT:";
2701 stream << indent_str;
2705 stream << " case ARG_SHORT:";
2707 stream << indent_str;
2711 stream << " case ARG_LONG:";
2713 stream << indent_str;
2717 stream << " case ARG_FLOAT:";
2719 stream << indent_str;
2723 stream << " case ARG_DOUBLE:";
2725 stream << indent_str;
2727 if (has_arg_longdouble)
2729 stream << " case ARG_LONGDOUBLE:";
2731 stream << indent_str;
2733 if (has_arg_longlong)
2735 stream << " case ARG_LONGLONG:";
2737 stream << indent_str;
2739 stream << " if (val && !(stop_char && *stop_char == '\\0')) {";
2741 stream << indent_str;
2742 stream << " fprintf(stderr, \"%s: invalid numeric value: %s\\n\", package_name, val);";
2744 stream << indent_str;
2745 stream << " return 1; /* failure */";
2747 stream << indent_str;
2750 stream << indent_str;
2751 stream << " break;";
2753 stream << indent_str;
2754 stream << " default:";
2756 stream << indent_str;
2759 stream << indent_str;
2762 stream << indent_str;
2765 stream << indent_str;
2766 stream << " /* store the original value */";
2768 stream << indent_str;
2769 stream << " switch(arg_type) {";
2771 stream << indent_str;
2772 stream << " case ARG_NO:";
2774 stream << indent_str;
2777 stream << " case ARG_FLAG:";
2779 stream << indent_str;
2781 stream << " break;";
2783 stream << indent_str;
2784 stream << " default:";
2786 stream << indent_str;
2787 stream << " if (value && orig_field) {";
2789 stream << indent_str;
2790 stream << " if (no_free) {";
2792 stream << indent_str;
2793 stream << " *orig_field = value;";
2795 stream << indent_str;
2796 stream << " } else {";
2798 stream << indent_str;
2799 stream << " if (*orig_field)";
2801 stream << indent_str;
2802 stream << " free (*orig_field); /* free previous string */";
2804 stream << indent_str;
2805 stream << " *orig_field = gengetopt_strdup (value);";
2807 stream << indent_str;
2810 stream << indent_str;
2813 stream << indent_str;
2816 stream << indent_str;
2818 stream << indent_str;
2819 stream << " return 0; /* OK */";
2821 stream << indent_str;
2824 stream << indent_str;
2827 stream << indent_str;
2828 if (multiple_token_functions)
2832 stream << indent_str;
2835 stream << "brief store information about a multiple option in a temporary list";
2837 stream << indent_str;
2840 stream << "param list where to (temporarily) store multiple options";
2842 stream << indent_str;
2845 stream << indent_str;
2848 stream << indent_str;
2849 stream << "int update_multiple_arg_temp(struct generic_list **list,";
2851 stream << indent_str;
2852 stream << " unsigned int *prev_given, const char *val,";
2854 stream << indent_str;
2855 stream << " const char *possible_values[], const char *default_value,";
2857 stream << indent_str;
2860 generate_string (parser_name, stream, indent + indent_str.length ());
2861 stream << "_arg_type arg_type,";
2864 stream << indent_str;
2865 stream << " const char *long_opt, char short_opt,";
2867 stream << indent_str;
2868 stream << " const char *additional_error)";
2870 stream << indent_str;
2873 stream << indent_str;
2874 stream << " /* store single arguments */";
2876 stream << indent_str;
2877 stream << " char *multi_token;";
2879 stream << indent_str;
2880 stream << " const char *multi_next;";
2882 stream << indent_str;
2884 stream << indent_str;
2885 stream << " if (arg_type == ARG_NO) {";
2887 stream << indent_str;
2888 stream << " (*prev_given)++;";
2890 stream << indent_str;
2891 stream << " return 0; /* OK */";
2893 stream << indent_str;
2896 stream << indent_str;
2898 stream << indent_str;
2899 stream << " multi_token = get_multiple_arg_token(val);";
2901 stream << indent_str;
2902 stream << " multi_next = get_multiple_arg_token_next (val);";
2904 stream << indent_str;
2906 stream << indent_str;
2907 stream << " while (1)";
2909 stream << indent_str;
2912 stream << indent_str;
2913 stream << " add_node (list);";
2915 stream << indent_str;
2916 stream << " if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0,";
2918 stream << indent_str;
2919 stream << " prev_given, multi_token, possible_values, default_value, ";
2921 stream << indent_str;
2922 stream << " arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {";
2924 stream << indent_str;
2925 stream << " if (multi_token) free(multi_token);";
2927 stream << indent_str;
2928 stream << " return 1; /* failure */";
2930 stream << indent_str;
2933 stream << indent_str;
2935 stream << indent_str;
2936 stream << " if (multi_next)";
2938 stream << indent_str;
2941 stream << indent_str;
2942 stream << " multi_token = get_multiple_arg_token(multi_next);";
2944 stream << indent_str;
2945 stream << " multi_next = get_multiple_arg_token_next (multi_next);";
2947 stream << indent_str;
2950 stream << indent_str;
2953 stream << indent_str;
2954 stream << " break;";
2956 stream << indent_str;
2959 stream << indent_str;
2961 stream << indent_str;
2962 stream << " return 0; /* OK */";
2964 stream << indent_str;
2967 stream << indent_str;
2969 stream << indent_str;
2972 stream << indent_str;
2975 stream << "brief free the passed list (including possible string argument)";
2977 stream << indent_str;
2980 stream << indent_str;
2983 stream << indent_str;
2984 stream << "void free_list(struct generic_list *list, short string_arg)";
2986 stream << indent_str;
2989 stream << indent_str;
2990 stream << " if (list) {";
2992 stream << indent_str;
2993 stream << " struct generic_list *tmp;";
2995 stream << indent_str;
2996 stream << " while (list)";
2998 stream << indent_str;
3001 stream << indent_str;
3002 stream << " tmp = list;";
3004 stream << indent_str;
3005 stream << " if (string_arg && list->arg.string_arg)";
3007 stream << indent_str;
3008 stream << " free (list->arg.string_arg);";
3010 stream << indent_str;
3011 stream << " if (list->orig)";
3013 stream << indent_str;
3014 stream << " free (list->orig);";
3016 stream << indent_str;
3017 stream << " list = list->next;";
3019 stream << indent_str;
3020 stream << " free (tmp);";
3022 stream << indent_str;
3025 stream << indent_str;
3028 stream << indent_str;
3031 stream << indent_str;
3033 stream << indent_str;
3036 stream << indent_str;
3039 stream << "brief updates a multiple option starting from the passed list";
3041 stream << indent_str;
3044 stream << indent_str;
3047 stream << indent_str;
3048 stream << "void update_multiple_arg(void *field, char ***orig_field,";
3050 stream << indent_str;
3051 stream << " unsigned int field_given, unsigned int prev_given, union generic_value *default_value,";
3053 stream << indent_str;
3056 generate_string (parser_name, stream, indent + indent_str.length ());
3057 stream << "_arg_type arg_type,";
3060 stream << indent_str;
3061 stream << " struct generic_list *list)";
3063 stream << indent_str;
3066 stream << indent_str;
3067 stream << " int i;";
3069 stream << indent_str;
3070 stream << " struct generic_list *tmp;";
3072 stream << indent_str;
3074 stream << indent_str;
3075 stream << " if (prev_given && list) {";
3077 stream << indent_str;
3078 stream << " *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *));";
3080 stream << indent_str;
3082 stream << indent_str;
3083 stream << " switch(arg_type) {";
3085 stream << indent_str;
3086 if (( has_arg_int || has_arg_enum ))
3090 stream << " case ARG_INT:";
3092 stream << indent_str;
3096 stream << " case ARG_ENUM:";
3098 stream << indent_str;
3100 stream << " *((int **)field) = (int *)realloc (*((int **)field), (field_given + prev_given) * sizeof (int)); break;";
3102 stream << indent_str;
3106 stream << " case ARG_SHORT:";
3108 stream << indent_str;
3109 stream << " *((short **)field) = (short *)realloc (*((short **)field), (field_given + prev_given) * sizeof (short)); break;";
3111 stream << indent_str;
3115 stream << " case ARG_LONG:";
3117 stream << indent_str;
3118 stream << " *((long **)field) = (long *)realloc (*((long **)field), (field_given + prev_given) * sizeof (long)); break;";
3120 stream << indent_str;
3124 stream << " case ARG_FLOAT:";
3126 stream << indent_str;
3127 stream << " *((float **)field) = (float *)realloc (*((float **)field), (field_given + prev_given) * sizeof (float)); break;";
3129 stream << indent_str;
3133 stream << " case ARG_DOUBLE:";
3135 stream << indent_str;
3136 stream << " *((double **)field) = (double *)realloc (*((double **)field), (field_given + prev_given) * sizeof (double)); break;";
3138 stream << indent_str;
3140 if (has_arg_longdouble)
3142 stream << " case ARG_LONGDOUBLE:";
3144 stream << indent_str;
3145 stream << " *((long double **)field) = (long double *)realloc (*((long double **)field), (field_given + prev_given) * sizeof (long double)); break;";
3147 stream << indent_str;
3149 if (has_arg_longlong)
3151 stream << " case ARG_LONGLONG:";
3153 stream << indent_str;
3154 stream << "#ifdef HAVE_LONG_LONG";
3156 stream << indent_str;
3157 stream << " *((long long int **)field) = (long long int *)realloc (*((long long int **)field), (field_given + prev_given) * sizeof (long long int)); break;";
3159 stream << indent_str;
3162 stream << indent_str;
3163 stream << " *((long **)field) = (long *)realloc (*((long **)field), (field_given + prev_given) * sizeof (long)); break;";
3165 stream << indent_str;
3168 stream << indent_str;
3172 stream << " case ARG_STRING:";
3174 stream << indent_str;
3175 stream << " *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break;";
3177 stream << indent_str;
3179 stream << " default:";
3181 stream << indent_str;
3182 stream << " break;";
3184 stream << indent_str;
3187 stream << indent_str;
3192 stream << indent_str;
3193 stream << " for (i = (prev_given - 1); i >= 0; --i)";
3195 stream << indent_str;
3198 stream << indent_str;
3199 stream << " tmp = list;";
3201 stream << indent_str;
3206 stream << indent_str;
3207 stream << " switch(arg_type) {";
3209 stream << indent_str;
3212 stream << " case ARG_INT:";
3214 stream << indent_str;
3215 stream << " (*((int **)field))[i + field_given] = tmp->arg.int_arg; break;";
3217 stream << indent_str;
3221 stream << " case ARG_SHORT:";
3223 stream << indent_str;
3224 stream << " (*((short **)field))[i + field_given] = tmp->arg.short_arg; break;";
3226 stream << indent_str;
3230 stream << " case ARG_LONG:";
3232 stream << indent_str;
3233 stream << " (*((long **)field))[i + field_given] = tmp->arg.long_arg; break;";
3235 stream << indent_str;
3239 stream << " case ARG_FLOAT:";
3241 stream << indent_str;
3242 stream << " (*((float **)field))[i + field_given] = tmp->arg.float_arg; break;";
3244 stream << indent_str;
3248 stream << " case ARG_DOUBLE:";
3250 stream << indent_str;
3251 stream << " (*((double **)field))[i + field_given] = tmp->arg.double_arg; break;";
3253 stream << indent_str;
3255 if (has_arg_longdouble)
3257 stream << " case ARG_LONGDOUBLE:";
3259 stream << indent_str;
3260 stream << " (*((long double **)field))[i + field_given] = tmp->arg.longdouble_arg; break;";
3262 stream << indent_str;
3264 if (has_arg_longlong)
3266 stream << " case ARG_LONGLONG:";
3268 stream << indent_str;
3269 stream << "#ifdef HAVE_LONG_LONG";
3271 stream << indent_str;
3272 stream << " (*((long long int **)field))[i + field_given] = tmp->arg.longlong_arg; break;";
3274 stream << indent_str;
3277 stream << indent_str;
3278 stream << " (*((long **)field))[i + field_given] = tmp->arg.longlong_arg; break;";
3280 stream << indent_str;
3283 stream << indent_str;
3287 stream << " case ARG_ENUM:";
3289 stream << indent_str;
3290 stream << " (*((int **)field))[i + field_given] = tmp->arg.int_arg; break;";
3292 stream << indent_str;
3296 stream << " case ARG_STRING:";
3298 stream << indent_str;
3299 stream << " (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break;";
3301 stream << indent_str;
3303 stream << " default:";
3305 stream << indent_str;
3306 stream << " break;";
3308 stream << indent_str;
3311 stream << indent_str;
3312 stream << " (*orig_field) [i + field_given] = list->orig;";
3314 stream << indent_str;
3315 stream << " list = list->next;";
3317 stream << indent_str;
3318 stream << " free (tmp);";
3320 stream << indent_str;
3323 stream << indent_str;
3324 stream << " } else { /* set the default value */";
3326 stream << indent_str;
3327 stream << " if (default_value && ! field_given) {";
3329 stream << indent_str;
3330 stream << " switch(arg_type) {";
3332 stream << indent_str;
3333 if (( has_arg_int || has_arg_enum ))
3337 stream << " case ARG_INT:";
3339 stream << indent_str;
3343 stream << " case ARG_ENUM:";
3345 stream << indent_str;
3347 stream << " if (! *((int **)field)) {";
3349 stream << indent_str;
3350 stream << " *((int **)field) = (int *)malloc (sizeof (int));";
3352 stream << indent_str;
3353 stream << " (*((int **)field))[0] = default_value->int_arg; ";
3355 stream << indent_str;
3358 stream << indent_str;
3359 stream << " break;";
3361 stream << indent_str;
3365 stream << " case ARG_SHORT:";
3367 stream << indent_str;
3368 stream << " if (! *((short **)field)) {";
3370 stream << indent_str;
3371 stream << " *((short **)field) = (short *)malloc (sizeof (short));";
3373 stream << indent_str;
3374 stream << " (*((short **)field))[0] = default_value->short_arg;";
3376 stream << indent_str;
3379 stream << indent_str;
3380 stream << " break;";
3382 stream << indent_str;
3386 stream << " case ARG_LONG:";
3388 stream << indent_str;
3389 stream << " if (! *((long **)field)) {";
3391 stream << indent_str;
3392 stream << " *((long **)field) = (long *)malloc (sizeof (long));";
3394 stream << indent_str;
3395 stream << " (*((long **)field))[0] = default_value->long_arg;";
3397 stream << indent_str;
3400 stream << indent_str;
3401 stream << " break;";
3403 stream << indent_str;
3407 stream << " case ARG_FLOAT:";
3409 stream << indent_str;
3410 stream << " if (! *((float **)field)) {";
3412 stream << indent_str;
3413 stream << " *((float **)field) = (float *)malloc (sizeof (float));";
3415 stream << indent_str;
3416 stream << " (*((float **)field))[0] = default_value->float_arg;";
3418 stream << indent_str;
3421 stream << indent_str;
3422 stream << " break;";
3424 stream << indent_str;
3428 stream << " case ARG_DOUBLE:";
3430 stream << indent_str;
3431 stream << " if (! *((double **)field)) {";
3433 stream << indent_str;
3434 stream << " *((double **)field) = (double *)malloc (sizeof (double));";
3436 stream << indent_str;
3437 stream << " (*((double **)field))[0] = default_value->double_arg;";
3439 stream << indent_str;
3442 stream << indent_str;
3443 stream << " break;";
3445 stream << indent_str;
3447 if (has_arg_longdouble)
3449 stream << " case ARG_LONGDOUBLE:";
3451 stream << indent_str;
3452 stream << " if (! *((long double **)field)) {";
3454 stream << indent_str;
3455 stream << " *((long double **)field) = (long double *)malloc (sizeof (long double));";
3457 stream << indent_str;
3458 stream << " (*((long double **)field))[0] = default_value->longdouble_arg;";
3460 stream << indent_str;
3463 stream << indent_str;
3464 stream << " break;";
3466 stream << indent_str;
3468 if (has_arg_longlong)
3470 stream << " case ARG_LONGLONG:";
3472 stream << indent_str;
3473 stream << "#ifdef HAVE_LONG_LONG";
3475 stream << indent_str;
3476 stream << " if (! *((long long int **)field)) {";
3478 stream << indent_str;
3479 stream << " *((long long int **)field) = (long long int *)malloc (sizeof (long long int));";
3481 stream << indent_str;
3482 stream << " (*((long long int **)field))[0] = default_value->longlong_arg;";
3484 stream << indent_str;
3487 stream << indent_str;
3490 stream << indent_str;
3491 stream << " if (! *((long **)field)) {";
3493 stream << indent_str;
3494 stream << " *((long **)field) = (long *)malloc (sizeof (long));";
3496 stream << indent_str;
3497 stream << " (*((long **)field))[0] = default_value->longlong_arg;";
3499 stream << indent_str;
3502 stream << indent_str;
3505 stream << indent_str;
3506 stream << " break;";
3508 stream << indent_str;
3512 stream << " case ARG_STRING:";
3514 stream << indent_str;
3515 stream << " if (! *((char ***)field)) {";
3517 stream << indent_str;
3518 stream << " *((char ***)field) = (char **)malloc (sizeof (char *));";
3520 stream << indent_str;
3521 stream << " (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg);";
3523 stream << indent_str;
3526 stream << indent_str;
3527 stream << " break;";
3529 stream << indent_str;
3531 stream << " default: break;";
3533 stream << indent_str;
3536 stream << indent_str;
3537 stream << " if (!(*orig_field)) {";
3539 stream << indent_str;
3540 stream << " *orig_field = (char **) malloc (sizeof (char *));";
3542 stream << indent_str;
3543 stream << " (*orig_field)[0] = 0;";
3545 stream << indent_str;
3548 stream << indent_str;
3551 stream << indent_str;
3554 stream << indent_str;
3557 stream << indent_str;
3562 stream << indent_str;
3563 stream << "static int check_modes(";
3565 stream << indent_str;
3566 stream << " int given1[], const char *options1[],";
3568 stream << indent_str;
3569 stream << " int given2[], const char *options2[])";
3571 stream << indent_str;
3574 stream << indent_str;
3575 stream << " int i = 0, j = 0, errors = 0;";
3577 stream << indent_str;
3582 stream << indent_str;
3583 stream << " while (given1[i] >= 0) {";
3585 stream << indent_str;
3586 stream << " if (given1[i]) {";
3588 stream << indent_str;
3589 stream << " while (given2[j] >= 0) {";
3591 stream << indent_str;
3592 stream << " if (given2[j]) {";
3594 stream << indent_str;
3595 stream << " ++errors;";
3597 stream << indent_str;
3598 stream << " fprintf(stderr, \"%s: option %s conflicts with option %s\\n\",";
3600 stream << indent_str;
3601 stream << " package_name, options1[i], options2[j]);";
3603 stream << indent_str;
3606 stream << indent_str;
3609 stream << indent_str;
3612 stream << indent_str;
3615 stream << indent_str;
3618 stream << indent_str;
3621 stream << indent_str;
3626 stream << indent_str;
3627 stream << " return errors;";
3629 stream << indent_str;
3632 stream << indent_str;
3635 stream << indent_str;
3638 stream << indent_str;
3639 generate_string (parser_name, stream, indent + indent_str.length ());
3640 stream << "_internal (";
3642 stream << indent_str;
3643 stream << " int argc, char **argv, struct ";
3644 generate_string (args_info, stream, indent + indent_str.length ());
3645 stream << " *args_info,";
3647 stream << indent_str;
3648 stream << " struct ";
3649 generate_string (parser_name, stream, indent + indent_str.length ());
3650 stream << "_params *params, const char *additional_error)";
3652 stream << indent_str;
3655 stream << indent_str;
3656 stream << " int c; /* Character of the parsed option. */";
3658 stream << indent_str;
3659 if (multiple_options_with_default)
3661 stream << " union generic_value multiple_default_value;";
3663 stream << indent_str;
3666 stream << indent_str;
3668 if (list_def.size () > 0)
3669 generate_string (list_def, stream, indent + indent_str.length ());
3671 generate_list_def (stream, indent + indent_str.length ());
3673 stream << indent_str;
3674 stream << " int error = 0;";
3676 stream << indent_str;
3677 stream << " struct ";
3678 generate_string (args_info, stream, indent + indent_str.length ());
3679 stream << " local_args_info;";
3681 stream << indent_str;
3686 stream << indent_str;
3687 stream << " int override;";
3689 stream << indent_str;
3690 stream << " int initialize;";
3692 stream << indent_str;
3693 stream << " int check_required;";
3695 stream << indent_str;
3696 stream << " int check_ambiguity;";
3698 stream << indent_str;
3702 stream << indent_str;
3703 stream << " char *optarg;";
3705 stream << indent_str;
3706 stream << " int optind;";
3708 stream << indent_str;
3709 stream << " int opterr;";
3711 stream << indent_str;
3712 stream << " int optopt;";
3714 stream << indent_str;
3718 stream << indent_str;
3719 stream << " package_name = argv[0];";
3721 stream << indent_str;
3726 stream << indent_str;
3727 stream << " override = params->override;";
3729 stream << indent_str;
3730 stream << " initialize = params->initialize;";
3732 stream << indent_str;
3733 stream << " check_required = params->check_required;";
3735 stream << indent_str;
3736 stream << " check_ambiguity = params->check_ambiguity;";
3738 stream << indent_str;
3740 stream << indent_str;
3741 stream << " if (initialize)";
3743 stream << indent_str;
3746 generate_string (parser_name, stream, indent + indent_str.length ());
3747 stream << "_init (args_info);";
3750 stream << indent_str;
3752 stream << indent_str;
3755 generate_string (parser_name, stream, indent + indent_str.length ());
3756 stream << "_init (&local_args_info);";
3759 stream << indent_str;
3761 stream << indent_str;
3762 stream << " optarg = 0;";
3764 stream << indent_str;
3765 stream << " optind = 0;";
3767 stream << indent_str;
3768 stream << " opterr = params->print_errors;";
3770 stream << indent_str;
3771 stream << " optopt = '?';";
3773 stream << indent_str;
3775 stream << indent_str;
3776 stream << " while (1)";
3778 stream << indent_str;
3781 stream << indent_str;
3782 stream << " int option_index = 0;";
3784 stream << indent_str;
3786 stream << indent_str;
3787 stream << " static struct option long_options[] = {";
3789 stream << indent_str;
3791 if (long_option_struct.size () > 0)
3792 generate_string (long_option_struct, stream, indent + indent_str.length ());
3794 generate_long_option_struct (stream, indent + indent_str.length ());
3796 stream << indent_str;
3797 stream << " { 0, 0, 0, 0 }";
3799 stream << indent_str;
3802 stream << indent_str;
3804 stream << indent_str;
3807 stream << " custom_optarg = optarg;";
3809 stream << indent_str;
3810 stream << " custom_optind = optind;";
3812 stream << indent_str;
3813 stream << " custom_opterr = opterr;";
3815 stream << indent_str;
3816 stream << " custom_optopt = optopt;";
3818 stream << indent_str;
3820 stream << indent_str;
3821 stream << " c = custom_getopt_long (argc, argv, \"";
3822 generate_string (getopt_string, stream, indent + indent_str.length ());
3823 stream << "\", long_options, &option_index);";
3825 stream << indent_str;
3827 stream << indent_str;
3828 stream << " optarg = custom_optarg;";
3830 stream << indent_str;
3831 stream << " optind = custom_optind;";
3833 stream << indent_str;
3834 stream << " opterr = custom_opterr;";
3836 stream << indent_str;
3837 stream << " optopt = custom_optopt;";
3839 stream << indent_str;
3843 stream << " c = getopt_long (argc, argv, \"";
3844 generate_string (getopt_string, stream, indent + indent_str.length ());
3845 stream << "\", long_options, &option_index);";
3847 stream << indent_str;
3850 stream << indent_str;
3851 stream << " if (c == -1) break; /* Exit from `while (1)' loop. */";
3853 stream << indent_str;
3855 stream << indent_str;
3856 stream << " switch (c)";
3858 stream << indent_str;
3861 stream << indent_str;
3863 if (handle_option.size () > 0)
3864 generate_string (handle_option, stream, indent + indent_str.length ());
3866 generate_handle_option (stream, indent + indent_str.length ());
3868 stream << indent_str;
3870 stream << indent_str;
3871 stream << " case 0: /* Long option with no short option */";
3873 stream << indent_str;
3875 if (handle_no_short_option.size () > 0)
3876 generate_string (handle_no_short_option, stream, indent + indent_str.length ());
3878 generate_handle_no_short_option (stream, indent + indent_str.length ());
3880 stream << indent_str;
3881 if (handle_question_mark)
3883 stream << " case '?': /* Invalid option. */";
3885 stream << indent_str;
3886 stream << " /* `getopt_long' already printed an error message. */";
3888 stream << indent_str;
3889 stream << " goto failure;";
3891 stream << indent_str;
3894 stream << indent_str;
3895 stream << " default: /* bug: option not considered. */";
3897 stream << indent_str;
3898 stream << " fprintf (stderr, \"%s: option unknown: %c%s\\n\", ";
3899 generate_string (package_var_name, stream, indent + indent_str.length ());
3900 stream << ", c, (additional_error ? additional_error : \"\"));";
3902 stream << indent_str;
3903 stream << " abort ();";
3905 stream << indent_str;
3906 stream << " } /* switch */";
3908 stream << indent_str;
3909 stream << " } /* while */";
3911 stream << indent_str;
3913 stream << indent_str;
3915 if (handle_group.size () > 0)
3916 generate_string (handle_group, stream, indent + indent_str.length ());
3918 generate_handle_group (stream, indent + indent_str.length ());
3920 stream << indent_str;
3922 stream << indent_str;
3924 if (multiple_fill_array.size () > 0)
3925 generate_string (multiple_fill_array, stream, indent + indent_str.length ());
3927 generate_multiple_fill_array (stream, indent + indent_str.length ());
3929 stream << indent_str;
3931 if (update_multiple_given.size () > 0)
3932 generate_string (update_multiple_given, stream, indent + indent_str.length ());
3934 generate_update_multiple_given (stream, indent + indent_str.length ());
3936 stream << indent_str;
3938 if (check_modes.size () > 0)
3939 generate_string (check_modes, stream, indent + indent_str.length ());
3941 generate_check_modes (stream, indent + indent_str.length ());
3943 stream << indent_str;
3945 stream << indent_str;
3946 if (check_required_options)
3948 stream << " if (check_required)";
3950 stream << indent_str;
3953 stream << indent_str;
3954 stream << " error += ";
3955 generate_string (parser_name, stream, indent + indent_str.length ());
3956 stream << "_required2 (args_info, argv[0], additional_error);";
3958 stream << indent_str;
3961 stream << indent_str;
3964 stream << indent_str;
3967 generate_string (parser_name, stream, indent + indent_str.length ());
3968 stream << "_release (&local_args_info);";
3971 stream << indent_str;
3973 stream << indent_str;
3974 stream << " if ( error )";
3976 stream << indent_str;
3977 stream << " return (EXIT_FAILURE);";
3979 stream << indent_str;
3981 stream << indent_str;
3984 stream << " if (optind < argc)";
3986 stream << indent_str;
3989 stream << indent_str;
3990 stream << " int i = 0 ;";
3992 stream << indent_str;
3993 stream << " int found_prog_name = 0;";
3995 stream << indent_str;
3996 stream << " /* whether program name, i.e., argv[0], is in the remaining args";
3998 stream << indent_str;
3999 stream << " (this may happen with some implementations of getopt,";
4001 stream << indent_str;
4002 stream << " but surely not with the one included by gengetopt) */";
4004 stream << indent_str;
4006 stream << indent_str;
4014 stream << " i = optind;";
4016 stream << indent_str;
4017 stream << " while (i < argc)";
4019 stream << indent_str;
4020 stream << " if (argv[i++] == argv[0]) {";
4022 stream << indent_str;
4023 stream << " found_prog_name = 1;";
4025 stream << indent_str;
4026 stream << " break;";
4028 stream << indent_str;
4031 stream << indent_str;
4032 stream << " i = 0;";
4034 stream << indent_str;
4037 stream << indent_str;
4038 stream << " args_info->inputs_num = argc - optind - found_prog_name;";
4040 stream << indent_str;
4041 stream << " args_info->inputs =";
4043 stream << indent_str;
4044 stream << " (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;";
4046 stream << indent_str;
4047 stream << " while (optind < argc)";
4049 stream << indent_str;
4052 stream << " args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;";
4054 stream << indent_str;
4058 stream << " if (argv[optind++] != argv[0])";
4060 stream << indent_str;
4061 stream << " args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;";
4063 stream << indent_str;
4067 stream << indent_str;
4069 stream << indent_str;
4071 stream << " return 0;";
4073 stream << indent_str;
4075 stream << indent_str;
4076 stream << "failure:";
4078 stream << indent_str;
4081 if (list_free.size () > 0)
4082 generate_string (list_free, stream, indent + indent_str.length ());
4084 generate_list_free (stream, indent + indent_str.length ());
4087 stream << indent_str;
4090 generate_string (parser_name, stream, indent + indent_str.length ());
4091 stream << "_release (&local_args_info);";
4094 stream << indent_str;
4095 stream << " return (EXIT_FAILURE);";
4097 stream << indent_str;
4100 stream << indent_str;
4104 stream << indent_str;
4105 stream << "#ifndef CONFIG_FILE_LINE_SIZE";
4107 stream << indent_str;
4108 stream << "#define CONFIG_FILE_LINE_SIZE 2048";
4110 stream << indent_str;
4113 stream << indent_str;
4114 stream << "#define ADDITIONAL_ERROR \" in configuration file \"";
4116 stream << indent_str;
4118 stream << indent_str;
4119 stream << "#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)";
4121 stream << indent_str;
4122 stream << "/* 3 is for \"--\" and \"=\" */";
4124 stream << indent_str;
4126 stream << indent_str;
4127 stream << "static int";
4129 stream << indent_str;
4131 generate_string (parser_name, stream, indent + indent_str.length ());
4132 stream << "_configfile (const char *filename, int *my_argc)";
4134 stream << indent_str;
4137 stream << indent_str;
4138 stream << " FILE* file;";
4140 stream << indent_str;
4141 stream << " char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];";
4143 stream << indent_str;
4144 stream << " char linebuf[CONFIG_FILE_LINE_SIZE];";
4146 stream << indent_str;
4147 stream << " int line_num = 0;";
4149 stream << indent_str;
4150 stream << " int result = 0, equal;";
4152 stream << indent_str;
4153 stream << " char *fopt, *farg;";
4155 stream << indent_str;
4156 stream << " char *str_index;";
4158 stream << indent_str;
4159 stream << " size_t len, next_token;";
4161 stream << indent_str;
4162 stream << " char delimiter;";
4164 stream << indent_str;
4166 stream << indent_str;
4167 stream << " if ((file = fopen(filename, \"r\")) == 0)";
4169 stream << indent_str;
4172 stream << indent_str;
4173 stream << " fprintf (stderr, \"%s: Error opening configuration file '%s'\\n\",";
4175 stream << indent_str;
4178 generate_string (package_var_name, stream, indent + indent_str.length ());
4179 stream << ", filename);";
4182 stream << indent_str;
4183 stream << " return EXIT_FAILURE;";
4185 stream << indent_str;
4188 stream << indent_str;
4190 stream << indent_str;
4191 stream << " while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != 0)";
4193 stream << indent_str;
4196 stream << indent_str;
4197 stream << " ++line_num;";
4199 stream << indent_str;
4200 stream << " my_argv[0] = '\\0';";
4202 stream << indent_str;
4203 stream << " len = strlen(linebuf);";
4205 stream << indent_str;
4206 stream << " if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))";
4208 stream << indent_str;
4211 stream << indent_str;
4212 stream << " fprintf (stderr, \"%s:%s:%d: Line too long in configuration file\\n\",";
4214 stream << indent_str;
4217 generate_string (package_var_name, stream, indent + indent_str.length ());
4218 stream << ", filename, line_num);";
4221 stream << indent_str;
4222 stream << " result = EXIT_FAILURE;";
4224 stream << indent_str;
4225 stream << " break;";
4227 stream << indent_str;
4230 stream << indent_str;
4232 stream << indent_str;
4233 stream << " /* find first non-whitespace character in the line */";
4235 stream << indent_str;
4236 stream << " next_token = strspn (linebuf, \" \\t\\r\\n\");";
4238 stream << indent_str;
4239 stream << " str_index = linebuf + next_token;";
4241 stream << indent_str;
4243 stream << indent_str;
4244 stream << " if ( str_index[0] == '\\0' || str_index[0] == '#')";
4246 stream << indent_str;
4247 stream << " continue; /* empty line or comment line is skipped */";
4249 stream << indent_str;
4251 stream << indent_str;
4252 stream << " fopt = str_index;";
4254 stream << indent_str;
4256 stream << indent_str;
4257 stream << " /* truncate fopt at the end of the first non-valid character */";
4259 stream << indent_str;
4260 stream << " next_token = strcspn (fopt, \" \\t\\r\\n=\");";
4262 stream << indent_str;
4264 stream << indent_str;
4265 stream << " if (fopt[next_token] == '\\0') /* the line is over */";
4267 stream << indent_str;
4270 stream << indent_str;
4271 stream << " farg = 0;";
4273 stream << indent_str;
4274 stream << " equal = 0;";
4276 stream << indent_str;
4277 stream << " goto noarg;";
4279 stream << indent_str;
4282 stream << indent_str;
4284 stream << indent_str;
4285 stream << " /* remember if equal sign is present */";
4287 stream << indent_str;
4288 stream << " equal = (fopt[next_token] == '=');";
4290 stream << indent_str;
4291 stream << " fopt[next_token++] = '\\0';";
4293 stream << indent_str;
4295 stream << indent_str;
4296 stream << " /* advance pointers to the next token after the end of fopt */";
4298 stream << indent_str;
4299 stream << " next_token += strspn (fopt + next_token, \" \\t\\r\\n\");";
4301 stream << indent_str;
4303 stream << indent_str;
4304 stream << " /* check for the presence of equal sign, and if so, skip it */";
4306 stream << indent_str;
4307 stream << " if ( !equal )";
4309 stream << indent_str;
4310 stream << " if ((equal = (fopt[next_token] == '=')))";
4312 stream << indent_str;
4315 stream << indent_str;
4316 stream << " next_token++;";
4318 stream << indent_str;
4319 stream << " next_token += strspn (fopt + next_token, \" \\t\\r\\n\");";
4321 stream << indent_str;
4324 stream << indent_str;
4325 stream << " str_index += next_token;";
4327 stream << indent_str;
4329 stream << indent_str;
4330 stream << " /* find argument */";
4332 stream << indent_str;
4333 stream << " farg = str_index;";
4335 stream << indent_str;
4336 stream << " if ( farg[0] == '\\\"' || farg[0] == '\\'' )";
4338 stream << indent_str;
4339 stream << " { /* quoted argument */";
4341 stream << indent_str;
4342 stream << " str_index = strchr (++farg, str_index[0] ); /* skip opening quote */";
4344 stream << indent_str;
4345 stream << " if (! str_index)";
4347 stream << indent_str;
4350 stream << indent_str;
4351 stream << " fprintf";
4353 stream << indent_str;
4354 stream << " (stderr,";
4356 stream << indent_str;
4357 stream << " \"%s:%s:%d: unterminated string in configuration file\\n\",";
4359 stream << indent_str;
4362 generate_string (package_var_name, stream, indent + indent_str.length ());
4363 stream << ", filename, line_num);";
4366 stream << indent_str;
4367 stream << " result = EXIT_FAILURE;";
4369 stream << indent_str;
4370 stream << " break;";
4372 stream << indent_str;
4375 stream << indent_str;
4378 stream << indent_str;
4381 stream << indent_str;
4382 stream << " { /* read up the remaining part up to a delimiter */";
4384 stream << indent_str;
4385 stream << " next_token = strcspn (farg, \" \\t\\r\\n#\\'\\\"\");";
4387 stream << indent_str;
4388 stream << " str_index += next_token;";
4390 stream << indent_str;
4393 stream << indent_str;
4395 stream << indent_str;
4396 stream << " /* truncate farg at the delimiter and store it for further check */";
4398 stream << indent_str;
4399 stream << " delimiter = *str_index, *str_index++ = '\\0';";
4401 stream << indent_str;
4403 stream << indent_str;
4404 stream << " /* everything but comment is illegal at the end of line */";
4406 stream << indent_str;
4407 stream << " if (delimiter != '\\0' && delimiter != '#')";
4409 stream << indent_str;
4412 stream << indent_str;
4413 stream << " str_index += strspn(str_index, \" \\t\\r\\n\");";
4415 stream << indent_str;
4416 stream << " if (*str_index != '\\0' && *str_index != '#')";
4418 stream << indent_str;
4421 stream << indent_str;
4422 stream << " fprintf";
4424 stream << indent_str;
4425 stream << " (stderr,";
4427 stream << indent_str;
4428 stream << " \"%s:%s:%d: malformed string in configuration file\\n\",";
4430 stream << indent_str;
4433 generate_string (package_var_name, stream, indent + indent_str.length ());
4434 stream << ", filename, line_num);";
4437 stream << indent_str;
4438 stream << " result = EXIT_FAILURE;";
4440 stream << indent_str;
4441 stream << " break;";
4443 stream << indent_str;
4446 stream << indent_str;
4449 stream << indent_str;
4451 stream << indent_str;
4452 stream << " noarg:";
4454 stream << indent_str;
4455 stream << " if (!strcmp(fopt,\"include\")) {";
4457 stream << indent_str;
4458 stream << " if (farg && *farg) {";
4460 stream << indent_str;
4461 stream << " result = _";
4462 generate_string (parser_name, stream, indent + indent_str.length ());
4463 stream << "_configfile(farg, my_argc);";
4465 stream << indent_str;
4466 stream << " } else {";
4468 stream << indent_str;
4469 stream << " fprintf(stderr, \"%s:%s:%d: include requires a filename argument.\\n\",";
4471 stream << indent_str;
4474 generate_string (package_var_name, stream, indent + indent_str.length ());
4475 stream << ", filename, line_num);";
4478 stream << indent_str;
4481 stream << indent_str;
4482 stream << " continue;";
4484 stream << indent_str;
4487 stream << indent_str;
4488 stream << " len = strlen(fopt);";
4490 stream << indent_str;
4491 stream << " strcat (my_argv, len > 1 ? \"--\" : \"-\");";
4493 stream << indent_str;
4494 stream << " strcat (my_argv, fopt);";
4496 stream << indent_str;
4497 stream << " if (len > 1 && ((farg && *farg) || equal))";
4499 stream << indent_str;
4500 stream << " strcat (my_argv, \"=\");";
4502 stream << indent_str;
4503 stream << " if (farg && *farg)";
4505 stream << indent_str;
4506 stream << " strcat (my_argv, farg);";
4508 stream << indent_str;
4509 stream << " ++(*my_argc);";
4511 stream << indent_str;
4513 stream << indent_str;
4514 stream << " cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));";
4516 stream << indent_str;
4517 stream << " cmd_line_list_tmp->next = cmd_line_list;";
4519 stream << indent_str;
4520 stream << " cmd_line_list = cmd_line_list_tmp;";
4522 stream << indent_str;
4523 stream << " cmd_line_list->string_arg = gengetopt_strdup(my_argv);";
4525 stream << indent_str;
4526 stream << " } /* while */";
4528 stream << indent_str;
4530 stream << indent_str;
4531 stream << " if (file)";
4533 stream << indent_str;
4534 stream << " fclose(file);";
4536 stream << indent_str;
4537 stream << " return result;";
4539 stream << indent_str;
4542 stream << indent_str;
4544 stream << indent_str;
4547 stream << indent_str;
4548 generate_string (parser_name, stream, indent + indent_str.length ());
4549 stream << "_configfile (";
4551 stream << indent_str;
4552 stream << " const char *filename,";
4554 stream << indent_str;
4555 stream << " struct ";
4556 generate_string (args_info, stream, indent + indent_str.length ());
4557 stream << " *args_info,";
4559 stream << indent_str;
4560 stream << " int override, int initialize, int check_required)";
4562 stream << indent_str;
4565 stream << indent_str;
4566 stream << " struct ";
4567 generate_string (parser_name, stream, indent + indent_str.length ());
4568 stream << "_params params;";
4570 stream << indent_str;
4572 stream << indent_str;
4573 stream << " params.override = override;";
4575 stream << indent_str;
4576 stream << " params.initialize = initialize;";
4578 stream << indent_str;
4579 stream << " params.check_required = check_required;";
4581 stream << indent_str;
4582 stream << " params.check_ambiguity = 0;";
4584 stream << indent_str;
4585 stream << " params.print_errors = 1;";
4587 stream << indent_str;
4592 stream << indent_str;
4593 stream << " return ";
4594 generate_string (parser_name, stream, indent + indent_str.length ());
4595 stream << "_config_file (filename, args_info, ¶ms);";
4597 stream << indent_str;
4600 stream << indent_str;
4602 stream << indent_str;
4605 stream << indent_str;
4606 generate_string (parser_name, stream, indent + indent_str.length ());
4607 stream << "_config_file (const char *filename,";
4609 stream << indent_str;
4610 stream << " struct ";
4611 generate_string (args_info, stream, indent + indent_str.length ());
4612 stream << " *args_info,";
4614 stream << indent_str;
4615 stream << " struct ";
4616 generate_string (parser_name, stream, indent + indent_str.length ());
4617 stream << "_params *params)";
4619 stream << indent_str;
4622 stream << indent_str;
4623 stream << " int i, result;";
4625 stream << indent_str;
4626 stream << " int my_argc = 1;";
4628 stream << indent_str;
4629 stream << " char **my_argv_arg;";
4631 stream << indent_str;
4632 stream << " char *additional_error;";
4634 stream << indent_str;
4636 stream << indent_str;
4637 stream << " /* store the program name */";
4639 stream << indent_str;
4640 stream << " cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));";
4642 stream << indent_str;
4643 stream << " cmd_line_list_tmp->next = cmd_line_list;";
4645 stream << indent_str;
4646 stream << " cmd_line_list = cmd_line_list_tmp;";
4648 stream << indent_str;
4649 stream << " cmd_line_list->string_arg = gengetopt_strdup (";
4650 generate_string (package_var_name, stream, indent + indent_str.length ());
4653 stream << indent_str;
4655 stream << indent_str;
4656 stream << " result = _";
4657 generate_string (parser_name, stream, indent + indent_str.length ());
4658 stream << "_configfile(filename, &my_argc);";
4660 stream << indent_str;
4662 stream << indent_str;
4663 stream << " if (result != EXIT_FAILURE) {";
4665 stream << indent_str;
4666 stream << " my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));";
4668 stream << indent_str;
4669 stream << " cmd_line_list_tmp = cmd_line_list;";
4671 stream << indent_str;
4673 stream << indent_str;
4674 stream << " for (i = my_argc - 1; i >= 0; --i) {";
4676 stream << indent_str;
4677 stream << " my_argv_arg[i] = cmd_line_list_tmp->string_arg;";
4679 stream << indent_str;
4680 stream << " cmd_line_list_tmp = cmd_line_list_tmp->next;";
4682 stream << indent_str;
4685 stream << indent_str;
4687 stream << indent_str;
4688 stream << " my_argv_arg[my_argc] = 0;";
4690 stream << indent_str;
4692 stream << indent_str;
4693 stream << " additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);";
4695 stream << indent_str;
4696 stream << " strcpy (additional_error, ADDITIONAL_ERROR);";
4698 stream << indent_str;
4699 stream << " strcat (additional_error, filename);";
4701 stream << indent_str;
4702 stream << " result =";
4704 stream << indent_str;
4707 generate_string (parser_name, stream, indent + indent_str.length ());
4708 stream << "_internal (my_argc, my_argv_arg, args_info,";
4711 stream << indent_str;
4712 stream << " params,";
4714 stream << indent_str;
4715 stream << " additional_error);";
4717 stream << indent_str;
4719 stream << indent_str;
4720 stream << " free (additional_error);";
4722 stream << indent_str;
4723 stream << " free (my_argv_arg);";
4725 stream << indent_str;
4728 stream << indent_str;
4730 stream << indent_str;
4731 stream << " free_cmd_list();";
4733 stream << indent_str;
4736 generate_string (final_exit, stream, indent + indent_str.length ());
4739 stream << indent_str;
4742 stream << indent_str;
4744 if (generate_string_parser)
4747 stream << indent_str;
4748 stream << "static unsigned int";
4750 stream << indent_str;
4751 generate_string (parser_name, stream, indent + indent_str.length ());
4752 stream << "_create_argv(const char *cmdline_, char ***argv_ptr, const char *prog_name)";
4754 stream << indent_str;
4757 stream << indent_str;
4758 stream << " char *cmdline, *p;";
4760 stream << indent_str;
4761 stream << " size_t n = 0, j;";
4763 stream << indent_str;
4764 stream << " int i;";
4766 stream << indent_str;
4768 stream << indent_str;
4769 stream << " if (prog_name) {";
4771 stream << indent_str;
4772 stream << " cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));";
4774 stream << indent_str;
4775 stream << " cmd_line_list_tmp->next = cmd_line_list;";
4777 stream << indent_str;
4778 stream << " cmd_line_list = cmd_line_list_tmp;";
4780 stream << indent_str;
4781 stream << " cmd_line_list->string_arg = gengetopt_strdup (prog_name);";
4783 stream << indent_str;
4785 stream << indent_str;
4788 stream << indent_str;
4791 stream << indent_str;
4793 stream << indent_str;
4794 stream << " cmdline = gengetopt_strdup(cmdline_);";
4796 stream << indent_str;
4797 stream << " p = cmdline;";
4799 stream << indent_str;
4801 stream << indent_str;
4802 stream << " while (p && strlen(p))";
4804 stream << indent_str;
4807 stream << indent_str;
4808 stream << " j = strcspn(p, \" \\t\");";
4810 stream << indent_str;
4813 stream << indent_str;
4814 stream << " if (j && j < strlen(p))";
4816 stream << indent_str;
4819 stream << indent_str;
4820 stream << " p[j] = '\\0';";
4822 stream << indent_str;
4824 stream << indent_str;
4825 stream << " cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));";
4827 stream << indent_str;
4828 stream << " cmd_line_list_tmp->next = cmd_line_list;";
4830 stream << indent_str;
4831 stream << " cmd_line_list = cmd_line_list_tmp;";
4833 stream << indent_str;
4834 stream << " cmd_line_list->string_arg = gengetopt_strdup (p);";
4836 stream << indent_str;
4838 stream << indent_str;
4839 stream << " p += (j+1);";
4841 stream << indent_str;
4842 stream << " p += strspn(p, \" \\t\");";
4844 stream << indent_str;
4847 stream << indent_str;
4850 stream << indent_str;
4853 stream << indent_str;
4854 stream << " cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));";
4856 stream << indent_str;
4857 stream << " cmd_line_list_tmp->next = cmd_line_list;";
4859 stream << indent_str;
4860 stream << " cmd_line_list = cmd_line_list_tmp;";
4862 stream << indent_str;
4863 stream << " cmd_line_list->string_arg = gengetopt_strdup (p);";
4865 stream << indent_str;
4867 stream << indent_str;
4868 stream << " break;";
4870 stream << indent_str;
4873 stream << indent_str;
4876 stream << indent_str;
4878 stream << indent_str;
4879 stream << " *argv_ptr = (char **) malloc((n + 1) * sizeof(char *));";
4881 stream << indent_str;
4882 stream << " cmd_line_list_tmp = cmd_line_list;";
4884 stream << indent_str;
4885 stream << " for (i = (n-1); i >= 0; --i)";
4887 stream << indent_str;
4890 stream << indent_str;
4891 stream << " (*argv_ptr)[i] = cmd_line_list_tmp->string_arg;";
4893 stream << indent_str;
4894 stream << " cmd_line_list_tmp = cmd_line_list_tmp->next;";
4896 stream << indent_str;
4899 stream << indent_str;
4901 stream << indent_str;
4902 stream << " (*argv_ptr)[n] = 0;";
4904 stream << indent_str;
4906 stream << indent_str;
4907 stream << " free(cmdline);";
4909 stream << indent_str;
4910 stream << " return n;";
4912 stream << indent_str;
4915 stream << indent_str;
4917 stream << indent_str;
4920 stream << indent_str;
4921 generate_string (parser_name, stream, indent + indent_str.length ());
4922 stream << "_string(const char *cmdline, struct ";
4923 generate_string (args_info, stream, indent + indent_str.length ());
4924 stream << " *args_info, const char *prog_name)";
4926 stream << indent_str;
4929 stream << indent_str;
4930 stream << " return ";
4931 generate_string (parser_name, stream, indent + indent_str.length ());
4932 stream << "_string2(cmdline, args_info, prog_name, 0, 1, 1);";
4934 stream << indent_str;
4937 stream << indent_str;
4939 stream << indent_str;
4942 stream << indent_str;
4943 generate_string (parser_name, stream, indent + indent_str.length ());
4944 stream << "_string2(const char *cmdline, struct ";
4945 generate_string (args_info, stream, indent + indent_str.length ());
4946 stream << " *args_info, const char *prog_name,";
4948 stream << indent_str;
4949 stream << " int override, int initialize, int check_required)";
4951 stream << indent_str;
4954 stream << indent_str;
4955 stream << " struct ";
4956 generate_string (parser_name, stream, indent + indent_str.length ());
4957 stream << "_params params;";
4959 stream << indent_str;
4961 stream << indent_str;
4962 stream << " params.override = override;";
4964 stream << indent_str;
4965 stream << " params.initialize = initialize;";
4967 stream << indent_str;
4968 stream << " params.check_required = check_required;";
4970 stream << indent_str;
4971 stream << " params.check_ambiguity = 0;";
4973 stream << indent_str;
4974 stream << " params.print_errors = 1;";
4976 stream << indent_str;
4978 stream << indent_str;
4979 stream << " return ";
4980 generate_string (parser_name, stream, indent + indent_str.length ());
4981 stream << "_string_ext(cmdline, args_info, prog_name, ¶ms);";
4983 stream << indent_str;
4986 stream << indent_str;
4988 stream << indent_str;
4991 stream << indent_str;
4992 generate_string (parser_name, stream, indent + indent_str.length ());
4993 stream << "_string_ext(const char *cmdline, struct ";
4994 generate_string (args_info, stream, indent + indent_str.length ());
4995 stream << " *args_info, const char *prog_name,";
4997 stream << indent_str;
4998 stream << " struct ";
4999 generate_string (parser_name, stream, indent + indent_str.length ());
5000 stream << "_params *params)";
5002 stream << indent_str;
5005 stream << indent_str;
5006 stream << " char **argv_ptr = 0;";
5008 stream << indent_str;
5009 stream << " int result;";
5011 stream << indent_str;
5012 stream << " unsigned int argc;";
5014 stream << indent_str;
5019 stream << indent_str;
5020 stream << " argc = ";
5021 generate_string (parser_name, stream, indent + indent_str.length ());
5022 stream << "_create_argv(cmdline, &argv_ptr, prog_name);";
5024 stream << indent_str;
5029 stream << indent_str;
5030 stream << " result =";
5032 stream << indent_str;
5035 generate_string (parser_name, stream, indent + indent_str.length ());
5036 stream << "_internal (argc, argv_ptr, args_info, params, 0);";
5039 stream << indent_str;
5044 stream << indent_str;
5045 stream << " if (argv_ptr)";
5047 stream << indent_str;
5050 stream << indent_str;
5051 stream << " free (argv_ptr);";
5053 stream << indent_str;
5056 stream << indent_str;
5058 stream << indent_str;
5059 stream << " free_cmd_list();";
5061 stream << indent_str;
5066 stream << indent_str;
5069 generate_string (final_exit, stream, indent + indent_str.length ());
5072 stream << indent_str;
5075 stream << indent_str;
5077 stream << indent_str;