void init_rpn() { ERROUT = 1; NCON = 0; NFUN = 0; NVAR = 0; NKernel=0; MaxPoints=4000; NSYM = STDSYM; two_args(); one_arg(); add_con("PI", M_PI); add_con("I'",0.0); /* This is going to be for interacting with the animator */ SumIndex=NCON-1; add_con("mouse_x",0.0); add_con("mouse_y",0.0); add_con("mouse_vx",0.0); add_con("mouse_vy",0.0); /* end animator stuff */ /* add_con("c___1",0.0); add_con("c___2",0.0); add_con("c___3",0.0); */ init_table(); if (newseed==1) RandSeed=time(0); nsrand48(RandSeed); }
init_rpn() { int i; ERROUT = 1; NCON = 0; NFUN = 0; NVAR = 0; NKernel=0; MaxPoints=4000; NSYM = STDSYM; two_args(); one_arg(); add_con("PI", M_PI); add_con("I'",0.0); SumIndex=NCON-1; init_table(); srand48(RandSeed); }
// // Tries to apply a token to args, to parse something out. Returns a PARSE_VAR // if the token's usage resulted in the creation of a variable. If an error was // encountered, make this apparent by setting the value of the variable at error PARSE_VAR *use_one_parse_token(CHAR_DATA *looker, PARSE_TOKEN *tok, char **args, bool *error, char *err_buf) { char buf[SMALL_BUFFER]; PARSE_VAR *var = NULL; char *arg = *args; // skip over any leading spaces we might have while(isspace(*arg)) arg++; switch(tok->type) { case PARSE_TOKEN_MULTI: { // make a proxy error value and error buf so we don't accidentally fill // these up when it turns out we find something on a var past the first bool multi_err = FALSE; char multi_err_buf[SMALL_BUFFER] = ""; // go through all of our possible types until we find something LIST_ITERATOR *multi_i = newListIterator(tok->token_list); PARSE_TOKEN *mtok = NULL; bool multiple_possible = FALSE; ITERATE_LIST(mtok, multi_i) { if(mtok->all_ok) multiple_possible = TRUE; var = use_one_parse_token(looker, mtok, &arg, &multi_err, multi_err_buf); // reset our error value for the next pass at it... if(var == NULL) multi_err = FALSE; // found something! Disambiguate the type else { switch(mtok->type) { case PARSE_TOKEN_CHAR: var->disambiguated_type = PARSE_CHAR; break; case PARSE_TOKEN_ROOM: var->disambiguated_type = PARSE_ROOM; break; case PARSE_TOKEN_EXIT: var->disambiguated_type = PARSE_EXIT; break; case PARSE_TOKEN_OBJ: var->disambiguated_type = PARSE_OBJ; break; case PARSE_TOKEN_WORD: var->disambiguated_type = PARSE_STRING; break; case PARSE_TOKEN_STRING: var->disambiguated_type = PARSE_STRING; break; case PARSE_TOKEN_INT: var->disambiguated_type = PARSE_INT; break; case PARSE_TOKEN_DOUBLE: var->disambiguated_type = PARSE_DOUBLE; break; case PARSE_TOKEN_BOOL: var->disambiguated_type = PARSE_BOOL; break; } // break out of the loop... we found something break; } } deleteListIterator(multi_i); // did we manage not to find something? if(var != NULL) var->multiple_possible = multiple_possible; else { one_arg(arg, buf); // get the first arg, for reporting... sprintf(err_buf, "Your argument '%s' was invalid or could not be found.", buf); *error = TRUE; } break; } case PARSE_TOKEN_FLAVOR: { int len = strlen(tok->flavor); // have we found the flavor text? if(strncasecmp(tok->flavor, arg, len) == 0 && (arg[len] == '\0' || isspace(arg[len]))) arg = arg + len; // do we need to do something about it? else if(!tok->flavor_optional) *error = TRUE; break; } // parse out a char value case PARSE_TOKEN_CHAR: arg = one_arg(arg, buf); var = use_one_parse_token_char(looker, tok, buf); if(var == NULL) { sprintf(err_buf, "The person, %s, could not be found.", buf); *error = TRUE; } break; // parse out an obj value case PARSE_TOKEN_OBJ: arg = one_arg(arg, buf); var = use_one_parse_token_obj(looker, tok, buf); if(var == NULL) { sprintf(err_buf, "The object, %s, could not be found.", buf); *error = TRUE; } break; // parse out a room value case PARSE_TOKEN_ROOM: arg = one_arg(arg, buf); var = use_one_parse_token_room(looker, tok, buf); if(var == NULL) { sprintf(err_buf, "The room, %s, could not be found.", buf); *error = TRUE; } break; // parse out an exit value case PARSE_TOKEN_EXIT: arg = one_arg(arg, buf); var = use_one_parse_token_exit(looker, tok, buf); if(var == NULL) { sprintf(err_buf, "The direction, %s, could not be found.", buf); *error = TRUE; } break; // try to parse out a double value case PARSE_TOKEN_DOUBLE: arg = one_arg(arg, buf); var = use_one_parse_token_double(buf); if(var == NULL) { sprintf(err_buf, "'%s' is not a decimal value.", buf); *error = TRUE; } break; // try to parse out an integer value case PARSE_TOKEN_INT: arg = one_arg(arg, buf); var = use_one_parse_token_int(buf); if(var == NULL) { sprintf(err_buf, "'%s' is not a%s number.", buf, (string_is_double(buf) ? "n acceptable" : "")); *error = TRUE; } break; // try to parse out a boolean value case PARSE_TOKEN_BOOL: arg = one_arg(arg, buf); var = use_one_parse_token_bool(buf); if(var == NULL) { sprintf(err_buf, "'%s' is not a yes/no value.", buf); *error = TRUE; } break; // parse out a single word case PARSE_TOKEN_WORD: { var = newParseVar(PARSE_VAR_STRING); var->ptr_val = arg; bool multi_word = FALSE; char multi_mark = '"'; // are we using quotation marks to specify multiple words? if(*arg == '"' || *arg == '\'') { multi_word = TRUE; multi_mark = *arg; arg++; var->ptr_val = arg; } // go through arg to the next space, and delimit the word for(; *arg != '\0'; arg++) { if((multi_word && *arg == multi_mark) || (!multi_word && isspace(*arg))) { *arg = '\0'; arg++; break; } } break; } // copies whatever is left case PARSE_TOKEN_STRING: var = newParseVar(PARSE_VAR_STRING); var->ptr_val = arg; // skip up the place of the arg... while(*arg != '\0') arg++; break; // since this doesn't really parse a value... case PARSE_TOKEN_OPTIONAL: break; } // up the placement of our arg if we didn't encounter an error if(!*error) *args = arg; return var; }
std::string test_extension_object() { debug_check_ref_queue(); Py::Tuple a; // just something that isn't an range... Py::ExtensionObject<range> r1( new range(1, 20, 3) ); if(range::check(a)) std::cout << "range::check failed (1)."; if(!range::check(r1)) return "r::check failed (2)."; debug_check_ref_queue(); RangeSequence r2(1, 10, 2); if(r2[1] != Py::Int(3)) return "RangeSequence check failed. "; debug_check_ref_queue(); // calling an extension object method using getattr Py::Callable w(r2.getAttr("amethod")); Py::Tuple args(1); Py::Int j(3); args[0]=j; Py::List answer(w.apply(args)); if(answer[0] != r2) return ("Extension object test failed (1)"); if(answer[1] != args[0]) return ("Extension object test failed (2)"); debug_check_ref_queue(); Py::Tuple nv(3); nv[0] = Py::Int(1); nv[1] = Py::Int(20); nv[2] = Py::Int(3); Py::Tuple unused; Py::List r2value; r2.assign(unused, nv); r2value = r2.value(unused); if(r2value[1] != Py::Int(4)) return("Extension object test failed. (3)"); debug_check_ref_queue(); // repeat using getattr w = r2.getAttr("assign"); Py::Tuple the_arguments(2); the_arguments[0] = unused; the_arguments[1] = nv; w.apply(the_arguments); debug_check_ref_queue(); w = r2.getAttr("value"); Py::Tuple one_arg(1); one_arg[0] = unused; r2value = w.apply(one_arg); if(r2value[1] != Py::Int(4)) return("Extension object test failed. (4)"); debug_check_ref_queue(); { Py::ExtensionObject<range> rheap( new range(1, 10, 2) ); debug_check_ref_queue(); // delete rheap } debug_check_ref_queue(); return "ok."; }