MPQC  3.0.0-alpha
ipv2.h
1 //
2 // ipv2.h
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Curtis Janssen <cljanss@limitpt.com>
7 // Maintainer: LPS
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _util_keyval_ipv2_ipv2_h
29 #define _util_keyval_ipv2_ipv2_h
30 
31 #include <iostream>
32 #include <util/misc/exenv.h>
33 #include <util/keyval/ipv2_scan.h>
34 
35 #undef yyFlexLexer
36 #define yyFlexLexer IPV2FlexLexer
37 #include <FlexLexer.h>
38 
39 namespace sc {
40 
41 // For temporary data (only used while parsing)
42 /* This integer list is used to keep track of the karray index. */
44  int i;
45  struct intlist_struct *p;
46  };
47 typedef struct intlist_struct intlist_t;
48 
49 // For permanent data
51  char *keyword;
52  char *classname;
53  char *truename;
54  struct ip_keyword_tree_struct *across; /* Circular list. */
55  struct ip_keyword_tree_struct *up; /* Terminated by NULL. */
56  struct ip_keyword_tree_struct *down; /* Terminated by NULL. */
57  char *variable; /* If this node points to another name, this
58  * is the name, otherwise NULL. */
59  char *value;
60  int seen;
61  };
62 
64  struct ip_keyword_tree_struct *kt;
66  };
67 
69  struct ip_keyword_tree_list_struct *ktl;
70  struct ip_cwk_stack_struct *p;
71  };
72 typedef struct ip_cwk_stack_struct ip_cwk_stack_t;
73 
76 
77 class IPV2
78 {
79  public:
80  enum Status {
81  OK=0 , /* No problem. */
82  KeyNotFound=1 , /* The keyword was not found. */
83  OutOfBounds=2 , /* An array subscript was out of bounds. */
84  Malloc=3 , /* Memory allocation failed. */
85  NotAnArray=4 , /* Gave index for data which isn't an array */
86  NotAScalar=5 , /* Didn't give index for data which is an array */
87  Type=6 , /* The datum is not of the appropiate type. */
88  HasNoValue=7 , /* The keyword has no value. */
89  ValNotExpd=8 /* A value was not expected for the keyword. */
90  };
91  enum { KEYWORD_LENGTH=256 };
92 
93  private:
94  char *filename_;
95 
96  // These are needed only when the input is being read in:
97  ip_string_list_t* table_keywords;
98  ip_string_list_t* current_table_keyword;
99  ip_keyword_tree_t* table_sub_tree;
100  int table_row_number;
101  int table_array_depth;
102  intlist_t *karray_indices;
103  ip_keyword_tree_t *sub_tree;
104  int init_karray;
105 
106  // this maintains a list of current working keyword lists (for cwk_push
107  // and cwk_pop)
108  ip_cwk_stack_t *cwkstack;
109 
110  // This keeps track of whether or not we've been initialized
111  int ip_initialized;
112 
113  // This is used for error processing
114  char lastkeyword[KEYWORD_LENGTH];
115 
116  // These are needed always:
117  std::istream* ip_in;
118  std::ostream* ip_out;
119  ip_keyword_tree_t* ip_tree;
120  ip_keyword_tree_list_t* ip_cwk;
121  int ip_keyword;
122 
123  // private routines mainly used for parsing the input
124  void ip_push_table_col(char*);
125  void ip_next_table_entry();
126  char* dup_string(const char*);
127  ip_keyword_tree_t* ip_get_variable_kt(char*);
128  char* ip_get_variable_value(char*);
129  void ip_internal_values();
130  void ip_push_keyword(char*);
131  void ip_push_keyclass(char*,char*,ip_string_list_t*);
132  void ip_pop_keyword();
133  void ip_begin_table(ip_string_list_t*);
134  void ip_done_table();
135  ip_string_list_t* ip_add_string_list(ip_string_list_t*,char*);
136  ip_string_list_t* ip_string_to_string_list(char*);
137  void ip_assign_variable(char*);
138  double ip_get_variable_double(char*);
139  char* ip_double_to_string(double);
140  void ip_assign_value(char*value);
141  void ip_start_karray();
142  void ip_init_karray();
143  void ip_incr_karray();
144  void ip_lastkeyword(const char*);
145  void ip_lastkeywordtree(ip_keyword_tree_t*);
146  void ip_lastkeyword_(ip_keyword_tree_t*);
147  ip_keyword_tree_t* ip_alloc_keyword_tree();
148  void ip_free_keyword_tree(ip_keyword_tree_t*);
149  void ip_cwk_add_kt(ip_keyword_tree_t*);
150  ip_keyword_tree_t* ip_cwk_descend_tree(const char*);
151  ip_keyword_tree_t* ip_descend_tree(ip_keyword_tree_t*,const char*);
152  char* ip_key_value(const char*);
153  void free_keyword_tree_list(ip_keyword_tree_list_t*);
154  ip_keyword_tree_list_t* splice_keyword_tree_list(ip_keyword_tree_t*,
156  void ip_cwk_karray_add_v(int,int*);
157  void ip_cwk_karray_add(int,...);
158  ip_keyword_tree_t* ip_karray_descend_v(ip_keyword_tree_t*,int,int*);
159  ip_keyword_tree_t* ip_karray_descend(ip_keyword_tree_t*,int,...);
160  void print_tree_(std::ostream&,ip_keyword_tree_t*);
161  int ip_special_characters(char*);
162  char* ip_append_keystrings(char*,char*);
163  void ip_pop_karray();
164  void ip_initialize(std::istream&,std::ostream&);
165  void ip_append(std::istream&,std::ostream&);
166  char* get_truename(ip_keyword_tree_t*kt);
167 
168  void showpos();
169 
170  IPV2FlexLexer *lexer;
171 
172  int ylex() { return lexer->yylex(); }
173  int yparse();
174  void yerror(const char* s);
175 
176  public:
177  IPV2();
178  virtual ~IPV2();
179  static int have_global();
180  static void set_global(IPV2*);
181  static IPV2* global();
182  // calls either ip_append or ip_initialize based on ip_initialized
183  void read(std::istream&,std::ostream&,const char *filename=0);
184  void append_from_input(const char*,std::ostream&);
185  void done();
186  const char* error_message(IPV2::Status);
187  void error(const char*);
188  void warn(const char*);
189  void cwk_root();
190  void cwk_clear();
191  void cwk_add(const char*);
192  void cwk_push();
193  void cwk_pop();
194  IPV2::Status boolean(const char*,int*,int,...);
195  IPV2::Status boolean_v(const char*,int*,int,int*);
196  int exist(const char*,int,...);
197  int exist_v(const char*,int,int*);
198  IPV2::Status data(const char*,const char*,void*,int,...);
199  IPV2::Status data_v(const char*,const char*,void*,int,int*);
200  // the character string produced by classname must not be delete[]'ed
201  IPV2::Status classname(const char*,const char**,int,...);
202  IPV2::Status classname_v(const char*,const char**,int,int*);
203  // the character string produced by truekeyword must not be delete[]'ed
204  // if there is no alias for the keyword the string pointer is set to
205  // null and if the keyword exists OK is returned
206  IPV2::Status truekeyword(const char*,const char**,int,...);
207  IPV2::Status truekeyword_v(const char*,const char**,int,int*);
208  IPV2::Status string(const char*,char**,int,...);
209  IPV2::Status string_v(const char*,char**,int,int*);
210  // the character string produced by value must not be delete[]'ed
211  // or free'ed.
212  IPV2::Status value(const char*,const char**,int,...);
213  IPV2::Status value_v(const char*,const char**,int,int*);
214 
215  IPV2::Status construct_key_v(const char*,char*,int,int*);
216  IPV2::Status count(const char*,int*,int,...);
217  IPV2::Status count_v(const char*,int*,int,int*);
218 
219  // some routines for debugging
220  void print_keyword(std::ostream&f=ExEnv::out0(),ip_keyword_tree_t*k=0);
221  void print_tree(std::ostream&f=ExEnv::out0(),ip_keyword_tree_t*k=0);
222  void print_unseen(std::ostream&f=ExEnv::out0(),ip_keyword_tree_t*k=0);
223  int have_unseen(ip_keyword_tree_t*k=0);
224 };
225 
226 }
227 
228 #endif
229 
230 // Local Variables:
231 // mode: c++
232 // c-file-style: "CLJ"
233 // End:
sc::ip_keyword_tree_list_struct
Definition: ipv2.h:63
sc::intlist_struct
Definition: ipv2.h:43
sc::ip_keyword_tree_struct
Definition: ipv2.h:50
sc::ip_string_list_struct
Definition: ipv2_scan.h:33
sc::ip_cwk_stack_struct
Definition: ipv2.h:68
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::IPV2
Definition: ipv2.h:77
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.