]> diplodocus.org Git - nmh/blobdiff - uip/prompter.c
Bump up size of two static char[] so gcc knows they won't overflow.
[nmh] / uip / prompter.c
index 304c9a5d7c01b80e17fb0a718acd7bd3b914a46d..303d2ad4a7f6be9e58bd4540f9f08ddee2ddc192 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * prompter.c -- simple prompting editor front-end
+/* prompter.c -- simple prompting editor front-end
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
 #include <h/mh.h>
 #include <fcntl.h>
 #include <h/signals.h>
+#include <h/utils.h>
+#include "../sbr/m_mktemp.h"
 #include <setjmp.h>
 
 #include <termios.h>
 
 #define        QUOTE '\\'
 
-#ifndef        CKILL
-# define CKILL '@'
-#endif
-
-#ifndef        CERASE
-# define CERASE '#'
-#endif
-
 #define PROMPTER_SWITCHES \
     X("erase chr", 0, ERASESW) \
     X("kill chr", 0, KILLSW) \
@@ -46,11 +38,7 @@ DEFINE_SWITCH_ENUM(PROMPTER);
 DEFINE_SWITCH_ARRAY(PROMPTER, switches);
 #undef X
 
-
 static struct termios tio;
-#define ERASE tio.c_cc[VERASE]
-#define KILL  tio.c_cc[VKILL]
-#define INTR  tio.c_cc[VINTR]
 
 static int wtuser = 0;
 static int sigint = 0;
@@ -59,7 +47,7 @@ static jmp_buf sigenv;
 /*
  * prototypes
  */
-int getln (char *, int);
+static int getln (char *, int);
 static int chrcnv (char *);
 static void chrdsp (char *, char);
 static void intrser (int);
@@ -71,14 +59,14 @@ main (int argc, char **argv)
     int body = 1, prepend = 1, rapid = 0;
     int doteof = 0, fdi, fdo, i, state;
     char *cp, *drft = NULL, *erasep = NULL;
-    char *killp = NULL, name[NAMESZ], field[BUFSIZ];
+    char *killp = NULL, name[NAMESZ], field[NMH_BUFSIZ];
     char buffer[BUFSIZ];
     char **arguments, **argp;
     FILE *in, *out;
     char *tmpfil;
     m_getfld_state_t gstate = 0;
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], 2)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -162,20 +150,20 @@ main (int argc, char **argv)
        tcgetattr(0, &tio);
 
        /* save original kill, erase character for later */
-       save_kill = KILL;
-       save_erase = ERASE;
+       save_kill = tio.c_cc[VKILL];
+       save_erase = tio.c_cc[VERASE];
 
        /* set new kill, erase character in terminal structure */
-       KILL = killp ? chrcnv (killp) : save_kill;
-       ERASE = erasep ? chrcnv (erasep) : save_erase;
+       tio.c_cc[VKILL] = killp ? chrcnv (killp) : save_kill;
+       tio.c_cc[VERASE] = erasep ? chrcnv (erasep) : save_erase;
 
        /* set the new terminal attributes */
         tcsetattr(0, TCSADRAIN, &tio);
 
        /* print out new kill erase characters */
-       chrdsp ("erase", ERASE);
-       chrdsp (", kill", KILL);
-       chrdsp (", intr", INTR);
+       chrdsp ("erase", tio.c_cc[VERASE]);
+       chrdsp (", kill", tio.c_cc[VKILL]);
+       chrdsp (", intr", tio.c_cc[VINTR]);
        putchar ('\n');
        fflush (stdout);
 
@@ -184,8 +172,8 @@ main (int argc, char **argv)
         * setup in terminal structure so we can easily
         * restore it upon exit.
         */
-       KILL = save_kill;
-       ERASE = save_erase;
+       tio.c_cc[VKILL] = save_kill;
+       tio.c_cc[VERASE] = save_erase;
     }
 
     sigint = 0;
@@ -214,8 +202,8 @@ main (int argc, char **argv)
                    while (state == FLDPLUS) {
                        fieldsz = sizeof field;
                        state = m_getfld (&gstate, name, field, &fieldsz, in);
-                       printf ("%s", field);
-                       fprintf (out, "%s", field);
+                       fputs(field, stdout);
+                       fputs(field, out);
                    }
                } else {
                    /* Else, get value of header field */
@@ -235,7 +223,7 @@ abort:
                        do {
                            if (field[0] != ' ' && field[0] != '\t')
                                putc (' ', out);
-                           fprintf (out, "%s", field);
+                           fputs(field, out);
                        } while (i == 1
                                    && (i = getln (field, sizeof(field))) >= 0);
                        if (i == -1)
@@ -251,7 +239,7 @@ abort:
                    break;
                fprintf (out, "--------\n");
                if (field[0] == 0 || !prepend)
-                   printf ("--------\n");
+                   puts("--------");
                if (field[0]) {
                    if (prepend && body) {
                        printf ("\n--------Enter initial text\n\n");
@@ -262,14 +250,14 @@ abort:
                                break;
                            if (buffer[0] == 0)
                                break;
-                           fprintf (out, "%s", buffer);
+                           fputs(buffer, out);
                        }
                    }
 
                    do {
-                       fprintf (out, "%s", field);
+                       fputs(field, out);
                        if (!rapid && !sigint)
-                           printf ("%s", field);
+                           fputs(field, stdout);
                    } while (state == BODY &&
                            (fieldsz = sizeof field,
                             state = m_getfld (&gstate, name, field, &fieldsz, in)));
@@ -286,7 +274,7 @@ abort:
                        break;
                    if (field[0] == 0)
                        break;
-                   fprintf (out, "%s", field);
+                   fputs(field, out);
                }
                break;
 
@@ -298,7 +286,7 @@ abort:
     m_getfld_state_destroy (&gstate);
 
     if (body)
-       printf ("--------\n");
+       puts("--------");
 
     fflush (stdout);
     fclose (in);
@@ -324,15 +312,14 @@ abort:
 }
 
 
-int
+static int
 getln (char *buffer, int n)
 {
     int c;
     char *cp;
     static int quoting = 0;
 
-    cp = buffer;
-    *cp = 0;
+    *buffer = 0;
 
     switch (setjmp (sigenv)) {
        case OK: 
@@ -348,6 +335,9 @@ getln (char *buffer, int n)
            return NOTOK;
     }
 
+    cp = buffer;
+    *cp = 0;
+
     for (;;) {
        switch (c = getchar ()) {
            case EOF: