]> diplodocus.org Git - nmh/blobdiff - uip/prompter.c
showfile.c: Move interface to own file.
[nmh] / uip / prompter.c
index 6dcf3bb0f28b8f838774acbc8b4adf4c70faacab..d91173f22814178f0b4b025b552e62a58db3e955 100644 (file)
@@ -5,11 +5,19 @@
  * complete copyright information.
  */
 
-#include <h/mh.h>
+#include "h/mh.h"
+#include "sbr/smatch.h"
+#include "sbr/cpydata.h"
+#include "sbr/m_atoi.h"
+#include "sbr/context_save.h"
+#include "sbr/ambigsw.h"
+#include "sbr/print_version.h"
+#include "sbr/print_help.h"
+#include "sbr/error.h"
 #include <fcntl.h>
-#include <h/signals.h>
+#include "h/signals.h"
 #include "h/done.h"
-#include <h/utils.h>
+#include "h/utils.h"
 #include "sbr/m_mktemp.h"
 #include <setjmp.h>
 
@@ -41,8 +49,8 @@ DEFINE_SWITCH_ARRAY(PROMPTER, switches);
 
 static struct termios tio;
 
-static int wtuser = 0;
-static int sigint = 0;
+static bool wtuser;
+static bool sigint;
 static jmp_buf sigenv;
 
 /*
@@ -57,8 +65,11 @@ static void intrser (int);
 int
 main (int argc, char **argv)
 {
-    int body = 1, prepend = 1, rapid = 0;
-    int doteof = 0, fdi, fdo, i, state;
+    bool body = true;
+    bool prepend = true;
+    bool rapid = false;
+    bool doteof = false;
+    int fdi, fdo, i, state;
     char *cp, *drft = NULL, *erasep = NULL;
     char *killp = NULL, name[NAMESZ], field[NMH_BUFSIZ];
     char buffer[BUFSIZ];
@@ -100,31 +111,31 @@ main (int argc, char **argv)
                    continue;
 
                case PREPSW: 
-                   prepend++;
+                   prepend = true;
                    continue;
                case NPREPSW: 
-                   prepend = 0;
+                   prepend = false;
                    continue;
 
                case RAPDSW: 
-                   rapid++;
+                   rapid = true;
                    continue;
                case NRAPDSW: 
-                   rapid = 0;
+                   rapid = false;
                    continue;
 
                case BODYSW: 
-                   body++;
+                   body = true;
                    continue;
                case NBODYSW: 
-                   body = 0;
+                   body = false;
                    continue;
 
                case DOTSW: 
-                   doteof++;
+                   doteof = true;
                    continue;
                case NDOTSW: 
-                   doteof = 0;
+                   doteof = false;
                    continue;
            }
        } else {
@@ -177,7 +188,7 @@ main (int argc, char **argv)
        tio.c_cc[VERASE] = save_erase;
     }
 
-    sigint = 0;
+    sigint = false;
     SIGNAL2 (SIGINT, intrser);
 
     /*
@@ -318,21 +329,21 @@ getln (char *buffer, int n)
 {
     int c;
     char *cp;
-    static int quoting = 0;
+    static bool quoting;
 
     *buffer = 0;
 
     switch (setjmp (sigenv)) {
        case OK: 
-           wtuser = 1;
+           wtuser = true;
            break;
 
        case DONE: 
-           wtuser = 0;
+           wtuser = false;
            return 0;
 
        default: 
-           wtuser = 0;
+           wtuser = false;
            return NOTOK;
     }
 
@@ -342,27 +353,27 @@ getln (char *buffer, int n)
     for (;;) {
        switch (c = getchar ()) {
            case EOF: 
-               quoting = 0;
+               quoting = false;
                clearerr (stdin);
                longjmp (sigenv, DONE);
 
            case '\n': 
                if (quoting) {
                    *(cp - 1) = c;
-                   quoting = 0;
-                   wtuser = 0;
+                   quoting = false;
+                   wtuser = false;
                    return 1;
                }
                *cp++ = c;
                *cp = 0;
-               wtuser = 0;
+               wtuser = false;
                return 0;
 
            default: 
                if (c == QUOTE) {
-                   quoting = 1;
+                   quoting = true;
                } else {
-                   quoting = 0;
+                   quoting = false;
                }
                if (cp < buffer + n)
                    *cp++ = c;
@@ -379,7 +390,7 @@ intrser (int i)
 
     if (wtuser)
        longjmp (sigenv, NOTOK);
-    sigint++;
+    sigint = true;
 }