home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / Mail / main.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  2KB  |  112 lines

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. #
  3.  
  4. #include "rcv.h"
  5. #include <sys/stat.h>
  6.  
  7. /*
  8.  * Mail -- a mail program
  9.  *
  10.  * Startup -- interface with user.
  11.  */
  12.  
  13. /*
  14.  * Find out who the user is, copy his mail file (if exists) into
  15.  * /tmp/Rxxxxx and set up the message pointers.  Then, print out the
  16.  * message headers and read user commands.
  17.  */
  18.  
  19. main(argc, argv)
  20.     char **argv;
  21. {
  22.     register char *ef;
  23.     register int i;
  24.     FILE *ibuf;
  25.     extern char tempMesg[], _sobuf[];
  26.  
  27.     argv[argc] = (char *) -1;
  28.     mypid = getpid();
  29.     intty = isatty(0);
  30.     outtty = isatty(1);
  31.     setbuf(stdout, _sobuf);
  32.     tinit();
  33.     ef = NOSTR;
  34.     for (i = 1; i < argc; i++) {
  35.         if (equal(argv[i], "-f")) {
  36.             ef = argv[i+1];
  37.             break;
  38.         }
  39.         if (equal(argv[i], "-n")) {
  40.             demail();
  41.             exit(0);
  42.         }
  43.     }
  44.     if (ef == NOSTR && argc > 1) {
  45.         commands();
  46.         i = 1;
  47.         if (equal(argv[1], "-i")) {
  48.             assign("ignore", "");
  49.             i++;
  50.         }
  51.         mail(&argv[i]);
  52.  
  53.         /*
  54.          * why wait?
  55.          */
  56.  
  57.         exit(0);
  58.     }
  59.     rcvmode++;
  60.     if (ef != NOSTR) {
  61.         edit++;
  62.         if (ef == (char *) -1)
  63.             ef = mbox;
  64.         editfile = mailname = ef;
  65.         if ((ibuf = fopen(mailname, "r")) == NULL) {
  66.             perror(mailname);
  67.             exit(1);
  68.         }
  69.         if ((i = open(mailname, 1)) < 0)
  70.             printf("Warning: \"%s\" not writable.\n", mailname);
  71.         else
  72.             close(i);
  73.     }
  74.     else {
  75.         if ((ibuf = fopen(mailname, "r")) == NULL) {
  76.             printf("No mail.\n");
  77.             exit(0);
  78.         }
  79.     }
  80.  
  81.     /*
  82.      * Copy the mudder into /tmp
  83.      * and set pointers.
  84.      * Announce the presence of this funny file.
  85.      */
  86.  
  87.     mailsize = fsize(ibuf);
  88.     if ((otf = fopen(tempMesg, "w")) == NULL) {
  89.         perror(tempMesg);
  90.         exit(1);
  91.     }
  92.     if ((itf = fopen(tempMesg, "r")) == NULL) {
  93.         perror(tempMesg);
  94.         exit(1);
  95.     }
  96.     unlink(tempMesg);
  97.     setptr(ibuf);
  98.     fclose(ibuf);
  99.  
  100.     /*
  101.      * print headings and accept user commands. */
  102.  
  103.     if (msgCount == 0) {
  104.         printf("No messages.\n");
  105.         exit(1);
  106.     }
  107.     commands();
  108.     if (!edit)
  109.         quit();
  110.     exit(0);
  111. }
  112.