home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 400-499 / ff473.lzh / CNewsSrc / cnews_src.lzh / libcnews / config.c < prev    next >
C/C++ Source or Header  |  1990-12-25  |  5KB  |  286 lines

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