void spoil_powers_aux(FILE *fff, power_info *table) { int i; variant vn, vd; var_init(&vn); var_init(&vd); fprintf(fff, "\n== Powers ==\n"); fprintf(fff, "|| || *Stat* || *Lvl* || *Cost* || *Fail* || *Description* ||\n"); for (i = 0; ; i++) { power_info *base = &table[i]; if (!base->spell.fn) break; base->spell.fn(SPELL_SPOIL_NAME, &vn); if (var_is_null(&vn)) base->spell.fn(SPELL_NAME, &vn); base->spell.fn(SPELL_SPOIL_DESC, &vd); if (var_is_null(&vd)) base->spell.fn(SPELL_DESC, &vd); fprintf(fff, "||%s||%s||%d||%d||%d||`%s`||\n", var_get_string(&vn), stat_abbrev_true[base->stat], base->spell.level, base->spell.cost, base->spell.fail, var_get_string(&vd) ); } var_clear(&vn); var_clear(&vd); }
void spoil_spells_aux(FILE *fff, spell_info *table) { int i; variant vn, vd; var_init(&vn); var_init(&vd); fprintf(fff, "\n== Spells ==\n"); fprintf(fff, "|| || *Lvl* || *Cost* || *Fail* || *Description* ||\n"); for (i = 0; ; i++) { spell_info *base = &table[i]; if (!base->fn) break; base->fn(SPELL_SPOIL_NAME, &vn); if (var_is_null(&vn)) base->fn(SPELL_NAME, &vn); base->fn(SPELL_SPOIL_DESC, &vd); if (var_is_null(&vd)) base->fn(SPELL_DESC, &vd); fprintf(fff, "||%s||%d||%d||%d||`%s`||\n", var_get_string(&vn), base->level, base->cost, base->fail, var_get_string(&vd)); } var_clear(&vn); var_clear(&vd); }
int main(){ struct Variable var; var_init(&var, "lol", "lolllvm", V_INT); assert (strcmp("lol", var_get_name(&var)) == 0); assert (strcmp("lolllvm", var_get_llvm_name(&var)) == 0); assert (var_is_int(&var) != 0); assert (var_is_float(&var) == 0); assert (var_get_type(&var) == V_INT); assert (var_is_special(&var) == 0); var_init(&var, "lol", "lolllvm", V_FLOAT|V_SPECIAL); var_info(&var); assert (var_is_int(&var) == 0); assert (var_is_float(&var) != 0); assert (var_get_type(&var) == V_FLOAT); assert (var_is_special(&var) != 0); var_set_value(&var, -131); assert (var_get_value(&var) == -131); var_set_value(&var, 1.234); assert (((var_get_value(&var)) - 1.234) < 0.00001); assert (var_get_value(&var) != 1); var_set_modified(&var, V_MODIFIED); assert (var_is_modified(&var) != 0); var_set_modified(&var, V_NULL); assert (var_is_modified(&var) == 0); var_set_type(&var, V_FLOAT); assert (var_is_int(&var) == 0); assert (var_is_float(&var) != 0); assert (var_get_type(&var) == V_FLOAT); var_set_special(&var, V_SPECIAL); assert (var_is_special(&var) != 0); var_set_type(&var, V_INT); assert (var_is_int(&var) != 0); assert (var_is_float(&var) == 0); assert (var_get_type(&var) == V_INT); var_set_access(&var, V_NULL); assert (var_is_writable(&var) == 0); var_set_access(&var, V_WRITABLE); assert (var_is_writable(&var) != 0); var.flags |= 1; assert (var_is_declared(&var) != 0); /* var_set_nb_args(&var, 13); */ /* assert (var_get_nb_args(&var) == 13); */ printf("Tests OK (sauf get_nb_args)\n"); }
void parse_varDef() { expression_t expr; size_t addr; switch(next_token.type) { case TT_TYPE_DOUBLE: case TT_TYPE_INT: case TT_TYPE_STRING: var_init(); parse_type(); var_set_type(curr_token.type); match(TT_IDENTIFICATOR); var_set_name(curr_token.str); addr = generate_push(); var_set_addr(addr); symbol_t* var = var_finish(); var_table_add(var); parse_varDefFollow(var_table_find(var->name)); break; case TT_TYPE_AUTO: var_init(); match(TT_TYPE_AUTO); match(TT_IDENTIFICATOR); var_set_name(curr_token.str); match_deduction(TT_OP_ASSIGNMENT); var_set_initialized(); addr = generate_push(); var_set_addr(addr); expr = parse_expr(); switch (expr.type) { case DOUBLE_DT: case INT_DT: case STRING_DT: var_set_type(expr.type); generate_mov(addr, expr.addr); break; case DOUBLE_LIT_DT: var_set_type(DOUBLE_DT); generate_mov_double(addr, expr.double_val); break; case INT_LIT_DT: var_set_type(INT_DT); generate_mov_int(addr, expr.int_val); break; case STRING_LIT_DT: var_set_type(STRING_DT); generate_mov_string(addr, expr.str_val); break; default: ; } var_table_add(var_finish()); break; default: error("Syntactic error: Failed to parse the program", ERROR_SYN); } }
static void _list(menu_ptr menu, char *keys) { char temp[255]; int i; int y = 1; int x = 13; Term_erase(x, y, 255); if (menu->heading) put_str(format(" %s", menu->heading), y++, x); for (i = 0; i < menu->count; i++) { byte attr = TERM_WHITE; variant key, text, color; var_init(&key); var_init(&text); var_init(&color); menu->fn(MENU_KEY, i, menu->cookie, &key); if (var_is_null(&key)) keys[i] = I2A(i); else keys[i] = (char)var_get_int(&key); if (menu->count <= 26) keys[i] = tolower(keys[i]); menu->fn(MENU_TEXT, i, menu->cookie, &text); if (var_is_null(&text)) var_set_string(&text, ""); menu->fn(MENU_COLOR, i, menu->cookie, &color); if (!var_is_null(&color)) attr = var_get_int(&color); if (attr == TERM_DARK) keys[i] = '\0'; sprintf(temp, " %c) %s", keys[i], var_get_string(&text)); c_prt(attr, temp, y + i, x); var_clear(&key); var_clear(&text); var_clear(&color); } Term_erase(x, y + menu->count, 255); }
void aff_map(char **map) { extern t_sdl t; var_init(); sdl_init(); pos_init_joueur(); pos_init_monstre(); while (t.continuer) { if (map[(t.joueur.y / 34) + 1][t.joueur.x / 34] != 'w' && map[(t.joueur.y / 34) + 1][t.joueur.x / 34] != 's') { t.joueur.y += 34; SDL_Delay(30); } else sdl_event(); sdl_aff(); sdl_monstre(); SDL_Flip(t.fenetre); if (map[t.joueur.y / 34][t.joueur.x / 34] == 'o') { t.flag = 2; t.continuer = 0; } } sdl_end(); }
static void set_up(void) { if (p == NULL) { p = permanent_pool = make_sub_pool(NULL); } (void) var_init(); }
END_TEST START_TEST (var_next_test) { int ok; const char *res, *desc; (void) var_free(); res = pr_var_next(NULL); fail_unless(res == NULL, "Failed to handle uninitialized Var table"); fail_unless(errno == EPERM, "Failed to set errno to EPERM"); (void) var_init(); res = pr_var_next(NULL); fail_unless(res == NULL, "Failed to handle empty table"); ok = pr_var_set(p, "%{foo}", NULL, PR_VAR_TYPE_STR, "bar", NULL, 0); fail_unless(ok == 0, "Failed to add var: %s", strerror(errno)); res = pr_var_next(&desc); fail_unless(res != NULL, "Failed to get next key: %s", strerror(errno)); fail_unless(desc == NULL, "Expected no desc, got '%s'", desc); res = pr_var_next(&desc); fail_unless(res == NULL, "Expected no more keys, got '%s'", res); }
END_TEST START_TEST (var_exists_test) { int res; const char *key; (void) var_free(); res = pr_var_exists(NULL); fail_unless(res == -1, "Failed to handle uninitialized Var table"); fail_unless(errno == EPERM, "Failed to set errno to EPERM"); (void) var_init(); res = pr_var_exists(NULL); fail_unless(res == -1, "Failed to handle null key"); fail_unless(errno == EINVAL, "Failed to set errno to EINVAL"); key = "%{foo}"; res = pr_var_exists(key); fail_unless(res == FALSE, "Failed to handle absent key"); res = pr_var_set(p, key, NULL, PR_VAR_TYPE_STR, "bar", NULL, 0); fail_unless(res == 0, "Failed to add var: %s", strerror(errno)); res = pr_var_exists(key); fail_unless(res == TRUE, "Failed to detect present key"); }
END_TEST START_TEST (var_delete_test) { int res; const char *key = "%{foo}"; (void) var_free(); res = pr_var_delete(NULL); fail_unless(res == -1, "Failed to handle uninitialized Var table"); fail_unless(errno == EPERM, "Failed to set errno to EPERM"); (void) var_init(); res = pr_var_delete(NULL); fail_unless(res == -1, "Failed to handle null key"); fail_unless(errno == EINVAL, "Failed to set errno to EINVAL"); res = pr_var_delete(key); fail_unless(res == -1, "Failed to handle absent key"); fail_unless(errno == ENOENT, "Failed to set errno to ENOENT"); res = pr_var_set(p, key, "test", PR_VAR_TYPE_STR, "bar", NULL, 0); fail_unless(res == 0, "Failed to add var: %s", strerror(errno)); res = pr_var_delete(key); fail_unless(res == 0, "Failed to delete var: %s", strerror(errno)); res = pr_var_delete(key); fail_unless(res == -1, "Failed to handle absent key"); fail_unless(errno == ENOENT, "Failed to set errno to ENOENT"); }
/* add a new variable using the supplied var struct rather * than a malloced * ----------------------------------------------------------------------- */ struct var *var_import(const char *v, int flags, struct var *var) { struct search ctx; struct var *newvar; /* we should be in the root to import vars */ assert(sh->varstack == &vartab_root); /* variable name must be valid! */ if(!var_valid(v)) return var; /* search if the var already exists */ vartab_hash(sh->varstack, v, &ctx); if(!(newvar = var_search(v, &ctx))) { /* if not we take the supplied var struct, */ newvar = var; var = NULL; var_init(v, newvar, &ctx); /* ...and then add it to the table */ vartab_add(sh->varstack, newvar, &ctx); } else if(flags & V_INIT) return var; newvar->flags = flags; newvar->sa.s = (char *)v; newvar->sa.len = str_len(v); if(newvar->sa.len > newvar->len) newvar->offset = newvar->len + 1; return newvar; }
void fail_spell(ang_spell spell) { variant res; var_init(&res); spell(SPELL_FAIL, &res); var_clear(&res); }
void _gain_power(int level) { int group_idx = -1; if (level % 2 == 1) group_idx = level/2; if (group_idx >= 0 && group_idx < _MAX_TALENTS && _group_size(group_idx) > 0) { variant name; int idx = randint0(_group_size(group_idx)); talent_t *talent = &_talents[group_idx][idx]; if (!talent->spell.fn) { msg_print("BUG: Where is your talent?!"); return; } var_init(&name); (talent->spell.fn)(SPELL_NAME, &name); msg_format("You gain the power of '%s' %s.", var_get_string(&name), talent->gain_desc); p_ptr->magic_num1[group_idx] = idx + 1; var_clear(&name); } }
void handle_sigwinch(int s) { char *tty = NULL; int fd = 0; int result = 0; struct winsize win; tty = ttyname(0); if (!tty) return; fd = open(tty, O_RDWR); if (fd == -1) return; result = ioctl(fd, TIOCGWINSZ, &win); if (result == -1) return; COLS = win.ws_col; LINES = win.ws_row; #ifdef HAVE_RESIZETERM resizeterm(LINES, COLS); #ifdef HAVE_WRESIZE if (wresize(stdscr, LINES, COLS) == ERR) c_die("Cannot resize window!"); #endif /* HAVE_WRESIZE */ #endif /* HAVE_RESIZETERM */ var_init(); /* Do these b/c width may have changed... */ clear(); refresh(); }
int main(int argc, char **argv) { var_init(); yyparse(); var_destroy(); yylex_destroy(); return (0); }
static void _character_dump(doc_ptr doc) { int i; spell_info spells[MAX_SPELLS]; int ct = _get_spells_imp(spells, MAX_SPELLS, 0, _MAX_TALENTS - 1); for (i = 0; i < ct; i++) { spell_info* current = &spells[i]; current->cost += get_spell_cost_extra(current->fn); current->fail = MAX(current->fail, get_spell_fail_min(current->fn)); } if (ct > 0) { int i; variant name, info; var_init(&name); var_init(&info); doc_printf(doc, "<topic:WildTalent>================================= <color:keypress>W</color>ild Talents ================================\n\n"); doc_printf(doc, "<color:G>%-23.23s Lv Stat Cost Fail Info</color>\n", ""); for (i = 0; i < ct; ++i) { spell_info *spell = &spells[i]; (spell->fn)(SPELL_NAME, &name); (spell->fn)(SPELL_INFO, &info); doc_printf(doc, "%-23.23s %2d %4.4s %4d %3d%% %s\n", var_get_string(&name), spell->level, stat_abbrev_true[_which_stat(i)], spell->cost, spell->fail, var_get_string(&info)); } var_clear(&name); var_clear(&info); doc_newline(doc); } }
void dump_spells_aux(FILE *fff, spell_info *table, int ct) { int i; variant vn, vd, vc, vfm; if (!ct) return; var_init(&vn); var_init(&vd); var_init(&vc); var_init(&vfm); if (character_dump_hack) { fprintf(fff, "=================================== Spells ====================================\n\n"); fprintf(fff, "%-20.20s Lvl Cost Fail %-15.15s Cast Fail\n", "", "Desc"); } else { fprintf(fff, "\n[[[[r|%-20.20s Lvl Cost Fail %-15.15s Cast Fail\n", "Spells", "Desc"); } for (i = 0; i < ct; i++) { spell_info *spell = &table[i]; spell_stats_ptr stats = spell_stats(spell); spell->fn(SPELL_NAME, &vn); spell->fn(SPELL_INFO, &vd); spell->fn(SPELL_COST_EXTRA, &vc); spell->fn(SPELL_FAIL_MIN, &vfm); fprintf(fff, "%-20.20s %3d %4d %3d%% %-15.15s %4d %4d %3d%%\n", var_get_string(&vn), spell->level, calculate_cost(spell->cost + var_get_int(&vc)), MAX(spell->fail, var_get_int(&vfm)), var_get_string(&vd), stats->ct_cast, stats->ct_fail, spell_stats_fail(stats) ); } var_clear(&vn); var_clear(&vd); var_clear(&vc); var_clear(&vfm); }
int hi3716mv300_ddr_training_result(unsigned int TRAINING_ADDR) { struct training_data *ddr = (struct training_data *)TRAINING_ADDR; var_init(ddr); print_prebit_result(ddr); return 0; }
static int _choose_spell(spell_info* spells, int ct, cptr desc, int max_cost) { int choice = -1; char prompt1[140]; char prompt2[140]; variant name; bool describe = FALSE; var_init(&name); for (;;) { char ch = '\0'; strnfmt(prompt1, 78, "Use which %s? (Type '?' to Browse) ", desc); strnfmt(prompt2, 78, "Browse which %s? (Type '?' to Use)", desc); _list_spells(spells, ct, max_cost); /* Prompt User */ choice = -1; if (!get_com(describe ? prompt2 : prompt1, &ch, FALSE)) break; if (ch == '?') { describe = !describe; if (!get_com(describe ? prompt2 : prompt1, &ch, FALSE)) break; } if (isupper(ch)) choice = ch - 'A' + 26; else if (islower(ch)) choice = ch - 'a'; else if (ch >= '0' && ch <= '9') choice = ch - '0' + 52; /* Valid Choice? */ if (choice < 0 || choice >= ct) { bell(); continue; } if (describe) { _describe_spell(&spells[choice], _col_height(ct)); continue; } /* Good to go! */ break; } var_clear(&name); return choice; }
bool cast_spell(ang_spell spell) { bool b; variant res; var_init(&res); spell(SPELL_CAST, &res); b = var_get_bool(&res); var_clear(&res); return b; }
cptr get_spell_name(ang_spell spell) { static char buf[255]; variant v; var_init(&v); spell(SPELL_NAME, &v); sprintf(buf, "%s", var_get_string(&v)); var_clear(&v); return buf; }
cptr get_spell_desc(ang_spell spell) { static char buf[1024]; variant v; var_init(&v); spell(SPELL_DESC, &v); sprintf(buf, "%s", var_get_string(&v)); var_clear(&v); return buf; }
int get_spell_fail_min(ang_spell spell) { int n; variant res; var_init(&res); spell(SPELL_FAIL_MIN, &res); n = var_get_int(&res); var_clear(&res); return n; }
int get_spell_cost_extra(ang_spell spell) { int n; variant res; var_init(&res); spell(SPELL_COST_EXTRA, &res); n = var_get_int(&res); var_clear(&res); return n; }
int get_spell_energy(ang_spell spell) { int n; variant res; var_init(&res); spell(SPELL_ENERGY, &res); n = var_get_int(&res); var_clear(&res); return n; }
void mut_name(int i, char* buf) { variant v; var_init(&v); if (i >= 0 && i < MAX_MUTATIONS) (_mutations[i].spell.fn)(SPELL_NAME, &v); else var_set_string(&v, "None"); sprintf(buf, "%s", var_get_string(&v)); var_clear(&v); }
int main(int argc, char *argv[]) { batch = (argc > 1) ? 1 : 0; /* if batch == 1, get input from text file */ var_init(argv[1]); shell_loop(); free(myshell_env.PWD); free(myshell_env.SHELL); free(prompt); return EXIT_SUCCESS; }
bool mut_lose(int mut_idx) { variant v; if (mut_idx < 0 || mut_idx >= MAX_MUTATIONS) return FALSE; if (!mut_present(mut_idx)) return FALSE; if (mut_locked(mut_idx)) return FALSE; var_init(&v); remove_flag(p_ptr->muta, mut_idx); (_mutations[mut_idx].spell.fn)(SPELL_LOSE_MUT, &v); var_clear(&v); _mut_refresh(); return TRUE; }
void mut_dump_file(FILE* file) { int i; variant desc; var_init(&desc); for (i = 0; i < MAX_MUTATIONS; ++i) { if (mut_present(i)) { (_mutations[i].spell.fn)(SPELL_MUT_DESC, &desc); fprintf(file, "%s\n", var_get_string(&desc)); } } var_clear(&desc); }
bool mut_gain(int mut_idx) { variant v; if (mut_idx < 0 || mut_idx >= MAX_MUTATIONS) return FALSE; if (mut_present(mut_idx)) return FALSE; var_init(&v); add_flag(p_ptr->muta, mut_idx); (_mutations[mut_idx].spell.fn)(SPELL_GAIN_MUT, &v); var_clear(&v); _mut_refresh(); return TRUE; }