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 >
Wrap
C/C++ Source or Header
|
1990-12-25
|
5KB
|
286 lines
/* :ts=4
* news configuration inquiry
*
* $Log: config.c,v $
* Revision 1.4 90/12/25 15:34:25 crash
* as of 12-15-90 patches
*
* Revision 1.3 90/07/05 21:23:42 crash
* changed #define for NONSTD()
*
* Revision 1.2 90/06/04 15:07:23 crash
* one of the #if's used AZTEC/LATTICE instead of AMIGA (changed)
*
* Revision 1.1 90/05/29 21:16:41 crash
* Initial revision
*
*/
#include <stdio.h>
#ifdef unix
# include <sys/types.h>
#endif /* unix */
#include "libc.h"
#include "news.h"
#include "config.h"
#ifndef NULL
#define NULL 0
#endif
#ifndef NEWSCTL
/* =()<#define NEWSCTL "@<NEWSCTL>@">()= */
/* #define NEWSCTL "/usr/lib/news" */
#define NEWSCTL "NewsCtl:"
#endif
#ifndef NEWSPATH
/* =()<#define NEWSPATH "@<NEWSPATH>@">()= */
#define NEWSPATH "C:,CNews:"
#endif
#ifndef NEWSARTS
/* =()<#define NEWSARTS "@<NEWSARTS>@">()= */
/* #define NEWSARTS "/usr/spool/news" */
#define NEWSARTS "NewsArts:"
#endif
#ifndef NEWSBIN
/* =()<#define NEWSBIN "@<NEWSBIN>@">()= */
/* #define NEWSBIN "/usr/lib/newsbin" */
#define NEWSBIN "NewsBin:"
#endif
#ifndef NEWSUMASK
/* =()<#define NEWSUMASK @<NEWSUMASK>@>()= */
#define NEWSUMASK 002
#endif
#ifndef NEWSMASTER
/* =()<#define NEWSMASTER "@<NEWSMASTER>@">()= */
#define NEWSMASTER "newsid"
#endif
static char *pwd = NULL; /* Current directory, NULL means unknown. */
static int dirsset = NO; /* Have the following been set up? */
static char *arts = NEWSARTS;
static char *bin = NEWSBIN;
static char *ctl = NEWSCTL;
static char *path = NEWSPATH;
static int numask = NEWSUMASK;
static char *nmaster = NEWSMASTER;
#define DIRS() if (!dirsset) setdirs()
extern char *strcpy();
extern char *strcat();
extern char *getenv();
/*
- setdirs - set up stuff from environment, for use by other functions
*
* Invokes user-supplied function unprivileged() if non-standard values used.
*/
static void
setdirs()
{
register char *p;
register int mask;
register char *scan;
register int ns = 0;
#ifdef AMIGA
# define NONSTD(reason)
#else
# define NONSTD(reason) { if (!ns) { unprivileged(reason); ns = 1; } }
#endif /* AMIGA */
if (dirsset)
return;
p = envparm("NEWSARTS");
if (p != NULL && !STREQ(p, arts)) {
arts = p;
NONSTD("NEWSARTS");
}
p = envparm("NEWSCTL");
if (p != NULL && !STREQ(p, ctl)) {
ctl = p;
NONSTD("NEWSCTL");
}
p = envparm("NEWSPATH");
if (p != NULL && !STREQ(p, path)) {
path = p;
NONSTD("NEWSPATH");
}
p = envparm("NEWSBIN");
if (p != NULL && !STREQ(p, bin)) {
bin = p;
NONSTD("NEWSBIN");
}
p = envparm("NEWSUMASK");
if (p != NULL) {
mask = 0;
for (scan = p; *scan != '\0'; scan++)
if ('0' <= *scan && *scan <= '7' && mask <= 077)
mask = (mask << 3) | (*scan - '0');
else { /* Garbage, ignore it. */
mask = numask;
break; /* NOTE BREAK OUT */
}
if (mask != numask) {
numask = mask;
NONSTD("NEWSUMASK");
}
}
p = envparm("NEWSMASTER");
if (p != NULL && !STREQ(p, nmaster)) {
nmaster = p;
NONSTD("NEWSMASTER");
}
dirsset = YES;
}
/*
- artfile - best pathname for a file in NEWSARTS
*/
char *
artfile(base)
char *base;
{
static char *artf = NULL;
DIRS();
if (base == NULL) /* he just wants the directory */
return (arts);
if (artf != NULL)
free(artf); /* toss old returned value */
if (pwd != NULL && STREQ(pwd, arts))
artf = strsave(base);
#ifdef AMIGA
else if (arts[ strlen(arts)-1 ] == ':')
artf = str3save(arts, "", base);
#endif
else
artf = str3save(arts, SFNDELIM, base);
return (artf);
}
/*
- fullartfile - full pathname for a file in NEWSARTS
*/
char *
fullartfile(base)
char *base;
{
register char *p;
register char *pwdsave;
pwdsave = pwd;
pwd = NULL; /* fool artfile() into giving full path */
p = artfile(base);
pwd = pwdsave;
return (p);
}
/*
- ctlfile - full pathname for a file in NEWSCTL
*/
char *
ctlfile(base)
char *base;
{
static char *ctlf = NULL;
DIRS();
if (ctlf != NULL)
free(ctlf); /* toss old returned value */
if (base == NULL) {
ctlf = NULL;
return(ctl);
} else {
#ifdef AMIGA
if (ctl[ strlen(ctl)-1 ] == ':')
ctlf = str3save(ctl, "", base);
else
#endif
ctlf = str3save(ctl, SFNDELIM, base);
return(ctlf);
}
}
/*
- binfile - full pathname for a file in NEWSBIN
*/
char *
binfile(base)
char *base;
{
static char *binf = NULL;
DIRS();
if (binf != NULL)
free(binf); /* toss old returned value */
if (base == NULL) {
binf = NULL;
return(bin);
} else {
#ifdef AMIGA
if (bin[ strlen(bin)-1 ] == ':')
binf = str3save(bin, "", base);
else
#endif
binf = str3save(bin, SFNDELIM, base);
return (binf);
}
}
/*
- cd - change to a directory, with checking
*/
void
cd(dir)
char *dir;
{
if (pwd != NULL)
free(pwd);
if (chdir(dir))
errunlock("cannot chdir(%s)", dir);
pwd = strsave(dir);
}
/*
- newspath - search path for normal system commands
*/
char *
newspath()
{
DIRS();
return(path);
}
/*
- newsumask - suitable value of umask for news stuff
*/
int
newsumask()
{
DIRS();
return(numask);
}
/*
- newsmaster - mail address to complain to
*/
char *
newsmaster()
{
DIRS();
return(nmaster);
}