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
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "config.h"
00038
00039 static char rcsid[] not_used =
00040 {"$Id: DAS.cc 16088 2007-03-28 21:42:19Z jimg $"
00041 };
00042
00043
00044 #include <stdio.h>
00045 #ifdef WIN32
00046 #include <io.h>
00047 #else
00048 #include <unistd.h>
00049 #endif
00050
00051 #include <iostream>
00052 #include <string>
00053
00054 #include "DAS.h"
00055 #include "Error.h"
00056 #include "InternalErr.h"
00057 #include "parser.h"
00058 #include "escaping.h"
00059 #include "debug.h"
00060
00061 using std::cerr;
00062 using std::endl;
00063
00064
00065 extern void das_switch_to_buffer(void *new_buffer);
00066 extern void das_delete_buffer(void * buffer);
00067 extern void *das_buffer(FILE *fp);
00068
00069 extern void dasrestart(FILE *yyin);
00070 extern int dasparse(void *arg);
00071
00072 AttrTable *
00073 DAS::das_find(string name)
00074 {
00075 return find_container(name);
00076 }
00077
00091 DAS::DAS(AttrTable *, unsigned int)
00092 {}
00093
00102 DAS::DAS(AttrTable *attr, string name)
00103 {
00104 append_container(attr, www2id(name));
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114 DAS::~DAS()
00115 {}
00116
00117 AttrTable::Attr_iter
00118 DAS::var_begin()
00119 {
00120 return AttrTable::attr_begin() ;
00121 }
00122
00123 AttrTable::Attr_iter
00124 DAS::var_end()
00125 {
00126 return AttrTable::attr_end() ;
00127 }
00128
00129
00130 string
00131 DAS::get_name(Attr_iter &i)
00132 {
00133 return AttrTable::get_name(i);
00134 }
00135
00137 AttrTable *
00138 DAS::get_table(Attr_iter &i)
00139 {
00140 return AttrTable::get_attr_table(i);
00141 }
00142
00145 AttrTable *
00146 DAS::get_table(const string &name)
00147 {
00148 return AttrTable::get_attr_table(name);
00149 }
00150
00152
00157
00159 AttrTable *
00160 DAS::add_table(const string &name, AttrTable *at)
00161 {
00162 DBG(cerr << "Adding table: " << name << "(" << at << ")" << endl);
00163 return AttrTable::append_container(at, name);
00164 }
00165
00167
00173
00174
00179 void
00180 DAS::parse(string fname)
00181 {
00182 FILE *in = fopen(fname.c_str(), "r");
00183
00184 if (!in) {
00185 throw Error(can_not_read_file, "Could not open: " + fname);
00186 }
00187
00188 parse(in);
00189
00190 int res = fclose(in);
00191 if (res) {
00192 DBG(cerr << "DAS::parse - Failed to close file " << (void *)in << endl ;) ;
00193 }
00194 }
00195
00206 void
00207 DAS::parse(int fd)
00208 {
00209 #ifdef WIN32
00210 FILE *in = fdopen(_dup(fd), "r");
00211 #else
00212 FILE *in = fdopen(dup(fd), "r");
00213 #endif
00214
00215 if (!in) {
00216 throw InternalErr(__FILE__, __LINE__, "Could not access file.");
00217 }
00218
00219 parse(in);
00220
00221 int res = fclose(in);
00222 if (res) {
00223 DBG(cerr << "DAS::parse(fd) - Failed to close " << (void *)in << endl ;) ;
00224 }
00225 }
00226
00227
00228
00235 void
00236 DAS::parse(FILE *in)
00237 {
00238 if (!in) {
00239 throw InternalErr(__FILE__, __LINE__, "Null input stream.");
00240 }
00241
00242 void *buffer = das_buffer(in);
00243 das_switch_to_buffer(buffer);
00244
00245 parser_arg arg(this);
00246
00247 bool status = dasparse((void *) & arg) == 0;
00248
00249 das_delete_buffer(buffer);
00250
00251
00252
00253 if (!status || !arg.status()) {
00254 if (arg.error())
00255 throw *arg.error();
00256 }
00257 }
00258
00260
00273 void
00274 DAS::print(FILE *out, bool dereference)
00275 {
00276 fprintf(out, "Attributes {\n") ;
00277
00278 AttrTable::print(out, " ", dereference);
00279
00280 fprintf(out, "}\n") ;
00281 }
00282
00290 void
00291 DAS::dump(ostream &strm) const
00292 {
00293 strm << DapIndent::LMarg << "DAS::dump - ("
00294 << (void *)this << ")" << endl ;
00295 DapIndent::Indent() ;
00296 AttrTable::dump(strm) ;
00297 DapIndent::UnIndent() ;
00298 }
00299