1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
/************************************************************************/
/* */
/* Spell checking utility routines. */
/* */
/************************************************************************/
# include "config.h"
# include <stdlib.h>
# include <string.h>
# include <stdio.h>
# include <ctype.h>
# include <debugon.h>
# include "docBuf.h"
# include "docSpell.h"
# include <ind.h>
# include <charnames.h>
/************************************************************************/
/* */
/* Find the first misspelling from a certain position in a document. */
/* */
/************************************************************************/
static int docSpellParaFind( BufferItem * bi,
int stroff,
int part,
int * pStart,
int * pLength,
SpellCheckContext * scc )
{
PossibleWord * possibilities= (PossibleWord *)0;
TextParticule * tp= bi->biParaParticules+ part;
/* 3 */
while( part < bi->biParaParticuleCount )
{
int count;
const unsigned char * str= bi->biParaString+ stroff;
while( stroff < tp->tpStroff+ tp->tpStrlen )
{
int isWord= 0;
while( stroff < tp->tpStroff+ tp->tpStrlen &&
! ( scc->sccCharKinds[ *str ] & CHARisALNUM ) )
{
indAddCharacterToPossibilities( possibilities, *str );
stroff++; str++;
}
if ( stroff < tp->tpStroff+ tp->tpStrlen &&
( scc->sccCharKinds[*str] & CHARisALNUM ) )
{
indAddCharacterToPossibilities( possibilities, *str );
possibilities= indNewPossibility( stroff, possibilities, *str );
if ( ! possibilities )
{ XDEB(possibilities); return -1; }
isWord= 1;
}
else{ isWord= 0; }
stroff++; str++;
while( stroff < tp->tpStroff+ tp->tpStrlen &&
( scc->sccCharKinds[*str] & CHARisALNUM ) )
{
indAddCharacterToPossibilities( possibilities, *str );
stroff++; str++;
}
if ( isWord )
{
count= indCountPossibilities( possibilities, stroff,
scc, *str );
if ( count == 0 )
{
PossibleWord * maxpw;
maxpw= indMaximalPossibility( possibilities );
*pStart= maxpw->pwStartPosition;
*pLength= maxpw->pwInsertionPoint;
indFreePossibilities( possibilities );
return 0;
}
}
}
possibilities= indRejectPossibilities( possibilities );
part++; tp++;
if ( part < bi->biParaParticuleCount )
{ stroff= tp->tpStroff; }
}
indFreePossibilities( possibilities );
return 1;
}
int docSpellFindNext( BufferPosition * bpFrom,
BufferSelection * bs,
SpellCheckContext * scc )
{
BufferItem * bi= bpFrom->bpBi;
int stroff= bpFrom->bpStroff;
int part= bpFrom->bpParticule;
TextParticule * tp= bi->biParaParticules+ part;
const unsigned char * str= bi->biParaString+ stroff;
int ret;
int start;
int length;
if ( bi->biLevel != DOClevPARA )
{ LLDEB(bi->biLevel,DOClevPARA); return -1; }
if ( stroff > tp->tpStroff )
{
while( stroff < tp->tpStroff+ tp->tpStrlen &&
( scc->sccCharKinds[ *str ] & CHARisALNUM ) )
{ stroff++; str++; }
}
if ( stroff == tp->tpStroff+ tp->tpStrlen )
{ tp++; part++; }
for (;;)
{
ret= docSpellParaFind( bi, stroff, part, &start, &length, scc );
if ( ret == 0 )
{
docSetSelection( bs, bi, 1, start, length );
return ret;
}
bi= docNextParagraph( bi );
if ( ! bi )
{ return 1; }
stroff= 0; part= 0;
}
}
|