X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/1564f19badd71bedb37fad0913a816a8873b7669..9f1e781a5c2beb9df943c832300a3f5bee1e4ed3:/uip/scansbr.c diff --git a/uip/scansbr.c b/uip/scansbr.c index a62faf2e..b82c3c56 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -5,12 +5,14 @@ * complete copyright information. */ -#include -#include -#include -#include -#include -#include +#include "h/mh.h" +#include "sbr/error.h" +#include "h/addrsbr.h" +#include "h/fmt_scan.h" +#include "h/scansbr.h" +#include "h/tws.h" +#include "h/utils.h" +#include "sbr/terminal.h" static struct format *fmt; static struct comp *datecomp; /* pntr to "date" comp */ @@ -26,6 +28,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 +50,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 +68,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 +180,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 +229,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 +275,7 @@ body:; if (scnout) { FPUTS ("\n\nBAD MSG:\n"); FPUTS (name); - if (putc ('\n', scnout) == EOF) DIEWRERR(); + PUTC('\n'); state = BODY; goto body; } @@ -274,7 +285,7 @@ body:; goto finished; default: - adios (NULL, "getfld() returned %d", state); + die("getfld() returned %d", state); } } @@ -338,17 +349,19 @@ finished: if (scnout && (ferror(scnout) || fclose (scnout) == EOF)) DIEWRERR(); - return (state != FILEEOF ? SCNERR : encrypted ? SCNENC : SCNMSG); + return state != FILEEOF ? SCNERR : encrypted ? SCNENC : SCNMSG; } /* The following two functions allow access to the global gstate above. */ void -scan_finished(void) { +scan_finished(void) +{ m_getfld_state_destroy (&gstate); } void -scan_detect_mbox_style (FILE *f) { +scan_detect_mbox_style (FILE *f) +{ m_unknown (&gstate, f); }