Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83 (MC840302); site erix.UUCP
Path: utzoo!linus!decvax!mcvax!enea!erix!per
From: per@erix.UUCP (Per Hedeland)
Newsgroups: net.news.b
Subject: Re: Speedup kludge for vnews 'p' command (a. o.) (using dbm files)
Message-ID: <542@erix.UUCP>
Date: Mon, 6-Aug-84 15:09:23 EDT
Article-I.D.: erix.542
Posted: Mon Aug  6 15:09:23 1984
Date-Received: Thu, 9-Aug-84 00:54:22 EDT
References: <459@erix.UUCP>
Organization: L M Ericsson, Stockholm, Sweden
Lines: 107

I'm afraid there was a bug in the fix I posted (quite a while back), in that
it didn't make sure that dbminit() was only done once. It should also be noted
that the fix doesn't agree well with the NETPATHS stuff, since you can't handle
more than one set of dbm files at a time. Anyway, here are the diffs again,
hopefully more correct this time.

Per Hedeland
per@erix.UUCP  or  ...{decvax,philabs}!mcvax!enea!erix!per


*** funcs.old.c	Sun May 27 00:09:59 1984
--- funcs.new.c	Mon Aug  6 11:29:26 1984
***************
*** 855,860
  	char oidbuf[BUFSIZ];
  	FILE *hfp;
  	char *p;
  
  	/* Try to understand old artid's as well.  Assume .UUCP domain. */
  	if (artid[0] != '<') {

--- 855,869 -----
  	char oidbuf[BUFSIZ];
  	FILE *hfp;
  	char *p;
+ #ifdef DBM
+ 	static int dbmopen = 0;
+ 	typedef struct {
+ 		char *dptr;
+ 		int dsize;
+ 	} datum;
+ 	datum lhs, rhs;
+ 	datum fetch();
+ #endif DBM
  
  	/* Try to understand old artid's as well.  Assume .UUCP domain. */
  	if (artid[0] != '<') {
***************
*** 867,872
  	} else
  		strcpy(oidbuf, artid);
  	hfp = xfopen(ARTFILE, "r");
  	while (fgets(lbuf, BUFLEN, hfp) != NULL) {
  		p = index(lbuf, '\t');
  		if (p == NULL)

--- 876,912 -----
  	} else
  		strcpy(oidbuf, artid);
  	hfp = xfopen(ARTFILE, "r");
+ #ifdef DBM
+ 	/* Use the dbm files (hoping expire is keeping them up to date) */
+ 	if (dbmopen == 0) {
+ 		if (dbminit(ARTFILE) == 0) dbmopen = 1;
+ 		else dbmopen = -1;
+ 	}
+ 	if (dbmopen == 1) {
+ 		lhs.dptr = oidbuf;
+ 		lhs.dsize = strlen(oidbuf) + 1;
+ 		rhs = fetch(lhs);
+ 		if (rhs.dptr == NULL) {
+ 			fclose(hfp);
+ 			return(NULL);
+ 		}
+ 		fseek(hfp, * (long *) rhs.dptr, 0);
+ 		if (fgets(lbuf, BUFLEN, hfp) != NULL) {
+ 			p = index(lbuf, '\t');
+ 			if (p == NULL)
+ 				p = index(lbuf, '\n');
+ 			*p = 0;
+ 			if (strcmp(lbuf, artid) == 0 || strcmp(lbuf, oidbuf) == 0) {
+ 				fclose(hfp);
+ 				*p = '\t';
+ 				*(lbuf + strlen(lbuf) - 1) = 0;	/* zap the \n */
+ 				return(lbuf);
+ 			}
+ 		}
+ 		/* The dbm files weren't up to date; revert to linear search */
+ 		fseek(hfp, 0L, 0);
+ 	}
+ #endif DBM
  	while (fgets(lbuf, BUFLEN, hfp) != NULL) {
  		p = index(lbuf, '\t');
  		if (p == NULL)


*** expire.old.c	Thu May 24 14:02:11 1984
--- expire.c	Thu May 24 14:54:57 1984
***************
*** 416,422
  		link(NARTFILE, ARTFILE);
  		unlink(NARTFILE);
  #ifdef DBM
- 		if (rebuild)
  			reblddbm ( );
  #endif
  	}

--- 416,421 -----
  		link(NARTFILE, ARTFILE);
  		unlink(NARTFILE);
  #ifdef DBM
  			reblddbm ( );
  #endif
  	}