this is a GNU extension, activated by including '-' as the first
character of the options string, whereby non-option arguments are
processed as if they were arguments to an option character '\1' rather
than ending option processing.
optind = 1;
}
- if (optind >= argc || !argv[optind] || argv[optind][0] != '-' || !argv[optind][1])
+ if (optind >= argc || !argv[optind])
return -1;
+
+ if (argv[optind][0] != '-') {
+ if (optstring[0] == '-') {
+ optarg = argv[optind++];
+ return 1;
+ }
+ return -1;
+ }
+
+ if (!argv[optind][1])
+ return -1;
+
if (argv[optind][1] == '-' && !argv[optind][2])
return optind++, -1;
optpos = 0;
}
+ if (optstring[0] == '-')
+ optstring++;
+
for (i=0; (l = mbtowc(&d, optstring+i, MB_LEN_MAX)) && d!=c; i+=l>0?l:1);
if (d != c) {
__optpos = 0;
optind = 1;
}
- if (optind >= argc || !argv[optind] || argv[optind][0] != '-') return -1;
- if ((longonly && argv[optind][1]) ||
- (argv[optind][1] == '-' && argv[optind][2]))
+ if (optind >= argc || !argv[optind]) return -1;
+ if (argv[optind][0] == '-' &&
+ ((longonly && argv[optind][1]) ||
+ (argv[optind][1] == '-' && argv[optind][2])))
{
int i;
for (i=0; longopts[i].name; i++) {