diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2002-09-12 09:59:58 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2002-09-12 09:59:58 +0000 |
commit | 9c8a16d08105c73ff586c107cd03b93024257f3c (patch) | |
tree | 9e7b5711b369e4a119f37dbb37f4c6ce0613ccc8 /lib | |
parent | 59c464dbdd2e253294343f5410be558cc1424392 (diff) | |
download | mailutils-9c8a16d08105c73ff586c107cd03b93024257f3c.tar.gz mailutils-9c8a16d08105c73ff586c107cd03b93024257f3c.tar.bz2 |
Moved files needed by libmailbox to mailbox directory
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 9 | ||||
-rw-r--r-- | lib/argcv.c | 211 | ||||
-rw-r--r-- | lib/argp-ba.c | 26 | ||||
-rw-r--r-- | lib/argp-eexst.c | 38 | ||||
-rw-r--r-- | lib/argp-fmtstream.c | 387 | ||||
-rw-r--r-- | lib/argp-fs-xinl.c | 41 | ||||
-rw-r--r-- | lib/argp-help.c | 1796 | ||||
-rw-r--r-- | lib/argp-parse.c | 979 | ||||
-rw-r--r-- | lib/argp-pv.c | 25 | ||||
-rw-r--r-- | lib/argp-pvh.c | 32 | ||||
-rw-r--r-- | lib/argp-xinl.c | 40 | ||||
-rw-r--r-- | lib/getline.c | 155 | ||||
-rw-r--r-- | lib/strchrnul.c | 163 | ||||
-rw-r--r-- | lib/strndup.c | 46 | ||||
-rw-r--r-- | lib/strnlen.c | 30 |
15 files changed, 3 insertions, 3975 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index f73e5ab42..f54be6263 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
@@ -9,15 +9,12 @@ SUBDIRS = posix | |||
9 | 9 | ||
10 | INCLUDES = -I${top_srcdir}/include | 10 | INCLUDES = -I${top_srcdir}/include |
11 | libmailutils_la_SOURCES = basename.c daemon.c getopt.c getopt1.c md5.c \ | 11 | libmailutils_la_SOURCES = basename.c daemon.c getopt.c getopt1.c md5.c \ |
12 | mu_dbm.c getline.c xstrdup.c xmalloc.c \ | 12 | mu_dbm.c xstrdup.c xmalloc.c \ |
13 | argcv.c \ | ||
14 | pin.c | 13 | pin.c |
15 | 14 | ||
16 | EXTRA_DIST = alloca.c fnmatch.c fgetpwent.c getpass.c malloc.c obstack.c \ | 15 | EXTRA_DIST = alloca.c fnmatch.c fgetpwent.c getpass.c malloc.c obstack.c \ |
17 | realloc.c setenv.c snprintf.c strchrnul.c strndup.c strnlen.c strncasecmp.c \ | 16 | realloc.c setenv.c snprintf.c strncasecmp.c \ |
18 | strcasecmp.c strtok_r.c strsignal.c xstrtol.c vasprintf.c \ | 17 | strcasecmp.c strsignal.c xstrtol.c vasprintf.c \ |
19 | argp-ba.c argp-eexst.c argp-fmtstream.c argp-fs-xinl.c \ | ||
20 | argp-help.c argp-parse.c argp-pv.c argp-pvh.c argp-xinl.c \ | ||
21 | utmp.c | 18 | utmp.c |
22 | 19 | ||
23 | noinst_HEADERS = argcv.h error.h fnmatch.h getline.h getopt.h md5.h \ | 20 | noinst_HEADERS = argcv.h error.h fnmatch.h getline.h getopt.h md5.h \ |
diff --git a/lib/argcv.c b/lib/argcv.c deleted file mode 100644 index 291f5c44d..000000000 --- a/lib/argcv.c +++ /dev/null | |||
@@ -1,211 +0,0 @@ | |||
1 | /* argcv.c - simple functions for parsing input based on whitespace | ||
2 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | #include <ctype.h> | ||
19 | |||
20 | #include "argcv.h" | ||
21 | |||
22 | /* | ||
23 | * takes a string and splits it into several strings, breaking at ' ' | ||
24 | * command is the string to split | ||
25 | * the number of strings is placed into argc | ||
26 | * the split strings are put into argv | ||
27 | * returns 0 on success, nonzero on failure | ||
28 | */ | ||
29 | |||
30 | #define isws(c) ((c)==' '||(c)=='\t'||(c)=='\n') | ||
31 | #define isdelim(c,delim) ((c)=='"'||strchr(delim,(c))!=NULL) | ||
32 | |||
33 | static int | ||
34 | argcv_scan (int len, const char *command, const char *delim, const char* cmnt, | ||
35 | int *start, int *end, int *save) | ||
36 | { | ||
37 | int i = 0; | ||
38 | |||
39 | for (;;) | ||
40 | { | ||
41 | i = *save; | ||
42 | |||
43 | if (i >= len) | ||
44 | return i + 1; | ||
45 | |||
46 | /* Skip initial whitespace */ | ||
47 | while (i < len && isws (command[i])) | ||
48 | i++; | ||
49 | *start = i; | ||
50 | |||
51 | switch (command[i]) | ||
52 | { | ||
53 | case '"': | ||
54 | case '\'': | ||
55 | while (++i < len && command[i] != command[*start]) | ||
56 | ; | ||
57 | if (i < len) /* found matching quote */ | ||
58 | break; | ||
59 | /*FALLTHRU*/ default: | ||
60 | if (isdelim (command[i], delim)) | ||
61 | break; | ||
62 | /* Skip until next whitespace character or end of line */ | ||
63 | while (++i < len && | ||
64 | !(isws (command[i]) || isdelim (command[i], delim))) | ||
65 | ; | ||
66 | i--; | ||
67 | break; | ||
68 | } | ||
69 | |||
70 | *end = i; | ||
71 | *save = i + 1; | ||
72 | |||
73 | /* If we have a token, and it starts with a comment character, skip | ||
74 | to the newline and restart the token search. */ | ||
75 | if (*save <= len) | ||
76 | { | ||
77 | if (cmnt && strchr (cmnt, command[*start]) != NULL) | ||
78 | { | ||
79 | i = *save; | ||
80 | while (i < len && command[i] != '\n') | ||
81 | i++; | ||
82 | |||
83 | *save = i; | ||
84 | continue; | ||
85 | } | ||
86 | } | ||
87 | break; | ||
88 | } | ||
89 | return *save; | ||
90 | } | ||
91 | |||
92 | int | ||
93 | argcv_get (const char *command, const char *delim, const char* cmnt, | ||
94 | int *argc, char ***argv) | ||
95 | { | ||
96 | int len = strlen (command); | ||
97 | int i = 0; | ||
98 | int start, end, save; | ||
99 | |||
100 | *argv = NULL; | ||
101 | |||
102 | /* Count number of arguments */ | ||
103 | *argc = 0; | ||
104 | save = 0; | ||
105 | |||
106 | while (argcv_scan (len, command, delim, cmnt, &start, &end, &save) <= len) | ||
107 | (*argc)++; | ||
108 | |||
109 | *argv = calloc ((*argc + 1), sizeof (char *)); | ||
110 | |||
111 | i = 0; | ||
112 | save = 0; | ||
113 | for (i = 0; i < *argc; i++) | ||
114 | { | ||
115 | int n; | ||
116 | argcv_scan (len, command, delim, cmnt, &start, &end, &save); | ||
117 | |||
118 | /* FIXME: this is the right place to do unescaping as well | ||
119 | as stripping of quotes. */ | ||
120 | if (command[start] == '"' && command[end] == '"') | ||
121 | { | ||
122 | start++; | ||
123 | end--; | ||
124 | } | ||
125 | else if (command[start] == '\'' && command[end] == '\'') | ||
126 | { | ||
127 | start++; | ||
128 | end--; | ||
129 | } | ||
130 | n = end - start + 1; | ||
131 | (*argv)[i] = calloc (n+1, sizeof (char)); | ||
132 | if ((*argv)[i] == NULL) | ||
133 | return 1; | ||
134 | memcpy ((*argv)[i], &command[start], n); | ||
135 | (*argv)[i][n] = 0; | ||
136 | } | ||
137 | (*argv)[i] = NULL; | ||
138 | return 0; | ||
139 | } | ||
140 | |||
141 | /* | ||
142 | * frees all elements of an argv array | ||
143 | * argc is the number of elements | ||
144 | * argv is the array | ||
145 | */ | ||
146 | int | ||
147 | argcv_free (int argc, char **argv) | ||
148 | { | ||
149 | while (--argc >= 0) | ||
150 | if (argv[argc]) | ||
151 | free (argv[argc]); | ||
152 | free (argv); | ||
153 | return 1; | ||
154 | } | ||
155 | |||
156 | /* Take a argv an make string separated by ' '. */ | ||
157 | |||
158 | int | ||
159 | argcv_string (int argc, char **argv, char **pstring) | ||
160 | { | ||
161 | int i; | ||
162 | size_t len; | ||
163 | char *buffer; | ||
164 | |||
165 | /* No need. */ | ||
166 | if (pstring == NULL) | ||
167 | return 1; | ||
168 | |||
169 | buffer = malloc (1); | ||
170 | if (buffer == NULL) | ||
171 | return 1; | ||
172 | *buffer = '\0'; | ||
173 | |||
174 | for (len = i = 0; i < argc; i++) | ||
175 | { | ||
176 | len += strlen (argv[i]) + 2; | ||
177 | buffer = realloc (buffer, len); | ||
178 | if (buffer == NULL) | ||
179 | return 1; | ||
180 | if (i != 0) | ||
181 | strcat (buffer, " "); | ||
182 | strcat (buffer, argv[i]); | ||
183 | } | ||
184 | |||
185 | /* Strip off trailing space. */ | ||
186 | if (*buffer != '\0') | ||
187 | { | ||
188 | while (buffer[strlen (buffer) - 1] == ' ') | ||
189 | { | ||
190 | buffer[strlen (buffer) - 1] = '\0'; | ||
191 | } | ||
192 | } | ||
193 | if (pstring) | ||
194 | *pstring = buffer; | ||
195 | return 0; | ||
196 | } | < |