--- parser3/src/classes/table.C 2009/05/14 08:10:09 1.256 +++ parser3/src/classes/table.C 2009/06/14 00:33:36 1.258 @@ -5,9 +5,9 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_TABLE_C="$Date: 2009/05/14 08:10:09 $"; +static const char * const IDENT_TABLE_C="$Date: 2009/06/14 00:33:36 $"; -#ifndef NO_STRINGSTREAM +#if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4)) #include using namespace std; #endif @@ -26,7 +26,7 @@ using namespace std; class MTable: public Methoded { public: // VStateless_class - Value* create_new_value(Pool&, HashStringValue&) { return new VTable(); } + Value* create_new_value(Pool&, HashStringValue*) { return new VTable(); } public: MTable(); @@ -389,51 +389,51 @@ static void _load(Request& r, MethodPara GET_SELF(r, VTable).set_table(table); } -#ifdef NO_STRINGSTREAM +#if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4)) -void maybe_enclose( String& to, const String& from, char encloser, const String* sencloser ) { +void maybe_enclose( ostringstream& to, const String& from, char encloser ) { if(encloser) { - to<<*sencloser; + to< i(*table.columns()); i.has_next(); ) { - maybe_enclose( sdata, *i.next(), separators.encloser, separators.sencloser ); - if(i.has_next()) - sdata<<*separators.scolumn; - } - } else { // nameless table [we were asked to output column names] - if(int lsize=table.count()?table[0]->count():0) - for(int column=0; column i(table); - while(i.has_next()) { - for(Array_iterator c(*i.next()); c.has_next(); ) { - maybe_enclose( sdata, *c.next(), separators.encloser, separators.sencloser ); - if(c.has_next()) - sdata<<*separators.scolumn; - } - sdata.append_know_length("\n", 1, String::L_CLEAN); - } - - // write - { - const char* data_cstr=sdata.cstr(); - file_write(file_spec, - data_cstr, sdata.length(), true, do_append); - if(*data_cstr) // not empty (when empty it's not heap memory) - pa_free((void*)data_cstr); // not needed anymore - } - -#else +#if (!defined(NO_STRINGSTREAM) && !defined(FREEBSD4)) ostringstream ost(stringstream::out); @@ -575,7 +530,52 @@ static void _save(Request& r, MethodPara file_write(file_spec, data_cstr, data.length(), true /* as text */, do_append); } -#endif +#else + + String sdata; + if(output_column_names) { + if(table.columns()) { // named table + for(Array_iterator i(*table.columns()); i.has_next(); ) { + maybe_enclose( sdata, *i.next(), separators.encloser, separators.sencloser ); + if(i.has_next()) + sdata<<*separators.scolumn; + } + } else { // nameless table [we were asked to output column names] + if(int lsize=table.count()?table[0]->count():0) + for(int column=0; column i(table); + while(i.has_next()) { + for(Array_iterator c(*i.next()); c.has_next(); ) { + maybe_enclose( sdata, *c.next(), separators.encloser, separators.sencloser ); + if(c.has_next()) + sdata<<*separators.scolumn; + } + sdata.append_know_length("\n", 1, String::L_CLEAN); + } + + // write + { + const char* data_cstr=sdata.cstr(); + file_write(file_spec, + data_cstr, sdata.length(), true, do_append); + if(*data_cstr) // not empty (when empty it's not heap memory) + pa_free((void*)data_cstr); // not needed anymore + } + +#endif // don't use stringstream } static void _count(Request& r, MethodParams&) {