Changeset 3213 for trunk/src/kmk/kmkbuiltin/getopt1_r.c
- Timestamp:
- Mar 30, 2018, 11:03:28 PM (7 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/getopt1_r.c
r3212 r3213 1 /* getopt_long and getopt_long_only entry points for GNU getopt. 1 /* Reentrant version of getopt_long and getopt_long_only. 2 3 Based on ../getopt*.*: 4 5 getopt_long and getopt_long_only entry points for GNU getopt. 2 6 Copyright (C) 1987-1994, 1996-2016 Free Software Foundation, Inc. 3 7 … … 15 19 16 20 You should have received a copy of the GNU General Public License along with 17 this program. If not, see <http://www.gnu.org/licenses/>. */ 21 this program. If not, see <http://www.gnu.org/licenses/>. 22 23 Modifications: 24 Copyright (c) 2018 knut st. osmundsen <bird-kBuild-spamx@anduin.net> 25 */ 18 26 19 27 28 #define FAKES_NO_GETOPT_H /* bird */ 20 29 #ifdef HAVE_CONFIG_H 21 30 #include <config.h> 22 31 #endif 23 32 24 #include "getopt .h"33 #include "getopt_r.h" 25 34 26 35 #if !defined __STDC__ || !__STDC__ … … 34 43 #include <stdio.h> 35 44 45 #if 0 36 46 /* Comment out all this code if we are using the GNU C Library, and are not 37 47 actually compiling the library itself. This code is part of the GNU C … … 49 59 #endif 50 60 #endif 61 #endif 51 62 52 #if ndef ELIDE_CODE63 #if 1 //ndef ELIDE_CODE 53 64 54 65 … … 64 75 65 76 int 66 getopt_long (int argc, char *const *argv, const char *options, 67 const struct option *long_options, int *opt_index) 77 getopt_long_r (struct getopt_state_r *gos, int *opt_index) 68 78 { 69 return _getopt_internal (argc, argv, options,long_options, opt_index, 0);79 return _getopt_internal_r (gos, gos->long_options, opt_index, 0); 70 80 } 71 81 … … 76 86 77 87 int 78 getopt_long_only (int argc, char *const *argv, const char *options, 79 const struct option *long_options, int *opt_index) 88 getopt_long_only_r (struct getopt_state_r *gos, int *opt_index) 80 89 { 81 return _getopt_internal (argc, argv, options, long_options, opt_index, 1);90 return _getopt_internal_r (gos, gos->long_options, opt_index, 0); 82 91 } 83 92 84 93 85 #endif 94 #endif /* #if 1 */ /* Not ELIDE_CODE. */ 86 95 87 96 … … 100 109 int this_option_optind = optind ? optind : 1; 101 110 int option_index = 0; 111 struct getopt_state_r gos; 102 112 static struct option long_options[] = 103 113 { … … 111 121 }; 112 122 113 c = getopt_long (argc, argv, "abc:d:0123456789",114 long_options, &option_index);123 getopt_initialize_r (&gos, argc, argv, "abc:d:0123456789", long_options, NULL, NULL); 124 c = getopt_long_r (&geo, &option_index); 115 125 if (c == -1) 116 126 break; … … 120 130 case 0: 121 131 printf ("option %s", long_options[option_index].name); 122 if ( optarg)123 printf (" with arg %s", optarg);132 if (geo.optarg) 133 printf (" with arg %s", geo.optarg); 124 134 printf ("\n"); 125 135 break; … … 150 160 151 161 case 'c': 152 printf ("option c with value '%s'\n", optarg);162 printf ("option c with value '%s'\n", geo.optarg); 153 163 break; 154 164 155 165 case 'd': 156 printf ("option d with value '%s'\n", optarg);166 printf ("option d with value '%s'\n", geo.optarg); 157 167 break; 158 168 … … 165 175 } 166 176 167 if ( optind < argc)177 if (geo.optind < argc) 168 178 { 169 179 printf ("non-option ARGV-elements: "); 170 180 while (optind < argc) 171 printf ("%s ", argv[ optind++]);181 printf ("%s ", argv[geo.optind++]); 172 182 printf ("\n"); 173 183 }
Note:
See TracChangeset
for help on using the changeset viewer.