From: David Levine Date: Sun, 26 Jun 2016 01:16:36 +0000 (-0400) Subject: Merge remote-tracking branch 'origin' into xoauth X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/23f2b007ecac94848616420b27f0819ea559507e?hp=c546ef90ba8ca862494086de6e754cebe207299b Merge remote-tracking branch 'origin' into xoauth --- diff --git a/Makefile.am b/Makefile.am index 2ec9d5ce..de88060c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -490,6 +490,10 @@ uip_viamail_LDADD = $(LDADD) $(POSTLINK) test_getfullname_SOURCES = test/getfullname.c test_getfullname_LDADD = $(LDADD) $(POSTLINK) +## +## Other program definitions +## + test_getcanon_SOURCES = test/getcanon.c test_getcanon_LDADD = $(POSTLINK) @@ -517,6 +521,7 @@ docs_contrib_sendfrom_LDADD = $(LDADD) $(TERMLIB) $(CURLLIB) $(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 @@ -601,10 +606,11 @@ sbr_libmh_a_SOURCES = sbr/addrsbr.c sbr/ambigsw.c sbr/atooi.c sbr/arglist.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 \ @@ -628,8 +634,8 @@ sbr_libmh_a_SOURCES = sbr/addrsbr.c sbr/ambigsw.c sbr/atooi.c sbr/arglist.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 ## diff --git a/h/prototypes.h b/h/prototypes.h index fc969094..782939be 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -26,7 +26,7 @@ char **argsplit (char *, char **, int *); 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 *); @@ -118,12 +118,44 @@ int folder_pack (struct msgs **, int); 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); /* @@ -247,7 +279,7 @@ void m_popen(char *name, int savestdout); 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); /* @@ -282,7 +314,7 @@ int pidwait (pid_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); @@ -328,7 +360,7 @@ void seq_setcur (struct msgs *, int); 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. @@ -363,7 +395,7 @@ int smatch(char *, struct swit *); * 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 *); diff --git a/man/slocal.man b/man/slocal.man index 53f9314a..6c8e4909 100644 --- a/man/slocal.man +++ b/man/slocal.man @@ -1,4 +1,4 @@ -.TH SLOCAL %manext1% "November 23, 2012" "%nmhversion%" +.TH SLOCAL %manext1% "May 2, 2016" "%nmhversion%" .\" .\" %nmhwarning% .\" @@ -76,7 +76,7 @@ The 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 @@ -383,8 +383,14 @@ quicker delivery into your maildrop. .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 diff --git a/sbr/ambigsw.c b/sbr/ambigsw.c index c11b9e75..15ff34cb 100644 --- a/sbr/ambigsw.c +++ b/sbr/ambigsw.c @@ -11,7 +11,7 @@ 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); diff --git a/sbr/context_read.c b/sbr/context_read.c index 80340688..de14b0d5 100644 --- a/sbr/context_read.c +++ b/sbr/context_read.c @@ -107,7 +107,7 @@ context_read (void) 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); diff --git a/sbr/makedir.c b/sbr/makedir.c index 562949be..6d3f0dc3 100644 --- a/sbr/makedir.c +++ b/sbr/makedir.c @@ -15,7 +15,7 @@ #include int -makedir (char *dir) +makedir (const char *dir) { char path[PATH_MAX]; char* folder_perms_ASCII; diff --git a/sbr/print_sw.c b/sbr/print_sw.c index 6d475aba..d790db69 100644 --- a/sbr/print_sw.c +++ b/sbr/print_sw.c @@ -11,7 +11,7 @@ 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; diff --git a/sbr/read_line.c b/sbr/read_line.c new file mode 100644 index 00000000..35d71a7a --- /dev/null +++ b/sbr/read_line.c @@ -0,0 +1,16 @@ +#include + +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; +} + diff --git a/sbr/gans.c b/sbr/read_switch.c similarity index 84% rename from sbr/gans.c rename to sbr/read_switch.c index 70234029..4599a41c 100644 --- a/sbr/gans.c +++ b/sbr/read_switch.c @@ -1,6 +1,6 @@ /* - * 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 @@ -11,11 +11,11 @@ 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 (;;) { diff --git a/sbr/getans.c b/sbr/read_switch_multiword.c similarity index 92% rename from sbr/getans.c rename to sbr/read_switch_multiword.c index 0800a3c0..f653a7fe 100644 --- a/sbr/getans.c +++ b/sbr/read_switch_multiword.c @@ -1,6 +1,6 @@ /* - * 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 @@ -21,7 +21,7 @@ static void intrser (int); char ** -getans (char *prompt, struct swit *ansp) +read_switch_multiword (const char *prompt, const struct swit *ansp) { int i; SIGNAL_HANDLER istat = NULL; diff --git a/sbr/getansreadline.c b/sbr/read_switch_multiword_via_readline.c similarity index 93% rename from sbr/getansreadline.c rename to sbr/read_switch_multiword_via_readline.c index 5d80dd97..570469bd 100644 --- a/sbr/getansreadline.c +++ b/sbr/read_switch_multiword_via_readline.c @@ -1,6 +1,6 @@ /* - * 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 @@ -26,7 +26,7 @@ static char ansbuf[BUFSIZ]; */ char ** -getans_via_readline(char *prompt, struct swit *ansp) +read_switch_multiword_via_readline(char *prompt, struct swit *ansp) { char *ans, **cpp; diff --git a/sbr/getanswer.c b/sbr/read_yes_or_no_if_tty.c similarity index 65% rename from sbr/getanswer.c rename to sbr/read_yes_or_no_if_tty.c index 73922158..07f1122a 100644 --- a/sbr/getanswer.c +++ b/sbr/read_yes_or_no_if_tty.c @@ -1,6 +1,6 @@ /* - * 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 @@ -11,12 +11,12 @@ 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); } diff --git a/sbr/smatch.c b/sbr/smatch.c index 4d1d3d68..8ec6e3f2 100644 --- a/sbr/smatch.c +++ b/sbr/smatch.c @@ -11,11 +11,11 @@ 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; diff --git a/sbr/ssequal.c b/sbr/ssequal.c index 5ccf28fd..cb765203 100644 --- a/sbr/ssequal.c +++ b/sbr/ssequal.c @@ -23,7 +23,7 @@ */ int -ssequal (char *s1, char *s2) +ssequal (const char *s1, const char *s2) { if (!s1) s1 = ""; diff --git a/sbr/utils.c b/sbr/utils.c index c6f75e07..6ab5f534 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -200,7 +200,7 @@ void create_folder(char *folder, int autocreate, void (*done_callback)(int)) 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) { diff --git a/test/slocal/test-slocal b/test/slocal/test-slocal index 08eb1a80..3fb73b24 100755 --- a/test/slocal/test-slocal +++ b/test/slocal/test-slocal @@ -143,19 +143,23 @@ run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/5 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" <"$md" <"$md" <"$md" <"$md" <"$md" <eb_flags) { @@ -2770,7 +2770,7 @@ openMail (CT ct, char **file) 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; diff --git a/uip/mhstoresbr.c b/uip/mhstoresbr.c index 62b2f4af..62a5ba43 100644 --- a/uip/mhstoresbr.c +++ b/uip/mhstoresbr.c @@ -1285,7 +1285,7 @@ clobber_check (char *original_file, mhstoreinfo_t info) { 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. */ diff --git a/uip/packf.c b/uip/packf.c index 30f0f484..d8e037db 100644 --- a/uip/packf.c +++ b/uip/packf.c @@ -111,7 +111,7 @@ main (int argc, char **argv) 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); } diff --git a/uip/repl.c b/uip/repl.c index ebe72ff2..5686b5bf 100644 --- a/uip/repl.c +++ b/uip/repl.c @@ -370,7 +370,8 @@ try_it_again: 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: diff --git a/uip/replsbr.c b/uip/replsbr.c index c4ca0c4b..6380884c 100644 --- a/uip/replsbr.c +++ b/uip/replsbr.c @@ -402,7 +402,7 @@ insert (struct mailname *np) 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; diff --git a/uip/rmf.c b/uip/rmf.c index c7e6426c..f714c472 100644 --- a/uip/rmf.c +++ b/uip/rmf.c @@ -103,7 +103,7 @@ main (int argc, char **argv) if (interactive) { cp = concat ("Remove folder \"", folder, "\"? ", NULL); - if (!getanswer (cp)) + if (!read_yes_or_no_if_tty (cp)) done (0); free (cp); } diff --git a/uip/send.c b/uip/send.c index a623964f..03a54698 100644 --- a/uip/send.c +++ b/uip/send.c @@ -333,7 +333,7 @@ main (int argc, char **argv) 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: diff --git a/uip/slocal.c b/uip/slocal.c index a26432c5..927e8583 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -273,8 +273,9 @@ main (int argc, char **argv) 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); diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index 21988791..d0423f53 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -237,9 +237,9 @@ WhatNow (int argc, char **argv) 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);