Diff for /parser3/src/classes/math.C between versions 1.57 and 1.60

version 1.57, 2010/10/13 11:30:08 version 1.60, 2012/05/23 20:51:40
Line 1 Line 1
 /** @file  /** @file
         Parser: @b math parser class.          Parser: @b math parser class.
   
         Copyright(c) 2001-2005 ArtLebedev Group(http://www.artlebedev.com)          Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru>(http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru>(http://paf.design.ru)
   
         portions from gen_uuid.c,          portions from gen_uuid.c,
         Copyright (C) 1996, 1997, 1998, 1999 Theodore Ts'o.          Copyright (C) 1996, 1997, 1998, 1999 Theodore Ts'o.
 */  */
   
 static const char * const IDENT_MATH_C="$Date$";  
   
 #include "pa_vmethod_frame.h"  #include "pa_vmethod_frame.h"
 #include "pa_common.h"  #include "pa_common.h"
 #include "pa_vint.h"  #include "pa_vint.h"
Line 32  static const char * const IDENT_MATH_C=" Line 30  static const char * const IDENT_MATH_C="
         extern char *crypt(const char* , const char* );          extern char *crypt(const char* , const char* );
 #endif  #endif
   
   volatile const char * IDENT_MATH_C="$Id$";
   
 // defines  // defines
   
 #define MAX_SALT 8  #define MAX_SALT 8
Line 357  static void _crc32(Request& r, MethodPar Line 357  static void _crc32(Request& r, MethodPar
         r.write_no_lang(*new VInt(pa_crc32(string, strlen(string))));          r.write_no_lang(*new VInt(pa_crc32(string, strlen(string))));
 }  }
   
 static void toBase(long value, int base, char*& ptr){  static void toBase(unsigned long value, unsigned int base, char*& ptr){
         static const char* hex="0123456789ABCDEF";          static const char* hex="0123456789ABCDEF";
         int rest = value % base;          int rest = value % base;
         if(value > base)          if(value >= base)
                 toBase( (value-rest)/base, base, ptr);                  toBase( (value-rest)/base, base, ptr);
         *ptr++=(char)hex[rest];          *ptr++=(char)hex[rest];
 }  }
   
 static void _convert(Request& r, MethodParams& params) {  static void _convert(Request& r, MethodParams& params) {
         const char *string=params.as_string(0, PARAMETER_MUST_BE_STRING).cstr();          const char *str=params.as_string(0, PARAMETER_MUST_BE_STRING).cstr();
   
         int base_from=params.as_int(1, "base from must be integer", r);          int base_from=params.as_int(1, "base from must be integer", r);
         if(base_from < 2 || base_from > 16)          if(base_from < 2 || base_from > 16)
                 throw Exception(PARSER_RUNTIME, 0, "base from must be an integer from 2 to 16");                  throw Exception(PARSER_RUNTIME, 0, "base from must be an integer from 2 to 16");
   
         char *error_pos;  
         long value=strtol(string, &error_pos, base_from);  
         while(char c=*error_pos++)  
                 if(!isspace((unsigned char)c))  
                         throw Exception("number.format",  
                                 0,  
                                 "'%s' is invalid number (int)", string);  
   
         int base_to=params.as_int(2, "base to must be integer", r);          int base_to=params.as_int(2, "base to must be integer", r);
         if(base_to < 2 || base_to > 16)          if(base_to < 2 || base_to > 16)
                 throw Exception(PARSER_RUNTIME, 0, "base to must be an integer from 2 to 16");                  throw Exception(PARSER_RUNTIME, 0, "base to must be an integer from 2 to 16");
   
         char result_cstr[sizeof(long)*8+1/*minus for negative number*/+1/*terminator*/];          while(*str && isspace((unsigned char)*str))
         char* ptr=(char *)&result_cstr;                  str++;
         if(value < 0){  
                 *ptr++='-';          if(!*str)
                 value=-value;                  return;
   
           char *error_pos;
   
           bool negative=false;
           if(str[0]=='-') {
                   negative=true;
                   str++;
           } else if(str[0]=='+') {
                   str++;
         }          }
   
           errno=0;
           unsigned long value=strtoul(str, &error_pos, base_from);
           if(errno==ERANGE)
                           throw Exception("number.format", 0, "'%s' is out of range (int)", str);
   
           while(char c=*error_pos++)
                   if(!isspace((unsigned char)c))
                           throw Exception("number.format", 0, "'%s' is invalid number (int)", str);
   
           char result_cstr[sizeof(unsigned long)*8+1/*minus for negative number*/+1/*terminator*/];
           char* ptr=result_cstr;
           if(negative)
                   *ptr++='-';
   
         toBase(value, base_to, ptr);          toBase(value, base_to, ptr);
         *ptr=0;          *ptr=0;
         r.write_pass_lang(*new String(pa_strdup(result_cstr)));          r.write_pass_lang(*new String(pa_strdup(result_cstr)));

Removed from v.1.57  
changed lines
  Added in v.1.60


E-mail: