home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Rat's Nest 1
/
ratsnest1.iso
/
prgmming
/
c
/
loadcnf.c
< prev
next >
Wrap
Text File
|
1995-05-19
|
5KB
|
137 lines
/**************************************************************************
*
Function: LoadConfig. *
Purpose: Loads VBoard config for given node. *
Returns: Nothing, exits program if fails. *
Notes: You must have global variables GConfig and NConfig. */
void LoadConfig(unsigned short NodeNum)
{
unsigned char GConfName[80];
unsigned char NConfName[80];
unsigned char Directory[40];
unsigned char Temp[10];
unsigned char *EnvP;
unsigned short ConfigRev;
signed int Handle;
if (access("VBOARD.CFG", FALSE)) {
if ((EnvP=getenv("VBOARD"))!=NULL) {
strcpy(Directory, EnvP);
strcat(Directory, "\\");
} else {
puts("No configuration file and no VBoard environment value.");
exit(EXIT_BADCONFIG);
}
} else *Directory='\0';
sprintf(GConfName, "%sVBOARD.CFG", Directory);
sprintf(NConfName, "%sNODE-%03X.CFG", Directory, NodeNum);
if ((Handle=sopen(GConfName, O_RDONLY | O_BINARY, SH_DENYNONE))==-1) {
puts("Can't open global config!");
exit(EXIT_BADCONFIG);
}
read(Handle, Temp, 8);
if (strncmp(Temp, "VBoard\n\r", 8)) {
puts("Invalid global configuration file!");
close(Handle);
exit(EXIT_BADCONFIG);
}
read(Handle, &ConfigRev, sizeof(unsigned short));
if (ConfigRev!=CONFIGREV) {
printf("Wrong configuration revision %u. Revision %u required!\n", ConfigRev, CONFIGREV);
printf(ConfigRev<CONFIGREV ?
"Too old version. Get a recent one.\n" :
"Too new version. Please update configuration.\n");
close(Handle);
exit(EXIT_BADCONFIG);
}
read(Handle, &GConfig, sizeof(GConfig));
close(Handle);
if ((Handle=sopen(NConfName, O_RDONLY | O_BINARY, SH_DENYNONE))==-1) {
puts("Can't open node config!");
exit(EXIT_BADCONFIG);
}
read(Handle, Temp, 8);
if (strncmp(Temp, "VBoard\n\r", 8)) {
puts("Invalid global configuration file!");
close(Handle);
exit(EXIT_BADCONFIG);
}
read(Handle, &ConfigRev, sizeof(unsigned short));
if (ConfigRev!=CONFIGREV) {
printf("Wrong configuration revision %u. Revision %u required!\n", ConfigRev, CONFIGREV);
close(Handle);
exit(EXIT_BADCONFIG);
}
read(Handle, &NConfig, sizeof(NConfig));
close(Handle);
return;
}
#ifndef NODETECTCONFS
/**************************************************************************
*
Function: DetectConfs. *
Purpose: Detects critical conference numbers from confinfo.dat. *
Returns: FALSE if all OK, errorcode if not. *
Notes: You must have global variables for conference numbers. */
unsigned char DetectConfs(void)
{
unsigned char FileName[128];
signed int Handle;
CONF DConf;
if (NumberOfConfs) return 3; /* DO NOT CALL TWISE!! */
/* Zero all akas before using them. */
#ifndef NO_AKA_STRUCT
memset(&AKA, FALSE, sizeof(AKA));
#endif
strcpy(FileName, NConfig.MainDir);
strcat(FileName, "CONFINFO.DAT");
if ((Handle=sopen(FileName, O_BINARY | O_RDONLY, SH_DENYNONE))==-1) {
puts("Failed to detect conferences.");
puts(FileName);
return 1; /* Warn */
}
while(read(Handle, &DConf, sizeof(CONF))==sizeof(CONF)) {
if (Conf_Post==CONF_NOT_PRESENT && DConf.PostConf && !DConf.NetArea) Conf_Post=NumberOfConfs;
if (Conf_NetMail==CONF_NOT_PRESENT && DConf.PostConf && DConf.NetArea) Conf_NetMail=NumberOfConfs;
if (Conf_Resume==CONF_NOT_PRESENT && DConf.ResumeConf) Conf_Resume=NumberOfConfs;
if (Conf_BadEcho==CONF_NOT_PRESENT && !strcmp(DConf.AreaTag, "BADECHO")) Conf_BadEcho=NumberOfConfs;
/* Generate AKA-list */
#ifndef NO_AKA_STRUCT
if (DConf.NetArea && DConf.OwnZone) {
unsigned char i;
for (i=0;i<MAX_AKA;++i) {
if (AKA[i].OwnZone==DConf.OwnZone) break;
if (AKA[i].OwnZone==FALSE) {
AKA[i].OwnZone=DConf.OwnZone; AKA[i].HubZone=DConf.HubZone;
AKA[i].OwnNet=DConf.OwnNet; AKA[i].HubNet=DConf.HubNet;
AKA[i].OwnNode=DConf.OwnNode; AKA[i].HubNode=DConf.HubNode;
break;
}
}
}
#endif
++NumberOfConfs;
} close(Handle);
return (Conf_Post!=CONF_NOT_PRESENT) ? FALSE: 2; /* No post conf.. FAIL!!! */
}
#endif