/* -*-mode: C; fill-column: 78; c-basic-offset: 4;-*- */
/* 
 * Copyright 1998-2001 by Eric House (fixin@peak.org).  All rights 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 _DAWG_H_
#define _DAWG_H_

/*
 * the bits field has five bits for the character (0-based rather than
 * 'a'-based, of course; one bit each indicating whether the edge may
 * be terminal and whether it's the last edge of a sub-array; and a final
 * bit that's overflow from the highByte field allowing indices to be in
 * the range 0-(2^^17)-1
 */
#define LETTERMASK 0x1f
#define ACCEPTINGMASK 0x20
#define LASTEDGEMASK 0x40
#define LASTBITMASK 0x80

typedef struct array_edge_old {
    XP_U8 highByte;
    XP_U8 lowByte;
    XP_U8 bits;
} array_edge_old;

typedef struct array_edge_new {
    array_edge_old o;
    XP_U8 moreBits;
} array_edge_new;

typedef XP_U8 array_edge;

/* This thing exists only in current xwords dicts (on PalmOS); not sure if I
 * should do away with it.
 */
typedef struct dawg_header {
    unsigned long numWords;
    unsigned char firstEdgeRecNum;
    unsigned char charTableRecNum;
    unsigned char valTableRecNum;
    unsigned char reserved[3]; /* worst case this points to a new resource */
} dawg_header;

/* Part of xwords3 dictionaries on PalmOS */
typedef struct Xloc_header {
    unsigned char langCodeFlags; /* can't do bitfields; gcc for pilot and x86
				    seem to generate different code */
    unsigned char padding;       /* ptrs to the shorts in Xloc_specialEntry
				    will otherwise be odd */
} Xloc_header;

typedef struct Xloc_specialEntry {
    unsigned char textVersion[4]; /* string can be up to 3 chars long */
    short hasLarge;
    short hasSmall;
} Xloc_specialEntry;

#endif /* _DAWG_H_ */
