add ext4,vfat and tar.bz2
[u-tools.git] / u-tools / apps / tar / gnu / getopt1.c
blobc7fe745dbb48e89b02b566a69bd890027f341fce
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* getopt_long and getopt_long_only entry points for GNU getopt.
4 Copyright (C) 1987-1994, 1996-1998, 2004, 2006, 2009-2011 Free Software
5 Foundation, Inc.
6 This file is part of the GNU C Library.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #ifdef _LIBC
22 # include <getopt.h>
23 #else
24 # include <config.h>
25 # include "getopt.h"
26 #endif
27 #include "getopt_int.h"
29 #include <stdio.h>
31 /* This needs to come after some library #include
32 to get __GNU_LIBRARY__ defined. */
33 #ifdef __GNU_LIBRARY__
34 #include <stdlib.h>
35 #endif
37 #ifndef NULL
38 #define NULL 0
39 #endif
41 int
42 getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
43 const struct option *long_options, int *opt_index)
45 return _getopt_internal (argc, (char **) argv, options, long_options,
46 opt_index, 0, 0);
49 int
50 _getopt_long_r (int argc, char **argv, const char *options,
51 const struct option *long_options, int *opt_index,
52 struct _getopt_data *d)
54 return _getopt_internal_r (argc, argv, options, long_options, opt_index,
55 0, d, 0);
58 /* Like getopt_long, but '-' as well as '--' can indicate a long option.
59 If an option that starts with '-' (not '--') doesn't match a long option,
60 but does match a short option, it is parsed as a short option
61 instead. */
63 int
64 getopt_long_only (int argc, char *__getopt_argv_const *argv,
65 const char *options,
66 const struct option *long_options, int *opt_index)
68 return _getopt_internal (argc, (char **) argv, options, long_options,
69 opt_index, 1, 0);
72 int
73 _getopt_long_only_r (int argc, char **argv, const char *options,
74 const struct option *long_options, int *opt_index,
75 struct _getopt_data *d)
77 return _getopt_internal_r (argc, argv, options, long_options, opt_index,
78 1, d, 0);
82 #ifdef TEST
84 #include <stdio.h>
86 int
87 main (int argc, char **argv)
89 int c;
90 int digit_optind = 0;
92 while (1)
94 int this_option_optind = optind ? optind : 1;
95 int option_index = 0;
96 static const struct option long_options[] =
98 {"add", 1, 0, 0},
99 {"append", 0, 0, 0},
100 {"delete", 1, 0, 0},
101 {"verbose", 0, 0, 0},
102 {"create", 0, 0, 0},
103 {"file", 1, 0, 0},
104 {0, 0, 0, 0}
107 c = getopt_long (argc, argv, "abc:d:0123456789",
108 long_options, &option_index);
109 if (c == -1)
110 break;
112 switch (c)
114 case 0:
115 printf ("option %s", long_options[option_index].name);
116 if (optarg)
117 printf (" with arg %s", optarg);
118 printf ("\n");
119 break;
121 case '0':
122 case '1':
123 case '2':
124 case '3':
125 case '4':
126 case '5':
127 case '6':
128 case '7':
129 case '8':
130 case '9':
131 if (digit_optind != 0 && digit_optind != this_option_optind)
132 printf ("digits occur in two different argv-elements.\n");
133 digit_optind = this_option_optind;
134 printf ("option %c\n", c);
135 break;
137 case 'a':
138 printf ("option a\n");
139 break;
141 case 'b':
142 printf ("option b\n");
143 break;
145 case 'c':
146 printf ("option c with value `%s'\n", optarg);
147 break;
149 case 'd':
150 printf ("option d with value `%s'\n", optarg);
151 break;
153 case '?':
154 break;
156 default:
157 printf ("?? getopt returned character code 0%o ??\n", c);
161 if (optind < argc)
163 printf ("non-option ARGV-elements: ");
164 while (optind < argc)
165 printf ("%s ", argv[optind++]);
166 printf ("\n");
169 exit (0);
172 #endif /* TEST */