home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
b
/
bmh02src.zip
/
RC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-16
|
6KB
|
207 lines
/*
rc.c : Copyright Paul Healy, EI9GL, 1992.
Derived from bm.
Copyright 1986 Bdale Garbee, All Rights Reserved.
Permission granted for non-commercial copying and use, provided
this notice is retained.
Copyright 1987 1988 Dave Trulli NN2Z, All Rights Reserved.
Permission granted for non-commercial copying and use, provided
this notice is retained.
resource filehandling - initialises internal bm user environment.
911217 : Added this header
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include "rc.h"
#include "pc.h"
#include "misc.h"
static int NotLoaded = 1;
#ifdef UNIX
#define RUNCOM ".bmrc" /* config file */
#endif
#ifdef MSDOS
#define RUNCOM "/bm.rc"
#endif
#ifndef RUNCOM
#define RUNCOM "bm.rc"
#endif
static int parsefile(char *name);
/*
* commands, and their defaults, which are valid in bm.rc / .bmrc
*/
static struct tok {
char *str;
char *val;
} rccmds[] = {
"alias", "/alias", /* alias, alias file */
"bufsize", "40960", /* bufsize, internal mail file buffer (40k) */
"current", "/current.bmh", /* current, file holding current folder/msg */
"edit", NULL, /* editor, user's favorite text editor */
"editline", "y", /* editline, call DOS fn 0A for console input */
"folder", NULL, /* folder, directory for saving read mail */
"fullname", NULL, /* fullname, fullname of user */
"host", NULL, /* hostname, name of this host */
"smtp", "/spool/mail", /* maildir, mail directory */
"columns", "80", /* maxcol, number of screen character columns */
"maxlet", "300", /* maxlet, maximum number of msgs in a file */
"rows", "24", /* maxrow, number of screen character rows */
"mqueue", "/spool/mqueue", /* mqueue, defined mqueue outbound directory */
"newsdir", "/spool/news", /* newsdir, news directory */
"organ", NULL, /* organ, nntp organization header */
"record", NULL, /* record, record outbound mail in this file */
"reply", NULL, /* replyto, address for reply-to header */
"rewrite", NULL, /* rewrite, rewrite file */
"signature",NULL, /* signature, location of sig file */
"spooldir", "/spool", /* spooldir, spool directory - areas file etc */
"mbox", "mbox", /* savebox, name of the mbox text file */
"screen", "bios", /* screen, screen access mode under Turbo C */
"source", NULL, /* source, pull in rc info from another file */
"tsbids", "y", /* tsbids, add time stamp to bids in history file */
"tmpdir", NULL, /* tmpdir, directory for temporary files */
"user", NULL, /* username, name of this user from rc file */
"viewer", NULL, /* viewer, program to view files with */
NULL,
};
/*
* return the rc type from a line of the configuration file
*/
static int
rctype(char *s)
{
int i;
for (i=0; rccmds[i].str != NULL; i++) {
if (strcmp(rccmds[i].str, s) == 0)
return i;
}
return -1;
}
/*
* check for important settings
*/
static int
checkrc(UserVar u)
{
switch (u) {
case maildir:
case mqueue:
if(access(rccmds[u].val, 0)) {
fprintf(stderr, "bm: unable to access %s\n", rccmds[u].val);
return -1;
}
break;
case hostname:
if(rccmds[u].val == NULL) {
fprintf(stderr, "bm: %s not set\n", rccmds[u].str);
return -1;
}
break;
case screen:
setvideo(rccmds[u].val);
break;
case source:
if (parsefile(rccmds[u].val) == -1)
return -1;
break;
default:
break;
}
return 0;
}
static int
parserc(char *s)
{
int type;
char *argv[MAXARGS];
if ( (parse(s, argv, MAXARGS) < 2 ) || (type = rctype(argv[0])) == -1) {
fprintf(stderr, "bm: invalid command '%s'\n", argv[0]);
return -1;
}
else {
rccmds[type].val = strdup(argv[1]);
if (checkrc(type) == -1)
return -1;
}
return 0;
}
static int
parsefile(char *name)
{
FILE *rcfp;
char rcline[LINELEN];
if ( (rcfp = fopen(name, "r")) == NULL) {
fprintf(stderr, "bm: cannot open '%s', check your installation\n", name);
return -1;
}
while (fgets(rcline, sizeof(rcline), rcfp) != NULL) {
if (*rcline == '#' || *rcline == '\n' ||
*rcline == '\0' || *rcline == ';')
continue;
rip(rcline);
if (parserc(rcline) == -1) {
fclose(rcfp);
return -1;
}
}
return fclose(rcfp);
}
char *
getrc(UserVar u)
{
if (NotLoaded)
loadconfig();
return rccmds[u].val;
}
/*
* returns -1 if config file couldn't be parsed correctly. 0 otherwise.
*/
int
loadconfig(void)
{
char runcom[LINELEN], *p;
NotLoaded = 0;
/*
* check for BMHRC/BMRC in the ENV
*/
if ((p = getenv("BMHRC")) != NULL)
strcpy(runcom, p);
else if ( (p = getenv("BMRC")) != NULL )
strcpy(runcom, p);
else if ((p = getenv("HOME")) != NULL) /* Try $HOME/RUNCOM */
sprintf(runcom, "%s/%s", p, RUNCOM);
else
strcpy(runcom, RUNCOM);
if (parsefile(runcom) == -1)
return -1;
if ( (checkrc(maildir) == -1) ||
(checkrc(mqueue) == -1) ||
(checkrc(hostname) == -1) )
return -1;
return 0;
}