home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / hyprmail.zip / hypermail.c < prev    next >
C/C++ Source or Header  |  1994-08-02  |  5KB  |  177 lines

  1. /*
  2. ** Copyright (C) 1994, Enterprise Integration Technologies Corp.        
  3. ** All Rights Reserved.
  4. ** Kevin Hughes, kevinh@eit.com 
  5. ** 8/2/94
  6. */
  7.  
  8. #define MAIN_FILE
  9. #include "hypermail.h"
  10.  
  11. int main(argc, argv)
  12.      int argc;
  13.      char **argv;
  14. {
  15.     extern char *optarg;
  16.     extern int optind;
  17.     int i, overwrite, use_stdin, use_mbox, increment;
  18.     char mbox[MAXLINE], label[MAXLINE], dir[MAXLINE],
  19.         archives[MAXLINE], about[MAXLINE], configfile[MAXLINE],
  20.         defaultindex[MAXLINE];
  21.  
  22. /* Load the hard-wired defaults, then the environment variables.
  23. */
  24.  
  25.     strcpy(mbox, MBOX);
  26.     if (getenv("HM_MBOX") != NULL)
  27.         strcpy(mbox, getenv("HM_MBOX"));
  28.     strcpy(archives, ARCHIVES);
  29.     if (getenv("HM_ARCHIVES") != NULL)
  30.         strcpy(archives, getenv("HM_ARCHIVES"));
  31.     strcpy(about, ABOUT);
  32.     if (getenv("HM_ABOUT") != NULL)
  33.         strcpy(about, getenv("HM_ABOUT"));
  34.     strcpy(label, LABEL);
  35.     if (getenv("HM_LABEL") != NULL)
  36.         strcpy(label, getenv("HM_LABEL"));
  37.     strcpy(dir, DIR);
  38.     if (getenv("HM_DIR") != NULL)
  39.         strcpy(dir, getenv("HM_DIR"));
  40.     strcpy(defaultindex, DEFAULTINDEX);
  41.     if (getenv("HM_DEFAULTINDEX") != NULL)
  42.         strcpy(defaultindex, getenv("HM_DEFAULTINDEX"));
  43.  
  44.     showprogress = PROGRESS;
  45.     if (getenv("HM_PROGRESS") != NULL)
  46.         showprogress = atoi(getenv("HM_PROGRESS"));
  47.     overwrite = OVERWRITE;
  48.     if (getenv("HM_OVERWRITE") != NULL)
  49.         overwrite = atoi(getenv("HM_OVERWRITE"));
  50.     increment = INCREMENT;
  51.     if (getenv("HM_INCREMENT") != NULL)
  52.         increment = atoi(getenv("HM_INCREMENT"));
  53.     reverse = REVERSE;
  54.     if (getenv("HM_REVERSE") != NULL)
  55.         reverse = atoi(getenv("HM_REVERSE"));
  56.     showheaders = SHOWHEADERS;
  57.     if (getenv("HM_SHOWHEADERS") != NULL)
  58.         showheaders = atoi(getenv("HM_SHOWHEADERS"));
  59.     showhtml = SHOWHTML;
  60.     if (getenv("HM_SHOWHTML") != NULL)
  61.         showhtml = atoi(getenv("HM_SHOWHTML"));
  62.     thrdlevels = THRDLEVELS;
  63.     if (getenv("HM_THRDLEVELS") != NULL)
  64.         thrdlevels = atoi(getenv("HM_THRDLEVELS"));
  65.     dirmode = DIRMODE;
  66.     if (getenv("HM_DIRMODE") != NULL)
  67.         dirmode = strtol(getenv("HM_DIRMODE"), (char **) NULL, 0);
  68.     filemode = FILEMODE;
  69.     if (getenv("HM_FILEMODE") != NULL)
  70.         filemode = strtol(getenv("HM_FILEMODE"), (char **) NULL, 0);
  71.  
  72.     strcpy(configfile, CONFIGFILE);
  73.     if (getenv("HM_CONFIGFILE") != NULL)
  74.         strcpy(configfile, getenv("HM_CONFIGFILE"));
  75.  
  76.     if (!strcmp(mbox, "NONE"))
  77.         use_stdin = 1;
  78.     else
  79.         use_stdin = 0;
  80.  
  81. /* ...then use the command-line options...
  82. */
  83.  
  84.     use_mbox = 0;
  85.     firstdatenum = lastdatenum = 0;
  86.     while ((i = (int) getopt(argc, argv, "?zhixupm:l:d:a:b:c:")) != -1)
  87.         if ((char) i == 'm') {
  88.             strcpy(mbox, optarg);
  89.             use_mbox = 1;
  90.         }
  91.         else if ((char) i == 'a')
  92.             strcpy(archives, optarg);
  93.         else if ((char) i == 'b')
  94.             strcpy(about, optarg);
  95.         else if ((char) i == 'l')
  96.             strcpy(label, optarg);
  97.         else if ((char) i == 'd')
  98.             strcpy(dir, optarg);
  99.         else if ((char) i == 'c')
  100.             strcpy(configfile, optarg);
  101.         else if ((char) i == 'x')
  102.             overwrite = 1;
  103.         else if ((char) i == 'i')
  104.             use_stdin = 1;
  105.         else if ((char) i == 'p')
  106.             showprogress = 1;
  107.         else if ((char) i == 'u')
  108.             increment = 1;
  109.         else if ((char) i == 'z' || (char) i == 'h' ||
  110.         (char) i == '?')
  111.             usage();
  112.         else
  113.             usage();
  114.  
  115. /* ...then read the configuration file.
  116. */
  117.  
  118.     readconfigs(configfile, mbox, label, dir, archives, about, &overwrite,
  119.         &increment, defaultindex);
  120.  
  121. /* Default names for directories and labels need to be figured out.
  122. */
  123.  
  124.     if (use_stdin && !strcmp(dir, "NONE"))
  125.         strcpy(dir, DIRNAME);
  126.     if (!strcmp(dir, "NONE"))
  127.         strcpy(dir, (strrchr(mbox, '/')) ? (char *) strrchr(mbox, '/')
  128.         + 1 : mbox);
  129.     if (!strcmp(label, "NONE"))
  130.         strcpy(label, (strrchr(mbox, '/')) ? (char *) strrchr(mbox, '/')
  131.         + 1 : mbox);
  132.  
  133. /* Which index file will be called "index.html"?
  134. */
  135.  
  136.     strcpy(datename, (!strcmp(defaultindex, "date")) ? INDEXNAME :
  137.     DATENAME);
  138.     strcpy(thrdname, (!strcmp(defaultindex, "thread")) ? INDEXNAME :
  139.     THRDNAME);
  140.     strcpy(subjname, (!strcmp(defaultindex, "subject")) ? INDEXNAME :
  141.     SUBJNAME);
  142.     strcpy(authname, (!strcmp(defaultindex, "author")) ? INDEXNAME :
  143.     AUTHNAME);
  144.  
  145.     if (use_mbox && use_stdin)
  146.         progerr("Can't read from file and stdin at once.");
  147.  
  148.     gettimezone();
  149.     getthisyear();
  150.     if (increment) {
  151.         loadoldheaders(dir);
  152.         loadheaders(mbox, use_stdin, 1);
  153.         checkdir(dir);
  154.         writearticles(dir, label, overwrite, bignum);
  155.         fixnextheader(dir, bignum - 1);
  156. #ifdef SHOWREPLIES
  157.         fixreplyheader(dir, bignum);
  158. #endif
  159.         fixthreadheader(dir, bignum);
  160.     }
  161.     else {
  162.         loadheaders(mbox, use_stdin, 0);
  163.         checkdir(dir);
  164.         writearticles(dir, label, overwrite, 0);
  165.     }
  166.  
  167. /* Always write the index files
  168. */
  169.  
  170.     writedates(dir, label, archives, about);
  171.     writethreads(dir, label, archives, about);
  172.     writesubjects(dir, label, archives, about);
  173.     writeauthors(dir, label, archives, about);
  174.  
  175.     exit(0);
  176. }
  177.