]> diplodocus.org Git - nmh/blobdiff - uip/prompter.c
Started revising m_getfld() code to replace direct buffer
[nmh] / uip / prompter.c
index 7c28aeced74d7ba2db8bbff5ebe9cfc43b43aacf..6b540dbca49ee5e12a336d949b4e3bd5464cddcb 100644 (file)
 #include <signal.h>
 #include <setjmp.h>
 
-#ifdef HAVE_TERMIOS_H
-# include <termios.h>
-#else
-# ifdef HAVE_TERMIO_H
-#  include <termio.h>
-# else
-#  include <sgtty.h>
-# endif
-#endif
+#include <termios.h>
 
 #define        QUOTE '\\'
 
@@ -63,25 +55,10 @@ static struct swit switches[] = {
 };
 
 
-#ifdef HAVE_TERMIOS_H
 static struct termios tio;
-# define ERASE tio.c_cc[VERASE]
-# define KILL  tio.c_cc[VKILL]
-# define INTR  tio.c_cc[VINTR]
-#else
-# ifdef HAVE_TERMIO_H
-static struct termio tio;
-#  define ERASE tio.c_cc[VERASE]
-#  define KILL  tio.c_cc[VKILL]
-#  define INTR  tio.c_cc[VINTR]
-# else
-static struct sgttyb tio;
-static struct tchars tc;
-#  define ERASE tio.sg_erase
-#  define KILL  tio.sg_kill
-#  define INTR  tc.t_intrc
-# endif
-#endif
+#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;
@@ -93,7 +70,7 @@ static jmp_buf sigenv;
 int getln (char *, int);
 static int chrcnv (char *);
 static void chrdsp (char *, char);
-static RETSIGTYPE intrser (int);
+static void intrser (int);
 
 
 int
@@ -132,10 +109,10 @@ main (int argc, char **argv)
                    snprintf (buffer, sizeof(buffer), "%s [switches] file",
                        invo_name);
                    print_help (buffer, switches, 1);
-                   done (1);
+                   done (0);
                case VERSIONSW:
                    print_version(invo_name);
-                   done (1);
+                   done (0);
 
                case ERASESW: 
                    if (!(erasep = *argp++) || *erasep == '-')
@@ -193,23 +170,10 @@ main (int argc, char **argv)
      * Are we changing the kill or erase character?
      */
     if (killp || erasep) {
-#ifdef HAVE_TERMIOS_H
        cc_t save_erase, save_kill;
-#else
-       int save_erase, save_kill;
-#endif
 
        /* get the current terminal attributes */
-#ifdef HAVE_TERMIOS_H
        tcgetattr(0, &tio);
-#else
-# ifdef HAVE_TERMIO_H
-       ioctl(0, TCGETA, &tio);
-# else
-       ioctl (0, TIOCGETP, (char *) &tio);
-       ioctl (0, TIOCGETC, (char *) &tc);
-# endif
-#endif
 
        /* save original kill, erase character for later */
        save_kill = KILL;
@@ -220,15 +184,7 @@ main (int argc, char **argv)
        ERASE = erasep ? chrcnv (erasep) : save_erase;
 
        /* set the new terminal attributes */
-#ifdef HAVE_TERMIOS_H
         tcsetattr(0, TCSADRAIN, &tio);
-#else
-# ifdef HAVE_TERMIO_H
-       ioctl(0, TCSETAW, &tio);
-# else
-       ioctl (0, TIOCSETN, (char *) &tio);
-# endif
-#endif
 
        /* print out new kill erase characters */
        chrdsp ("erase", ERASE);
@@ -253,7 +209,8 @@ main (int argc, char **argv)
      * Loop through the lines of the draft skeleton.
      */
     for (state = FLD;;) {
-       switch (state = m_getfld (state, name, field, sizeof(field), in)) {
+       int fieldsz = sizeof field;
+       switch (state = m_getfld (state, name, field, &fieldsz, in)) {
            case FLD: 
            case FLDEOF: 
            case FLDPLUS: 
@@ -270,8 +227,8 @@ main (int argc, char **argv)
                    printf ("%s:%s", name, field);
                    fprintf (out, "%s:%s", name, field);
                    while (state == FLDPLUS) {
-                       state =
-                           m_getfld (state, name, field, sizeof(field), in);
+                       fieldsz = sizeof field;
+                       state = m_getfld (state, name, field, &fieldsz, in);
                        printf ("%s", field);
                        fprintf (out, "%s", field);
                    }
@@ -283,15 +240,7 @@ main (int argc, char **argv)
                    if (i == -1) {
 abort:
                        if (killp || erasep) {
-#ifdef HAVE_TERMIOS_H
                            tcsetattr(0, TCSADRAIN, &tio);
-#else
-# ifdef HAVE_TERMIO
-                           ioctl (0, TCSETA, &tio);
-# else
-                           ioctl (0, TIOCSETN, (char *) &tio);
-# endif
-#endif
                        }
                        unlink (tmpfil);
                        done (1);
@@ -345,7 +294,8 @@ abort:
                        if (!rapid && !sigint)
                            printf ("%s", field);
                    } while (state == BODY &&
-                           (state = m_getfld (state, name, field, sizeof(field), in)));
+                           (fieldsz = sizeof field,
+                            state = m_getfld (state, name, field, &fieldsz, in)));
                    if (prepend || !body)
                        break;
                    else
@@ -378,15 +328,7 @@ no_body:
     SIGNAL (SIGINT, SIG_IGN);
 
     if (killp || erasep) {
-#ifdef HAVE_TERMIOS_H
         tcsetattr(0, TCSADRAIN, &tio);
-#else
-# ifdef HAVE_TERMIO_H
-       ioctl (0, TCSETAW, &tio);
-# else
-       ioctl (0, TIOCSETN, (char *) &tio);
-# endif
-#endif
     }
 
     if ((fdi = open (tmpfil, O_RDONLY)) == NOTOK)
@@ -453,12 +395,10 @@ getln (char *buffer, int n)
 }
 
 
-static RETSIGTYPE
+static void
 intrser (int i)
 {
-#ifndef        RELIABLE_SIGNALS
-    SIGNAL (SIGINT, intrser);
-#endif
+    NMH_UNUSED (i);
 
     if (wtuser)
        longjmp (sigenv, NOTOK);