Diff for /parser3/src/main/pa_common.C between versions 1.17 and 1.19.2.4

version 1.17, 2001/03/19 17:56:27 version 1.19.2.4, 2001/03/20 18:55:43
Line 18 Line 18
 #include <io.h>  #include <io.h>
 #include <stdio.h>  #include <stdio.h>
 #include <string.h>  #include <string.h>
   #include <errno.h>
   
   #ifdef WIN32
   #else
   #       include <unistd.h>
   #endif
   
 #include "pa_common.h"  #include "pa_common.h"
 #include "pa_types.h"  #include "pa_types.h"
Line 45  int __snprintf(char *b, size_t s, const Line 51  int __snprintf(char *b, size_t s, const
   
 #endif  #endif
   
 char *file_read(Pool& pool, const char *fname, bool fail_on_read_problem) {  
   char *file_read_text(Pool& pool, const char *fname, bool fail_on_read_problem) {
     int f;      int f;
     struct stat finfo;      struct stat finfo;
     if(fname && !stat(fname,&finfo) &&(f=open(fname,O_RDONLY      if(fname && !stat(fname,&finfo) &&(f=open(fname,O_RDONLY
Line 72  char *file_read(Pool& pool, const char * Line 79  char *file_read(Pool& pool, const char *
     return 0;      return 0;
 }  }
   
   void file_write(Pool& pool, 
                                   const char *fname, 
                                   const char *data, size_t size, 
                                   bool as_text/*,
                                   bool exclusive*/) {
           if(fname) {
                   int f;
                   if(access(fname, F_OK)!=0) {/*no*/
                           if((f=open(fname,O_WRONLY|O_CREAT|_O_BINARY,0666))>0)
                                   close(f);
                   }
                   if(access(fname, R_OK|W_OK)==0) {
                           int mode=O_RDWR
   #ifdef WIN32
                                   |O_TRUNC
   #endif
                           ;
                           mode|=as_text?_O_TEXT:_O_BINARY;
                           if((f=open(fname,mode,0666))>=0) {
                                   /*if(exclusive)
                                           flock(f, LOCK_EX);*/
                                   
                                   if(size) write(f,data,size);
   #ifndef WIN32
                                   ftruncate(f,size);
   #endif
                                   /*if(exclusive)
                                           flock(f, LOCK_UN);*/
                                   close(f);
                                   return;
                           }
                   }
           }
           if(fname)
                   PTHROW(0, 0,
                           0,
                           "file_write('%s'): %s (#%d)", 
                                   fname, strerror(errno), errno);
           else
                   PTHROW(0, 0,
                           0,
                           "file_write: no filename specified");
   }
   
 char *getrow(char **row_ref, char delim) {  char *getrow(char **row_ref, char delim) {
     char *result=*row_ref;      char *result=*row_ref;
     if(result) {      if(result) {
Line 103  char *lsplit(char **string_ref, char del Line 154  char *lsplit(char **string_ref, char del
 }  }
   
 char *rsplit(char *string, char delim) {  char *rsplit(char *string, char delim) {
     if(string){      if(string) {
                 char *v=strrchr(string, delim);                  char *v=strrchr(string, delim);
                 if (v){                  if(v) {
                         *v=0;                          *v=0;
                         return v+1;                          return v+1;
                 }                  }
Line 118  char *format(Pool& pool, double value, c Line 169  char *format(Pool& pool, double value, c
         if(fmt)          if(fmt)
                 if(strpbrk(fmt, "diouxX"))                  if(strpbrk(fmt, "diouxX"))
                         if(strpbrk(fmt, "ouxX"))                          if(strpbrk(fmt, "ouxX"))
                                 snprintf(result, MAX_NUMBER, fmt, (uint)value );                                  snprintf(result, MAX_NUMBER, fmt,(uint)value );
                         else                          else
                                 snprintf(result, MAX_NUMBER, fmt, (int)value );                                  snprintf(result, MAX_NUMBER, fmt,(int)value );
                 else                  else
                         snprintf(result, MAX_NUMBER, fmt, value);                          snprintf(result, MAX_NUMBER, fmt, value);
         else          else
                 snprintf(result, MAX_NUMBER, "%d", (int)value);                  snprintf(result, MAX_NUMBER, "%d",(int)value);
                   
         return result;          return result;
 }  }
Line 191  static void append_attribute_subattribut Line 242  static void append_attribute_subattribut
         // ...; charset=windows1251          // ...; charset=windows1251
         String *string=static_cast<String *>(info);          String *string=static_cast<String *>(info);
         string->APPEND_CONST("; ");          string->APPEND_CONST("; ");
         string->append(akey, String::Untaint_lang::HEADER, true);          string->append(akey, String::UL_HEADER, true);
         string->APPEND_CONST("=");          string->APPEND_CONST("=");
         string->append(static_cast<Value *>(avalue)->as_string(),           string->append(static_cast<Value *>(avalue)->as_string(), 
                 String::Untaint_lang::HEADER, true);                  String::UL_HEADER, true);
 }  }
 const String& attributed_meaning_string(Value *meaning) {  const String& attributed_meaning_string(Value *meaning) {
         String &result=*new(meaning->pool()) String(meaning->pool());          String &result=*new(meaning->pool()) String(meaning->pool());
         if(Hash *hash=meaning->get_hash()) {          if(Hash *hash=meaning->get_hash()) {
                 // $value(value) $subattribute(subattribute value)                  // $value(value) $subattribute(subattribute value)
                 if(Value *value=static_cast<Value *>(hash->get(*value_name)))                  if(Value *value=static_cast<Value *>(hash->get(*value_name)))
                         result.append(value->as_string(), String::Untaint_lang::HEADER, true);                          result.append(value->as_string(), String::UL_HEADER, true);
   
                 hash->foreach(append_attribute_subattribute, &result);                  hash->foreach(append_attribute_subattribute, &result);
         } else // result value          } else // result value
                 result.append(meaning->as_string(), String::Untaint_lang::HEADER, true);                  result.append(meaning->as_string(), String::UL_HEADER, true);
   
         return result;          return result;
 }  }
   

Removed from v.1.17  
changed lines
  Added in v.1.19.2.4


E-mail: