Main Page Class Hierarchy Compound List File List Compound Members Related Pages

# ipv2.h

    00001 //
    00002 // ipv2.h
    00003 //
    00004 // Copyright (C) 1996 Limit Point Systems, Inc.
    00005 //
    00006 // Author: Curtis Janssen <cljanss@limitpt.com>
    00007 // Maintainer: LPS
    00008 //
    00009 // This file is part of the SC Toolkit.
    00010 //
    00011 // The SC Toolkit is free software; you can redistribute it and/or modify
    00012 // it under the terms of the GNU Library General Public License as published by
    00013 // the Free Software Foundation; either version 2, or (at your option)
    00014 // any later version.
    00015 //
    00016 // The SC Toolkit is distributed in the hope that it will be useful,
    00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00019 // GNU Library General Public License for more details.
    00020 //
    00021 // You should have received a copy of the GNU Library General Public License
    00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
    00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
    00024 //
    00025 // The U.S. Government is granted a limited license as per AL 91-7.
    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 // For temporary data (only used while parsing)
    00045 /* This integer list is used to keep track of the karray index. */
    00046 struct intlist_struct {
    00047   int i;
    00048   struct intlist_struct *p;
    00049   };
    00050 typedef struct intlist_struct intlist_t;
    00051
    00052 // For permanent data
    00053 struct ip_keyword_tree_struct {
    00054   char *keyword;
    00055   char *classname;
    00056   char *truename;
    00057   struct ip_keyword_tree_struct *across; /* Circular list. */
    00058   struct ip_keyword_tree_struct *up;    /* Terminated by NULL. */
    00059   struct ip_keyword_tree_struct *down;  /* Terminated by NULL. */
    00060   char *variable;  /* If this node points to another name, this
    00061                     * is the name, otherwise NULL. */
    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          ,  /* No problem. */
    00085       KeyNotFound=1 ,  /* The keyword was not found. */
    00086       OutOfBounds=2 ,  /* An array subscript was out of bounds. */
    00087       Malloc=3      ,  /* Memory allocation failed. */
    00088       NotAnArray=4  ,  /* Gave index for data which isn't an array */
    00089       NotAScalar=5  ,  /* Didn't give index for data which is an array */
    00090       Type=6        ,  /* The datum is not of the appropiate type. */
    00091       HasNoValue=7  ,  /* The keyword has no value. */
    00092       ValNotExpd=8     /* A value was not expected for the keyword. */
    00093       };
    00094   enum { KEYWORD_LENGTH=256 };
    00095
    00096  private:
    00097   char *filename_;
    00098
    00099   // These are needed only when the input is being read in:
    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   // this maintains a list of current working keyword lists (for cwk_push
    00110   // and cwk_pop)
    00111   ip_cwk_stack_t *cwkstack;
    00112
    00113   // This keeps track of whether or not we've been initialized
    00114   int ip_initialized;
    00115
    00116   // This is used for error processing
    00117   char lastkeyword[KEYWORD_LENGTH];
    00118
    00119   // These are needed always:
    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   // private routines mainly used for parsing the input
    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   // calls either ip_append or ip_initialize based on ip_initialized
    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     // the character string produced by classname must not be delete[]'ed
    00204   IPV2::Status classname(const char*,const char**,int,...);
    00205   IPV2::Status classname_v(const char*,const char**,int,int*);
    00206     // the character string produced by truekeyword must not be delete[]'ed
    00207     // if there is no alias for the keyword the string pointer is set to
    00208     // null and if the keyword exists OK is returned
    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     // the character string produced by value must not be delete[]'ed
    00214     // or free'ed.
    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   // some routines for debugging
    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 // Local Variables:
    00234 // mode: c++
    00235 // c-file-style: "CLJ"
    00236 // End: