mirror of
https://github.com/antoinevignau/source.git
synced 2025-01-22 14:30:24 +00:00
1 line
6.9 KiB
C++
1 line
6.9 KiB
C++
|
/***********************************************************************\
Filename: thesutil.c
\***********************************************************************/
extern pascal int Tlexcmp();
extern pascal void Tlexphon();
/*#include <ctype.h>*/
#include "proxio.h"
#include "tlex.h"
#include "spmemory.h"
#include "scdef.h"
#include "tenviron.h"
#include "thesmisc.h"
static remphon();
char *memread();
/* keep a global lexicon pointer for unftry */
static int Curbyte;
static int Bitsleft = 0;
static int Blknum = 0;
static char *Memblk;
static char *Bufend;
static char *Bufp;
/* return the thesaurus hash value of a word */
long theswtoh(word)
char *word;
{
char *lexword = Tscdecomp;
int wcount;
int blknum;
long hash;
char peword[MAXPHWORD];
char shit[5];
/* phonetically encode word */
if (phfull(word, peword, Tlexprod & SHORTLEX) == ERROR)
return (ERROR);
/* compute block to search */
Tlexblknum(peword);
blknum = Tsccurblk;
/* if seed word matches the query word, simply return the hash */
/* of the block */
hash = (long) blknum << WORDFLD;
if (Tlexcmp(peword, Tlexindextab[blknum]) == 0)
return (hash);
/* read block into memory */
if ((Tlexblk = memread(blknum + Tlexoffset, Tlexfile, MM_READ | MM_PR3)) ==
NULL)
return (ERROR);
/* prepare for sequential decompression of block */
wcount = 0;
Tlexblkptr = Tlexblk + BLOCKSEGS;
Tscendptr = strecpy(lexword, Tlexindextab[blknum]);
/* decompress until end of block or word found */
while (*Tlexblkptr)
{
Tlexbinnext();
++wcount;
if (!Tlexcmp(peword, Tscdecomp))
return ((long) wcount + hash);
}
return (ERROR);
}
/* given a hash value, return the corresponding word from the lexicon */
theshash(hash, phword)
long hash;
char *phword;
{
int blknum;
int nwords;
int nseg;
int i;
int c;
int offset;
char *blkptr;
*phword = '\0';
blknum = (int) (hash >> WORDFLD);
/* if the block number is greater than the number of */
/* blocks in the lexicon, the hash value is illegal */
if (blknum >= Tlexnindex)
return (ERROR);
Tsccurblk = blknum;
/* find out the number of words that need decompression */
nwords = (int) (hash & WORDBITS);
if (nwords == 0)
{
strecpy(phword, Tlexindextab[blknum]);
return (TRUE);
}
/* read the block indicated by offset */
if ((Tlexblk = memread(blknum + Tlexoffset, Tlexfile, MM_READ | MM_PR3)) ==
NULL)
return (ERROR);
/* find the segment where word is likely to be found */
nseg = nwords / Tlexsegwords;
if (nseg > BLOCKSEGS)
nseg = BLOCKSEGS;
blkptr = Tlexblk;
if (nseg != 0)
{
offset = 0;
for (i = 0; i < nseg && (c = ctoi(*blkptr++)) != 0; i++)
{
offset += c;
offset += Tlexsegwords;
nwords -= Tlexsegwords;
}
Tlexblkptr = Tlexblk + offset;
Tscendptr = Tscdecomp;
}
else
{
Tscendptr = strecpy(Tscdecomp,Tlexindextab[blknum]);
Tlexblkptr = Tlexblk + BLOCKSEGS;
}
Tlexphon();
/* use sequential lexget mode to get word after nwords */
while (--nwords >= 0)
if (!Tlexbinnext())
return (ERROR);
strecpy(phword, Tscdecomp);
return (TRUE);
}
/* convert a phonetically encoded word into an ascii word */
lextoasc(inword, outword, flags)
char *inword;
char *outword;
int flags;
{
char ascii[LONGWORD];
/* special check for null word, since skipping phonetic bin */
/* characters would automatically skip over an initial null */
if (*inword == '\0')
{
*outword = '\0';
return;
}
strecpy(ascii, inword);
remphon(ascii);
strecpy(outword, ascii);
undoflags(ascii, flags, outword);
}
/* get next nbits from the input stream */
#define NBITS 8
long
thesbit(ioptr, nbits)
HANDLE ioptr;
int nbits;
{
|