--- parser3/src/classes/math.C 2003/11/20 16:34:23 1.36 +++ parser3/src/classes/math.C 2007/04/23 10:30:09 1.45 @@ -1,14 +1,14 @@ /** @file Parser: @b math parser class. - Copyright(c) 2001-2003 ArtLebedev Group(http://www.artlebedev.com) + Copyright(c) 2001-2005 ArtLebedev Group(http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) portions from gen_uuid.c, Copyright (C) 1996, 1997, 1998, 1999 Theodore Ts'o. */ -static const char * const IDENT_MATH_C="$Date: 2003/11/20 16:34:23 $"; +static const char * const IDENT_MATH_C="$Date: 2007/04/23 10:30:09 $"; #include "pa_vmethod_frame.h" #include "pa_common.h" @@ -164,10 +164,9 @@ static inline int _random(uint top) { } static void _random(Request& r, MethodParams& params) { - Value& range=params.as_junction(0, "range must be expression"); - double top=r.process_to_value(range).as_double(); + double top=params.as_double(0, "range must be expression", r); if(top<=0 || top>MAX_UINT) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "top(%g) must be [1..%u]", top, MAX_UINT); @@ -181,9 +180,8 @@ static double degrees(double param) { re static double radians(double param) { return param /180 *PI; } static void math1(Request& r, MethodParams& params, math1_func_ptr func) { - Value& param=params.as_junction(0, "parameter must be expression"); - - double result=func(r.process_to_value(param).as_double()); + double param=params.as_double(0, "parameter must be expression", r); + double result=func(param); r.write_no_lang(*new VDouble(result)); } @@ -208,12 +206,9 @@ MATH1(sqrt); typedef double (*math2_func_ptr)(double, double); static void math2(Request& r, MethodParams& params, math2_func_ptr func) { - Value& a=params.as_junction(0, "parameter must be expression"); - Value& b=params.as_junction(1, "parameter must be expression"); - - double result=func( - r.process_to_value(a).as_double(), - r.process_to_value(b).as_double()); + double a=params.as_double(0, "parameter must be expression", r); + double b=params.as_double(1, "parameter must be expression", r); + double result=func(a, b); r.write_no_lang(*new VDouble(result)); } @@ -227,10 +222,10 @@ inline bool is_salt_body_char(int c) { return isalnum(c) || c == '.' || c=='/'; } static size_t calc_prefix_size(const char* salt) { - if(size_t salt_size=strlen(salt)) { - if(!is_salt_body_char(salt[0])) { // $... {... + if(strlen(salt)) { + if(!is_salt_body_char((unsigned char)salt[0])) { // $... {... const char* cur=salt+1; // skip - while(is_salt_body_char(*cur++)) // ...$ ...} + while(is_salt_body_char((unsigned char)*cur++)) // ...$ ...} ; return cur-salt; } else @@ -273,40 +268,22 @@ static void _crypt(Request& r, MethodPar if(!static_sample_buf // nothing generated || !static_sample_buf[0] // generated nothing || strncmp(static_sample_buf, normal_salt, prefix_size)!=0) // salt prefix not preserved - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "crypt on this platform does not support '%.*s' salt prefix", prefix_size, normal_salt); r.write_pass_lang(String(pa_strdup(static_sample_buf))); #else - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "salt must start with '" PA_MD5PW_ID "'"); #endif } } -static const char* hex_string(unsigned char* bytes, size_t size, bool upcase) { - char *bytes_hex=new(PointerFreeGC) char [size*2/*byte->hh*/+1/*for zero-teminator*/]; - unsigned char *src=bytes; - unsigned char *end=bytes+size; - char *dest=bytes_hex; - - static const char *hex=upcase?"0123456789ABCDEF":"0123456789abcdef"; - - for(; src