mirror of
https://github.com/antoinevignau/source.git
synced 2025-03-08 22:30:52 +00:00
1 line
4.8 KiB
C
Executable File
1 line
4.8 KiB
C
Executable File
/***********************************************************************\
|
|
|
|
Filename: isword.c
|
|
|
|
\***********************************************************************/
|
|
|
|
#include <language.h>
|
|
#include "corelex.h"
|
|
#include "cache.h"
|
|
#include "clam.h"
|
|
#include "lex.h"
|
|
#include "spath.h"
|
|
#include "environ.h"
|
|
#include "query.h"
|
|
#include "string.h"
|
|
|
|
/* 'Isword' is the basic function for looking up words in the word lists.
|
|
|
|
Its input is the word that is to be spell checked. An isword `word'
|
|
should be isolated from its surrounding text.
|
|
|
|
Isword looks up the word in the various word lists and reports the result
|
|
of the lookup. If the word is not in the word lists then isword will
|
|
attempt to find the word by using the word construction rules for the
|
|
language.
|
|
|
|
Isword returns the status of the look up. More information about the
|
|
lookup is available in the Query structure. */
|
|
|
|
#define IW_ALL (IW_CLAM | IW_LEX | IW_CORELEX)
|
|
|
|
/* Isword is actually an interface to the general word list lookup
|
|
function. */
|
|
|
|
isword(word)
|
|
char *word;
|
|
{
|
|
Sciswctl = SP_DETECT;
|
|
return(sclookup(word));
|
|
}
|
|
|
|
/* Look up a word using the searchpath; this is called from isword() and
|
|
hyword(). */
|
|
|
|
sclookup(word)
|
|
char *word;
|
|
{
|
|
int retval;
|
|
|
|
/* Word hasn't been found anywhere yet. */
|
|
|
|
Quwlist = -1;
|
|
Quwflags = IW_NOTFOUND;
|
|
|
|
/* Initialize the query information. */
|
|
|
|
if (!setquery(word))
|
|
{
|
|
Scerror |= ERR_ISWORD;
|
|
return (IW_NOTFOUND);
|
|
}
|
|
|
|
/* The first stage of the look up is to see if the whole word is a
|
|
word element. A word element is either something that is explicitly
|
|
in a word list or is constructed according to the standard compounding
|
|
rules for the language. (n/a for English) */
|
|
|
|
retval = iswelement(IW_ALL >> 8);
|
|
|
|
Quinfo[0] = QU_WORD;
|
|
if (retval == IW_NOTFOUND)
|
|
Quinfo[0] |= QU_ERROR;
|
|
return (retval);
|
|
}
|
|
|
|
|
|
/* ¥¥¥ÊDEADCODE
|
|
|
|
/* This routine is called by various routines to check out an element of
|
|
Quword. It assumes that the element has been isolated by placing a
|
|
null at its end. Quinfo is set appropriately for the element. The
|
|
return value is TRUE if the element is not found. *
|
|
|
|
iswcheck(word)
|
|
char *word; /* Points into Quword *
|
|
{
|
|
char *ptr;
|
|
|
|
ptr = &Quinfo[word - Quword];
|
|
*ptr = QU_WORD;
|
|
if (!setcquery(word) || iswelement(IW_ALL >> 8) == IW_NOTFOUND)
|
|
{
|
|
*ptr |= QU_ERROR;
|
|
return (TRUE);
|
|
}
|
|
return (FALSE);
|
|
}
|
|
|
|
¥¥¥ */
|
|
|
|
/* This array is used to compute indexes into en_acctab. */
|
|
|
|
STATIC char Flagtab[] = {
|
|
IW_COMMON,
|
|
IW_PROPER,
|
|
IW_ACRONYM,
|
|
IW_COMMON | IW_ENDDOT,
|
|
IW_PROPER | IW_ENDDOT,
|
|
IW_ACRONYM | IW_ENDDOT,
|
|
IW_COMMON | IW_ALLDOT,
|
|
IW_PROPER | IW_ALLDOT,
|
|
IW_ACRONYM | IW_ALLDOT,
|
|
IW_SPECIAL,
|
|
IW_SPECIAL | IW_ENDDOT,
|
|
0
|
|
};
|
|
|
|
/* Look up an element of a word. The lists argument determines the type
|
|
of word lists to look in. */
|
|
|
|
iswelement(lists)
|
|
int lists; /* the lists to check */
|
|
{
|
|
SPENTRY *ep; /* Current searchpath entry */
|
|
int i;
|
|
char *ptr;
|
|
|
|
/* Now, go look up the word in each word list; record the places
|
|
where the canonical form was found. */
|
|
|
|
ep = Srchpath;
|
|
while (ep < Srchend)
|
|
{
|
|
/* Call the appropriate search routine. */
|
|
|
|
Sccurlist = ep->sp_access;
|
|
Scfdecomp[0] = Scfdecomp[1] = 0;
|
|
if (lists & ep->sp_type)
|
|
switch (ep->sp_type)
|
|
{
|
|
case IW_CORELEX >> 8:
|
|
Scfdecomp[0] = clxword(Sclookup);
|
|
break;
|
|
|
|
case IW_LEX >> 8:
|
|
if (!lexword(Sclookup))
|
|
Scfdecomp[0] = 0;
|
|
break;
|
|
|
|
case IW_CLAM >> 8:
|
|
Scfdecomp[0] = clamword(Sclookup, (CLAM *) ep->sp_access);
|
|
break;
|
|
}
|
|
|
|
/* If the word was not found then go on to the next word
|
|
list. */
|
|
|
|
if (!Scfdecomp[0])
|
|
{
|
|
++ep;
|
|
continue;
|
|
}
|
|
|
|
/* The word was found in a wordlist, check that the flag
|
|
the query are compatible with those of the wordlist. If
|
|
so then return the flags.
|
|
If the wordlist is a stop-list then return word not
|
|
found. */
|
|
|
|
Quwlist = ctoi(ep->sp_idcode);
|
|
ptr = Scfdecomp;
|
|
while (*ptr)
|
|
{
|
|
Quwflags = i = ctoi(*ptr++);
|
|
|
|
/* See if the word list flags and the query flags
|
|
are compatible. */
|
|
|
|
if (Iswacctab[strchr(Flagtab, Scflags) - Flagtab]
|
|
& (1 << (strchr(Flagtab, i) - Flagtab)))
|
|
return (i | (ep->sp_type << 8));
|
|
if (ep->sp_flags & SP_STOP)
|
|
return (IW_NOTFOUND);
|
|
}
|
|
++ep;
|
|
}
|
|
return (IW_NOTFOUND);
|
|
}
|