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