--- parser3/src/classes/op.C 2003/11/19 11:00:32 1.136 +++ parser3/src/classes/op.C 2005/02/17 14:56:54 1.151 @@ -1,11 +1,11 @@ /** @file Parser: parser @b operators. - Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_OP_C="$Date: 2003/11/19 11:00:32 $"; +static const char * const IDENT_OP_C="$Date: 2005/02/17 14:56:54 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -18,6 +18,7 @@ static const char* IDENT_OP_C="$Date: 20 #include "pa_vdate.h" #include "pa_vmethod_frame.h" #include "pa_vclass.h" +#include "pa_charset.h" // limits @@ -26,6 +27,9 @@ static const char* IDENT_OP_C="$Date: 20 // defines #define CASE_DEFAULT_VALUE "DEFAULT" +#define PROCESS_MAIN_OPTION_NAME "main" +#define PROCESS_FILE_OPTION_NAME "file" +#define PROCESS_LINENO_OPTION_NAME "lineno" // class @@ -66,7 +70,6 @@ public: ULN("http-header", HTTP_HEADER); ULN("mail-header", MAIL_HEADER); ULN("uri", URI); - ULN("table", TABLE); ULN("sql", SQL); ULN("js", JS); ULN("xml", XML); @@ -83,7 +86,6 @@ static void _if(Request& r, MethodParams Value& condition_code=params.as_junction(0, "condition must be expression"); bool condition=r.process_to_value(condition_code, - /*0/*no name* /,*/ false/*don't intercept string*/).as_bool(); if(condition) r.write_pass_lang(r.process(params.as_junction(1, "'then' parameter must be code"))); @@ -163,23 +165,54 @@ static void _process(Request& r, MethodP // temporary zero @auto so it wouldn't be auto-called in Request::use_buf Temp_method temp_method_auto(*target_class, auto_method_name, 0); - size_t main_alias_index=index+1; - const String* main_alias=0; - if(main_alias_indexget(PROCESS_MAIN_OPTION_NAME)) { + valid_options++; + main_alias=&vmain_alias->as_string(); + } + if(Value* vfile_alias=options->get(PROCESS_FILE_OPTION_NAME)) { + valid_options++; + file_alias=&vfile_alias->as_string(); + } + if(Value* vline_no_alias_offset=options->get(PROCESS_LINENO_OPTION_NAME)) { + valid_options++; + line_no_alias_offset=vline_no_alias_offset->as_int(); + } + + if(valid_options!=options->count()) + throw Exception("parser.runtime", + 0, + "called with invalid option"); } + uint processe_file_no=file_alias? + r.register_file(r.absolute(*file_alias)) + : pseudo_file_no__process; + // process...{string} + Value& vjunction=params.as_junction(index, "body must be code"); + // evaluate source to process + const String& source=r.process_to_string(vjunction); + r.use_buf(*target_class, + source.cstr(String::L_UNSPECIFIED, r.connection(false)), + main_alias, + processe_file_no, + line_no_alias_offset); + // main_method main_method=target_class->get_method(main_method_name); } @@ -193,7 +226,7 @@ static void _process(Request& r, MethodP } } -static void _rem(Request& r, MethodParams& params) { +static void _rem(Request&, MethodParams& params) { params.as_junction(0, "body must be code"); } @@ -210,7 +243,6 @@ static void _while(Request& r, MethodPar "endless loop detected"); bool condition=r.process_to_value(vcondition, - /*0/*no name* /,*/ false/*don't intercept string*/).as_bool(); if(!condition) // ...condition is true break; @@ -258,7 +290,6 @@ static void _eval(Request& r, MethodPara Value& expr=params.as_junction(0, "need expression"); // evaluate expresion Value& value_result=r.process_to_value(expr, - /*0/*no name YET* /,*/ true/*don't intercept string*/).as_expr_result(); if(params.count()>1) { Value& fmt=params.as_no_junction(1, "fmt must not be code"); @@ -286,8 +317,9 @@ struct timeval mt[2]; gettimeofday(&mt[0],NULL); #endif // connect - SQL_Connection* connection=SQL_driver_manager.get_connection(url.as_string(), - protocol2driver_and_client); + SQL_Connection* connection=SQL_driver_manager->get_connection(url.as_string(), + protocol2driver_and_client, + r.charsets.source().NAME().cstr()); #ifdef RESOURCES_DEBUG //measure:after connect @@ -333,11 +365,8 @@ static void _switch(Request& r, MethodPa // execution of found ^case[...]{code} must be in context of ^switch[...]{code} // because of stacked WWrapper used there as wcontext r.process(cases_code, true/*intercept_string*/); - if(Value* selected_code=data->found? data->found: data->_default) { - // setting code context, would execute in ^switch[...]{>>context<<} - //selected_code->get_junction()->change_context(cases_code.get_junction()); + if(Value* selected_code=data->found? data->found: data->_default) r.write_pass_lang(r.process(*selected_code)); - } } static void _case(Request& r, MethodParams& params) { @@ -350,10 +379,6 @@ static void _case(Request& r, MethodPara int count=params.count(); Value& code=params.as_junction(--count, "case result must be code"); - // killing context for safety, would execute in ^switch[...]{>>context<<} - // reason: context is stacked, and it would become invalid afterwards - //code->get_junction()->change_context(0); - for(int i=0; iexpires=expires; return; - } + } else if(params.count()<3) + throw Exception("parser.runtime", + 0, + "invalid number of parameters"); // file_spec, expires, body code const String& file_spec=r.absolute(params.as_string(0, "filespec must be string")); - Cache_scope scope={as_expires(r, params, 1, now)}; + Cache_scope scope={as_expires(r, params, 1, now), 0}; Temp_hash_value cache_scope_setter(r.classes_conf, cache_data_name, &scope); @@ -697,7 +728,7 @@ static void _try_operator(Request& r, Me r.write_pass_lang(result.processed_code); } -static void _throw_operator(Request& r, MethodParams& params) { +static void _throw_operator(Request&, MethodParams& params) { if(params.count()==1) { if(HashStringValue *hash=params[0].get_hash()) { const char* type=0; @@ -706,7 +737,7 @@ static void _throw_operator(Request& r, const String* source=0; if(Value* value=hash->get(exception_source_part_name)) source=&value->as_string(); - const char* comment; + const char* comment=0; if(Value* value=hash->get(exception_comment_part_name)) comment=value->as_string().cstr(); @@ -726,9 +757,14 @@ static void _throw_operator(Request& r, } } +static void _sleep_operator(Request& r, MethodParams& params) { + double seconds=params.as_double(0, "seconds must be double", r); + pa_sleep((int)trunc(seconds), (int)trunc(seconds*1000)); + } + #if defined(WIN32) && defined(_DEBUG) # define PA_BPT -static void _bpt(Request& r, MethodParams& params) { +static void _bpt(Request&, MethodParams&) { _asm int 3; } #endif @@ -754,7 +790,7 @@ VClassMAIN::VClassMAIN(): VClass() { add_native_method("taint", Method::CT_ANY, _taint, 1, 2); // ^process[code] - add_native_method("process", Method::CT_ANY, _process, 1, 2); + add_native_method("process", Method::CT_ANY, _process, 1, 3); // ^rem{code} add_native_method("rem", Method::CT_ANY, _rem, 1, 10000); @@ -796,6 +832,7 @@ VClassMAIN::VClassMAIN(): VClass() { // ^throw[type;source;comment] add_native_method("throw", Method::CT_ANY, _throw_operator, 1, 3); + add_native_method("sleep", Method::CT_ANY, _sleep_operator, 1, 1); } // constructor & configurator