/*
 *
 * fowc.h -- header file for fowc.c
 *
 * This code is copyright 1995 by James A. Cherry, jac@doe.carleton.ca.
 * It is not to be redistributed or modified without his permission.
 *
 */

/* Maximum argument and token count */

#define MAXARGS		10
#define MAXTOKENS	30

/* Token types */

typedef enum { TOKEN_OPEN, TOKEN_CLOSE, TOKEN_NOT, TOKEN_ARG, TOKEN_OR,
	       TOKEN_AND } token_t;

/* Token pair allowabilities */

typedef enum { PAIR_OK = 1, PAIR_AND, PAIR_SYN } pair_t;

/* Argument senses */

typedef enum { SENSE_POS = 1, SENSE_NEG } args_t;

/* Argument types */

typedef enum { ARG_MAY_ONLY_CONTAIN = 1, ARG_MUST_CONTAIN, ARG_LENGTH,
	       ARG_REGEXP } argt_t;

/* Length possibilities */

typedef enum { LENGTH_IMPOSSIBLE = 1, LENGTH_POSSIBLE,
	       LENGTH_DEFINITE } length_t;

char RName[20];                  /* name of command giver */

int WArgC;                       /* argument count */
char *WArgV[MAXARGS];            /* argument text */
int WArgL[MAXARGS];              /* argument lengths */
argt_t WArgT[MAXARGS];           /* ARG_MUST_CONTAIN, etc. */
args_t WArgS[MAXARGS];           /* SENSE_POS, etc. */

int Tokens;                      /* number of tokens */
token_t TokenType[MAXTOKENS];    /* type of each token */
int TokenArg[MAXTOKENS];         /* which token number an argument is */
int CTok, FreeEntry;             /* current token count; last free entry */
int TreeHead, TreeDepth;         /* pointer to head of tree; depth of tree */

/* Leaves for search tree */

struct treeent {
    token_t type;                /* TOKEN_ARG, etc. */
    int arg;                     /* pointer to argument */
    int left;                    /* pointer to left branch */
    int right;                   /* pointer to right branch */
    args_t negsense;             /* SENSE_POS, etc. */
    int llower;                  /* depth of tree on left side */
    int rlower;                  /* depth of tree on right side */
} WTree[MAXARGS * 2 - 1];

length_t VLen[MAXARGS][MAX_WLEN + 1]; /* LENGTH_IMPOSSIBLE, etc. */
int LenW;                        /* global storage for length of word */

int LetAr[MAXARGS][27];          /* letter count for `>' and `<' args */

int REStart[MAXARGS];            /* 1 if `^' in pattern */
int REEnd[MAXARGS];              /* 1 if '$' in pattern */
int RELen[MAXARGS];              /* length of pattern */
int REValidL[MAXARGS][MAX_WLEN][26]; /* valid letters at each pattern pos'n */

int WMatches;                    /* counts number of matches */
int FMLen, LMLen;                /* first and last match word lengths */
int FMInd, LMInd;                /* first and last match indices */
int FMNum, LMNum;                /* first and last match word numbers */
int MWXSize, MWYSize;            /* size of output grid */
char MWGrid[20][80];             /* output grid storage */

/* Search types */

typedef enum { WORDS_ROBOT = 1, WORDS_CRITIQUE, WORDS_BINGO } words_t;
words_t SType;

int FirstSearch;                 /* is this the first search with this tree? */
int *LineList;                   /* storage for list of matching word lines */
int LLLen;                       /* length of line list */
int LineInd;                     /* index into line list */

/* Words command types */

typedef enum { WC_WORDS = 1, WC_GOTO, WC_PAGE } wc_t;

