00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024
00025 #ifdef _LIBC
00026 # include <getopt.h>
00027 #else
00028 # include "getopt.h"
00029 #endif
00030
00031 #if !defined __STDC__ || !__STDC__
00032
00033
00034 #ifndef const
00035 #define const
00036 #endif
00037 #endif
00038
00039 #include <stdio.h>
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #define GETOPT_INTERFACE_VERSION 2
00050 #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
00051 #include <gnu-versions.h>
00052 #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
00053 #define ELIDE_CODE
00054 #endif
00055 #endif
00056
00057 #ifndef ELIDE_CODE
00058
00059
00060
00061
00062 #ifdef __GNU_LIBRARY__
00063 #include <stdlib.h>
00064 #endif
00065
00066 #ifndef NULL
00067 #define NULL 0
00068 #endif
00069
00070 int
00071 getopt_long (argc, argv, options, long_options, opt_index)
00072 int argc;
00073 char *const *argv;
00074 const char *options;
00075 const struct option *long_options;
00076 int *opt_index;
00077 {
00078 return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
00079 }
00080
00081
00082
00083
00084
00085
00086 int
00087 getopt_long_only (argc, argv, options, long_options, opt_index)
00088 int argc;
00089 char *const *argv;
00090 const char *options;
00091 const struct option *long_options;
00092 int *opt_index;
00093 {
00094 return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
00095 }
00096
00097 # ifdef _LIBC
00098 libc_hidden_def (getopt_long)
00099 libc_hidden_def (getopt_long_only)
00100 # endif
00101
00102 #endif
00103
00104 #ifdef TEST
00105
00106 #include <stdio.h>
00107
00108 int
00109 main (argc, argv)
00110 int argc;
00111 char **argv;
00112 {
00113 int c;
00114 int digit_optind = 0;
00115
00116 while (1)
00117 {
00118 int this_option_optind = optind ? optind : 1;
00119 int option_index = 0;
00120 static struct option long_options[] =
00121 {
00122 {"add", 1, 0, 0},
00123 {"append", 0, 0, 0},
00124 {"delete", 1, 0, 0},
00125 {"verbose", 0, 0, 0},
00126 {"create", 0, 0, 0},
00127 {"file", 1, 0, 0},
00128 {0, 0, 0, 0}
00129 };
00130
00131 c = getopt_long (argc, argv, "abc:d:0123456789",
00132 long_options, &option_index);
00133 if (c == -1)
00134 break;
00135
00136 switch (c)
00137 {
00138 case 0:
00139 printf ("option %s", long_options[option_index].name);
00140 if (optarg)
00141 printf (" with arg %s", optarg);
00142 printf ("\n");
00143 break;
00144
00145 case '0':
00146 case '1':
00147 case '2':
00148 case '3':
00149 case '4':
00150 case '5':
00151 case '6':
00152 case '7':
00153 case '8':
00154 case '9':
00155 if (digit_optind != 0 && digit_optind != this_option_optind)
00156 printf ("digits occur in two different argv-elements.\n");
00157 digit_optind = this_option_optind;
00158 printf ("option %c\n", c);
00159 break;
00160
00161 case 'a':
00162 printf ("option a\n");
00163 break;
00164
00165 case 'b':
00166 printf ("option b\n");
00167 break;
00168
00169 case 'c':
00170 printf ("option c with value `%s'\n", optarg);
00171 break;
00172
00173 case 'd':
00174 printf ("option d with value `%s'\n", optarg);
00175 break;
00176
00177 case '?':
00178 break;
00179
00180 default:
00181 printf ("?? getopt returned character code 0%o ??\n", c);
00182 }
00183 }
00184
00185 if (optind < argc)
00186 {
00187 printf ("non-option ARGV-elements: ");
00188 while (optind < argc)
00189 printf ("%s ", argv[optind++]);
00190 printf ("\n");
00191 }
00192
00193 exit (0);
00194 }
00195
00196 #endif