File: docSpell.c

package info (click to toggle)
ted 2.11-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 11,064 kB
  • ctags: 13,935
  • sloc: ansic: 120,446; makefile: 7,469; sh: 253
file content (106 lines) | stat: -rw-r--r-- 2,622 bytes parent folder | download
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
/************************************************************************/
/*									*/
/*  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.	*/
/*									*/
/************************************************************************/

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;

    indInitSpellScanJob( &ssj );

    if  ( stroff > 0						&&
	  ( scc->sccCharKinds[ str[ 0] ] & CHARisALNUM )	&&
	  ( scc->sccCharKinds[ str[-1] ] & CHARisALNUM )	)
	{
	while( stroff < paraBi->biParaStrlen			&&
	       ( scc->sccCharKinds[ *str ] & CHARisALNUM )	)
	    { stroff++; str++; }
	}

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

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

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

	indAddCharacterToPossibilities( &ssj, *str );

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

	stroff++; str++;
	while( stroff < paraBi->biParaStrlen		&&
	       ( 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->pwStartPosition,
						maxpw->pwInsertionPoint );
	    indCleanSpellScanJob( &ssj );

	    return 0;
	    }

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

    indCleanSpellScanJob( &ssj );

    return 1;
    }