X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fscansbr.c;h=6a9278bbd539895d2f636d2c8a16abba032c45cc;hp=143a059cb6c4fc1dcca6532a13ffeb1cd55ee89f;hb=fed3e593e1e99bacd6de13663103e3c1940a9957;hpb=c4ce52f0d1cc06ae49317c31a068a5e555bf54d6 diff --git a/uip/scansbr.c b/uip/scansbr.c index 143a059..6a9278b 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -3,13 +3,18 @@ * scansbr.c -- routines to help scan along... * * $Id$ + * + * 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 #include #include #include -#include +#include +#include #ifdef _FSTDIO # define _ptr _p /* Gag */ @@ -50,9 +55,11 @@ static int dat[5]; /* aux. data for format routine */ char *scanl = 0; /* text of most recent scanline */ +#define DIEWRERR() adios (scnmsg, "write error on") + #define FPUTS(buf) {\ if (mh_fputs(buf,scnout) == EOF)\ - adios (scnmsg, "write error on");\ + DIEWRERR();\ } /* @@ -61,13 +68,19 @@ char *scanl = 0; /* text of most recent scanline */ int sc_width (void); /* from termsbr.c */ static int mh_fputs(char *, FILE *); +#ifdef MULTIBYTE_SUPPORT +#define SCAN_CHARWIDTH MB_CUR_MAX +#else +#define SCAN_CHARWIDTH 1 +#endif int scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, int unseen, char *folder, long size, int noisy) { int i, compnum, encrypted, state; - char *cp, *tmpbuf, **nxtbuf; + unsigned char *cp, *tmpbuf; + char **nxtbuf; char *saved_c_text; struct comp *cptr; struct comp **savecomp; @@ -90,8 +103,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, width = MAXSCANL; } dat[3] = slwidth = width; - if ((scanl = (char *) malloc((size_t) (slwidth + 2) )) == NULL) - adios (NULL, "unable to malloc scan line (%d bytes)", slwidth+2); + scanl = (char *) mh_xmalloc((size_t) SCAN_CHARWIDTH * (slwidth + 2) ); if (outnum) umask(~m_gmprot()); @@ -127,8 +139,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, used_buf += ncomps+1; *--used_buf = 0; rlwidth = bodycomp && (width > SBUFSIZ) ? width : SBUFSIZ; for (i = ncomps; i--; ) - if ((*nxtbuf++ = malloc(rlwidth)) == NULL) - adios (NULL, "unable to allocate component buffer"); + *nxtbuf++ = mh_xmalloc(rlwidth); } /* @@ -187,7 +198,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, compnum++; if (outnum) { FPUTS (name); - putc (':', scnout); + if ( putc (':', scnout) == EOF) DIEWRERR(); FPUTS (tmpbuf); } /* @@ -198,7 +209,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, */ if ((cptr = wantcomp[CHASH(name)])) { do { - if (!strcasecmp(name, cptr->c_name)) { + if (!mh_strcasecmp(name, cptr->c_name)) { if (! cptr->c_text) { cptr->c_text = tmpbuf; for (cp = tmpbuf + strlen (tmpbuf) - 1; @@ -228,7 +239,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, state = FILEEOF; /* stop now if scan cmd */ goto finished; } - putc ('\n', scnout); + if (putc ('\n', scnout) == EOF) DIEWRERR(); FPUTS (tmpbuf); /* * performance hack: some people like to run "inc" on @@ -249,7 +260,7 @@ body:; if (scnout->_cnt <= 0) { #endif if (fflush(scnout) == EOF) - adios (scnmsg, "write error on"); + DIEWRERR (); } #ifdef LINUX_STDIO state = m_getfld(state, name, scnout->_IO_write_ptr, @@ -274,7 +285,7 @@ body:; if (outnum) { FPUTS ("\n\nBAD MSG:\n"); FPUTS (name); - putc ('\n', scnout); + if (putc ('\n', scnout) == EOF) DIEWRERR(); state = BODY; goto body; } @@ -306,7 +317,10 @@ finished: if (size) dat[2] = size; else if (outnum > 0) + { dat[2] = ftell(scnout); + if (dat[2] == EOF) DIEWRERR(); + } if ((datecomp && !datecomp->c_text) || (!size && !outnum)) { struct stat st; @@ -322,9 +336,9 @@ finished: if (datecomp->c_tws == NULL) adios (NULL, "unable to allocate tws buffer"); *datecomp->c_tws = *dlocaltime ((time_t *) &st.st_mtime); - datecomp->c_flags = -1; + datecomp->c_flags |= CF_DATEFAB|CF_TRUE; } else { - datecomp->c_flags = 0; + datecomp->c_flags &= ~CF_DATEFAB; } } } @@ -354,7 +368,7 @@ finished: *--nxtbuf = tmpbuf; if (outnum && (ferror(scnout) || fclose (scnout) == EOF)) - adios (scnmsg, "write error on"); + DIEWRERR(); return (state != FILEEOF ? SCNERR : encrypted ? SCNENC : SCNMSG); }