File: docSpell.c

package info (click to toggle)
ted 2.16-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,944 kB
  • ctags: 20,273
  • sloc: ansic: 167,980; makefile: 12,518; sh: 263
file content (159 lines) | stat: -rw-r--r-- 4,112 bytes parent folder | download | duplicates (2)
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
152
153
154
155
156
157
158
159
/************************************************************************/
/*									*/
/*  Spell checking utility routines.					*/
/*									*/
/************************************************************************/

#   include	"tedConfig.h"

#   include	<stdlib.h>
#   include	<string.h>
#   include	<stdio.h>
#   include	<ctype.h>

#   include	<appDebugon.h>

#   include	"docBuf.h"
#   include	"docFind.h"

#   include	<ind.h>
#   include	<charnames.h>

/************************************************************************/
/*									*/
/*  Find the first misspelling from a certain position in a paragraph.	*/
/*									*/
/*  1)	Skip initial particules: Find the first particule that starts	*/
/*	after the starting point for spell checking.			*/
/*  2)	Skip particules that can be included in a spell check range.	*/
/*  3)	If spell checking starts in the middle of a word, skip to the	*/
/*	end of the word.						*/
/*  4)	Do not extend the string beyond the beginning/end of a field.	*/
/*									*/
/*  TODO: Do not check the contents of fields that are not editable.	*/
/*									*/
/************************************************************************/

int docSpellParaFindNext(	DocumentSelection *		ds,
				BufferItem *			paraBi,
				const BufferDocument *		bd,
				const DocumentPosition *	dpFrom,
				void *				through )
    {
    SpellCheckContext *		scc= (SpellCheckContext *)through;
    SpellScanJob		ssj;
    int				stroff= dpFrom->dpStroff;
    int				acceptedPos= stroff;
    const unsigned char *	str= paraBi->biParaString+ stroff;

    const int			lastOne= 1;
    int				part;
    const TextParticule *	tp;

    int				stroffUpto;

    indInitSpellScanJob( &ssj );

    if  ( docFindParticule( &part, paraBi, stroff, lastOne ) )
	{ LDEB(stroff); return -1;	}

    tp= paraBi->biParaParticules+ part;

    /*  1  */
    while( part < paraBi->biParaParticuleCount	&&
	   tp->tpStroff <= stroff		)
	{ part++; tp++;	}

    /*  2  */
    while( part < paraBi->biParaParticuleCount	&&
	   ! DOCkindBETWEEN_TEXT( tp->tpKind )	)
	{ part++; tp++;	}

    /*  3  */
    if  ( stroff > 0						&&
	  ( scc->sccCharKinds[ str[ 0] ] & CHARisALNUM )	&&
	  ( scc->sccCharKinds[ str[-1] ] & CHARisALNUM )	)
	{
	/*  4  */
	if  ( part < paraBi->biParaParticuleCount )
	    { stroffUpto= tp->tpStroff;		}
	else{ stroffUpto= paraBi->biParaStrlen; }

	while( stroff < stroffUpto				&&
	       ( scc->sccCharKinds[ *str ] & CHARisALNUM )	)
	    { stroff++; str++; }
	}

    while( stroff < paraBi->biParaStrlen )
	{
	int		count;

	/*  1  */
	while( part < paraBi->biParaParticuleCount	&&
	       tp->tpStroff <= stroff		)
	    { part++; tp++;	}

	/*  2  */
	while( part < paraBi->biParaParticuleCount	&&
	       ! DOCkindBETWEEN_TEXT( tp->tpKind )	)
	    { part++; tp++;	}

	/*  4  */
	if  ( part < paraBi->biParaParticuleCount )
	    { stroffUpto= tp->tpStroff;		}
	else{ stroffUpto= paraBi->biParaStrlen; }

	while( stroff < stroffUpto				&&
	       ! ( scc->sccCharKinds[ *str ] & CHARisALNUM )	)
	    {
	    indAddCharacterToPossibilities( &ssj, *str );
	    stroff++; str++;
	    }

	if  ( stroff >= paraBi->biParaStrlen )
	    { break;	}
	if  ( stroff >= stroffUpto )
	    { continue;	}

	indAddCharacterToPossibilities( &ssj, *str );

	if  ( indNewPossibility( &ssj, stroff, *str ) )
	    { CDEB(*str); return -1;	}

	stroff++; str++;
	while( stroff < stroffUpto				&&
	       ( scc->sccCharKinds[*str] & CHARisALNUM )	)
	    {
	    indAddCharacterToPossibilities( &ssj, *str );
	    stroff++; str++;
	    }

	count= indCountPossibilities( &ssj, scc, stroff- 1, stroff,
				    stroff >= paraBi->biParaStrlen, *str );

	if  ( count == 0 )
	    {
	    PossibleWord *	maxpw;
	    const int		direction= 1;

	    maxpw= indMaximalPossibility( &ssj );

	    if  ( ! maxpw )
		{ XDEB(maxpw); return -1;	}

	    docSetParaSelection( ds, paraBi, direction,
						maxpw->pwStartAt,
						maxpw->pwInsertionPoint );
	    indCleanSpellScanJob( &ssj );

	    return 0;
	    }

	indRejectPossibilities( &acceptedPos, acceptedPos, &ssj );
	}

    indCleanSpellScanJob( &ssj );

    return 1;
    }