/* ---------------------------------------------------------------------------- * Reads the provided script variables, if any, and does stuff with them. */ void pikmin::read_script_vars(const string &vars) { mob::read_script_vars(vars); maturity = s2i(get_var_value(vars, "maturity", "2")); if(s2b(get_var_value(vars, "sprout", "0"))) { fsm.first_state_override = PIKMIN_STATE_SPROUT; } }
int particular_cases(t_link *link, int type) { char *tmp; if (type == 0) { if ((tmp = get_var_value(link, "HOME")) != NULL) if (tmp[0] != '\0') update_pwd(link, tmp, tmp); return (42); } if (type == 1) { if ((tmp = get_var_value(link, "OLDPWD")) != NULL) update_pwd(link, tmp, tmp); return (42); } if (type == 2) { if ((tmp = my_strdup("/")) != NULL) update_pwd(link, tmp, tmp); return (42); } return (42); }
int xml_unpack(char *a) { int iret; char msgtype[21]; char msgtypefile[60]; memset(msgtype,0,sizeof(msgtype)); memset(msgtypefile,0,sizeof(msgtypefile)); if(a[0]=='V') { SysLog(LOG_APP_SHOW,"从变量V_MSGTYPE取报文类型进行处理"); iret = get_var_value(a+1,sizeof(msgtype),1,msgtype); if(iret == -1) { SysLog(LOG_APP_ERR,"从变量[%s]取报文类型进行处理失败",a+1); return -1; } SysLog(LOG_APP_SHOW,"获取到待解包报文类型[%s]\n",msgtype); trim(msgtype); SysLog(LOG_APP_SHOW,"从变量V_XMLFILE读取报文进行处理"); iret = get_var_value("V_XMLFILE",sizeof(msgtypefile),1,msgtypefile); if(iret == -1) { SysLog(LOG_APP_ERR,"从变量V_XMLFILE读取报文进行处理失败"); return -1; } SysLog(LOG_APP_SHOW,"获取到待处理报文[%s]",msgtypefile); trim(msgtypefile); if(unpack_xml(msgtype,msgtypefile)==-1) { SysLog(LOG_APP_ERR,"解报文类型[%s]失败",msgtype); return -1; } return 0; }else if(a[0]=='B') { sprintf(msgtypefile,"%s%s/%s_1.xml",upshome,"/cfg/xmlcfg",a+1); if(unpack_xml(a,msgtypefile)==-1) { SysLog(LOG_APP_ERR,"解报文类型[%s]失败",a); return -1; } } SysLog(LOG_APP_SHOW,"解析报文成功"); return 0; }
char *upgrade_pwd(t_link *link, char *pwd, char *element, int i) { char *new_pwd; char *tmp; if (i == 0 && !element[0]) { free(pwd); pwd = my_strdup("/"); return (pwd); } if (i == 0 && (!my_strcmp(element, "~") && (tmp = get_var_value(link, "HOME")))) { free(pwd); pwd = my_strdup(tmp); return (pwd); } if (!element[0] || !my_strcmp(element, ".")) return (pwd); tmp = element; if (my_count_char(pwd, '/') > 1 || (my_count_char(pwd, '/') == 1 && pwd[1])) tmp = my_strcat("/", element); new_pwd = my_strcat(pwd, tmp); free(tmp); free(pwd); return (new_pwd); }
/* ---------------------------------------------------------------------------- * Creates a Pikmin. */ pikmin::pikmin(const float x, const float y, pikmin_type* type, const float angle, const string &vars) : mob(x, y, type, angle, vars) { pik_type = type; hazard_time_left = -1; attacking_mob = NULL; latched = false; attack_time = 0; being_chomped = false; carrying_mob = NULL; wants_to_carry = NULL; pluck_reserved = false; team = MOB_TEAM_PLAYER_1; // TODO maturity = s2i(get_var_value(vars, "maturity", "2")); if(s2b(get_var_value(vars, "buried", "0"))) state = PIKMIN_STATE_BURIED; }
/* ---------------------------------------------------------------------------- * Creates a treasure. */ treasure::treasure( const float x, const float y, treasure_type* type, const float angle, const string &vars ) : mob(x, y, type, angle, vars), tre_type(type), buried(s2f(get_var_value(vars, "buried", "0"))) { become_carriable(true); set_animation(ANIM_IDLING); }
// Replace any terminal code strings in from[] with the equivalent internal // vim representation. This is used for the "from" and "to" part of a // mapping, and the "to" part of a menu command. // Any strings like "<C-UP>" are also replaced, unless 'cpoptions' contains // '<'. // K_SPECIAL by itself is replaced by K_SPECIAL KS_SPECIAL KE_FILLER. // // The replacement is done in result[] and finally copied into allocated // memory. If this all works well *bufp is set to the allocated memory and a // pointer to it is returned. If something fails *bufp is set to NULL and from // is returned. // // CTRL-V characters are removed. When "from_part" is TRUE, a trailing CTRL-V // is included, otherwise it is removed (for ":map xx ^V", maps xx to // nothing). When 'cpoptions' does not contain 'B', a backslash can be used // instead of a CTRL-V. char_u * replace_termcodes ( char_u *from, char_u **bufp, int from_part, int do_lt, // also translate <lt> int special // always accept <key> notation ) { ssize_t i; size_t slen; char_u key; size_t dlen = 0; char_u *src; int do_backslash; // backslash is a special character int do_special; // recognize <> key codes char_u *result; // buffer for resulting string do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL); do_special = (vim_strchr(p_cpo, CPO_SPECI) == NULL) || special; // Allocate space for the translation. Worst case a single character is // replaced by 6 bytes (shifted special key), plus a NUL at the end. result = xmalloc(STRLEN(from) * 6 + 1); src = from; // Check for #n at start only: function key n if (from_part && src[0] == '#' && VIM_ISDIGIT(src[1])) { // function key result[dlen++] = K_SPECIAL; result[dlen++] = 'k'; if (src[1] == '0') { result[dlen++] = ';'; // #0 is F10 is "k;" } else { result[dlen++] = src[1]; // #3 is F3 is "k3" } src += 2; } // Copy each byte from *from to result[dlen] while (*src != NUL) { // If 'cpoptions' does not contain '<', check for special key codes, // like "<C-S-LeftMouse>" if (do_special && (do_lt || STRNCMP(src, "<lt>", 4) != 0)) { // Replace <SID> by K_SNR <script-nr> _. // (room: 5 * 6 = 30 bytes; needed: 3 + <nr> + 1 <= 14) if (STRNICMP(src, "<SID>", 5) == 0) { if (current_SID <= 0) { EMSG(_(e_usingsid)); } else { src += 5; result[dlen++] = K_SPECIAL; result[dlen++] = (int)KS_EXTRA; result[dlen++] = (int)KE_SNR; sprintf((char *)result + dlen, "%" PRId64, (int64_t)current_SID); dlen += STRLEN(result + dlen); result[dlen++] = '_'; continue; } } slen = trans_special(&src, result + dlen, TRUE); if (slen) { dlen += slen; continue; } } if (do_special) { char_u *p, *s, len; // Replace <Leader> by the value of "mapleader". // Replace <LocalLeader> by the value of "maplocalleader". // If "mapleader" or "maplocalleader" isn't set use a backslash. if (STRNICMP(src, "<Leader>", 8) == 0) { len = 8; p = get_var_value((char_u *)"g:mapleader"); } else if (STRNICMP(src, "<LocalLeader>", 13) == 0) { len = 13; p = get_var_value((char_u *)"g:maplocalleader"); } else { len = 0; p = NULL; } if (len != 0) { // Allow up to 8 * 6 characters for "mapleader". if (p == NULL || *p == NUL || STRLEN(p) > 8 * 6) { s = (char_u *)"\\"; } else { s = p; } while (*s != NUL) { result[dlen++] = *s++; } src += len; continue; } } // Remove CTRL-V and ignore the next character. // For "from" side the CTRL-V at the end is included, for the "to" // part it is removed. // If 'cpoptions' does not contain 'B', also accept a backslash. key = *src; if (key == Ctrl_V || (do_backslash && key == '\\')) { ++src; // skip CTRL-V or backslash if (*src == NUL) { if (from_part) { result[dlen++] = key; } break; } } // skip multibyte char correctly for (i = (*mb_ptr2len)(src); i > 0; --i) { // If the character is K_SPECIAL, replace it with K_SPECIAL // KS_SPECIAL KE_FILLER. // If compiled with the GUI replace CSI with K_CSI. if (*src == K_SPECIAL) { result[dlen++] = K_SPECIAL; result[dlen++] = KS_SPECIAL; result[dlen++] = KE_FILLER; } else { result[dlen++] = *src; } ++src; } } result[dlen] = NUL; *bufp = xrealloc(result, dlen + 1); return *bufp; }
unsigned char * varsubst_heap(const serve_state_t state, unsigned char *in_str, int free_flag, const struct config_parse_info *global_vars, const struct config_parse_info *problem_vars, const struct config_parse_info *language_vars, const struct config_parse_info *tester_vars) { unsigned char *out_str = 0, *p1, *p2; unsigned char *var_name = 0; size_t var_name_size = 0, in_str_len = 0, var_value_len = 0; const unsigned char *var_value = 0; //fprintf(stderr, ">>%s\n", in_str); in_str_len = strlen(in_str); while (1) { // find the first variable use p1 = in_str; for (p1 = in_str; *p1; p1++) { if (*p1 == '$' && p1[1] == '{') break; } if (!*p1) break; p2 = p1 + 2; while (*p2 && *p2 != '}') p2++; if (!*p2 || p2 == p1 + 2) { err("varsubst_heap: invalid variable name in %s", in_str); if (free_flag) xfree(in_str); xfree(var_name); return 0; } if (p2 - p1 > var_name_size) { var_name_size = p2 - p1; xfree(var_name); var_name = xmalloc(var_name_size); } memcpy(var_name, p1 + 2, p2 - p1 - 2); var_name[p2 - p1 - 2] = 0; var_value = get_var_value(state, var_name, global_vars, problem_vars, language_vars, tester_vars); if (!var_value) { if (free_flag) xfree(in_str); xfree(var_name); return 0; } var_value_len = strlen(var_value); out_str = xmalloc(in_str_len + var_value_len + 1); memcpy(out_str, in_str, p1 - in_str); memcpy(out_str + (p1 - in_str), var_value, var_value_len); strcpy(out_str + (p1 - in_str) + var_value_len, p2 + 1); if (free_flag) xfree(in_str); in_str = out_str; in_str_len = strlen(in_str); free_flag = 1; } xfree(var_name); //fprintf(stderr, ">>%s\n", in_str); // find whether there are dollar substitutions for (p1 = in_str; *p1; p1++) { if (*p1 == '$' && p1[1] == '$') break; } if (!*p1) return in_str; out_str = xmalloc(in_str_len + 1); for (p1 = in_str, p2 = out_str; *p1; p1++, p2++) { *p2 = *p1; if (*p1 == '$' && p1[1] == '$') p1++; } if (free_flag) xfree(in_str); return out_str; }
cons_t eval(cons_t *c, var_t *local_vars){ cons_t p; switch(c->type){ case TYPE_OPERATE:{ int (*func)(int x, int y) = c->v.func; int n; if(c->cdr == NULL){ printf("operate error\n"); return p; } n = eval(c->cdr, local_vars).v.i; c = c->cdr->cdr; while(c != NULL){ p = eval(c, local_vars); n = func(n, p.v.i); c = c->cdr; } p.type = TYPE_INT; p.v.i = n; return p; } case TYPE_COMPARE:{ int (*func)(int x, int y) = c->v.func; if(c->cdr == NULL || c->cdr->cdr == NULL){ printf("compare error\n"); return p; } int n1 = eval(c->cdr, local_vars).v.i; int n2 = eval(c->cdr->cdr, local_vars).v.i; p.type = func(n1, n2); return p; } case TYPE_IF: p = eval(c->cdr, local_vars); if(p.type != TYPE_NIL){ return eval(c->cdr->cdr, local_vars); }else{ return eval(c->cdr->cdr->cdr, local_vars); } case TYPE_SETQ: c = c->cdr; if(c->type == TYPE_STR){ p = eval(c->cdr, local_vars); if(p.type == TYPE_INT){ const char *name = c->v.str; int value = p.v.i; global_vars = set_var_value(global_vars, name, value); return p; }else{ printf("setq error 1"); } }else{ printf("setq error 2"); } break; case TYPE_DEFUN: c = c->cdr; funcs = set_func(funcs, c->v.str, c->cdr->v.car, c->cdr->cdr->v.car); p.type = TYPE_DEFUN; return p; case TYPE_STR:{ func_t *f = get_func(funcs, c->v.str); if(f != NULL){ // function? cons_t *args = f->args; var_t *locals = NULL; c = c->cdr; while(args != NULL){ if(c == NULL){ printf("func argument error\n"); return p; } cons_t p = eval(c, local_vars); locals = set_var_value(locals, args->v.str, p.v.i); args = args->cdr; c = c->cdr; } p = eval(f->car, locals); free_vars(locals); }else{ var_t *v; // local variable? v = get_var_value(local_vars, c->v.str); if(v == NULL){ // global variable? v = get_var_value(global_vars, c->v.str); } if(v == NULL){ printf("var get error\n"); return p; } p.type = TYPE_INT; p.v.i = v->value; } break; } case TYPE_INT: return *c; case TYPE_CAR: return eval(c->v.car, local_vars); default: printf("error type %d\n", c->type); } return p; }