Remove libmu_compat
Showing
20 changed files
with
2 additions
and
1284 deletions
... | @@ -1318,7 +1318,6 @@ test -z "$client_list" && client_list=" [NONE]" | ... | @@ -1318,7 +1318,6 @@ test -z "$client_list" && client_list=" [NONE]" |
1318 | # Initialize the (autotest) test suite. | 1318 | # Initialize the (autotest) test suite. |
1319 | AC_CONFIG_TESTDIR(libmailutils/tests) | 1319 | AC_CONFIG_TESTDIR(libmailutils/tests) |
1320 | AC_CONFIG_TESTDIR(testsuite) | 1320 | AC_CONFIG_TESTDIR(testsuite) |
1321 | AC_CONFIG_TESTDIR(libmu_compat/tests) | ||
1322 | AC_CONFIG_TESTDIR(frm/tests) | 1321 | AC_CONFIG_TESTDIR(frm/tests) |
1323 | AC_CONFIG_TESTDIR(maidag/tests) | 1322 | AC_CONFIG_TESTDIR(maidag/tests) |
1324 | AC_CONFIG_TESTDIR(mail/tests) | 1323 | AC_CONFIG_TESTDIR(mail/tests) |
... | @@ -1331,8 +1330,6 @@ AC_CONFIG_TESTDIR(imap4d/tests) | ... | @@ -1331,8 +1330,6 @@ AC_CONFIG_TESTDIR(imap4d/tests) |
1331 | 1330 | ||
1332 | AC_CONFIG_FILES([libmailutils/tests/Makefile | 1331 | AC_CONFIG_FILES([libmailutils/tests/Makefile |
1333 | libmailutils/tests/atlocal | 1332 | libmailutils/tests/atlocal |
1334 | libmu_compat/tests/Makefile | ||
1335 | libmu_compat/tests/atlocal | ||
1336 | testsuite/Makefile | 1333 | testsuite/Makefile |
1337 | testsuite/atlocal | 1334 | testsuite/atlocal |
1338 | comsat/tests/Makefile | 1335 | comsat/tests/Makefile |
... | @@ -1487,7 +1484,6 @@ AC_CONFIG_FILES([ | ... | @@ -1487,7 +1484,6 @@ AC_CONFIG_FILES([ |
1487 | libproto/nntp/Makefile | 1484 | libproto/nntp/Makefile |
1488 | libproto/imap/Makefile | 1485 | libproto/imap/Makefile |
1489 | libproto/imap/tests/Makefile | 1486 | libproto/imap/tests/Makefile |
1490 | libmu_compat/Makefile | ||
1491 | maidag/Makefile | 1487 | maidag/Makefile |
1492 | mail/Makefile | 1488 | mail/Makefile |
1493 | mail/testsuite/Makefile | 1489 | mail/testsuite/Makefile | ... | ... |
... | @@ -28,7 +28,6 @@ pkginclude_HEADERS = \ | ... | @@ -28,7 +28,6 @@ pkginclude_HEADERS = \ |
28 | acl.h\ | 28 | acl.h\ |
29 | address.h\ | 29 | address.h\ |
30 | alloc.h\ | 30 | alloc.h\ |
31 | argcv.h\ | ||
32 | assoc.h\ | 31 | assoc.h\ |
33 | attribute.h\ | 32 | attribute.h\ |
34 | auth.h\ | 33 | auth.h\ |
... | @@ -102,7 +101,6 @@ pkginclude_HEADERS = \ | ... | @@ -102,7 +101,6 @@ pkginclude_HEADERS = \ |
102 | tls.h\ | 101 | tls.h\ |
103 | types.h\ | 102 | types.h\ |
104 | url.h\ | 103 | url.h\ |
105 | vartab.h\ | ||
106 | version.h\ | 104 | version.h\ |
107 | wordsplit.h | 105 | wordsplit.h |
108 | 106 | ... | ... |
include/mailutils/argcv.h
deleted
100644 → 0
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999-2001, 2005, 2007, 2010-2012, 2014-2016 Free | ||
3 | Software Foundation, Inc. | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 3 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General | ||
16 | Public License along with this library. If not, see | ||
17 | <http://www.gnu.org/licenses/>. */ | ||
18 | |||
19 | #ifndef _ARGCV_H | ||
20 | #define _ARGCV_H 1 | ||
21 | |||
22 | #include <stdio.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <unistd.h> | ||
25 | #include <string.h> | ||
26 | |||
27 | #include <mailutils/types.h> | ||
28 | |||
29 | #ifdef __cplusplus | ||
30 | extern "C" { | ||
31 | #endif | ||
32 | |||
33 | void mu_argcv_free (size_t argc, char **argv); | ||
34 | void mu_argv_free (char **argv); | ||
35 | |||
36 | enum mu_argcv_escape | ||
37 | { | ||
38 | mu_argcv_escape_no, | ||
39 | mu_argcv_escape_c | ||
40 | /* mu_argcv_escape_sh */ | ||
41 | }; | ||
42 | |||
43 | int mu_argcv_join (int argc, char **argv, char *delim, | ||
44 | enum mu_argcv_escape esc, | ||
45 | char **pstring); | ||
46 | void mu_argcv_remove (int *pargc, char ***pargv, | ||
47 | int (*sel) (const char *, void *), void *); | ||
48 | int mu_argcv_string (int argc, char **argv, char **string); | ||
49 | |||
50 | |||
51 | /* Deprecated interfaces */ | ||
52 | |||
53 | #define MU_ARGCV_RETURN_DELIMS 0x01 | ||
54 | |||
55 | #ifndef MU_ARCGV_DEPRECATED | ||
56 | # define MU_ARCGV_DEPRECATED MU_DEPRECATED | ||
57 | #endif | ||
58 | |||
59 | int mu_argcv_get (const char *command, const char *delim, | ||
60 | const char *cmnt, | ||
61 | int *argc, char ***argv) MU_ARCGV_DEPRECATED; | ||
62 | int mu_argcv_get_n (const char *command, int len, | ||
63 | const char *delim, const char *cmnt, | ||
64 | int *argc, char ***argv) MU_ARCGV_DEPRECATED; | ||
65 | int mu_argcv_get_np (const char *command, int len, | ||
66 | const char *delim, const char *cmnt, | ||
67 | int flags, | ||
68 | int *pargc, char ***pargv, char **endp) | ||
69 | MU_ARCGV_DEPRECATED; | ||
70 | |||
71 | int mu_argcv_unquote_char (int c) MU_ARCGV_DEPRECATED; | ||
72 | int mu_argcv_quote_char (int c) MU_ARCGV_DEPRECATED; | ||
73 | size_t mu_argcv_quoted_length (const char *str, int *quote) | ||
74 | MU_ARCGV_DEPRECATED; | ||
75 | void mu_argcv_unquote_copy (char *dst, const char *src, size_t n) | ||
76 | MU_ARCGV_DEPRECATED; | ||
77 | void mu_argcv_quote_copy (char *dst, const char *src) | ||
78 | MU_ARCGV_DEPRECATED; | ||
79 | |||
80 | #ifdef __cplusplus | ||
81 | } | ||
82 | #endif | ||
83 | |||
84 | #endif /* _ARGCV_H */ |
... | @@ -134,13 +134,6 @@ enum mu_iconv_fallback_mode | ... | @@ -134,13 +134,6 @@ enum mu_iconv_fallback_mode |
134 | mu_fallback_copy_octal | 134 | mu_fallback_copy_octal |
135 | }; | 135 | }; |
136 | 136 | ||
137 | extern int mu_filter_iconv_create (mu_stream_t *s, mu_stream_t transport, | ||
138 | const char *fromcode, const char *tocode, | ||
139 | int flags, | ||
140 | enum mu_iconv_fallback_mode fallback_mode) | ||
141 | MU_DEPRECATED; | ||
142 | |||
143 | |||
144 | extern int mu_linelen_filter_create (mu_stream_t *pstream, mu_stream_t stream, | 137 | extern int mu_linelen_filter_create (mu_stream_t *pstream, mu_stream_t stream, |
145 | size_t limit, int flags); | 138 | size_t limit, int flags); |
146 | 139 | ... | ... |
... | @@ -154,8 +154,6 @@ int mu_list_foreach_dir (mu_list_t _list, int _dir, mu_list_action_t _action, | ... | @@ -154,8 +154,6 @@ int mu_list_foreach_dir (mu_list_t _list, int _dir, mu_list_action_t _action, |
154 | void *_cbdata); | 154 | void *_cbdata); |
155 | /* Same as mu_list_foreach_dir with _dir==0. */ | 155 | /* Same as mu_list_foreach_dir with _dir==0. */ |
156 | int mu_list_foreach (mu_list_t _list, mu_list_action_t _action, void *_data); | 156 | int mu_list_foreach (mu_list_t _list, mu_list_action_t _action, void *_data); |
157 | /* A historical alias to the above. */ | ||
158 | int mu_list_do (mu_list_t, mu_list_action_t, void *) MU_DEPRECATED; | ||
159 | 157 | ||
160 | 158 | ||
161 | /* ************************************************* */ | 159 | /* ************************************************* */ | ... | ... |
include/mailutils/vartab.h
deleted
100644 → 0
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007, 2010-2012, 2014-2016 Free Software Foundation, | ||
3 | Inc. | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 3 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General | ||
16 | Public License along with this library; If not, see | ||
17 | <http://www.gnu.org/licenses/>. */ | ||
18 | |||
19 | #ifndef _MAILUTILS_VARTAB_H | ||
20 | #define _MAILUTILS_VARTAB_H | ||
21 | |||
22 | #include <mailutils/types.h> | ||
23 | |||
24 | #ifdef MU_SUPPRESS_DEPRECATION | ||
25 | # undef MU_DEPRECATED | ||
26 | # define MU_DEPRECATED | ||
27 | #else | ||
28 | # warning "Mailutils support for vartab functions has been deprecated." | ||
29 | # warning "Revise your code to use <mailutils/wordsplit.h>." | ||
30 | #endif | ||
31 | |||
32 | typedef int (*mu_var_expansion_fp) (const char *name, void *data, char **p); | ||
33 | typedef void (*mu_var_free_fp) (void *data, char *value); | ||
34 | |||
35 | int mu_vartab_create (mu_vartab_t *pvar) MU_DEPRECATED; | ||
36 | int mu_vartab_destroy (mu_vartab_t *pvar) MU_DEPRECATED; | ||
37 | int mu_vartab_define (mu_vartab_t var, const char *name, const char *value, | ||
38 | int isstatic) MU_DEPRECATED; | ||
39 | int mu_vartab_define_exp (mu_vartab_t var, const char *name, | ||
40 | mu_var_expansion_fp fun, mu_var_free_fp free, | ||
41 | void *data) MU_DEPRECATED; | ||
42 | int mu_vartab_count (mu_vartab_t vt, size_t *pcount) MU_DEPRECATED; | ||
43 | int mu_vartab_getvar (mu_vartab_t vt, const char *name, const char **pvalue) | ||
44 | MU_DEPRECATED; | ||
45 | int mu_vartab_expand (mu_vartab_t vt, const char *str, char **pres) | ||
46 | MU_DEPRECATED; | ||
47 | #endif |
... | @@ -45,11 +45,3 @@ mu_list_foreach (mu_list_t list, mu_list_action_t action, void *cbdata) | ... | @@ -45,11 +45,3 @@ mu_list_foreach (mu_list_t list, mu_list_action_t action, void *cbdata) |
45 | mu_iterator_destroy (&itr); | 45 | mu_iterator_destroy (&itr); |
46 | return status; | 46 | return status; |
47 | } | 47 | } |
48 | |||
49 | /* Retained for compatibility with previous versions. | ||
50 | In the future it will be removed, or changed to a define or weak alias. */ | ||
51 | int | ||
52 | mu_list_do (mu_list_t list, mu_list_action_t action, void *cbdata) | ||
53 | { | ||
54 | return mu_list_foreach (list, action, cbdata); | ||
55 | } | ... | ... |
libmu_compat/Makefile.am
deleted
100644 → 0
1 | # This file is part of GNU Mailutils | ||
2 | # Copyright (C) 2010-2012, 2014-2016 Free Software Foundation, Inc. | ||
3 | # | ||
4 | # GNU Mailutils is free software; you can redistribute it and/or | ||
5 | # modify it under the terms of the GNU General Public License as | ||
6 | # published by the Free Software Foundation; either version 3, or (at | ||
7 | # your option) any later version. | ||
8 | # | ||
9 | # GNU Mailutils is distributed in the hope that it will be useful, but | ||
10 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | # General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | SUBDIRS = . tests | ||
18 | lib_LTLIBRARIES = libmu_compat.la | ||
19 | |||
20 | libmu_compat_la_SOURCES = \ | ||
21 | argcv.c\ | ||
22 | filter_iconv.c\ | ||
23 | vartab.c | ||
24 | |||
25 | AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils | ||
26 |
libmu_compat/argcv.c
deleted
100644 → 0
1 | /* argcv.c - simple functions for parsing input based on whitespace | ||
2 | Copyright (C) 1999-2001, 2003-2006, 2010-2012, 2014-2016 Free | ||
3 | Software Foundation, Inc. | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 3 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General | ||
16 | Public License along with this library. If not, see | ||
17 | <http://www.gnu.org/licenses/>. */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include <config.h> | ||
21 | #endif | ||
22 | |||
23 | #include <ctype.h> | ||
24 | #include <errno.h> | ||
25 | #define MU_ARCGV_DEPRECATED | ||
26 | #include <mailutils/argcv.h> | ||
27 | |||
28 | /* Keep mailutils namespace clean */ | ||
29 | #define argcv_get mu_argcv_get | ||
30 | #define argcv_get_n mu_argcv_get_n | ||
31 | #define argcv_get_np mu_argcv_get_np | ||
32 | #define argcv_unquote_char mu_argcv_unquote_char | ||
33 | #define argcv_quote_char mu_argcv_quote_char | ||
34 | #define argcv_quoted_length mu_argcv_quoted_length | ||
35 | #define argcv_unquote_copy mu_argcv_unquote_copy | ||
36 | #define argcv_quote_copy mu_argcv_quote_copy | ||
37 | |||
38 | /* | ||
39 | * takes a string and splits it into several strings, breaking at ' ' | ||
40 | * command is the string to split | ||
41 | * the number of strings is placed into argc | ||
42 | * the split strings are put into argv | ||
43 | * returns 0 on success, nonzero on failure | ||
44 | */ | ||
45 | |||
46 | #define isws(c) ((c)==' '||(c)=='\t'||(c)=='\n') | ||
47 | #define isdelim(c,delim) (strchr(delim,(c))!=NULL) | ||
48 | |||
49 | struct argcv_info | ||
50 | { | ||
51 | int len; | ||
52 | const char *command; | ||
53 | const char *delim; | ||
54 | const char *comment; | ||
55 | int flags; | ||
56 | |||
57 | int start; | ||
58 | int end; | ||
59 | int save; | ||
60 | int finish_pos; | ||
61 | }; | ||
62 | |||
63 | static void | ||
64 | init_argcv_info (struct argcv_info *ap, int flags, | ||
65 | int len, const char *command, const char *delim, | ||
66 | const char *comment) | ||
67 | { | ||
68 | memset (ap, 0, sizeof *ap); | ||
69 | ap->len = len; | ||
70 | ap->command = command; | ||
71 | ap->delim = delim; | ||
72 | ap->comment = comment; | ||
73 | ap->flags = flags; | ||
74 | } | ||
75 | |||
76 | static int | ||
77 | argcv_scan (struct argcv_info *ap) | ||
78 | { | ||
79 | int i = 0; | ||
80 | int len = ap->len; | ||
81 | const char *command = ap->command; | ||
82 | const char *delim = ap->delim; | ||
83 | const char *comment = ap->comment; | ||
84 | |||
85 | for (;;) | ||
86 | { | ||
87 | i = ap->save; | ||
88 | |||
89 | if (i >= len) | ||
90 | return i + 1; | ||
91 | |||
92 | /* Skip initial whitespace */ | ||
93 | while (i < len && isws (command[i])) | ||
94 | i++; | ||
95 | ap->start = i; | ||
96 | |||
97 | if (!isdelim (command[i], delim)) | ||
98 | { | ||
99 | while (i < len) | ||
100 | { | ||
101 | if (command[i] == '\\') | ||
102 | { | ||
103 | if (++i == len) | ||
104 | break; | ||
105 | i++; | ||
106 | continue; | ||
107 | } | ||
108 | |||
109 | if (command[i] == '\'' || command[i] == '"') | ||
110 | { | ||
111 | int j; | ||
112 | for (j = i + 1; j < len && command[j] != command[i]; j++) | ||
113 | if (command[j] == '\\') | ||
114 | j++; | ||
115 | if (j < len) | ||
116 | i = j + 1; | ||
117 | else | ||
118 | i++; | ||
119 | } | ||
120 | else if (isws (command[i]) || isdelim (command[i], delim)) | ||
121 | break; | ||
122 | else | ||
123 | i++; /* skip the escaped character */ | ||
124 | } | ||
125 | i--; | ||
126 | } | ||
127 | else if (!(ap->flags & MU_ARGCV_RETURN_DELIMS)) | ||
128 | { | ||
129 | while (i < len && isdelim (command[i], delim)) | ||
130 | i++; | ||
131 | ap->save = i; | ||
132 | continue; | ||
133 | } | ||
134 | |||
135 | |||
136 | ap->end = i; | ||
137 | ap->save = ap->finish_pos = i + 1; | ||
138 | |||
139 | /* If we have a token, and it starts with a comment character, skip | ||
140 | to the newline and restart the token search. */ | ||
141 | if (ap->save <= len) | ||
142 | { | ||
143 | if (strchr (comment, command[ap->start]) != NULL) | ||
144 | { | ||
145 | ap->finish_pos = ap->start; | ||
146 | i = ap->save; | ||
147 | while (i < len && command[i] != '\n') | ||
148 | i++; | ||
149 | |||
150 | ap->save = i; | ||
151 | continue; | ||
152 | } | ||
153 | } | ||
154 | break; | ||
155 | } | ||
156 | return ap->save; | ||
157 | } | ||
158 | |||
159 | static char quote_transtab[] = "\\\\\"\"a\ab\bf\fn\nr\rt\tv\v"; | ||
160 | |||
161 | int | ||
162 | argcv_unquote_char (int c) | ||
163 | { | ||
164 | char *p; | ||
165 | |||
166 | for (p = quote_transtab; *p; p += 2) | ||
167 | { | ||
168 | if (*p == c) | ||
169 | return p[1]; | ||
170 | } | ||
171 | return c; | ||
172 | } | ||
173 | |||
174 | int | ||
175 | argcv_quote_char (int c) | ||
176 | { | ||
177 | char *p; | ||
178 | |||
179 | for (p = quote_transtab + sizeof(quote_transtab) - 2; | ||
180 | p > quote_transtab; p -= 2) | ||
181 | { | ||
182 | if (*p == c) | ||
183 | return p[-1]; | ||
184 | } | ||
185 | return -1; | ||
186 | } | ||
187 | |||
188 | #define to_num(c) \ | ||
189 | (isdigit(c) ? c - '0' : (isxdigit(c) ? toupper(c) - 'A' + 10 : 255 )) | ||
190 | |||
191 | static int | ||
192 | xtonum (int *pval, const char *src, int base, int cnt) | ||
193 | { | ||
194 | int i, val; | ||
195 | |||
196 | for (i = 0, val = 0; i < cnt; i++, src++) | ||
197 | { | ||
198 | int n = *(unsigned char*)src; | ||
199 | if (n > 127 || (n = to_num(n)) >= base) | ||
200 | break; | ||
201 | val = val*base + n; | ||
202 | } | ||
203 | *pval = val; | ||
204 | return i; | ||
205 | } | ||
206 | |||
207 | size_t | ||
208 | argcv_quoted_length (const char *str, int *quote) | ||
209 | { | ||
210 | size_t len = 0; | ||
211 | |||
212 | *quote = 0; | ||
213 | for (; *str; str++) | ||
214 | { | ||
215 | if (*str == ' ') | ||
216 | { | ||
217 | len++; | ||
218 | *quote = 1; | ||
219 | } | ||
220 | else if (*str == '"') | ||
221 | { | ||
222 | len += 2; | ||
223 | *quote = 1; | ||
224 | } | ||
225 | else if (*str != '\t' && *str != '\\' && isprint (*str)) | ||
226 | len++; | ||
227 | else if (argcv_quote_char (*str) != -1) | ||
228 | len += 2; | ||
229 | else | ||
230 | len += 4; | ||
231 | } | ||
232 | return len; | ||
233 | } | ||
234 | |||
235 | void | ||
236 | argcv_unquote_copy (char *dst, const char *src, size_t n) | ||
237 | { | ||
238 | int i = 0; | ||
239 | int c; | ||
240 | int expect_delim = 0; | ||
241 | |||
242 | while (i < n) | ||
243 | { | ||
244 | switch (src[i]) | ||
245 | { | ||
246 | case '\'': | ||
247 | case '"': | ||
248 | if (!expect_delim) | ||
249 | { | ||
250 | const char *p; | ||
251 | |||
252 | for (p = src+i+1; *p && *p != src[i]; p++) | ||
253 | if (*p == '\\') | ||
254 | p++; | ||
255 | if (*p) | ||
256 | expect_delim = src[i++]; | ||
257 | else | ||
258 | *dst++ = src[i++]; | ||
259 | } | ||
260 | else if (expect_delim == src[i]) | ||
261 | ++i; | ||
262 | else | ||
263 | *dst++ = src[i++]; | ||
264 | break; | ||
265 | |||
266 | case '\\': | ||
267 | ++i; | ||
268 | if (src[i] == 'x' || src[i] == 'X') | ||
269 | { | ||
270 | if (n - i < 2) | ||
271 | { | ||
272 | *dst++ = '\\'; | ||
273 | *dst++ = src[i++]; | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | int off = xtonum(&c, src + i + 1, 16, 2); | ||
278 | if (off == 0) | ||
279 | { | ||
280 | *dst++ = '\\'; | ||
281 | *dst++ = src[i++]; | ||
282 | } | ||
283 | else | ||
284 | { | ||
285 | *dst++ = c; | ||
286 | i += off + 1; | ||
287 | } | ||
288 | } | ||
289 | } | ||
290 | else if ((unsigned char)src[i] < 128 && isdigit (src[i])) | ||
291 | { | ||
292 | if (n - i < 1) | ||
293 | { | ||
294 | *dst++ = '\\'; | ||
295 | *dst++ = src[i++]; | ||
296 | } | ||
297 | else | ||
298 | { | ||
299 | int off = xtonum (&c, src+i, 8, 3); | ||
300 | if (off == 0) | ||
301 | { | ||
302 | *dst++ = '\\'; | ||
303 | *dst++ = src[i++]; | ||
304 | } | ||
305 | else | ||
306 | { | ||
307 | *dst++ = c; | ||
308 | i += off; | ||
309 | } | ||
310 | } | ||
311 | } | ||
312 | else | ||
313 | *dst++ = argcv_unquote_char (src[i++]); | ||
314 | break; | ||
315 | |||
316 | default: | ||
317 | *dst++ = src[i++]; | ||
318 | } | ||
319 | } | ||
320 | *dst = 0; | ||
321 | } | ||
322 | |||
323 | void | ||
324 | argcv_quote_copy (char *dst, const char *src) | ||
325 | { | ||
326 | for (; *src; src++) | ||
327 | { | ||
328 | if (*src == '"') | ||
329 | { | ||
330 | *dst++ = '\\'; | ||
331 | *dst++ = *src; | ||
332 | } | ||
333 | else if (*src != '\t' && *src != '\\' && isprint(*src)) | ||
334 | *dst++ = *src; | ||
335 | else | ||
336 | { | ||
337 | int c = argcv_quote_char (*src); | ||
338 | *dst++ = '\\'; | ||
339 | if (c != -1) | ||
340 | *dst++ = c; | ||
341 | else | ||
342 | { | ||
343 | char tmp[4]; | ||
344 | snprintf (tmp, sizeof tmp, "%03o", *(unsigned char*)src); | ||
345 | memcpy (dst, tmp, 3); | ||
346 | dst += 3; | ||
347 | } | ||
348 | } | ||
349 | } | ||
350 | } | ||
351 | |||
352 | int | ||
353 | argcv_get_np (const char *command, int len, | ||
354 | const char *delim, const char *cmnt, | ||
355 | int flags, | ||
356 | int *pargc, char ***pargv, char **endp) | ||
357 | { | ||
358 | int i = 0; | ||
359 | struct argcv_info info; | ||
360 | int argc; | ||
361 | char **argv; | ||
362 | |||
363 | if (!delim) | ||
364 | delim = ""; | ||
365 | if (!cmnt) | ||
366 | cmnt = ""; | ||
367 | |||
368 | init_argcv_info (&info, flags, len, command, delim, cmnt); | ||
369 | |||
370 | /* Count number of arguments */ | ||
371 | argc = 0; | ||
372 | while (argcv_scan (&info) <= len) | ||
373 | argc++; | ||
374 | |||
375 | argv = calloc ((argc + 1), sizeof (char *)); | ||
376 | if (argv == NULL) | ||
377 | return ENOMEM; | ||
378 | |||
379 | i = 0; | ||
380 | info.save = 0; | ||
381 | for (i = 0; i < argc; i++) | ||
382 | { | ||
383 | int n; | ||
384 | int unquote; | ||
385 | |||
386 | argcv_scan (&info); | ||
387 | |||
388 | if ((command[info.start] == '"' || command[info.end] == '\'') | ||
389 | && command[info.end] == command[info.start]) | ||
390 | { | ||
391 | if (info.start < info.end) | ||
392 | { | ||
393 | info.start++; | ||
394 | info.end--; | ||
395 | } | ||
396 | unquote = 0; | ||
397 | } | ||
398 | else | ||
399 | unquote = 1; | ||
400 | |||
401 | n = info.end - info.start + 1; | ||
402 | argv[i] = calloc (n + 1, sizeof (char)); | ||
403 | if (argv[i] == NULL) | ||
404 | { | ||
405 | mu_argcv_free (i, argv); | ||
406 | return ENOMEM; | ||
407 | } | ||
408 | if (unquote) | ||
409 | argcv_unquote_copy (argv[i], &command[info.start], n); | ||
410 | else | ||
411 | memcpy (argv[i], &command[info.start], n); | ||
412 | argv[i][n] = 0; | ||
413 | } | ||
414 | argv[i] = NULL; | ||
415 | |||
416 | *pargc = argc; | ||
417 | *pargv = argv; | ||
418 | if (endp) | ||
419 | *endp = (char*) (command + info.finish_pos); | ||
420 | return 0; | ||
421 | } | ||
422 | |||
423 | int | ||
424 | argcv_get_n (const char *command, int len, const char *delim, const char *cmnt, | ||
425 | int *pargc, char ***pargv) | ||
426 | { | ||
427 | return argcv_get_np (command, len, delim, cmnt, MU_ARGCV_RETURN_DELIMS, | ||
428 | pargc, pargv, NULL); | ||
429 | } | ||
430 | |||
431 | int | ||
432 | argcv_get (const char *command, const char *delim, const char *cmnt, | ||
433 | int *argc, char ***argv) | ||
434 | { | ||
435 | return argcv_get_n (command, strlen (command), delim, cmnt, argc, argv); | ||
436 | } | ||
437 | |||
438 | |||
439 | |||
440 |
libmu_compat/filter_iconv.c
deleted
100644 → 0
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2010-2012, 2014-2016 Free Software Foundation, Inc. | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 3 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library 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 GNU | ||
12 | Lesser General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Lesser General | ||
15 | Public License along with this library. If not, see | ||
16 | <http://www.gnu.org/licenses/>. */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | #include <stdlib.h> | ||
22 | #include <mailutils/types.h> | ||
23 | #include <mailutils/stream.h> | ||
24 | #include <mailutils/filter.h> | ||
25 | |||
26 | int | ||
27 | mu_filter_iconv_create (mu_stream_t *s, mu_stream_t transport, | ||
28 | const char *fromcode, const char *tocode, int flags, | ||
29 | enum mu_iconv_fallback_mode fallback_mode) | ||
30 | { | ||
31 | const char *argv[] = { "iconv", fromcode, tocode, NULL, NULL }; | ||
32 | |||
33 | switch (fallback_mode) | ||
34 | { | ||
35 | case mu_fallback_none: | ||
36 | argv[3] = "none"; | ||
37 | break; | ||
38 | |||
39 | case mu_fallback_copy_pass: | ||
40 | argv[3] = "copy-pass"; | ||
41 | break; | ||
42 | |||
43 | case mu_fallback_copy_octal: | ||
44 | argv[3] = "copy-octal"; | ||
45 | } | ||
46 | |||
47 | return mu_filter_create_args (s, transport, "iconv", 4, argv, | ||
48 | MU_FILTER_DECODE, MU_FILTER_READ); | ||
49 | } | ||
50 | |||
51 |
libmu_compat/tests/.gitignore
deleted
100644 → 0
libmu_compat/tests/Makefile.am
deleted
100644 → 0
1 | # This file is part of GNU Mailutils. | ||
2 | # Copyright (C) 2010-2012, 2014-2016 Free Software Foundation, Inc. | ||
3 | # | ||
4 | # GNU Mailutils is free software; you can redistribute it and/or | ||
5 | # modify it under the terms of the GNU General Public License as | ||
6 | # published by the Free Software Foundation; either version 3, or (at | ||
7 | # your option) any later version. | ||
8 | # | ||
9 | # GNU Mailutils is distributed in the hope that it will be useful, but | ||
10 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | # General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 | ||
18 | DISTCLEANFILES = atconfig $(check_SCRIPTS) | ||
19 | MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE) | ||
20 | |||
21 | ## ------------ ## | ||
22 | ## package.m4. ## | ||
23 | ## ------------ ## | ||
24 | |||
25 | $(srcdir)/package.m4: $(top_srcdir)/configure.ac | ||
26 | $(AM_V_GEN){ \ | ||
27 | echo '# Signature of the current package.'; \ | ||
28 | echo 'm4_define([AT_PACKAGE_NAME], [@PACKAGE_NAME@])'; \ | ||
29 | echo 'm4_define([AT_PACKAGE_TARNAME], [@PACKAGE_TARNAME@])'; \ | ||
30 | echo 'm4_define([AT_PACKAGE_VERSION], [@PACKAGE_VERSION@])'; \ | ||
31 | echo 'm4_define([AT_PACKAGE_STRING], [@PACKAGE_STRING@])'; \ | ||
32 | echo 'm4_define([AT_PACKAGE_BUGREPORT], [@PACKAGE_BUGREPORT@])'; \ | ||
33 | } >$(srcdir)/package.m4 | ||
34 | |||
35 | # | ||
36 | |||
37 | ## -------------------------- ## | ||
38 | ## Non-installable programs | ||
39 | ## -------------------------- ## | ||
40 | |||
41 | AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@ | ||
42 | noinst_PROGRAMS = argcv | ||
43 | |||
44 | LDADD = ../libmu_compat.la ${MU_LIB_MAILUTILS} | ||
45 | |||
46 | ## ------------ ## | ||
47 | ## Test suite. ## | ||
48 | ## ------------ ## | ||
49 | |||
50 | TESTSUITE_AT = \ | ||
51 | argcv.at\ | ||
52 | testsuite.at | ||
53 | |||
54 | TESTSUITE = $(srcdir)/testsuite | ||
55 | M4=m4 | ||
56 | |||
57 | AUTOTEST = $(AUTOM4TE) --language=autotest | ||
58 | $(TESTSUITE): package.m4 $(TESTSUITE_AT) $(top_srcdir)/testsuite/testsuite.inc | ||
59 | $(AM_V_GEN)$(AUTOTEST) -I $(srcdir) -I $(top_srcdir)/testsuite testsuite.at -o $@.tmp | ||
60 | $(AM_V_at)mv $@.tmp $@ | ||
61 | |||
62 | atconfig: $(top_builddir)/config.status | ||
63 | cd $(top_builddir) && ./config.status tests/$@ | ||
64 | |||
65 | clean-local: | ||
66 | @test ! -f $(TESTSUITE) || $(SHELL) $(TESTSUITE) --clean | ||
67 | |||
68 | check-local: atconfig atlocal $(TESTSUITE) | ||
69 | @$(SHELL) $(TESTSUITE) | ||
70 | |||
71 | # Run the test suite on the *installed* tree. | ||
72 | #installcheck-local: | ||
73 | # $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin | ||
74 | |||
75 |
libmu_compat/tests/argcv.at
deleted
100644 → 0
1 | # This file is part of GNU Mailutils. -*- Autotest -*- | ||
2 | # Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc. | ||
3 | # | ||
4 | # GNU Mailutils is free software; you can redistribute it and/or | ||
5 | # modify it under the terms of the GNU General Public License as | ||
6 | # published by the Free Software Foundation; either version 3, or (at | ||
7 | # your option) any later version. | ||
8 | # | ||
9 | # GNU Mailutils is distributed in the hope that it will be useful, but | ||
10 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | # General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | dnl ------------------------------------------------------------ | ||
18 | dnl TESTARGS([NAME], [KW = `'], [INPUT], [STDOUT = `'], | ||
19 | dnl [STDERR = `'], [RUN-IF-FAIL], [RUN-IF-PASS]) | ||
20 | dnl | ||
21 | m4_pushdef([TESTARGS],[ | ||
22 | m4_pushdef([MU_TEST_GROUP],[Argcv]) | ||
23 | m4_pushdef([MU_TEST_KEYWORDS],[argcv]) | ||
24 | m4_pushdef([MU_TEST_COMMAND],[argcv]) | ||
25 | |||
26 | AT_SETUP([Argcv: m4_if([$1],[],mu_firstline([$3]),[$1])]) | ||
27 | AT_KEYWORDS([argcv $2]) | ||
28 | AT_CHECK([ | ||
29 | AT_DATA([input],[$3 | ||
30 | ]) | ||
31 | argcv < input],[0],[$4],[$5],[$6],[$7]) | ||
32 | AT_CLEANUP | ||
33 | ]) | ||
34 | |||
35 | dnl ------------------------------------------------------------ | ||
36 | TESTARGS([simple input],[], | ||
37 | [1 2 3], | ||
38 | [3: 1 2 3 | ||
39 | ]) | ||
40 | |||
41 | TESTARGS([quoted space],[], | ||
42 | [quoted\ space], | ||
43 | [1: "quoted space" | ||
44 | ]) | ||
45 | |||
46 | TESTARGS([tab character],[], | ||
47 | [a "tab character"], | ||
48 | [2: a tab\tcharacter | ||
49 | ]) | ||
50 | |||
51 | TESTARGS([octal and hex escapes],[], | ||
52 | [\157\143\164\141\154\40and\x20\x68\x65\x78], | ||
53 | [1: "octal and hex" | ||
54 | ]) | ||
55 | |||
56 | TESTARGS([octal and hex escapes 2],[], | ||
57 | [\157\143\164\141\154\40 and \x20\x68\x65\x78], | ||
58 | [3: "octal " and " hex" | ||
59 | ]) | ||
60 | |||
61 | TESTARGS([escape representation],[], | ||
62 | [A\x3-\48\39], | ||
63 | [1: A\003-\0048\0039 | ||
64 | ]) | ||
65 | |||
66 | TESTARG([8-bit input],[], | ||
67 | [×ÅÒÈÎÑÑ ÐÏÌÏ×ÉÎÁ ÔÁÂÌÉÃÙ], | ||
68 | [3: \327\305\322\310\316\321\321 \320\317\314\317\327\311\316\301 \324\301\302\314\311\303\331]) | ||
69 | |||
70 | TESTARG([misquoted input],[], | ||
71 | [messed up'quotations ' in "a single'" "command" lin"e], | ||
72 | [6: messed "upquotations " in "a single'" command "lin\"e" | ||
73 | ]) | ||
74 | |||
75 | TESTARG([unbalanced quote],[], | ||
76 | ['unbalanced "quote], | ||
77 | [2: 'unbalanced "\"quote" | ||
78 | ]) | ||
79 | |||
80 | TESTARG([unbalanced quote 2],[], | ||
81 | [unbalanced "quote], | ||
82 | [2: unbalanced "\"quote" | ||
83 | ]) | ||
84 | |||
85 | TESTARG([unbalanced quote 3],[], | ||
86 | ["], | ||
87 | [1: "\"" | ||
88 | ]) | ||
89 | |||
90 | m4_popdef([TESTARGS]) | ||
91 | |||
92 | |||
93 | |||
94 | |||
95 |
libmu_compat/tests/argcv.c
deleted
100644 → 0
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2005, 2007, 2009-2012, 2014-2016 Free Software | ||
3 | Foundation, Inc. | ||
4 | |||
5 | GNU Mailutils is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 3, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | GNU Mailutils is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ | ||
17 | |||
18 | #ifdef HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | #include <errno.h> | ||
25 | #include <unistd.h> | ||
26 | #define MU_ARCGV_DEPRECATED | ||
27 | #include <mailutils/argcv.h> | ||
28 | #include <mailutils/errno.h> | ||
29 | |||
30 | int | ||
31 | main (int argc, char **argv) | ||
32 | { | ||
33 | char *delim = ""; | ||
34 | char *comment = "#"; | ||
35 | char buf[512]; | ||
36 | |||
37 | while (fgets (buf, sizeof buf, stdin)) | ||
38 | { | ||
39 | int status, c; | ||
40 | char **v; | ||
41 | char *s; | ||
42 | |||
43 | status = mu_argcv_get (buf, delim, comment, &c, &v); | ||
44 | if (status) | ||
45 | { | ||
46 | fprintf (stderr, "cannot parse: %s\n", mu_strerror (status)); | ||
47 | continue; | ||
48 | } | ||
49 | status = mu_argcv_string (c, v, &s); | ||
50 | if (status) | ||
51 | fprintf (stderr, "cannot create string: %s\n", mu_strerror (status)); | ||
52 | else | ||
53 | { | ||
54 | printf ("%d: %s\n", c, s); | ||
55 | free (s); | ||
56 | } | ||
57 | mu_argcv_free (c, v); | ||
58 | } | ||
59 | exit (0); | ||
60 | } |
libmu_compat/tests/atlocal.in
deleted
100644 → 0
libmu_compat/tests/testsuite.at
deleted
100644 → 0
1 | # This file is part of GNU Mailutils. -*- Autotest -*- | ||
2 | # Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc. | ||
3 | # | ||
4 | # GNU Mailutils is free software; you can redistribute it and/or | ||
5 | # modify it under the terms of the GNU General Public License as | ||
6 | # published by the Free Software Foundation; either version 3, or (at | ||
7 | # your option) any later version. | ||
8 | # | ||
9 | # GNU Mailutils is distributed in the hope that it will be useful, but | ||
10 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | # General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | m4_include([testsuite.inc]) | ||
18 | AT_INIT | ||
19 | m4_include([argcv.at]) |
libmu_compat/vartab.c
deleted
100644 → 0
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2007, 2010-2012, 2014-2016 Free Software Foundation, | ||
3 | Inc. | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 3 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General | ||
16 | Public License along with this library; If not, see | ||
17 | <http://www.gnu.org/licenses/>. */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | #include <config.h> | ||
21 | #endif | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | #include <mailutils/assoc.h> | ||
25 | #include <mailutils/stream.h> | ||
26 | #include <mailutils/errno.h> | ||
27 | #include <mailutils/iterator.h> | ||
28 | #define MU_SUPPRESS_DEPRECATION | ||
29 | #include <mailutils/vartab.h> | ||
30 | |||
31 | struct _mu_vartab | ||
32 | { | ||
33 | mu_assoc_t assoc; | ||
34 | mu_stream_t stream; | ||
35 | char *buf; | ||
36 | size_t bufsize; | ||
37 | }; | ||
38 | |||
39 | #define MU_VARDEFN_STATIC 0x1 | ||
40 | #define MU_VARDEFN_FUNC 0x2 | ||
41 | |||
42 | struct vardefn | ||
43 | { | ||
44 | int flags; | ||
45 | char *value; | ||
46 | mu_var_expansion_fp fun; | ||
47 | mu_var_free_fp free; | ||
48 | void *data; | ||
49 | }; | ||
50 | |||
51 | int | ||
52 | mu_vartab_create (mu_vartab_t *pvar) | ||
53 | { | ||
54 | int rc; | ||
55 | struct _mu_vartab *p = calloc (1, sizeof *p); | ||
56 | if (!p) | ||
57 | return ENOMEM; | ||
58 | rc = mu_assoc_create (&p->assoc, sizeof (struct vardefn), 0); | ||
59 | if (rc) | ||
60 | { | ||
61 | free (p); | ||
62 | return rc; | ||
63 | } | ||
64 | *pvar = p; | ||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | static void | ||
69 | vardefn_free (struct vardefn *vd) | ||
70 | { | ||
71 | if (vd->value) | ||
72 | { | ||
73 | if (vd->free) | ||
74 | vd->free (vd->data, vd->value); | ||
75 | else if (!(vd->flags & MU_VARDEFN_STATIC)) | ||
76 | free (vd->value); | ||
77 | } | ||
78 | memset (vd, 0, sizeof *vd); | ||
79 | } | ||
80 | |||
81 | int | ||
82 | mu_vartab_destroy (mu_vartab_t *pvar) | ||
83 | { | ||
84 | int rc; | ||
85 | mu_vartab_t var = *pvar; | ||
86 | mu_iterator_t itr; | ||
87 | |||
88 | if (!var) | ||
89 | return EINVAL; | ||
90 | rc = mu_assoc_get_iterator (var->assoc, &itr); | ||
91 | if (rc) | ||
92 | return rc; | ||
93 | for (mu_iterator_first (itr); !mu_iterator_is_done (itr); | ||
94 | mu_iterator_next (itr)) | ||
95 | { | ||
96 | struct vardefn *vd; | ||
97 | mu_iterator_current (itr, (void**)&vd); | ||
98 | vardefn_free (vd); | ||
99 | } | ||
100 | mu_iterator_destroy (&itr); | ||
101 | |||
102 | mu_assoc_destroy (&var->assoc); | ||
103 | mu_stream_destroy (&var->stream); | ||
104 | free (var->buf); | ||
105 | free (var); | ||
106 | *pvar = NULL; | ||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | int | ||
111 | mu_vartab_define (mu_vartab_t var, const char *name, const char *value, | ||
112 | int isstatic) | ||
113 | { | ||
114 | int rc; | ||
115 | struct vardefn *vd; | ||
116 | |||
117 | if (!var) | ||
118 | return EINVAL; | ||
119 | rc = mu_assoc_ref_install (var->assoc, name, (void **) &vd); | ||
120 | if (rc == MU_ERR_EXISTS) | ||
121 | vardefn_free (vd); | ||
122 | else if (rc != 0) | ||
123 | return rc; | ||
124 | |||
125 | if (isstatic) | ||
126 | { | ||
127 | vd->flags = MU_VARDEFN_STATIC; | ||
128 | vd->value = (char*) value; | ||
129 | } | ||
130 | else | ||
131 | { | ||
132 | vd->flags = 0; | ||
133 | vd->value = strdup (value); | ||
134 | if (!vd->value) | ||
135 | return ENOMEM; | ||
136 | } | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | int | ||
141 | mu_vartab_define_exp (mu_vartab_t var, const char *name, | ||
142 | mu_var_expansion_fp fun, mu_var_free_fp free, | ||
143 | void *data) | ||
144 | { | ||
145 | int rc; | ||
146 | struct vardefn *vd; | ||
147 | |||
148 | if (!var) | ||
149 | return EINVAL; | ||
150 | rc = mu_assoc_ref_install (var->assoc, name, (void **) &vd); | ||
151 | if (rc == MU_ERR_EXISTS) | ||
152 | vardefn_free (vd); | ||
153 | else if (rc != 0) | ||
154 | return rc; | ||
155 | |||
156 | vd->flags = MU_VARDEFN_FUNC; | ||
157 | vd->fun = fun; | ||
158 | vd->free = free; | ||
159 | vd->data = data; | ||
160 | return 0; | ||
161 | } | ||
162 | |||
163 | int | ||
164 | mu_vartab_count (mu_vartab_t vt, size_t *pcount) | ||
165 | { | ||
166 | if (!vt) | ||
167 | return EINVAL; | ||
168 | return mu_assoc_count (vt->assoc, pcount); | ||
169 | } | ||
170 | |||
171 | static int | ||
172 | vardefn_expand (const char *name, struct vardefn *vd, const char **pvalue) | ||
173 | { | ||
174 | if (!vd->value) | ||
175 | { | ||
176 | if (vd->fun) | ||
177 | { | ||
178 | int rc = vd->fun (name, vd->data, &vd->value); | ||
179 | if (rc) | ||
180 | return rc; | ||
181 | } | ||
182 | else | ||
183 | return EINVAL; | ||
184 | } | ||
185 | *pvalue = vd->value; | ||
186 | return 0; | ||
187 | } | ||
188 | |||
189 | int | ||
190 | mu_vartab_getvar (mu_vartab_t vt, const char *name, const char **pvalue) | ||
191 | { | ||
192 | struct vardefn *vdefn; | ||
193 | |||
194 | if (!vt) | ||
195 | return EINVAL; | ||
196 | vdefn = mu_assoc_ref (vt->assoc, name); | ||
197 | if (!vdefn) | ||
198 | return MU_ERR_NOENT; | ||
199 | return vardefn_expand (name, vdefn, pvalue); | ||
200 | } | ||
201 | |||
202 | static char * | ||
203 | copy_name (mu_vartab_t vt, const char *name, size_t len) | ||
204 | { | ||
205 | if (len + 1 > vt->bufsize) | ||
206 | { | ||
207 | char *p = realloc (vt->buf, len + 1); | ||
208 | if (!p) | ||
209 | return NULL; | ||
210 | vt->buf = p; | ||
211 | vt->bufsize = len + 1; | ||
212 | } | ||
213 | memcpy (vt->buf, name, len); | ||
214 | vt->buf[len] = 0; | ||
215 | return vt->buf; | ||
216 | } | ||
217 | |||
218 | int | ||
219 | mu_vartab_expand (mu_vartab_t vt, const char *str, char **pres) | ||
220 | { | ||
221 | int rc; | ||
222 | mu_off_t size; | ||
223 | const char *p; | ||
224 | |||
225 | if (!vt) | ||
226 | return EINVAL; | ||
227 | if (!vt->stream) | ||
228 | { | ||
229 | rc = mu_memory_stream_create (&vt->stream, 0); | ||
230 | if (rc) | ||
231 | return rc; | ||
232 | } | ||
233 | else | ||
234 | mu_stream_truncate (vt->stream, 0); | ||
235 | mu_stream_seek (vt->stream, 0, MU_SEEK_SET, NULL); | ||
236 | |||
237 | for (p = str; *p; ) | ||
238 | { | ||
239 | if (*p == '$') | ||
240 | { | ||
241 | switch (*++p) | ||
242 | { | ||
243 | case '$': | ||
244 | mu_stream_write (vt->stream, str, p - str, NULL); | ||
245 | str = p + 1; | ||
246 | p = str + 1; | ||
247 | break; | ||
248 | |||
249 | case '{': | ||
250 | { | ||
251 | const char *e = strchr (p + 1, '}'); | ||
252 | if (e) | ||
253 | { | ||
254 | const char *pvalue; | ||
255 | size_t len = e - p - 1; | ||
256 | char *name = copy_name (vt, p + 1, len); | ||
257 | rc = mu_vartab_getvar (vt, name, &pvalue); | ||
258 | if (rc == 0) | ||
259 | { | ||
260 | mu_stream_write (vt->stream, str, p - str - 1, NULL); | ||
261 | mu_stream_write (vt->stream, pvalue, strlen (pvalue), | ||
262 | NULL); | ||
263 | str = e + 1; | ||
264 | p = str + 1; | ||
265 | } | ||
266 | else if (rc == MU_ERR_NOENT) | ||
267 | p = e + 1; | ||
268 | else | ||
269 | return rc; | ||
270 | } | ||
271 | else | ||
272 | p++; | ||
273 | } | ||
274 | break; | ||
275 | |||
276 | default: | ||
277 | { | ||
278 | char *name = copy_name (vt, p, 1); | ||
279 | const char *pvalue; | ||
280 | rc = mu_vartab_getvar (vt, name, &pvalue); | ||
281 | if (rc == 0) | ||
282 | { | ||
283 | mu_stream_write (vt->stream, str, p - str - 1, NULL); | ||
284 | mu_stream_write (vt->stream, pvalue, strlen (pvalue), | ||
285 | NULL); | ||
286 | str = p + 1; | ||
287 | p = str + 1; | ||
288 | } | ||
289 | else if (rc == MU_ERR_NOENT) | ||
290 | p++; | ||
291 | else | ||
292 | return rc; | ||
293 | } | ||
294 | break; | ||
295 | } | ||
296 | } | ||
297 | else if (*p == '%') | ||
298 | { | ||
299 | /* allow `%' as prefix for single-character entities, for | ||
300 | compatibility with v. prior to 1.2.91 */ | ||
301 | if (*++p == '%') | ||
302 | { | ||
303 | mu_stream_write (vt->stream, str, p - str, NULL); | ||
304 | str = p + 1; | ||
305 | p = str + 1; | ||
306 | } | ||
307 | else | ||
308 | { | ||
309 | char *name = copy_name (vt, p, 1); | ||
310 | const char *pvalue; | ||
311 | rc = mu_vartab_getvar (vt, name, &pvalue); | ||
312 | if (rc == 0) | ||
313 | { | ||
314 | mu_stream_write (vt->stream, str, p - str - 1, NULL); | ||
315 | mu_stream_write (vt->stream, pvalue, strlen (pvalue), | ||
316 | NULL); | ||
317 | str = p + 1; | ||
318 | p = str + 1; | ||
319 | } | ||
320 | else if (rc == MU_ERR_NOENT) | ||
321 | p++; | ||
322 | else | ||
323 | return rc; | ||
324 | } | ||
325 | } | ||
326 | else | ||
327 | p++; | ||
328 | } | ||
329 | |||
330 | if (p > str) | ||
331 | mu_stream_write (vt->stream, str, p - str, NULL); | ||
332 | |||
333 | mu_stream_size (vt->stream, &size); | ||
334 | *pres = malloc (size + 1); | ||
335 | if (!*pres) | ||
336 | return ENOMEM; | ||
337 | mu_stream_seek (vt->stream, 0, MU_SEEK_SET, NULL); | ||
338 | mu_stream_read (vt->stream, *pres, size, NULL); | ||
339 | (*pres)[size] = 0; | ||
340 | return 0; | ||
341 | } | ||
342 | |||
343 | |||
344 | |||
345 | |||
346 | |||
347 | |||
348 |
... | @@ -411,7 +411,7 @@ run_metamail (const char *mailcap_cmd, mu_message_t mesg) | ... | @@ -411,7 +411,7 @@ run_metamail (const char *mailcap_cmd, mu_message_t mesg) |
411 | status = mu_message_get_streamref (mesg, &stream); | 411 | status = mu_message_get_streamref (mesg, &stream); |
412 | if (status) | 412 | if (status) |
413 | { | 413 | { |
414 | mu_error ("mu_message_get_stream: %s", mu_strerror (status)); | 414 | mu_error ("mu_message_get_streamref: %s", mu_strerror (status)); |
415 | break; | 415 | break; |
416 | } | 416 | } |
417 | 417 | ... | ... |
... | @@ -57,7 +57,6 @@ struct lib_descr { | ... | @@ -57,7 +57,6 @@ struct lib_descr { |
57 | #endif | 57 | #endif |
58 | { "mailer", "-lmu_mailer", 0 }, | 58 | { "mailer", "-lmu_mailer", 0 }, |
59 | { "sieve", "-lmu_sieve", 0, NOTALL }, | 59 | { "sieve", "-lmu_sieve", 0, NOTALL }, |
60 | { "compat", "-lmu_compat", 0 }, | ||
61 | { "auth", "-lmu_auth " AUTHLIBS, 2 }, | 60 | { "auth", "-lmu_auth " AUTHLIBS, 2 }, |
62 | #ifdef WITH_GUILE | 61 | #ifdef WITH_GUILE |
63 | { "guile", "-lmu_scm " GUILE_LIBS, -1, NOTALL }, | 62 | { "guile", "-lmu_scm " GUILE_LIBS, -1, NOTALL }, |
... | @@ -65,6 +64,7 @@ struct lib_descr { | ... | @@ -65,6 +64,7 @@ struct lib_descr { |
65 | #ifdef WITH_PYTHON | 64 | #ifdef WITH_PYTHON |
66 | { "python", "-lmu_py " PYTHON_LIBS, -1, NOTALL }, | 65 | { "python", "-lmu_py " PYTHON_LIBS, -1, NOTALL }, |
67 | #endif | 66 | #endif |
67 | { "compat", NULL, 0, 0 }, /* deprecated */ | ||
68 | { "cfg", NULL, 0, 0 }, /* deprecated */ | 68 | { "cfg", NULL, 0, 0 }, /* deprecated */ |
69 | { "argp", NULL, 0, 0 }, /* deprecated */ | 69 | { "argp", NULL, 0, 0 }, /* deprecated */ |
70 | { NULL } | 70 | { NULL } | ... | ... |
-
Please register or sign in to post a comment