/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <ctype.h>
#include <stdio.h>
#include <sys/sysmacros.h>
#include <sys/byteorder.h>
#if SHARE
#endif
#include "invlib.h"
#include "library.h"
extern char *argv0; /* command name (must be set in main function) */
int invbreak;
#if STATS
#endif
static union {
} logicalblk;
static long totpost;
#endif
#if STATS
#endif
static void invcannotalloc(size_t n);
static void invcannotopen(char *file);
static void invcannotwrite(char *file);
static int invnewterm(void);
static int boolready(void);
long
{
unsigned char *s;
long num;
int i;
long fileindex;
unsigned long *intptr;
long tlong;
#if STATS
int j;
unsigned maxtermlen = 0;
#endif
/* output file */
return (0);
}
/* posting file */
return (0);
}
nextpost = 0;
/* get space for the postings list */
return (0);
}
/* get space for the superfinger (superindex) */
return (0);
}
/* also for the superfinger index */
invcannotalloc(supintsize * sizeof (long));
return (0);
}
supint++; /* leave first term open for a count */
/* initialize using an empty term */
*supint++ = 0;
*supfing++ = ' ';
*supfing++ = '\0';
nextsupfing = 2;
totpost = 0L;
#endif
totterm = 0L;
numpost = 1;
/*
* set up as though a block had come and gone, i.e., set up for
* new block
*/
numinvitems = 0;
numlogblk = 0;
/* now loop as long as more to read (till eof) */
++totpost;
#endif
if (s == NULL) /* where did this line come from ??? */
continue; /* workaround: just skip it */
*s = '\0';
#if STATS
maxtermlen = i;
}
#endif
#if DEBUG
#endif
return (0);
}
#if DEBUG
(void) printf("reallocated post space to %u, "
#endif
}
numpost++;
} else {
/* have a new term */
if (!invnewterm()) {
return (0);
}
numpost = 1;
fileindex = 0;
}
/* get the new posting */
num = *++s - '!';
i = 1;
do {
} while (++i < PRECISION);
;
}
num = *++s - '!';
if (*s != '\n') {
num = *++s - '!';
while (*++s != '\n') {
}
} else {
}
#if DEBUG
#endif
}
if (!invnewterm()) {
return (0);
}
/* now clean up final block */
/* loops pointer around to start */
goto cannotwrite;
}
numlogblk++;
/* write out block to save space. what in it doesn't matter */
goto cannotwrite;
}
/* finish up the super finger */
/* add to the offsets the size of the offset pointers */
*intptr++ += i;
/* write out the offsets (1 for the N at start) and the super finger */
outfile) == 0 ||
goto cannotwrite;
}
/* save the size for reference later */
nextsupfing = sizeof (long) + sizeof (long) * numlogblk +
/*
* make sure the file ends at a logical block boundary. This is
* necessary for invinsert to correctly create extended blocks
*/
i = nextsupfing % BLOCKSIZE;
/* write out junk to fill log blk */
/* rewind doesn't check for write failure */
goto cannotwrite;
}
/* write the control area */
goto cannotwrite;
}
for (i = 0; i < 10; i++) /* for future use */
1, outfile) == 0) {
goto cannotwrite;
}
/* make first block loop backwards to last block */
/* fseek doesn't check for write failure */
goto cannotwrite;
}
/* get to second word first block */
return (0);
}
return (0);
}
--totterm; /* don't count null term */
#if STATS
(void) printf("logical blocks = %d, postings = %ld, terms = %ld, "
if (showzipf) {
(void) printf(
"\n************* ZIPF curve ****************\n");
for (j = ZIPFSIZE; j > 1; j--)
if (zipf[j])
break;
for (i = 1; i < j; ++i) {
}
}
#endif
/* free all malloc'd memory */
return (totterm);
}
/* add a term to the data base */
static int
invnewterm(void)
{
union {
ENTRY e;
} iteminfo;
totterm++;
#if STATS
/* keep zipfian info on the distribution */
else
zipf[0]++;
#endif
/* new block if at least 1 item in block */
/* set up new block */
supersize += 20000;
return (0);
}
#if DEBUG
(void) printf("reallocated superfinger space to %d, "
#endif
}
/* check that room for the offset as well */
supintsize += SUPERINC;
supintsize * sizeof (long))) == NULL) {
invcannotalloc(supintsize * sizeof (long));
return (0);
}
#if DEBUG
(void) printf("reallocated superfinger offset to %d, "
"totpost = %ld\n", supintsize * sizeof (long),
totpost);
#endif
}
/* See if backup is efficatious */
backupflag = 0;
if (maxback > numinvitems)
howfar = 0;
while (--maxback > 0) {
howfar++;
(sizeof (long) - 1)];
maxback = i;
backupflag = howfar;
}
}
/* see if backup will occur */
if (backupflag) {
}
/* set forward pointer pointing to next */
/* set back pointer to last block */
return (0);
}
amtused = 16;
numlogblk++;
/* check if had to back up, if so do it */
if (backupflag) {
/* find out where the end of the new block is */
/* move the index for this block */
logicalblk.invblk[i] =
}
/* move the word into the super index */
#if DEBUG
(void) printf("backup %d at term=%s to term=%s\n",
#endif
*supint++ = nextsupfing;
/* now fix up the logical block */
lastinblk -= j;
}
} else { /* no backup needed */
numinvitems = 0;
/* add new term to superindex */
*supint++ = nextsupfing;
}
}
amtused += numwilluse;
return (0);
}
}
return (1);
}
static void
{
uint32_t *s;
for (s = p; s < e; s++)
*s = BSWAP_32(*s);
}
static void
{
}
static void
{
/*
* The superfinger consists of a count, followed by
* count offsets, followed by a string table (which
* the offsets reference).
*
* We need to swap the count and the offsets.
*/
}
}
static void
{
/* note always fetch it if the file is busy */
SEEK_SET);
/*
* A logblock consists of a count, a next block id,
* and a previous block id, followed by count
* ENTRYs, followed by alternating strings and
* offsets.
*/
/*
* After the string is the posting offset.
*/
}
}
}
}
void
{
/*
* fileindex is a 24-bit field, so shift it before swapping
*/
}
}
int
{
int read_index;
return (-1);
}
goto closeinv;
}
"%s: cannot read old index format; use -U option to "
"force database to rebuild\n", argv0);
goto closeinv;
}
goto closeinv;
}
goto closeinv;
}
/* allocate core for a logical block */
goto closeboth;
}
/* allocate for and read in superfinger */
read_index = 1;
#if SHARE
char *shmat();
int shm_id;
/* see if the shared segment exists */
/*
* Failure simply means (hopefully) that segment doesn't
* exist
*/
if (shm_id == -1) {
/*
* Have to give general write permission due to AMdahl
* not having protected segments
*/
IPC_CREAT | 0666);
if (shm_id == -1)
perror("Could not create shared "
"memory segment");
} else
read_index = 0;
if (shm_id != -1) {
((read_index) ? 0 : SHM_RDONLY));
"%s: shared memory link failed\n", argv0);
read_index = 1;
}
}
}
#endif
goto closeboth;
}
if (read_index) {
}
if (boolready() == -1) {
return (-1);
}
/* write back out the control block if anything changed */
return (1);
}
/* invclose must be called to wrap things up and deallocate core */
void
{
/* write out the control block in case anything changed */
}
#if SHARE
}
#endif
}
/* invstep steps the inverted file forward one item */
void
{
return;
}
/* move forward a block else wrap */
}
/* invforward moves forward one term in the inverted file */
int
{
/* skip things with 0 postings */
}
/* Check for having wrapped - reached start of inverted file! */
return (0);
return (1);
}
/* invterm gets the present term from the present logical block */
int
{
}
/* invfind searches for an individual item in the inverted file */
long
{
long num;
int i;
/* make sure it is initialized via invready */
return (-1L);
/* now search for the appropriate finger block */
ilow = 0;
if (i < 0)
else if (i > 0)
else {
break;
}
}
/* be careful about case where searchterm is after last in this block */
/* fetch the appropriate logical block if not in core */
/* now find the term in this block. tricky this */
ilow = 0;
intptr += 3;
num = 0;
if (i == 0)
if (i < 0)
else if (i > 0)
else {
break;
}
}
/* be careful about case where searchterm is after last in this block */
/* note if this happens the term could be in extended block */
goto srch_ext;
} else
return (num);
}
#if DEBUG
/* invdump dumps the block the term parameter is in */
void
{
long i, j, n, *longptr;
/* dump superindex if term is "-" */
if (*term == '-') {
n = *longptr++;
(void) printf("Superindex dump, num blocks=%ld\n", n);
longptr += j;
invbreak == 0) {
longptr++;
}
return;
} else if (*term == '#') {
/* fetch the appropriate logical block */
read_logblock(invcntl, j);
} else
n = *longptr++;
(void) printf("Entry term to invdump=%s, postings=%ld, "
*(longptr + 1));
(void) printf("%ld terms in this block, block=%ld\n", n,
(void) printf("\tterm\t\t\tposts\tsize\toffset\tspace\t1st word\n");
for (j = 0; j < n && invbreak == 0; j++) {
ptr += (sizeof (long) *
(sizeof (long) - 1)) / sizeof (long)));
entryptr++;
}
}
#endif
static int
boolready(void)
{
numitems = 0;
return (-1);
}
return (-1);
}
return (0);
}
void
boolclear(void)
{
numitems = 0;
}
POSTING *
{
char *ptr;
unsigned long *ptr2;
unsigned u;
switch (bool) {
case OR:
case NOT:
if (*num == 0) {
return (item);
}
}
/* make room for the new set */
u = 0;
switch (bool) {
case AND:
case NOT:
break;
case OR:
/* FALLTHROUGH */
case REVERSENOT:
u += *num;
if (u > setsize1) {
u += SETINC;
goto cannotalloc;
}
setsize1 = u;
}
} else {
if (u > setsize2) {
u += SETINC;
invcannotalloc(u * sizeof (POSTING));
(void) boolready();
*num = -1;
return (NULL);
}
setsize2 = u;
}
}
}
newsetc = 0;
switch (bool) {
case OR:
/* while something in both sets */
set1c++;
set2c++;
set1c++;
set2c++;
} else { /* identical postings */
set1c++;
set2c++;
}
}
/* find out what ran out and move the rest in */
}
} else {
newsetc++;
}
}
break; /* end of OR */
#if 0
case AND:
set1c = 0;
set2c = 0;
set1p++;
set1c++;
set2c++;
*set1p++;
set1c++;
set2c++;
} else { /* identical postings */
newsetc++;
set1c++;
set2c++;
}
}
break; /* end of AND */
case NOT:
set1c = 0;
set2c = 0;
newsetc++;
set1c++;
set2c++;
newsetc++;
set1c++;
set2c++;
} else { /* identical postings */
set1c++;
set1p++;
set2c++;
}
}
}
break; /* end of NOT */
case REVERSENOT: /* core NOT incoming set */
set1c = 0;
set2c = 0;
set1p++;
set1c++;
set2c++;
set1p++;
set1c++;
set2c++;
} else { /* identical postings */
set1c++;
set1p++;
set2c++;
}
}
newsetc++;
}
break; /* end of REVERSENOT */
#endif
}
}
#if 0
POSTING *
{
int i;
if (numitems == 0) {
if (clear)
boolclear();
return (NULL);
}
/*
* if clear then give them what we have and use (void)
* boolready to realloc
*/
if (clear) {
/* free up the space we didn't give them */
else
(void) boolready();
return (ptr);
}
invcannotalloc(i);
return (ptr);
}
/* move present set into place */
return (ptr);
}
#endif
static void
{
}
static void
{
}
static void
{
}