Removed the space between function names and the opening parenthesis.
[mmh] / uip / prompter.c
index f92eda1..a75c563 100644 (file)
@@ -1,10 +1,10 @@
 /*
- * 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
- * complete copyright information.
- */
+** 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
+** complete copyright information.
+*/
 
 #include <h/mh.h>
 #include <fcntl.h>
@@ -87,16 +87,16 @@ static int sigint = 0;
 static jmp_buf sigenv;
 
 /*
- * prototypes
- */
-int getln (char *, int);
-static int chrcnv (char *);
-static void chrdsp (char *, char);
-static RETSIGTYPE intrser (int);
+** prototypes
+*/
+int getln(char *, int);
+static int chrcnv(char *);
+static void chrdsp(char *, char);
+static RETSIGTYPE intrser(int);
 
 
 int
-main (int argc, char **argv)
+main(int argc, char **argv)
 {
        int body = 1, prepend = 1, rapid = 0;
        int doteof = 0, fdi, fdo, i, state;
@@ -110,39 +110,40 @@ main (int argc, char **argv)
 #ifdef LOCALE
        setlocale(LC_ALL, "");
 #endif
-       invo_name = r1bindex (argv[0], '/');
+       invo_name = r1bindex(argv[0], '/');
 
        /* read user profile/context */
        context_read();
 
-       arguments = getarguments (invo_name, argc, argv, 1);
+       arguments = getarguments(invo_name, argc, argv, 1);
        argp = arguments;
 
        while ((cp = *argp++))
                if (*cp == '-') {
-                       switch (smatch (++cp, switches)) {
+                       switch (smatch(++cp, switches)) {
                                case AMBIGSW:
-                                       ambigsw (cp, switches);
-                                       done (1);
+                                       ambigsw(cp, switches);
+                                       done(1);
                                case UNKWNSW:
-                                       adios (NULL, "-%s unknown", cp);
+                                       adios(NULL, "-%s unknown", cp);
 
                                case HELPSW:
-                                       snprintf (buffer, sizeof(buffer), "%s [switches] file",
-                                               invo_name);
-                                       print_help (buffer, switches, 1);
-                                       done (1);
+                                       snprintf(buffer, sizeof(buffer),
+                                                       "%s [switches] file",
+                                                       invo_name);
+                                       print_help(buffer, switches, 1);
+                                       done(1);
                                case VERSIONSW:
                                        print_version(invo_name);
-                                       done (1);
+                                       done(1);
 
                                case ERASESW:
                                        if (!(erasep = *argp++) || *erasep == '-')
-                                               adios (NULL, "missing argument to %s", argp[-2]);
+                                               adios(NULL, "missing argument to %s", argp[-2]);
                                        continue;
                                case KILLSW:
                                        if (!(killp = *argp++) || *killp == '-')
-                                               adios (NULL, "missing argument to %s", argp[-2]);
+                                               adios(NULL, "missing argument to %s", argp[-2]);
                                        continue;
 
                                case PREPSW:
@@ -173,24 +174,24 @@ main (int argc, char **argv)
                                        doteof = 0;
                                        continue;
                        }
-               } else {
-                       if (!drft)
-                               drft = cp;
+               } else if (!drft) {
+                       drft = cp;
                }
 
        if (!drft)
-               adios (NULL, "usage: %s [switches] file", invo_name);
-       if ((in = fopen (drft, "r")) == NULL)
-               adios (drft, "unable to open");
+               adios(NULL, "usage: %s [switches] file", invo_name);
+       if ((in = fopen(drft, "r")) == NULL)
+               adios(drft, "unable to open");
 
        tfile = m_mktemp2(NULL, invo_name, NULL, &out);
-       if (tfile == NULL) adios("prompter", "unable to create temporary file");
-       chmod (tmpfil, 0600);
-       strncpy (tmpfil, tfile, sizeof(tmpfil));
+       if (tfile == NULL)
+               adios("prompter", "unable to create temporary file");
+       chmod(tmpfil, 0600);
+       strncpy(tmpfil, tfile, sizeof(tmpfil));
 
        /*
-        * Are we changing the kill or erase character?
-        */
+       ** Are we changing the kill or erase character?
+       */
        if (killp || erasep) {
 #ifdef HAVE_TERMIOS_H
                cc_t save_erase, save_kill;
@@ -205,8 +206,8 @@ main (int argc, char **argv)
 # ifdef HAVE_TERMIO_H
                ioctl(0, TCGETA, &tio);
 # else
-               ioctl (0, TIOCGETP, (char *) &tio);
-               ioctl (0, TIOCGETC, (char *) &tc);
+               ioctl(0, TIOCGETP, (char *) &tio);
+               ioctl(0, TIOCGETC, (char *) &tc);
 # endif
 #endif
 
@@ -215,8 +216,8 @@ main (int argc, char **argv)
                save_erase = ERASE;
 
                /* set new kill, erase character in terminal structure */
-               KILL = killp ? chrcnv (killp) : save_kill;
-               ERASE = erasep ? chrcnv (erasep) : save_erase;
+               KILL = killp ? chrcnv(killp) : save_kill;
+               ERASE = erasep ? chrcnv(erasep) : save_erase;
 
                /* set the new terminal attributes */
 #ifdef HAVE_TERMIOS_H
@@ -225,60 +226,60 @@ main (int argc, char **argv)
 # ifdef HAVE_TERMIO_H
                ioctl(0, TCSETAW, &tio);
 # else
-               ioctl (0, TIOCSETN, (char *) &tio);
+               ioctl(0, TIOCSETN, (char *) &tio);
 # endif
 #endif
 
                /* print out new kill erase characters */
-               chrdsp ("erase", ERASE);
-               chrdsp (", kill", KILL);
-               chrdsp (", intr", INTR);
-               putchar ('\n');
-               fflush (stdout);
+               chrdsp("erase", ERASE);
+               chrdsp(", kill", KILL);
+               chrdsp(", intr", INTR);
+               putchar('\n');
+               fflush(stdout);
 
                /*
-                * We set the kill and erase character back to original
-                * setup in terminal structure so we can easily
-                * restore it upon exit.
-                */
+               ** We set the kill and erase character back to original
+               ** setup in terminal structure so we can easily
+               ** restore it upon exit.
+               */
                KILL = save_kill;
                ERASE = save_erase;
        }
 
        sigint = 0;
-       SIGNAL2 (SIGINT, intrser);
+       SIGNAL2(SIGINT, intrser);
 
        /*
-        * Loop through the lines of the draft skeleton.
-        */
+       ** Loop through the lines of the draft skeleton.
+       */
        for (state = FLD;;) {
-               switch (state = m_getfld (state, name, field, sizeof(field), in)) {
+               switch (state = m_getfld(state, name, field, sizeof(field),
+                               in)) {
                        case FLD:
                        case FLDEOF:
                        case FLDPLUS:
                                /*
-                                * Check if the value of field contains anything
-                                * other than space or tab.
-                                */
+                               ** Check if the value of field contains
+                               ** anything other than space or tab.
+                               */
                                for (cp = field; *cp; cp++)
                                        if (*cp != ' ' && *cp != '\t')
                                                break;
 
                                /* If so, just add header line to draft */
                                if (*cp++ != '\n' || *cp != 0) {
-                                       printf ("%s:%s", name, field);
-                                       fprintf (out, "%s:%s", name, field);
+                                       printf("%s:%s", name, field);
+                                       fprintf(out, "%s:%s", name, field);
                                        while (state == FLDPLUS) {
-                                               state =
-                                                       m_getfld (state, name, field, sizeof(field), in);
-                                               printf ("%s", field);
-                                               fprintf (out, "%s", field);
+                                               state = m_getfld(state, name, field, sizeof(field), in);
+                                               printf("%s", field);
+                                               fprintf(out, "%s", field);
                                        }
                                } else {
                                        /* Else, get value of header field */
-                                       printf ("%s: ", name);
-                                       fflush (stdout);
-                                       i = getln (field, sizeof(field));
+                                       printf("%s: ", name);
+                                       fflush(stdout);
+                                       i = getln(field, sizeof(field));
                                        if (i == -1) {
 abort:
                                                if (killp || erasep) {
@@ -286,31 +287,30 @@ abort:
                                                        tcsetattr(0, TCSADRAIN, &tio);
 #else
 # ifdef HAVE_TERMIO
-                                                       ioctl (0, TCSETA, &tio);
+                                                       ioctl(0, TCSETA, &tio);
 # else
-                                                       ioctl (0, TIOCSETN, (char *) &tio);
+                                                       ioctl(0, TIOCSETN, (char *) &tio);
 # endif
 #endif
                                                }
-                                               unlink (tmpfil);
-                                               done (1);
+                                               unlink(tmpfil);
+                                               done(1);
                                        }
                                        if (i != 0 || (field[0] != '\n' && field[0] != 0)) {
-                                               fprintf (out, "%s:", name);
+                                               fprintf(out, "%s:", name);
                                                do {
                                                        if (field[0] != ' ' && field[0] != '\t')
-                                                               putc (' ', out);
-                                                       fprintf (out, "%s", field);
-                                               } while (i == 1
-                                                                       && (i = getln (field, sizeof(field))) >= 0);
+                                                               putc(' ', out);
+                                                       fprintf(out, "%s", field);
+                                               } while (i == 1 && (i = getln(field, sizeof(field))) >= 0);
                                                if (i == -1)
                                                        goto abort;
                                        }
                                }
 
                                if (state == FLDEOF) {  /* moby hack */
-                                       fprintf (out, "--------\n");
-                                       printf ("--------\n");
+                                       fprintf(out, "--------\n");
+                                       printf("--------\n");
                                        if (!body)
                                                break;
                                        goto no_body;
@@ -322,89 +322,89 @@ abort:
                        case FILEEOF:
                                if (!body)
                                        break;
-                               fprintf (out, "--------\n");
+                               fprintf(out, "--------\n");
                                if (field[0] == 0 || !prepend)
-                                       printf ("--------\n");
+                                       printf("--------\n");
                                if (field[0]) {
                                        if (prepend && body) {
-                                               printf ("\n--------Enter initial text\n\n");
-                                               fflush (stdout);
+                                               printf("\n--------Enter initial text\n\n");
+                                               fflush(stdout);
                                                for (;;) {
-                                                       getln (buffer, sizeof(buffer));
+                                                       getln(buffer, sizeof(buffer));
                                                        if (doteof && buffer[0] == '.' && buffer[1] == '\n')
                                                                break;
                                                        if (buffer[0] == 0)
                                                                break;
-                                                       fprintf (out, "%s", buffer);
+                                                       fprintf(out, "%s", buffer);
                                                }
                                        }
 
                                        do {
-                                               fprintf (out, "%s", field);
+                                               fprintf(out, "%s", field);
                                                if (!rapid && !sigint)
-                                                       printf ("%s", field);
+                                                       printf("%s", field);
                                        } while (state == BODY &&
-                                                       (state = m_getfld (state, name, field, sizeof(field), in)));
+                                                       (state = m_getfld(state, name, field, sizeof(field), in)));
                                        if (prepend || !body)
                                                break;
                                        else
                                                printf ("\n--------Enter additional text\n\n");
                                }
 no_body:
-                               fflush (stdout);
+                               fflush(stdout);
                                for (;;) {
-                                       getln (field, sizeof(field));
+                                       getln(field, sizeof(field));
                                        if (doteof && field[0] == '.' && field[1] == '\n')
                                                break;
                                        if (field[0] == 0)
                                                break;
-                                        fprintf (out, "%s", field);
+                                        fprintf(out, "%s", field);
                                }
                                break;
 
                        default:
-                               adios (NULL, "skeleton is poorly formatted");
+                               adios(NULL, "skeleton is poorly formatted");
                }
                break;
        }
 
        if (body)
-               printf ("--------\n");
+               printf("--------\n");
 
-       fflush (stdout);
-       fclose (in);
-       fclose (out);
-       SIGNAL (SIGINT, SIG_IGN);
+       fflush(stdout);
+       fclose(in);
+       fclose(out);
+       SIGNAL(SIGINT, SIG_IGN);
 
        if (killp || erasep) {
 #ifdef HAVE_TERMIOS_H
                 tcsetattr(0, TCSADRAIN, &tio);
 #else
 # ifdef HAVE_TERMIO_H
-               ioctl (0, TCSETAW, &tio);
+               ioctl(0, TCSETAW, &tio);
 # else
-               ioctl (0, TIOCSETN, (char *) &tio);
+               ioctl(0, TIOCSETN, (char *) &tio);
 # endif
 #endif
        }
 
-       if ((fdi = open (tmpfil, O_RDONLY)) == NOTOK)
-               adios (tmpfil, "unable to re-open");
-       if ((fdo = creat (drft, m_gmprot ())) == NOTOK)
-               adios (drft, "unable to write");
-       cpydata (fdi, fdo, tmpfil, drft);
-       close (fdi);
-       close (fdo);
-       unlink (tmpfil);
-
-       context_save ();  /* save the context file */
-       done (0);
+       if ((fdi = open(tmpfil, O_RDONLY)) == NOTOK)
+               adios(tmpfil, "unable to re-open");
+       if ((fdo = creat(drft, m_gmprot())) == NOTOK)
+               adios(drft, "unable to write");
+       cpydata(fdi, fdo, tmpfil, drft);
+       close(fdi);
+       close(fdo);
+       unlink(tmpfil);
+
+       context_save();  /* save the context file */
+       done(0);
        return 1;
 }
 
 
 int
-getln (char *buffer, int n)
+getln(char *buffer, int n)
 {
        int c;
        char *cp;
@@ -412,7 +412,7 @@ getln (char *buffer, int n)
        cp = buffer;
        *cp = 0;
 
-       switch (setjmp (sigenv)) {
+       switch (setjmp(sigenv)) {
                case OK:
                        wtuser = 1;
                        break;
@@ -427,10 +427,10 @@ getln (char *buffer, int n)
        }
 
        for (;;) {
-               switch (c = getchar ()) {
+               switch (c = getchar()) {
                        case EOF:
-                               clearerr (stdin);
-                               longjmp (sigenv, DONE);
+                               clearerr(stdin);
+                               longjmp(sigenv, DONE);
 
                        case '\n':
                                if (cp[-1] == QUOTE) {
@@ -453,31 +453,31 @@ getln (char *buffer, int n)
 
 
 static RETSIGTYPE
-intrser (int i)
+intrser(int i)
 {
 #ifndef RELIABLE_SIGNALS
-       SIGNAL (SIGINT, intrser);
+       SIGNAL(SIGINT, intrser);
 #endif
 
        if (wtuser)
-               longjmp (sigenv, NOTOK);
+               longjmp(sigenv, NOTOK);
        sigint++;
 }
 
 
 static int
-chrcnv (char *cp)
+chrcnv(char *cp)
 {
-       return (*cp != QUOTE ? *cp : m_atoi (++cp));
+       return (*cp != QUOTE ? *cp : m_atoi(++cp));
 }
 
 
 static void
-chrdsp (char *s, char c)
+chrdsp(char *s, char c)
 {
-       printf ("%s ", s);
+       printf("%s ", s);
        if (c < ' ' || c == 0177)
-               printf ("^%c", c ^ 0100);
+               printf("^%c", c ^ 0100);
        else
-               printf ("%c", c);
+               printf("%c", c);
 }