--- parser3/src/classes/op.C 2003/12/11 09:25:50 1.142 +++ 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 * const IDENT_OP_C="$Date: 2003/12/11 09:25:50 $"; +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 * const IDENT_OP_C="$D #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 * const IDENT_OP_C="$D // 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); @@ -162,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); } @@ -284,7 +318,8 @@ gettimeofday(&mt[0],NULL); #endif // connect SQL_Connection* connection=SQL_driver_manager->get_connection(url.as_string(), - protocol2driver_and_client); + protocol2driver_and_client, + r.charsets.source().NAME().cstr()); #ifdef RESOURCES_DEBUG //measure:after connect @@ -330,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) { @@ -347,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")); @@ -726,6 +757,11 @@ static void _throw_operator(Request&, Me } } +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&, MethodParams&) { @@ -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