POSIX.1 National Language Support API for MinGW
リビジョン | 4169903111ce12e8fc3edd929d1b6d50bb7848d4 (tree) |
---|---|
日時 | 2008-01-12 08:38:46 |
作者 | Keith Marshall <keithmarshall@user...> |
コミッター | Keith Marshall |
Make replacement getopt' function module more GNU compatible.
@@ -1,3 +1,11 @@ | ||
1 | +2008-01-11 Keith Marshall <keithmarshall@users.sourceforge.net> | |
2 | + | |
3 | + Make replacement `getopt' function module more GNU compatible. | |
4 | + | |
5 | + * repl/getopt.c (optind): Initialise to one; POSIX requires this. | |
6 | + (getopt_parse): Handle changed initial value for `optind'; allow | |
7 | + caller to reset the parser, by setting `optind = 0'. | |
8 | + | |
1 | 9 | 2008-01-10 Keith Marshall <keithmarshall@users.sourceforge.net> |
2 | 10 | |
3 | 11 | * gencat.c: Delay writing the catalogue header until *after* the |
@@ -9,7 +9,7 @@ | ||
9 | 9 | * This file is part of the MinGW32 package set. |
10 | 10 | * |
11 | 11 | * Contributed by Keith Marshall <keithmarshall@users.sourceforge.net> |
12 | - * Last modification: 27-Dec-2007 | |
12 | + * Last modification: 11-Jan-2008 | |
13 | 13 | * |
14 | 14 | * THIS SOFTWARE IS NOT COPYRIGHTED |
15 | 15 | * |
@@ -49,7 +49,7 @@ extern char __declspec(dllimport) *__progname; | ||
49 | 49 | |
50 | 50 | /* Initialise the public variables. */ |
51 | 51 | |
52 | -int optind = 0; /* index for first non-option arg */ | |
52 | +int optind = 1; /* index for first non-option arg */ | |
53 | 53 | int opterr = 1; /* enable built-in error messages */ |
54 | 54 | |
55 | 55 | char *optarg = NULL; /* pointer to current option argument */ |
@@ -306,6 +306,19 @@ int getopt_parse( int mode, getopt_std_args, ... ) | ||
306 | 306 | static const CHAR *nextchar = NULL; |
307 | 307 | static int optmark = 0; |
308 | 308 | |
309 | + if( (argind == 0) || (optind == 0) ) | |
310 | + { | |
311 | + /* POSIX wants `optind' to have an initial value of one, but we want | |
312 | + * it to be initialised to zero, when we are called for the first time, | |
313 | + * (as indicated by `argind' having a value of zero). We also want to | |
314 | + * allow the caller to reset the `getopt' parser, causing it to scan | |
315 | + * the arguments again, (or to scan a new set of arguments); this | |
316 | + * may be achieved by the caller resetting `optind' to zero. | |
317 | + */ | |
318 | + optmark = optind = argind = 0; | |
319 | + nextchar = NULL; | |
320 | + } | |
321 | + | |
309 | 322 | if( nextchar && *nextchar ) |
310 | 323 | { |
311 | 324 | /* we are parsing a standard, or short format, option argument ... |
@@ -633,4 +646,4 @@ __weak_alias( getopt_long, _getopt_long ) | ||
633 | 646 | __weak_alias( getopt_long_only, _getopt_long_only ) |
634 | 647 | #endif |
635 | 648 | |
636 | -/* $RCSfile$Revision$: end of file */ | |
649 | +/* $RCSfile$Revision: 1.1 $: end of file */ |