scansbr: Only write to file if we're incing, but not when scanning.
authormarkus schnalke <meillo@marmaro.de>
Thu, 22 Mar 2012 17:50:10 +0000 (18:50 +0100)
committermarkus schnalke <meillo@marmaro.de>
Thu, 22 Mar 2012 17:50:10 +0000 (18:50 +0100)
If the original author would have used logical flags instead of magic
values in `outnum', the code wouldn't have been broken all the time.
Writing to /dev/null instead of not writing at all ... oh my! :-/

uip/scansbr.c

index dca761c..ca98c5a 100644 (file)
@@ -139,14 +139,10 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg,
                }
        }
 
-       if (ismbox) {
-               if (incing) {
-                       scnmsg = m_name(outnum);
-                       if (*scnmsg == '?')  /* msg num out of range */
-                               return SCNNUM;
-               } else {
-                       scnmsg = "/dev/null";
-               }
+       if (incing) {
+               scnmsg = m_name(outnum);
+               if (*scnmsg == '?')  /* msg num out of range */
+                       return SCNNUM;
                if ((scnout = fopen(scnmsg, "w")) == NULL)
                        adios(scnmsg, "unable to write");
                /*
@@ -211,7 +207,7 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg,
                case BODY:
                        compnum = -1;
                        if (!incing) {
-                               state = FILEEOF; /* stop now if scan cmd */
+                               state = FILEEOF; /* stop here if scan cmd */
                                goto finished;
                        }
                        if (putc('\n', scnout) == EOF)
@@ -334,7 +330,7 @@ finished:
        }
        *--nxtbuf = tmpbuf;
 
-       if (ismbox && (ferror(scnout) || fclose(scnout) == EOF))
+       if (incing && (ferror(scnout) || fclose(scnout) == EOF))
                adios(scnmsg, "write error on");
 
        return (state != FILEEOF ? SCNERR : SCNMSG);