1 #ifndef ___CONFIG_H 2 #define ___CONFIG_H 3 4 #ident "$Id: config.h,v 4.5 2006/03/29 12:26:09 gert Exp $ Copyright (c) 1993 Gert Doering" 5 6 /* type definitions, prototypes, defines needed for configuration stuff 7 */ 8 9 #ifdef PTR_IS_LONG 10 typedef long p_int; /* a "long" is the same size as an "char *" */ 11 #else 12 typedef int p_int; /* an "int" is the same size as an "char *" */ 13 #endif 14 15 typedef struct conf_data { 16 char * key; 17 union { p_int i; void * p; } d; 18 enum { CT_INT, CT_STRING, CT_CHAT, CT_BOOL, 19 CT_FLOWL, CT_ACTION, CT_KEYWORD } type; 20 enum { C_EMPTY, C_PRESET, C_OVERRIDE, C_CONF, 21 C_IGNORE } flags; 22 } conf_data; 23 24 int get_config _PROTO(( char * conf_file, conf_data * cd, 25 char * section_key, char * key_value )); 26 27 void display_cd _PROTO(( conf_data * cd )); 28 29 char * fgetline _PROTO(( FILE * fp )); 30 void norm_line _PROTO(( char ** line, char ** key )); 31 void * conf_get_chat _PROTO(( char * line )); 32 33 #ifndef ERROR 34 #define ERROR -1 35 #define NOERROR 0 36 #endif 37 38 39 /* macros for effecient initializing of "conf_data" values */ 40 41 #define conf_set_string( cp, s ) { (cp)->d.p = (s); (cp)->flags = C_OVERRIDE; } 42 #define conf_set_bool( cp, b ) { (cp)->d.i = (b); (cp)->flags = C_OVERRIDE; } 43 #define conf_set_int( cp, n ) { (cp)->d.i = (n); (cp)->flags = C_OVERRIDE; } 44 45 /* macros for implementation-indepentent access */ 46 #define c_isset( cp ) ( c.cp.flags != C_EMPTY ) 47 #define c_string( cp ) ((char *) c.cp.d.p) 48 #define c_bool( cp ) ((boolean) c.cp.d.i) 49 #define c_int( cp ) ((int) c.cp.d.i) 50 #define c_chat( cp ) ((char **) c.cp.d.p) 51 52 /* concatenate two paths (if second path doesn't start with "/") */ 53 /* two variants: ANSI w/ macro, K&R w/ C subroutine in config.c */ 54 #ifdef __STDC__ 55 #define makepath( file, base ) ((file)[0] == '/'? (file) : (base"/"file)) 56 #else 57 #define makepath( file, base ) _makepath( file, base ) 58 #endif 59 extern char * _makepath _PROTO(( char * file, char * base )); 60 61 #endif /* ___CONFIG_H */ 62