home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume22
/
bigb
/
part01
/
read_data.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-13
|
4KB
|
131 lines
/* This reads in the lists of terminals/users to be checked/not checked -
* it also sets the flags to determine how the system databases should
* be most efficiently searched.
*/
#include "bigb.h"
#include <ctype.h>
#include <memory.h>
#include <string.h>
#include <signal.h>
/* Define the local functions */
PRIVATE void get_terminal_data(void);
PRIVATE void get_user_data(void);
PRIVATE int logical_option(int, int);
/* Read all the entries from the data files */
PUBLIC void get_params(void)
{
/* Read the list of terminals to be checked/not checked */
get_terminal_data();
/* Read the list of users to be checked/not checked */
get_user_data();
}
PRIVATE void get_terminal_data(void)
{
FILE *fp1,
*fp2;
int n1 = -1, /* Number of 'check' entries read */
n2 = -1; /* Number of 'nocheck' entries read */
fp1 = fopen(terminal_check_file,"r");
fp2 = fopen(terminal_nocheck_file,"r");
if (fp1 != FNULL) /* If check file exists */
n1=read_list(&terminals_to_check, fp1);
if (fp2 != FNULL) /* If exclude file exists */
n2=read_list(&terminals_to_exclude, fp2);
fclose(fp2);
fclose(fp1);
/* Choose the CHECK_ALL, CHECK_NONE, ... status */
terminal_check = logical_option(n1,n2);
if (terminal_check == CHECK_NONE)
/* A warning seems appropriate */
puts("bigb: Not checking any terminals");
}
PRIVATE void get_user_data(void)
{
FILE *fp1,
*fp2;
int n1 = -1, /* Number of 'check' entries read */
n2 = -1; /* Number of 'nocheck' entries read */
fp1 = fopen(user_check_file,"r");
fp2 = fopen(user_nocheck_file,"r");
if (fp1 != FNULL) /* If check file exists */
n1=read_list(&users_to_check, fp1);
if (fp2 != FNULL) /* If exclude file exists */
n2=read_list(&users_to_exclude, fp2);
fclose(fp2);
fclose(fp1);
/* Choose the CHECK_ALL, CHECK_NONE, ... status */
user_check = logical_option(n1,n2);
if (user_check == CHECK_NONE)
/* A warning seems appropriate */
puts("bigb: Not checking any users");
}
/* Choose the most efficient option for the combination of items to
* check and exclude given.
*/
PRIVATE int logical_option(int n1,int n2)
{
/* n1 is the number of check entries ( -1 for no list given ) */
/* n2 is the number of ignore entries ( -1 for no list given ) */
if (n1 < 0) {
switch(n2) {
case -1 : return(CHECK_NONE);
case 0 : return(CHECK_ALL);
default : return(CHECK_EXCLUDE);
}
return(CHECK_NONE); /* Should not get here */
}
if (n1 == 0) {
return(CHECK_NONE);
}
if (n1 > 0) {
switch(n2) {
case -1 : return(CHECK_SPECIFIC);
case 0 : return(CHECK_SPECIFIC);
default : return(CHECK_SPECIFIC | CHECK_EXCLUDE);
}
return(CHECK_NONE); /* Should not get here */
}
}
/* Update the lists of terminals and users to be checked
* This is called by signal() so can happen at any time.
*/
PUBLIC void update_data(void)
{
/* Stop signals while processing the last one */
signal(SIGHUP,SIG_IGN);
/* Free all the old lists */
free_list(&terminals_to_check);
free_list(&terminals_to_exclude);
free_list(&users_to_check);
free_list(&users_to_exclude);
/* Read the new data */
read_config();
get_params();
/* Restart signals */
signal(SIGHUP,update_data);
}