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