home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / auucp+-1.02 / fuucp_plus_src.lzh / dmail / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-21  |  6.3 KB  |  289 lines

  1.  
  2. /*
  3.  * MAIN.C
  4.  *
  5.  *  $Header: Beta:src/uucp/src/dmail/RCS/main.c,v 1.1 90/02/02 12:03:43 dillon Exp Locker: dillon $
  6.  *
  7.  *  (C) Copyright 1985-1990 by Matthew Dillon,  All Rights Reserved.
  8.  *
  9.  *  Global Routines:    MAIN()
  10.  *            INIT()
  11.  *            SIG_HANDLE()
  12.  *
  13.  *  Static Routines:    none.
  14.  *
  15.  *  23 Aug 90: Changed sendmail.c for use with my new sendmail prg.
  16.  *             Ingo Feulner
  17.  */
  18.  
  19. #include <pwd.h>
  20. #include <stdio.h>
  21. #include <signal.h>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #include <config.h>
  25. #include "version.h"
  26.  
  27. #include "dmail.h"
  28.  
  29. IDENT(".04");
  30. char *dillon_cpr = DCOPYRIGHT;
  31. static char *version20 = "$VER: dmail 1.05 (23 Aug 90)\n\r";
  32.  
  33. #define MAILHOME MakeConfigPath(UUMAIL, "")
  34. #define MBOX     MakeConfigPath(UUMAIL, "mbox")
  35. #define ALT_MBOX MakeConfigPath(UUMAIL, ".mbox")
  36. #define MAILRC     MakeConfigPath(UULIB, ".dmailrc")
  37. #define VISUAL     GetConfig(EDITOR, "dme")
  38.  
  39. void  init();
  40.  
  41. main(argc, argv)
  42. char *argv[];
  43. {
  44.     int i, next, Retry;
  45.     int fop = 0, oop = 0;
  46.     int rcload = 1;
  47.     int options = 1;
  48.     int no_mail_overide = 0;
  49.     int nc = 0;
  50.     static int nameslist[128];
  51.     char *rcname;
  52.  
  53.     if (push_base())
  54.     done (1);
  55.  
  56.     init();
  57.     rcname = malloc (strlen(home_dir) + strlen(MAILRC) + 2);
  58. #ifdef AMIGA
  59.     rcname[0] = 0;
  60. #else
  61.     strcpy (rcname, home_dir);
  62.     strcat (rcname, "/");
  63. #endif
  64.     strcat (rcname, MAILRC);
  65.     for (i = 1; i < argc; ++i) {
  66.     next = 0;
  67.     if ((*argv[i] == '-') && options) {
  68.         if (*(argv[i] + 1) == '\0') {
  69.         options = 0;
  70.         continue;
  71.         }
  72.         while (*++argv[i]) {
  73.         switch (*argv[i]) {
  74.         case 'S':
  75.             lmessage_overide = 1;
  76.             break;
  77.         case 'O':
  78.             no_mail_overide = 1;
  79.             break;
  80.         case 'l':
  81.             rcload  = 1;
  82.             if (i + 1 < argc  &&  *argv[i + 1] != '-') {
  83.             xfree (rcname);
  84.             oop = 1;
  85.             ++i;
  86.             ++next;
  87.             rcname = malloc (strlen (argv[i]) + 1);
  88.             strcpy (rcname, argv[i]);
  89.             }
  90.             break;
  91.         case 'L':
  92.             rcload = 0;
  93.             break;
  94.         case 'D':
  95.             XDebug = 1;
  96.             break;
  97.         case 'F':
  98.             if (++i < argc) {
  99.             add_extra (argv[i]);
  100.             } else {
  101.             puts (" -F Requires Field argument");
  102.             exit (1);
  103.             }
  104.             ++next;
  105.             break;
  106.         case 'v':
  107.             set_var (LEVEL_SET, "verbose", "");
  108.             break;
  109.         case 'o':
  110.             xfree (output_file);
  111.             if (i + 1 < argc  &&  *argv[i + 1] != '-') {
  112.             oop = 1;
  113.             ++i;
  114.             ++next;
  115.             output_file = malloc (strlen (argv[i]) + 1);
  116.             strcpy (output_file, argv[i]);
  117.             } else {
  118.             oop = -1;
  119.             output_file = malloc (strlen(home_dir) +
  120.                 strlen(ALT_MBOX) + 2);
  121. #ifdef AMIGA
  122.             strcpy (output_file, ALT_MBOX);
  123. #else
  124.             sprintf (output_file, "%s/%s", home_dir, ALT_MBOX);
  125. #endif
  126.             }
  127.             break;
  128.         case 'f':
  129.             if (i + 1 < argc  &&  *argv[i + 1] != '-') {
  130.             fop = 1;
  131.             ++i;
  132.             ++next;
  133.             mail_file = realloc (mail_file, strlen (argv[i]) + 1);
  134.             strcpy (mail_file, argv[i]);
  135.             } else {
  136.             fop = -1;
  137.             mail_file = realloc (mail_file,
  138.                 strlen(home_dir) + strlen(MBOX) + 2);
  139. #ifdef AMIGA
  140.             strcpy (mail_file, MBOX);
  141. #else
  142.             sprintf (mail_file, "%s/%s", home_dir, MBOX);
  143. #endif
  144.             }
  145.             break;
  146.         default:
  147.             puts ("dmail: Bad argument");
  148.             puts ("dmail -O      then 'help' for help.");
  149.             done (1);
  150.         }
  151.         if (next)
  152.             break;
  153.         }
  154.     } else {
  155.         No_load_mail = 1;
  156.         nameslist[nc++] = i;
  157.     }
  158.     }
  159.     if (oop == -1  &&  fop == -1) {
  160.     mail_file = realloc (mail_file, strlen(output_file) + 1);
  161.     strcpy (mail_file, output_file);
  162.     }
  163. ends:
  164.     initial_load_mail();
  165.     m_select (Nulav, M_RESET);
  166.     Current = indexof (1);
  167.     if (nc)
  168.     set_var (LEVEL_SET, "comlinemail", "");
  169.     if (rcload) {
  170.     ac = 2;
  171.     av[1] = rcname;
  172.     do_source(rcname, 1);
  173.     }
  174.     if (nc) {
  175.     av[0] = "mail";
  176.     for (i = 0; i < nc; ++i)
  177.         av[i + 1] = argv[nameslist[i]];
  178.     ac = nc + 1;
  179.     do_reply ("", R_MAIL);
  180.     done (0);
  181.     }
  182.     if (Entries + no_mail_overide == 0) {
  183.     printf ("\nNO MAIL for %s\n\n", user_name);
  184.     return;
  185.     }
  186.     printf ("\nRF %-20s   WF %-20s\n", mail_file, output_file);
  187.     do {
  188.     Retry = 20;
  189.     pop_base();
  190. loop:
  191.     if (push_base()) {
  192.         pop_base();
  193.         if (XDebug)
  194.         printf ("TOP LEVEL INTR, Level: %d\n", Longstack);
  195.         if (--Retry == 0)
  196.         done (1);
  197.         puts ("");
  198.         goto loop;
  199.     }
  200.     check_new_mail();
  201.     } while (do_command() > 0);
  202.  
  203.     return(0);
  204. }
  205.  
  206. void
  207. init()
  208. {
  209.     char *str;
  210.     struct passwd *passwd;
  211.     extern int sig_handle();
  212.  
  213.     Entry = (struct ENTRY *)malloc (sizeof(*Entry));
  214.     Entry->status = Entry->no = Entry->fpos = 0;
  215.     passwd = getpwuid(getuid());
  216.     if (passwd == NULL) {
  217.     printf("DMail, unable to get passwd entry for uid %d\n", getuid());
  218.     exit(1);
  219.     }
  220.     user_name    = malloc (strlen(passwd->pw_name) + 1);
  221.     home_dir    = malloc (strlen(passwd->pw_dir) + 1);
  222.     visual    = malloc (strlen(VISUAL) + 1);
  223.     strcpy  (visual     , VISUAL);
  224.     strcpy  (user_name, passwd->pw_name);
  225.     strcpy  (home_dir , passwd->pw_dir);
  226. #ifdef AMIGA
  227.     if (str = FindConfig(HOME))
  228.     strcpy ((home_dir = realloc (home_dir, strlen(str) + 1)), str);
  229.     if (str = FindConfig(USERNAME))
  230.     strcpy ((user_name = realloc (user_name, strlen(str) + 1)), str);
  231.     if (str = FindConfig(EDITOR))
  232.     strcpy ((visual = realloc (visual, strlen(str) + 1)), str);
  233.  
  234.     if (str = MallocEnviro("USER"))
  235.     user_name = str;
  236.  
  237. #else
  238.     if ((str = getenv ("HOME")) != NULL)
  239.     strcpy ((home_dir = realloc (home_dir, strlen(str) + 1)), str);
  240.     if ((str = getenv ("USER")) != NULL)
  241.     strcpy ((user_name = realloc (user_name, strlen(str) + 1)), str);
  242.     if ((str = getenv ("VISUAL")) != NULL)
  243.     strcpy ((visual = realloc (visual, strlen(str) + 1)), str);
  244. #endif
  245.     mail_file    = malloc (strlen(MAILHOME) + strlen(user_name) + 1);
  246.     sprintf (mail_file  , "%s%s", MAILHOME, user_name);
  247.     output_file = malloc (strlen(home_dir) + 2 + strlen(MBOX) + 1);
  248. #ifdef AMIGA
  249.     strcpy(output_file, MBOX);
  250. #else
  251.     sprintf (output_file, "%s/%s", home_dir, MBOX);
  252. #endif
  253.     fix_globals();
  254. #ifdef UNIX
  255.     signal (SIGHUP, sig_handle);
  256.     signal (SIGINT, sig_handle);
  257.     signal (SIGPIPE, SIG_IGN);
  258. #endif
  259. #ifdef AMIGA
  260.     signal (SIGINT, sig_handle);
  261. #endif
  262. }
  263.  
  264. sig_handle()
  265. {
  266. #ifdef UNIX
  267.     int mask = sigblock (0);
  268.  
  269.     sigsetmask (mask & ~((1 << SIGHUP) | (1 << SIGINT)));
  270. #endif
  271. #ifdef AMIGA
  272.     signal (SIGINT, sig_handle);    /*  reload signal */
  273. #endif
  274.     if (Longstack  &&  !Breakstack)
  275.     longjmp (env[Longstack], 1);
  276.     return(0);
  277. }
  278.  
  279. get_inode(file)
  280. char *file;
  281. {
  282.     struct stat stats;
  283.  
  284.     if (stat (file, &stats) < 0)
  285.     return (-1);
  286.     return (stats.st_ino);
  287. }
  288.  
  289.