X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/0bfb53a23531bea3aaeadcd1a6f6c372eef96612..d3e11c5e9:/uip/distsbr.c?ds=sidebyside diff --git a/uip/distsbr.c b/uip/distsbr.c index b5119fbe..c9f6656b 100644 --- a/uip/distsbr.c +++ b/uip/distsbr.c @@ -1,6 +1,4 @@ - -/* - * distsbr.c -- routines to do additional "dist-style" processing +/* distsbr.c -- routines to do additional "dist-style" processing * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -10,6 +8,7 @@ #include #include #include +#include "../sbr/m_mktemp.h" static int hdrfd = NOTOK; static int txtfd = NOTOK; @@ -28,10 +27,9 @@ int distout (char *drft, char *msgnam, char *backup) { int state; - register unsigned char *dp; - register char *resent; - char name[NAMESZ], buffer[BUFSIZ]; - register FILE *ifp, *ofp; + char *dp, *resent; + char name[NAMESZ], buffer[NMH_BUFSIZ]; + FILE *ifp, *ofp; m_getfld_state_t gstate = 0; if (rename (drft, strcpy (backup, m_backup (drft))) == NOTOK) @@ -44,7 +42,7 @@ distout (char *drft, char *msgnam, char *backup) chmod (drft, m_gmprot ()); ready_msg (msgnam); - lseek (hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */ + lseek(hdrfd, 0, SEEK_SET); /* msgnam not accurate */ cpydata (hdrfd, fileno (ofp), msgnam, drft); for (resent = NULL;;) { @@ -57,7 +55,7 @@ distout (char *drft, char *msgnam, char *backup) if (uprf (name, "distribution-")) snprintf (name, sizeof(name), "%s%s", "Resent", &name[12]); if (!uprf (name, "resent")) { - advise (NULL, BADHDR, "draft", name); + inform(BADHDR, "draft", name); goto leave_bad; } if (state == FLD) @@ -74,8 +72,8 @@ distout (char *drft, char *msgnam, char *backup) case BODY: for (dp = buffer; *dp; dp++) - if (!isspace (*dp)) { - advise (NULL, BADTXT, "draft"); + if (!isspace ((unsigned char) *dp)) { + inform(BADTXT, "draft"); goto leave_bad; } @@ -84,11 +82,11 @@ distout (char *drft, char *msgnam, char *backup) case LENERR: case FMTERR: - advise (NULL, BADRFT, "draft"); + inform(BADRFT, "draft"); leave_bad: ; fclose (ifp); fclose (ofp); - unlink (drft); + (void) m_unlink (drft); if (rename (backup, drft) == NOTOK) adios (drft, "unable to rename %s to", backup); return NOTOK; @@ -103,9 +101,9 @@ process: ; fflush (ofp); if (!resent) { - advise (NULL, BADMSG, "draft"); + inform(BADMSG, "draft"); fclose (ofp); - unlink (drft); + (void) m_unlink (drft); if (rename (backup, drft) == NOTOK) adios (drft, "unable to rename %s to", backup); return NOTOK; @@ -113,7 +111,7 @@ process: ; free (resent); if (txtfd != NOTOK) { - lseek (txtfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */ + lseek(txtfd, 0, SEEK_SET); /* msgnam not accurate */ cpydata (txtfd, fileno (ofp), msgnam, drft); } @@ -127,29 +125,32 @@ static void ready_msg (char *msgnam) { int state, out; - char name[NAMESZ], buffer[BUFSIZ], tmpfil[BUFSIZ]; - register FILE *ifp, *ofp; + char name[NAMESZ], buffer[NMH_BUFSIZ], tmpfil[BUFSIZ]; + FILE *ifp, *ofp; char *cp = NULL; m_getfld_state_t gstate = 0; - if (hdrfd != NOTOK) - close (hdrfd), hdrfd = NOTOK; - if (txtfd != NOTOK) - close (txtfd), txtfd = NOTOK; + if (hdrfd != NOTOK) { + close (hdrfd); + hdrfd = NOTOK; + } + if (txtfd != NOTOK) { + close (txtfd); + txtfd = NOTOK; + } if ((ifp = fopen (msgnam, "r")) == NULL) adios (msgnam, "unable to open message"); cp = m_mktemp2(NULL, "dist", &hdrfd, NULL); if (cp == NULL) { - adios("distsbr", "unable to create temporary file"); + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); } - fchmod(hdrfd, 0600); strncpy(tmpfil, cp, sizeof(tmpfil)); if ((out = dup (hdrfd)) == NOTOK || (ofp = fdopen (out, "w")) == NULL) adios (NULL, "no file descriptors -- you lose big"); - unlink (tmpfil); + (void) m_unlink (tmpfil); for (;;) { int buffersz = sizeof buffer; @@ -171,14 +172,15 @@ ready_msg (char *msgnam) cp = m_mktemp2(NULL, "dist", &txtfd, NULL); if (cp == NULL) { - adios("distsbr", "unable to create temporary file"); + adios(NULL, "unable to create temporary file in %s", + get_temp_dir()); } fchmod(txtfd, 0600); strncpy (tmpfil, cp, sizeof(tmpfil)); if ((out = dup (txtfd)) == NOTOK || (ofp = fdopen (out, "w")) == NULL) adios (NULL, "no file descriptors -- you lose big"); - unlink (tmpfil); + (void) m_unlink (tmpfil); fprintf (ofp, "\n%s", buffer); while (state == BODY) { buffersz = sizeof buffer;