trunk: changeset 1303

Mon, 16 Feb 2004 00:44:56 +0100

author
tuomov
date
Mon, 16 Feb 2004 00:44:56 +0100
changeset 58
789df543d0c3
parent 57
de75d868bc0b
child 59
d8ecbeda7683

trunk: changeset 1303
Moved header files to top level directory.

Makefile file | annotate | diff | comparison | revisions
dlist.h file | annotate | diff | comparison | revisions
include/libtu/dlist.h file | annotate | diff | comparison | revisions
include/libtu/map.h file | annotate | diff | comparison | revisions
include/libtu/misc.h file | annotate | diff | comparison | revisions
include/libtu/optparser.h file | annotate | diff | comparison | revisions
include/libtu/output.h file | annotate | diff | comparison | revisions
include/libtu/parser.h file | annotate | diff | comparison | revisions
include/libtu/tokenizer.h file | annotate | diff | comparison | revisions
include/libtu/types.h file | annotate | diff | comparison | revisions
include/libtu/util.h file | annotate | diff | comparison | revisions
map.h file | annotate | diff | comparison | revisions
misc.h file | annotate | diff | comparison | revisions
optparser.h file | annotate | diff | comparison | revisions
output.h file | annotate | diff | comparison | revisions
parser.h file | annotate | diff | comparison | revisions
tokenizer.h file | annotate | diff | comparison | revisions
types.h file | annotate | diff | comparison | revisions
util.h file | annotate | diff | comparison | revisions
--- a/Makefile	Sun Jan 25 12:07:52 2004 +0100
+++ b/Makefile	Mon Feb 16 00:44:56 2004 +0100
@@ -25,6 +25,8 @@
 
 TARGETS=libtu.a
 TESTERS=tester tester2 tester3
+HEADERS=dlist.h misc.h output.h tokenizer.h util.h \
+        map.h np-conv.h optparser.h parser.h types.h
 
 ######################################
 
@@ -51,6 +53,6 @@
 	$(INSTALLDIR) $(LIBDIR)
 	$(INSTALLDIR) $(INCDIR)/libtu
 	$(INSTALL) -m $(DATA_MODE) libtu.a $(LIBDIR)
-	for i in include/libtu/*.h; do \
+	for i in $(HEADERS); do \
 		$(INSTALL) -m $(DATA_MODE) $$i $(INCDIR)/libtu; \
 	done
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dlist.h	Mon Feb 16 00:44:56 2004 +0100
@@ -0,0 +1,76 @@
+/*
+ * libtu/common.h
+ *
+ * Copyright (c) Tuomo Valkonen 1999-2002. 
+ *
+ * You may distribute and modify this library under the terms of either
+ * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
+ */
+
+#ifndef LIBTU_DLIST_H
+#define LIBTU_DLIST_H
+
+#define LINK_ITEM(LIST, ITEM, NEXT, PREV) \
+	(ITEM)->NEXT=NULL;                    \
+	if((LIST)==NULL){                     \
+		(LIST)=(ITEM);                    \
+		(ITEM)->PREV=(ITEM);              \
+	}else{                                \
+		(ITEM)->PREV=(LIST)->PREV;        \
+		(ITEM)->PREV->NEXT=(ITEM);        \
+		(LIST)->PREV=(ITEM);              \
+	}
+
+
+#define LINK_ITEM_FIRST(LIST, ITEM, NEXT, PREV) \
+	(ITEM)->NEXT=(LIST);                        \
+	if((LIST)==NULL){                           \
+		(ITEM)->PREV=(ITEM);                    \
+	}else{                                      \
+		(ITEM)->PREV=(LIST)->PREV;              \
+		(LIST)->PREV=(ITEM);                    \
+	}                                           \
+	(LIST)=(ITEM);
+
+
+#define LINK_ITEM_LIST LINK_ITEM
+
+
+#define LINK_ITEM_BEFORE(LIST, BEFORE, ITEM, NEXT, PREV) \
+	(ITEM)->NEXT=(BEFORE);                               \
+	(ITEM)->PREV=(BEFORE)->PREV;                         \
+	(BEFORE)->PREV=(ITEM);                               \
+	if((BEFORE)==(LIST))                                 \
+		(LIST)=(ITEM);                                   \
+	else                                                 \
+		(ITEM)->PREV->NEXT=(ITEM)
+
+
+#define LINK_ITEM_AFTER(LIST, AFTER, ITEM, NEXT, PREV) \
+	(ITEM)->NEXT=(AFTER)->NEXT;                        \
+	(ITEM)->PREV=(AFTER);                              \
+	(AFTER)->NEXT=(ITEM);                              \
+	if((ITEM)->NEXT==NULL)                             \
+		(LIST)->PREV=(ITEM);                           \
+	else                                               \
+		(ITEM)->NEXT->PREV=ITEM;
+
+
+#define UNLINK_ITEM(LIST, ITEM, NEXT, PREV)  \
+	if((ITEM)->PREV!=NULL){                  \
+		if((ITEM)==(LIST)){                  \
+			(LIST)=(ITEM)->NEXT;             \
+			if((LIST)!=NULL)                 \
+				(LIST)->PREV=(ITEM)->PREV;   \
+		}else if((ITEM)->NEXT==NULL){        \
+			(ITEM)->PREV->NEXT=NULL;         \
+			(LIST)->PREV=(ITEM)->PREV;       \
+		}else{                               \
+			(ITEM)->PREV->NEXT=(ITEM)->NEXT; \
+			(ITEM)->NEXT->PREV=(ITEM)->PREV; \
+		}                                    \
+	}                                        \
+	(ITEM)->NEXT=NULL;                       \
+	(ITEM)->PREV=NULL;
+
+#endif /* LIBTU_DLIST_H */
--- a/include/libtu/dlist.h	Sun Jan 25 12:07:52 2004 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-/*
- * libtu/common.h
- *
- * Copyright (c) Tuomo Valkonen 1999-2002. 
- *
- * You may distribute and modify this library under the terms of either
- * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
- */
-
-#ifndef LIBTU_DLIST_H
-#define LIBTU_DLIST_H
-
-#define LINK_ITEM(LIST, ITEM, NEXT, PREV) \
-	(ITEM)->NEXT=NULL;                    \
-	if((LIST)==NULL){                     \
-		(LIST)=(ITEM);                    \
-		(ITEM)->PREV=(ITEM);              \
-	}else{                                \
-		(ITEM)->PREV=(LIST)->PREV;        \
-		(ITEM)->PREV->NEXT=(ITEM);        \
-		(LIST)->PREV=(ITEM);              \
-	}
-
-
-#define LINK_ITEM_FIRST(LIST, ITEM, NEXT, PREV) \
-	(ITEM)->NEXT=(LIST);                        \
-	if((LIST)==NULL){                           \
-		(ITEM)->PREV=(ITEM);                    \
-	}else{                                      \
-		(ITEM)->PREV=(LIST)->PREV;              \
-		(LIST)->PREV=(ITEM);                    \
-	}                                           \
-	(LIST)=(ITEM);
-
-
-#define LINK_ITEM_LIST LINK_ITEM
-
-
-#define LINK_ITEM_BEFORE(LIST, BEFORE, ITEM, NEXT, PREV) \
-	(ITEM)->NEXT=(BEFORE);                               \
-	(ITEM)->PREV=(BEFORE)->PREV;                         \
-	(BEFORE)->PREV=(ITEM);                               \
-	if((BEFORE)==(LIST))                                 \
-		(LIST)=(ITEM);                                   \
-	else                                                 \
-		(ITEM)->PREV->NEXT=(ITEM)
-
-
-#define LINK_ITEM_AFTER(LIST, AFTER, ITEM, NEXT, PREV) \
-	(ITEM)->NEXT=(AFTER)->NEXT;                        \
-	(ITEM)->PREV=(AFTER);                              \
-	(AFTER)->NEXT=(ITEM);                              \
-	if((ITEM)->NEXT==NULL)                             \
-		(LIST)->PREV=(ITEM);                           \
-	else                                               \
-		(ITEM)->NEXT->PREV=ITEM;
-
-
-#define UNLINK_ITEM(LIST, ITEM, NEXT, PREV)  \
-	if((ITEM)->PREV!=NULL){                  \
-		if((ITEM)==(LIST)){                  \
-			(LIST)=(ITEM)->NEXT;             \
-			if((LIST)!=NULL)                 \
-				(LIST)->PREV=(ITEM)->PREV;   \
-		}else if((ITEM)->NEXT==NULL){        \
-			(ITEM)->PREV->NEXT=NULL;         \
-			(LIST)->PREV=(ITEM)->PREV;       \
-		}else{                               \
-			(ITEM)->PREV->NEXT=(ITEM)->NEXT; \
-			(ITEM)->NEXT->PREV=(ITEM)->PREV; \
-		}                                    \
-	}                                        \
-	(ITEM)->NEXT=NULL;                       \
-	(ITEM)->PREV=NULL;
-
-#endif /* LIBTU_DLIST_H */
--- a/include/libtu/map.h	Sun Jan 25 12:07:52 2004 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-/*
- * libtu/map.h
- *
- * Copyright (c) Tuomo Valkonen 1999-2002. 
- *
- * You may distribute and modify this library under the terms of either
- * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
- */
-
-#ifndef LIBTU_MAP_H
-#define LIBTU_MAP_H
-
-typedef struct _StringIntMap{
-	const char *string;
-	int value;
-} StringIntMap;
-
-#define END_STRINGINTMAP {NULL, 0}
-
-/* Return the index of str in map or -1 if not found. */
-extern int stringintmap_ndx(const StringIntMap *map, const char *str);
-extern int stringintmap_value(const StringIntMap *map, const char *str,
-							  int dflt);
-
-#endif /* LIBTU_MAP_H */
--- a/include/libtu/misc.h	Sun Jan 25 12:07:52 2004 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-/*
- * libtu/misc.h
- *
- * Copyright (c) Tuomo Valkonen 1999-2002. 
- *
- * You may distribute and modify this library under the terms of either
- * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
- */
-
-#ifndef LIBTU_MISC_H
-#define LIBTU_MISC_H
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-#include "types.h"
-
-#define TR(X) X
-#define DUMMY_TR(X) X
-
-#define ALLOC(X) (X*)malloczero(sizeof(X))
-#define ALLOC_N(X, N) (X*)malloczero(sizeof(X)*(N))
-#define REALLOC_N(PTR, X, S, N) (X*)remalloczero(PTR, sizeof(X)*(S), sizeof(X)*(N))
-
-#define FREE(X) do{if(X!=NULL)free(X);}while(0)
-
-extern void* malloczero(size_t size);
-extern void* remalloczero(void *ptr, size_t oldsize, size_t newsize);
-
-extern char* scopy(const char *p);
-extern char* scat(const char *p1, const char *p2);
-extern char* scatn(const char *p1, ssize_t n1, const char *p2, ssize_t n2);
-extern char* scat3(const char *p1, const char *p2, const char *p3);
-extern void stripws(char *p);
-
-extern const char* simple_basename(const char *name);
-
-/* I dislike fread and fwrite... */
-extern bool readf(FILE *fd, void *buf, size_t n);
-extern bool writef(FILE *fd, const void *buf, size_t n);
-
-#endif /* LIBTU_MISC_H */
--- a/include/libtu/optparser.h	Sun Jan 25 12:07:52 2004 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-/*
- * libtu/optparser.h
- *
- * Copyright (c) Tuomo Valkonen 1999-2002. 
- *
- * You may distribute and modify this library under the terms of either
- * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
- */
-
-#ifndef LIBTU_OPTPARSER_H
-#define LIBTU_OPTPARSER_H
-
-#include "types.h"
-
-
-#define OPT_ID_NOSHORT_FLAG 0x10000
-#define OPT_ID_RESERVED_FLAG 0x20000
-
-#define OPT_ID(X)			((X)|OPT_ID_NOSHORT_FLAG)
-#define OPT_ID_RESERVED(X)	((X)|OPT_ID_RESERVED_FLAG)
-
-/* OPTP_CHAIN is the normal behavior, i.e. single-letter options can be
- *		"chained" together: 'lr -lR'. Use for normal command line programs.
- * OPTP_MIDLONG allows '-display foo' -like args but disables chaining
- * 		of single-letter options. X programs should probably use this.
- * OPTP_IMMEDIATE allows immediate arguments (-I/usr/include) (and disables
- *		chaining and midlong options).
- * OPTP_NO_DASH is the same as OPTP_CHAIN but allows the dash to be omitted
- * 		for 'tar xzf foo' -like behavior.
- * Long '--foo=bar' options are supported in all of the modes.
- */
-
-enum{
-	OPTP_CHAIN=0,
-	OPTP_DEFAULT=0,
-	OPTP_MIDLONG=1,
-	OPTP_IMMEDIATE=2,
-	OPTP_NO_DASH=3
-};
-	
-enum{
-	OPT_ARG=1,					/* option has an argument					*/
-	OPT_OPT_ARG=3				/* option may have an argument				*/
-};
-
-
-#define END_OPTPARSEROPTS {0, NULL, 0, NULL, NULL}
-
-typedef struct _OptParserOpt{
-	int optid;
-	const char *longopt;
-	int	flags;
-	const char *argname;
-	const char *descr;
-} OptParserOpt;
-
-
-typedef struct _OptParserCommonInfo{
-	const char *version;
-	const char *usage_tmpl;
-	const char *about;
-} OptParserCommonInfo;
-
-
-enum{
-	OPT_ID_END=0,
-	OPT_ID_ARGUMENT=1,
-
-	E_OPT_INVALID_OPTION=-1,
-	E_OPT_INVALID_CHAIN_OPTION=-2,
-	E_OPT_SYNTAX_ERROR=-3,
-	E_OPT_MISSING_ARGUMENT=-4,
-	E_OPT_UNEXPECTED_ARGUMENT=-5
-};
-
-
-extern void optparser_init(int argc, char *const argv[], int mode,
-						   const OptParserOpt *opts,
-						   const OptParserCommonInfo *cinfo);
-
-extern int  optparser_get_opt();
-extern const char* optparser_get_arg();
-extern void optparser_print_error();
-
-#endif /* LIBTU_OPTPARSER_H */
--- a/include/libtu/output.h	Sun Jan 25 12:07:52 2004 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/*
- * libtu/output.h
- *
- * Copyright (c) Tuomo Valkonen 1999-2002. 
- *
- * You may distribute and modify this library under the terms of either
- * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
- */
-
-#ifndef LIBTU_OUTPUT_H
-#define LIBTU_OUTPUT_H
-
-#include <stdarg.h>
-
-#include "types.h"
-
-typedef void WarnHandler(const char *);
-extern WarnHandler *set_warn_handler(WarnHandler *handler);
-
-extern void verbose(const char *p, ...);
-extern void verbose_v(const char *p, va_list args);
-extern void verbose_enable(bool enable);
-extern int verbose_indent(int depth);
-
-extern void warn_progname_enable(bool enable);
-
-extern void die(const char *p, ...);
-extern void die_v(const char *p, va_list args);
-
-extern void die_obj(const char *obj, const char *p, ...);
-extern void die_obj_v(const char *obj, const char *p, va_list args);
-extern void die_obj_line(const char *obj, int line, const char *p, ...);
-extern void die_obj_line_v(const char *obj, int line, const char *p, va_list args);
-
-extern void die_err();
-extern void die_err_obj(const char *obj);
-extern void die_err_obj_line(const char *obj, int line);
-
-
-extern void warn(const char *p, ...);
-extern void warn_v(const char *p, va_list args);
-
-extern void warn_obj(const char *obj, const char *p, ...);
-extern void warn_obj_v(const char *obj, const char *p, va_list args);
-extern void warn_obj_line(const char *obj, int line, const char *p, ...);
-extern void warn_obj_line_v(const char *obj, int line, const char *p, va_list args);
-
-extern void warn_err();
-extern void warn_err_obj(const char *obj);
-extern void warn_err_obj_line(const char *obj, int line);
-
-
-extern char *errmsg(const char *p, ...);
-extern char *errmsg_v(const char *p, va_list args);
-
-extern char *errmsg_obj(const char *obj, const char *p, ...);
-extern char *errmsg_obj_v(const char *obj, const char *p, va_list args);
-extern char *errmsg_obj_line(const char *obj, int line, const char *p, ...);
-extern char *errmsg_obj_line_v(const char *obj, int line, const char *p, va_list args);
-
-extern char *errmsg_err();
-extern char *errmsg_err_obj(const char *obj);
-extern char *errmsg_err_obj_line(const char *obj, int line);
-
-extern void libtu_asprintf(char **ret, const char *fmt, ...);
-extern void libtu_vasprintf(char **ret, const char *fmt, va_list args);
-
-#endif /* LIBTU_OUTPUT_H */
--- a/include/libtu/parser.h	Sun Jan 25 12:07:52 2004 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*
- * libtu/parser.h
- *
- * Copyright (c) Tuomo Valkonen 1999-2002. 
- *
- * You may distribute and modify this library under the terms of either
- * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
- */
-
-#ifndef LIBTU_PARSER_H
-#define LIBTU_PARSER_H
-
-#include "tokenizer.h"
-
-/*
- * format:
- * 	l = long
- *	d = double
- * 	i = identifier
- * 	s = string
- * 	c = char
- *  . = 1 times any     ("l.d")
- *  * = 0 or more times any (must be the last, "sd*")
- * 	? = optional		("?c")
- * 	: = conditional		(":c:s")
- *  + = 1 or more times last (most be the last, "l+")
- * special entries:
- * 
- * "#end" 		call this handler at the end of section.
- * "#cancel" 	call this handler when recovering from error
- */
-
-#define END_CONFOPTS {NULL, NULL, NULL, NULL}
-
-typedef struct _ConfOpt{
-	const char *optname;
-	const char *argfmt;
-	bool (*fn)(Tokenizer *tokz, int n, Token *toks);
-	struct _ConfOpt *opts;
-} ConfOpt;
-
-#define CONFOPTS_NOT_SET libtu_dummy_confopts
-extern ConfOpt libtu_dummy_confopts[];
-
-extern bool parse_config_tokz(Tokenizer *tokz, const ConfOpt *options);
-extern bool parse_config_tokz_skip_section(Tokenizer *tokz);
-extern bool parse_config(const char *fname, const ConfOpt *options, int flags);
-extern bool parse_config_file(FILE *file, const ConfOpt *options, int flags);
-extern bool check_args(const Tokenizer *tokz, Token *tokens, int ntokens,
-					   const char *fmt);
-extern bool check_args_loose(const Tokenizer *tokz, Token *tokens, int ntokens,
-							 const char *fmt);
-
-#endif /* LIBTU_PARSER_H */
--- a/include/libtu/tokenizer.h	Sun Jan 25 12:07:52 2004 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,212 +0,0 @@
-/*
- * libtu/tokenizer.h
- *
- * Copyright (c) Tuomo Valkonen 1999-2002. 
- *
- * You may distribute and modify this library under the terms of either
- * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
- */
-
-#ifndef LIBTU_TOKENIZER_H
-#define LIBTU_TOKENIZER_H
-
-#include <stdio.h>
-#include "types.h"
-
-
-#define TOK_SET_BOOL(TOK, VAL) 		{(TOK)->type=TOK_BOOL; (TOK)->u.bval=VAL;}
-#define TOK_SET_LONG(TOK, VAL) 		{(TOK)->type=TOK_LONG; (TOK)->u.lval=VAL;}
-#define TOK_SET_DOUBLE(TOK, VAL) 	{(TOK)->type=TOK_DOUBLE; (TOK)->u.dval=VAL;}
-#define TOK_SET_CHAR(TOK, VAL) 		{(TOK)->type=TOK_CHAR; (TOK)->u.cval=VAL;}
-#define TOK_SET_STRING(TOK, VAL) 	{(TOK)->type=TOK_STRING; (TOK)->u.sval=VAL;}
-#define TOK_SET_IDENT(TOK, VAL) 	{(TOK)->type=TOK_IDENT; (TOK)->u.sval=VAL;}
-#define TOK_SET_COMMENT(TOK, VAL) 	{(TOK)->type=TOK_COMMENT; (TOK)->u.sval=VAL;}
-#define TOK_SET_OP(TOK, VAL) 		{(TOK)->type=TOK_OP; (TOK)->u.opval=VAL;}
-
-#define TOK_TYPE(TOK)				((TOK)->type)
-#define TOK_BOOL_VAL(TOK)			((TOK)->u.bval)
-#define TOK_LONG_VAL(TOK)			((TOK)->u.lval)
-#define TOK_DOUBLE_VAL(TOK)			((TOK)->u.dval)
-#define TOK_CHAR_VAL(TOK)			((TOK)->u.cval)
-#define TOK_STRING_VAL(TOK)			((TOK)->u.sval)
-#define TOK_IDENT_VAL(TOK)			((TOK)->u.sval)
-#define TOK_COMMENT_VAL(TOK)		((TOK)->u.sval)
-#define TOK_OP_VAL(TOK)				((TOK)->u.opval)
-
-#define TOK_IS_INVALID(TOK)			((TOK)->type==TOK_INVALID)
-#define TOK_IS_BOOL(TOK)			((TOK)->type==TOK_BOOL)
-#define TOK_IS_LONG(TOK)			((TOK)->type==TOK_LONG)
-#define TOK_IS_DOUBLE(TOK)			((TOK)->type==TOK_DOUBLE)
-#define TOK_IS_CHAR(TOK)			((TOK)->type==TOK_CHAR)
-#define TOK_IS_STRING(TOK)			((TOK)->type==TOK_STRING)
-#define TOK_IS_IDENT(TOK)			((TOK)->type==TOK_IDENT)
-#define TOK_IS_COMMENT(TOK)			((TOK)->type==TOK_COMMENT)
-#define TOK_IS_OP(TOK)				((TOK)->type==TOK_OP)
-
-#define TOK_OP_IS(TOK, OP)			((TOK)->type==TOK_OP && (TOK)->u.opval==(OP))
-
-#define TOK_TAKE_STRING_VAL(TOK)	((TOK)->type=TOK_INVALID, (TOK)->u.sval)
-#define TOK_TAKE_IDENT_VAL(TOK)		((TOK)->type=TOK_INVALID, (TOK)->u.sval)
-#define TOK_TAKE_COMMENT_VAL(TOK)	((TOK)->type=TOK_INVALID, (TOK)->u.sval)
-
-
-enum{
-	TOK_INVALID=0,
-	TOK_LONG='l',
-	TOK_DOUBLE='d',
-	TOK_CHAR='c',
-	TOK_STRING='s',
-	TOK_IDENT='i',
-	TOK_BOOL='b',
-	TOK_COMMENT='#',
-	TOK_OP='+'
-};
-
-
-enum{
-#define OP2(X,Y)   ((X)|((Y)<<8))
-#define OP3(X,Y,Z) ((X)|((Y)<<8)|((Z)<<16))
-
-	OP_L_PAR=	'(', OP_R_PAR=	')', OP_L_BRK=	'[', OP_R_BRK=	']',
-	OP_L_BRC=	'{', OP_R_BRC=	'}', OP_COMMA=	',', OP_SCOLON=	';',
-
-	OP_PLUS=	'+', OP_MINUS=	'-', OP_MUL=	'*', OP_DIV=	'/',
-	OP_MOD=		'%', OP_POW=	'^', OP_OR= 	'|', OP_AND=	'&',
-	/*OP_NOT=	'~',*/ OP_NOT=	'!', OP_ASGN=	'=', OP_LT=		'<',
-	OP_GT=		'>', OP_DOT=	'.', OP_COLON=	':', OP_QMARK=	'?',
-	OP_AT=		'@',
-	OP_NEXTLINE='\n',OP_EOF=	-1,
-	
-	OP_INC=		OP2('+','+'),		 OP_DEC=	OP2('-','-'),
-	OP_LSHIFT=	OP2('<','<'), 		 OP_RSHIFT=	OP2('>','>'),
-	OP_AS_INC=	OP2('+','='), 		 OP_AS_DEC= OP2('-','='),
-	OP_AS_MUL=	OP2('*','='), 		 OP_AS_DIV= OP2('/','='),
-	OP_AS_MOD=	OP2('%','='), 		 OP_AS_POW= OP2('^','='),
-
-/*	AS_OR=		OP2('|','='),		 AS_AND=	OP2('&','='), */
-	OP_EQ=		OP2('=','='), 		 OP_NE=		OP2('!','='),
-	OP_LE=		OP2('<','='), 		 OP_GE=		OP2('>','=')
-	
-/*	L_AND=		OP2('&','&'), L_OR=		OP2('|','|'),
-	L_XOR=		OP2('^','^'), */
-
-/*	AsLShift=	OP3('<','<','='),
-	AsRShift=	OP3('>','>','='), */
-		
-#undef OP2
-#undef OP3
-};
-
-
-typedef struct{
-	int type;
-	int line;
-	union{
-		bool bval;
-		long lval;
-		double dval;
-		char cval;
-		char *sval;
-		int opval;
-	} u;
-} Token;
-
-#define TOK_INIT {0, 0, {0}}
-
-
-extern void tok_free(Token*tok);
-extern void tok_init(Token*tok);
-
-
-/* */
-
-
-enum{
-	TOKZ_IGNORE_NEXTLINE=0x1,
-	TOKZ_READ_COMMENTS=0x2,
-	TOKZ_PARSER_INDENT_MODE=0x04,
-	TOKZ_ERROR_TOLERANT=0x8,
-	TOKZ_READ_FROM_BUFFER=0x10,
-	TOKZ_DEFAULT_OPTION=0x20
-};
-
-
-enum{
-	E_TOKZ_UNEXPECTED_EOF=1,
-	E_TOKZ_UNEXPECTED_EOL,
-	E_TOKZ_EOL_EXPECTED,
-	E_TOKZ_INVALID_CHAR,
-	E_TOKZ_TOOBIG,
-	E_TOKZ_NUMFMT,
-	E_TOKZ_NUM_JUNK,
-	E_TOKZ_NOTINT,
-	E_TOKZ_RANGE,
-	E_TOKZ_MULTICHAR,
-	
-	E_TOKZ_TOKEN_LIMIT,
-	E_TOKZ_UNKNOWN_OPTION,
-	E_TOKZ_SYNTAX,
-	E_TOKZ_INVALID_ARGUMENT,
-	E_TOKZ_EOS_EXPECTED,
-	E_TOKZ_TOO_FEW_ARGS,
-	E_TOKZ_TOO_MANY_ARGS,
-	E_TOKZ_MAX_NEST,
-	E_TOKZ_IDENTIFIER_EXPECTED,
-	
-	E_TOKZ_LBRACE_EXPECTED
-};
-
-
-struct _ConfOpt;
-
-typedef struct _Tokenizer_FInfo{
-	FILE *file;
-	char *name;
-	int line;
-	int ungetc;
-	Token ungettok;
-} Tokenizer_FInfo;
-
-typedef struct _Tokenizer_Buffer{
-		char *data;
-		int len;
-		int pos;
-} Tokenizer_Buffer;
-	
-typedef struct _Tokenizer{
-	FILE *file;
-	char *name;
-	int line;
-	int ungetc;
-	Token ungettok;
-	
-	Tokenizer_Buffer buffer;
-
-	int flags;
-	const struct _ConfOpt **optstack;
-	int nest_lvl;
-	void *user_data;
-
-	int filestack_n;
-	Tokenizer_FInfo *filestack;
-	
-	char **includepaths;
-} Tokenizer;
-
-
-extern Tokenizer *tokz_open(const char *fname);
-extern Tokenizer *tokz_open_file(FILE *file, const char *fname);
-extern Tokenizer *tokz_prepare_buffer(char *buffer, int len);
-extern void tokz_close(Tokenizer *tokz);
-extern bool tokz_get_token(Tokenizer *tokz, Token *tok);
-extern void tokz_unget_token(Tokenizer *tokz, Token *tok);
-extern void tokz_warn_error(const Tokenizer *tokz, int line, int e);
-extern void tokz_warn(const Tokenizer *tokz, int line, const char *fmt, ...);
-
-extern bool tokz_pushf(Tokenizer *tokz, const char *fname);
-extern bool tokz_pushf_file(Tokenizer *tokz, FILE *file, const char *fname);
-extern bool tokz_popf(Tokenizer *tokz);
-
-extern void tokz_set_includepaths(Tokenizer *tokz, char **paths);
-
-#endif /* LIBTU_TOKENIZER_H */
--- a/include/libtu/types.h	Sun Jan 25 12:07:52 2004 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-/*
- * libtu/types.h
- *
- * Copyright (c) Tuomo Valkonen 1999-2002. 
- *
- * You may distribute and modify this library under the terms of either
- * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
- */
-
-#ifndef LIBTU_TYPES_H
-#define LIBTU_TYPES_H
-
-#include <sys/types.h>
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-#ifndef NULL
-#define NULL ((void*)0)
-#endif
-
-#ifndef LIBTU_TYPEDEF_UXXX
-
- /* All systems seem to define these whichever way they want to
-  * despite -D_*_SOURCE etc. so there is no easy way to know whether
-  * they can be typedef'd or not. Unless you want to go through using
-  * autoconf or similar methods. ==> Just stick to #define. :-(
-  */
-  
-#ifndef uchar
-#define uchar unsigned char
-#endif
-
-#ifndef ushort
-#define ushort unsigned short
-#endif
-
-#ifndef uint
-#define uint unsigned int
-#endif
-
-#ifndef ulong
-#define ulong unsigned long
-#endif
-
-#else /* LIBTU_TYPEDEF_UXXX */
-
-#ifndef uchar
-typedef unsigned char uchar;
-#endif
-
-#ifndef ushort
-typedef unsigned short ushort;
-#endif
-
-#ifndef uint
-typedef unsigned int uint;
-#endif
-
-#ifndef ulong
-typedef unsigned long ulong;
-#endif
- 
-#endif /* LIBTU_TYPEDEF_UXXX */
-
-
-#ifndef LIBTU_TYPEDEF_BOOL
-
-#ifndef bool
-#define bool int
-#endif
- 
-#else /* LIBTU_TYPEDEF_BOOL */
-
-#ifndef bool
-typedef int bool;
-#endif
- 
-#endif /* LIBTU_TYPEDEF_BOOL */
-
-#endif /* LIBTU_TYPES_H */
--- a/include/libtu/util.h	Sun Jan 25 12:07:52 2004 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/*
- * libtu/util.h
- *
- * Copyright (c) Tuomo Valkonen 1999-2002. 
- *
- * You may distribute and modify this library under the terms of either
- * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
- */
-
-#ifndef LIBTU_UTIL_H
-#define LIBTU_UTIL_H
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "types.h"
-#include "optparser.h"
-
-extern void libtu_init(const char *argv0);
-extern void libtu_init_copt(int argc, char *const argv[],
-							const OptParserCommonInfo *cinfo);
-					   
-
-extern const char *prog_execname();
-
-#endif /* LIBTU_UTIL_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/map.h	Mon Feb 16 00:44:56 2004 +0100
@@ -0,0 +1,25 @@
+/*
+ * libtu/map.h
+ *
+ * Copyright (c) Tuomo Valkonen 1999-2002. 
+ *
+ * You may distribute and modify this library under the terms of either
+ * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
+ */
+
+#ifndef LIBTU_MAP_H
+#define LIBTU_MAP_H
+
+typedef struct _StringIntMap{
+	const char *string;
+	int value;
+} StringIntMap;
+
+#define END_STRINGINTMAP {NULL, 0}
+
+/* Return the index of str in map or -1 if not found. */
+extern int stringintmap_ndx(const StringIntMap *map, const char *str);
+extern int stringintmap_value(const StringIntMap *map, const char *str,
+							  int dflt);
+
+#endif /* LIBTU_MAP_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc.h	Mon Feb 16 00:44:56 2004 +0100
@@ -0,0 +1,42 @@
+/*
+ * libtu/misc.h
+ *
+ * Copyright (c) Tuomo Valkonen 1999-2002. 
+ *
+ * You may distribute and modify this library under the terms of either
+ * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
+ */
+
+#ifndef LIBTU_MISC_H
+#define LIBTU_MISC_H
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include "types.h"
+
+#define TR(X) X
+#define DUMMY_TR(X) X
+
+#define ALLOC(X) (X*)malloczero(sizeof(X))
+#define ALLOC_N(X, N) (X*)malloczero(sizeof(X)*(N))
+#define REALLOC_N(PTR, X, S, N) (X*)remalloczero(PTR, sizeof(X)*(S), sizeof(X)*(N))
+
+#define FREE(X) do{if(X!=NULL)free(X);}while(0)
+
+extern void* malloczero(size_t size);
+extern void* remalloczero(void *ptr, size_t oldsize, size_t newsize);
+
+extern char* scopy(const char *p);
+extern char* scat(const char *p1, const char *p2);
+extern char* scatn(const char *p1, ssize_t n1, const char *p2, ssize_t n2);
+extern char* scat3(const char *p1, const char *p2, const char *p3);
+extern void stripws(char *p);
+
+extern const char* simple_basename(const char *name);
+
+/* I dislike fread and fwrite... */
+extern bool readf(FILE *fd, void *buf, size_t n);
+extern bool writef(FILE *fd, const void *buf, size_t n);
+
+#endif /* LIBTU_MISC_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/optparser.h	Mon Feb 16 00:44:56 2004 +0100
@@ -0,0 +1,85 @@
+/*
+ * libtu/optparser.h
+ *
+ * Copyright (c) Tuomo Valkonen 1999-2002. 
+ *
+ * You may distribute and modify this library under the terms of either
+ * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
+ */
+
+#ifndef LIBTU_OPTPARSER_H
+#define LIBTU_OPTPARSER_H
+
+#include "types.h"
+
+
+#define OPT_ID_NOSHORT_FLAG 0x10000
+#define OPT_ID_RESERVED_FLAG 0x20000
+
+#define OPT_ID(X)			((X)|OPT_ID_NOSHORT_FLAG)
+#define OPT_ID_RESERVED(X)	((X)|OPT_ID_RESERVED_FLAG)
+
+/* OPTP_CHAIN is the normal behavior, i.e. single-letter options can be
+ *		"chained" together: 'lr -lR'. Use for normal command line programs.
+ * OPTP_MIDLONG allows '-display foo' -like args but disables chaining
+ * 		of single-letter options. X programs should probably use this.
+ * OPTP_IMMEDIATE allows immediate arguments (-I/usr/include) (and disables
+ *		chaining and midlong options).
+ * OPTP_NO_DASH is the same as OPTP_CHAIN but allows the dash to be omitted
+ * 		for 'tar xzf foo' -like behavior.
+ * Long '--foo=bar' options are supported in all of the modes.
+ */
+
+enum{
+	OPTP_CHAIN=0,
+	OPTP_DEFAULT=0,
+	OPTP_MIDLONG=1,
+	OPTP_IMMEDIATE=2,
+	OPTP_NO_DASH=3
+};
+	
+enum{
+	OPT_ARG=1,					/* option has an argument					*/
+	OPT_OPT_ARG=3				/* option may have an argument				*/
+};
+
+
+#define END_OPTPARSEROPTS {0, NULL, 0, NULL, NULL}
+
+typedef struct _OptParserOpt{
+	int optid;
+	const char *longopt;
+	int	flags;
+	const char *argname;
+	const char *descr;
+} OptParserOpt;
+
+
+typedef struct _OptParserCommonInfo{
+	const char *version;
+	const char *usage_tmpl;
+	const char *about;
+} OptParserCommonInfo;
+
+
+enum{
+	OPT_ID_END=0,
+	OPT_ID_ARGUMENT=1,
+
+	E_OPT_INVALID_OPTION=-1,
+	E_OPT_INVALID_CHAIN_OPTION=-2,
+	E_OPT_SYNTAX_ERROR=-3,
+	E_OPT_MISSING_ARGUMENT=-4,
+	E_OPT_UNEXPECTED_ARGUMENT=-5
+};
+
+
+extern void optparser_init(int argc, char *const argv[], int mode,
+						   const OptParserOpt *opts,
+						   const OptParserCommonInfo *cinfo);
+
+extern int  optparser_get_opt();
+extern const char* optparser_get_arg();
+extern void optparser_print_error();
+
+#endif /* LIBTU_OPTPARSER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/output.h	Mon Feb 16 00:44:56 2004 +0100
@@ -0,0 +1,68 @@
+/*
+ * libtu/output.h
+ *
+ * Copyright (c) Tuomo Valkonen 1999-2002. 
+ *
+ * You may distribute and modify this library under the terms of either
+ * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
+ */
+
+#ifndef LIBTU_OUTPUT_H
+#define LIBTU_OUTPUT_H
+
+#include <stdarg.h>
+
+#include "types.h"
+
+typedef void WarnHandler(const char *);
+extern WarnHandler *set_warn_handler(WarnHandler *handler);
+
+extern void verbose(const char *p, ...);
+extern void verbose_v(const char *p, va_list args);
+extern void verbose_enable(bool enable);
+extern int verbose_indent(int depth);
+
+extern void warn_progname_enable(bool enable);
+
+extern void die(const char *p, ...);
+extern void die_v(const char *p, va_list args);
+
+extern void die_obj(const char *obj, const char *p, ...);
+extern void die_obj_v(const char *obj, const char *p, va_list args);
+extern void die_obj_line(const char *obj, int line, const char *p, ...);
+extern void die_obj_line_v(const char *obj, int line, const char *p, va_list args);
+
+extern void die_err();
+extern void die_err_obj(const char *obj);
+extern void die_err_obj_line(const char *obj, int line);
+
+
+extern void warn(const char *p, ...);
+extern void warn_v(const char *p, va_list args);
+
+extern void warn_obj(const char *obj, const char *p, ...);
+extern void warn_obj_v(const char *obj, const char *p, va_list args);
+extern void warn_obj_line(const char *obj, int line, const char *p, ...);
+extern void warn_obj_line_v(const char *obj, int line, const char *p, va_list args);
+
+extern void warn_err();
+extern void warn_err_obj(const char *obj);
+extern void warn_err_obj_line(const char *obj, int line);
+
+
+extern char *errmsg(const char *p, ...);
+extern char *errmsg_v(const char *p, va_list args);
+
+extern char *errmsg_obj(const char *obj, const char *p, ...);
+extern char *errmsg_obj_v(const char *obj, const char *p, va_list args);
+extern char *errmsg_obj_line(const char *obj, int line, const char *p, ...);
+extern char *errmsg_obj_line_v(const char *obj, int line, const char *p, va_list args);
+
+extern char *errmsg_err();
+extern char *errmsg_err_obj(const char *obj);
+extern char *errmsg_err_obj_line(const char *obj, int line);
+
+extern void libtu_asprintf(char **ret, const char *fmt, ...);
+extern void libtu_vasprintf(char **ret, const char *fmt, va_list args);
+
+#endif /* LIBTU_OUTPUT_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/parser.h	Mon Feb 16 00:44:56 2004 +0100
@@ -0,0 +1,54 @@
+/*
+ * libtu/parser.h
+ *
+ * Copyright (c) Tuomo Valkonen 1999-2002. 
+ *
+ * You may distribute and modify this library under the terms of either
+ * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
+ */
+
+#ifndef LIBTU_PARSER_H
+#define LIBTU_PARSER_H
+
+#include "tokenizer.h"
+
+/*
+ * format:
+ * 	l = long
+ *	d = double
+ * 	i = identifier
+ * 	s = string
+ * 	c = char
+ *  . = 1 times any     ("l.d")
+ *  * = 0 or more times any (must be the last, "sd*")
+ * 	? = optional		("?c")
+ * 	: = conditional		(":c:s")
+ *  + = 1 or more times last (most be the last, "l+")
+ * special entries:
+ * 
+ * "#end" 		call this handler at the end of section.
+ * "#cancel" 	call this handler when recovering from error
+ */
+
+#define END_CONFOPTS {NULL, NULL, NULL, NULL}
+
+typedef struct _ConfOpt{
+	const char *optname;
+	const char *argfmt;
+	bool (*fn)(Tokenizer *tokz, int n, Token *toks);
+	struct _ConfOpt *opts;
+} ConfOpt;
+
+#define CONFOPTS_NOT_SET libtu_dummy_confopts
+extern ConfOpt libtu_dummy_confopts[];
+
+extern bool parse_config_tokz(Tokenizer *tokz, const ConfOpt *options);
+extern bool parse_config_tokz_skip_section(Tokenizer *tokz);
+extern bool parse_config(const char *fname, const ConfOpt *options, int flags);
+extern bool parse_config_file(FILE *file, const ConfOpt *options, int flags);
+extern bool check_args(const Tokenizer *tokz, Token *tokens, int ntokens,
+					   const char *fmt);
+extern bool check_args_loose(const Tokenizer *tokz, Token *tokens, int ntokens,
+							 const char *fmt);
+
+#endif /* LIBTU_PARSER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tokenizer.h	Mon Feb 16 00:44:56 2004 +0100
@@ -0,0 +1,212 @@
+/*
+ * libtu/tokenizer.h
+ *
+ * Copyright (c) Tuomo Valkonen 1999-2002. 
+ *
+ * You may distribute and modify this library under the terms of either
+ * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
+ */
+
+#ifndef LIBTU_TOKENIZER_H
+#define LIBTU_TOKENIZER_H
+
+#include <stdio.h>
+#include "types.h"
+
+
+#define TOK_SET_BOOL(TOK, VAL) 		{(TOK)->type=TOK_BOOL; (TOK)->u.bval=VAL;}
+#define TOK_SET_LONG(TOK, VAL) 		{(TOK)->type=TOK_LONG; (TOK)->u.lval=VAL;}
+#define TOK_SET_DOUBLE(TOK, VAL) 	{(TOK)->type=TOK_DOUBLE; (TOK)->u.dval=VAL;}
+#define TOK_SET_CHAR(TOK, VAL) 		{(TOK)->type=TOK_CHAR; (TOK)->u.cval=VAL;}
+#define TOK_SET_STRING(TOK, VAL) 	{(TOK)->type=TOK_STRING; (TOK)->u.sval=VAL;}
+#define TOK_SET_IDENT(TOK, VAL) 	{(TOK)->type=TOK_IDENT; (TOK)->u.sval=VAL;}
+#define TOK_SET_COMMENT(TOK, VAL) 	{(TOK)->type=TOK_COMMENT; (TOK)->u.sval=VAL;}
+#define TOK_SET_OP(TOK, VAL) 		{(TOK)->type=TOK_OP; (TOK)->u.opval=VAL;}
+
+#define TOK_TYPE(TOK)				((TOK)->type)
+#define TOK_BOOL_VAL(TOK)			((TOK)->u.bval)
+#define TOK_LONG_VAL(TOK)			((TOK)->u.lval)
+#define TOK_DOUBLE_VAL(TOK)			((TOK)->u.dval)
+#define TOK_CHAR_VAL(TOK)			((TOK)->u.cval)
+#define TOK_STRING_VAL(TOK)			((TOK)->u.sval)
+#define TOK_IDENT_VAL(TOK)			((TOK)->u.sval)
+#define TOK_COMMENT_VAL(TOK)		((TOK)->u.sval)
+#define TOK_OP_VAL(TOK)				((TOK)->u.opval)
+
+#define TOK_IS_INVALID(TOK)			((TOK)->type==TOK_INVALID)
+#define TOK_IS_BOOL(TOK)			((TOK)->type==TOK_BOOL)
+#define TOK_IS_LONG(TOK)			((TOK)->type==TOK_LONG)
+#define TOK_IS_DOUBLE(TOK)			((TOK)->type==TOK_DOUBLE)
+#define TOK_IS_CHAR(TOK)			((TOK)->type==TOK_CHAR)
+#define TOK_IS_STRING(TOK)			((TOK)->type==TOK_STRING)
+#define TOK_IS_IDENT(TOK)			((TOK)->type==TOK_IDENT)
+#define TOK_IS_COMMENT(TOK)			((TOK)->type==TOK_COMMENT)
+#define TOK_IS_OP(TOK)				((TOK)->type==TOK_OP)
+
+#define TOK_OP_IS(TOK, OP)			((TOK)->type==TOK_OP && (TOK)->u.opval==(OP))
+
+#define TOK_TAKE_STRING_VAL(TOK)	((TOK)->type=TOK_INVALID, (TOK)->u.sval)
+#define TOK_TAKE_IDENT_VAL(TOK)		((TOK)->type=TOK_INVALID, (TOK)->u.sval)
+#define TOK_TAKE_COMMENT_VAL(TOK)	((TOK)->type=TOK_INVALID, (TOK)->u.sval)
+
+
+enum{
+	TOK_INVALID=0,
+	TOK_LONG='l',
+	TOK_DOUBLE='d',
+	TOK_CHAR='c',
+	TOK_STRING='s',
+	TOK_IDENT='i',
+	TOK_BOOL='b',
+	TOK_COMMENT='#',
+	TOK_OP='+'
+};
+
+
+enum{
+#define OP2(X,Y)   ((X)|((Y)<<8))
+#define OP3(X,Y,Z) ((X)|((Y)<<8)|((Z)<<16))
+
+	OP_L_PAR=	'(', OP_R_PAR=	')', OP_L_BRK=	'[', OP_R_BRK=	']',
+	OP_L_BRC=	'{', OP_R_BRC=	'}', OP_COMMA=	',', OP_SCOLON=	';',
+
+	OP_PLUS=	'+', OP_MINUS=	'-', OP_MUL=	'*', OP_DIV=	'/',
+	OP_MOD=		'%', OP_POW=	'^', OP_OR= 	'|', OP_AND=	'&',
+	/*OP_NOT=	'~',*/ OP_NOT=	'!', OP_ASGN=	'=', OP_LT=		'<',
+	OP_GT=		'>', OP_DOT=	'.', OP_COLON=	':', OP_QMARK=	'?',
+	OP_AT=		'@',
+	OP_NEXTLINE='\n',OP_EOF=	-1,
+	
+	OP_INC=		OP2('+','+'),		 OP_DEC=	OP2('-','-'),
+	OP_LSHIFT=	OP2('<','<'), 		 OP_RSHIFT=	OP2('>','>'),
+	OP_AS_INC=	OP2('+','='), 		 OP_AS_DEC= OP2('-','='),
+	OP_AS_MUL=	OP2('*','='), 		 OP_AS_DIV= OP2('/','='),
+	OP_AS_MOD=	OP2('%','='), 		 OP_AS_POW= OP2('^','='),
+
+/*	AS_OR=		OP2('|','='),		 AS_AND=	OP2('&','='), */
+	OP_EQ=		OP2('=','='), 		 OP_NE=		OP2('!','='),
+	OP_LE=		OP2('<','='), 		 OP_GE=		OP2('>','=')
+	
+/*	L_AND=		OP2('&','&'), L_OR=		OP2('|','|'),
+	L_XOR=		OP2('^','^'), */
+
+/*	AsLShift=	OP3('<','<','='),
+	AsRShift=	OP3('>','>','='), */
+		
+#undef OP2
+#undef OP3
+};
+
+
+typedef struct{
+	int type;
+	int line;
+	union{
+		bool bval;
+		long lval;
+		double dval;
+		char cval;
+		char *sval;
+		int opval;
+	} u;
+} Token;
+
+#define TOK_INIT {0, 0, {0}}
+
+
+extern void tok_free(Token*tok);
+extern void tok_init(Token*tok);
+
+
+/* */
+
+
+enum{
+	TOKZ_IGNORE_NEXTLINE=0x1,
+	TOKZ_READ_COMMENTS=0x2,
+	TOKZ_PARSER_INDENT_MODE=0x04,
+	TOKZ_ERROR_TOLERANT=0x8,
+	TOKZ_READ_FROM_BUFFER=0x10,
+	TOKZ_DEFAULT_OPTION=0x20
+};
+
+
+enum{
+	E_TOKZ_UNEXPECTED_EOF=1,
+	E_TOKZ_UNEXPECTED_EOL,
+	E_TOKZ_EOL_EXPECTED,
+	E_TOKZ_INVALID_CHAR,
+	E_TOKZ_TOOBIG,
+	E_TOKZ_NUMFMT,
+	E_TOKZ_NUM_JUNK,
+	E_TOKZ_NOTINT,
+	E_TOKZ_RANGE,
+	E_TOKZ_MULTICHAR,
+	
+	E_TOKZ_TOKEN_LIMIT,
+	E_TOKZ_UNKNOWN_OPTION,
+	E_TOKZ_SYNTAX,
+	E_TOKZ_INVALID_ARGUMENT,
+	E_TOKZ_EOS_EXPECTED,
+	E_TOKZ_TOO_FEW_ARGS,
+	E_TOKZ_TOO_MANY_ARGS,
+	E_TOKZ_MAX_NEST,
+	E_TOKZ_IDENTIFIER_EXPECTED,
+	
+	E_TOKZ_LBRACE_EXPECTED
+};
+
+
+struct _ConfOpt;
+
+typedef struct _Tokenizer_FInfo{
+	FILE *file;
+	char *name;
+	int line;
+	int ungetc;
+	Token ungettok;
+} Tokenizer_FInfo;
+
+typedef struct _Tokenizer_Buffer{
+		char *data;
+		int len;
+		int pos;
+} Tokenizer_Buffer;
+	
+typedef struct _Tokenizer{
+	FILE *file;
+	char *name;
+	int line;
+	int ungetc;
+	Token ungettok;
+	
+	Tokenizer_Buffer buffer;
+
+	int flags;
+	const struct _ConfOpt **optstack;
+	int nest_lvl;
+	void *user_data;
+
+	int filestack_n;
+	Tokenizer_FInfo *filestack;
+	
+	char **includepaths;
+} Tokenizer;
+
+
+extern Tokenizer *tokz_open(const char *fname);
+extern Tokenizer *tokz_open_file(FILE *file, const char *fname);
+extern Tokenizer *tokz_prepare_buffer(char *buffer, int len);
+extern void tokz_close(Tokenizer *tokz);
+extern bool tokz_get_token(Tokenizer *tokz, Token *tok);
+extern void tokz_unget_token(Tokenizer *tokz, Token *tok);
+extern void tokz_warn_error(const Tokenizer *tokz, int line, int e);
+extern void tokz_warn(const Tokenizer *tokz, int line, const char *fmt, ...);
+
+extern bool tokz_pushf(Tokenizer *tokz, const char *fname);
+extern bool tokz_pushf_file(Tokenizer *tokz, FILE *file, const char *fname);
+extern bool tokz_popf(Tokenizer *tokz);
+
+extern void tokz_set_includepaths(Tokenizer *tokz, char **paths);
+
+#endif /* LIBTU_TOKENIZER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/types.h	Mon Feb 16 00:44:56 2004 +0100
@@ -0,0 +1,86 @@
+/*
+ * libtu/types.h
+ *
+ * Copyright (c) Tuomo Valkonen 1999-2002. 
+ *
+ * You may distribute and modify this library under the terms of either
+ * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
+ */
+
+#ifndef LIBTU_TYPES_H
+#define LIBTU_TYPES_H
+
+#include <sys/types.h>
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef NULL
+#define NULL ((void*)0)
+#endif
+
+#ifndef LIBTU_TYPEDEF_UXXX
+
+ /* All systems seem to define these whichever way they want to
+  * despite -D_*_SOURCE etc. so there is no easy way to know whether
+  * they can be typedef'd or not. Unless you want to go through using
+  * autoconf or similar methods. ==> Just stick to #define. :-(
+  */
+  
+#ifndef uchar
+#define uchar unsigned char
+#endif
+
+#ifndef ushort
+#define ushort unsigned short
+#endif
+
+#ifndef uint
+#define uint unsigned int
+#endif
+
+#ifndef ulong
+#define ulong unsigned long
+#endif
+
+#else /* LIBTU_TYPEDEF_UXXX */
+
+#ifndef uchar
+typedef unsigned char uchar;
+#endif
+
+#ifndef ushort
+typedef unsigned short ushort;
+#endif
+
+#ifndef uint
+typedef unsigned int uint;
+#endif
+
+#ifndef ulong
+typedef unsigned long ulong;
+#endif
+ 
+#endif /* LIBTU_TYPEDEF_UXXX */
+
+
+#ifndef LIBTU_TYPEDEF_BOOL
+
+#ifndef bool
+#define bool int
+#endif
+ 
+#else /* LIBTU_TYPEDEF_BOOL */
+
+#ifndef bool
+typedef int bool;
+#endif
+ 
+#endif /* LIBTU_TYPEDEF_BOOL */
+
+#endif /* LIBTU_TYPES_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/util.h	Mon Feb 16 00:44:56 2004 +0100
@@ -0,0 +1,27 @@
+/*
+ * libtu/util.h
+ *
+ * Copyright (c) Tuomo Valkonen 1999-2002. 
+ *
+ * You may distribute and modify this library under the terms of either
+ * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
+ */
+
+#ifndef LIBTU_UTIL_H
+#define LIBTU_UTIL_H
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "types.h"
+#include "optparser.h"
+
+extern void libtu_init(const char *argv0);
+extern void libtu_init_copt(int argc, char *const argv[],
+							const OptParserCommonInfo *cinfo);
+					   
+
+extern const char *prog_execname();
+
+#endif /* LIBTU_UTIL_H */

mercurial