2012-11-11 19:38 UTC+0100 Viktor Szakats (harbour syenar.net)

* extras/gfspell/spell.prg
  * extras/gfspell/spellc.c
    * unicode, 64-bit and various other minor cleanups,
      though this thing just doesn't work at all.
      XUNFORM() seems to be buggy, maybe it pulls the
      whole thing down. I'm giving up. I will delete this
      library if it stays unusable.
This commit is contained in:
Viktor Szakats
2012-11-11 18:40:08 +00:00
parent 92be5b0370
commit 78a86226c1
3 changed files with 61 additions and 56 deletions

View File

@@ -16,6 +16,15 @@
The license applies to all entries newer than 2009-04-28.
*/
2012-11-11 19:38 UTC+0100 Viktor Szakats (harbour syenar.net)
* extras/gfspell/spell.prg
* extras/gfspell/spellc.c
* unicode, 64-bit and various other minor cleanups,
though this thing just doesn't work at all.
XUNFORM() seems to be buggy, maybe it pulls the
whole thing down. I'm giving up. I will delete this
library if it stays unusable.
2012-11-11 18:41 UTC+0100 Viktor Szakats (harbour syenar.net)
* extras/gfspell/spell.prg
% deleted commented full screen debug trace lines

View File

@@ -26,13 +26,10 @@
#include "fileio.ch"
#xtranslate StoreWord( <cWord> ) => xForm( <cWord> )
#xtranslate ExtractWord( <cWord> ) => xUnForm( <cWord> )
#define EACH_WORD 6
#define NSIZE ( 26 * 26 * EACH_WORD )
#define CRLF Chr( 13 ) + Chr( 10 )
#define FOUR_BYTES Chr( 0 ) + Chr( 0 ) + Chr( 0 ) + Chr( 0 )
#define FOUR_BYTES hb_BChar( 0 ) + hb_BChar( 0 ) + hb_BChar( 0 ) + hb_BChar( 0 )
#define MAX_STRING 40000
#define COMMON_WORDS t_aGlobal[ 1 ]
@@ -107,7 +104,8 @@ FUNCTION Sp_Add( cWord )
// an auxiliary dictionary name was specified
IF Sp_Init() .AND. ! Empty( AUXILIARY_DICTIONARY )
cWord := Upper( AllTrim( cWord ) )
cWord := Upper( AllTrim( cWord ) )
//
// If the auxiliary dictionary does not exist,
@@ -121,14 +119,12 @@ FUNCTION Sp_Add( cWord )
ENDIF
IF nAuxHandle >= 0
FSeek( nAuxHandle, 0, FS_END ) // Bottom of the file
nWritten := FWrite( nAuxHandle, ; // Write word into file
cWord + CRLF )
FSeek( nAuxHandle, 0, FS_END ) // Bottom of the file
nWritten := FWrite( nAuxHandle, cWord + CRLF ) // Write word into file
FClose( nAuxHandle ) // Close the file
Sp_Cache( cWord ) // Add word to cache
FClose( nAuxHandle ) // Close the file
Sp_Cache( cWord ) // Add word to cache
was_added := ( nWritten == Len( cWord ) + 2 )
was_added := ( nWritten == hb_BLen( cWord ) + hb_BLen( CRLF ) )
ENDIF
ENDIF
@@ -136,7 +132,7 @@ FUNCTION Sp_Add( cWord )
// Function: Sp_cache()
// Purpose: To add a word to the cache list
// Syntax: <logical> := Sp_cache(cWord)
// Syntax: <logical> := Sp_Cache( cWord )
// Arguments: cWord - upper case, all trimmed word to add
// Returns: <logical> - TRUE if added,
// FALSE otherwise
@@ -198,8 +194,8 @@ FUNCTION Sp_Check( cWord )
cLookUp := SubStr( cLookup, 1, Len( cLookup ) -2 )
ENDIF
cTemp := "|" + cLookup + "|"
IF fat( cTemp, COMMON_WORDS ) == 0 // Check the common words first
IF fat( cTemp, CACHE_WORDS ) == 0 // then check the cache words
IF At( cTemp, COMMON_WORDS ) == 0 // Check the common words first
IF At( cTemp, CACHE_WORDS ) == 0 // then check the cache words
ok := .F.
nRow := Asc( SubStr( cLookup, 1, 1 ) ) - 64
nCol := Asc( SubStr( cLookup, 2, 1 ) ) - 64
@@ -223,12 +219,12 @@ FUNCTION Sp_Check( cWord )
ELSEIF Len( cLookup ) < 3
ok := bit( @t_cBuf, 27 )
ELSEIF y > 4
cTemp := StoreWord( cLookup )
cTemp := xForm( cLookup )
DO WHILE z < y
z := fat( cTemp, t_cBuf, z )
z := bfat( cTemp, t_cBuf, z )
IF z < 6
EXIT
ELSEIF hb_BSubStr( t_cBuf, z - 1, 1 ) < Chr( 128 )
ELSEIF hb_BSubStr( t_cBuf, z - 1, 1 ) < hb_BChar( 128 )
z++
ELSE
EXIT
@@ -280,9 +276,9 @@ STATIC FUNCTION sp_GetBuf( cLetters )
RETURN cBuf
// Function: Sp_clear()
// Function: Sp_Clear()
// Purpose: To clear out the cache list
// Syntax: Sp_clear()
// Syntax: Sp_Clear()
// Returns: NIL
//
// Static: CACHE_WORDS - String of cache words
@@ -295,7 +291,7 @@ FUNCTION Sp_Clear()
// Function: Sp_GetSet()
// Purpose: To get/set a parameter for the spell check function
// Syntax: <xOldValue> := Sp_GetSet( nWhich [,xNewSetting] )
// Syntax: <xOldValue> := Sp_GetSet( nWhich [, xNewSetting] )
// Parameters: nWhich - Which parameter to get/set
// xNewSetting - Value to set parameter to
//
@@ -352,7 +348,7 @@ FUNCTION Sp_LoadAux( cFile )
// Function: Sp_Suggest()
// Purpose: To return an array of possible spellings
// Syntax: aSuggest_ := Sp_Suggest(cWord [,lInclude] )
// Syntax: aSuggest_ := Sp_Suggest( cWord [, lInclude] )
// Arguments: cWord - Word to look for suggestions for
// lInclude - Should word be included in list?
// Returns: aSuggest_ - List of suggested words
@@ -432,7 +428,9 @@ FUNCTION Sp_Suggest( cWord, lInclude )
RETURN aRet_ // single letter words
ENDIF
IF lInclude == NIL ; lInclude := .F. ; ENDIF
IF lInclude == NIL
lInclude := .F.
ENDIF
//
// Should the current word be included?
@@ -707,7 +705,7 @@ FUNCTION Sp_Suggest( cWord, lInclude )
ELSEIF cKey < cMeta
EXIT
ENDIF
jj := kk
jj := kk
ENDIF
kk--
ENDDO
@@ -903,17 +901,17 @@ FUNCTION Sp_Expand( cWord )
FUNCTION Sp_WildCard( cPattern )
LOCAL cTemp
LOCAL ii, kk, jj, cFirst, cHold, x, z
LOCAL arr_ := {}
LOCAL nStart, nEnd
LOCAL cTemp
LOCAL ii, kk, jj, cFirst, cHold, x, z
LOCAL arr_ := {}
LOCAL nStart, nEnd
cPattern := Upper( cPattern )
IF Sp_Init()
x := fat( "*", cPattern )
x := At( "*", cPattern )
IF x == 0
x := fat( "?", cPattern )
x := At( "?", cPattern )
ENDIF
IF x == 1 // Can't handle wildcards in first position
RETURN arr_
@@ -1105,7 +1103,7 @@ FUNCTION DBF2Dic( cDbf, cDictionary, lTalk )
// Write out enough bytes to hold the index information
//
FWrite( nH, "JJ" + L2Bin( NSIZE + 4 ) + Replicate( Chr( 0 ), NSIZE ) + Space( 10 ) )
FWrite( nH, "JJ" + L2Bin( NSIZE + 4 ) + Replicate( hb_BChar( 0 ), NSIZE ) + Space( 10 ) )
FOR i := 1 TO 26
DO WHILE Left( DICT->word, 1 ) == Chr( i + 64 ) .AND. ! Eof()
@@ -1124,7 +1122,7 @@ FUNCTION DBF2Dic( cDbf, cDictionary, lTalk )
ELSEIF Len( RTrim( DICT->word ) ) == 2
bit( @cBits, 27, .T. )
ELSE
temp += StoreWord( RTrim( DICT->word ) )
temp += xForm( RTrim( DICT->word ) )
ENDIF
dbSkip()
IF lTalk
@@ -1169,7 +1167,7 @@ FUNCTION DBF2Dic( cDbf, cDictionary, lTalk )
// Function: Dic2DBF()
// Purpose: To create a DBF file from a DIC file
// Syntax: nStatus := DIC2DBF( <cDIC_file>, <cDBF_file> )
// Syntax: nStatus := Dic2DBF( <cDIC_file>, <cDBF_file> )
// Arguments: <cDIC_File> - Name of DIC file to read, assumes
// dict.dic
// <cDBF_File> - Name of DBF to create, assumes dict.dbf
@@ -1279,10 +1277,10 @@ FUNCTION Dic2DBF( cDictionary, cDBF, lTalk )
cBuf := SubStr( cBuf, 5 )
z := 1
DO WHILE ! Empty( cBuf )
IF SubStr( cBuf, z, 1 ) >= Chr( 128 )
IF SubStr( cBuf, z, 1 ) >= hb_BChar( 128 )
cWord := SubStr( cBuf, 1, z )
dbAppend()
DICT->word := temp + ExtractWord( cWord )
DICT->word := temp + xUnForm( cWord )
cWord := ""
cBuf := SubStr( cBuf, z + 1 )
z := 1
@@ -1290,7 +1288,6 @@ FUNCTION Dic2DBF( cDictionary, cDBF, lTalk )
IF lTalk
hb_DispOutAt( 11, 41, Transform( LastRec(), "99,999" ), "W+/R" )
ENDIF
ELSE
z++
ENDIF
@@ -1452,7 +1449,7 @@ FUNCTION aWords( cLine )
cWord := Chr( y )
z++
y := Asc( SubStr( cLine, z, 1 ) )
WHILE ( y >= 48 .AND. ! Chr( y ) $ ":;<=>?@[\^]_`{|}~" ) .OR. y == 39
WHILE ( y >= 48 .AND. ! Chr( y ) $ ":;<=>?@[\^]_`{|}~" ) .OR. y == "'"
cWord += Chr( y )
z++
IF z > nSize
@@ -1469,12 +1466,16 @@ FUNCTION aWords( cLine )
// Find an occurrence of 'f_str' in 'l_str' starting from position 'f_rom'
FUNCTION fat( f_str, l_str, f_rom )
LOCAL ret_val
IF PCount() < 3 // Is f_rom passed?
f_rom := 1
ENDIF
RETURN At( f_str, SubStr( l_str, f_rom ) )
STATIC FUNCTION bfat( f_str, l_str, f_rom )
IF PCount() < 3 // Is f_rom passed?
f_rom := 1
ENDIF
ret_val := At( f_str, SubStr( l_str, f_rom ) )
RETURN ret_val
RETURN hb_BAt( f_str, hb_BSubStr( l_str, f_rom ) )

View File

@@ -14,7 +14,7 @@ static const char * s_cRepl = "[\\]^_`a";
/*
* Function: xForm()
* Purpose: Internal function to translate words to dictionary
* Arguments: cWord - upper case word to format
* Arguments: cWord - upper case word to format
* Returns: cXformed - translated word
*
* Notes: I'm assuming that the passed word won't exceed 128 bytes.
@@ -33,6 +33,7 @@ HB_FUNC( XFORM )
{
iKey = *( ( HB_UINT * ) cWord );
for( x = 0; x < 14; x += 2 )
{
if( *( ( HB_UINT * ) ( s_cSearch + x ) ) == iKey )
{
if( x == 0 )
@@ -53,9 +54,11 @@ HB_FUNC( XFORM )
*cPtr++ = *( s_cRepl + ( x >> 1 ) );
break;
}
}
if( x >= 14 )
*cPtr++ = *cWord++;
iRetLen++;
}
@@ -72,11 +75,10 @@ HB_FUNC( XFORM )
hb_retclen( cRet, iRetLen );
}
/*
* Function: xUnForm()
* Purpose: Internal function to translate words from dictionary
* Arguments: cWord - formatted word
* Arguments: cWord - formatted word
* Returns: cXformed - unformatted word
*
* Notes: I'm assuming that the returned word won't exceed 128 bytes.
@@ -101,7 +103,7 @@ HB_FUNC( XUNFORM )
else
c -= 128;
if( ( x = ( int ) memchr( s_cRepl, c, 7 ) ) <= 6 )
if( ( x = ( HB_ISIZ ) memchr( s_cRepl, c, 7 ) ) <= 6 )
{
if( x == 0 )
{
@@ -128,7 +130,6 @@ HB_FUNC( XUNFORM )
hb_retclen( cRet, iRetLen );
}
/***************************
* Function: Sp_Rate()
* Syntax: cRating := Sp_Rate( cFound, cWord )
@@ -184,8 +185,6 @@ HB_FUNC( SP_RATE )
hb_retclen_buffer( cRating, 3 );
}
/** Start of C_MetaFone() **/
/*
* Author: Clayton Neff
* Copyright (c) 1992 by CoN Computer Consultants
@@ -769,8 +768,6 @@ HB_FUNC( C_METAFONE )
hb_xfree( sReturn );
}
/** Start of bit() **/
/*
* Purpose: Sets the given bit in a passed bit string. Returns the previous
* value. Be sure to pass the string by reference. NOTE. In order
@@ -805,10 +802,9 @@ HB_FUNC( BIT )
*ptr = ( HB_UCHAR ) *ptr & ~mask;
}
}
hb_retl( res );
}
/** Start of Sp_Line() **/
hb_retl( res != 0 );
}
static HB_BOOL WordSep( HB_UCHAR c )
{
@@ -882,7 +878,7 @@ HB_FUNC( SP_LINE )
nOffset += nCount + 1;
if( ! bLineBreak )
{
while( cIn[ nOffset ] == 32 ) /* Remove leading spaces */
while( cIn[ nOffset ] == ' ' ) /* Remove leading spaces */
nOffset++;
}
nOffset++; /* +1 for Harbour string */
@@ -896,6 +892,5 @@ HB_FUNC( SP_LINE )
else
hb_retc_null();
if( HB_ISBYREF( 2 ) ) /* Change reference val */
hb_stornl( nOffset, 2 );
hb_storns( nOffset, 2 );
}