test_getfullname_SOURCES = test/getfullname.c
test_getfullname_LDADD = $(LDADD) $(POSTLINK)
+##
+## Other program definitions
+##
+
test_getcanon_SOURCES = test/getcanon.c
test_getcanon_LDADD = $(POSTLINK)
## Hard-code the config/version.c target, instead of using $@, so this
## rule works for the distcheck target with Solaris (System V) make.
+
## distcheck uses VPATH, causes that make to prepend the VPATH to $@.
config/version.c: Makefile $(srcdir)/config/version.sh
env srcdir="$(srcdir)" sh $(srcdir)/config/version.sh $(VERSION) > ./config/version.c
sbr/error.c sbr/ext_hook.c sbr/fdcompare.c \
sbr/folder_addmsg.c sbr/folder_delmsgs.c \
sbr/folder_free.c sbr/folder_pack.c \
- sbr/folder_read.c sbr/folder_realloc.c sbr/gans.c \
- sbr/getans.c sbr/getanswer.c sbr/getarguments.c \
+ sbr/folder_read.c sbr/folder_realloc.c sbr/read_switch.c \
+ sbr/read_switch_multiword.c sbr/read_switch_multiword_via_readline.c \
+ sbr/read_yes_or_no_if_tty.c sbr/getarguments.c \
sbr/getcpy.c sbr/geteditor.c sbr/getfolder.c \
- sbr/getpass.c \
+ sbr/getpass.c sbr/read_line.c \
sbr/fmt_addr.c sbr/fmt_compile.c sbr/fmt_new.c \
sbr/fmt_rfc2047.c sbr/fmt_scan.c \
sbr/icalparse.y sbr/icalendar.l sbr/datetime.c \
sbr/trimcpy.c sbr/unquote.c \
sbr/uprf.c sbr/vfgets.c \
sbr/mf.c sbr/utils.c sbr/ctype-checked.c \
- sbr/m_mktemp.c sbr/getansreadline.c sbr/vector.c \
- config/config.c config/version.c sbr/oauth.c \
+ sbr/m_mktemp.c sbr/vector.c sbr/oauth.c \
+ config/config.c config/version.c \
thirdparty/jsmn/jsmn.c
##
void argsplit_msgarg (struct msgs_array *, char *, char **);
void argsplit_insert (struct msgs_array *, char *, char **);
void arglist_free (char *, char **);
-void ambigsw (char *, struct swit *);
+void ambigsw (const char *, const struct swit *);
int atooi(char *);
char **brkstring (char *, char *, char *);
struct msgs *folder_read (char *name, int lockflag);
struct msgs *folder_realloc (struct msgs *, int, int);
-int gans (char *, struct swit *);
-char **getans (char *, struct swit *);
+
+/*
+ * Flush standard output, read a line from standard input into a static buffer,
+ * zero out the newline, and return a pointer to the buffer.
+ * On error, return NULL.
+ */
+const char *read_line(void);
+
+/*
+ * Print null-terminated PROMPT to and flush standard output. Read answers from
+ * standard input until one matches an entry in SWITCHES. When one matches,
+ * return its swret field. Return 0 on EOF.
+ */
+int read_switch(const char *PROMPT, const struct swit *SWITCHES);
+
+/*
+ * If standard input is not a tty, return 1 without printing anything. Else,
+ * print null-terminated PROMPT to and flush standard output. Read answers from
+ * standard input until one is "yes" or "no", returning 1 for "yes" and 0 for
+ * "no". Also return 0 on EOF.
+ */
+int read_yes_or_no_if_tty(const char *PROMPT);
+
+/*
+ * Print null-terminated PROMPT to and flush standard output. Read multi-word
+ * answers from standard input until a first word matches an entry in SWITCHES.
+ * When one matches, return a pointer to an array of pointers to the words.
+ * Return NULL on EOF, interrupt, or other error.
+ */
+char **read_switch_multiword(const char *PROMPT, const struct swit *SWITCHES);
+
+/*
+ * Same as read_switch_multiword but using readline(3) for input.
+ */
#ifdef READLINE_SUPPORT
-char **getans_via_readline (char *, struct swit *);
+char **read_switch_multiword_via_readline (char *, struct swit *);
#endif /* READLINE_SUPPORT */
-int getanswer (char *);
+
char **getarguments (char *, int, char **, int);
/*
void m_pclose(void);
void m_unknown(m_getfld_state_t *, FILE *);
-int makedir (char *);
+int makedir (const char *);
char *message_id (time_t, int);
/*
int pidstatus (int, FILE *, char *);
char *pluspath(char *);
void print_help (char *, struct swit *, int);
-void print_sw (char *, struct swit *, char *, FILE *);
+void print_sw (const char *, const struct swit *, char *, FILE *);
void print_version (char *);
void push (void);
char *pwd (void);
void seq_setprev (struct msgs *);
void seq_setunseen (struct msgs *, int);
int showfile (char **, char *);
-int smatch(char *, struct swit *);
+int smatch(const char *, const struct swit *);
/*
* Convert a set of bit flags to printable format.
* from least significant bit to most significant.
*/
char *snprintb (char *buffer, size_t size, unsigned flags, char *bitfield);
-int ssequal (char *, char *);
+int ssequal (const char *, const char *);
int stringdex (char *, char *);
char *trimcpy (char *);
int unputenv (char *);
-.TH SLOCAL %manext1% "November 23, 2012" "%nmhversion%"
+.TH SLOCAL %manext1% "May 2, 2016" "%nmhversion%"
.\"
.\" %nmhwarning%
.\"
switch tells
.B slocal
the name of the user for
-whom it is delivering mail. The
+whom it is delivering mail. It must exist on the local system. The
.B \-mailbox
switch tells
.B slocal
.RB ` \-maildelivery "' defaults to $HOME/\&.maildelivery"
.RB ` \-mailbox "' deaults to %mailspool%/$USER"
.RB ` \-file "' defaults to stdin"
+.RB ` \-addr "' defaults to the current user"
.RB ` \-user "' defaults to the current user"
.fi
+.PP
+.B \-addr
+and
+.B \-user
+will be set the the user part of the Local-Mailbox profile entry, if set.
.SH CONTEXT
None
.SH HISTORY
void
-ambigsw (char *arg, struct swit *swp)
+ambigsw (const char *arg, const struct swit *swp)
{
advise (NULL, "-%s ambiguous. It matches", arg);
print_sw (arg, swp, "-", stderr);
cp = concat ("Your MH-directory \"", nd, "\" doesn't exist; Create it? ", NULL);
- if (!getanswer(cp))
+ if (!read_yes_or_no_if_tty(cp))
adios (NULL, "unable to access MH-directory \"%s\"", nd);
free (cp);
#include <sys/file.h>
int
-makedir (char *dir)
+makedir (const char *dir)
{
char path[PATH_MAX];
char* folder_perms_ASCII;
void
-print_sw (char *substr, struct swit *swp, char *prefix, FILE *fp)
+print_sw (const char *substr, const struct swit *swp, char *prefix, FILE *fp)
{
int len, optno;
register int i;
--- /dev/null
+#include <h/mh.h>
+
+const char *
+read_line(void)
+{
+ char *cp;
+ static char line[BUFSIZ];
+
+ fflush(stdout);
+ if (fgets(line, sizeof(line), stdin) == NULL)
+ return NULL;
+ if ((cp = strchr(line, '\n')))
+ *cp = 0;
+ return line;
+}
+
/*
- * gans.c -- get an answer from the user
+ * read_switch.c -- prompt the user for an answer from the list
*
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
int
-gans (char *prompt, struct swit *ansp)
+read_switch (const char *prompt, const struct swit *ansp)
{
register int i;
register char *cp;
- register struct swit *ap;
+ register const struct swit *ap;
char ansbuf[BUFSIZ];
for (;;) {
/*
- * getans.c -- get an answer from the user and return a string array
+ * read_switch_multiword.c -- get an answer from the user and return a string array
*
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
char **
-getans (char *prompt, struct swit *ansp)
+read_switch_multiword (const char *prompt, const struct swit *ansp)
{
int i;
SIGNAL_HANDLER istat = NULL;
/*
- * getansreadline.c -- get an answer from the user, with readline
+ * read_switch_multiword_via_readline.c -- get an answer from the user, with readline
*
* This code is Copyright (c) 2012, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
*/
char **
-getans_via_readline(char *prompt, struct swit *ansp)
+read_switch_multiword_via_readline(char *prompt, struct swit *ansp)
{
char *ans, **cpp;
/*
- * getanswer.c -- get a yes/no answer from the user
+ * read_yes_or_no_if_tty.c -- get a yes/no answer from the user
*
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
int
-getanswer (char *prompt)
+read_yes_or_no_if_tty (const char *prompt)
{
static int interactive = -1;
if (interactive < 0)
interactive = isatty (fileno (stdin)) ? 1 : 0;
- return (interactive ? gans (prompt, anoyes) : 1);
+ return (interactive ? read_switch (prompt, anoyes) : 1);
}
int
-smatch(char *string, struct swit *swp)
+smatch(const char *string, const struct swit *swp)
{
- char *sp, *tcp;
+ const char *sp, *tcp;
int firstone, len;
- struct swit *tp;
+ const struct swit *tp;
firstone = UNKWNSW;
*/
int
-ssequal (char *s1, char *s2)
+ssequal (const char *s1, const char *s2)
{
if (!s1)
s1 = "";
if (autocreate == 0) {
/* ask before creating folder */
cp = concat ("Create folder \"", folder, "\"? ", NULL);
- if (!getanswer (cp))
+ if (!read_yes_or_no_if_tty (cp))
done_callback (1);
free (cp);
} else if (autocreate == -1) {
check "$MH_TEST_DIR/Mail/inbox/5" "$actual" 'keep first'
check "$MH_TEST_DIR/Mail/inbox/5" "$actual2" 'keep first'
-# Use current login for address, user, etc., because it must be an
-# existing user on the host.
-me=`"$MH_LIBEXEC_DIR"/ap -format '%(me)' 0`
-
# check -addr
cat >"$md" <<EOF
-addr "$me" qpipe A "$tee $actual"
+addr someaddress qpipe A "$tee $actual"
EOF
-run_prog $slocal -addr "$me" -maildelivery "$md" $mbox \
+run_prog $slocal -addr someaddress -maildelivery "$md" $mbox \
<"$MH_TEST_DIR"/Mail/inbox/6
check "$MH_TEST_DIR/Mail/inbox/6" "$actual" 'keep first'
+# check -addr with . in address
+cat >"$md" <<EOF
+addr "first.last" qpipe A "$tee $actual"
+EOF
+run_prog $slocal -addr 'first.last' \
+ -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/6
+check "$MH_TEST_DIR/Mail/inbox/6" "$actual" 'keep first'
+
# check -info
cat >"$md" <<EOF
* - qpipe A "\$(info) $actual"
# check -sender, which is compared with "source"
cat >"$md" <<EOF
-source "$me" qpipe A "$tee $actual"
+source somesender qpipe A "$tee $actual"
EOF
-run_prog $slocal -sender "$me" -maildelivery "$md" $mbox \
+run_prog $slocal -sender somesender -maildelivery "$md" $mbox \
<"$MH_TEST_DIR"/Mail/inbox/8
check "$MH_TEST_DIR/Mail/inbox/8" "$actual" 'keep first'
* - qpipe A "$tee $actual"
EOF
+# Use current login for user because it must be an existing user on the host.
+me=`"$MH_LIBEXEC_DIR"/ap -format '%(me)' 0`
run_prog $slocal -user "$me" -maildelivery "$md" $mbox \
<"$MH_TEST_DIR"/Mail/inbox/9
check "$MH_TEST_DIR/Mail/inbox/9" "$actual" 'keep first'
+# Can't check -user with . in address because the user must
+# have an account on the local system, and we can't guarantee
+# that there is one.
+
# check -mailbox
cat >"$md" <<EOF
EOF
<"$MH_TEST_DIR"/Mail/inbox/2
check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
-
exit ${failed:-0}
adios (drft, "unable to stat");
printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size);
for (i = LISTDSW; i != YESW;) {
- if (!(argp = getans ("\nDisposition? ", isdf ? aqrunl : aqrul)))
+ if (!(argp = read_switch_multiword ("\nDisposition? ",
+ isdf ? aqrunl : aqrul)))
done (1);
switch (i = smatch (*argp, isdf ? aqrunl : aqrul)) {
case NOSW:
if (stat (drft, &st) != NOTOK) {
printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size);
for (i = LISTDSW; i != YESW;) {
- if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl)))
+ if (!(argp = read_switch_multiword ("\nDisposition? ",
+ isdf ? aqrnl : aqrl)))
done (1);
switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) {
case NOSW:
if (!buildsw && stat (drft, &st) != NOTOK) {
printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size);
for (i = LISTDSW; i != YESW;) {
- if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl)))
+ if (!(argp = read_switch_multiword ("\nDisposition? ",
+ isdf ? aqrnl : aqrl)))
done (1);
switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) {
case NOSW:
if (errno != ENOENT)
adios (packfile, "error on file");
cp = concat ("Create file \"", packfile, "\"? ", NULL);
- if (noisy && !getanswer (cp))
+ if (noisy && !read_yes_or_no_if_tty (cp))
done (1);
free (cp);
}
DEFINE_SWITCH_ARRAY(INSTALLMH, switches);
#undef X
-/*
- * static prototypes
- */
-static char *geta(void);
-
int
main (int argc, char **argv)
{
int autof = 0;
- char *cp, *pathname, buf[BUFSIZ];
+ char *cp, buf[BUFSIZ];
+ const char *pathname;
char *dp, **arguments, **argp;
struct node *np;
struct passwd *pw;
done(1);
}
- if (!autof && gans ("Do you want help? ", anoyes)) {
+ if (!autof && read_switch ("Do you want help? ", anoyes)) {
(void)printf(
"\n"
"Prior to using nmh, it is necessary to have a file in your login\n"
if (S_ISDIR(st.st_mode)) {
cp = concat ("You already have the standard nmh directory \"",
cp, "\".\nDo you want to use it for nmh? ", NULL);
- if (gans (cp, anoyes))
+ if (read_switch (cp, anoyes))
pathname = "Mail";
else
goto query;
else
cp = concat ("Do you want the standard nmh path \"",
mypath, "/", "Mail\"? ", NULL);
- if (autof || gans (cp, anoyes))
+ if (autof || read_switch (cp, anoyes))
pathname = "Mail";
else {
query:
- if (gans ("Do you want a path below your login directory? ",
+ if (read_switch ("Do you want a path below your login directory? ",
anoyes)) {
printf ("What is the path? %s/", mypath);
- pathname = geta ();
+ pathname = read_line ();
+ if (pathname == NULL) done (1);
} else {
printf ("What is the whole path? /");
- pathname = concat ("/", geta (), NULL);
+ pathname = read_line ();
+ if (pathname == NULL) done (1);
+ pathname = concat ("/", pathname, NULL);
}
}
}
}
if (chdir (pathname) == NOTOK) {
cp = concat ("\"", pathname, "\" doesn't exist; Create it? ", NULL);
- if (autof || gans (cp, anoyes))
+ if (autof || read_switch (cp, anoyes))
if (makedir (pathname) == 0)
adios (NULL, "unable to create %s", pathname);
} else {
done (0);
return 1;
}
-
-
-static char *
-geta (void)
-{
- char *cp;
- static char line[BUFSIZ];
-
- fflush(stdout);
- if (fgets(line, sizeof(line), stdin) == NULL)
- done (1);
- if ((cp = strchr(line, '\n')))
- *cp = 0;
- return line;
-}
snprintf (bp, buflen, "\n in file %s? ", buffer);
/* Now, check answer */
- if (!getanswer (query))
+ if (!read_yes_or_no_if_tty (query))
status = NOTOK;
}
}
ep = concat ("Create directory \"", file, "\"? ", NULL);
- answer = getanswer (ep);
+ answer = read_yes_or_no_if_tty (ep);
free (ep);
if (!answer)
/*
* Now, check the answer
*/
- if (!getanswer (buffer))
+ if (!read_yes_or_no_if_tty (buffer))
return NOTOK;
if (e->eb_flags) {
e->eb_subject ? e->eb_subject : e->eb_body);
/* Now, check answer */
- if (!getanswer (buffer))
+ if (!read_yes_or_no_if_tty (buffer))
return NOTOK;
vecp = 0;
if (isatty (fileno (stdin))) {
char *prompt =
concat ("Overwrite \"", file, "\" [y/n/rename]? ", NULL);
- ans = getans (prompt, answer);
+ ans = read_switch_multiword (prompt, answer);
free (prompt);
} else {
/* Overwrite, that's what nmh used to do. And warn. */
if (errno != ENOENT)
adios (file, "error on file");
cp = concat ("Create file \"", file, "\"? ", NULL);
- if (!getanswer (cp))
+ if (!read_yes_or_no_if_tty (cp))
done (1);
free (cp);
}
if (!buildsw && stat (drft, &st) != NOTOK) {
printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size);
for (i = LISTDSW; i != YESW;) {
- if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl)))
+ if (!(argp = read_switch_multiword ("\nDisposition? ",
+ isdf ? aqrnl : aqrl)))
done (1);
switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) {
case NOSW:
if (querysw) {
snprintf (buffer, sizeof(buffer), "Reply to %s? ", adrformat (np));
- if (!gans (buffer, anoyes))
+ if (!read_switch (buffer, anoyes))
return 0;
}
mp->m_next = np;
if (interactive) {
cp = concat ("Remove folder \"", folder, "\"? ", NULL);
- if (!getanswer (cp))
+ if (!read_yes_or_no_if_tty (cp))
done (0);
free (cp);
}
adios (msgs[0], "unable to stat draft file");
cp = concat ("Use \"", msgs[0], "\"? ", NULL);
for (status = LISTDSW; status != YESW;) {
- if (!(argp = getans (cp, anyl)))
+ if (!(argp = read_switch_multiword (cp, anyl)))
done (1);
switch (status = smatch (*argp, anyl)) {
case NOSW:
if (addr == NULL)
addr = getusername ();
- if (user == NULL)
- user = (cp = strchr(addr, '.')) ? ++cp : addr;
+ if (user == NULL) {
+ user = getusername ();
+ }
if ((pw = getpwnam (user)) == NULL)
adios (NULL, "no such local user as %s", user);
snprintf (prompt, sizeof(prompt), myprompt, invo_name);
for (;;) {
#ifdef READLINE_SUPPORT
- if (!(argp = getans_via_readline (prompt, aleqs))) {
+ if (!(argp = read_switch_multiword_via_readline (prompt, aleqs))) {
#else /* ! READLINE_SUPPORT */
- if (!(argp = getans (prompt, aleqs))) {
+ if (!(argp = read_switch_multiword (prompt, aleqs))) {
#endif /* READLINE_SUPPORT */
(void) m_unlink (LINK);
done (1);