home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / nn.tar / nn-6.5.1 / active.c < prev    next >
C/C++ Source or Header  |  1995-04-29  |  3KB  |  135 lines

  1. /*
  2.  *    (c) Copyright 1990, Kim Fabricius Storm.  All rights reserved.
  3.  *
  4.  *    read/update incore copy of active file
  5.  */
  6.  
  7. #include "config.h"
  8.  
  9. void
  10. read_active_file(act, copy)
  11. FILE *act, *copy;
  12. {
  13.     char line[512];
  14.     register char *cp, *name;
  15.     register group_header *gh, *gh1;
  16.     int must_update;
  17.     register flag_type old_flag;
  18.     
  19.     Loop_Groups_Header(gh) {
  20.     gh->master_flag &= ~M_VALID;
  21.     gh->first_a_article = 0;
  22.     gh->last_a_article = 0;
  23.     }
  24.  
  25.     while (fgets(line, 512, act)) {
  26.     if (copy != NULL) fputs(line, copy);
  27.     must_update = 0;
  28.  
  29.     cp = line;
  30.     while (*cp && isspace(*cp)) cp++; /* eat blank lines */
  31.     if (*cp == NUL || *cp == '#') continue;
  32.  
  33.     /* cp -> NAME space 00888 ... nl */
  34.     name = cp;
  35.     while (*cp != ' ') cp++;
  36.     *cp++ = NUL;
  37.  
  38.     gh = lookup_no_alias(name);
  39.     if (gh == NULL) {
  40.         /* new group */
  41.         gh = add_new_group(name);
  42.         if (gh == NULL) continue;
  43.         must_update = 1;
  44.     }
  45.     
  46.     while (*cp && isspace(*cp)) cp++;
  47.     gh->last_a_article = atol(cp);
  48.  
  49.     while (*cp && isdigit(*cp)) cp++;
  50.     while (*cp && isspace(*cp)) cp++;
  51.  
  52.     if (*cp == NUL) {
  53.         log_entry('E', "Error in active file for entry %s", name);
  54.         continue;
  55.     }
  56.  
  57.     gh->first_a_article = atol(cp);
  58.     if (gh->first_a_article == 0) gh->first_a_article = 1;
  59.     while (*cp && isdigit(*cp)) cp++;
  60.     while (*cp && isspace(*cp)) cp++;
  61.  
  62.     gh->master_flag |= M_VALID;
  63.     if (gh->master_flag & M_IGNORE_G) continue;
  64.  
  65.     old_flag = gh->master_flag & 
  66.         (M_IGNORE_A | M_MODERATED | M_NOPOST | M_ALIASED);
  67.     gh->master_flag &= 
  68.         ~(M_IGNORE_A | M_MODERATED | M_NOPOST | M_ALIASED);
  69.     
  70.     switch (*cp) {
  71.      default:
  72.         break;
  73.  
  74.      case 'x':
  75.         gh->master_flag |= M_IGNORE_A;
  76.         if ((old_flag & (M_IGNORE_A|M_ALIASED)) == M_IGNORE_A) continue;
  77.         must_update++;
  78.         break;
  79.  
  80.      case 'm':
  81.         gh->master_flag |= M_MODERATED;
  82.         if (old_flag & M_MODERATED) continue;
  83.         must_update++;
  84.         break;
  85.  
  86.      case 'n':
  87.         gh->master_flag |= M_NOPOST;
  88.         if (old_flag & M_NOPOST) continue;
  89.         must_update++;
  90.         break;
  91.  
  92.      case '=':
  93.         while (*++cp && isspace(*cp)) cp++;
  94.         name = cp;
  95.         while (*cp && !isspace(*cp)) cp++;
  96.         *cp = NUL;
  97.         if (old_flag & M_ALIASED) {
  98.         /* quick check: has the alias changed */
  99.         int32 n = (int32)gh->data_write_offset;
  100.         if (n >= 0 && n < master.number_of_groups) {
  101.             gh1 = ACTIVE_GROUP(n);
  102.             if (strcmp(gh1->group_name, name) == 0) {
  103.             gh->master_flag |= M_ALIASED | M_IGNORE_A;
  104.             continue;
  105.             }
  106.         }
  107.         }
  108.         gh1 = lookup_no_alias(name);
  109.         if (gh1 == NULL) {
  110.         /* '=unknown.group' is treated just like 'x' */
  111.         if ((old_flag & M_IGNORE_A) == 0)
  112.             log_entry('R', "Group %s aliased to unknown group (%s)",
  113.                   gh->group_name, name);
  114.         gh->master_flag |= M_IGNORE_A;
  115.         if ((old_flag & (M_IGNORE_A|M_ALIASED)) == M_IGNORE_A)
  116.             continue;
  117.         } else {
  118.         gh->master_flag |= M_ALIASED | M_IGNORE_A;
  119.         gh->data_write_offset = (off_t)gh1->group_num;
  120.         }
  121.         must_update = 1;
  122.         break;
  123.     }
  124.  
  125.     if ((old_flag & M_ALIASED) && (gh->master_flag & M_ALIASED) == 0) {
  126.         gh->data_write_offset = 0;
  127.         gh->master_flag |= M_MUST_CLEAN;
  128.         continue;
  129.     }
  130.         
  131.     if (must_update && who_am_i == I_AM_MASTER)
  132.         db_write_group(gh);
  133.     }
  134. }
  135.