Remove unneeded files
[wmaker-crm.git] / plugins / libwmfun / getopt1.c
blob8ac367003acb37a2fc9b0757a0f994dd67e26d7e
1 /* getopt_long and getopt_long_only entry points for GNU getopt.
2 Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
3 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any
8 later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. */
15 #include "getopt.h"
17 #ifndef __STDC__
18 /* This is a separate conditional since some stdc systems
19 reject `defined (const)'. */
20 #ifndef const
21 #define const
22 #endif
23 #endif
25 #include <stdio.h>
27 /* Comment out all this code if we are using the GNU C Library, and are not
28 actually compiling the library itself. This code is part of the GNU C
29 Library, but also included in many other GNU distributions. Compiling
30 and linking in this code is a waste when using the GNU C library
31 (especially if it is a shared library). Rather than having every GNU
32 program understand `configure --with-gnu-libc' and omit the object files,
33 it is simpler to just do this in the source for each such file. */
35 #if defined (_LIBC) || !defined (__GNU_LIBRARY__)
37 /* This needs to come after some library #include
38 to get __GNU_LIBRARY__ defined. */
39 #ifdef __GNU_LIBRARY__
40 #include <stdlib.h>
41 #else
42 char *getenv();
43 #endif
45 #ifndef NULL
46 #define NULL 0
47 #endif
49 int getopt_long(argc, argv, options, long_options, opt_index)
50 int argc;
51 char *const *argv;
52 const char *options;
53 const struct option *long_options;
54 int *opt_index;
56 return _getopt_internal(argc, argv, options, long_options, opt_index, 0);
59 /* Like getopt_long, but '-' as well as '--' can indicate a long option.
60 If an option that starts with '-' (not '--') doesn't match a long option,
61 but does match a short option, it is parsed as a short option
62 instead. */
64 int getopt_long_only(argc, argv, options, long_options, opt_index)
65 int argc;
66 char *const *argv;
67 const char *options;
68 const struct option *long_options;
69 int *opt_index;
71 return _getopt_internal(argc, argv, options, long_options, opt_index, 1);
74 #endif /* _LIBC or not __GNU_LIBRARY__. */
76 #ifdef TEST
78 #include <stdio.h>
80 int main(argc, argv)
81 int argc;
82 char **argv;
84 int c;
85 int digit_optind = 0;
87 while (1) {
88 int this_option_optind = optind ? optind : 1;
89 int option_index = 0;
90 static struct option long_options[] = {
91 {"add", 1, 0, 0},
92 {"append", 0, 0, 0},
93 {"delete", 1, 0, 0},
94 {"verbose", 0, 0, 0},
95 {"create", 0, 0, 0},
96 {"file", 1, 0, 0},
97 {0, 0, 0, 0}
100 c = getopt_long(argc, argv, "abc:d:0123456789", long_options, &option_index);
101 if (c == EOF)
102 break;
104 switch (c) {
105 case 0:
106 printf("option %s", long_options[option_index].name);
107 if (optarg)
108 printf(" with arg %s", optarg);
109 printf("\n");
110 break;
112 case '0':
113 case '1':
114 case '2':
115 case '3':
116 case '4':
117 case '5':
118 case '6':
119 case '7':
120 case '8':
121 case '9':
122 if (digit_optind != 0 && digit_optind != this_option_optind)
123 printf("digits occur in two different argv-elements.\n");
124 digit_optind = this_option_optind;
125 printf("option %c\n", c);
126 break;
128 case 'a':
129 printf("option a\n");
130 break;
132 case 'b':
133 printf("option b\n");
134 break;
136 case 'c':
137 printf("option c with value `%s'\n", optarg);
138 break;
140 case 'd':
141 printf("option d with value `%s'\n", optarg);
142 break;
144 case '?':
145 break;
147 default:
148 printf("?? getopt returned character code 0%o ??\n", c);
152 if (optind < argc) {
153 printf("non-option ARGV-elements: ");
154 while (optind < argc)
155 printf("%s ", argv[optind++]);
156 printf("\n");
159 exit(0);
162 #endif /* TEST */