Commit 1ba98c36 1ba98c365c5e5ce5cbc02a82054749a90a34c689 by Sergey Poznyakoff

Merge recent fixes from master

2 parents e4c393f9 263e2e9f
Showing 51 changed files with 433 additions and 95 deletions
...@@ -279,7 +279,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr, ...@@ -279,7 +279,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
279 size_t i; 279 size_t i;
280 size_t optlen; /* Length of the option in optstr */ 280 size_t optlen; /* Length of the option in optstr */
281 int found = 0; /* 1 if the match was found, 2 if option is ambiguous */ 281 int found = 0; /* 1 if the match was found, 2 if option is ambiguous */
282 enum neg_match neg; /* 1 if a boolean option is negated */ 282 int negated; /* 1 if a boolean option is negated */
283 struct mu_option *ret_opt = NULL; 283 struct mu_option *ret_opt = NULL;
284 struct mu_option *used_opt; 284 struct mu_option *used_opt;
285 285
...@@ -290,7 +290,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr, ...@@ -290,7 +290,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
290 size_t j = po->po_longidx[i]; 290 size_t j = po->po_longidx[i];
291 size_t len = strlen (po->po_optv[j]->opt_long); 291 size_t len = strlen (po->po_optv[j]->opt_long);
292 struct mu_option *opt = option_unalias (po, j); 292 struct mu_option *opt = option_unalias (po, j);
293 neg = neg_nomatch; 293 enum neg_match neg = neg_nomatch;
294 if ((optlen <= len 294 if ((optlen <= len
295 && memcmp (po->po_optv[j]->opt_long, optstr, optlen) == 0) 295 && memcmp (po->po_optv[j]->opt_long, optstr, optlen) == 0)
296 || (neg = negmatch (po, j, optstr, optlen))) 296 || (neg = negmatch (po, j, optstr, optlen)))
...@@ -301,6 +301,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr, ...@@ -301,6 +301,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
301 used_opt = po->po_optv[j]; 301 used_opt = po->po_optv[j];
302 ret_opt = opt; 302 ret_opt = opt;
303 found++; 303 found++;
304 negated = neg != neg_nomatch;
304 if (optlen == len || neg == neg_match_exact) 305 if (optlen == len || neg == neg_match_exact)
305 i = po->po_longcnt - 1; /* exact match: break the loop */ 306 i = po->po_longcnt - 1; /* exact match: break the loop */
306 break; 307 break;
...@@ -353,12 +354,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr, ...@@ -353,12 +354,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
353 ++optlen; 354 ++optlen;
354 *used_value = (char *)(optstr + optlen); 355 *used_value = (char *)(optstr + optlen);
355 if (ret_opt->opt_type == mu_c_bool) 356 if (ret_opt->opt_type == mu_c_bool)
356 { 357 *value = negated ? "0" : "1";
357 if (neg)
358 *value = "0";
359 else
360 *value = "1";
361 }
362 else 358 else
363 *value = NULL; 359 *value = NULL;
364 return ret_opt; 360 return ret_opt;
......
...@@ -145,6 +145,7 @@ TESTSUITE_AT = \ ...@@ -145,6 +145,7 @@ TESTSUITE_AT = \
145 parseopt25.at\ 145 parseopt25.at\
146 parseopt26.at\ 146 parseopt26.at\
147 parseopt27.at\ 147 parseopt27.at\
148 parseopt28.at\
148 parseopt_help00.at\ 149 parseopt_help00.at\
149 parseopt_help01.at\ 150 parseopt_help01.at\
150 parseopt_help02.at\ 151 parseopt_help02.at\
......
...@@ -26,6 +26,7 @@ char *find_value; ...@@ -26,6 +26,7 @@ char *find_value;
26 int jobs = 0; 26 int jobs = 0;
27 int x_option; 27 int x_option;
28 int a_option; 28 int a_option;
29 int headers_option = 1;
29 int d_option; 30 int d_option;
30 int debug_level_value; 31 int debug_level_value;
31 char *debug_info_value; 32 char *debug_info_value;
...@@ -46,6 +47,9 @@ struct mu_option group_a[] = { ...@@ -46,6 +47,9 @@ struct mu_option group_a[] = {
46 "no arguments to this one", 47 "no arguments to this one",
47 mu_c_bool, &a_option }, 48 mu_c_bool, &a_option },
48 { "debug-all", 0, NULL, MU_OPTION_ALIAS }, 49 { "debug-all", 0, NULL, MU_OPTION_ALIAS },
50 { "headers", 0, NULL, MU_OPTION_DEFAULT,
51 "show headers",
52 mu_c_bool, &headers_option },
49 MU_OPTION_END 53 MU_OPTION_END
50 }; 54 };
51 55
...@@ -218,6 +222,7 @@ main (int argc, char *argv[]) ...@@ -218,6 +222,7 @@ main (int argc, char *argv[])
218 printf ("opt_value=%s\n", S(opt_value)); 222 printf ("opt_value=%s\n", S(opt_value));
219 printf ("x_option=%d\n", x_option); 223 printf ("x_option=%d\n", x_option);
220 printf ("a_option=%d\n", a_option); 224 printf ("a_option=%d\n", a_option);
225 printf ("headers_option=%d\n", headers_option);
221 printf ("find_value=%s\n", S(find_value)); 226 printf ("find_value=%s\n", S(find_value));
222 printf ("d_option=%d\n", d_option); 227 printf ("d_option=%d\n", d_option);
223 printf ("jobs=%d\n", jobs); 228 printf ("jobs=%d\n", jobs);
......
...@@ -26,6 +26,7 @@ file_name=(null) ...@@ -26,6 +26,7 @@ file_name=(null)
26 opt_value=initial 26 opt_value=initial
27 x_option=0 27 x_option=0
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=0 31 d_option=0
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=(null) ...@@ -26,6 +26,7 @@ file_name=(null)
26 opt_value=initial 26 opt_value=initial
27 x_option=0 27 x_option=0
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=0 31 d_option=0
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=file ...@@ -26,6 +26,7 @@ file_name=file
26 opt_value=initial 26 opt_value=initial
27 x_option=1 27 x_option=1
28 a_option=1 28 a_option=1
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=1 31 d_option=1
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=file ...@@ -26,6 +26,7 @@ file_name=file
26 opt_value=initial 26 opt_value=initial
27 x_option=1 27 x_option=1
28 a_option=1 28 a_option=1
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=1 31 d_option=1
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=(null) ...@@ -26,6 +26,7 @@ file_name=(null)
26 opt_value=file 26 opt_value=file
27 x_option=0 27 x_option=0
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=0 31 d_option=0
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=(null) ...@@ -26,6 +26,7 @@ file_name=(null)
26 opt_value=(null) 26 opt_value=(null)
27 x_option=0 27 x_option=0
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=0 31 d_option=0
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=(null) ...@@ -26,6 +26,7 @@ file_name=(null)
26 opt_value=initial 26 opt_value=initial
27 x_option=0 27 x_option=0
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=2 31 d_option=2
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=file ...@@ -26,6 +26,7 @@ file_name=file
26 opt_value=10 26 opt_value=10
27 x_option=1 27 x_option=1
28 a_option=1 28 a_option=1
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=2 31 d_option=2
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=file ...@@ -26,6 +26,7 @@ file_name=file
26 opt_value=initial 26 opt_value=initial
27 x_option=0 27 x_option=0
28 a_option=1 28 a_option=1
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=0 31 d_option=0
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=file ...@@ -26,6 +26,7 @@ file_name=file
26 opt_value=initial 26 opt_value=initial
27 x_option=0 27 x_option=0
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=0 31 d_option=0
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=(null) ...@@ -26,6 +26,7 @@ file_name=(null)
26 opt_value=file 26 opt_value=file
27 x_option=0 27 x_option=0
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=0 31 d_option=0
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=(null) ...@@ -26,6 +26,7 @@ file_name=(null)
26 opt_value=(null) 26 opt_value=(null)
27 x_option=0 27 x_option=0
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=0 31 d_option=0
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=(null) ...@@ -26,6 +26,7 @@ file_name=(null)
26 opt_value=initial 26 opt_value=initial
27 x_option=0 27 x_option=0
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=2 31 d_option=2
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=file ...@@ -26,6 +26,7 @@ file_name=file
26 opt_value=initial 26 opt_value=initial
27 x_option=0 27 x_option=0
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=Word 30 find_value=Word
30 d_option=0 31 d_option=0
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=filename ...@@ -26,6 +26,7 @@ file_name=filename
26 opt_value=(null) 26 opt_value=(null)
27 x_option=1 27 x_option=1
28 a_option=1 28 a_option=1
29 headers_option=1
29 find_value=word 30 find_value=word
30 d_option=0 31 d_option=0
31 jobs=10 32 jobs=10
......
...@@ -26,6 +26,7 @@ file_name=(null) ...@@ -26,6 +26,7 @@ file_name=(null)
26 opt_value=initial 26 opt_value=initial
27 x_option=0 27 x_option=0
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=3 31 d_option=3
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=file ...@@ -26,6 +26,7 @@ file_name=file
26 opt_value=(null) 26 opt_value=(null)
27 x_option=1 27 x_option=1
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=0 31 d_option=0
31 jobs=0 32 jobs=0
...@@ -48,6 +49,7 @@ file_name=file ...@@ -48,6 +49,7 @@ file_name=file
48 opt_value=(null) 49 opt_value=(null)
49 x_option=1 50 x_option=1
50 a_option=0 51 a_option=0
52 headers_option=1
51 find_value=(null) 53 find_value=(null)
52 d_option=0 54 d_option=0
53 jobs=0 55 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=foobar ...@@ -26,6 +26,7 @@ file_name=foobar
26 opt_value=initial 26 opt_value=initial
27 x_option=1 27 x_option=1
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=0 31 d_option=0
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=foobar ...@@ -26,6 +26,7 @@ file_name=foobar
26 opt_value=initial 26 opt_value=initial
27 x_option=1 27 x_option=1
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=0 31 d_option=0
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=filename ...@@ -26,6 +26,7 @@ file_name=filename
26 opt_value=initial 26 opt_value=initial
27 x_option=0 27 x_option=0
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=0 31 d_option=0
31 jobs=0 32 jobs=0
......
...@@ -26,6 +26,7 @@ file_name=(null) ...@@ -26,6 +26,7 @@ file_name=(null)
26 opt_value=initial 26 opt_value=initial
27 x_option=0 27 x_option=0
28 a_option=0 28 a_option=0
29 headers_option=1
29 find_value=(null) 30 find_value=(null)
30 d_option=0 31 d_option=0
31 jobs=0 32 jobs=0
......
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2017 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 AT_SETUP([boolean negation])
18 AT_KEYWORDS([parseopt parseopt_bool parseopt28])
19 AT_CHECK([
20 PARSEOPT_DEFAULT
21 MU_PARSEOPT_NEGATION=no-
22 export MU_PARSEOPT_NEGATION
23 echo "# full option"
24 parseopt --no-headers
25 echo "# abbreviated option"
26 parseopt --no-header
27 ],
28 [0],
29 [# full option
30 rc=0
31 file_name=(null)
32 opt_value=initial
33 x_option=0
34 a_option=0
35 headers_option=0
36 find_value=(null)
37 d_option=0
38 jobs=0
39 debug_level_value=0
40 debug_info_value=(null)
41 argv:
42 # abbreviated option
43 rc=0
44 file_name=(null)
45 opt_value=initial
46 x_option=0
47 a_option=0
48 headers_option=0
49 find_value=(null)
50 d_option=0
51 jobs=0
52 debug_level_value=0
53 debug_info_value=(null)
54 argv:
55 ])
56 AT_CLEANUP
...@@ -26,6 +26,7 @@ parseopt --help ...@@ -26,6 +26,7 @@ parseopt --help
26 Group A 26 Group A
27 -a, --all, --debug-all no arguments to this one 27 -a, --all, --debug-all no arguments to this one
28 -f, --file=FILE set file name 28 -f, --file=FILE set file name
29 --headers show headers
29 -o, --optional[=FILE] optional argument 30 -o, --optional[=FILE] optional argument
30 -x short-only option 31 -x short-only option
31 32
......
...@@ -23,7 +23,7 @@ parseopt --usage ...@@ -23,7 +23,7 @@ parseopt --usage
23 [0], 23 [0],
24 [[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N] [-o[FILE]] [--all] 24 [[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N] [-o[FILE]] [--all]
25 [--debug] [--debug-all] [--debug-info=S] [--debug-level=NUM] 25 [--debug] [--debug-all] [--debug-info=S] [--debug-level=NUM]
26 [--file=FILE] [--find=VALUE] [--help] [--jobs=N] 26 [--file=FILE] [--find=VALUE] [--headers] [--help] [--jobs=N]
27 [--optional[=FILE]] [--usage] [--verbose] 27 [--optional[=FILE]] [--usage] [--verbose]
28 ]]) 28 ]])
29 AT_CLEANUP 29 AT_CLEANUP
......
...@@ -26,6 +26,7 @@ MU_PARSEOPT_PROG_NAME=newname parseopt --help ...@@ -26,6 +26,7 @@ MU_PARSEOPT_PROG_NAME=newname parseopt --help
26 Group A 26 Group A
27 -a, --all, --debug-all no arguments to this one 27 -a, --all, --debug-all no arguments to this one
28 -f, --file=FILE set file name 28 -f, --file=FILE set file name
29 --headers show headers
29 -o, --optional[=FILE] optional argument 30 -o, --optional[=FILE] optional argument
30 -x short-only option 31 -x short-only option
31 32
......
...@@ -27,6 +27,7 @@ Tests option parsing ...@@ -27,6 +27,7 @@ Tests option parsing
27 Group A 27 Group A
28 -a, --all, --debug-all no arguments to this one 28 -a, --all, --debug-all no arguments to this one
29 -f, --file=FILE set file name 29 -f, --file=FILE set file name
30 --headers show headers
30 -o, --optional[=FILE] optional argument 31 -o, --optional[=FILE] optional argument
31 -x short-only option 32 -x short-only option
32 33
......
...@@ -26,6 +26,7 @@ MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS" parseopt --help ...@@ -26,6 +26,7 @@ MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS" parseopt --help
26 Group A 26 Group A
27 -a, --all, --debug-all no arguments to this one 27 -a, --all, --debug-all no arguments to this one
28 -f, --file=FILE set file name 28 -f, --file=FILE set file name
29 --headers show headers
29 -o, --optional[[=FILE]] optional argument 30 -o, --optional[[=FILE]] optional argument
30 -x short-only option 31 -x short-only option
31 32
......
...@@ -26,6 +26,7 @@ MU_PARSEOPT_BUG_ADDRESS='gray@gnu.org' parseopt --help ...@@ -26,6 +26,7 @@ MU_PARSEOPT_BUG_ADDRESS='gray@gnu.org' parseopt --help
26 Group A 26 Group A
27 -a, --all, --debug-all no arguments to this one 27 -a, --all, --debug-all no arguments to this one
28 -f, --file=FILE set file name 28 -f, --file=FILE set file name
29 --headers show headers
29 -o, --optional[[=FILE]] optional argument 30 -o, --optional[[=FILE]] optional argument
30 -x short-only option 31 -x short-only option
31 32
......
...@@ -26,6 +26,7 @@ MU_PARSEOPT_PACKAGE_NAME='GNU Mailutils' MU_PARSEOPT_PACKAGE_URL='http://mailuti ...@@ -26,6 +26,7 @@ MU_PARSEOPT_PACKAGE_NAME='GNU Mailutils' MU_PARSEOPT_PACKAGE_URL='http://mailuti
26 Group A 26 Group A
27 -a, --all, --debug-all no arguments to this one 27 -a, --all, --debug-all no arguments to this one
28 -f, --file=FILE set file name 28 -f, --file=FILE set file name
29 --headers show headers
29 -o, --optional[=FILE] optional argument 30 -o, --optional[=FILE] optional argument
30 -x short-only option 31 -x short-only option
31 32
......
...@@ -33,6 +33,7 @@ Tests option parsing ...@@ -33,6 +33,7 @@ Tests option parsing
33 Group A 33 Group A
34 -a, --all, --debug-all no arguments to this one 34 -a, --all, --debug-all no arguments to this one
35 -f, --file=FILE set file name 35 -f, --file=FILE set file name
36 --headers show headers
36 -o, --optional[=FILE] optional argument 37 -o, --optional[=FILE] optional argument
37 -x short-only option 38 -x short-only option
38 39
......
...@@ -27,6 +27,7 @@ ARGP_HELP_FMT=dup-args,no-dup-args-note,short-opt-col=1,opt-doc-col=32,header-co ...@@ -27,6 +27,7 @@ ARGP_HELP_FMT=dup-args,no-dup-args-note,short-opt-col=1,opt-doc-col=32,header-co
27 Group A 27 Group A
28 -a, --all, --debug-all no arguments to this one 28 -a, --all, --debug-all no arguments to this one
29 -f FILE, --file=FILE set file name 29 -f FILE, --file=FILE set file name
30 --headers show headers
30 -o[FILE], --optional[=FILE] optional argument 31 -o[FILE], --optional[=FILE] optional argument
31 -x short-only option 32 -x short-only option
32 33
......
...@@ -24,7 +24,7 @@ ARGP_HELP_FMT=rmargin=62,usage-indent=1\ ...@@ -24,7 +24,7 @@ ARGP_HELP_FMT=rmargin=62,usage-indent=1\
24 [0], 24 [0],
25 [[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N] 25 [[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N]
26 [-o[FILE]] [--all] [--debug] [--debug-all] [--debug-info=S] 26 [-o[FILE]] [--all] [--debug] [--debug-all] [--debug-info=S]
27 [--debug-level=NUM] [--file=FILE] [--find=VALUE] [--help] 27 [--debug-level=NUM] [--file=FILE] [--find=VALUE] [--headers]
28 [--jobs=N] [--optional[=FILE]] [--usage] [--verbose] 28 [--help] [--jobs=N] [--optional[=FILE]] [--usage] [--verbose]
29 ]]) 29 ]])
30 AT_CLEANUP 30 AT_CLEANUP
......
...@@ -23,7 +23,7 @@ MU_PARSEOPT_VERSION_HOOK=1 parseopt --usage ...@@ -23,7 +23,7 @@ MU_PARSEOPT_VERSION_HOOK=1 parseopt --usage
23 [0], 23 [0],
24 [[Usage: parseopt [-advVx?] [-f FILE] [-F VALUE] [-j N] [-o[FILE]] [--all] 24 [[Usage: parseopt [-advVx?] [-f FILE] [-F VALUE] [-j N] [-o[FILE]] [--all]
25 [--debug] [--debug-all] [--debug-info=S] [--debug-level=NUM] 25 [--debug] [--debug-all] [--debug-info=S] [--debug-level=NUM]
26 [--file=FILE] [--find=VALUE] [--help] [--jobs=N] 26 [--file=FILE] [--find=VALUE] [--headers] [--help] [--jobs=N]
27 [--optional[=FILE]] [--usage] [--verbose] [--version] 27 [--optional[=FILE]] [--usage] [--verbose] [--version]
28 ]]) 28 ]])
29 AT_CLEANUP 29 AT_CLEANUP
......
...@@ -26,6 +26,7 @@ MU_PARSEOPT_VERSION_HOOK=1 parseopt --help ...@@ -26,6 +26,7 @@ MU_PARSEOPT_VERSION_HOOK=1 parseopt --help
26 Group A 26 Group A
27 -a, --all, --debug-all no arguments to this one 27 -a, --all, --debug-all no arguments to this one
28 -f, --file=FILE set file name 28 -f, --file=FILE set file name
29 --headers show headers
29 -o, --optional[=FILE] optional argument 30 -o, --optional[=FILE] optional argument
30 -x short-only option 31 -x short-only option
31 32
......
...@@ -28,6 +28,7 @@ MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS|ALTERNATIVE ARGS|ANOTHER ARGS" parseopt -- ...@@ -28,6 +28,7 @@ MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS|ALTERNATIVE ARGS|ANOTHER ARGS" parseopt --
28 Group A 28 Group A
29 -a, --all, --debug-all no arguments to this one 29 -a, --all, --debug-all no arguments to this one
30 -f, --file=FILE set file name 30 -f, --file=FILE set file name
31 --headers show headers
31 -o, --optional[[=FILE]] optional argument 32 -o, --optional[[=FILE]] optional argument
32 -x short-only option 33 -x short-only option
33 34
......
...@@ -131,6 +131,7 @@ m4_include([parseopt24.at]) ...@@ -131,6 +131,7 @@ m4_include([parseopt24.at])
131 m4_include([parseopt25.at]) 131 m4_include([parseopt25.at])
132 m4_include([parseopt26.at]) 132 m4_include([parseopt26.at])
133 m4_include([parseopt27.at]) 133 m4_include([parseopt27.at])
134 m4_include([parseopt28.at])
134 135
135 AT_BANNER([Command line help output]) 136 AT_BANNER([Command line help output])
136 m4_include([parseopt_help00.at]) 137 m4_include([parseopt_help00.at])
......
...@@ -210,13 +210,14 @@ struct mh_whatnow_env /* whatnow shell environment */ ...@@ -210,13 +210,14 @@ struct mh_whatnow_env /* whatnow shell environment */
210 char *file; /* The file being processed */ 210 char *file; /* The file being processed */
211 char *msg; /* File name of the original message (if any) */ 211 char *msg; /* File name of the original message (if any) */
212 char *draftfile; /* File to preserve the draft into */ 212 char *draftfile; /* File to preserve the draft into */
213 const char *editor; 213 const char *editor; /* Default editor */
214 char *prompt; 214 char *prompt;
215 char *anno_field; /* Annotate field to be used */ 215 char *anno_field; /* Annotate field to be used */
216 mu_list_t anno_list; /* List of messages (mu_message_t) to annotate */ 216 mu_list_t anno_list; /* List of messages (mu_message_t) to annotate */
217 mu_mailbox_t mbox; 217 mu_mailbox_t mbox;
218 int nowhatnowproc; 218 int nowhatnowproc;
219 int reedit:1; /* Set if the editor was already invoked */ 219 int reedit:1; /* Set if the editor was already invoked */
220 char *last_ed; /* Last used editor */
220 }; 221 };
221 222
222 #define DISP_QUIT 0 223 #define DISP_QUIT 0
......
...@@ -324,6 +324,9 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab) ...@@ -324,6 +324,9 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab)
324 struct mu_wordsplit ws; 324 struct mu_wordsplit ws;
325 int wsflags = MU_WRDSF_DEFFLAGS|MU_WRDSF_COMMENT; 325 int wsflags = MU_WRDSF_DEFFLAGS|MU_WRDSF_COMMENT;
326 326
327 wh->reedit = 0;
328 wh->last_ed = NULL;
329
327 do 330 do
328 { 331 {
329 size_t n; 332 size_t n;
...@@ -360,6 +363,8 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab) ...@@ -360,6 +363,8 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab)
360 while (rc == 0); 363 while (rc == 0);
361 if (wsflags & MU_WRDSF_REUSE) 364 if (wsflags & MU_WRDSF_REUSE)
362 mu_wordsplit_free (&ws); 365 mu_wordsplit_free (&ws);
366 free (wh->last_ed);
367 wh->last_ed = NULL;
363 free (line); 368 free (line);
364 return status; 369 return status;
365 } 370 }
...@@ -382,8 +387,9 @@ display (struct mh_whatnow_env *wh, int argc, char **argv, int *status) ...@@ -382,8 +387,9 @@ display (struct mh_whatnow_env *wh, int argc, char **argv, int *status)
382 static int 387 static int
383 edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs) 388 edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs)
384 { 389 {
385 char const *ed = wh->editor; 390 char const *ed = wh->last_ed ? wh->last_ed : wh->editor;
386 int i, rc, status; 391 int i, rc, status;
392 char *p;
387 393
388 if (wh->reedit) 394 if (wh->reedit)
389 { 395 {
...@@ -456,7 +462,9 @@ edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs) ...@@ -456,7 +462,9 @@ edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs)
456 mu_error (_("problems with edit")); 462 mu_error (_("problems with edit"));
457 } 463 }
458 464
459 wh->editor = ed; 465 p = mu_strdup (ed);
466 free (wh->last_ed);
467 wh->last_ed = p;
460 wh->reedit = 1; 468 wh->reedit = 1;
461 469
462 return 0; 470 return 0;
......
...@@ -3,10 +3,8 @@ ...@@ -3,10 +3,8 @@
3 # Copyright (C) 2004, 2010-2012, 2014-2017 Free Software Foundation, 3 # Copyright (C) 2004, 2010-2012, 2014-2017 Free Software Foundation,
4 # Inc. 4 # Inc.
5 5
6 PATH=@abs_builddir@:@abs_top_builddir@/mh:$top_srcdir:$srcdir:$PATH 6 PATH=@abs_builddir@:@abs_top_builddir@/testsuite:@abs_top_builddir@/mh:$top_srcdir:$srcdir:$PATH
7 remove_curdir() { 7
8 sed "s|$HOME/*||;s| *$||" $*
9 }
10 # mimeflt [FILE] 8 # mimeflt [FILE]
11 # Filter out all variable information from a MIME message in FILE. 9 # Filter out all variable information from a MIME message in FILE.
12 # If FILE is not given, filter stdin. 10 # If FILE is not given, filter stdin.
......
...@@ -19,7 +19,7 @@ m4_pushdef([MH_KEYWORDS],[comp]) ...@@ -19,7 +19,7 @@ m4_pushdef([MH_KEYWORDS],[comp])
19 m4_pushdef([compcmd],[comp -editor $abs_top_srcdir/mh/tests/mhed]) 19 m4_pushdef([compcmd],[comp -editor $abs_top_srcdir/mh/tests/mhed])
20 20
21 MH_CHECK([comp -file],[comp00 comp-file],[ 21 MH_CHECK([comp -file],[comp00 comp-file],[
22 echo quit | compcmd -file ./infile | remove_curdir | sed 's/ *$//' 22 echo quit | compcmd -file $HOME/infile | cwdrepl | sed 's/ *$//'
23 sed 's/ *$//' infile 23 sed 's/ *$//' infile
24 ], 24 ],
25 [0], 25 [0],
...@@ -39,7 +39,7 @@ Seen by mhed ...@@ -39,7 +39,7 @@ Seen by mhed
39 ]) 39 ])
40 40
41 MH_CHECK([comp -file (del)],[comp01 comp-file_del],[ 41 MH_CHECK([comp -file (del)],[comp01 comp-file_del],[
42 echo 'quit -delete' | compcmd -file ./infile | remove_curdir 42 echo 'quit -delete' | compcmd -file $HOME/infile | cwdrepl | sed 's/ *$//'
43 ], 43 ],
44 [0], 44 [0],
45 [-- Editor invocation: ./infile 45 [-- Editor invocation: ./infile
...@@ -53,18 +53,18 @@ What now? ...@@ -53,18 +53,18 @@ What now?
53 ]) 53 ])
54 54
55 MH_CHECK([comp file],[comp02 comp_file],[ 55 MH_CHECK([comp file],[comp02 comp_file],[
56 echo 'quit' | compcmd file | remove_curdir | sed 's/ *$//' 56 echo 'quit' | compcmd file | cwdrepl | sed 's/ *$//'
57 sed 's/ *$//' Mail/file 57 sed 's/ *$//' Mail/file
58 ], 58 ],
59 [0], 59 [0],
60 [-- Editor invocation: Mail/file 60 [-- Editor invocation: ./Mail/file
61 -- Input file: 61 -- Input file:
62 To: 62 To:
63 cc: 63 cc:
64 Subject: 64 Subject:
65 -------- 65 --------
66 -- Input file end 66 -- Input file end
67 What now? draft left on "Mail/file". 67 What now? draft left on "./Mail/file".
68 To: 68 To:
69 cc: 69 cc:
70 Subject: 70 Subject:
...@@ -80,11 +80,11 @@ Subject: test input ...@@ -80,11 +80,11 @@ Subject: test input
80 message body 80 message body
81 ]) 81 ])
82 82
83 echo 'quit' | compcmd -use file | remove_curdir | sed 's/ *$//' 83 echo 'quit' | compcmd -use file | cwdrepl | sed 's/ *$//'
84 sed 's/ *$//' Mail/file 84 sed 's/ *$//' Mail/file
85 ], 85 ],
86 [0], 86 [0],
87 [-- Editor invocation: Mail/file 87 [-- Editor invocation: ./Mail/file
88 -- Input file: 88 -- Input file:
89 From: gray 89 From: gray
90 To: root 90 To: root
...@@ -92,7 +92,7 @@ Subject: test input ...@@ -92,7 +92,7 @@ Subject: test input
92 92
93 message body 93 message body
94 -- Input file end 94 -- Input file end
95 What now? draft left on "Mail/file". 95 What now? draft left on "./Mail/file".
96 From: gray 96 From: gray
97 To: root 97 To: root
98 Subject: test input 98 Subject: test input
...@@ -110,14 +110,14 @@ Subject: test input ...@@ -110,14 +110,14 @@ Subject: test input
110 message body 110 message body
111 ]) 111 ])
112 112
113 echo 'quit' | compcmd +inbox 1 | remove_curdir | sed 's/ *$//' 113 echo 'quit' | compcmd +inbox 1 | cwdrepl | sed 's/ *$//'
114 echo Mail/draft 114 echo Mail/draft
115 sed 's/ *$//' Mail/draft 115 sed 's/ *$//' Mail/draft
116 echo Message 116 echo Message
117 sed 's/ *$//' Mail/inbox/1 117 sed 's/ *$//' Mail/inbox/1
118 ], 118 ],
119 [0], 119 [0],
120 [-- Editor invocation: Mail/draft 120 [-- Editor invocation: ./Mail/draft
121 -- Input file: 121 -- Input file:
122 From: gray 122 From: gray
123 To: root 123 To: root
...@@ -125,7 +125,7 @@ Subject: test input ...@@ -125,7 +125,7 @@ Subject: test input
125 125
126 message body 126 message body
127 -- Input file end 127 -- Input file end
128 What now? draft left on "Mail/draft". 128 What now? draft left on "./Mail/draft".
129 Mail/draft 129 Mail/draft
130 From: gray 130 From: gray
131 To: root 131 To: root
...@@ -143,18 +143,18 @@ message body ...@@ -143,18 +143,18 @@ message body
143 143
144 MH_CHECK([comp -draftfolder],[comp05 comp-draftfolder draftfolder],[ 144 MH_CHECK([comp -draftfolder],[comp05 comp-draftfolder draftfolder],[
145 mkdir Mail/drafts 145 mkdir Mail/drafts
146 echo 'quit' | compcmd -draftfolder drafts | remove_curdir | sed 's/ *$//' 146 echo 'quit' | compcmd -draftfolder drafts | cwdrepl | sed 's/ *$//'
147 sed 's/ *$//' Mail/drafts/1 147 sed 's/ *$//' Mail/drafts/1
148 ], 148 ],
149 [0], 149 [0],
150 [-- Editor invocation: Mail/drafts/1 150 [-- Editor invocation: ./Mail/drafts/1
151 -- Input file: 151 -- Input file:
152 To: 152 To:
153 cc: 153 cc:
154 Subject: 154 Subject:
155 -------- 155 --------
156 -- Input file end 156 -- Input file end
157 What now? draft left on "Mail/drafts/1". 157 What now? draft left on "./Mail/drafts/1".
158 To: 158 To:
159 cc: 159 cc:
160 Subject: 160 Subject:
...@@ -172,11 +172,11 @@ message body ...@@ -172,11 +172,11 @@ message body
172 ]) 172 ])
173 echo "cur: 1" > Mail/drafts/.mh_sequences 173 echo "cur: 1" > Mail/drafts/.mh_sequences
174 174
175 echo 'quit' | compcmd -draftfolder drafts -use| remove_curdir | sed 's/ *$//' 175 echo 'quit' | compcmd -draftfolder drafts -use| cwdrepl | sed 's/ *$//'
176 sed 's/ *$//' Mail/drafts/1 176 sed 's/ *$//' Mail/drafts/1
177 ], 177 ],
178 [0], 178 [0],
179 [-- Editor invocation: Mail/drafts/1 179 [-- Editor invocation: ./Mail/drafts/1
180 -- Input file: 180 -- Input file:
181 From: gray 181 From: gray
182 To: root 182 To: root
...@@ -184,7 +184,7 @@ Subject: test input ...@@ -184,7 +184,7 @@ Subject: test input
184 184
185 message body 185 message body
186 -- Input file end 186 -- Input file end
187 What now? draft left on "Mail/drafts/1". 187 What now? draft left on "./Mail/drafts/1".
188 From: gray 188 From: gray
189 To: root 189 To: root
190 Subject: test input 190 Subject: test input
......
...@@ -27,7 +27,7 @@ Subject: test input ...@@ -27,7 +27,7 @@ Subject: test input
27 message body 27 message body
28 ]) 28 ])
29 29
30 echo quit | forwcmd +inbox 1 | remove_curdir 30 echo quit | forwcmd +inbox 1 | cwdrepl
31 echo == Mail/draft == 31 echo == Mail/draft ==
32 cat Mail/draft 32 cat Mail/draft
33 echo == Message == 33 echo == Message ==
...@@ -36,7 +36,7 @@ echo == Message == ...@@ -36,7 +36,7 @@ echo == Message ==
36 sed '/^X-IMAPbase/d' Mail/inbox/1 36 sed '/^X-IMAPbase/d' Mail/inbox/1
37 ], 37 ],
38 [0], 38 [0],
39 [-- Editor invocation: Mail/draft 39 [-- Editor invocation: ./Mail/draft
40 -- Input file: 40 -- Input file:
41 To: 41 To:
42 cc: 42 cc:
...@@ -53,7 +53,7 @@ message body ...@@ -53,7 +53,7 @@ message body
53 ------- End of Forwarded message 53 ------- End of Forwarded message
54 54
55 -- Input file end 55 -- Input file end
56 What now? draft left on "Mail/draft". 56 What now? draft left on "./Mail/draft".
57 == Mail/draft == 57 == Mail/draft ==
58 To: 58 To:
59 cc: 59 cc:
...@@ -87,7 +87,7 @@ Subject: test input ...@@ -87,7 +87,7 @@ Subject: test input
87 message body 87 message body
88 ]) 88 ])
89 89
90 echo quit | forwcmd -format +inbox 1 | remove_curdir 90 echo quit | forwcmd -format +inbox 1 | cwdrepl
91 echo == Mail/draft == 91 echo == Mail/draft ==
92 cat Mail/draft 92 cat Mail/draft
93 echo == Message == 93 echo == Message ==
...@@ -96,7 +96,7 @@ echo == Message == ...@@ -96,7 +96,7 @@ echo == Message ==
96 sed '/^X-IMAPbase/d' Mail/inbox/1 96 sed '/^X-IMAPbase/d' Mail/inbox/1
97 ], 97 ],
98 [0], 98 [0],
99 [-- Editor invocation: Mail/draft 99 [-- Editor invocation: ./Mail/draft
100 -- Input file: 100 -- Input file:
101 To: 101 To:
102 cc: 102 cc:
...@@ -113,7 +113,7 @@ message body ...@@ -113,7 +113,7 @@ message body
113 ------- End of Forwarded message 113 ------- End of Forwarded message
114 114
115 -- Input file end 115 -- Input file end
116 What now? draft left on "Mail/draft". 116 What now? draft left on "./Mail/draft".
117 == Mail/draft == 117 == Mail/draft ==
118 To: 118 To:
119 cc: 119 cc:
...@@ -153,7 +153,7 @@ Subject: 2nd message ...@@ -153,7 +153,7 @@ Subject: 2nd message
153 2nd message body 153 2nd message body
154 ]) 154 ])
155 155
156 echo quit | forwcmd +inbox 1 2 | remove_curdir 156 echo quit | forwcmd +inbox 1 2 | cwdrepl
157 echo == Mail/draft == 157 echo == Mail/draft ==
158 cat Mail/draft 158 cat Mail/draft
159 echo == Message 1 == 159 echo == Message 1 ==
...@@ -162,7 +162,7 @@ echo == Message 2 == ...@@ -162,7 +162,7 @@ echo == Message 2 ==
162 cat Mail/inbox/2 162 cat Mail/inbox/2
163 ], 163 ],
164 [0], 164 [0],
165 [-- Editor invocation: Mail/draft 165 [-- Editor invocation: ./Mail/draft
166 -- Input file: 166 -- Input file:
167 To: 167 To:
168 cc: 168 cc:
...@@ -188,7 +188,7 @@ Subject: 2nd message ...@@ -188,7 +188,7 @@ Subject: 2nd message
188 ------- End of Forwarded messages 188 ------- End of Forwarded messages
189 189
190 -- Input file end 190 -- Input file end
191 What now? draft left on "Mail/draft". 191 What now? draft left on "./Mail/draft".
192 == Mail/draft == 192 == Mail/draft ==
193 To: 193 To:
194 cc: 194 cc:
...@@ -237,7 +237,7 @@ Subject: test input ...@@ -237,7 +237,7 @@ Subject: test input
237 message body 237 message body
238 ]) 238 ])
239 239
240 forwcmd -build +inbox 1 | remove_curdir 240 forwcmd -build +inbox 1 | cwdrepl
241 echo == Mail/draft == 241 echo == Mail/draft ==
242 cat Mail/draft 242 cat Mail/draft
243 echo == Message == 243 echo == Message ==
...@@ -282,9 +282,9 @@ Subject: 2nd message ...@@ -282,9 +282,9 @@ Subject: 2nd message
282 2nd message body 282 2nd message body
283 ]) 283 ])
284 284
285 forwcmd -build -mime +inbox 1 2 | remove_curdir 285 forwcmd -build -mime +inbox 1 2 | cwdrepl
286 echo == Mail/draft == 286 echo == Mail/draft ==
287 remove_curdir Mail/draft 287 cwdrepl < Mail/draft
288 echo == Message 1 == 288 echo == Message 1 ==
289 sed '/^X-IMAPbase/d' Mail/inbox/1 289 sed '/^X-IMAPbase/d' Mail/inbox/1
290 echo == Message 2 == 290 echo == Message 2 ==
...@@ -296,7 +296,7 @@ To: ...@@ -296,7 +296,7 @@ To:
296 cc: 296 cc:
297 Subject: 297 Subject:
298 -------- 298 --------
299 #forw [] +Mail/inbox 1 2 299 #forw [] +./Mail/inbox 1 2
300 300
301 == Message 1 == 301 == Message 1 ==
302 From: gray 302 From: gray
...@@ -322,14 +322,14 @@ Subject: test input ...@@ -322,14 +322,14 @@ Subject: test input
322 message body 322 message body
323 ]) 323 ])
324 324
325 echo "quit" | forwcmd -draftfolder drafts 1 | remove_curdir 325 echo "quit" | forwcmd -draftfolder drafts 1 | cwdrepl
326 echo == Mail/drafts/1 == 326 echo == Mail/drafts/1 ==
327 cat Mail/drafts/1 327 cat Mail/drafts/1
328 echo == Message == 328 echo == Message ==
329 sed '/^X-IMAPbase/d' Mail/inbox/1 329 sed '/^X-IMAPbase/d' Mail/inbox/1
330 ], 330 ],
331 [0], 331 [0],
332 [-- Editor invocation: Mail/drafts/1 332 [-- Editor invocation: ./Mail/drafts/1
333 -- Input file: 333 -- Input file:
334 To: 334 To:
335 cc: 335 cc:
...@@ -346,7 +346,7 @@ message body ...@@ -346,7 +346,7 @@ message body
346 ------- End of Forwarded message 346 ------- End of Forwarded message
347 347
348 -- Input file end 348 -- Input file end
349 What now? draft left on "Mail/drafts/1". 349 What now? draft left on "./Mail/drafts/1".
350 == Mail/drafts/1 == 350 == Mail/drafts/1 ==
351 To: 351 To:
352 cc: 352 cc:
...@@ -379,10 +379,10 @@ Subject: test input ...@@ -379,10 +379,10 @@ Subject: test input
379 message body 379 message body
380 ]) 380 ])
381 381
382 echo "quit" | forwcmd -file infile | remove_curdir 382 echo "quit" | forwcmd -file infile | cwdrepl
383 ], 383 ],
384 [0], 384 [0],
385 [-- Editor invocation: Mail/draft 385 [-- Editor invocation: ./Mail/draft
386 -- Input file: 386 -- Input file:
387 To: 387 To:
388 cc: 388 cc:
...@@ -394,7 +394,7 @@ Subject: test input ...@@ -394,7 +394,7 @@ Subject: test input
394 394
395 message body 395 message body
396 -- Input file end 396 -- Input file end
397 What now? draft left on "Mail/draft". 397 What now? draft left on "./Mail/draft".
398 ]) 398 ])
399 399
400 m4_popdef([forwcmd]) 400 m4_popdef([forwcmd])
......
...@@ -130,21 +130,21 @@ Be off, or I'll kick you down stairs!' ...@@ -130,21 +130,21 @@ Be off, or I'll kick you down stairs!'
130 130
131 MH_CHECK([mhn -store -auto],[mhn03 mhn-store-auto],[ 131 MH_CHECK([mhn -store -auto],[mhn03 mhn-store-auto],[
132 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 132 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
133 mhn +inbox -store -auto 4 | remove_curdir || exit $? 133 mhn +inbox -store -auto 4 | cwdrepl || exit $?
134 ], 134 ],
135 [0], 135 [0],
136 [storing message 4 part 1 as file msg.21 136 [storing message 4 part 1 as file ./msg.21
137 storing message 4 part 2.1 as file msg.22 137 storing message 4 part 2.1 as file ./msg.22
138 storing message 4 part 2.2.1 as file msg.23 138 storing message 4 part 2.2.1 as file ./msg.23
139 storing message 4 part 2.2.2 as file msg.24 139 storing message 4 part 2.2.2 as file ./msg.24
140 ]) 140 ])
141 141
142 MH_CHECK([mhn -store -auto -part],[mhn04 mhn-store-auto-part],[ 142 MH_CHECK([mhn -store -auto -part],[mhn04 mhn-store-auto-part],[
143 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700]) 143 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
144 mhn +inbox -store -auto -part 2.2.1 4 | remove_curdir || exit $? 144 mhn +inbox -store -auto -part 2.2.1 4 | cwdrepl || exit $?
145 ], 145 ],
146 [0], 146 [0],
147 [storing message 4 part 2.2.1 as file msg.23 147 [storing message 4 part 2.2.1 as file ./msg.23
148 ]) 148 ])
149 149
150 MH_CHECK([mhn -store -auto (pathname safety)],[mhn05 mhn-store-auto-safety],[ 150 MH_CHECK([mhn -store -auto (pathname safety)],[mhn05 mhn-store-auto-safety],[
...@@ -178,13 +178,13 @@ MUT_MBCHMOD(Mail/inbox, 700) ...@@ -178,13 +178,13 @@ MUT_MBCHMOD(Mail/inbox, 700)
178 mkdir out 178 mkdir out
179 echo "mhn-storage: $HOME/out" >> $MH 179 echo "mhn-storage: $HOME/out" >> $MH
180 180
181 mhn +inbox -store 4 | remove_curdir || echo $? 181 mhn +inbox -store 4 | cwdrepl || echo $?
182 ], 182 ],
183 [0], 183 [0],
184 [storing message 4 part 1 as file out/4.1.plain 184 [storing message 4 part 1 as file ./out/4.1.plain
185 storing message 4 part 2.1 as file out/4.2.1.octet-stream 185 storing message 4 part 2.1 as file ./out/4.2.1.octet-stream
186 storing message 4 part 2.2.1 as file out/4.2.2.1.octet-stream 186 storing message 4 part 2.2.1 as file ./out/4.2.2.1.octet-stream
187 storing message 4 part 2.2.2 as file out/4.2.2.2.octet-stream 187 storing message 4 part 2.2.2 as file ./out/4.2.2.2.octet-stream
188 ]) 188 ])
189 189
190 MH_CHECK([mhn-store-: all escapes],[mhn07 mhn-store_escapes],[ 190 MH_CHECK([mhn-store-: all escapes],[mhn07 mhn-store_escapes],[
...@@ -193,7 +193,7 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox ...@@ -193,7 +193,7 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
193 MUT_MBCHMOD(Mail/inbox, 700) 193 MUT_MBCHMOD(Mail/inbox, 700)
194 194
195 echo "mhn-store-application: %%-%m%P.%s-%p" >> $MH 195 echo "mhn-store-application: %%-%m%P.%s-%p" >> $MH
196 mhn +inbox -store 4 | remove_curdir || exit $? 196 mhn +inbox -store 4 || exit $?
197 find . -name '%*' | sort 197 find . -name '%*' | sort
198 ], 198 ],
199 [0], 199 [0],
...@@ -213,13 +213,13 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox ...@@ -213,13 +213,13 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
213 MUT_MBCHMOD(Mail/inbox, 700) 213 MUT_MBCHMOD(Mail/inbox, 700)
214 214
215 echo "mhn-store-application: $HOME/out/%m%P.%s" >> $MH 215 echo "mhn-store-application: $HOME/out/%m%P.%s" >> $MH
216 mhn +inbox -store 4 | remove_curdir || exit $? 216 mhn +inbox -store 4 | cwdrepl || exit $?
217 ], 217 ],
218 [0], 218 [0],
219 [storing message 4 part 1 as file 4.1.plain 219 [storing message 4 part 1 as file 4.1.plain
220 storing message 4 part 2.1 as file out/4.2.1.octet-stream 220 storing message 4 part 2.1 as file ./out/4.2.1.octet-stream
221 storing message 4 part 2.2.1 as file out/4.2.2.1.octet-stream 221 storing message 4 part 2.2.1 as file ./out/4.2.2.1.octet-stream
222 storing message 4 part 2.2.2 as file out/4.2.2.2.octet-stream 222 storing message 4 part 2.2.2 as file ./out/4.2.2.2.octet-stream
223 ]) 223 ])
224 224
225 MH_CHECK([mhn-store-: +folder],[mhn09 mhn-store+folder],[ 225 MH_CHECK([mhn-store-: +folder],[mhn09 mhn-store+folder],[
...@@ -229,7 +229,7 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox ...@@ -229,7 +229,7 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
229 MUT_MBCHMOD(Mail, 700) 229 MUT_MBCHMOD(Mail, 700)
230 230
231 echo "mhn-store-application: +app" >> $MH 231 echo "mhn-store-application: +app" >> $MH
232 mhn +inbox -store 4 | remove_curdir || exit $? 232 mhn +inbox -store 4 | cwdrepl || exit $?
233 ], 233 ],
234 [0], 234 [0],
235 [storing message 4 part 1 as file 4.1.plain 235 [storing message 4 part 1 as file 4.1.plain
...@@ -247,7 +247,7 @@ echo "Current-Folder: inbox" > Mail/context ...@@ -247,7 +247,7 @@ echo "Current-Folder: inbox" > Mail/context
247 cat >> $MH <<EOT 247 cat >> $MH <<EOT
248 mhn-store-application/octet-stream: + 248 mhn-store-application/octet-stream: +
249 EOT 249 EOT
250 mhn +inbox -store -part 2.2.1 4 | remove_curdir || exit $? 250 mhn +inbox -store -part 2.2.1 4 | cwdrepl || exit $?
251 ], 251 ],
252 [0], 252 [0],
253 [storing message 4 part 2.2.1 to folder inbox as message 5 253 [storing message 4 part 2.2.1 to folder inbox as message 5
......
...@@ -20,43 +20,43 @@ m4_pushdef([MH_KEYWORDS],[mhpath]) ...@@ -20,43 +20,43 @@ m4_pushdef([MH_KEYWORDS],[mhpath])
20 MH_CHECK([mhpath],[mhpath00],[ 20 MH_CHECK([mhpath],[mhpath00],[
21 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 21 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
22 echo 'Current-Folder: inbox' > Mail/context 22 echo 'Current-Folder: inbox' > Mail/context
23 mhpath | remove_curdir 23 mhpath | cwdrepl
24 ], 24 ],
25 [0], 25 [0],
26 [Mail/inbox 26 [./Mail/inbox
27 ]) 27 ])
28 28
29 MH_CHECK([mhpath +],[mhpath01 mhpath+],[ 29 MH_CHECK([mhpath +],[mhpath01 mhpath+],[
30 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 30 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
31 echo 'Current-Folder: inbox' > Mail/context 31 echo 'Current-Folder: inbox' > Mail/context
32 mhpath +| remove_curdir 32 mhpath +| cwdrepl
33 ], 33 ],
34 [0], 34 [0],
35 [Mail 35 [./Mail
36 ]) 36 ])
37 37
38 MH_CHECK([mhpath msgs],[mhpath02 mhparam_msgs],[ 38 MH_CHECK([mhpath msgs],[mhpath02 mhparam_msgs],[
39 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 39 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
40 mhpath 1-3 | remove_curdir 40 mhpath 1-3 | cwdrepl
41 ], 41 ],
42 [0], 42 [0],
43 [Mail/inbox/1 43 [./Mail/inbox/1
44 Mail/inbox/2 44 ./Mail/inbox/2
45 Mail/inbox/3 45 ./Mail/inbox/3
46 ]) 46 ])
47 47
48 MH_CHECK([mhpath msgs (some nonexistent)],[mhpath03 mhparam_msgs_some_nonex],[ 48 MH_CHECK([mhpath msgs (some nonexistent)],[mhpath03 mhparam_msgs_some_nonex],[
49 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 49 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
50 mhpath 4-10 | remove_curdir 50 mhpath 4-10 | cwdrepl
51 ], 51 ],
52 [0], 52 [0],
53 [Mail/inbox/4 53 [./Mail/inbox/4
54 Mail/inbox/5 54 ./Mail/inbox/5
55 ]) 55 ])
56 56
57 MH_CHECK([mhpath msgs (all nonexistent)],[mhpath04 mhparam_msgs_all_nonex],[ 57 MH_CHECK([mhpath msgs (all nonexistent)],[mhpath04 mhparam_msgs_all_nonex],[
58 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 58 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
59 mhpath 8-10 | remove_curdir 59 mhpath 8-10 | cwdrepl
60 ], 60 ],
61 [0], 61 [0],
62 [], 62 [],
...@@ -87,7 +87,7 @@ mhpath 8-10 | remove_curdir ...@@ -87,7 +87,7 @@ mhpath 8-10 | remove_curdir
87 87
88 MH_CHECK([mhpath nonexistent],[mhpath05 mhparam_nonexistent],[ 88 MH_CHECK([mhpath nonexistent],[mhpath05 mhparam_nonexistent],[
89 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 89 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
90 mhpath 10 | remove_curdir 90 mhpath 10 | cwdrepl
91 ], 91 ],
92 [0], 92 [0],
93 [], 93 [],
...@@ -96,10 +96,10 @@ mhpath 10 | remove_curdir ...@@ -96,10 +96,10 @@ mhpath 10 | remove_curdir
96 96
97 MH_CHECK([mhpath new],[mhpath06 mhparam_new],[ 97 MH_CHECK([mhpath new],[mhpath06 mhparam_new],[
98 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox]) 98 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
99 mhpath new | remove_curdir 99 mhpath new | cwdrepl
100 ], 100 ],
101 [0], 101 [0],
102 [Mail/inbox/6 102 [./Mail/inbox/6
103 ]) 103 ])
104 104
105 m4_popdef[MH_KEYWORDS]) 105 m4_popdef[MH_KEYWORDS])
......
...@@ -28,19 +28,19 @@ Subject: test input ...@@ -28,19 +28,19 @@ Subject: test input
28 28
29 message body 29 message body
30 ]) 30 ])
31 echo "quit" | replcmd +inbox 1 | remove_curdir 31 echo "quit" | replcmd +inbox 1 | cwdrepl
32 echo == Mail/draft == 32 echo == Mail/draft ==
33 cat Mail/draft 33 cat Mail/draft
34 ], 34 ],
35 [0], 35 [0],
36 [-- Editor invocation: Mail/draft 36 [-- Editor invocation: ./Mail/draft
37 -- Input file: 37 -- Input file:
38 To: <gray@example.com> 38 To: <gray@example.com>
39 Subject: Re: test input 39 Subject: Re: test input
40 X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION) 40 X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
41 -------- 41 --------
42 -- Input file end 42 -- Input file end
43 What now? draft left on "Mail/draft". 43 What now? draft left on "./Mail/draft".
44 == Mail/draft == 44 == Mail/draft ==
45 To: <gray@example.com> 45 To: <gray@example.com>
46 Subject: Re: test input 46 Subject: Re: test input
...@@ -58,19 +58,19 @@ Subject: test input ...@@ -58,19 +58,19 @@ Subject: test input
58 58
59 message body 59 message body
60 ]) 60 ])
61 echo "quit" | replcmd -draftfolder drafts +inbox 1 | remove_curdir 61 echo "quit" | replcmd -draftfolder drafts +inbox 1 | cwdrepl
62 echo == Mail/drafts/1 == 62 echo == Mail/drafts/1 ==
63 cat Mail/drafts/1 63 cat Mail/drafts/1
64 ], 64 ],
65 [0], 65 [0],
66 [-- Editor invocation: Mail/drafts/1 66 [-- Editor invocation: ./Mail/drafts/1
67 -- Input file: 67 -- Input file:
68 To: <gray@example.com> 68 To: <gray@example.com>
69 Subject: Re: test input 69 Subject: Re: test input
70 X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION) 70 X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
71 -------- 71 --------
72 -- Input file end 72 -- Input file end
73 What now? draft left on "Mail/drafts/1". 73 What now? draft left on "./Mail/drafts/1".
74 == Mail/drafts/1 == 74 == Mail/drafts/1 ==
75 To: <gray@example.com> 75 To: <gray@example.com>
76 Subject: Re: test input 76 Subject: Re: test input
......
...@@ -51,6 +51,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac ...@@ -51,6 +51,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
51 AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@ 51 AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@
52 noinst_PROGRAMS = \ 52 noinst_PROGRAMS = \
53 bs\ 53 bs\
54 cwdrepl\
54 fldel\ 55 fldel\
55 lstuid\ 56 lstuid\
56 mbdel\ 57 mbdel\
...@@ -76,11 +77,14 @@ smtpsend_LDADD = \ ...@@ -76,11 +77,14 @@ smtpsend_LDADD = \
76 @MU_AUTHLIBS@\ 77 @MU_AUTHLIBS@\
77 ${MU_LIB_MAILUTILS} 78 ${MU_LIB_MAILUTILS}
78 79
80 cwdrepl_LDADD = ${MU_LIB_MAILUTILS}
81
79 ## ------------ ## 82 ## ------------ ##
80 ## Test suite. ## 83 ## Test suite. ##
81 ## ------------ ## 84 ## ------------ ##
82 85
83 TESTSUITE_AT = \ 86 TESTSUITE_AT = \
87 cwdrepl.at\
84 fldel.at\ 88 fldel.at\
85 lstuid00.at\ 89 lstuid00.at\
86 lstuid01.at\ 90 lstuid01.at\
......
1 # This file is part of GNU Mailutils. -*- Autotest -*-
2 # Copyright (C) 2017 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 AT_SETUP([cwdrepl tool])
18 AT_KEYWORDS([cwdrepl])
19
20 AT_CHECK([
21 pwd -P >/dev/null 2>&1 || AT_SKIP_TEST
22 cwd=`pwd -P`
23 cwdrepl <<EOT
24 $cwd
25 CWD is "$cwd"
26 $cwd/foo "$cwd" end
27 EOT
28 ],
29 [0],
30 [.
31 CWD is "."
32 ./foo "." end
33 ])
34
35 AT_CHECK([
36 pwd -P >/dev/null 2>&1 || AT_SKIP_TEST
37 pwd -L >/dev/null 2>&1 || AT_SKIP_TEST
38 mkdir physical logical
39 ln -s physical logical || AT_SKIP_TEST
40 cd logical
41 phy=`pwd -P`
42 log=`pwd -L`
43 cwdrepl <<EOT
44 $phy $log
45 LOG is "$log", PHY is "$phy"
46 $log/foo "$log" end
47 $phy/foo "$phy" end
48 EOT
49 ],
50 [0],
51 [. .
52 LOG is ".", PHY is "."
53 ./foo "." end
54 ./foo "." end
55 ])
56
57 AT_CLEANUP
58
59
1 /* This file is part of GNU Mailutils testsuite.
2 Copyright (C) 2017 Free Software Foundation, Inc.
3
4 GNU Mailutils 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 3, or (at your option)
7 any later version.
8
9 GNU Mailutils 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 GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16
17 /*
18
19 NAME
20
21 cwdrepl - replace occurrences of CWD with .
22
23 SYNOPSIS
24
25 COMMAND | cwdrepl [DIR REPL]...
26
27 DESCRIPTION
28
29 Some testcases operate programs that produce full file names as part
30 of their output. To make this output independent of the actual file
31 location, this tool replaces every occurrence of the current working
32 directory with dot. Both logical (as given by the PWD environment
33 variable) and physical (as returned by getcwd(3)) locations are replaced.
34
35 The same effect could have been achieved by using "pwd -P", "pwd -L"
36 and sed, but this would pose portability problems.
37
38 Additionally, any number of DIR REPL pairs can be supplied in the command
39 line. Each pair instructs the tool to replace every occurrence of DIR
40 with REPL on output. Note that these pairs take precedence over the
41 default ones, so running "cwdrepl $PWD 'PWD'" will replace occurrences
42 of the logical current working directory name with the string PWS, instead
43 of the default dot.
44
45 */
46
47 #ifdef HAVE_CONFIG_H
48 # include <config.h>
49 #endif
50 #include <stdlib.h>
51 #include <string.h>
52 #include <mailutils/mailutils.h>
53
54 struct dirtrans
55 {
56 char *dir;
57 size_t dirlen;
58 char const *trans;
59 ssize_t translen;
60 };
61
62 mu_list_t translist;
63
64 static int
65 transcmp (const void *a, const void *b)
66 {
67 struct dirtrans const *trans1 = a;
68 struct dirtrans const *trans2 = b;
69 return strcmp (trans1->dir, trans2->dir);
70 }
71
72 static void
73 newdir (char const *dir, char const *trans)
74 {
75 if (dir)
76 {
77 size_t dirlen = strlen (dir);
78 size_t translen = strlen (trans);
79 struct dirtrans *dt = mu_alloc (sizeof *dt);
80
81 while (dirlen > 0 && dir[dirlen-1] == '/')
82 dirlen--;
83
84 dt->dir = mu_alloc (dirlen + 1);
85 memcpy (dt->dir, dir, dirlen);
86 dt->dir[dirlen] = 0;
87 dt->dirlen = dirlen;
88 dt->trans = trans;
89 dt->translen = translen;
90
91 if (!translist)
92 {
93 MU_ASSERT (mu_list_create (&translist));
94 mu_list_set_comparator (translist, transcmp);
95 }
96 else if (mu_list_locate (translist, dt, NULL) == 0)
97 {
98 free (dt->dir);
99 free (dt);
100 return;
101 }
102
103 MU_ASSERT (mu_list_append (translist, dt));
104 }
105 }
106
107 static inline int
108 isbnd (int c)
109 {
110 return mu_c_is_class (c, MU_CTYPE_CNTRL|MU_CTYPE_PUNCT|MU_CTYPE_SPACE);
111 }
112
113 int
114 main (int argc, char **argv)
115 {
116 int i;
117 int rc;
118 char *buf = NULL;
119 size_t size, n;
120 mu_iterator_t itr;
121
122 mu_set_program_name (argv[0]);
123 mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
124
125 for (i = 1; i < argc; i += 2)
126 newdir (argv[i], (i + 1 < argc) ? argv[i + 1] : "");
127
128 newdir (getenv ("PWD"), ".");
129 newdir (mu_getcwd (), ".");
130
131 MU_ASSERT (mu_list_get_iterator (translist, &itr));
132 while ((rc = mu_stream_getline (mu_strin, &buf, &size, &n)) == 0 && n > 0)
133 {
134 n = mu_rtrim_class (buf, MU_CTYPE_SPACE);
135 for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
136 mu_iterator_next (itr))
137 {
138 struct dirtrans *dt;
139 size_t start = 0;
140 char *p;
141
142 mu_iterator_current (itr, (void**) &dt);
143 while ((p = strstr (buf + start, dt->dir)))
144 {
145 if (isbnd (p[dt->dirlen]))
146 {
147 size_t off = p - buf;
148 size_t rest = n - start;
149 ssize_t d = (ssize_t)dt->translen - dt->dirlen;
150
151 if (d > 0)
152 {
153 if (n + d + 1 > size)
154 {
155 size = n + d + 1;
156 buf = mu_realloc (buf, size);
157 p = buf + off;
158 }
159 }
160
161 memmove (p + dt->translen, p + dt->dirlen,
162 rest - dt->dirlen + 1);
163 memcpy (p, dt->trans, dt->translen);
164
165 n += d;
166 start = off + dt->translen;
167 }
168 else
169 start++;
170 }
171 }
172 mu_stream_write (mu_strout, buf, n, NULL);
173 mu_stream_write (mu_strout, "\n", 1, NULL);
174 }
175 return 0;
176 }
...@@ -38,3 +38,4 @@ m4_include([smtp-str.at]) ...@@ -38,3 +38,4 @@ m4_include([smtp-str.at])
38 38
39 AT_BANNER(Various) 39 AT_BANNER(Various)
40 m4_include([ufms.at]) 40 m4_include([ufms.at])
41 m4_include([cwdrepl.at])
......