home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume22 / bigb / part01 / read_data.c < prev    next >
C/C++ Source or Header  |  1991-09-13  |  4KB  |  131 lines

  1. /* This reads in the lists of terminals/users to be checked/not checked -
  2.  * it also sets the flags to determine how the system databases should
  3.  * be most efficiently searched.
  4. */
  5.  
  6. #include "bigb.h"
  7. #include <ctype.h>
  8. #include <memory.h>
  9. #include <string.h>
  10. #include <signal.h>
  11.  
  12. /* Define the local functions */
  13. PRIVATE void    get_terminal_data(void);
  14. PRIVATE void    get_user_data(void);
  15. PRIVATE int     logical_option(int, int);
  16.  
  17. /* Read all the entries from the data files */
  18. PUBLIC void get_params(void)
  19. {
  20.     /* Read the list of terminals to be checked/not checked */
  21.     get_terminal_data();
  22.  
  23.     /* Read the list of users to be checked/not checked */
  24.     get_user_data();
  25. }
  26.  
  27. PRIVATE void get_terminal_data(void)
  28. {
  29.     FILE    *fp1,
  30.             *fp2;
  31.     int     n1 = -1,    /* Number of 'check' entries read */
  32.             n2 = -1;    /* Number of 'nocheck' entries read */
  33.  
  34.     fp1 = fopen(terminal_check_file,"r");
  35.     fp2 = fopen(terminal_nocheck_file,"r");
  36.  
  37.     if (fp1 != FNULL)   /* If check file exists */
  38.         n1=read_list(&terminals_to_check, fp1);
  39.     if (fp2 != FNULL)   /* If exclude file exists */
  40.         n2=read_list(&terminals_to_exclude, fp2);
  41.  
  42.     fclose(fp2);
  43.     fclose(fp1);
  44.  
  45.     /* Choose the CHECK_ALL, CHECK_NONE, ... status */
  46.     terminal_check = logical_option(n1,n2);
  47.  
  48.     if (terminal_check == CHECK_NONE)
  49.         /* A warning seems appropriate */
  50.         puts("bigb: Not checking any terminals");
  51. }
  52.  
  53. PRIVATE void get_user_data(void)
  54. {
  55.     FILE    *fp1,
  56.             *fp2;
  57.     int     n1 = -1,    /* Number of 'check' entries read */
  58.             n2 = -1;    /* Number of 'nocheck' entries read */
  59.  
  60.     fp1 = fopen(user_check_file,"r");
  61.     fp2 = fopen(user_nocheck_file,"r");
  62.  
  63.     if (fp1 != FNULL)   /* If check file exists */
  64.         n1=read_list(&users_to_check, fp1);
  65.     if (fp2 != FNULL)   /* If exclude file exists */
  66.         n2=read_list(&users_to_exclude, fp2);
  67.  
  68.     fclose(fp2);
  69.     fclose(fp1);
  70.  
  71.     /* Choose the CHECK_ALL, CHECK_NONE, ... status */
  72.     user_check = logical_option(n1,n2);
  73.  
  74.     if (user_check == CHECK_NONE)
  75.         /* A warning seems appropriate */
  76.         puts("bigb: Not checking any users");
  77. }
  78.  
  79. /* Choose the most efficient option for the combination of items to
  80.  * check and exclude given.
  81. */
  82. PRIVATE int logical_option(int n1,int n2)
  83. {
  84.     /* n1 is the number of check entries ( -1 for no list given ) */
  85.     /* n2 is the number of ignore entries ( -1 for no list given ) */
  86.  
  87.     if (n1 < 0) {
  88.         switch(n2) {
  89.             case -1 : return(CHECK_NONE);
  90.             case 0  : return(CHECK_ALL);
  91.             default : return(CHECK_EXCLUDE);
  92.         }
  93.         return(CHECK_NONE);     /* Should not get here */
  94.     }
  95.  
  96.     if (n1 == 0) {
  97.         return(CHECK_NONE);
  98.     }
  99.  
  100.     if (n1 > 0) {
  101.         switch(n2) {
  102.             case -1 : return(CHECK_SPECIFIC);
  103.             case 0  : return(CHECK_SPECIFIC);
  104.             default : return(CHECK_SPECIFIC | CHECK_EXCLUDE);
  105.         }
  106.         return(CHECK_NONE);     /* Should not get here */
  107.     }
  108. }
  109.  
  110. /* Update the lists of terminals and users to be checked
  111.  * This is called by signal() so can happen at any time.
  112. */
  113. PUBLIC void update_data(void)
  114. {
  115.     /* Stop signals while processing the last one */
  116.     signal(SIGHUP,SIG_IGN);
  117.  
  118.     /* Free all the old lists */
  119.     free_list(&terminals_to_check);
  120.     free_list(&terminals_to_exclude);
  121.     free_list(&users_to_check);
  122.     free_list(&users_to_exclude);
  123.  
  124.     /* Read the new data */
  125.     read_config();
  126.     get_params();
  127.  
  128.     /* Restart signals */
  129.     signal(SIGHUP,update_data);
  130. }
  131.