diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2003-10-06 13:10:08 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2003-10-06 13:10:08 +0000 |
commit | 197b7ddda691b5f40eec611c198d8308f506771b (patch) | |
tree | 791e9f6f7aa56cc694bc65478dee303f10688652 /lib | |
parent | ba69c209956af7a5e0145e00507e142987694729 (diff) | |
download | mailutils-197b7ddda691b5f40eec611c198d8308f506771b.tar.gz mailutils-197b7ddda691b5f40eec611c198d8308f506771b.tar.bz2 |
Moved getopt stuff to mailbox
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/getopt.c | 1060 | ||||
-rw-r--r-- | lib/getopt1.c | 188 |
3 files changed, 1 insertions, 1249 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 5832e1704..110dde5fe 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
@@ -20,7 +20,7 @@ | |||
20 | noinst_LTLIBRARIES = libmailutils.la | 20 | noinst_LTLIBRARIES = libmailutils.la |
21 | 21 | ||
22 | INCLUDES = -I${top_srcdir}/include -I${top_builddir}/include/mailutils/gnu @INTLINCS@ | 22 | INCLUDES = -I${top_srcdir}/include -I${top_builddir}/include/mailutils/gnu @INTLINCS@ |
23 | libmailutils_la_SOURCES = basename.c daemon.c getopt.c getopt1.c md5.c \ | 23 | libmailutils_la_SOURCES = basename.c daemon.c md5.c \ |
24 | mu_dbm.c xstrdup.c xmalloc.c | 24 | mu_dbm.c xstrdup.c xmalloc.c |
25 | 25 | ||
26 | EXTRA_DIST = alloca.c fnmatch.c getpass.c malloc.c obstack.c \ | 26 | EXTRA_DIST = alloca.c fnmatch.c getpass.c malloc.c obstack.c \ |
diff --git a/lib/getopt.c b/lib/getopt.c deleted file mode 100644 index e852127f6..000000000 --- a/lib/getopt.c +++ /dev/null | |||
@@ -1,1060 +0,0 @@ | |||
1 | /* Getopt for GNU. | ||
2 | NOTE: The canonical source of this file is maintained with the GNU | ||
3 | C Library. Bugs can be reported to bug-glibc@gnu.org. | ||
4 | |||
5 | Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000 | ||
6 | Free Software Foundation, Inc. | ||
7 | |||
8 | This program is free software; you can redistribute it and/or modify it | ||
9 | under the terms of the GNU General Public License as published by the | ||
10 | Free Software Foundation; either version 2, or (at your option) any | ||
11 | later version. | ||
12 | |||
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. | ||
17 | |||
18 | You should have received a copy of the GNU General Public License | ||
19 | along with this program; if not, write to the Free Software Foundation, | ||
20 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | ||
21 | |||
22 | /* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. | ||
23 | Ditto for AIX 3.2 and <stdlib.h>. */ | ||
24 | #ifndef _NO_PROTO | ||
25 | # define _NO_PROTO | ||
26 | #endif | ||
27 | |||
28 | #ifdef HAVE_CONFIG_H | ||
29 | # include <config.h> | ||
30 | #endif | ||
31 | |||
32 | #if !defined __STDC__ || !__STDC__ | ||
33 | /* This is a separate conditional since some stdc systems | ||
34 | reject `defined (const)'. */ | ||
35 | # ifndef const | ||
36 | # define const | ||
37 | # endif | ||
38 | #endif | ||
39 | |||
40 | #include <stdio.h> | ||
41 | |||
42 | /* Comment out all this code if we are using the GNU C Library, and are not | ||
43 | actually compiling the library itself. This code is part of the GNU C | ||
44 | Library, but also included in many other GNU distributions. Compiling | ||
45 | and linking in this code is a waste when using the GNU C library | ||
46 | (especially if it is a shared library). Rather than having every GNU | ||
47 | program understand `configure --with-gnu-libc' and omit the object files, | ||
48 | it is simpler to just do this in the source for each such file. */ | ||
49 | |||
50 | #define GETOPT_INTERFACE_VERSION 2 | ||
51 | #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 | ||
52 | # include <gnu-versions.h> | ||
53 | # if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION | ||
54 | # define ELIDE_CODE | ||
55 | # endif | ||
56 | #endif | ||
57 | |||
58 | #ifndef ELIDE_CODE | ||
59 | |||
60 | |||
61 | /* This needs to come after some library #include | ||
62 | to get __GNU_LIBRARY__ defined. */ | ||
63 | #ifdef __GNU_LIBRARY__ | ||
64 | /* Don't include stdlib.h for non-GNU C libraries because some of them | ||
65 | contain conflicting prototypes for getopt. */ | ||
66 | # include <stdlib.h> | ||
67 | # include <unistd.h> | ||
68 | #endif /* GNU C library. */ | ||
69 | |||
70 | #ifdef VMS | ||
71 | # include <unixlib.h> | ||
72 | # if HAVE_STRING_H - 0 | ||
73 | # include <string.h> | ||
74 | # endif | ||
75 | #endif | ||
76 | |||
77 | #ifndef _ | ||
78 | /* This is for other GNU distributions with internationalized messages. */ | ||
79 | # if defined HAVE_LIBINTL_H || defined _LIBC | ||
80 | # include <libintl.h> | ||
81 | # ifndef _ | ||
82 | # define _(msgid) gettext (msgid) | ||
83 | # endif | ||
84 | # else | ||
85 | # define _(msgid) (msgid) | ||
86 | # endif | ||
87 | #endif | ||
88 | |||
89 | /* This version of `getopt' appears to the caller like standard Unix `getopt' | ||
90 | but it behaves differently for the user, since it allows the user | ||
91 | to intersperse the options with the other arguments. | ||
92 | |||
93 | As `getopt' works, it permutes the elements of ARGV so that, | ||
94 | when it is done, all the options precede everything else. Thus | ||
95 | all application programs are extended to handle flexible argument order. | ||
96 | |||
97 | Setting the environment variable POSIXLY_CORRECT disables permutation. | ||
98 | Then the behavior is completely standard. | ||
99 | |||
100 | GNU application programs can use a third alternative mode in which | ||
101 | they can distinguish the relative order of options and other arguments. */ | ||
102 | |||
103 | #include "getopt.h" | ||
104 | |||
105 | /* For communication from `getopt' to the caller. | ||
106 | When `getopt' finds an option that takes an argument, | ||
107 | the argument value is returned here. | ||
108 | Also, when `ordering' is RETURN_IN_ORDER, | ||
109 | each non-option ARGV-element is returned here. */ | ||
110 | |||
111 | char *optarg; | ||
112 | |||
113 | /* Index in ARGV of the next element to be scanned. | ||
114 | This is used for communication to and from the caller | ||
115 | and for communication between successive calls to `getopt'. | ||
116 | |||
117 | On entry to `getopt', zero means this is the first call; initialize. | ||
118 | |||
119 | When `getopt' returns -1, this is the index of the first of the | ||
120 | non-option elements that the caller should itself scan. | ||
121 | |||
122 | Otherwise, `optind' communicates from one call to the next | ||
123 | how much of ARGV has been scanned so far. */ | ||
124 | |||
125 | /* 1003.2 says this must be 1 before any call. */ | ||
126 | int optind = 1; | ||
127 | |||
128 | /* Formerly, initialization of getopt depended on optind==0, which | ||
129 | causes problems with re-calling getopt as programs generally don't | ||
130 | know that. */ | ||
131 | |||
132 | int __getopt_initialized; | ||
133 | |||
134 | /* The next char to be scanned in the option-element | ||
135 | in which the last option character we returned was found. | ||
136 | This allows us to pick up the scan where we left off. | ||
137 | |||
138 | If this is zero, or a null string, it means resume the scan | ||
139 | by advancing to the next ARGV-element. */ | ||
140 | |||
141 | static char *nextchar; | ||
142 | |||
143 | /* Callers store zero here to inhibit the error message | ||
144 | for unrecognized options. */ | ||
145 | |||
146 | int opterr = 1; | ||
147 | |||
148 | /* Set to an option character which was unrecognized. | ||
149 | This must be initialized on some systems to avoid linking in the | ||
150 | system's own getopt implementation. */ | ||
151 | |||
152 | int optopt = '?'; | ||
153 | |||
154 | /* Describe how to deal with options that follow non-option ARGV-elements. | ||
155 | |||
156 | If the caller did not specify anything, | ||
157 | the default is REQUIRE_ORDER if the environment variable | ||
158 | POSIXLY_CORRECT is defined, PERMUTE otherwise. | ||
159 | |||
160 | REQUIRE_ORDER means don't recognize them as options; | ||
161 | stop option processing when the first non-option is seen. | ||
162 | This is what Unix does. | ||
163 | This mode of operation is selected by either setting the environment | ||
164 | variable POSIXLY_CORRECT, or using `+' as the first character | ||
165 | of the list of option characters. | ||
166 | |||
167 | PERMUTE is the default. We permute the contents of ARGV as we scan, | ||
168 | so that eventually all the non-options are at the end. This allows options | ||
169 | to be given in any order, even with programs that were not written to | ||
170 | expect this. | ||
171 | |||
172 | RETURN_IN_ORDER is an option available to programs that were written | ||
173 | to expect options and other ARGV-elements in any order and that care about | ||
174 | the ordering of the two. We describe each non-option ARGV-element | ||
175 | as if it were the argument of an option with character code 1. | ||
176 | Using `-' as the first character of the list of option characters | ||
177 | selects this mode of operation. | ||
178 | |||
179 | The special argument `--' forces an end of option-scanning regardless | ||
180 | of the value of `ordering'. In the case of RETURN_IN_ORDER, only | ||
181 | `--' can cause `getopt' to return -1 with `optind' != ARGC. */ | ||
182 | |||
183 | static enum | ||
184 | { | ||
185 | REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER | ||
186 | } ordering; | ||
187 | |||
188 | /* Value of POSIXLY_CORRECT environment variable. */ | ||
189 | static char *posixly_correct; | ||
190 | |||
191 | #ifdef __GNU_LIBRARY__ | ||
192 | /* We want to avoid inclusion of string.h with non-GNU libraries | ||
193 | because there are many ways it can cause trouble. | ||
194 | On some systems, it contains special magic macros that don't work | ||
195 | in GCC. */ | ||
196 | # include <string.h> | ||
197 | # define my_index strchr | ||
198 | #else | ||
199 | |||
200 | # if HAVE_STRING_H | ||
201 | # include <string.h> | ||
202 | # else | ||
203 | # include <strings.h> | ||
204 | # endif | ||
205 | |||
206 | /* Avoid depending on library functions or files | ||
207 | whose names are inconsistent. */ | ||
208 | |||
209 | #ifndef getenv | ||
210 | extern char *getenv (); | ||
211 | #endif | ||
212 | |||
213 | static char * | ||
214 | my_index (str, chr) | ||
215 | const char *str; | ||
216 | int chr; | ||
217 | { | ||
218 | while (*str) | ||
219 | { | ||