Use sysexits.h for better exit-codes
[mmh] / sbr / m_getfld.c
index 2ebb44a..12d05b9 100644 (file)
@@ -8,6 +8,8 @@
 
 #include <h/mh.h>
 #include <h/utils.h>
+#include <ctype.h>
+#include <sysexits.h>
 
 /*
 ** This module has a long and checkered history.
@@ -154,14 +156,6 @@ static int (*eom_action)(int) = NULL;
 # define DEFINED__FILBUF_TO_SOMETHING_SPECIFIC
 #endif
 
-#ifdef SCO_5_STDIO
-# define _ptr  __ptr
-# define _cnt  __cnt
-# define _base __base
-# define _filbuf(fp)  ((fp)->__cnt = 0, __filbuf(fp))
-# define DEFINED__FILBUF_TO_SOMETHING_SPECIFIC
-#endif
-
 #ifndef DEFINED__FILBUF_TO_SOMETHING_SPECIFIC
 extern int  _filbuf(FILE*);
 #endif
@@ -431,8 +425,8 @@ m_getfld(int state, unsigned char *name, unsigned char *buf,
                        *cp++ = j = *(iob->_ptr + c);
                        c = _filbuf(iob);
 #endif
-                       if (c == EOF ||
-                         ((j == '\0' || j == '\n') && c != ' ' && c != '\t')) {
+                       if (c == EOF || ((j == '\0' || j == '\n')
+                                       && c != ' ' && c != '\t')) {
                                if (c != EOF) {
 #ifdef LINUX_STDIO
                                        --iob->_IO_read_ptr;
@@ -570,7 +564,7 @@ m_getfld(int state, unsigned char *name, unsigned char *buf,
                break;
 
        default:
-               adios(NULL, "m_getfld() called with bogus state of %d", state);
+               adios(EX_SOFTWARE, NULL, "m_getfld() called with bogus state of %d", state);
        }
 finish:
        *cp = 0;
@@ -583,11 +577,16 @@ void
 thisisanmbox(FILE *iob)
 {
        register int c;
-       register long pos;
        char text[10];
        register char *cp;
        register char *delimstr;
 
+       c = getc(iob); 
+       if (feof(iob)) {
+               return;
+       }
+       ungetc(c, iob);
+
        /*
        ** Figure out what the message delimitter string is for this
        ** maildrop.  (This used to be part of m_Eom but I didn't like
@@ -600,12 +599,11 @@ thisisanmbox(FILE *iob)
        ** abort.
        */
 
-       pos = ftell(iob);
        if (fread(text, sizeof(*text), 5, iob) != 5) {
-               adios(NULL, "Read error");
+               adios(EX_IOERR, NULL, "Read error");
        }
        if (strncmp(text, "From ", 5)!=0) {
-               adios(NULL, "No Unix style (mbox) maildrop.");
+               adios(EX_USAGE, NULL, "No Unix style (mbox) maildrop.");
        }
        ismbox = TRUE;
        delimstr = "\nFrom ";
@@ -623,7 +621,7 @@ thisisanmbox(FILE *iob)
        strcpy(msg_delim, delimstr);
        delimend = (unsigned char *)msg_delim + edelimlen;
        if (edelimlen <= 1)
-               adios(NULL, "maildrop delimiter must be at least 2 bytes");
+               adios(EX_DATAERR, NULL, "maildrop delimiter must be at least 2 bytes");
        /*
        ** build a Boyer-Moore end-position map for the matcher in m_getfld.
        ** N.B. - we don't match just the first char (since it's the newline