/*-------------------------------------------------------------------------
 * tox - an XML tokenizer
 *
 * Copyright (c) 2000 Eckhart Köppen
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *-----------------------------------------------------------------------*/

/* $Id: tox.h,v 1.10 2000/05/19 14:28:37 koeppen Exp $ */

#ifndef __TOX_H
#define __TOX_H

#ifdef __cplusplus
extern "C" {
#endif

typedef unsigned short char_t;

/* typedef unsigned char char_t; */

typedef struct
{
	unsigned int accept_type;
	char_t accept_value;
	int next_state;
	unsigned char action;
} state_def;

typedef struct
{
	char_t start;
	char_t end;
} char_range;

struct _parser_state;

typedef void (callback)(struct _parser_state *);

typedef struct _parser_state
{
	char_t *text;
	int current;
	int maxtext;

	int state;

	char pump;
	char_t *buffer;
	int bcurrent;
	int maxbuf;

	int squoteLevel;
	int dquoteLevel;
	int angleBracketLevel;

	callback *element_callback;
	callback *attrname_callback;
	callback *attrval_callback;
	callback *word_callback;
	callback *ws_callback;
	
	void *userdata;
} parser_state;

typedef struct
{
	parser_state *state;
	
	callback *element_callback;
	callback *attrname_callback;
	callback *attrval_callback;
	callback *word_callback;
} parser;

#define STATE_ERROR             -2
#define STATE_END               -1
#define STATE_CONTENT            0
#define STATE_STARTTAG_START     1
#define STATE_REF_START          2
#define STATE_CHARDATA           3
#define STATE_ENDTAG_START       4
#define STATE_STARTTAG_NAME      5
#define STATE_REF_NAME           6
#define STATE_ENDTAG_NAME        7
#define STATE_STARTTAG_NAMEEND   8
#define STATE_ENDTAG_NAMEEND     9
#define STATE_ATTR_NAME         10
#define STATE_ATTR_NAMEEND      11
#define STATE_ATTR_VALSTART     12
#define STATE_ATTR_VALDQUOT     13
#define STATE_EMPTYTAG_END      14
#define STATE_ATTR_VALDQUOT_REF 15
#define STATE_ATTR_VDQ_REFNAME  16
#define STATE_ATTR_VALSQUOT     17
#define STATE_ATTR_VALSQUOT_REF 18
#define STATE_ATTR_VSQ_REFNAME  19
#define STATE_DTD_START         20
#define STATE_MARKUPDECL_START  21
#define STATE_CDATA             22
#define STATE_CDATA_1ST_BRACKET 23
#define STATE_CDATA_2ND_BRACKET 24
#define STATE_PI                25
#define STATE_PI_END_QMARK      26
#define STATE_COMMENT           27
#define STATE_COMMENT_1ST_DASH  28
#define STATE_COMMENT_2ND_DASH  29
#define STATE_REF_NUMBER        30
#define	STATE_REF_HEX_NUMBER_1  31
#define	STATE_REF_HEX_NUMBER    32
#define STATE_REF_DEC_NUMBER    33
#define STATE_WS_CONTENT        34
#define STATE_WORD_CONTENT      35
#define STATE_COMMENT_START_1ST 36
#define STATE_DOCTYPE_D         37
#define STATE_DOCTYPE_O         38
#define STATE_DOCTYPE_C         39
#define STATE_DOCTYPE_T         40
#define STATE_DOCTYPE_Y         41
#define STATE_DOCTYPE_P         42
#define STATE_CDATA_BRACKET     43
#define STATE_CDATA_C           44
#define STATE_CDATA_D           45
#define STATE_CDATA_A           46
#define STATE_CDATA_T           47
#define STATE_CDATA_A2          48

void tox_parse (parser_state *parser);
int tox_wstrcmp (char_t *s1, char *s2);
int tox_strlen (char *s);

#ifdef __cplusplus
}
#endif

#endif


/*
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 4
 * End:
 */
