]> diplodocus.org Git - nmh/blobdiff - uip/prompter.c
Print pointers in debug with C99's `%p' rather than `0x%x'.
[nmh] / uip / prompter.c
index 0532c2194d2dfc5b666b27522c1f38b50e49fb18..878b2b43b775c38718306695f647cfdfa8f17df1 100644 (file)
@@ -8,6 +8,7 @@
 #include <h/mh.h>
 #include <fcntl.h>
 #include <h/signals.h>
 #include <h/mh.h>
 #include <fcntl.h>
 #include <h/signals.h>
+#include <h/utils.h>
 #include "../sbr/m_mktemp.h"
 #include <setjmp.h>
 
 #include "../sbr/m_mktemp.h"
 #include <setjmp.h>
 
 
 #define        QUOTE '\\'
 
 
 #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) \
 #define PROMPTER_SWITCHES \
     X("erase chr", 0, ERASESW) \
     X("kill chr", 0, KILLSW) \
@@ -45,11 +38,7 @@ DEFINE_SWITCH_ENUM(PROMPTER);
 DEFINE_SWITCH_ARRAY(PROMPTER, switches);
 #undef X
 
 DEFINE_SWITCH_ARRAY(PROMPTER, switches);
 #undef X
 
-
 static struct termios tio;
 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;
 
 static int wtuser = 0;
 static int sigint = 0;
@@ -58,7 +47,7 @@ static jmp_buf sigenv;
 /*
  * prototypes
  */
 /*
  * prototypes
  */
-int getln (char *, int);
+static int getln (char *, int);
 static int chrcnv (char *);
 static void chrdsp (char *, char);
 static void intrser (int);
 static int chrcnv (char *);
 static void chrdsp (char *, char);
 static void intrser (int);
@@ -75,7 +64,7 @@ main (int argc, char **argv)
     char **arguments, **argp;
     FILE *in, *out;
     char *tmpfil;
     char **arguments, **argp;
     FILE *in, *out;
     char *tmpfil;
-    m_getfld_state_t gstate = 0;
+    m_getfld_state_t gstate;
 
     if (nmh_init(argv[0], 2)) { return 1; }
 
 
     if (nmh_init(argv[0], 2)) { return 1; }
 
@@ -161,20 +150,20 @@ main (int argc, char **argv)
        tcgetattr(0, &tio);
 
        /* save original kill, erase character for later */
        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 */
 
        /* 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 */
 
        /* 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);
 
        putchar ('\n');
        fflush (stdout);
 
@@ -183,8 +172,8 @@ main (int argc, char **argv)
         * setup in terminal structure so we can easily
         * restore it upon exit.
         */
         * 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;
     }
 
     sigint = 0;
@@ -193,9 +182,10 @@ main (int argc, char **argv)
     /*
      * Loop through the lines of the draft skeleton.
      */
     /*
      * Loop through the lines of the draft skeleton.
      */
+    gstate = m_getfld_state_init(in);
     for (;;) {
        int fieldsz = sizeof field;
     for (;;) {
        int fieldsz = sizeof field;
-       switch (state = m_getfld (&gstate, name, field, &fieldsz, in)) {
+       switch (state = m_getfld2(&gstate, name, field, &fieldsz)) {
            case FLD: 
            case FLDPLUS: 
                /*
            case FLD: 
            case FLDPLUS: 
                /*
@@ -212,7 +202,7 @@ main (int argc, char **argv)
                    fprintf (out, "%s:%s", name, field);
                    while (state == FLDPLUS) {
                        fieldsz = sizeof field;
                    fprintf (out, "%s:%s", name, field);
                    while (state == FLDPLUS) {
                        fieldsz = sizeof field;
-                       state = m_getfld (&gstate, name, field, &fieldsz, in);
+                       state = m_getfld2(&gstate, name, field, &fieldsz);
                        fputs(field, stdout);
                        fputs(field, out);
                    }
                        fputs(field, stdout);
                        fputs(field, out);
                    }
@@ -271,11 +261,10 @@ abort:
                            fputs(field, stdout);
                    } while (state == BODY &&
                            (fieldsz = sizeof field,
                            fputs(field, stdout);
                    } while (state == BODY &&
                            (fieldsz = sizeof field,
-                            state = m_getfld (&gstate, name, field, &fieldsz, in)));
+                            state = m_getfld2(&gstate, name, field, &fieldsz)));
                    if (prepend || !body)
                        break;
                    if (prepend || !body)
                        break;
-                   else
-                       printf ("\n--------Enter additional text\n\n");
+                    printf ("\n--------Enter additional text\n\n");
                }
 
                fflush (stdout);
                }
 
                fflush (stdout);
@@ -323,7 +312,7 @@ abort:
 }
 
 
 }
 
 
-int
+static int
 getln (char *buffer, int n)
 {
     int c;
 getln (char *buffer, int n)
 {
     int c;