sbr/folder_read.c sbr/folder_realloc.c sbr/gans.c \
sbr/getans.c sbr/getanswer.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 \
void add_profile_entry (const char *, const char *);
void adios (char *, char *, ...) NORETURN;
void admonish (char *, char *, ...);
-void advertise (char *, char *, char *, va_list);
-void advise (char *, char *, ...);
+void advertise (const char *, char *, char *, va_list);
+void advise (const char *, char *, ...);
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 *);
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 *);
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);
* print out error message
*/
void
-advise (char *what, char *fmt, ...)
+advise (const char *what, char *fmt, ...)
{
va_list ap;
* main routine for printing error messages.
*/
void
-advertise (char *what, char *tail, char *fmt, va_list ap)
+advertise (const char *what, char *tail, char *fmt, va_list ap)
{
int eindex = errno;
char buffer[BUFSIZ], err[BUFSIZ];
if (*what) {
iov->iov_len = strlen (iov->iov_base = " ");
iov++;
- iov->iov_len = strlen (iov->iov_base = what);
+ iov->iov_len = strlen (iov->iov_base = (void*)what);
iov++;
iov->iov_len = strlen (iov->iov_base = ": ");
iov++;
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;
+ const register struct swit *ap;
char ansbuf[BUFSIZ];
for (;;) {
char **
-getans (char *prompt, struct swit *ansp)
+read_switch_multiword (const char *prompt, const struct swit *ansp)
{
int i;
SIGNAL_HANDLER istat = NULL;
*/
char **
-getans_via_readline(char *prompt, struct swit *ansp)
+read_switch_multiword_via_readline(char *prompt, struct swit *ansp)
{
char *ans, **cpp;
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);
}
#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;
+}
+
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) {
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:
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);