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