void declare_native_rule( const char * module, const char * rule, const char * * args, LIST * (*f)( FRAME *, int ), int version ) { OBJECT * module_obj = 0; module_t * m; if ( module ) { module_obj = object_new( module ); } m = bindmodule( module_obj ); if ( module_obj ) { object_free( module_obj ); } if (m->native_rules == 0) { m->native_rules = hashinit( sizeof( native_rule_t ), "native rules"); } { native_rule_t n, *np = &n; n.name = object_new( rule ); if (args) { n.arguments = args_new(); lol_build( n.arguments->data, args ); } else { n.arguments = 0; } n.procedure = function_builtin( f, 0 ); n.version = version; hashenter(m->native_rules, (HASHDATA**)&np); } }
RULE* bind_builtin( char* name, LIST*(*f)(PARSE*, FRAME*), int flags, char** args ) { argument_list* arg_list = 0; if ( args ) { arg_list = args_new(); lol_build( arg_list->data, args ); } return new_rule_body( root_module(), name, arg_list, parse_make( f, P0, P0, P0, C0, C0, flags ), 1 ); }
// Function.prototype.apply(thisValue[, argsArray]) js_val * func_proto_apply(js_val *instance, js_args *args, eval_state *state) { js_val *this = ARG(args, 0); js_val *arr = ARG(args, 1); js_args *func_args = args_new(); unsigned long i; for (i = 0; i < arr->object.length; i++) args_append(func_args, fh_get(arr, JSNUMKEY(i)->string.ptr)); return fh_call(state->ctx, this, instance, func_args); }
LIST * compile_setcomp( PARSE * parse, FRAME * frame ) { argument_list * arg_list = 0; /* Create new LOL describing argument requirements if supplied. */ if ( parse->right ) { PARSE * p; arg_list = args_new(); for ( p = parse->right; p; p = p->left ) lol_add( arg_list->data, parse_evaluate( p->right, frame ) ); } new_rule_body( frame->module, parse->string, arg_list, parse->left, !parse->num ); return L0; }
ARGPARSEcode subcommand_add_operand(subcommand *scmd, operand *op) { if (!scmd->args) scmd->args = args_new(); return args_add_operand(scmd->args, op); }
ARGPARSEcode subcommand_add_option(subcommand *scmd, option *opt) { if (!scmd->args) scmd->args = args_new(); return args_add_option(scmd->args, opt); }
static int _handleconn (int delay_time, int max_cost_time, int error) { if (error) { if (error == 1) { daemon_printf( "%d server temporarily unavailable\n", CODE_TEMPORARILY_UNAVAILABLE ); printf("daemon busy: temporarily unavailable\n"); } else { printf("daemon too busy: drop connection\n"); } net_close_fd(); return 0; } daemon_banner(); std::string buf; std::vector<std::string> *args; alarm(delay_time); while (true) { if (net_read_line(buf)) break; alarm(max_cost_time); printf("%s\n", buf.c_str()); args = args_new(buf.c_str()); if (args->size() == 0) { daemon_printf( "%d no command\n", CODE_SYNTAX_ERROR ); } else if ((*args)[0] == "client" && args->size()>=3) { daemon_client((*args)[1], (*args)[2]); } else if ((*args)[0] == "auth" && args->size()>=3) { daemon_auth((*args)[1], (*args)[2]); } else if ((*args)[0] == "lookup" && args->size()>=2) { if (args->size() >=3) { int wordcount = atoi((*args)[2].c_str()); if (wordcount < 1) { wordcount = 1; } else if (wordcount > 100) { wordcount = 100; } daemon_lookup((*args)[1], wordcount); } else { daemon_lookup((*args)[1], 30); } } else if ((*args)[0] == "query" && args->size()>=2) { daemon_query((*args)[1]); } else if ((*args)[0] == "selectquery" && args->size()>=2) { daemon_selectquery((*args)[1]); } else if ((*args)[0] == "smartquery" && args->size()>=3) { daemon_smartquery((*args)[1], (*args)[2]); } else if ((*args)[0] == "define" && args->size()>=2) { daemon_define((*args)[1]); } else if ((*args)[0] == "previous" && args->size()>=2) { if (args->size() >=3) { int wordcount = atoi((*args)[2].c_str()); if (wordcount < 1) { wordcount = 1; } else if (wordcount > 50) { wordcount = 50; } daemon_previous((*args)[1], wordcount); } else { daemon_previous((*args)[1], 15); } } else if ((*args)[0] == "next" && args->size()>=2) { if (args->size() >=3) { int wordcount = atoi((*args)[2].c_str()); if (wordcount < 1) { wordcount = 1; } else if (wordcount > 100) { wordcount = 100; } daemon_next((*args)[1], wordcount); } else { daemon_next((*args)[1], 30); } } else if ((*args)[0] == "quit" && args->size()>=1) { daemon_quit(); } else if ((*args)[0] == "register" && args->size()>=4) { daemon_register((*args)[1], (*args)[2], (*args)[3]); } else if ((*args)[0] == "change_password" && args->size()>=4) { daemon_change_password((*args)[1], (*args)[2], (*args)[3]); } else if ((*args)[0] == "setdictmask" && args->size()>=2) { daemon_setdictmask((*args)[1]); } else if ((*args)[0] == "getdictmask" && args->size()>=1) { daemon_getdictmask(); } else if ((*args)[0] == "setcollatefunc" && args->size()>=2) { daemon_setcollatefunc((*args)[1]); } else if ((*args)[0] == "getcollatefunc" && args->size()>=1) { daemon_getcollatefunc(); } else if ((*args)[0] == "setlanguage" && args->size()>=2) { daemon_setlanguage((*args)[1]); } else if ((*args)[0] == "getlanguage" && args->size()>=1) { daemon_getlanguage(); } else if ((*args)[0] == "setemail" && args->size()>=2) { daemon_setemail((*args)[1]); } else if ((*args)[0] == "getemail" && args->size()>=1) { daemon_getemail(); } else if ((*args)[0] == "getuserlevel" && args->size()>=1) { daemon_getuserlevel(); } else if ((*args)[0] == "maxdictcount" && args->size()>=1) { daemon_maxdictcount(); } else if ((*args)[0] == "dirinfo" && args->size()>=2) { daemon_dirinfo((*args)[1]); } else if ((*args)[0] == "dictinfo" && args->size()>=2) { daemon_dictinfo((*args)[1]); } else if ((*args)[0] == "userlevel" && args->size()>=4) { daemon_userlevel((*args)[1], (*args)[2], (*args)[3]); } else if ((*args)[0] == "fromto" && args->size() >= 1) { daemon_fromto(); } else if ((*args)[0] == "dictslist" && args->size()>=2) { daemon_dictslist((*args)[1]); } else if ((*args)[0] == "tmpdictmask" && args->size() >= 2) { daemon_LookupinTmpdictmask((*args)[1]); } else if ((*args)[0] == "getadinfo" && args->size()>=1) { daemon_getadinfo(); } else { daemon_printf( "%d unknown command\n", CODE_SYNTAX_ERROR ); } delete args; alarm(delay_time); } daemon_terminate( 0, "close" ); return 0; }