home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / hyprmail.zip / file.c < prev    next >
C/C++ Source or Header  |  1997-03-16  |  3KB  |  128 lines

  1. /*
  2. ** Copyright (C) 1994, Enterprise Integration Technologies Corp.        
  3. ** All Rights Reserved.
  4. ** Kevin Hughes, kevinh@eit.com 
  5. ** 7/25/94
  6. */
  7.  
  8. #include "hypermail.h"
  9. #include "file.h"
  10.  
  11. /* Is a file a directory?
  12. */
  13.  
  14. int isdirectory(path)
  15.      char *path;
  16. {
  17.     struct stat stbuf;
  18.  
  19.     if (stat(path, &stbuf))
  20.         return 0;
  21.     return ((stbuf.st_mode & S_IFMT) == S_IFDIR) ? 1 : 0;
  22. }
  23.  
  24. /* Does a file exist?
  25. */
  26.  
  27. int isfile(path)
  28.      char *path;
  29. {
  30.     struct stat stbuf;
  31.  
  32.     if (stat(path, &stbuf))
  33.         return 0;
  34.     return ((stbuf.st_mode & S_IFMT) == S_IFREG) ? 1 : 0;
  35. }
  36.  
  37. /* This tries to create and chmod a directory.
  38. */
  39.  
  40. void checkdir(dir)
  41.      char *dir;
  42. {
  43.     if (!isdirectory(dir)) {
  44.         if (mkdir(dir, dirmode) == -1) {
  45.             sprintf(errmsg,
  46.             "Couldn't create archive directory \"%s\".", dir);
  47.             progerr(NULL);
  48.         }
  49.         else if (showprogress)
  50.             printf("Creating directory \"%s\", mode %o.\n",
  51.             dir, dirmode);
  52.         if (chmod(dir, dirmode) == -1) {
  53.             sprintf(errmsg, "Couldn't chmod \"%s\" to %o.",
  54.             dir, dirmode);
  55.             progerr(NULL);
  56.         }
  57.     }
  58. }
  59.  
  60. /* Reads a configuration file if it exists and puts all the right
  61. ** values into the right variables.
  62. */
  63.  
  64. void readconfigs(path, mbox, label, dir, archives, about, overwrite, increment,
  65. defaultindex)
  66.      char *path;
  67.      char *mbox;
  68.      char *label;
  69.      char *dir;
  70.      char *archives;
  71.      char *about;
  72.      int *overwrite;
  73.      int *increment;
  74.      char *defaultindex;
  75. {
  76.     char tmppath[MAXFILELEN], line[MAXLINE], value[MAXLINE];
  77.     FILE *fp;
  78.  
  79.     if (!strcmp(path, "NONE"))
  80.         return;
  81.     if (path[0] == '~') {
  82.         sprintf(tmppath, "%s%s", getenv("HOME"), path + 1);
  83.         if ((fp = fopen(tmppath, "r")) == NULL)
  84.             return;
  85.     }
  86.     else {
  87.         if ((fp = fopen(path, "r")) == NULL)
  88.             return;
  89.         printf("path: %s\n", path);
  90.     }
  91.     while (fgets(line, MAXLINE, fp) != NULL) {
  92.         if (line[0] == '#' || line[0] == '\n')
  93.             continue;
  94.         if (getconfvalue(line, "hm_mbox", value) != NULL)
  95.             strcpy(mbox, value);
  96.         if (getconfvalue(line, "hm_label", value) != NULL)
  97.             strcpy(label, value);
  98.         if (getconfvalue(line, "hm_archives", value) != NULL)
  99.             strcpy(archives, value);
  100.         if (getconfvalue(line, "hm_about", value) != NULL)
  101.             strcpy(about, value);
  102.         if (getconfvalue(line, "hm_dir", value) != NULL)
  103.             strcpy(dir, value);
  104.         if (getconfvalue(line, "hm_defaultindex", value) != NULL)
  105.             strcpy(defaultindex, value);
  106.  
  107.         if (getconfvalue(line, "hm_progress", value) != NULL)
  108.             showprogress = atoi(value);
  109.         if (getconfvalue(line, "hm_overwrite", value) != NULL)
  110.             *overwrite = atoi(value);
  111.         if (getconfvalue(line, "hm_increment", value) != NULL)
  112.             *increment = atoi(value);
  113.         if (getconfvalue(line, "hm_reverse", value) != NULL)
  114.             reverse = atoi(value);
  115.         if (getconfvalue(line, "hm_showheaders", value) != NULL)
  116.             showheaders = atoi(value);
  117.         if (getconfvalue(line, "hm_showhtml", value) != NULL)
  118.             showhtml = atoi(value);
  119.         if (getconfvalue(line, "hm_thrdlevels", value) != NULL)
  120.             thrdlevels = atoi(value);
  121.         if (getconfvalue(line, "hm_dirmode", value) != NULL)
  122.             dirmode = strtol(value, (char **) NULL, 0);
  123.         if (getconfvalue(line, "hm_filemode", value) != NULL)
  124.             filemode = strtol(value, (char **) NULL, 0);
  125.     }
  126.     fclose(fp);
  127. }
  128.