|
|
1.1 ! root 1: /* $Header: ngdata.c,v 4.3 85/05/01 11:44:38 lwall Exp $ ! 2: * ! 3: * $Log: ngdata.c,v $ ! 4: * Revision 4.3 85/05/01 11:44:38 lwall ! 5: * Baseline for release with 4.3bsd. ! 6: * ! 7: */ ! 8: ! 9: #include "EXTERN.h" ! 10: #include "common.h" ! 11: #include "ndir.h" ! 12: #include "rcstuff.h" ! 13: #include "rn.h" ! 14: #include "intrp.h" ! 15: #include "final.h" ! 16: #include "rcln.h" ! 17: #include "INTERN.h" ! 18: #include "ngdata.h" ! 19: ! 20: void ! 21: ngdata_init() ! 22: { ! 23: /* The following is only for systems that do not zero globals properly */ ! 24: #ifdef ZEROGLOB ! 25: # ifdef CACHEFIRST ! 26: for (i=0; i<MAXRCLINE; i++) ! 27: abs1st[i] = 0; ! 28: # endif ! 29: #endif /* ZEROGLOB */ ! 30: ! 31: /* open the active file */ ! 32: ! 33: actfp = fopen(filexp(ACTIVE),"r"); ! 34: if (actfp == Nullfp) { ! 35: printf(cantopen,filexp(ACTIVE)) FLUSH; ! 36: finalize(1); ! 37: } ! 38: } ! 39: ! 40: /* find the maximum article number of a newsgroup */ ! 41: ! 42: ART_NUM ! 43: getngsize(num) ! 44: register NG_NUM num; ! 45: { ! 46: register int len; ! 47: register char *nam; ! 48: char tmpbuf[80]; ! 49: ART_POS oldsoft; ! 50: ! 51: nam = rcline[num]; ! 52: len = rcnums[num] - 1; ! 53: softtries++; ! 54: #ifdef DEBUGGING ! 55: if (debug & DEB_SOFT_POINTERS) ! 56: printf("Softptr = %ld\n",(long)softptr[num]) FLUSH; ! 57: #endif ! 58: oldsoft = softptr[num]; ! 59: if ((softptr[num] = findact(tmpbuf, nam, len, (long)oldsoft)) >= 0) { ! 60: if (softptr[num] != oldsoft) { ! 61: softmisses++; ! 62: writesoft = TRUE; ! 63: } ! 64: } ! 65: else { ! 66: softptr[num] = 0; ! 67: if (rcchar[num] == ':') /* unsubscribe quietly */ ! 68: rcchar[num] = NEGCHAR; ! 69: return TR_BOGUS; /* well, not so quietly, actually */ ! 70: } ! 71: ! 72: #ifdef DEBUGGING ! 73: if (debug & DEB_SOFT_POINTERS) { ! 74: printf("Should be %ld\n",(long)softptr[num]) FLUSH; ! 75: } ! 76: #endif ! 77: #ifdef MININACT ! 78: { ! 79: register char *s; ! 80: ART_NUM tmp; ! 81: ! 82: for (s=tmpbuf+len+1; isdigit(*s); s++) ; ! 83: if (tmp = atol(s)) ! 84: #ifdef CACHEFIRST ! 85: abs1st[num] = tmp; ! 86: #else ! 87: abs1st = tmp; ! 88: #endif ! 89: } ! 90: #endif ! 91: return atol(tmpbuf+len+1); ! 92: } ! 93: ! 94: ACT_POS ! 95: findact(outbuf,nam,len,suggestion) ! 96: char *outbuf; ! 97: char *nam; ! 98: int len; ! 99: long suggestion; ! 100: { ! 101: ACT_POS retval; ! 102: ! 103: fseek(actfp,100000L,1); /* hopefully this forces a reread */ ! 104: if (suggestion == 0L || fseek(actfp,suggestion,0) < 0 || ! 105: fgets(outbuf,80,actfp) == Nullch || ! 106: outbuf[len] != ' ' || ! 107: strnNE(outbuf,nam,len)) { ! 108: #ifdef DEBUGGING ! 109: if (debug & DEB_SOFT_POINTERS) ! 110: printf("Missed, looking for %s in %sLen = %d\n",nam,outbuf,len) ! 111: FLUSH; ! 112: #endif ! 113: fseek(actfp,0L,0); ! 114: #ifndef lint ! 115: retval = (ACT_POS)ftell(actfp); ! 116: #else ! 117: retval = Null(ACT_POS); ! 118: #endif lint ! 119: while (fgets(outbuf,80,actfp) != Nullch) { ! 120: if (outbuf[len] == ' ' && strnEQ(outbuf,nam,len)) ! 121: return retval; ! 122: #ifndef lint ! 123: retval = (ACT_POS) ftell(actfp); ! 124: #endif lint ! 125: } ! 126: return (ACT_POS) -1; /* well, not so quietly, actually */ ! 127: } ! 128: else ! 129: #ifndef lint ! 130: return (ACT_POS) suggestion; ! 131: #else ! 132: return retval; ! 133: #endif lint ! 134: /*NOTREACHED*/ ! 135: } ! 136: ! 137: /* determine the absolutely first existing article number */ ! 138: ! 139: ART_NUM ! 140: getabsfirst(ngnum,ngsize) ! 141: register NG_NUM ngnum; ! 142: ART_NUM ngsize; ! 143: { ! 144: register ART_NUM a1st; ! 145: #ifndef MININACT ! 146: char dirname[MAXFILENAME]; ! 147: #endif ! 148: ! 149: #ifdef CACHEFIRST ! 150: if (a1st = abs1st[ngnum]) ! 151: return a1st; ! 152: #endif ! 153: #ifdef MININACT ! 154: getngsize(ngnum); ! 155: # ifdef CACHEFIRST ! 156: return abs1st[ngnum]; ! 157: # else ! 158: return abs1st; ! 159: # endif ! 160: #else not MININACT ! 161: sprintf(dirname,"%s/%s",spool,getngdir(rcline[ngnum])); ! 162: a1st = getngmin(dirname,0L); ! 163: if (!a1st) /* nothing there at all? */ ! 164: a1st = ngsize+1; /* aim them at end of newsgroup */ ! 165: # ifdef CACHEFIRST ! 166: abs1st[ngnum] = a1st; ! 167: # endif ! 168: return a1st; ! 169: #endif MININACT ! 170: } ! 171: ! 172: /* scan a directory for minimum article number greater than floor */ ! 173: ! 174: ART_NUM ! 175: getngmin(dirname,floor) ! 176: char *dirname; ! 177: ART_NUM floor; ! 178: { ! 179: register DIR *dirp; ! 180: register struct direct *dp; ! 181: register ART_NUM min = 1000000; ! 182: register ART_NUM maybe; ! 183: register char *p; ! 184: char tmpbuf[128]; ! 185: ! 186: dirp = opendir(dirname); ! 187: if (!dirp) ! 188: return 0; ! 189: while ((dp = readdir(dirp)) != Null(struct direct *)) { ! 190: if ((maybe = atol(dp->d_name)) < min && maybe > floor) { ! 191: for (p = dp->d_name; *p; p++) ! 192: if (!isdigit(*p)) ! 193: goto nope; ! 194: if (*dirname == '.' && !dirname[1]) ! 195: stat(dp->d_name, &filestat); ! 196: else { ! 197: sprintf(tmpbuf,"%s/%s",dirname,dp->d_name); ! 198: stat(tmpbuf, &filestat); ! 199: } ! 200: if (! (filestat.st_mode & S_IFDIR)) ! 201: min = maybe; ! 202: } ! 203: nope: ! 204: ; ! 205: } ! 206: closedir(dirp); ! 207: return min==1000000 ? 0 : min; ! 208: } ! 209:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.