Commit 1ba98c36 1ba98c365c5e5ce5cbc02a82054749a90a34c689 by Sergey Poznyakoff

Merge recent fixes from master

2 parents e4c393f9 263e2e9f
Showing 51 changed files with 434 additions and 96 deletions
......@@ -279,7 +279,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
size_t i;
size_t optlen; /* Length of the option in optstr */
int found = 0; /* 1 if the match was found, 2 if option is ambiguous */
enum neg_match neg; /* 1 if a boolean option is negated */
int negated; /* 1 if a boolean option is negated */
struct mu_option *ret_opt = NULL;
struct mu_option *used_opt;
......@@ -290,7 +290,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
size_t j = po->po_longidx[i];
size_t len = strlen (po->po_optv[j]->opt_long);
struct mu_option *opt = option_unalias (po, j);
neg = neg_nomatch;
enum neg_match neg = neg_nomatch;
if ((optlen <= len
&& memcmp (po->po_optv[j]->opt_long, optstr, optlen) == 0)
|| (neg = negmatch (po, j, optstr, optlen)))
......@@ -301,6 +301,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
used_opt = po->po_optv[j];
ret_opt = opt;
found++;
negated = neg != neg_nomatch;
if (optlen == len || neg == neg_match_exact)
i = po->po_longcnt - 1; /* exact match: break the loop */
break;
......@@ -353,12 +354,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
++optlen;
*used_value = (char *)(optstr + optlen);
if (ret_opt->opt_type == mu_c_bool)
{
if (neg)
*value = "0";
else
*value = "1";
}
*value = negated ? "0" : "1";
else
*value = NULL;
return ret_opt;
......
......@@ -145,6 +145,7 @@ TESTSUITE_AT = \
parseopt25.at\
parseopt26.at\
parseopt27.at\
parseopt28.at\
parseopt_help00.at\
parseopt_help01.at\
parseopt_help02.at\
......
......@@ -26,6 +26,7 @@ char *find_value;
int jobs = 0;
int x_option;
int a_option;
int headers_option = 1;
int d_option;
int debug_level_value;
char *debug_info_value;
......@@ -46,6 +47,9 @@ struct mu_option group_a[] = {
"no arguments to this one",
mu_c_bool, &a_option },
{ "debug-all", 0, NULL, MU_OPTION_ALIAS },
{ "headers", 0, NULL, MU_OPTION_DEFAULT,
"show headers",
mu_c_bool, &headers_option },
MU_OPTION_END
};
......@@ -218,6 +222,7 @@ main (int argc, char *argv[])
printf ("opt_value=%s\n", S(opt_value));
printf ("x_option=%d\n", x_option);
printf ("a_option=%d\n", a_option);
printf ("headers_option=%d\n", headers_option);
printf ("find_value=%s\n", S(find_value));
printf ("d_option=%d\n", d_option);
printf ("jobs=%d\n", jobs);
......
......@@ -26,6 +26,7 @@ file_name=(null)
opt_value=initial
x_option=0
a_option=0
headers_option=1
find_value=(null)
d_option=0
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=(null)
opt_value=initial
x_option=0
a_option=0
headers_option=1
find_value=(null)
d_option=0
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=file
opt_value=initial
x_option=1
a_option=1
headers_option=1
find_value=(null)
d_option=1
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=file
opt_value=initial
x_option=1
a_option=1
headers_option=1
find_value=(null)
d_option=1
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=(null)
opt_value=file
x_option=0
a_option=0
headers_option=1
find_value=(null)
d_option=0
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=(null)
opt_value=(null)
x_option=0
a_option=0
headers_option=1
find_value=(null)
d_option=0
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=(null)
opt_value=initial
x_option=0
a_option=0
headers_option=1
find_value=(null)
d_option=2
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=file
opt_value=10
x_option=1
a_option=1
headers_option=1
find_value=(null)
d_option=2
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=file
opt_value=initial
x_option=0
a_option=1
headers_option=1
find_value=(null)
d_option=0
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=file
opt_value=initial
x_option=0
a_option=0
headers_option=1
find_value=(null)
d_option=0
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=(null)
opt_value=file
x_option=0
a_option=0
headers_option=1
find_value=(null)
d_option=0
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=(null)
opt_value=(null)
x_option=0
a_option=0
headers_option=1
find_value=(null)
d_option=0
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=(null)
opt_value=initial
x_option=0
a_option=0
headers_option=1
find_value=(null)
d_option=2
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=file
opt_value=initial
x_option=0
a_option=0
headers_option=1
find_value=Word
d_option=0
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=filename
opt_value=(null)
x_option=1
a_option=1
headers_option=1
find_value=word
d_option=0
jobs=10
......
......@@ -26,6 +26,7 @@ file_name=(null)
opt_value=initial
x_option=0
a_option=0
headers_option=1
find_value=(null)
d_option=3
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=file
opt_value=(null)
x_option=1
a_option=0
headers_option=1
find_value=(null)
d_option=0
jobs=0
......@@ -48,6 +49,7 @@ file_name=file
opt_value=(null)
x_option=1
a_option=0
headers_option=1
find_value=(null)
d_option=0
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=foobar
opt_value=initial
x_option=1
a_option=0
headers_option=1
find_value=(null)
d_option=0
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=foobar
opt_value=initial
x_option=1
a_option=0
headers_option=1
find_value=(null)
d_option=0
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=filename
opt_value=initial
x_option=0
a_option=0
headers_option=1
find_value=(null)
d_option=0
jobs=0
......
......@@ -26,6 +26,7 @@ file_name=(null)
opt_value=initial
x_option=0
a_option=0
headers_option=1
find_value=(null)
d_option=0
jobs=0
......
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2017 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([boolean negation])
AT_KEYWORDS([parseopt parseopt_bool parseopt28])
AT_CHECK([
PARSEOPT_DEFAULT
MU_PARSEOPT_NEGATION=no-
export MU_PARSEOPT_NEGATION
echo "# full option"
parseopt --no-headers
echo "# abbreviated option"
parseopt --no-header
],
[0],
[# full option
rc=0
file_name=(null)
opt_value=initial
x_option=0
a_option=0
headers_option=0
find_value=(null)
d_option=0
jobs=0
debug_level_value=0
debug_info_value=(null)
argv:
# abbreviated option
rc=0
file_name=(null)
opt_value=initial
x_option=0
a_option=0
headers_option=0
find_value=(null)
d_option=0
jobs=0
debug_level_value=0
debug_info_value=(null)
argv:
])
AT_CLEANUP
......@@ -26,6 +26,7 @@ parseopt --help
Group A
-a, --all, --debug-all no arguments to this one
-f, --file=FILE set file name
--headers show headers
-o, --optional[=FILE] optional argument
-x short-only option
......
......@@ -23,7 +23,7 @@ parseopt --usage
[0],
[[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N] [-o[FILE]] [--all]
[--debug] [--debug-all] [--debug-info=S] [--debug-level=NUM]
[--file=FILE] [--find=VALUE] [--help] [--jobs=N]
[--file=FILE] [--find=VALUE] [--headers] [--help] [--jobs=N]
[--optional[=FILE]] [--usage] [--verbose]
]])
AT_CLEANUP
......
......@@ -26,6 +26,7 @@ MU_PARSEOPT_PROG_NAME=newname parseopt --help
Group A
-a, --all, --debug-all no arguments to this one
-f, --file=FILE set file name
--headers show headers
-o, --optional[=FILE] optional argument
-x short-only option
......
......@@ -27,6 +27,7 @@ Tests option parsing
Group A
-a, --all, --debug-all no arguments to this one
-f, --file=FILE set file name
--headers show headers
-o, --optional[=FILE] optional argument
-x short-only option
......
......@@ -26,6 +26,7 @@ MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS" parseopt --help
Group A
-a, --all, --debug-all no arguments to this one
-f, --file=FILE set file name
--headers show headers
-o, --optional[[=FILE]] optional argument
-x short-only option
......
......@@ -26,6 +26,7 @@ MU_PARSEOPT_BUG_ADDRESS='gray@gnu.org' parseopt --help
Group A
-a, --all, --debug-all no arguments to this one
-f, --file=FILE set file name
--headers show headers
-o, --optional[[=FILE]] optional argument
-x short-only option
......
......@@ -26,6 +26,7 @@ MU_PARSEOPT_PACKAGE_NAME='GNU Mailutils' MU_PARSEOPT_PACKAGE_URL='http://mailuti
Group A
-a, --all, --debug-all no arguments to this one
-f, --file=FILE set file name
--headers show headers
-o, --optional[=FILE] optional argument
-x short-only option
......
......@@ -33,6 +33,7 @@ Tests option parsing
Group A
-a, --all, --debug-all no arguments to this one
-f, --file=FILE set file name
--headers show headers
-o, --optional[=FILE] optional argument
-x short-only option
......
......@@ -27,6 +27,7 @@ ARGP_HELP_FMT=dup-args,no-dup-args-note,short-opt-col=1,opt-doc-col=32,header-co
Group A
-a, --all, --debug-all no arguments to this one
-f FILE, --file=FILE set file name
--headers show headers
-o[FILE], --optional[=FILE] optional argument
-x short-only option
......
......@@ -24,7 +24,7 @@ ARGP_HELP_FMT=rmargin=62,usage-indent=1\
[0],
[[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N]
[-o[FILE]] [--all] [--debug] [--debug-all] [--debug-info=S]
[--debug-level=NUM] [--file=FILE] [--find=VALUE] [--help]
[--jobs=N] [--optional[=FILE]] [--usage] [--verbose]
[--debug-level=NUM] [--file=FILE] [--find=VALUE] [--headers]
[--help] [--jobs=N] [--optional[=FILE]] [--usage] [--verbose]
]])
AT_CLEANUP
......
......@@ -23,7 +23,7 @@ MU_PARSEOPT_VERSION_HOOK=1 parseopt --usage
[0],
[[Usage: parseopt [-advVx?] [-f FILE] [-F VALUE] [-j N] [-o[FILE]] [--all]
[--debug] [--debug-all] [--debug-info=S] [--debug-level=NUM]
[--file=FILE] [--find=VALUE] [--help] [--jobs=N]
[--file=FILE] [--find=VALUE] [--headers] [--help] [--jobs=N]
[--optional[=FILE]] [--usage] [--verbose] [--version]
]])
AT_CLEANUP
......
......@@ -26,6 +26,7 @@ MU_PARSEOPT_VERSION_HOOK=1 parseopt --help
Group A
-a, --all, --debug-all no arguments to this one
-f, --file=FILE set file name
--headers show headers
-o, --optional[=FILE] optional argument
-x short-only option
......
......@@ -28,6 +28,7 @@ MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS|ALTERNATIVE ARGS|ANOTHER ARGS" parseopt --
Group A
-a, --all, --debug-all no arguments to this one
-f, --file=FILE set file name
--headers show headers
-o, --optional[[=FILE]] optional argument
-x short-only option
......
......@@ -131,6 +131,7 @@ m4_include([parseopt24.at])
m4_include([parseopt25.at])
m4_include([parseopt26.at])
m4_include([parseopt27.at])
m4_include([parseopt28.at])
AT_BANNER([Command line help output])
m4_include([parseopt_help00.at])
......
......@@ -210,13 +210,14 @@ struct mh_whatnow_env /* whatnow shell environment */
char *file; /* The file being processed */
char *msg; /* File name of the original message (if any) */
char *draftfile; /* File to preserve the draft into */
const char *editor;
const char *editor; /* Default editor */
char *prompt;
char *anno_field; /* Annotate field to be used */
mu_list_t anno_list; /* List of messages (mu_message_t) to annotate */
mu_mailbox_t mbox;
int nowhatnowproc;
int reedit:1; /* Set if the editor was already invoked */
char *last_ed; /* Last used editor */
};
#define DISP_QUIT 0
......
......@@ -323,6 +323,9 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab)
size_t size = 0;
struct mu_wordsplit ws;
int wsflags = MU_WRDSF_DEFFLAGS|MU_WRDSF_COMMENT;
wh->reedit = 0;
wh->last_ed = NULL;
do
{
......@@ -360,6 +363,8 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab)
while (rc == 0);
if (wsflags & MU_WRDSF_REUSE)
mu_wordsplit_free (&ws);
free (wh->last_ed);
wh->last_ed = NULL;
free (line);
return status;
}
......@@ -382,8 +387,9 @@ display (struct mh_whatnow_env *wh, int argc, char **argv, int *status)
static int
edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs)
{
char const *ed = wh->editor;
char const *ed = wh->last_ed ? wh->last_ed : wh->editor;
int i, rc, status;
char *p;
if (wh->reedit)
{
......@@ -455,8 +461,10 @@ edit (struct mh_whatnow_env *wh, int argc, char **argv, int *whs)
else
mu_error (_("problems with edit"));
}
wh->editor = ed;
p = mu_strdup (ed);
free (wh->last_ed);
wh->last_ed = p;
wh->reedit = 1;
return 0;
......
......@@ -3,10 +3,8 @@
# Copyright (C) 2004, 2010-2012, 2014-2017 Free Software Foundation,
# Inc.
PATH=@abs_builddir@:@abs_top_builddir@/mh:$top_srcdir:$srcdir:$PATH
remove_curdir() {
sed "s|$HOME/*||;s| *$||" $*
}
PATH=@abs_builddir@:@abs_top_builddir@/testsuite:@abs_top_builddir@/mh:$top_srcdir:$srcdir:$PATH
# mimeflt [FILE]
# Filter out all variable information from a MIME message in FILE.
# If FILE is not given, filter stdin.
......
......@@ -19,7 +19,7 @@ m4_pushdef([MH_KEYWORDS],[comp])
m4_pushdef([compcmd],[comp -editor $abs_top_srcdir/mh/tests/mhed])
MH_CHECK([comp -file],[comp00 comp-file],[
echo quit | compcmd -file ./infile | remove_curdir | sed 's/ *$//'
echo quit | compcmd -file $HOME/infile | cwdrepl | sed 's/ *$//'
sed 's/ *$//' infile
],
[0],
......@@ -39,7 +39,7 @@ Seen by mhed
])
MH_CHECK([comp -file (del)],[comp01 comp-file_del],[
echo 'quit -delete' | compcmd -file ./infile | remove_curdir
echo 'quit -delete' | compcmd -file $HOME/infile | cwdrepl | sed 's/ *$//'
],
[0],
[-- Editor invocation: ./infile
......@@ -53,18 +53,18 @@ What now?
])
MH_CHECK([comp file],[comp02 comp_file],[
echo 'quit' | compcmd file | remove_curdir | sed 's/ *$//'
echo 'quit' | compcmd file | cwdrepl | sed 's/ *$//'
sed 's/ *$//' Mail/file
],
[0],
[-- Editor invocation: Mail/file
[-- Editor invocation: ./Mail/file
-- Input file:
To:
cc:
Subject:
--------
-- Input file end
What now? draft left on "Mail/file".
What now? draft left on "./Mail/file".
To:
cc:
Subject:
......@@ -80,11 +80,11 @@ Subject: test input
message body
])
echo 'quit' | compcmd -use file | remove_curdir | sed 's/ *$//'
echo 'quit' | compcmd -use file | cwdrepl | sed 's/ *$//'
sed 's/ *$//' Mail/file
],
[0],
[-- Editor invocation: Mail/file
[-- Editor invocation: ./Mail/file
-- Input file:
From: gray
To: root
......@@ -92,7 +92,7 @@ Subject: test input
message body
-- Input file end
What now? draft left on "Mail/file".
What now? draft left on "./Mail/file".
From: gray
To: root
Subject: test input
......@@ -110,14 +110,14 @@ Subject: test input
message body
])
echo 'quit' | compcmd +inbox 1 | remove_curdir | sed 's/ *$//'
echo 'quit' | compcmd +inbox 1 | cwdrepl | sed 's/ *$//'
echo Mail/draft
sed 's/ *$//' Mail/draft
echo Message
sed 's/ *$//' Mail/inbox/1
],
[0],
[-- Editor invocation: Mail/draft
[-- Editor invocation: ./Mail/draft
-- Input file:
From: gray
To: root
......@@ -125,7 +125,7 @@ Subject: test input
message body
-- Input file end
What now? draft left on "Mail/draft".
What now? draft left on "./Mail/draft".
Mail/draft
From: gray
To: root
......@@ -143,18 +143,18 @@ message body
MH_CHECK([comp -draftfolder],[comp05 comp-draftfolder draftfolder],[
mkdir Mail/drafts
echo 'quit' | compcmd -draftfolder drafts | remove_curdir | sed 's/ *$//'
echo 'quit' | compcmd -draftfolder drafts | cwdrepl | sed 's/ *$//'
sed 's/ *$//' Mail/drafts/1
],
[0],
[-- Editor invocation: Mail/drafts/1
[-- Editor invocation: ./Mail/drafts/1
-- Input file:
To:
cc:
Subject:
--------
-- Input file end
What now? draft left on "Mail/drafts/1".
What now? draft left on "./Mail/drafts/1".
To:
cc:
Subject:
......@@ -172,11 +172,11 @@ message body
])
echo "cur: 1" > Mail/drafts/.mh_sequences
echo 'quit' | compcmd -draftfolder drafts -use| remove_curdir | sed 's/ *$//'
echo 'quit' | compcmd -draftfolder drafts -use| cwdrepl | sed 's/ *$//'
sed 's/ *$//' Mail/drafts/1
],
[0],
[-- Editor invocation: Mail/drafts/1
[-- Editor invocation: ./Mail/drafts/1
-- Input file:
From: gray
To: root
......@@ -184,7 +184,7 @@ Subject: test input
message body
-- Input file end
What now? draft left on "Mail/drafts/1".
What now? draft left on "./Mail/drafts/1".
From: gray
To: root
Subject: test input
......
......@@ -27,7 +27,7 @@ Subject: test input
message body
])
echo quit | forwcmd +inbox 1 | remove_curdir
echo quit | forwcmd +inbox 1 | cwdrepl
echo == Mail/draft ==
cat Mail/draft
echo == Message ==
......@@ -36,7 +36,7 @@ echo == Message ==
sed '/^X-IMAPbase/d' Mail/inbox/1
],
[0],
[-- Editor invocation: Mail/draft
[-- Editor invocation: ./Mail/draft
-- Input file:
To:
cc:
......@@ -53,7 +53,7 @@ message body
------- End of Forwarded message
-- Input file end
What now? draft left on "Mail/draft".
What now? draft left on "./Mail/draft".
== Mail/draft ==
To:
cc:
......@@ -87,7 +87,7 @@ Subject: test input
message body
])
echo quit | forwcmd -format +inbox 1 | remove_curdir
echo quit | forwcmd -format +inbox 1 | cwdrepl
echo == Mail/draft ==
cat Mail/draft
echo == Message ==
......@@ -96,7 +96,7 @@ echo == Message ==
sed '/^X-IMAPbase/d' Mail/inbox/1
],
[0],
[-- Editor invocation: Mail/draft
[-- Editor invocation: ./Mail/draft
-- Input file:
To:
cc:
......@@ -113,7 +113,7 @@ message body
------- End of Forwarded message
-- Input file end
What now? draft left on "Mail/draft".
What now? draft left on "./Mail/draft".
== Mail/draft ==
To:
cc:
......@@ -153,7 +153,7 @@ Subject: 2nd message
2nd message body
])
echo quit | forwcmd +inbox 1 2 | remove_curdir
echo quit | forwcmd +inbox 1 2 | cwdrepl
echo == Mail/draft ==
cat Mail/draft
echo == Message 1 ==
......@@ -162,7 +162,7 @@ echo == Message 2 ==
cat Mail/inbox/2
],
[0],
[-- Editor invocation: Mail/draft
[-- Editor invocation: ./Mail/draft
-- Input file:
To:
cc:
......@@ -188,7 +188,7 @@ Subject: 2nd message
------- End of Forwarded messages
-- Input file end
What now? draft left on "Mail/draft".
What now? draft left on "./Mail/draft".
== Mail/draft ==
To:
cc:
......@@ -237,7 +237,7 @@ Subject: test input
message body
])
forwcmd -build +inbox 1 | remove_curdir
forwcmd -build +inbox 1 | cwdrepl
echo == Mail/draft ==
cat Mail/draft
echo == Message ==
......@@ -282,9 +282,9 @@ Subject: 2nd message
2nd message body
])
forwcmd -build -mime +inbox 1 2 | remove_curdir
forwcmd -build -mime +inbox 1 2 | cwdrepl
echo == Mail/draft ==
remove_curdir Mail/draft
cwdrepl < Mail/draft
echo == Message 1 ==
sed '/^X-IMAPbase/d' Mail/inbox/1
echo == Message 2 ==
......@@ -296,7 +296,7 @@ To:
cc:
Subject:
--------
#forw [] +Mail/inbox 1 2
#forw [] +./Mail/inbox 1 2
== Message 1 ==
From: gray
......@@ -322,14 +322,14 @@ Subject: test input
message body
])
echo "quit" | forwcmd -draftfolder drafts 1 | remove_curdir
echo "quit" | forwcmd -draftfolder drafts 1 | cwdrepl
echo == Mail/drafts/1 ==
cat Mail/drafts/1
echo == Message ==
sed '/^X-IMAPbase/d' Mail/inbox/1
],
[0],
[-- Editor invocation: Mail/drafts/1
[-- Editor invocation: ./Mail/drafts/1
-- Input file:
To:
cc:
......@@ -346,7 +346,7 @@ message body
------- End of Forwarded message
-- Input file end
What now? draft left on "Mail/drafts/1".
What now? draft left on "./Mail/drafts/1".
== Mail/drafts/1 ==
To:
cc:
......@@ -379,10 +379,10 @@ Subject: test input
message body
])
echo "quit" | forwcmd -file infile | remove_curdir
echo "quit" | forwcmd -file infile | cwdrepl
],
[0],
[-- Editor invocation: Mail/draft
[-- Editor invocation: ./Mail/draft
-- Input file:
To:
cc:
......@@ -394,7 +394,7 @@ Subject: test input
message body
-- Input file end
What now? draft left on "Mail/draft".
What now? draft left on "./Mail/draft".
])
m4_popdef([forwcmd])
......
......@@ -130,21 +130,21 @@ Be off, or I'll kick you down stairs!'
MH_CHECK([mhn -store -auto],[mhn03 mhn-store-auto],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
mhn +inbox -store -auto 4 | remove_curdir || exit $?
mhn +inbox -store -auto 4 | cwdrepl || exit $?
],
[0],
[storing message 4 part 1 as file msg.21
storing message 4 part 2.1 as file msg.22
storing message 4 part 2.2.1 as file msg.23
storing message 4 part 2.2.2 as file msg.24
[storing message 4 part 1 as file ./msg.21
storing message 4 part 2.1 as file ./msg.22
storing message 4 part 2.2.1 as file ./msg.23
storing message 4 part 2.2.2 as file ./msg.24
])
MH_CHECK([mhn -store -auto -part],[mhn04 mhn-store-auto-part],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
mhn +inbox -store -auto -part 2.2.1 4 | remove_curdir || exit $?
mhn +inbox -store -auto -part 2.2.1 4 | cwdrepl || exit $?
],
[0],
[storing message 4 part 2.2.1 as file msg.23
[storing message 4 part 2.2.1 as file ./msg.23
])
MH_CHECK([mhn -store -auto (pathname safety)],[mhn05 mhn-store-auto-safety],[
......@@ -178,13 +178,13 @@ MUT_MBCHMOD(Mail/inbox, 700)
mkdir out
echo "mhn-storage: $HOME/out" >> $MH
mhn +inbox -store 4 | remove_curdir || echo $?
mhn +inbox -store 4 | cwdrepl || echo $?
],
[0],
[storing message 4 part 1 as file out/4.1.plain
storing message 4 part 2.1 as file out/4.2.1.octet-stream
storing message 4 part 2.2.1 as file out/4.2.2.1.octet-stream
storing message 4 part 2.2.2 as file out/4.2.2.2.octet-stream
[storing message 4 part 1 as file ./out/4.1.plain
storing message 4 part 2.1 as file ./out/4.2.1.octet-stream
storing message 4 part 2.2.1 as file ./out/4.2.2.1.octet-stream
storing message 4 part 2.2.2 as file ./out/4.2.2.2.octet-stream
])
MH_CHECK([mhn-store-: all escapes],[mhn07 mhn-store_escapes],[
......@@ -193,7 +193,7 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
MUT_MBCHMOD(Mail/inbox, 700)
echo "mhn-store-application: %%-%m%P.%s-%p" >> $MH
mhn +inbox -store 4 | remove_curdir || exit $?
mhn +inbox -store 4 || exit $?
find . -name '%*' | sort
],
[0],
......@@ -213,13 +213,13 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
MUT_MBCHMOD(Mail/inbox, 700)
echo "mhn-store-application: $HOME/out/%m%P.%s" >> $MH
mhn +inbox -store 4 | remove_curdir || exit $?
mhn +inbox -store 4 | cwdrepl || exit $?
],
[0],
[storing message 4 part 1 as file 4.1.plain
storing message 4 part 2.1 as file out/4.2.1.octet-stream
storing message 4 part 2.2.1 as file out/4.2.2.1.octet-stream
storing message 4 part 2.2.2 as file out/4.2.2.2.octet-stream
storing message 4 part 2.1 as file ./out/4.2.1.octet-stream
storing message 4 part 2.2.1 as file ./out/4.2.2.1.octet-stream
storing message 4 part 2.2.2 as file ./out/4.2.2.2.octet-stream
])
MH_CHECK([mhn-store-: +folder],[mhn09 mhn-store+folder],[
......@@ -229,7 +229,7 @@ cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
MUT_MBCHMOD(Mail, 700)
echo "mhn-store-application: +app" >> $MH
mhn +inbox -store 4 | remove_curdir || exit $?
mhn +inbox -store 4 | cwdrepl || exit $?
],
[0],
[storing message 4 part 1 as file 4.1.plain
......@@ -247,7 +247,7 @@ echo "Current-Folder: inbox" > Mail/context
cat >> $MH <<EOT
mhn-store-application/octet-stream: +
EOT
mhn +inbox -store -part 2.2.1 4 | remove_curdir || exit $?
mhn +inbox -store -part 2.2.1 4 | cwdrepl || exit $?
],
[0],
[storing message 4 part 2.2.1 to folder inbox as message 5
......
......@@ -20,43 +20,43 @@ m4_pushdef([MH_KEYWORDS],[mhpath])
MH_CHECK([mhpath],[mhpath00],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
echo 'Current-Folder: inbox' > Mail/context
mhpath | remove_curdir
mhpath | cwdrepl
],
[0],
[Mail/inbox
[./Mail/inbox
])
MH_CHECK([mhpath +],[mhpath01 mhpath+],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
echo 'Current-Folder: inbox' > Mail/context
mhpath +| remove_curdir
mhpath +| cwdrepl
],
[0],
[Mail
[./Mail
])
MH_CHECK([mhpath msgs],[mhpath02 mhparam_msgs],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
mhpath 1-3 | remove_curdir
mhpath 1-3 | cwdrepl
],
[0],
[Mail/inbox/1
Mail/inbox/2
Mail/inbox/3
[./Mail/inbox/1
./Mail/inbox/2
./Mail/inbox/3
])
MH_CHECK([mhpath msgs (some nonexistent)],[mhpath03 mhparam_msgs_some_nonex],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
mhpath 4-10 | remove_curdir
mhpath 4-10 | cwdrepl
],
[0],
[Mail/inbox/4
Mail/inbox/5
[./Mail/inbox/4
./Mail/inbox/5
])
MH_CHECK([mhpath msgs (all nonexistent)],[mhpath04 mhparam_msgs_all_nonex],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
mhpath 8-10 | remove_curdir
mhpath 8-10 | cwdrepl
],
[0],
[],
......@@ -87,7 +87,7 @@ mhpath 8-10 | remove_curdir
MH_CHECK([mhpath nonexistent],[mhpath05 mhparam_nonexistent],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
mhpath 10 | remove_curdir
mhpath 10 | cwdrepl
],
[0],
[],
......@@ -96,10 +96,10 @@ mhpath 10 | remove_curdir
MH_CHECK([mhpath new],[mhpath06 mhparam_new],[
MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
mhpath new | remove_curdir
mhpath new | cwdrepl
],
[0],
[Mail/inbox/6
[./Mail/inbox/6
])
m4_popdef[MH_KEYWORDS])
......
......@@ -28,19 +28,19 @@ Subject: test input
message body
])
echo "quit" | replcmd +inbox 1 | remove_curdir
echo "quit" | replcmd +inbox 1 | cwdrepl
echo == Mail/draft ==
cat Mail/draft
],
[0],
[-- Editor invocation: Mail/draft
[-- Editor invocation: ./Mail/draft
-- Input file:
To: <gray@example.com>
Subject: Re: test input
X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
--------
-- Input file end
What now? draft left on "Mail/draft".
What now? draft left on "./Mail/draft".
== Mail/draft ==
To: <gray@example.com>
Subject: Re: test input
......@@ -58,19 +58,19 @@ Subject: test input
message body
])
echo "quit" | replcmd -draftfolder drafts +inbox 1 | remove_curdir
echo "quit" | replcmd -draftfolder drafts +inbox 1 | cwdrepl
echo == Mail/drafts/1 ==
cat Mail/drafts/1
],
[0],
[-- Editor invocation: Mail/drafts/1
[-- Editor invocation: ./Mail/drafts/1
-- Input file:
To: <gray@example.com>
Subject: Re: test input
X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
--------
-- Input file end
What now? draft left on "Mail/drafts/1".
What now? draft left on "./Mail/drafts/1".
== Mail/drafts/1 ==
To: <gray@example.com>
Subject: Re: test input
......
......@@ -51,6 +51,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@
noinst_PROGRAMS = \
bs\
cwdrepl\
fldel\
lstuid\
mbdel\
......@@ -76,11 +77,14 @@ smtpsend_LDADD = \
@MU_AUTHLIBS@\
${MU_LIB_MAILUTILS}
cwdrepl_LDADD = ${MU_LIB_MAILUTILS}
## ------------ ##
## Test suite. ##
## ------------ ##
TESTSUITE_AT = \
cwdrepl.at\
fldel.at\
lstuid00.at\
lstuid01.at\
......
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2017 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3, or (at
# your option) any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([cwdrepl tool])
AT_KEYWORDS([cwdrepl])
AT_CHECK([
pwd -P >/dev/null 2>&1 || AT_SKIP_TEST
cwd=`pwd -P`
cwdrepl <<EOT
$cwd
CWD is "$cwd"
$cwd/foo "$cwd" end
EOT
],
[0],
[.
CWD is "."
./foo "." end
])
AT_CHECK([
pwd -P >/dev/null 2>&1 || AT_SKIP_TEST
pwd -L >/dev/null 2>&1 || AT_SKIP_TEST
mkdir physical logical
ln -s physical logical || AT_SKIP_TEST
cd logical
phy=`pwd -P`
log=`pwd -L`
cwdrepl <<EOT
$phy $log
LOG is "$log", PHY is "$phy"
$log/foo "$log" end
$phy/foo "$phy" end
EOT
],
[0],
[. .
LOG is ".", PHY is "."
./foo "." end
./foo "." end
])
AT_CLEANUP
/* This file is part of GNU Mailutils testsuite.
Copyright (C) 2017 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
/*
NAME
cwdrepl - replace occurrences of CWD with .
SYNOPSIS
COMMAND | cwdrepl [DIR REPL]...
DESCRIPTION
Some testcases operate programs that produce full file names as part
of their output. To make this output independent of the actual file
location, this tool replaces every occurrence of the current working
directory with dot. Both logical (as given by the PWD environment
variable) and physical (as returned by getcwd(3)) locations are replaced.
The same effect could have been achieved by using "pwd -P", "pwd -L"
and sed, but this would pose portability problems.
Additionally, any number of DIR REPL pairs can be supplied in the command
line. Each pair instructs the tool to replace every occurrence of DIR
with REPL on output. Note that these pairs take precedence over the
default ones, so running "cwdrepl $PWD 'PWD'" will replace occurrences
of the logical current working directory name with the string PWS, instead
of the default dot.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <mailutils/mailutils.h>
struct dirtrans
{
char *dir;
size_t dirlen;
char const *trans;
ssize_t translen;
};
mu_list_t translist;
static int
transcmp (const void *a, const void *b)
{
struct dirtrans const *trans1 = a;
struct dirtrans const *trans2 = b;
return strcmp (trans1->dir, trans2->dir);
}
static void
newdir (char const *dir, char const *trans)
{
if (dir)
{
size_t dirlen = strlen (dir);
size_t translen = strlen (trans);
struct dirtrans *dt = mu_alloc (sizeof *dt);
while (dirlen > 0 && dir[dirlen-1] == '/')
dirlen--;
dt->dir = mu_alloc (dirlen + 1);
memcpy (dt->dir, dir, dirlen);
dt->dir[dirlen] = 0;
dt->dirlen = dirlen;
dt->trans = trans;
dt->translen = translen;
if (!translist)
{
MU_ASSERT (mu_list_create (&translist));
mu_list_set_comparator (translist, transcmp);
}
else if (mu_list_locate (translist, dt, NULL) == 0)
{
free (dt->dir);
free (dt);
return;
}
MU_ASSERT (mu_list_append (translist, dt));
}
}
static inline int
isbnd (int c)
{
return mu_c_is_class (c, MU_CTYPE_CNTRL|MU_CTYPE_PUNCT|MU_CTYPE_SPACE);
}
int
main (int argc, char **argv)
{
int i;
int rc;
char *buf = NULL;
size_t size, n;
mu_iterator_t itr;
mu_set_program_name (argv[0]);
mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
for (i = 1; i < argc; i += 2)
newdir (argv[i], (i + 1 < argc) ? argv[i + 1] : "");
newdir (getenv ("PWD"), ".");
newdir (mu_getcwd (), ".");
MU_ASSERT (mu_list_get_iterator (translist, &itr));
while ((rc = mu_stream_getline (mu_strin, &buf, &size, &n)) == 0 && n > 0)
{
n = mu_rtrim_class (buf, MU_CTYPE_SPACE);
for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
mu_iterator_next (itr))
{
struct dirtrans *dt;
size_t start = 0;
char *p;
mu_iterator_current (itr, (void**) &dt);
while ((p = strstr (buf + start, dt->dir)))
{
if (isbnd (p[dt->dirlen]))
{
size_t off = p - buf;
size_t rest = n - start;
ssize_t d = (ssize_t)dt->translen - dt->dirlen;
if (d > 0)
{
if (n + d + 1 > size)
{
size = n + d + 1;
buf = mu_realloc (buf, size);
p = buf + off;
}
}
memmove (p + dt->translen, p + dt->dirlen,
rest - dt->dirlen + 1);
memcpy (p, dt->trans, dt->translen);
n += d;
start = off + dt->translen;
}
else
start++;
}
}
mu_stream_write (mu_strout, buf, n, NULL);
mu_stream_write (mu_strout, "\n", 1, NULL);
}
return 0;
}
......@@ -38,3 +38,4 @@ m4_include([smtp-str.at])
AT_BANNER(Various)
m4_include([ufms.at])
m4_include([cwdrepl.at])
......