Path: blob/main/japanese/FreeWnn-server/files/patch-Wnn-etc-getopt1.c
16461 views
Index: Wnn/etc/getopt1.c1===================================================================2RCS file: /home/cvs/private/hrs/freewnn/Wnn/etc/getopt1.c,v3retrieving revision 1.1.1.14retrieving revision 1.25diff -u -p -r1.1.1.1 -r1.26--- Wnn/etc/getopt1.c 20 Dec 2008 07:13:30 -0000 1.1.1.17+++ Wnn/etc/getopt1.c 20 Dec 2008 15:22:40 -0000 1.28@@ -66,14 +66,13 @@9#endif1011int12-getopt_long (argc, argv, options, long_options, opt_index)13- int argc;14- char *const *argv;15- const char *options;16- const struct option *long_options;17- int *opt_index;18+getopt_long(int argc,19+ char * const *argv,20+ const char *options,21+ const struct option *long_options,22+ int *opt_index)23{24- return _getopt_internal (argc, argv, options, long_options, opt_index, 0);25+ return _getopt_internal(argc, argv, options, long_options, opt_index, 0);26}2728/* Like getopt_long, but '-' as well as '--' can indicate a long option.29@@ -82,14 +81,13 @@ getopt_long (argc, argv, options, long_o30instead. */3132int33-getopt_long_only (argc, argv, options, long_options, opt_index)34- int argc;35- char *const *argv;36- const char *options;37- const struct option *long_options;38- int *opt_index;39+getopt_long_only(int argc,40+ char * const *argv,41+ const char *options,42+ const struct option *long_options,43+ int *opt_index)44{45- return _getopt_internal (argc, argv, options, long_options, opt_index, 1);46+ return _getopt_internal(argc, argv, options, long_options, opt_index, 1);47}484950@@ -100,91 +98,87 @@ getopt_long_only (argc, argv, options, l51#include <stdio.h>5253int54-main (argc, argv)55- int argc;56- char **argv;57+main(int argc, char **argv)58{59- int c;60- int digit_optind = 0;61+ int c;62+ int digit_optind = 0;6364- while (1)65- {66- int this_option_optind = optind ? optind : 1;67- int option_index = 0;68- static struct option long_options[] =69- {70- {"add", 1, 0, 0},71- {"append", 0, 0, 0},72- {"delete", 1, 0, 0},73- {"verbose", 0, 0, 0},74- {"create", 0, 0, 0},75- {"file", 1, 0, 0},76- {0, 0, 0, 0}77- };78-79- c = getopt_long (argc, argv, "abc:d:0123456789",80- long_options, &option_index);81- if (c == -1)82- break;83-84- switch (c)85- {86- case 0:87- printf ("option %s", long_options[option_index].name);88- if (optarg)89- printf (" with arg %s", optarg);90- printf ("\n");91- break;92-93- case '0':94- case '1':95- case '2':96- case '3':97- case '4':98- case '5':99- case '6':100- case '7':101- case '8':102- case '9':103- if (digit_optind != 0 && digit_optind != this_option_optind)104- printf ("digits occur in two different argv-elements.\n");105- digit_optind = this_option_optind;106- printf ("option %c\n", c);107- break;108-109- case 'a':110- printf ("option a\n");111- break;112-113- case 'b':114- printf ("option b\n");115- break;116-117- case 'c':118- printf ("option c with value `%s'\n", optarg);119- break;120-121- case 'd':122- printf ("option d with value `%s'\n", optarg);123- break;124+ while (1) {125+ int this_option_optind = optind ? optind : 1;126+ int option_index = 0;127+ static struct option long_options[] = {128+ {"add", 1, 0, 0},129+ {"append", 0, 0, 0},130+ {"delete", 1, 0, 0},131+ {"verbose", 0, 0, 0},132+ {"create", 0, 0, 0},133+ {"file", 1, 0, 0},134+ {0, 0, 0, 0}135+ };136+137+ c = getopt_long(argc, argv, "abc:d:0123456789",138+ long_options, &option_index);139+140+ if (c == -1)141+ break;142+143+ switch (c) {144+ case 0:145+ printf ("option %s", long_options[option_index].name);146+ if (optarg)147+ printf (" with arg %s", optarg);148+149+ printf ("\n");150+ break;151+ case '0':152+ case '1':153+ case '2':154+ case '3':155+ case '4':156+ case '5':157+ case '6':158+ case '7':159+ case '8':160+ case '9':161+ if (digit_optind != 0 && digit_optind != this_option_optind)162+ printf ("digits occur in two different argv-elements.\n");163+ digit_optind = this_option_optind;164+ printf ("option %c\n", c);165+ break;166+167+ case 'a':168+ printf ("option a\n");169+ break;170+171+ case 'b':172+ printf ("option b\n");173+ break;174+175+ case 'c':176+ printf ("option c with value `%s'\n", optarg);177+ break;178+179+ case 'd':180+ printf ("option d with value `%s'\n", optarg);181+ break;182+183+ case '?':184+ break;185+186+ default:187+ printf ("?? getopt returned character code 0%o ??\n", c);188+ }189+ }190191- case '?':192- break;193+ if (optind < argc) {194+ printf ("non-option ARGV-elements: ");195196- default:197- printf ("?? getopt returned character code 0%o ??\n", c);198+ while (optind < argc)199+ printf ("%s ", argv[optind++]);200+ printf ("\n");201}202- }203-204- if (optind < argc)205- {206- printf ("non-option ARGV-elements: ");207- while (optind < argc)208- printf ("%s ", argv[optind++]);209- printf ("\n");210- }211212- exit (0);213+ exit(0);214}215216#endif /* TEST */217218219