BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / calendar / calendar.c
index a162d39..964687f 100644 (file)
@@ -2,17 +2,33 @@
  * Copyright (c) 1989 The Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1989 The Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not 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
@@ -22,13 +38,14 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)calendar.c 4.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)calendar.c 4.11 (Berkeley) 10/12/90";
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <sys/file.h>
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <sys/file.h>
+#include <sys/uio.h>
 #include <pwd.h>
 #include <errno.h>
 #include <tzfile.h>
 #include <pwd.h>
 #include <errno.h>
 #include <tzfile.h>
@@ -36,9 +53,9 @@ static char sccsid[] = "@(#)calendar.c        4.7 (Berkeley) %G%";
 #include <ctype.h>
 #include <unistd.h>
 #include <string.h>
 #include <ctype.h>
 #include <unistd.h>
 #include <string.h>
-#include <paths.h>
 #include "pathnames.h"
 
 #include "pathnames.h"
 
+extern int errno;
 struct passwd *pw;
 int doall;
 
 struct passwd *pw;
 int doall;
 
@@ -46,7 +63,7 @@ main(argc, argv)
        int argc;
        char **argv;
 {
        int argc;
        char **argv;
 {
-       extern int errno, optind;
+       extern int optind;
        int ch;
 
        while ((ch = getopt(argc, argv, "-a")) != EOF)
        int ch;
 
        while ((ch = getopt(argc, argv, "-a")) != EOF)
@@ -101,7 +118,7 @@ cal()
                        while ((ch = getchar()) != '\n' && ch != EOF);
                if (buf[0] == '\0')
                        continue;
                        while ((ch = getchar()) != '\n' && ch != EOF);
                if (buf[0] == '\0')
                        continue;
-               if (!isspace(buf[0]))
+               if (buf[0] != '\t')
                        printing = isnow(buf) ? 1 : 0;
                if (printing)
                        (void)fprintf(fp, "%s\n", buf);
                        printing = isnow(buf) ? 1 : 0;
                if (printing)
                        (void)fprintf(fp, "%s\n", buf);
@@ -109,6 +126,16 @@ cal()
        closecal(fp);
 }
 
        closecal(fp);
 }
 
+struct iovec header[] = {
+       "From: ", 6,
+       NULL, 0,
+       " (Reminder Service)\nTo: ", 24,
+       NULL, 0,
+       "\nSubject: ", 10,
+       NULL, 0,
+       "'s Calendar\nPrecedence: bulk\n\n",  30,
+};
+
 /* 1-based month, 0-based days, cumulative */
 int daytab[][14] = {
        0, 0, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364,
 /* 1-based month, 0-based days, cumulative */
 int daytab[][14] = {
        0, 0, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364,
@@ -132,8 +159,9 @@ settime()
                cumdays = daytab[0];
        }
        /* Friday displays Monday's events */
                cumdays = daytab[0];
        }
        /* Friday displays Monday's events */
-       offset = tp->tm_wday == 6 ? 3 : 1;
-       (void)strftime(dayname, sizeof(dayname), "%A", tp);
+       offset = tp->tm_wday == 5 ? 3 : 1;
+       header[5].iov_base = dayname;
+       header[5].iov_len = strftime(dayname, sizeof(dayname), "%A", tp);
 }
 
 /*
 }
 
 /*
@@ -256,6 +284,7 @@ opencal()
        }
        /* parent -- set stdin to pipe output */
        (void)dup2(pdes[0], STDIN_FILENO);
        }
        /* parent -- set stdin to pipe output */
        (void)dup2(pdes[0], STDIN_FILENO);
+       (void)close(pdes[0]);
        (void)close(pdes[1]);
 
        /* not reading all calendar files, just set output to stdout */
        (void)close(pdes[1]);
 
        /* not reading all calendar files, just set output to stdout */
@@ -273,7 +302,6 @@ closecal(fp)
        FILE *fp;
 {
        struct stat sbuf;
        FILE *fp;
 {
        struct stat sbuf;
-       FILE *iop;
        int nread, pdes[2], status;
        char buf[1024], *mktemp();
 
        int nread, pdes[2], status;
        char buf[1024], *mktemp();
 
@@ -297,18 +325,18 @@ closecal(fp)
                        (void)close(pdes[0]);
                }
                (void)close(pdes[1]);
                        (void)close(pdes[0]);
                }
                (void)close(pdes[1]);
-               execl(_PATH_SENDMAIL, "-i", "-t", "-F",
-                   "\"Reminder Service\"", "-f", "root");
+               execl(_PATH_SENDMAIL, "sendmail", "-i", "-t", "-F",
+                   "\"Reminder Service\"", "-f", "root", NULL);
+               (void)fprintf(stderr, "calendar: %s: %s.\n", 
+                   _PATH_SENDMAIL, strerror(errno));
                _exit(1);
        }
                _exit(1);
        }
-       /* parent -- rewind file, write to pipe input */
+       /* parent -- write to pipe input */
        (void)close(pdes[0]);
 
        (void)close(pdes[0]);
 
-       iop = fdopen(pdes[1], "w");
-       (void)fprintf(iop,
-"From: %s (Reminder Service)\nTo: %s\nSubject: %s's Calendar\nPrecedence: bulk\n\n",
-           pw->pw_name, pw->pw_name, dayname);
-       (void)fflush(iop);
+       header[1].iov_base = header[3].iov_base = pw->pw_name;
+       header[1].iov_len = header[3].iov_len = strlen(pw->pw_name);
+       writev(pdes[1], header, 7);
        while ((nread = read(fileno(fp), buf, sizeof(buf))) > 0)
                (void)write(pdes[1], buf, nread);
        (void)close(pdes[1]);
        while ((nread = read(fileno(fp), buf, sizeof(buf))) > 0)
                (void)write(pdes[1], buf, nread);
        (void)close(pdes[1]);