00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _util_keyval_ipv2_ipv2_h
00029 #define _util_keyval_ipv2_ipv2_h
00030 #ifdef __GNUG__
00031 #pragma interface
00032 #endif
00033
00034 #include <iostream>
00035 #include <util/misc/exenv.h>
00036 #include <util/keyval/ipv2_scan.h>
00037
00038 #undef yyFlexLexer
00039 #define yyFlexLexer IPV2FlexLexer
00040 #include <FlexLexer.h>
00041
00042
00043
00044 struct intlist_struct {
00045 int i;
00046 struct intlist_struct *p;
00047 };
00048 typedef struct intlist_struct intlist_t;
00049
00050
00051 struct ip_keyword_tree_struct {
00052 char *keyword;
00053 char *classname;
00054 char *truename;
00055 struct ip_keyword_tree_struct *across;
00056 struct ip_keyword_tree_struct *up;
00057 struct ip_keyword_tree_struct *down;
00058 char *variable;
00059
00060 char *value;
00061 int seen;
00062 };
00063
00064 struct ip_keyword_tree_list_struct {
00065 struct ip_keyword_tree_struct *kt;
00066 struct ip_keyword_tree_list_struct *p;
00067 };
00068
00069 struct ip_cwk_stack_struct {
00070 struct ip_keyword_tree_list_struct *ktl;
00071 struct ip_cwk_stack_struct *p;
00072 };
00073 typedef struct ip_cwk_stack_struct ip_cwk_stack_t;
00074
00075 typedef struct ip_keyword_tree_struct ip_keyword_tree_t;
00076 typedef struct ip_keyword_tree_list_struct ip_keyword_tree_list_t;
00077
00078 class IPV2
00079 {
00080 public:
00081 enum Status {
00082 OK=0 ,
00083 KeyNotFound=1 ,
00084 OutOfBounds=2 ,
00085 Malloc=3 ,
00086 NotAnArray=4 ,
00087 NotAScalar=5 ,
00088 Type=6 ,
00089 HasNoValue=7 ,
00090 ValNotExpd=8
00091 };
00092 enum { KEYWORD_LENGTH=256 };
00093
00094 private:
00095 char *filename_;
00096
00097
00098 ip_string_list_t* table_keywords;
00099 ip_string_list_t* current_table_keyword;
00100 ip_keyword_tree_t* table_sub_tree;
00101 int table_row_number;
00102 int table_array_depth;
00103 intlist_t *karray_indices;
00104 ip_keyword_tree_t *sub_tree;
00105 int init_karray;
00106
00107
00108
00109 ip_cwk_stack_t *cwkstack;
00110
00111
00112 int ip_initialized;
00113
00114
00115 char lastkeyword[KEYWORD_LENGTH];
00116
00117
00118 std::istream* ip_in;
00119 std::ostream* ip_out;
00120 ip_keyword_tree_t* ip_tree;
00121 ip_keyword_tree_list_t* ip_cwk;
00122 int ip_keyword;
00123
00124
00125 void ip_push_table_col(char*);
00126 void ip_next_table_entry();
00127 char* dup_string(const char*);
00128 ip_keyword_tree_t* ip_get_variable_kt(char*);
00129 char* ip_get_variable_value(char*);
00130 void ip_internal_values();
00131 void ip_push_keyword(char*);
00132 void ip_push_keyclass(char*,char*,ip_string_list_t*);
00133 void ip_pop_keyword();
00134 void ip_begin_table(ip_string_list_t*);
00135 void ip_done_table();
00136 ip_string_list_t* ip_add_string_list(ip_string_list_t*,char*);
00137 ip_string_list_t* ip_string_to_string_list(char*);
00138 void ip_assign_variable(char*);
00139 double ip_get_variable_double(char*);
00140 char* ip_double_to_string(double);
00141 void ip_assign_value(char*value);
00142 void ip_start_karray();
00143 void ip_init_karray();
00144 void ip_incr_karray();
00145 void ip_lastkeyword(const char*);
00146 void ip_lastkeywordtree(ip_keyword_tree_t*);
00147 void ip_lastkeyword_(ip_keyword_tree_t*);
00148 ip_keyword_tree_t* ip_alloc_keyword_tree();
00149 void ip_free_keyword_tree(ip_keyword_tree_t*);
00150 void ip_cwk_add_kt(ip_keyword_tree_t*);
00151 ip_keyword_tree_t* ip_cwk_descend_tree(const char*);
00152 ip_keyword_tree_t* ip_descend_tree(ip_keyword_tree_t*,const char*);
00153 char* ip_key_value(const char*);
00154 void free_keyword_tree_list(ip_keyword_tree_list_t*);
00155 ip_keyword_tree_list_t* splice_keyword_tree_list(ip_keyword_tree_t*,
00156 ip_keyword_tree_list_t*);
00157 void ip_cwk_karray_add_v(int,int*);
00158 void ip_cwk_karray_add(int,...);
00159 ip_keyword_tree_t* ip_karray_descend_v(ip_keyword_tree_t*,int,int*);
00160 ip_keyword_tree_t* ip_karray_descend(ip_keyword_tree_t*,int,...);
00161 void print_tree_(std::ostream&,ip_keyword_tree_t*);
00162 int ip_special_characters(char*);
00163 char* ip_append_keystrings(char*,char*);
00164 void ip_pop_karray();
00165 void ip_initialize(std::istream&,std::ostream&);
00166 void ip_append(std::istream&,std::ostream&);
00167 char* get_truename(ip_keyword_tree_t*kt);
00168
00169 void showpos();
00170
00171 IPV2FlexLexer *lexer;
00172
00173 int ylex() { return lexer->yylex(); }
00174 int yparse();
00175 void yerror(const char* s);
00176
00177 public:
00178 IPV2();
00179 virtual ~IPV2();
00180 static int have_global();
00181 static void set_global(IPV2*);
00182 static IPV2* global();
00183
00184 void read(std::istream&,std::ostream&,const char *filename=0);
00185 void append_from_input(const char*,std::ostream&);
00186 void done();
00187 const char* error_message(IPV2::Status);
00188 void error(const char*);
00189 void warn(const char*);
00190 void cwk_root();
00191 void cwk_clear();
00192 void cwk_add(const char*);
00193 void cwk_push();
00194 void cwk_pop();
00195 IPV2::Status boolean(const char*,int*,int,...);
00196 IPV2::Status boolean_v(const char*,int*,int,int*);
00197 int exist(const char*,int,...);
00198 int exist_v(const char*,int,int*);
00199 IPV2::Status data(const char*,const char*,void*,int,...);
00200 IPV2::Status data_v(const char*,const char*,void*,int,int*);
00201
00202 IPV2::Status classname(const char*,const char**,int,...);
00203 IPV2::Status classname_v(const char*,const char**,int,int*);
00204
00205
00206
00207 IPV2::Status truekeyword(const char*,const char**,int,...);
00208 IPV2::Status truekeyword_v(const char*,const char**,int,int*);
00209 IPV2::Status string(const char*,char**,int,...);
00210 IPV2::Status string_v(const char*,char**,int,int*);
00211
00212
00213 IPV2::Status value(const char*,const char**,int,...);
00214 IPV2::Status value_v(const char*,const char**,int,int*);
00215
00216 IPV2::Status construct_key_v(const char*,char*,int,int*);
00217 IPV2::Status count(const char*,int*,int,...);
00218 IPV2::Status count_v(const char*,int*,int,int*);
00219
00220
00221 void print_keyword(std::ostream&f=ExEnv::out(),ip_keyword_tree_t*k=0);
00222 void print_tree(std::ostream&f=ExEnv::out(),ip_keyword_tree_t*k=0);
00223 void print_unseen(std::ostream&f=ExEnv::out(),ip_keyword_tree_t*k=0);
00224 int have_unseen(ip_keyword_tree_t*k=0);
00225 };
00226
00227 #endif
00228
00229
00230
00231
00232