2011-11-01 05:05:34 +01:00
|
|
|
/* -*- compile-command: "cd ../linux && make MEMDEBUG=TRUE -j3"; -*- */
|
2011-11-01 02:30:55 +01:00
|
|
|
/*
|
2020-08-17 04:29:08 +02:00
|
|
|
* Copyright 1997 - 2020 by Eric House (xwords@eehouse.org). All rights
|
2011-11-01 02:30:55 +01:00
|
|
|
* reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DICTITER_H__
|
|
|
|
#define __DICTITER_H__
|
|
|
|
|
|
|
|
#ifdef XWFEATURE_WALKDICT
|
|
|
|
|
|
|
|
#include "comtypes.h"
|
|
|
|
|
|
|
|
#include "dawg.h"
|
|
|
|
#include "model.h"
|
|
|
|
#include "mempool.h"
|
|
|
|
|
|
|
|
#ifdef CPLUS
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2011-11-18 16:56:02 +01:00
|
|
|
#define MAX_COLS_DICT 15
|
2011-11-01 02:30:55 +01:00
|
|
|
|
|
|
|
/* API for iterating over a dict */
|
2011-11-01 05:05:34 +01:00
|
|
|
typedef XP_S32 DictPosition;
|
2011-11-01 02:30:55 +01:00
|
|
|
|
|
|
|
typedef struct _IndexData {
|
2011-11-01 05:05:34 +01:00
|
|
|
DictPosition* indices;
|
2011-11-01 02:30:55 +01:00
|
|
|
Tile* prefixes;
|
|
|
|
XP_U16 count; /* in-out: must indicate others are large enough */
|
|
|
|
} IndexData;
|
|
|
|
|
2011-11-18 17:15:21 +01:00
|
|
|
typedef struct _LengthsArray {
|
2011-11-19 06:14:24 +01:00
|
|
|
XP_U32 lens[MAX_COLS_DICT+1];
|
2011-11-18 17:15:21 +01:00
|
|
|
} LengthsArray;
|
|
|
|
|
add filtering to wordlist browser
Add a basic regular expression engine to the dictiter, and to the UI add
the ability to filter for "starts with", "contains" and "ends with",
which translate into ANDed RE_*, _*RE_* and _*RE, respectively (with
_ standing for blank/wildcard). The engine's tightly integrated with the
next/prevWord() functions for greatest possible speed, but unless
there's no pattern does slow things down a bit (especially when "ENDS
WITH" is used.) The full engine is not exposed (users can't provide raw
REs), and while the parser will accept nesting (e.g. ([AB]_*[CD]){2,5}
to mean words from 2-5 tiles long starting with A or B and ending with C
or D) the engine can't handle it. Which is why filtering for word length
is handled separately from REs (but also tightly integrated.)
Users can enter strings that don't map to tiles. They now get an
error. It made sense for the error alert to have a "Show tiles"
button, so there's now a dialog listing all the tiles in a wordlist,
something the browser has needed all along.
2020-08-05 18:25:33 +02:00
|
|
|
typedef struct DictIter DictIter;
|
|
|
|
|
|
|
|
/* A pattern is a list of Tiles (that must be contained in the wordlist) plus
|
|
|
|
* regex meta-characters. Tiles are optionally delimited by '.' (to deal with
|
|
|
|
* the Hungarian case) Supported are:
|
|
|
|
*
|
|
|
|
* tile sets (e.g. [A.B.C]); also [^A.B.C] means NOT these, and [+A.B.C] means
|
|
|
|
* use at most once [+A.B.C]{3} would mean "use all of them once each"
|
|
|
|
*
|
2020-08-17 04:29:08 +02:00
|
|
|
* '_' (meaning blank/anything, same as '.' in most regex languages),
|
add filtering to wordlist browser
Add a basic regular expression engine to the dictiter, and to the UI add
the ability to filter for "starts with", "contains" and "ends with",
which translate into ANDed RE_*, _*RE_* and _*RE, respectively (with
_ standing for blank/wildcard). The engine's tightly integrated with the
next/prevWord() functions for greatest possible speed, but unless
there's no pattern does slow things down a bit (especially when "ENDS
WITH" is used.) The full engine is not exposed (users can't provide raw
REs), and while the parser will accept nesting (e.g. ([AB]_*[CD]){2,5}
to mean words from 2-5 tiles long starting with A or B and ending with C
or D) the engine can't handle it. Which is why filtering for word length
is handled separately from REs (but also tightly integrated.)
Users can enter strings that don't map to tiles. They now get an
error. It made sense for the error alert to have a "Show tiles"
button, so there's now a dialog listing all the tiles in a wordlist,
something the browser has needed all along.
2020-08-05 18:25:33 +02:00
|
|
|
*
|
|
|
|
* '*' meaning 0 or more of what's before
|
|
|
|
*
|
|
|
|
* '+' meaning 1 or more of what's before
|
|
|
|
*
|
2020-08-17 04:29:08 +02:00
|
|
|
* '{m[,n]}' meaning between m and n of what's before, so _{2,15} matches
|
add filtering to wordlist browser
Add a basic regular expression engine to the dictiter, and to the UI add
the ability to filter for "starts with", "contains" and "ends with",
which translate into ANDed RE_*, _*RE_* and _*RE, respectively (with
_ standing for blank/wildcard). The engine's tightly integrated with the
next/prevWord() functions for greatest possible speed, but unless
there's no pattern does slow things down a bit (especially when "ENDS
WITH" is used.) The full engine is not exposed (users can't provide raw
REs), and while the parser will accept nesting (e.g. ([AB]_*[CD]){2,5}
to mean words from 2-5 tiles long starting with A or B and ending with C
or D) the engine can't handle it. Which is why filtering for word length
is handled separately from REs (but also tightly integrated.)
Users can enter strings that don't map to tiles. They now get an
error. It made sense for the error alert to have a "Show tiles"
button, so there's now a dialog listing all the tiles in a wordlist,
something the browser has needed all along.
2020-08-05 18:25:33 +02:00
|
|
|
* everything
|
|
|
|
*
|
2020-08-17 04:29:08 +02:00
|
|
|
* '()' (not implemented) also required to express word length: (AB_*CD){2,15}
|
|
|
|
* is "an word beginning with AB and ending with CD from 2 to 15 letters long.
|
add filtering to wordlist browser
Add a basic regular expression engine to the dictiter, and to the UI add
the ability to filter for "starts with", "contains" and "ends with",
which translate into ANDed RE_*, _*RE_* and _*RE, respectively (with
_ standing for blank/wildcard). The engine's tightly integrated with the
next/prevWord() functions for greatest possible speed, but unless
there's no pattern does slow things down a bit (especially when "ENDS
WITH" is used.) The full engine is not exposed (users can't provide raw
REs), and while the parser will accept nesting (e.g. ([AB]_*[CD]){2,5}
to mean words from 2-5 tiles long starting with A or B and ending with C
or D) the engine can't handle it. Which is why filtering for word length
is handled separately from REs (but also tightly integrated.)
Users can enter strings that don't map to tiles. They now get an
error. It made sense for the error alert to have a "Show tiles"
button, so there's now a dialog listing all the tiles in a wordlist,
something the browser has needed all along.
2020-08-05 18:25:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* di_makeIter: It's either-or: provide the pattern as a reg-ex string, or as
|
|
|
|
* an array of three tile-strings representing starts-with, contains, and
|
|
|
|
* ends-with. The first is more powerful but I'm not sure it'll ever be part
|
|
|
|
* of a shipping UI.*/
|
|
|
|
typedef struct _PatDesc {
|
2020-08-11 23:13:11 +02:00
|
|
|
Tile tiles[MAX_COLS_DICT];
|
add filtering to wordlist browser
Add a basic regular expression engine to the dictiter, and to the UI add
the ability to filter for "starts with", "contains" and "ends with",
which translate into ANDed RE_*, _*RE_* and _*RE, respectively (with
_ standing for blank/wildcard). The engine's tightly integrated with the
next/prevWord() functions for greatest possible speed, but unless
there's no pattern does slow things down a bit (especially when "ENDS
WITH" is used.) The full engine is not exposed (users can't provide raw
REs), and while the parser will accept nesting (e.g. ([AB]_*[CD]){2,5}
to mean words from 2-5 tiles long starting with A or B and ending with C
or D) the engine can't handle it. Which is why filtering for word length
is handled separately from REs (but also tightly integrated.)
Users can enter strings that don't map to tiles. They now get an
error. It made sense for the error alert to have a "Show tiles"
button, so there's now a dialog listing all the tiles in a wordlist,
something the browser has needed all along.
2020-08-05 18:25:33 +02:00
|
|
|
XP_U16 nTiles;
|
|
|
|
XP_Bool anyOrderOk;
|
|
|
|
} PatDesc;
|
|
|
|
|
|
|
|
typedef struct _DIMinMax {
|
|
|
|
XP_U16 min;
|
|
|
|
XP_U16 max;
|
|
|
|
} DIMinMax;
|
|
|
|
|
|
|
|
DictIter* di_makeIter( const DictionaryCtxt* dict, XWEnv xwe,
|
|
|
|
const DIMinMax* lens, /* NULL means use defaults */
|
|
|
|
const XP_UCHAR** strPats, XP_U16 nStrPats,
|
|
|
|
const PatDesc* pats, XP_U16 nPatDescs );
|
|
|
|
void di_freeIter( DictIter* iter, XWEnv xwe );
|
|
|
|
|
|
|
|
#ifdef XWFEATURE_TESTPATSTR
|
|
|
|
XP_Bool di_stringMatches( DictIter* iter, const XP_UCHAR* string );
|
|
|
|
#endif
|
|
|
|
|
2020-05-04 06:45:08 +02:00
|
|
|
XP_U32 di_countWords( const DictIter* iter, LengthsArray* lens );
|
|
|
|
void di_makeIndex( const DictIter* iter, XP_U16 depth, IndexData* data );
|
|
|
|
XP_Bool di_firstWord( DictIter* iter );
|
|
|
|
XP_Bool di_lastWord( DictIter* iter );
|
|
|
|
XP_Bool di_getNextWord( DictIter* iter );
|
|
|
|
XP_Bool di_getPrevWord( DictIter* iter );
|
add filtering to wordlist browser
Add a basic regular expression engine to the dictiter, and to the UI add
the ability to filter for "starts with", "contains" and "ends with",
which translate into ANDed RE_*, _*RE_* and _*RE, respectively (with
_ standing for blank/wildcard). The engine's tightly integrated with the
next/prevWord() functions for greatest possible speed, but unless
there's no pattern does slow things down a bit (especially when "ENDS
WITH" is used.) The full engine is not exposed (users can't provide raw
REs), and while the parser will accept nesting (e.g. ([AB]_*[CD]){2,5}
to mean words from 2-5 tiles long starting with A or B and ending with C
or D) the engine can't handle it. Which is why filtering for word length
is handled separately from REs (but also tightly integrated.)
Users can enter strings that don't map to tiles. They now get an
error. It made sense for the error alert to have a "Show tiles"
button, so there's now a dialog listing all the tiles in a wordlist,
something the browser has needed all along.
2020-08-05 18:25:33 +02:00
|
|
|
XP_Bool di_getNthWord( DictIter* iter, XWEnv xwe, DictPosition position, XP_U16 depth,
|
2020-05-04 06:45:08 +02:00
|
|
|
const IndexData* data );
|
add filtering to wordlist browser
Add a basic regular expression engine to the dictiter, and to the UI add
the ability to filter for "starts with", "contains" and "ends with",
which translate into ANDed RE_*, _*RE_* and _*RE, respectively (with
_ standing for blank/wildcard). The engine's tightly integrated with the
next/prevWord() functions for greatest possible speed, but unless
there's no pattern does slow things down a bit (especially when "ENDS
WITH" is used.) The full engine is not exposed (users can't provide raw
REs), and while the parser will accept nesting (e.g. ([AB]_*[CD]){2,5}
to mean words from 2-5 tiles long starting with A or B and ending with C
or D) the engine can't handle it. Which is why filtering for word length
is handled separately from REs (but also tightly integrated.)
Users can enter strings that don't map to tiles. They now get an
error. It made sense for the error alert to have a "Show tiles"
button, so there's now a dialog listing all the tiles in a wordlist,
something the browser has needed all along.
2020-08-05 18:25:33 +02:00
|
|
|
XP_U32 di_getNWords( const DictIter* iter );
|
|
|
|
void di_getMinMax( const DictIter* iter, XP_U16* min, XP_U16* max );
|
|
|
|
|
2020-05-04 17:33:15 +02:00
|
|
|
void di_wordToString( const DictIter* iter, XP_UCHAR* buf, XP_U16 buflen,
|
|
|
|
const XP_UCHAR* delim );
|
|
|
|
void di_stringToTiles( const XP_UCHAR* str, Tile out[], XP_U16* nTiles );
|
2020-05-04 06:45:08 +02:00
|
|
|
DictPosition di_getPosition( const DictIter* iter );
|
2011-11-01 02:30:55 +01:00
|
|
|
#ifdef CPLUS
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* XWFEATURE_WALKDICT */
|
|
|
|
#endif
|