2 File autogenerated by gengetopt version 2.19.1
3 generated with the following command:
4 gengetopt -uCOMMAND --set-version=0.3
6 The developers of gengetopt consider the fixed text that goes in all
7 gengetopt output files to be in the public domain:
8 we make no copyright claims on it.
11 /* If we use autoconf. */
24 const char *gengetopt_args_info_purpose
= "";
26 const char *gengetopt_args_info_usage
= "Usage: untie [OPTIONS]... [COMMAND]...";
28 const char *gengetopt_args_info_description
= "";
30 const char *gengetopt_args_info_help
[] = {
31 " -h, --help Print help and exit",
32 " -V, --version Print version and exit",
33 " --mount New mount namespace (default=off)",
34 " --uname New uname (default=off)",
35 " --ipc New IPC context (default=off)",
36 " --mask=MASK Pass user defined flag",
37 " --chroot=DIRECTORY Chroot in the specified directory",
38 " --uid=UID Change to the specified UID",
39 " --username=USERNAME Change to the specified username",
40 " --gid=GID Add the specified GID",
41 " --groupname=GROUP Add the specified group",
42 " --daemonize Run as daemon (default=off)",
43 " --alarm=SECONDS Set an alarm after the specified delay",
44 " --nice=NICE Run as the specified nice level",
45 " --sched=SCHED Use the specified (possibly RT) scheduling policy",
46 " --schedprio=PRIO Set the priority according to the given scheduler",
51 void clear_given (struct gengetopt_args_info
*args_info
);
53 void clear_args (struct gengetopt_args_info
*args_info
);
56 cmdline_parser_internal (int argc
, char * const *argv
, struct gengetopt_args_info
*args_info
, int override
, int initialize
, int check_required
, const char *additional_error
);
59 cmdline_parser_required2 (struct gengetopt_args_info
*args_info
, const char *prog_name
, const char *additional_error
);
65 struct int_list
* next
;
72 struct string_list
* next
;
76 gengetopt_strdup (const char *s
);
79 void clear_given (struct gengetopt_args_info
*args_info
)
81 args_info
->help_given
= 0 ;
82 args_info
->version_given
= 0 ;
83 args_info
->mount_given
= 0 ;
84 args_info
->uname_given
= 0 ;
85 args_info
->ipc_given
= 0 ;
86 args_info
->mask_given
= 0 ;
87 args_info
->chroot_given
= 0 ;
88 args_info
->uid_given
= 0 ;
89 args_info
->username_given
= 0 ;
90 args_info
->gid_given
= 0 ;
91 args_info
->groupname_given
= 0 ;
92 args_info
->daemonize_given
= 0 ;
93 args_info
->alarm_given
= 0 ;
94 args_info
->nice_given
= 0 ;
95 args_info
->sched_given
= 0 ;
96 args_info
->schedprio_given
= 0 ;
100 void clear_args (struct gengetopt_args_info
*args_info
)
102 args_info
->mount_flag
= 0;
103 args_info
->uname_flag
= 0;
104 args_info
->ipc_flag
= 0;
105 args_info
->mask_arg
= NULL
;
106 args_info
->mask_orig
= NULL
;
107 args_info
->chroot_arg
= NULL
;
108 args_info
->chroot_orig
= NULL
;
109 args_info
->uid_orig
= NULL
;
110 args_info
->username_arg
= NULL
;
111 args_info
->username_orig
= NULL
;
112 args_info
->gid_arg
= NULL
;
113 args_info
->gid_orig
= NULL
;
114 args_info
->groupname_arg
= NULL
;
115 args_info
->groupname_orig
= NULL
;
116 args_info
->daemonize_flag
= 0;
117 args_info
->alarm_orig
= NULL
;
118 args_info
->nice_orig
= NULL
;
119 args_info
->sched_arg
= NULL
;
120 args_info
->sched_orig
= NULL
;
121 args_info
->schedprio_orig
= NULL
;
126 void init_args_info(struct gengetopt_args_info
*args_info
)
128 args_info
->help_help
= gengetopt_args_info_help
[0] ;
129 args_info
->version_help
= gengetopt_args_info_help
[1] ;
130 args_info
->mount_help
= gengetopt_args_info_help
[2] ;
131 args_info
->uname_help
= gengetopt_args_info_help
[3] ;
132 args_info
->ipc_help
= gengetopt_args_info_help
[4] ;
133 args_info
->mask_help
= gengetopt_args_info_help
[5] ;
134 args_info
->mask_min
= -1;
135 args_info
->mask_max
= -1;
136 args_info
->chroot_help
= gengetopt_args_info_help
[6] ;
137 args_info
->uid_help
= gengetopt_args_info_help
[7] ;
138 args_info
->username_help
= gengetopt_args_info_help
[8] ;
139 args_info
->gid_help
= gengetopt_args_info_help
[9] ;
140 args_info
->gid_min
= -1;
141 args_info
->gid_max
= -1;
142 args_info
->groupname_help
= gengetopt_args_info_help
[10] ;
143 args_info
->groupname_min
= -1;
144 args_info
->groupname_max
= -1;
145 args_info
->daemonize_help
= gengetopt_args_info_help
[11] ;
146 args_info
->alarm_help
= gengetopt_args_info_help
[12] ;
147 args_info
->nice_help
= gengetopt_args_info_help
[13] ;
148 args_info
->sched_help
= gengetopt_args_info_help
[14] ;
149 args_info
->schedprio_help
= gengetopt_args_info_help
[15] ;
154 cmdline_parser_print_version (void)
156 printf ("%s %s\n", CMDLINE_PARSER_PACKAGE
, CMDLINE_PARSER_VERSION
);
160 cmdline_parser_print_help (void)
163 cmdline_parser_print_version ();
165 if (strlen(gengetopt_args_info_purpose
) > 0)
166 printf("\n%s\n", gengetopt_args_info_purpose
);
168 printf("\n%s\n\n", gengetopt_args_info_usage
);
170 if (strlen(gengetopt_args_info_description
) > 0)
171 printf("%s\n", gengetopt_args_info_description
);
173 while (gengetopt_args_info_help
[i
])
174 printf("%s\n", gengetopt_args_info_help
[i
++]);
178 cmdline_parser_init (struct gengetopt_args_info
*args_info
)
180 clear_given (args_info
);
181 clear_args (args_info
);
182 init_args_info (args_info
);
184 args_info
->inputs
= NULL
;
185 args_info
->inputs_num
= 0;
189 cmdline_parser_release (struct gengetopt_args_info
*args_info
)
193 if (args_info
->mask_arg
)
195 for (i
= 0; i
< args_info
->mask_given
; ++i
)
197 if (args_info
->mask_orig
[i
])
199 free (args_info
->mask_orig
[i
]); /* free previous argument */
200 args_info
->mask_orig
[i
] = 0;
203 free (args_info
->mask_arg
); /* free previous argument */
204 args_info
->mask_arg
= 0;
205 free (args_info
->mask_orig
); /* free previous argument */
206 args_info
->mask_orig
= 0;
208 if (args_info
->chroot_arg
)
210 free (args_info
->chroot_arg
); /* free previous argument */
211 args_info
->chroot_arg
= 0;
213 if (args_info
->chroot_orig
)
215 free (args_info
->chroot_orig
); /* free previous argument */
216 args_info
->chroot_orig
= 0;
218 if (args_info
->uid_orig
)
220 free (args_info
->uid_orig
); /* free previous argument */
221 args_info
->uid_orig
= 0;
223 if (args_info
->username_arg
)
225 free (args_info
->username_arg
); /* free previous argument */
226 args_info
->username_arg
= 0;
228 if (args_info
->username_orig
)
230 free (args_info
->username_orig
); /* free previous argument */
231 args_info
->username_orig
= 0;
233 if (args_info
->gid_arg
)
235 for (i
= 0; i
< args_info
->gid_given
; ++i
)
237 if (args_info
->gid_orig
[i
])
239 free (args_info
->gid_orig
[i
]); /* free previous argument */
240 args_info
->gid_orig
[i
] = 0;
243 free (args_info
->gid_arg
); /* free previous argument */
244 args_info
->gid_arg
= 0;
245 free (args_info
->gid_orig
); /* free previous argument */
246 args_info
->gid_orig
= 0;
248 if (args_info
->groupname_arg
)
250 for (i
= 0; i
< args_info
->groupname_given
; ++i
)
252 if (args_info
->groupname_arg
[i
])
254 free (args_info
->groupname_arg
[i
]); /* free previous argument */
255 args_info
->groupname_arg
[i
] = 0;
257 if (args_info
->groupname_orig
[i
])
259 free (args_info
->groupname_orig
[i
]); /* free previous argument */
260 args_info
->groupname_orig
[i
] = 0;
263 if (args_info
->groupname_arg
[0])
264 free (args_info
->groupname_arg
[0]); /* free default string */
265 free (args_info
->groupname_arg
); /* free previous argument */
266 args_info
->groupname_arg
= 0;
267 free (args_info
->groupname_orig
); /* free previous argument */
268 args_info
->groupname_orig
= 0;
270 if (args_info
->alarm_orig
)
272 free (args_info
->alarm_orig
); /* free previous argument */
273 args_info
->alarm_orig
= 0;
275 if (args_info
->nice_orig
)
277 free (args_info
->nice_orig
); /* free previous argument */
278 args_info
->nice_orig
= 0;
280 if (args_info
->sched_arg
)
282 free (args_info
->sched_arg
); /* free previous argument */
283 args_info
->sched_arg
= 0;
285 if (args_info
->sched_orig
)
287 free (args_info
->sched_orig
); /* free previous argument */
288 args_info
->sched_orig
= 0;
290 if (args_info
->schedprio_orig
)
292 free (args_info
->schedprio_orig
); /* free previous argument */
293 args_info
->schedprio_orig
= 0;
296 for (i
= 0; i
< args_info
->inputs_num
; ++i
)
297 free (args_info
->inputs
[i
]);
299 if (args_info
->inputs_num
)
300 free (args_info
->inputs
);
302 clear_given (args_info
);
306 cmdline_parser_file_save(const char *filename
, struct gengetopt_args_info
*args_info
)
311 outfile
= fopen(filename
, "w");
315 fprintf (stderr
, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE
, filename
);
319 if (args_info
->help_given
) {
320 fprintf(outfile
, "%s\n", "help");
322 if (args_info
->version_given
) {
323 fprintf(outfile
, "%s\n", "version");
325 if (args_info
->mount_given
) {
326 fprintf(outfile
, "%s\n", "mount");
328 if (args_info
->uname_given
) {
329 fprintf(outfile
, "%s\n", "uname");
331 if (args_info
->ipc_given
) {
332 fprintf(outfile
, "%s\n", "ipc");
334 if (args_info
->mask_orig
)
336 for (i
= 0; i
< args_info
->mask_given
; ++i
)
338 if (args_info
->mask_orig
[i
])
340 fprintf(outfile
, "%s=\"%s\"\n", "mask", args_info
->mask_orig
[i
]);
344 if (args_info
->chroot_given
) {
345 if (args_info
->chroot_orig
) {
346 fprintf(outfile
, "%s=\"%s\"\n", "chroot", args_info
->chroot_orig
);
348 fprintf(outfile
, "%s\n", "chroot");
351 if (args_info
->uid_given
) {
352 if (args_info
->uid_orig
) {
353 fprintf(outfile
, "%s=\"%s\"\n", "uid", args_info
->uid_orig
);
355 fprintf(outfile
, "%s\n", "uid");
358 if (args_info
->username_given
) {
359 if (args_info
->username_orig
) {
360 fprintf(outfile
, "%s=\"%s\"\n", "username", args_info
->username_orig
);
362 fprintf(outfile
, "%s\n", "username");
365 if (args_info
->gid_orig
)
367 for (i
= 0; i
< args_info
->gid_given
; ++i
)
369 if (args_info
->gid_orig
[i
])
371 fprintf(outfile
, "%s=\"%s\"\n", "gid", args_info
->gid_orig
[i
]);
375 if (args_info
->groupname_orig
)
377 for (i
= 0; i
< args_info
->groupname_given
; ++i
)
379 if (args_info
->groupname_orig
[i
])
381 fprintf(outfile
, "%s=\"%s\"\n", "groupname", args_info
->groupname_orig
[i
]);
385 if (args_info
->daemonize_given
) {
386 fprintf(outfile
, "%s\n", "daemonize");
388 if (args_info
->alarm_given
) {
389 if (args_info
->alarm_orig
) {
390 fprintf(outfile
, "%s=\"%s\"\n", "alarm", args_info
->alarm_orig
);
392 fprintf(outfile
, "%s\n", "alarm");
395 if (args_info
->nice_given
) {
396 if (args_info
->nice_orig
) {
397 fprintf(outfile
, "%s=\"%s\"\n", "nice", args_info
->nice_orig
);
399 fprintf(outfile
, "%s\n", "nice");
402 if (args_info
->sched_given
) {
403 if (args_info
->sched_orig
) {
404 fprintf(outfile
, "%s=\"%s\"\n", "sched", args_info
->sched_orig
);
406 fprintf(outfile
, "%s\n", "sched");
409 if (args_info
->schedprio_given
) {
410 if (args_info
->schedprio_orig
) {
411 fprintf(outfile
, "%s=\"%s\"\n", "schedprio", args_info
->schedprio_orig
);
413 fprintf(outfile
, "%s\n", "schedprio");
424 cmdline_parser_free (struct gengetopt_args_info
*args_info
)
426 cmdline_parser_release (args_info
);
430 /* gengetopt_strdup() */
431 /* strdup.c replacement of strdup, which is not standard */
433 gengetopt_strdup (const char *s
)
439 result
= (char*)malloc(strlen(s
) + 1);
440 if (result
== (char*)0)
447 get_multiple_arg_token(const char *arg
)
450 size_t len
, num_of_escape
;
456 tok
= strchr (arg
, ',');
459 /* make sure it is not escaped */
462 if (*(tok
-1) == '\\')
464 /* find the next one */
465 tok
= strchr (tok
+1, ',');
473 len
= (size_t)(tok
- arg
+ 1);
475 len
= strlen (arg
) + 1;
477 len
-= num_of_escape
;
479 ret
= (char *) malloc (len
);
483 while (arg
[i
] && (j
< len
-1))
497 get_multiple_arg_token_next(const char *arg
)
504 tok
= strchr (arg
, ',');
506 /* make sure it is not escaped */
509 if (*(tok
-1) == '\\')
511 /* find the next one */
512 tok
= strchr (tok
+1, ',');
518 if (! tok
|| strlen(tok
) == 1)
525 check_multiple_option_occurrences(const char *prog_name
, unsigned int option_given
, int min
, int max
, const char *option_desc
);
528 check_multiple_option_occurrences(const char *prog_name
, unsigned int option_given
, int min
, int max
, const char *option_desc
)
532 if (option_given
&& ! (min
< 0 && max
< 0))
534 if (min
>= 0 && max
>= 0)
538 /* specific occurrences */
539 if (option_given
!= min
)
541 fprintf (stderr
, "%s: %s option occurrences must be %d\n",
542 prog_name
, option_desc
, min
);
546 else if (option_given
< min
547 || option_given
> max
)
549 /* range occurrences */
550 fprintf (stderr
, "%s: %s option occurrences must be between %d and %d\n",
551 prog_name
, option_desc
, min
, max
);
558 if (option_given
< min
)
560 fprintf (stderr
, "%s: %s option occurrences must be at least %d\n",
561 prog_name
, option_desc
, min
);
568 if (option_given
> max
)
570 fprintf (stderr
, "%s: %s option occurrences must be at most %d\n",
571 prog_name
, option_desc
, max
);
580 cmdline_parser (int argc
, char * const *argv
, struct gengetopt_args_info
*args_info
)
582 return cmdline_parser2 (argc
, argv
, args_info
, 0, 1, 1);
586 cmdline_parser2 (int argc
, char * const *argv
, struct gengetopt_args_info
*args_info
, int override
, int initialize
, int check_required
)
590 result
= cmdline_parser_internal (argc
, argv
, args_info
, override
, initialize
, check_required
, NULL
);
592 if (result
== EXIT_FAILURE
)
594 cmdline_parser_free (args_info
);
602 cmdline_parser_required (struct gengetopt_args_info
*args_info
, const char *prog_name
)
604 int result
= EXIT_SUCCESS
;
606 if (cmdline_parser_required2(args_info
, prog_name
, NULL
) > 0)
607 result
= EXIT_FAILURE
;
609 if (result
== EXIT_FAILURE
)
611 cmdline_parser_free (args_info
);
619 cmdline_parser_required2 (struct gengetopt_args_info
*args_info
, const char *prog_name
, const char *additional_error
)
623 /* checks for required options */
624 if (check_multiple_option_occurrences(prog_name
, args_info
->mask_given
, args_info
->mask_min
, args_info
->mask_max
, "'--mask'"))
627 if (check_multiple_option_occurrences(prog_name
, args_info
->gid_given
, args_info
->gid_min
, args_info
->gid_max
, "'--gid'"))
630 if (check_multiple_option_occurrences(prog_name
, args_info
->groupname_given
, args_info
->groupname_min
, args_info
->groupname_max
, "'--groupname'"))
634 /* checks for dependences among options */
640 cmdline_parser_internal (int argc
, char * const *argv
, struct gengetopt_args_info
*args_info
, int override
, int initialize
, int check_required
, const char *additional_error
)
642 int c
; /* Character of the parsed option. */
643 char *multi_token
, *multi_next
; /* for multiple options */
647 struct int_list
* mask_list
= NULL
,* mask_new
= NULL
;
648 struct int_list
* gid_list
= NULL
,* gid_new
= NULL
;
649 struct string_list
* groupname_list
= NULL
,* groupname_new
= NULL
;
651 struct gengetopt_args_info local_args_info
;
654 cmdline_parser_init (args_info
);
656 cmdline_parser_init (&local_args_info
);
665 int option_index
= 0;
668 static struct option long_options
[] = {
669 { "help", 0, NULL
, 'h' },
670 { "version", 0, NULL
, 'V' },
671 { "mount", 0, NULL
, 0 },
672 { "uname", 0, NULL
, 0 },
673 { "ipc", 0, NULL
, 0 },
674 { "mask", 1, NULL
, 0 },
675 { "chroot", 1, NULL
, 0 },
676 { "uid", 1, NULL
, 0 },
677 { "username", 1, NULL
, 0 },
678 { "gid", 1, NULL
, 0 },
679 { "groupname", 1, NULL
, 0 },
680 { "daemonize", 0, NULL
, 0 },
681 { "alarm", 1, NULL
, 0 },
682 { "nice", 1, NULL
, 0 },
683 { "sched", 1, NULL
, 0 },
684 { "schedprio", 1, NULL
, 0 },
689 c
= getopt_long (argc
, argv
, "hV", long_options
, &option_index
);
691 if (c
== -1) break; /* Exit from `while (1)' loop. */
695 case 'h': /* Print help and exit. */
696 cmdline_parser_print_help ();
697 cmdline_parser_free (&local_args_info
);
700 case 'V': /* Print version and exit. */
701 cmdline_parser_print_version ();
702 cmdline_parser_free (&local_args_info
);
706 case 0: /* Long option with no short option */
707 /* New mount namespace. */
708 if (strcmp (long_options
[option_index
].name
, "mount") == 0)
710 if (local_args_info
.mount_given
)
712 fprintf (stderr
, "%s: `--mount' option given more than once%s\n", argv
[0], (additional_error
? additional_error
: ""));
715 if (args_info
->mount_given
&& ! override
)
717 local_args_info
.mount_given
= 1;
718 args_info
->mount_given
= 1;
719 args_info
->mount_flag
= !(args_info
->mount_flag
);
722 else if (strcmp (long_options
[option_index
].name
, "uname") == 0)
724 if (local_args_info
.uname_given
)
726 fprintf (stderr
, "%s: `--uname' option given more than once%s\n", argv
[0], (additional_error
? additional_error
: ""));
729 if (args_info
->uname_given
&& ! override
)
731 local_args_info
.uname_given
= 1;
732 args_info
->uname_given
= 1;
733 args_info
->uname_flag
= !(args_info
->uname_flag
);
735 /* New IPC context. */
736 else if (strcmp (long_options
[option_index
].name
, "ipc") == 0)
738 if (local_args_info
.ipc_given
)
740 fprintf (stderr
, "%s: `--ipc' option given more than once%s\n", argv
[0], (additional_error
? additional_error
: ""));
743 if (args_info
->ipc_given
&& ! override
)
745 local_args_info
.ipc_given
= 1;
746 args_info
->ipc_given
= 1;
747 args_info
->ipc_flag
= !(args_info
->ipc_flag
);
749 /* Pass user defined flag. */
750 else if (strcmp (long_options
[option_index
].name
, "mask") == 0)
752 local_args_info
.mask_given
++;
754 multi_token
= get_multiple_arg_token(optarg
);
755 multi_next
= get_multiple_arg_token_next (optarg
);
759 mask_new
= (struct int_list
*) malloc (sizeof (struct int_list
));
760 mask_new
->next
= mask_list
;
761 mask_list
= mask_new
;
762 mask_new
->arg
= strtol (multi_token
, &stop_char
, 0);
763 if (!(stop_char
&& *stop_char
== '\0')) {
764 fprintf(stderr
, "%s: invalid numeric value: %s\n", argv
[0], multi_token
);
767 mask_new
->orig
= multi_token
;
771 multi_token
= get_multiple_arg_token(multi_next
);
772 multi_next
= get_multiple_arg_token_next (multi_next
);
773 local_args_info
.mask_given
++;
780 /* Chroot in the specified directory. */
781 else if (strcmp (long_options
[option_index
].name
, "chroot") == 0)
783 if (local_args_info
.chroot_given
)
785 fprintf (stderr
, "%s: `--chroot' option given more than once%s\n", argv
[0], (additional_error
? additional_error
: ""));
788 if (args_info
->chroot_given
&& ! override
)
790 local_args_info
.chroot_given
= 1;
791 args_info
->chroot_given
= 1;
792 if (args_info
->chroot_arg
)
793 free (args_info
->chroot_arg
); /* free previous string */
794 args_info
->chroot_arg
= gengetopt_strdup (optarg
);
795 if (args_info
->chroot_orig
)
796 free (args_info
->chroot_orig
); /* free previous string */
797 args_info
->chroot_orig
= gengetopt_strdup (optarg
);
799 /* Change to the specified UID. */
800 else if (strcmp (long_options
[option_index
].name
, "uid") == 0)
802 if (local_args_info
.uid_given
)
804 fprintf (stderr
, "%s: `--uid' option given more than once%s\n", argv
[0], (additional_error
? additional_error
: ""));
807 if (args_info
->uid_given
&& ! override
)
809 local_args_info
.uid_given
= 1;
810 args_info
->uid_given
= 1;
811 args_info
->uid_arg
= strtol (optarg
, &stop_char
, 0);
812 if (!(stop_char
&& *stop_char
== '\0')) {
813 fprintf(stderr
, "%s: invalid numeric value: %s\n", argv
[0], optarg
);
816 if (args_info
->uid_orig
)
817 free (args_info
->uid_orig
); /* free previous string */
818 args_info
->uid_orig
= gengetopt_strdup (optarg
);
820 /* Change to the specified username. */
821 else if (strcmp (long_options
[option_index
].name
, "username") == 0)
823 if (local_args_info
.username_given
)
825 fprintf (stderr
, "%s: `--username' option given more than once%s\n", argv
[0], (additional_error
? additional_error
: ""));
828 if (args_info
->username_given
&& ! override
)
830 local_args_info
.username_given
= 1;
831 args_info
->username_given
= 1;
832 if (args_info
->username_arg
)
833 free (args_info
->username_arg
); /* free previous string */
834 args_info
->username_arg
= gengetopt_strdup (optarg
);
835 if (args_info
->username_orig
)
836 free (args_info
->username_orig
); /* free previous string */
837 args_info
->username_orig
= gengetopt_strdup (optarg
);
839 /* Add the specified GID. */
840 else if (strcmp (long_options
[option_index
].name
, "gid") == 0)
842 local_args_info
.gid_given
++;
844 multi_token
= get_multiple_arg_token(optarg
);
845 multi_next
= get_multiple_arg_token_next (optarg
);
849 gid_new
= (struct int_list
*) malloc (sizeof (struct int_list
));
850 gid_new
->next
= gid_list
;
852 gid_new
->arg
= strtol (multi_token
, &stop_char
, 0);
853 if (!(stop_char
&& *stop_char
== '\0')) {
854 fprintf(stderr
, "%s: invalid numeric value: %s\n", argv
[0], multi_token
);
857 gid_new
->orig
= multi_token
;
861 multi_token
= get_multiple_arg_token(multi_next
);
862 multi_next
= get_multiple_arg_token_next (multi_next
);
863 local_args_info
.gid_given
++;
870 /* Add the specified group. */
871 else if (strcmp (long_options
[option_index
].name
, "groupname") == 0)
873 local_args_info
.groupname_given
++;
875 multi_token
= get_multiple_arg_token(optarg
);
876 multi_next
= get_multiple_arg_token_next (optarg
);
880 groupname_new
= (struct string_list
*) malloc (sizeof (struct string_list
));
881 groupname_new
->next
= groupname_list
;
882 groupname_list
= groupname_new
;
883 groupname_new
->arg
= gengetopt_strdup (multi_token
);
884 groupname_new
->orig
= multi_token
;
888 multi_token
= get_multiple_arg_token(multi_next
);
889 multi_next
= get_multiple_arg_token_next (multi_next
);
890 local_args_info
.groupname_given
++;
898 else if (strcmp (long_options
[option_index
].name
, "daemonize") == 0)
900 if (local_args_info
.daemonize_given
)
902 fprintf (stderr
, "%s: `--daemonize' option given more than once%s\n", argv
[0], (additional_error
? additional_error
: ""));
905 if (args_info
->daemonize_given
&& ! override
)
907 local_args_info
.daemonize_given
= 1;
908 args_info
->daemonize_given
= 1;
909 args_info
->daemonize_flag
= !(args_info
->daemonize_flag
);
911 /* Set an alarm after the specified delay. */
912 else if (strcmp (long_options
[option_index
].name
, "alarm") == 0)
914 if (local_args_info
.alarm_given
)
916 fprintf (stderr
, "%s: `--alarm' option given more than once%s\n", argv
[0], (additional_error
? additional_error
: ""));
919 if (args_info
->alarm_given
&& ! override
)
921 local_args_info
.alarm_given
= 1;
922 args_info
->alarm_given
= 1;
923 args_info
->alarm_arg
= strtol (optarg
, &stop_char
, 0);
924 if (!(stop_char
&& *stop_char
== '\0')) {
925 fprintf(stderr
, "%s: invalid numeric value: %s\n", argv
[0], optarg
);
928 if (args_info
->alarm_orig
)
929 free (args_info
->alarm_orig
); /* free previous string */
930 args_info
->alarm_orig
= gengetopt_strdup (optarg
);
932 /* Run as the specified nice level. */
933 else if (strcmp (long_options
[option_index
].name
, "nice") == 0)
935 if (local_args_info
.nice_given
)
937 fprintf (stderr
, "%s: `--nice' option given more than once%s\n", argv
[0], (additional_error
? additional_error
: ""));
940 if (args_info
->nice_given
&& ! override
)
942 local_args_info
.nice_given
= 1;
943 args_info
->nice_given
= 1;
944 args_info
->nice_arg
= strtol (optarg
, &stop_char
, 0);
945 if (!(stop_char
&& *stop_char
== '\0')) {
946 fprintf(stderr
, "%s: invalid numeric value: %s\n", argv
[0], optarg
);
949 if (args_info
->nice_orig
)
950 free (args_info
->nice_orig
); /* free previous string */
951 args_info
->nice_orig
= gengetopt_strdup (optarg
);
953 /* Use the specified (possibly RT) scheduling policy. */
954 else if (strcmp (long_options
[option_index
].name
, "sched") == 0)
956 if (local_args_info
.sched_given
)
958 fprintf (stderr
, "%s: `--sched' option given more than once%s\n", argv
[0], (additional_error
? additional_error
: ""));
961 if (args_info
->sched_given
&& ! override
)
963 local_args_info
.sched_given
= 1;
964 args_info
->sched_given
= 1;
965 if (args_info
->sched_arg
)
966 free (args_info
->sched_arg
); /* free previous string */
967 args_info
->sched_arg
= gengetopt_strdup (optarg
);
968 if (args_info
->sched_orig
)
969 free (args_info
->sched_orig
); /* free previous string */
970 args_info
->sched_orig
= gengetopt_strdup (optarg
);
972 /* Set the priority according to the given scheduler. */
973 else if (strcmp (long_options
[option_index
].name
, "schedprio") == 0)
975 if (local_args_info
.schedprio_given
)
977 fprintf (stderr
, "%s: `--schedprio' option given more than once%s\n", argv
[0], (additional_error
? additional_error
: ""));
980 if (args_info
->schedprio_given
&& ! override
)
982 local_args_info
.schedprio_given
= 1;
983 args_info
->schedprio_given
= 1;
984 args_info
->schedprio_arg
= strtol (optarg
, &stop_char
, 0);
985 if (!(stop_char
&& *stop_char
== '\0')) {
986 fprintf(stderr
, "%s: invalid numeric value: %s\n", argv
[0], optarg
);
989 if (args_info
->schedprio_orig
)
990 free (args_info
->schedprio_orig
); /* free previous string */
991 args_info
->schedprio_orig
= gengetopt_strdup (optarg
);
995 case '?': /* Invalid option. */
996 /* `getopt_long' already printed an error message. */
999 default: /* bug: option not considered. */
1000 fprintf (stderr
, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE
, c
, (additional_error
? additional_error
: ""));
1006 if (local_args_info
.mask_given
&& mask_list
)
1008 struct int_list
*tmp
;
1009 args_info
->mask_arg
= (int *) realloc (args_info
->mask_arg
, (args_info
->mask_given
+ local_args_info
.mask_given
) * sizeof (int));
1010 args_info
->mask_orig
= (char **) realloc (args_info
->mask_orig
, (args_info
->mask_given
+ local_args_info
.mask_given
) * sizeof (char *));
1011 for (i
= (local_args_info
.mask_given
- 1); i
>= 0; --i
)
1014 args_info
->mask_arg
[i
+ args_info
->mask_given
] = mask_list
->arg
;
1015 args_info
->mask_orig
[i
+ args_info
->mask_given
] = mask_list
->orig
;
1016 mask_list
= mask_list
->next
;
1021 if (local_args_info
.gid_given
&& gid_list
)
1023 struct int_list
*tmp
;
1024 args_info
->gid_arg
= (int *) realloc (args_info
->gid_arg
, (args_info
->gid_given
+ local_args_info
.gid_given
) * sizeof (int));
1025 args_info
->gid_orig
= (char **) realloc (args_info
->gid_orig
, (args_info
->gid_given
+ local_args_info
.gid_given
) * sizeof (char *));
1026 for (i
= (local_args_info
.gid_given
- 1); i
>= 0; --i
)
1029 args_info
->gid_arg
[i
+ args_info
->gid_given
] = gid_list
->arg
;
1030 args_info
->gid_orig
[i
+ args_info
->gid_given
] = gid_list
->orig
;
1031 gid_list
= gid_list
->next
;
1036 if (local_args_info
.groupname_given
&& groupname_list
)
1038 struct string_list
*tmp
;
1039 args_info
->groupname_arg
= (char * *) realloc (args_info
->groupname_arg
, (args_info
->groupname_given
+ local_args_info
.groupname_given
) * sizeof (char *));
1040 args_info
->groupname_orig
= (char **) realloc (args_info
->groupname_orig
, (args_info
->groupname_given
+ local_args_info
.groupname_given
) * sizeof (char *));
1041 for (i
= (local_args_info
.groupname_given
- 1); i
>= 0; --i
)
1043 tmp
= groupname_list
;
1044 args_info
->groupname_arg
[i
+ args_info
->groupname_given
] = groupname_list
->arg
;
1045 args_info
->groupname_orig
[i
+ args_info
->groupname_given
] = groupname_list
->orig
;
1046 groupname_list
= groupname_list
->next
;
1052 args_info
->mask_given
+= local_args_info
.mask_given
;
1053 local_args_info
.mask_given
= 0;
1054 args_info
->gid_given
+= local_args_info
.gid_given
;
1055 local_args_info
.gid_given
= 0;
1056 args_info
->groupname_given
+= local_args_info
.groupname_given
;
1057 local_args_info
.groupname_given
= 0;
1061 error
+= cmdline_parser_required2 (args_info
, argv
[0], additional_error
);
1064 cmdline_parser_release (&local_args_info
);
1067 return (EXIT_FAILURE
);
1072 int found_prog_name
= 0;
1073 /* whether program name, i.e., argv[0], is in the remaining args
1074 (this may happen with some implementations of getopt,
1075 but surely not with the one included by gengetopt) */
1079 if (argv
[i
++] == argv
[0]) {
1080 found_prog_name
= 1;
1085 args_info
->inputs_num
= argc
- optind
- found_prog_name
;
1087 (char **)(malloc ((args_info
->inputs_num
)*sizeof(char *))) ;
1088 while (optind
< argc
)
1089 if (argv
[optind
++] != argv
[0])
1090 args_info
->inputs
[ i
++ ] = gengetopt_strdup (argv
[optind
-1]) ;
1098 struct int_list
*tmp
;
1102 free (mask_list
->orig
);
1103 mask_list
= mask_list
->next
;
1109 struct int_list
*tmp
;
1113 free (gid_list
->orig
);
1114 gid_list
= gid_list
->next
;
1120 struct string_list
*tmp
;
1121 while (groupname_list
)
1123 tmp
= groupname_list
;
1124 free (groupname_list
->arg
);
1125 free (groupname_list
->orig
);
1126 groupname_list
= groupname_list
->next
;
1131 cmdline_parser_release (&local_args_info
);
1132 return (EXIT_FAILURE
);