1: #ifndef lint
   2: static char *sccsid = "@(#)active.c	1.2	(Berkeley) 3/20/86";
   3: #endif
   4: 
   5: #include "common.h"
   6: 
   7: /*
   8:  * Routines to deal with the active file
   9:  */
  10: 
  11: extern  int act_cmp();
  12: 
  13: /*
  14:  * read_groups -- read the active file into memory, sort it,
  15:  *	and return the number of newsgroups read in.
  16:  *	If FASTFORK is true, this can be called by interrupt,
  17:  *	and may have to free up the old storage.  We decide
  18:  *	this by the fact that "num_groups" will be non-zero if
  19:  *	we're here on an interrupt.
  20:  *
  21:  *	Parameters:	None.
  22:  *
  23:  *	Returns:	Number of newsgroups read into
  24:  *			memory.
  25:  *			Zero on error.
  26:  *
  27:  *	Side effects:	Reads newsgroups into "group_array"
  28:  *			and sorts them.
  29:  */
  30: 
  31: read_groups()
  32: {
  33:     char        line[MAX_STRLEN];
  34:     register int    i;
  35:     register FILE   *act_fp;
  36:     char        *malloc();
  37: 
  38:     i = 0;
  39: 
  40:     /* If we're here on an interrupt, free up all the */
  41:     /* previous groups */
  42: 
  43:     if (num_groups != 0)
  44:         for (i = 0; i < num_groups; ++i)
  45:             free(group_array[i]);
  46: 
  47:     act_fp = fopen(ACTIVE_FILE, "r");
  48:     if (act_fp == NULL)
  49:         return(0);
  50: 
  51:     while (i < MAX_GROUPS && fgets(line, sizeof(line), act_fp) != NULL) {
  52:         if ((group_array[i] = malloc(strlen(line)+1)) == NULL) {
  53:             (void) fclose(act_fp);
  54:             return(0);
  55:         }
  56:         (void) strcpy(group_array[i++], line);
  57:     }
  58: 
  59:     if (i == MAX_GROUPS) {
  60:         syslog(LOG_ERR, "read_active: active file >= %d groups", i);
  61:         syslog(LOG_ERR, "warning: recompile with MAX_GROUPS larger");
  62:     }
  63: 
  64:     (void) fclose(act_fp);
  65: 
  66:     qsort((char *) group_array, i, sizeof(char *), act_cmp);
  67: 
  68:     return(i);
  69: }
  70: 
  71: 
  72: act_cmp(ptr1, ptr2)
  73: char     **ptr1, **ptr2;
  74: {
  75:     return(strcmp(*ptr1, *ptr2));
  76: }
  77: 
  78: /*
  79:  * find_group -- find a given newsgroup and return
  80:  *	the low and high message numbers in the group
  81:  *	(space provided by user).
  82:  *
  83:  *	Parameters:	"group" is the name of the group
  84:  *			we're searching for.
  85:  *			"num_groups" is the total number
  86:  *			of groups in the group array.
  87:  *			"low_msg" and "high_msg" are
  88:  *			pointers to where we're supposed
  89:  *			to put the low and high message numbers.
  90:  *
  91:  *	Returns:	0 if all goes well,
  92:  *			-1 if we can't find the group.
  93:  *
  94:  *	Side effects:	None.
  95:  */
  96: 
  97: find_group(group, num_groups, low_msg, high_msg)
  98: char    *group;
  99: int num_groups;
 100: int *low_msg, *high_msg;
 101: {
 102:     char    kludgebuf[MAX_STRLEN];
 103:     int cond;
 104:     int low, high;
 105:     int length;
 106:     register int mid;
 107: 
 108:     low = 0;
 109:     high = num_groups-1;
 110:     (void) strcpy(kludgebuf, group);
 111:     (void) strcat(kludgebuf, " ");
 112:     length = strlen(kludgebuf);
 113: 
 114:     while (low <= high) {
 115:         mid = (low + high) / 2;
 116:         if ((cond = strncmp(kludgebuf, group_array[mid], length)) < 0)
 117:             high = mid - 1;
 118:         else if (cond > 0)
 119:             low = mid + 1;
 120:         else {
 121:             (void) sscanf(group_array[mid], "%s %d %d",
 122:                 kludgebuf, high_msg, low_msg);
 123:             return(0);
 124:         }
 125:     }
 126:     return(-1);
 127: }

Defined functions

act_cmp defined in line 72; used 2 times
find_group defined in line 97; used 1 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1986-03-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1108
Valid CSS Valid XHTML 1.0 Strict