home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff319.lzh / CNewsSrc / cnews.orig.lzh / libcnews / config.c < prev    next >
C/C++ Source or Header  |  1989-06-27  |  4KB  |  251 lines

  1. /*
  2.  * news configuration inquiry
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include "libc.h"
  8. #include "news.h"
  9. #include "config.h"
  10.  
  11. #ifndef NULL
  12. #define    NULL    0
  13. #endif
  14.  
  15. #ifndef NEWSCTL
  16. /* =()<#define    NEWSCTL    "@<NEWSCTL>@">()= */
  17. #define    NEWSCTL    "/usr/lib/news"
  18. #endif
  19. #ifndef NEWSPATH
  20. /* =()<#define    NEWSPATH    "@<NEWSPATH>@">()= */
  21. #define    NEWSPATH    "/bin:/usr/bin"
  22. #endif
  23. #ifndef NEWSARTS
  24. /* =()<#define    NEWSARTS    "@<NEWSARTS>@">()= */
  25. #define    NEWSARTS    "/usr/spool/news"
  26. #endif
  27. #ifndef NEWSBIN
  28. /* =()<#define    NEWSBIN    "@<NEWSBIN>@">()= */
  29. #define    NEWSBIN    "/usr/lib/newsbin"
  30. #endif
  31. #ifndef NEWSUMASK
  32. /* =()<#define    NEWSUMASK    @<NEWSUMASK>@>()= */
  33. #define    NEWSUMASK    002
  34. #endif
  35. #ifndef NEWSMASTER
  36. /* =()<#define    NEWSMASTER    "@<NEWSMASTER>@">()= */
  37. #define    NEWSMASTER    "usenet"
  38. #endif
  39.  
  40. static char *pwd = NULL;    /* Current directory, NULL means unknown. */
  41. static int dirsset = NO;    /* Have the following been set up? */
  42. static char *arts = NEWSARTS;
  43. static char *bin = NEWSBIN;
  44. static char *ctl = NEWSCTL;
  45. static char *path = NEWSPATH;
  46. static int numask = NEWSUMASK;
  47. static char *nmaster = NEWSMASTER;
  48. #define    DIRS()    if (!dirsset) setdirs()
  49.  
  50. extern char *strcpy();
  51. extern char *strcat();
  52. extern char *getenv();
  53.  
  54. /*
  55.  - setdirs - set up stuff from environment, for use by other functions
  56.  *
  57.  * Invokes user-supplied function unprivileged() if non-standard values used.
  58.  */
  59. static void
  60. setdirs()
  61. {
  62.     register char *p;
  63.     register int nonstd = NO;
  64.     register int mask;
  65.     register char *scan;
  66.  
  67.     if (dirsset)
  68.         return;
  69.  
  70.     p = getenv("NEWSARTS");
  71.     if (p != NULL && !STREQ(p, arts)) {
  72.         nonstd = YES;
  73.         arts = p;
  74.     }
  75.  
  76.     p = getenv("NEWSCTL");
  77.     if (p != NULL && !STREQ(p, ctl)) {
  78.         ctl = p;
  79.         nonstd = YES;
  80.     }
  81.  
  82.     p = getenv("NEWSPATH");
  83.     if (p != NULL && !STREQ(p, path)) {
  84.         path = p;
  85.         nonstd = YES;
  86.     }
  87.  
  88.     p = getenv("NEWSBIN");
  89.     if (p != NULL && !STREQ(p, bin)) {
  90.         bin = p;
  91.         nonstd = YES;
  92.     }
  93.  
  94.     p = getenv("NEWSUMASK");
  95.     if (p != NULL) {
  96.         mask = 0;
  97.         for (scan = p; *scan != '\0'; scan++)
  98.             if ('0' <= *scan && *scan <= '7' && mask <= 077)
  99.                 mask = (mask << 3) | (*scan - '0');
  100.             else {    /* Garbage, ignore it. */
  101.                 mask = numask;
  102.                 break;            /* NOTE BREAK OUT */
  103.             }
  104.         if (mask != numask) {
  105.             numask = mask;
  106.             nonstd = YES;
  107.         }
  108.     }
  109.  
  110.     p = getenv("NEWSMASTER");
  111.     if (p != NULL && !STREQ(p, nmaster)) {
  112.         nmaster = p;
  113.         nonstd = YES;
  114.     }
  115.  
  116.     dirsset = YES;
  117.     if (nonstd)
  118.         unprivileged();
  119. }
  120.  
  121. /*
  122.  - artfile - best pathname for a file in NEWSARTS
  123.  */
  124. char *
  125. artfile(base)
  126. char *base;
  127. {
  128.     static char *artf = NULL;
  129.  
  130.     DIRS();
  131.  
  132.     if (base == NULL)    /* he just wants the directory */
  133.         return (arts);
  134.  
  135.     if (artf != NULL)
  136.         free(artf);    /* toss old returned value */
  137.     if (pwd != NULL && STREQ(pwd, arts))
  138.         artf = strsave(base);
  139.     else
  140.         artf = str3save(arts, SFNDELIM, base);
  141.  
  142.     return (artf);
  143. }
  144.  
  145. /*
  146.  - fullartfile - full pathname for a file in NEWSARTS
  147.  */
  148. char *
  149. fullartfile(base)
  150. char *base;
  151. {
  152.     register char *p;
  153.     register char *pwdsave;
  154.  
  155.     pwdsave = pwd;
  156.     pwd = NULL;        /* fool artfile() into giving full path */
  157.     p = artfile(base);
  158.     pwd = pwdsave;
  159.     return (p);
  160. }
  161.  
  162. /*
  163.  - ctlfile - full pathname for a file in NEWSCTL
  164.  */
  165. char *
  166. ctlfile(base)
  167. char *base;
  168. {
  169.     static char *ctlf = NULL;
  170.  
  171.     DIRS();
  172.  
  173.     if (ctlf != NULL)
  174.         free(ctlf);        /* toss old returned value */
  175.  
  176.     if (base == NULL) {
  177.         ctlf = NULL;
  178.         return(ctl);
  179.     } else {
  180.         ctlf = str3save(ctl, SFNDELIM, base);
  181.         return(ctlf);
  182.     }
  183. }
  184.  
  185. /*
  186.  - binfile - full pathname for a file in NEWSBIN
  187.  */
  188. char *
  189. binfile(base)
  190. char *base;
  191. {
  192.     static char *binf = NULL;
  193.  
  194.     DIRS();
  195.  
  196.     if (binf != NULL)
  197.         free(binf);        /* toss old returned value */
  198.  
  199.     if (base == NULL) {
  200.         binf = NULL;
  201.         return(bin);
  202.     } else {
  203.         binf = str3save(bin, SFNDELIM, base);
  204.         return (binf);
  205.     }
  206. }
  207.  
  208. /*
  209.  - cd - change to a directory, with checking
  210.  */
  211. void
  212. cd(dir)
  213. char *dir;
  214. {
  215.     if (pwd != NULL)
  216.         free(pwd);
  217.     if (chdir(dir) < 0)
  218.         errunlock("cannot chdir(%s)", dir);
  219.     pwd = strsave(dir);
  220. }
  221.  
  222. /*
  223.  - newspath - search path for normal system commands
  224.  */
  225. char *
  226. newspath()
  227. {
  228.     DIRS();
  229.     return(path);
  230. }
  231.  
  232. /*
  233.  - newsumask - suitable value of umask for news stuff
  234.  */
  235. int
  236. newsumask()
  237. {
  238.     DIRS();
  239.     return(numask);
  240. }
  241.  
  242. /*
  243.  - newsmaster - mail address to complain to
  244.  */
  245. char *
  246. newsmaster()
  247. {
  248.     DIRS();
  249.     return(nmaster);
  250. }
  251.