Diff for /parser3/src/classes/table.C between versions 1.22 and 1.29

version 1.22, 2001/03/20 07:34:30 version 1.29, 2001/03/26 09:53:42
Line 8 Line 8
         $Id$          $Id$
 */  */
   
 #include <string.h>  #include "pa_config_includes.h"
 #include "pa_common.h"  #include "pa_common.h"
 #include "pa_request.h"  #include "pa_request.h"
 #include "_table.h"  #include "_table.h"
Line 35  static void set_or_load( Line 35  static void set_or_load(
                 method_name, is_load?"file name must not be junction":"body must be junction");                  method_name, is_load?"file name must not be junction":"body must be junction");
   
         // data or file_name          // data or file_name
         char *ldata_or_filename;          char *data;
         if(is_load) {          if(is_load) {
                 // forcing untaint language                  // forcing untaint language
                 String lfile_name(pool);                  String lfile_name(pool);
                 lfile_name.append(vdata_or_filename->as_string(),                  lfile_name.append(vdata_or_filename->as_string(), String::UL_FILE_NAME, true);
                         String::Untaint_lang::FILE_NAME, true);                  // loading text
                 ldata_or_filename=lfile_name.cstr();                  data=file_read_text(pool, r.absolute(lfile_name));
         } else {          } else {
                 // suggesting untaint language                  // suggesting untaint language
                 Temp_lang temp_lang(r, String::Untaint_lang::TABLE);                  Temp_lang temp_lang(r, String::UL_TABLE);
                 ldata_or_filename=r.process(*vdata_or_filename).as_string().cstr();                  data=r.process(*vdata_or_filename).as_string().cstr();
         }          }
         // data  
         char *data=is_load?  
                 file_read_text(pool, r.absolute(ldata_or_filename)/*\, false*/):ldata_or_filename;  
   
         // parse columns          // parse columns
         Array *columns;          Array *columns;
Line 72  static void set_or_load( Line 69  static void set_or_load(
         }          }
   
         // parse cells          // parse cells
         Table& table=*new(pool) Table(pool, method_name, columns);          Table& table=*new(pool) Table(pool, &method_name, columns);
         char *row_chars;          char *row_chars;
         while(row_chars=getrow(&data)) {          while(row_chars=getrow(&data)) {
                   if(!*row_chars) // remove empty lines
                           continue;
                 Array *row=new(pool) Array(pool);                  Array *row=new(pool) Array(pool);
                 while(char *cell_chars=lsplit(&row_chars, '\t')) {                  while(char *cell_chars=lsplit(&row_chars, '\t')) {
                         String *cell=new(pool) String(pool);                          String *cell=new(pool) String(pool);
Line 109  static void _save(Request& r, const Stri Line 108  static void _save(Request& r, const Stri
         // forcing untaint language          // forcing untaint language
         String lfile_name(pool);          String lfile_name(pool);
         lfile_name.append(vfile_name->as_string(),          lfile_name.append(vfile_name->as_string(),
                 String::Untaint_lang::FILE_NAME, true);                  String::UL_FILE_NAME, true);
   
         Table& table=static_cast<VTable *>(r.self)->table();          Table& table=static_cast<VTable *>(r.self)->table();
   
Line 121  static void _save(Request& r, const Stri Line 120  static void _save(Request& r, const Stri
                                 if(column)                                  if(column)
                                         sdata.APPEND_CONST("\t");                                          sdata.APPEND_CONST("\t");
                                 sdata.append(*static_cast<String *>(columns->quick_get(column)),                                   sdata.append(*static_cast<String *>(columns->quick_get(column)), 
                                         String::Untaint_lang::TABLE);                                          String::UL_TABLE);
                         }                          }
                 } else { // nameless table                  } else { // nameless table
                         int size=table.size()?static_cast<Array *>(table.get(0))->size():0;                          int size=table.size()?static_cast<Array *>(table.get(0))->size():0;
Line 143  static void _save(Request& r, const Stri Line 142  static void _save(Request& r, const Stri
                         if(column)                          if(column)
                                 sdata.APPEND_CONST("\t");                                  sdata.APPEND_CONST("\t");
                         sdata.append(*static_cast<String *>(row->quick_get(column)),                           sdata.append(*static_cast<String *>(row->quick_get(column)), 
                                 String::Untaint_lang::TABLE);                                  String::UL_TABLE);
                 }                  }
                 sdata.APPEND_CONST("\n");                  sdata.APPEND_CONST("\n");
         }          }
   
         // write          // write
         char *cdata=sdata.cstr();          char *cdata=sdata.cstr();
         file_write(pool, r.absolute(lfile_name.cstr()), cdata, strlen(cdata), true, true);          file_write(pool, r.absolute(lfile_name), cdata, strlen(cdata), true);
 }  }
   
 static void _count(Request& r, const String&, Array *) {  static void _count(Request& r, const String&, Array *) {
Line 215  static void _empty(Request& r, const Str Line 214  static void _empty(Request& r, const Str
         }          }
 }  }
   
   struct Record_info {
           Pool *pool;
           Table *table;
           Hash *hash;
   };
   static void store_column_item_to_hash(Array::Item *item, void *info) {
           Record_info& ri=*static_cast<Record_info *>(info);
           String& column_name=*static_cast<String *>(item);
           const String *column_item=ri.table->item(column_name);
           Value *value;
           if(column_item)
                   value=new(*ri.pool) VString(*column_item);
           else
                   value=new(*ri.pool) VUnknown(*ri.pool);
           ri.hash->put(column_name, value);
   }
   static void _record(Request& r, const String&, Array *params) {
           Table& table=static_cast<VTable *>(r.self)->table();
           if(const Array *columns=table.columns()) {
                   Pool& pool=r.pool();
                   Value& value=*new(pool) VHash(pool);
                   Record_info record_info={&pool, &table, value.get_hash()};
                   columns->for_each(store_column_item_to_hash, &record_info);
                   
                   r.write_no_lang(value);
           }
   }
   
 // initialize  // initialize
   
 void initialize_table_class(Pool& pool, VStateless_class& vclass) {  void initialize_table_class(Pool& pool, VStateless_class& vclass) {
Line 248  void initialize_table_class(Pool& pool, Line 275  void initialize_table_class(Pool& pool,
         // ^table.empty{code-when-empty}{code-when-not}          // ^table.empty{code-when-empty}{code-when-not}
         vclass.add_native_method("empty", _empty, 1, 2);          vclass.add_native_method("empty", _empty, 1, 2);
   
           // ^table.record[]
           vclass.add_native_method("record", _record, 0, 0);
   
 }         }       

Removed from v.1.22  
changed lines
  Added in v.1.29


E-mail: