]> diplodocus.org Git - nmh/commitdiff
uip/scansbr.c: Add PUTC() macro, similar to FPUTS().
authorRalph Corderoy <ralph@inputplus.co.uk>
Mon, 29 May 2017 11:23:38 +0000 (12:23 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Mon, 29 May 2017 11:23:38 +0000 (12:23 +0100)
FPUTS() exists, but all the putc(3) checks for error were written
alongside in longhand.  May as well have a PUTC() to match, though
perhaps just the existing check of the FILE's sticky error state with
ferror(3) is sufficient and neither macro is required.

uip/scansbr.c

index a62faf2..df9ef64 100644 (file)
@@ -26,6 +26,10 @@ static m_getfld_state_t gstate;              /* for accessor functions below    */
 
 #define DIEWRERR() adios (scnmsg, "write error on")
 
 
 #define DIEWRERR() adios (scnmsg, "write error on")
 
+#define PUTC(c) \
+    if (putc((c), scnout) == EOF) \
+        DIEWRERR();
+
 #define FPUTS(buf) {\
                if (fputs(buf,scnout) == EOF)\
                    DIEWRERR();\
 #define FPUTS(buf) {\
                if (fputs(buf,scnout) == EOF)\
                    DIEWRERR();\
@@ -169,7 +173,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
                compnum++;
                if (scnout) {
                    FPUTS (name);
                compnum++;
                if (scnout) {
                    FPUTS (name);
-                   if ( putc (':', scnout) == EOF) DIEWRERR();
+                   PUTC(':');
                    FPUTS (tmpbuf);
                }
                /*
                    FPUTS (tmpbuf);
                }
                /*
@@ -218,7 +222,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
                    goto finished;
                }
                 if (scnout) {
                    goto finished;
                }
                 if (scnout) {
-                    if (putc ('\n', scnout) == EOF) DIEWRERR();
+                    PUTC('\n');
                     FPUTS (tmpbuf);
                 }
                /*
                     FPUTS (tmpbuf);
                 }
                /*
@@ -264,7 +268,7 @@ body:;
                if (scnout) {
                    FPUTS ("\n\nBAD MSG:\n");
                    FPUTS (name);
                if (scnout) {
                    FPUTS ("\n\nBAD MSG:\n");
                    FPUTS (name);
-                   if (putc ('\n', scnout) == EOF) DIEWRERR();
+                   PUTC('\n');
                    state = BODY;
                    goto body;
                }
                    state = BODY;
                    goto body;
                }