POSIX.1 National Language Support API for MinGW
リビジョン | a784c945a39524e7d248c53f38c0dc13dcd8ce0d (tree) |
---|---|
日時 | 2008-01-13 03:01:42 |
作者 | Keith Marshall <keithmarshall@user...> |
コミッター | Keith Marshall |
* gencat.c: Force an abort, with appropriate diagnostic, on parsing an unrecognised command line option.
@@ -1,3 +1,8 @@ | ||
1 | +2008-01-12 Keith Marshall <keithmarshall@users.sourceforge.net> | |
2 | + | |
3 | + * gencat.c: Force an abort, with appropriate diagnostic, on parsing an | |
4 | + unrecognised command line option. | |
5 | + | |
1 | 6 | 2008-01-11 Keith Marshall <keithmarshall@users.sourceforge.net> |
2 | 7 | |
3 | 8 | Make replacement `getopt' function module more GNU compatible. |
@@ -8,7 +8,7 @@ | ||
8 | 8 | * This file implements the `main' function for the `gencat' program. |
9 | 9 | * |
10 | 10 | * Written by Keith Marshall <keithmarshall@users.sourceforge.net> |
11 | - * Last modification: 09-Jan-2008 | |
11 | + * Last modification: 12-Jan-2008 | |
12 | 12 | * |
13 | 13 | * |
14 | 14 | * This is free software. It is provided AS IS, in the hope that it may |
@@ -175,12 +175,20 @@ int main( int argc, char **argv ) | ||
175 | 175 | */ |
176 | 176 | banner_printf( print_top_banner + print_nl_duplicate, COPYRIGHT_NOTICE ); |
177 | 177 | exit( EXIT_SUCCESS ); |
178 | + | |
179 | + case '?': | |
180 | + /* | |
181 | + * This means the user specified an unrecognised option... | |
182 | + * continue parsing, to catch other possible errors, but flag it, | |
183 | + * so we can bail out before processing any message catalogue. | |
184 | + */ | |
185 | + gencat_errno = opt; | |
178 | 186 | } |
179 | 187 | |
180 | 188 | progname = *argv; |
181 | 189 | cat_index.id = tag; |
182 | 190 | |
183 | - if( (argc -= optind) > 1 ) | |
191 | + if( ((argc -= optind) > 1) && (gencat_errno == 0) ) | |
184 | 192 | { |
185 | 193 | /* Establish the message catalogue name, recognising `/dev/stdout' |
186 | 194 | * as an alias for `-', representing the standard output stream. |
@@ -381,10 +389,18 @@ int main( int argc, char **argv ) | ||
381 | 389 | } |
382 | 390 | |
383 | 391 | else |
384 | - { /* User specified insufficient command line arguments. | |
385 | - * Diagnose, and bail out. | |
392 | + { /* An error was detected, while parsing the command line... | |
393 | + */ | |
394 | + if( argc < 2 ) | |
395 | + /* | |
396 | + * User specified insufficient command line arguments. | |
397 | + */ | |
398 | + fprintf( errmsg( MSG_MISSING_ARGS ), progname ); | |
399 | + | |
400 | + /* In any case, (it may have been an unrecognised option, | |
401 | + * which was previously diagnosed), display the usage summary, | |
402 | + * and bail out. | |
386 | 403 | */ |
387 | - fprintf( errmsg( MSG_MISSING_ARGS ), progname ); | |
388 | 404 | fprintf( errmsg( MSG_GENCAT_USAGE ), progname ); |
389 | 405 | return EXIT_FAILURE; |
390 | 406 | } |
@@ -393,4 +409,4 @@ int main( int argc, char **argv ) | ||
393 | 409 | return EXIT_SUCCESS; |
394 | 410 | } |
395 | 411 | |
396 | -/* $RCSfile$Revision: 1.5 $: end of file */ | |
412 | +/* $RCSfile$Revision: 1.6 $: end of file */ |