⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 invlib.c

📁 tvapp用于播放tv程序
💻 C
📖 第 1 页 / 共 3 页
字号:
		entryptr = (ENTRY *)intptr + imid;		i = strncmp(searchterm, invcntl->logblk->chrblk + entryptr->offset,		    (int) entryptr->size );		if (i == 0)			i = strlen(searchterm) - entryptr->size;		if (i < 0)			ihigh = imid - 1;		else if (i > 0)			ilow = ++imid;		else {			num = entryptr->post;			break;		}	}	/* be careful about case where searchterm is after last in this block  */	if (imid >= invcntl->logblk->invblk[0]) {		invcntl->keypnt = invcntl->logblk->invblk[0];		invstep(invcntl);		/* note if this happens the term could be in extended block */		if (invcntl->param.startbyte < invcntl->numblk * invcntl->param.sizeblk)			goto srch_ext;	} else		invcntl->keypnt = imid;	return(num);}#if DEBUG/** invdump dumps the block the term parameter is in **/voidinvdump(INVCONTROL *invcntl, char *term){	long	i, j, n, *longptr;	ENTRY * entryptr;	char	temp[512], *ptr;	/* dump superindex if term is "-"  */	if (*term == '-') {		j = atoi(term + 1);		longptr = (long *)invcntl->iindex;		n = *longptr++;		(void) printf("Superindex dump, num blocks=%ld\n", n);		longptr += j;		while ((longptr <= ((long *)invcntl->iindex) + n) && invbreak == 0) {			(void) printf("%2ld  %6ld %s\n", j++, *longptr, invcntl->iindex + *longptr);			longptr++;		}		return;	} else if (*term == '#') {		j = atoi(term + 1);		/* fetch the appropriate logical block */		invcntl->numblk = j;		(void) fseek(invcntl->invfile, (j * invcntl->param.sizeblk) + invcntl->param.cntlsize, 0);		(void) fread(invcntl->logblk, (int) invcntl->param.sizeblk, 1, invcntl->invfile);	} else		i = abs((int) invfind(invcntl, term));	longptr = invcntl->logblk->invblk;	n = *longptr++;	(void) printf("Entry term to invdump=%s, postings=%ld, forwrd ptr=%ld, back ptr=%ld\n"	    , term, i, *(longptr), *(longptr + 1));	/* FIXME HBB: magic number alert! (3) */	entryptr = (ENTRY *) (invcntl->logblk->invblk + 3);	(void) printf("%ld terms in this block, block=%ld\n", n, invcntl->numblk);	(void) printf("\tterm\t\t\tposts\tsize\toffset\tspace\t1st word\n");	for (j = 0; j < n && invbreak == 0; j++) {		ptr = invcntl->logblk->chrblk + entryptr->offset;		(void) strncpy(temp, ptr, (int) entryptr->size);		temp[entryptr->size] = '\0';		ptr += (sizeof(long) * (long)((entryptr->size + (sizeof(long) - 1)) / sizeof(long)));		(void) printf("%2ld  %-24s\t%5ld\t%3d\t%d\t%d\t%ld\n", j, temp, entryptr->post,		    entryptr->size, entryptr->offset, entryptr->space,		    *(long *)ptr);		entryptr++;	}}#endifstatic intboolready(void){	numitems = 0;	if (item1 != NULL) 		free(item1);	setsize1 = SETINC;	if ((item1 = malloc(SETINC * sizeof(POSTING))) == NULL) {		invcannotalloc(SETINC);		return(-1);	}	if (item2 != NULL) 		free(item2);	setsize2 = SETINC;	if ((item2 = malloc(SETINC * sizeof(POSTING))) == NULL) {		invcannotalloc(SETINC);		return(-1);	}	item = item1;	enditem = item;	return(0);}voidboolclear(void){	numitems = 0;	item = item1;	enditem = item;}POSTING *boolfile(INVCONTROL *invcntl, long *num, int boolarg){	ENTRY	*entryptr;	FILE	*file;	void	*ptr;	unsigned long	*ptr2;	POSTING	*newitem = NULL; /* initialize, to avoid warning */	POSTING	posting;	unsigned u;	POSTING *newsetp = NULL, *set1p;	long	newsetc, set1c, set2c;	/* FIXME HBB: magic number alert! (3) */	entryptr = (ENTRY *) (invcntl->logblk->invblk + 3) + invcntl->keypnt;	ptr = invcntl->logblk->chrblk + entryptr->offset;	ptr2 = ((unsigned long *) ptr) + (entryptr->size + (sizeof(long) - 1)) / sizeof(long);	*num = entryptr->post;	switch (boolarg) {	case BOOL_OR:	case NOT:		if (*num == 0) {			*num = numitems;			return(item);		}	}	/* make room for the new set */	u = 0;	switch (boolarg) {	case AND:	case NOT:		newsetp = set1p = item;		break;	case BOOL_OR:		u = enditem - item;		/* FALLTHROUGH */	case REVERSENOT:		u += *num;		if (item == item2) {			if (u > setsize1) {				u += SETINC;				if ((item1 = realloc(				    item1, u * sizeof(POSTING))) == NULL) {					goto cannotalloc;				}				setsize1 = u;			}			newitem = item1;		}		else {			if (u > setsize2) {				u += SETINC;				if ((item2 = realloc( 				    item2, u * sizeof(POSTING))) == NULL) {				cannotalloc:					invcannotalloc(u * sizeof(POSTING));					(void) boolready();					*num = -1;					return(NULL);				}				setsize2 = u;			}			newitem = item2;		}		set1p = item;		newsetp = newitem;	}	file = invcntl->postfile;	(void) fseek(file, (long) *ptr2, 0);	(void) fread(&posting, (int) sizeof(posting), 1, file);	newsetc = 0;	switch (boolarg) {	case BOOL_OR:		/* while something in both sets */		set1p = item;		newsetp = newitem;		for (set1c = 0, set2c = 0;		    set1c < numitems && set2c < *num; newsetc++) {			if (set1p->lineoffset < posting.lineoffset) {				*newsetp++ = *set1p++;				set1c++;			}			else if (set1p->lineoffset > posting.lineoffset) {				*newsetp++ = posting;				(void) fread(&posting, (int) sizeof(posting), 1, file);				set2c++;			}			else if (set1p->type < posting.type) {				*newsetp++ = *set1p++;				set1c++;			}			else if (set1p->type > posting.type) {				*newsetp++ = posting;				(void) fread(&posting, (int) sizeof(posting), 1, file);				set2c++;			}			else {	/* identical postings */				*newsetp++ = *set1p++;				set1c++;				(void) fread(&posting, (int) sizeof(posting), 1, file);				set2c++;			}		}		/* find out what ran out and move the rest in */		if (set1c < numitems) {			newsetc += numitems - set1c;			while (set1c++ < numitems) {				*newsetp++ = *set1p++;			}		} else {			while (set2c++ < *num) {				*newsetp++ = posting;				newsetc++;				(void) fread(&posting, (int) sizeof(posting), 1, file);			}		}		item = newitem;		break; /* end of BOOL_OR */#if 0	case AND:		for (set1c = 0, set2c = 0; set1c < numitems && set2c < *num; ) {			if (set1p->lineoffset < posting.lineoffset) {				set1p++;				set1c++;			}			else if (set1p->lineoffset > posting.lineoffset) {				(void) fread(&posting, (int) sizeof(posting), 1, file);				set2c++;			}			else if (set1p->type < posting.type)  {				*set1p++;				set1c++;			}			else if (set1p->type > posting.type) {				(void) fread(&posting, (int) sizeof(posting), 1, file);				set2c++;			}			else {	/* identical postings */				*newsetp++ = *set1p++;				newsetc++;				set1c++;				(void) fread(&posting, (int) sizeof(posting), 1, file);				set2c++;			}		}		break; /* end of AND */	case NOT:		for (set1c = 0, set2c = 0; set1c < numitems && set2c < *num; ) {			if (set1p->lineoffset < posting.lineoffset) {				*newsetp++ = *set1p++;				newsetc++;				set1c++;			}			else if (set1p->lineoffset > posting.lineoffset) {				(void) fread(&posting, (int) sizeof(posting), 1, file);				set2c++;			}			else if (set1p->type < posting.type) {				*newsetp++ = *set1p++;				newsetc++;				set1c++;			}			else if (set1p->type > posting.type) {				(void) fread(&posting, (int) sizeof(posting), 1, file);				set2c++;			}			else {	/* identical postings */				set1c++;				set1p++;				(void) fread(&posting, (int) sizeof(posting), 1, file);				set2c++;			}		}		newsetc += numitems - set1c;		while (set1c++ < numitems) {			*newsetp++ = *set1p++;		}		break; /* end of NOT */	case REVERSENOT:  /* core NOT incoming set */		for (set1c = 0, set2c = 0; set1c < numitems && set2c < *num; ) {			if (set1p->lineoffset < posting.lineoffset) {				set1p++;				set1c++;			}			else if (set1p->lineoffset > posting.lineoffset) {				*newsetp++ = posting;				(void) fread(&posting, (int) sizeof(posting), 1, file);				set2c++;			}			else if (set1p->type < posting.type) {				set1p++;				set1c++;			}			else if (set1p->type > posting.type) {				*newsetp++ = posting;				(void) fread(&posting, (int) sizeof(posting), 1, file);				set2c++;			}			else {	/* identical postings */				set1c++;				set1p++;				(void) fread(&posting, (int) sizeof(posting), 1, file);				set2c++;			}		}		while (set2c++ < *num) {			*newsetp++ = posting;			newsetc++;			(void) fread(&posting, (int) sizeof(posting), 1, file);		}		item = newitem;		break; /* end of REVERSENOT  */#endif	}	numitems = newsetc;	*num = newsetc;	enditem = (POSTING *) newsetp;	return((POSTING *) item);}#if 0POSTING *boolsave(int clear)		/* flag about whether to clear core  */{	int	i;	POSTING	*ptr;	POSTING	*oldstuff, *newstuff;	if (numitems == 0) {		if (clear) 			boolclear();		return(NULL);	}	/* if clear then give them what we have and use (void) boolready to realloc  */	if (clear) {		ptr = item;		/* free up the space we didn't give them */		if (item == item1)			item1 = NULL;		else			item2 = NULL;		(void) boolready();		return(ptr);	}	i = (enditem - item) * sizeof(POSTING) + 100;	if ((ptr = malloc(i))r == NULL) {		invcannotalloc(i);		return(ptr);	}	/* move present set into place  */	oldstuff = item;	newstuff = ptr;	while (oldstuff < enditem)		*newstuff++ = *oldstuff++;	return(ptr);}#endifstatic voidinvcannotalloc(unsigned n){	(void) fprintf(stderr, "%s: cannot allocate %u bytes\n", argv0, n);}static voidinvcannotopen(char *file){	(void) fprintf(stderr, "%s: cannot open file %s\n", argv0, file);}static voidinvcannotwrite(char *file){	perror(argv0);	/* must be first to preserve errno */	(void) fprintf(stderr, "%s: write to file %s failed\n", argv0, file);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -