OSDN Git Service

wwww
[proj16/16.git] / src / lib / doslib / ext / speex / getopt1.c
1 /* getopt_long and getopt_long_only entry points for GNU getopt.\r
2    Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98\r
3      Free Software Foundation, Inc.\r
4    This file is part of the GNU C Library.\r
5 \r
6    The GNU C Library is free software; you can redistribute it and/or\r
7    modify it under the terms of the GNU Library General Public License as\r
8    published by the Free Software Foundation; either version 2 of the\r
9    License, or (at your option) any later version.\r
10 \r
11    The GNU C Library is distributed in the hope that it will be useful,\r
12    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
14    Library General Public License for more details.\r
15 \r
16    You should have received a copy of the GNU Library General Public\r
17    License along with the GNU C Library; see the file COPYING.LIB.  If not,\r
18    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
19    Boston, MA 02111-1307, USA.  */\r
20 \r
21 #ifdef HAVE_CONFIG_H\r
22 #include "config.h"\r
23 #endif\r
24 \r
25 #include "getopt_win.h"\r
26 \r
27 #if !defined __STDC__ || !__STDC__\r
28 /* This is a separate conditional since some stdc systems\r
29    reject `defined (const)'.  */\r
30 #ifndef const\r
31 #define const\r
32 #endif\r
33 #endif\r
34 \r
35 #include <stdio.h>\r
36 \r
37 /* Comment out all this code if we are using the GNU C Library, and are not\r
38    actually compiling the library itself.  This code is part of the GNU C\r
39    Library, but also included in many other GNU distributions.  Compiling\r
40    and linking in this code is a waste when using the GNU C library\r
41    (especially if it is a shared library).  Rather than having every GNU\r
42    program understand `configure --with-gnu-libc' and omit the object files,\r
43    it is simpler to just do this in the source for each such file.  */\r
44 \r
45 #define GETOPT_INTERFACE_VERSION 2\r
46 #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2\r
47 #include <gnu-versions.h>\r
48 #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION\r
49 #define ELIDE_CODE\r
50 #endif\r
51 #endif\r
52 \r
53 #ifndef ELIDE_CODE\r
54 \r
55 \r
56 /* This needs to come after some library #include\r
57    to get __GNU_LIBRARY__ defined.  */\r
58 #ifdef __GNU_LIBRARY__\r
59 #include <stdlib.h>\r
60 #endif\r
61 \r
62 #ifndef NULL\r
63 #define NULL 0\r
64 #endif\r
65 \r
66 int\r
67 getopt_long (argc, argv, options, long_options, opt_index)\r
68      int argc;\r
69      char *const *argv;\r
70      const char *options;\r
71      const struct option *long_options;\r
72      int *opt_index;\r
73 {\r
74   return _getopt_internal (argc, argv, options, long_options, opt_index, 0);\r
75 }\r
76 \r
77 /* Like getopt_long, but '-' as well as '--' can indicate a long option.\r
78    If an option that starts with '-' (not '--') doesn't match a long option,\r
79    but does match a short option, it is parsed as a short option\r
80    instead.  */\r
81 \r
82 int\r
83 getopt_long_only (argc, argv, options, long_options, opt_index)\r
84      int argc;\r
85      char *const *argv;\r
86      const char *options;\r
87      const struct option *long_options;\r
88      int *opt_index;\r
89 {\r
90   return _getopt_internal (argc, argv, options, long_options, opt_index, 1);\r
91 }\r
92 \r
93 \r
94 #endif  /* Not ELIDE_CODE.  */\r
95 \f\r
96 #ifdef TEST\r
97 \r
98 #include <stdio.h>\r
99 \r
100 int\r
101 main (argc, argv)\r
102      int argc;\r
103      char **argv;\r
104 {\r
105   int c;\r
106   int digit_optind = 0;\r
107 \r
108   while (1)\r
109     {\r
110       int this_option_optind = optind ? optind : 1;\r
111       int option_index = 0;\r
112       static struct option long_options[] =\r
113       {\r
114         {"add", 1, 0, 0},\r
115         {"append", 0, 0, 0},\r
116         {"delete", 1, 0, 0},\r
117         {"verbose", 0, 0, 0},\r
118         {"create", 0, 0, 0},\r
119         {"file", 1, 0, 0},\r
120         {0, 0, 0, 0}\r
121       };\r
122 \r
123       c = getopt_long (argc, argv, "abc:d:0123456789",\r
124                        long_options, &option_index);\r
125       if (c == -1)\r
126         break;\r
127 \r
128       switch (c)\r
129         {\r
130         case 0:\r
131           printf ("option %s", long_options[option_index].name);\r
132           if (optarg)\r
133             printf (" with arg %s", optarg);\r
134           printf ("\n");\r
135           break;\r
136 \r
137         case '0':\r
138         case '1':\r
139         case '2':\r
140         case '3':\r
141         case '4':\r
142         case '5':\r
143         case '6':\r
144         case '7':\r
145         case '8':\r
146         case '9':\r
147           if (digit_optind != 0 && digit_optind != this_option_optind)\r
148             printf ("digits occur in two different argv-elements.\n");\r
149           digit_optind = this_option_optind;\r
150           printf ("option %c\n", c);\r
151           break;\r
152 \r
153         case 'a':\r
154           printf ("option a\n");\r
155           break;\r
156 \r
157         case 'b':\r
158           printf ("option b\n");\r
159           break;\r
160 \r
161         case 'c':\r
162           printf ("option c with value `%s'\n", optarg);\r
163           break;\r
164 \r
165         case 'd':\r
166           printf ("option d with value `%s'\n", optarg);\r
167           break;\r
168 \r
169         case '?':\r
170           break;\r
171 \r
172         default:\r
173           printf ("?? getopt returned character code 0%o ??\n", c);\r
174         }\r
175     }\r
176 \r
177   if (optind < argc)\r
178     {\r
179       printf ("non-option ARGV-elements: ");\r
180       while (optind < argc)\r
181         printf ("%s ", argv[optind++]);\r
182       printf ("\n");\r
183     }\r
184 \r
185   exit (0);\r
186 }\r
187 \r
188 #endif /* TEST */\r