# HG changeset patch # User tuomov # Date 1076888696 -3600 # Node ID 789df543d0c308aa22da095c0e7bde19b0c03f3f # Parent de75d868bc0bf312b58f21b1eaf70fc1a03d88a4 trunk: changeset 1303 Moved header files to top level directory. diff -r de75d868bc0b -r 789df543d0c3 Makefile --- 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 diff -r de75d868bc0b -r 789df543d0c3 dlist.h --- /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 */ diff -r de75d868bc0b -r 789df543d0c3 include/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 */ diff -r de75d868bc0b -r 789df543d0c3 include/libtu/map.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 */ diff -r de75d868bc0b -r 789df543d0c3 include/libtu/misc.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 -#include -#include -#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 */ diff -r de75d868bc0b -r 789df543d0c3 include/libtu/optparser.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 */ diff -r de75d868bc0b -r 789df543d0c3 include/libtu/output.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 - -#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 */ diff -r de75d868bc0b -r 789df543d0c3 include/libtu/parser.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 */ diff -r de75d868bc0b -r 789df543d0c3 include/libtu/tokenizer.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 -#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 */ diff -r de75d868bc0b -r 789df543d0c3 include/libtu/types.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 - -#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 */ diff -r de75d868bc0b -r 789df543d0c3 include/libtu/util.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 -#include -#include - -#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 */ diff -r de75d868bc0b -r 789df543d0c3 map.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 */ diff -r de75d868bc0b -r 789df543d0c3 misc.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 +#include +#include +#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 */ diff -r de75d868bc0b -r 789df543d0c3 optparser.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 */ diff -r de75d868bc0b -r 789df543d0c3 output.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 + +#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 */ diff -r de75d868bc0b -r 789df543d0c3 parser.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 */ diff -r de75d868bc0b -r 789df543d0c3 tokenizer.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 +#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 */ diff -r de75d868bc0b -r 789df543d0c3 types.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 + +#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 */ diff -r de75d868bc0b -r 789df543d0c3 util.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 +#include +#include + +#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 */