BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / msgs / msgs.c
index 0661b2d..28208e0 100644 (file)
@@ -2,19 +2,33 @@
  * Copyright (c) 1980 The Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1980 The Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that: (1) source distributions retain this entire copyright
- * notice and comment, and (2) distributions including binaries display
- * the following acknowledgement:  ``This product includes software
- * developed by the University of California, Berkeley and its contributors''
- * in the documentation or other materials provided with the distribution
- * and in all advertising materials mentioning features or use of this
- * software. Neither the name of the University nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -24,7 +38,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)msgs.c     5.6 (Berkeley) 5/29/90";
+static char sccsid[] = "@(#)msgs.c     5.8 (Berkeley) 2/4/91";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -55,14 +69,18 @@ static char sccsid[] = "@(#)msgs.c  5.6 (Berkeley) 5/29/90";
 /* #define UNBUFFERED  /* use unbuffered output */
 
 #include <sys/param.h>
 /* #define UNBUFFERED  /* use unbuffered output */
 
 #include <sys/param.h>
-#include <signal.h>
 #include <sys/dir.h>
 #include <sys/stat.h>
 #include <ctype.h>
 #include <sys/dir.h>
 #include <sys/stat.h>
 #include <ctype.h>
+#include <errno.h>
 #include <pwd.h>
 #include <pwd.h>
-#include <sgtty.h>
 #include <setjmp.h>
 #include <setjmp.h>
+#include <sgtty.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
 #include "pathnames.h"
 
 #define CMODE  0666            /* bounds file creation mode */
 #include "pathnames.h"
 
 #define CMODE  0666            /* bounds file creation mode */
@@ -81,6 +99,7 @@ static char sccsid[] = "@(#)msgs.c    5.6 (Berkeley) 5/29/90";
 
 typedef        char    bool;
 
 
 typedef        char    bool;
 
+FILE   *msgsrc;
 FILE   *newmsg;
 char   *sep = "-";
 char   inbuf[BUFSIZ];
 FILE   *newmsg;
 char   *sep = "-";
 char   inbuf[BUFSIZ];
@@ -102,7 +121,6 @@ bool        mailing = NO;
 bool   quitit = NO;
 bool   sending = NO;
 bool   intrpflg = NO;
 bool   quitit = NO;
 bool   sending = NO;
 bool   intrpflg = NO;
-bool   tstpflag = NO;
 int    uid;
 int    msg;
 int    prevmsg;
 int    uid;
 int    msg;
 int    prevmsg;
@@ -113,23 +131,18 @@ time_t    t;
 time_t keep;
 struct sgttyb  otty;
 
 time_t keep;
 struct sgttyb  otty;
 
-char   *ctime();
+char   *mktemp();
 char   *nxtfld();
 char   *nxtfld();
-int    onintr();
-int    onsusp();
-off_t  ftell();
-FILE   *popen();
-struct passwd  *getpwuid();
-
-extern int     errno;
+void   onintr();
+void   onsusp();
 
 /* option initialization */
 bool   hdrs = NO;
 bool   qopt = NO;
 bool   hush = NO;
 
 /* option initialization */
 bool   hdrs = NO;
 bool   qopt = NO;
 bool   hush = NO;
-bool   send = NO;
+bool   send_msg = NO;
 bool   locomode = NO;
 bool   locomode = NO;
-bool   pause = NO;
+bool   use_pager = NO;
 bool   clean = NO;
 bool   lastcmd = NO;
 jmp_buf        tstpbuf;
 bool   clean = NO;
 bool   lastcmd = NO;
 jmp_buf        tstpbuf;
@@ -142,7 +155,7 @@ int argc; char *argv[];
        int rcback = 0;                 /* amount to back off of rcfirst */
        int firstmsg, nextmsg, lastmsg = 0;
        int blast = 0;
        int rcback = 0;                 /* amount to back off of rcfirst */
        int firstmsg, nextmsg, lastmsg = 0;
        int blast = 0;
-       FILE *bounds, *msgsrc;
+       FILE *bounds;
 
 #ifdef UNBUFFERED
        setbuf(stdout, NULL);
 
 #ifdef UNBUFFERED
        setbuf(stdout, NULL);
@@ -195,7 +208,7 @@ int argc; char *argv[];
                                break;
 
                        case 'p':               /* pipe thru 'more' during long msgs */
                                break;
 
                        case 'p':               /* pipe thru 'more' during long msgs */
-                               pause = YES;
+                               use_pager = YES;
                                break;
 
                        case 'q':               /* query only */
                                break;
 
                        case 'q':               /* query only */
@@ -203,7 +216,7 @@ int argc; char *argv[];
                                break;
 
                        case 's':               /* sending TO msgs */
                                break;
 
                        case 's':               /* sending TO msgs */
-                               send = YES;
+                               send_msg = YES;
                                break;
 
                        default:
                                break;
 
                        default:
@@ -288,7 +301,7 @@ int argc; char *argv[];
                else if (blast > lastmsg)
                        lastmsg = blast;
 
                else if (blast > lastmsg)
                        lastmsg = blast;
 
-               if (!send) {
+               if (!send_msg) {
                        bounds = fopen(fname, "w");
                        if (bounds == NULL) {
                                perror(fname);
                        bounds = fopen(fname, "w");
                        if (bounds == NULL) {
                                perror(fname);
@@ -300,7 +313,7 @@ int argc; char *argv[];
                }
        }
 
                }
        }
 
-       if (send) {
+       if (send_msg) {
                /*
                 * Send mode - place msgs in _PATH_MSGS
                 */
                /*
                 * Send mode - place msgs in _PATH_MSGS
                 */
@@ -366,7 +379,7 @@ int argc; char *argv[];
         * prepare to display messages
         */
        totty = (isatty(fileno(stdout)) != 0);
         * prepare to display messages
         */
        totty = (isatty(fileno(stdout)) != 0);
-       pause = pause && totty;
+       use_pager = use_pager && totty;
 
        sprintf(fname, "%s/%s", getenv("HOME"), MSGSRC);
        msgsrc = fopen(fname, "r");
 
        sprintf(fname, "%s/%s", getenv("HOME"), MSGSRC);
        msgsrc = fopen(fname, "r");
@@ -377,7 +390,7 @@ int argc; char *argv[];
                if (nextmsg > lastmsg+1) {
                        printf("Warning: bounds have been reset (%d, %d)\n",
                                firstmsg, lastmsg);
                if (nextmsg > lastmsg+1) {
                        printf("Warning: bounds have been reset (%d, %d)\n",
                                firstmsg, lastmsg);
-                       truncate(fname, 0);
+                       truncate(fname, (off_t)0);
                        newrc = YES;
                }
                else if (!rcfirst)
                        newrc = YES;
                }
                else if (!rcfirst)
@@ -450,15 +463,14 @@ int argc; char *argv[];
 
                if (already && !hdrs)
                        putchar('\n');
 
                if (already && !hdrs)
                        putchar('\n');
-               already = YES;
 
                /*
                 * Print header
                 */
 
                /*
                 * Print header
                 */
-again:
                if (totty)
                        signal(SIGTSTP, onsusp);
                (void) setjmp(tstpbuf);
                if (totty)
                        signal(SIGTSTP, onsusp);
                (void) setjmp(tstpbuf);
+               already = YES;
                nlines = 2;
                if (seenfrom) {
                        printf("Message %d:\nFrom %s %s", msg, from, date);
                nlines = 2;
                if (seenfrom) {
                        printf("Message %d:\nFrom %s %s", msg, from, date);
@@ -521,7 +533,7 @@ cmnd:
 
                        case 'p':
                        case 'P':
 
                        case 'p':
                        case 'P':
-                               pause = (*in++ == 'p');
+                               use_pager = (*in++ == 'p');
                                /* intentional fallthru */
                        case '\n':
                        case 'y':
                                /* intentional fallthru */
                        case '\n':
                        case 'y':
@@ -582,10 +594,9 @@ cmnd:
 prmesg(length)
 int length;
 {
 prmesg(length)
 int length;
 {
-       FILE *outf, *inf;
-       int c;
+       FILE *outf;
 
 
-       if (pause && length > Lpp) {
+       if (use_pager && length > Lpp) {
                signal(SIGPIPE, SIG_IGN);
                signal(SIGQUIT, SIG_IGN);
                sprintf(cmdbuf, _PATH_PAGER, Lpp);
                signal(SIGPIPE, SIG_IGN);
                signal(SIGQUIT, SIG_IGN);
                sprintf(cmdbuf, _PATH_PAGER, Lpp);
@@ -593,7 +604,7 @@ int length;
                if (!outf)
                        outf = stdout;
                else
                if (!outf)
                        outf = stdout;
                else
-                       setbuf(outf, NULL);
+                       setbuf(outf, (char *)NULL);
        }
        else
                outf = stdout;
        }
        else
                outf = stdout;
@@ -622,6 +633,7 @@ int length;
        stty(fileno(stdout), &otty);
 }
 
        stty(fileno(stdout), &otty);
 }
 
+void
 onintr()
 {
        signal(SIGINT, onintr);
 onintr()
 {
        signal(SIGINT, onintr);
@@ -646,6 +658,7 @@ onintr()
 /*
  * We have just gotten a susp.  Suspend and prepare to resume.
  */
 /*
  * We have just gotten a susp.  Suspend and prepare to resume.
  */
+void
 onsusp()
 {
 
 onsusp()
 {
 
@@ -654,7 +667,7 @@ onsusp()
        kill(0, SIGTSTP);
        signal(SIGTSTP, onsusp);
        if (!mailing)
        kill(0, SIGTSTP);
        signal(SIGTSTP, onsusp);
        if (!mailing)
-               longjmp(tstpbuf);
+               longjmp(tstpbuf, 0);
 }
 
 linecnt(f)
 }
 
 linecnt(f)