]> diplodocus.org Git - nmh/blobdiff - uip/scansbr.c
Make sure we return the descriptor from the file handle. Noted by
[nmh] / uip / scansbr.c
index a62faf2e617443bcefc788bfda09db91b4c3cc8d..24609d26c48d48ce95ace41734480ebfda0bdad2 100644 (file)
@@ -26,6 +26,10 @@ static m_getfld_state_t gstate;              /* for accessor functions below    */
 
 #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();\
@@ -44,6 +48,8 @@ int
 scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
       int unseen, char *folder, long size, int noisy, charstring_t *scanl)
 {
+    static bool deja_vu;
+    static int tty_width;
     int i, compnum, encrypted, state;
     char *cp, *tmpbuf, *startbody, **nxtbuf;
     char *saved_c_text = NULL;
@@ -60,9 +66,12 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
        scanl used to be a global. */
     if (! *scanl) {
        if (width == -1) {
-           /* Default:  width of the terminal, but at least WIDTH/2. */
-           if ((width = sc_width ()) < WIDTH/2)
-               width = WIDTH/2;
+            if (!deja_vu) {
+                deja_vu = true;
+                tty_width = sc_width();
+            }
+
+            width = max(tty_width, WIDTH / 2);
        } else if (width == 0) {
            /* Unlimited width. */
            width = INT_MAX;
@@ -169,7 +178,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
                compnum++;
                if (scnout) {
                    FPUTS (name);
-                   if ( putc (':', scnout) == EOF) DIEWRERR();
+                   PUTC(':');
                    FPUTS (tmpbuf);
                }
                /*
@@ -218,7 +227,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
                    goto finished;
                }
                 if (scnout) {
-                    if (putc ('\n', scnout) == EOF) DIEWRERR();
+                    PUTC('\n');
                     FPUTS (tmpbuf);
                 }
                /*
@@ -264,7 +273,7 @@ body:;
                if (scnout) {
                    FPUTS ("\n\nBAD MSG:\n");
                    FPUTS (name);
-                   if (putc ('\n', scnout) == EOF) DIEWRERR();
+                   PUTC('\n');
                    state = BODY;
                    goto body;
                }