result_t end_tag(void *user, const char_t *name) { parserinfo_mv_t *pinfo = (parserinfo_mv_t *)user; if( pinfo ) { if( checkflag(pinfo->flags,MV_FLAG_TARGET) ) { cp_end_tag_rcm(&pinfo->rcm, &pinfo->std, name); if( (pinfo->std.depth == 1) && !checkflag(pinfo->rcm.flags,RCM_CP_OKINSERT) ) { errormsg(E_WARNING, "missing target insertion point, nothing copied.\n"); } } else { if( pinfo->std.sel.active ) { write_end_tag_tempcollect(&pinfo->sav, name); } rm_end_tag_rcm(&pinfo->rcm, &pinfo->std, name); } } return PARSER_OK; }
bool_t end_file_fun(void *user, const char_t *file, const char_t **xpaths) { parserinfo_mv_t *pinfo = (parserinfo_mv_t *)user; if( pinfo ) { if( checkflag(pinfo->flags,MV_FLAG_TARGET) ) { cp_end_target_rcm(&pinfo->rcm, file); } else { rm_end_file_rcm(&pinfo->rcm, file); if( !checkflag(pinfo->rcm.flags, RCM_WRITE_FILES) ) { /* this only occurs the first time the target is seen */ if( (strcmp(file, pinfo->target) == 0) && pinfo->tempfile ) { close(pinfo->tempfd); pinfo->tempfd = -1; clearflag(&pinfo->rcm.flags, RCM_RM_OUTPUT); } } } return TRUE; } return FALSE; }
result_t flush_stringval_stdout(parserinfo_cut_t *pinfo) { if( pinfo ) { if( checkflag(pinfo->flags,CUT_FLAG_FIELD) ) { if( !is_empty_tempcollect(&pinfo->stringval) ) { if( !print_fields_stdout(pinfo) ) { /* write_stdout_tempcollect(&pinfo->stringval); /\* safety *\/ */ } reset_tempcollect(&pinfo->stringval); } } else if( checkflag(pinfo->flags,CUT_FLAG_CHAR) ) { if( !is_empty_tempcollect(&pinfo->stringval) ) { if( !print_chars_stdout(pinfo) ) { /* write_stdout_tempcollect(&pinfo->stringval); */ } reset_tempcollect(&pinfo->stringval); } } return TRUE; } return FALSE; }
void debug_flags() { for (u16 flag = 0x1E0; flag < 0x280; flag++) { dprintf("%x : %x\n", flag, checkflag(flag)); } for (u16 flag = 0x900; flag < 0xA00; flag++) { dprintf("%x : %x\n", flag, checkflag(flag)); } }
void exec_result(result_t r, parser_t *parser) { if( checkflag(r,PARSER_ABORT) ) { stop_parser(parser, TRUE); } else if( checkflag(r,PARSER_STOP) ) { stop_parser(parser, FALSE); } else if( checkflag(r,PARSER_DEFAULT) && parser->callbacks.dfault) { XML_DefaultCurrent(parser->p); } }
void sanity_check(parserinfo_cut_t *pinfo) { int f; f = (checkflag(pinfo->flags,CUT_FLAG_CHAR) > 0) + (checkflag(pinfo->flags,CUT_FLAG_FIELD) > 0) + (checkflag(pinfo->flags,CUT_FLAG_TAG) > 0); if( f != 1 ) { errormsg(E_FATAL, "exactly one of -c, -f, or -t options must be given.\n"); } }
int battle_obedience_get_max_level() { int max_level = 20; if (checkflag(FRBADGE_1)) { max_level = max(max_level, 30); } if (checkflag(FRBADGE_2)) { max_level = max(max_level, 40); } if (checkflag(FRBADGE_3)) { max_level = max(max_level, 50); } if (checkflag(FRBADGE_4)) { max_level = max(max_level, 60); } if (checkflag(FRBADGE_5)) { max_level = max(max_level, 70); } if (checkflag(FRBADGE_6)) { max_level = max(max_level, 80); } if (checkflag(FRBADGE_7)) { max_level = max(max_level, 90); } if (checkflag(FRBADGE_8)) { max_level = max(max_level, 100); } return max_level; }
bool_t start_file_fun(void *user, const char_t *file, const char_t **xpaths) { parserinfo_mv_t *pinfo = (parserinfo_mv_t *)user; if( pinfo ) { if( checkflag(pinfo->flags,MV_FLAG_TARGET) ) { if( (strcmp(file, "stdin") == 0) && checkflag(pinfo->rcm.flags, RCM_WRITE_FILES) ) { errormsg(E_WARNING, "cannot write to stdin, ignoring this file.\n"); return FALSE; } cp_start_target_rcm(&pinfo->rcm, file); } else { if( strcmp(file, "stdout") == 0 ) { if( checkflag(pinfo->flags, MV_FLAG_SEEN_STDOUT) ) { if( false_and_setflag(&pinfo->flags, MV_FLAG_WARN_STDOUT) ) { errormsg(E_WARNING, "only one stdout target allowed, ignoring remaining.\n"); } } setflag(&pinfo->flags, MV_FLAG_SEEN_STDOUT); } if( checkflag(pinfo->rcm.flags, RCM_WRITE_FILES) ) { if( strcmp(file, "stdin") == 0 ) { errormsg(E_WARNING, "cannot write to stdin, ignoring this file.\n"); return FALSE; } } else { /* this only occurs the first time the target is seen */ if( (strcmp(file, pinfo->target) == 0) && pinfo->tempfile && (pinfo->tempfd != -1) ) { open_redirect_stdout(pinfo->tempfd); setflag(&pinfo->rcm.flags, RCM_RM_OUTPUT); } } rm_start_file_rcm(&pinfo->rcm, file); } return TRUE; } return FALSE; }
result_t start_tag(void *user, const char_t *name, const char_t **att) { parserinfo_ls_t *pinfo = (parserinfo_ls_t *)user; unsigned int d; if( pinfo ) { pinfo->npos++; pinfo->contin = FALSE; d = pinfo->std.depth - pinfo->std.sel.mindepth; if( (d <= pinfo->pd) && (d >= 0) ) { putc_stdout('\n'); nputc_stdout('\t', pinfo->indent + d); putc_stdout('<'); puts_stdout(name); if( checkflag(pinfo->flags,LS_FLAG_ATTRIBUTES) ) { #define TRUNCATE_ATTS 10 while( att && *att ) { putc_stdout(' '); puts_stdout(att[0]); puts_stdout("=\""); write_truncate_stdout(TRUNCATE_ATTS, att[1], strlen(att[1])); putc_stdout('\"'); att += 2; } } /* also include the node position in original document */ /* nprintf_stdout(32, " pos=\"%d\"/>", pinfo->npos); */ puts_stdout( (d < pinfo->pd) ? ">" : "/>"); } } return PARSER_OK; }
result_t start_tag(void *user, const char_t *name, const char_t **att) { parserinfo_mv_t *pinfo = (parserinfo_mv_t *)user; const char_t *path; const char_t **fatt; if( pinfo ) { if( checkflag(pinfo->flags,MV_FLAG_TARGET) ) { cp_start_tag_rcm(&pinfo->rcm, &pinfo->std, name, att); } else { if( pinfo->std.sel.active ) { write_start_tag_tempcollect(&pinfo->sav, name, att); } else if( pinfo->std.sel.attrib ) { path = string_xpath(&pinfo->std.cp); fatt = att; do { if( check_xattributelist(&pinfo->std.sel.atts, path, fatt[0]) ) { puts_tempcollect(&pinfo->sav, fatt[1]); } fatt += 2; } while( fatt && *fatt ); } rm_start_tag_rcm(&pinfo->rcm, &pinfo->std, name, att); } } return PARSER_OK; }
void dungeon2_cave_wild_pokemon_level_distribution(u8 *mean, u8 *std_deviation) { if(checkflag(FRBADGE_4)) { *mean = 34; *std_deviation = 3; } else if (checkflag(FRBADGE_3)) { *mean = 26; *std_deviation = 3; } else if (checkflag(FRBADGE_2)) { *mean = 16; *std_deviation = 2; } else if (checkflag(FRBADGE_1)) { *mean = 10; *std_deviation = 2; } else { *mean = 5; *std_deviation = 1; } }
bool_t reset_stringlist(stringlist_t *sl) { int i; if( sl ) { if( !checkflag(sl->flags,STRINGLIST_DONTFREE) ) { for(i = 0; i < sl->num; i++) { if( sl->list[i] ) { free((void *)sl->list[i]); } } } sl->num = 0; return TRUE; } return FALSE; }
bool script_cmd_x88_pokemart3(void *script_state){ u16* additional_items = (u16*) overworld_script_read_word(script_state); u16 *item_space = (fmem.dmart); //256 items is the maximum int i = 0; int j = 0; int z; while(mart_items[i]){ u16 to_add = 0; for(z = 0; mart_items[i][z].item; z++){ if(!mart_items[i][z].flag || checkflag(mart_items[i][z].flag)){ to_add = mart_items[i][z].item; break; } } if(to_add){ //check if we can add this item to our list (maybe it is already there) bool contained = false; for(z = 0; z < j; z++){ if(item_space[z] == to_add){ contained = true; break; } } if(!contained){ item_space[j++] = to_add; } } i++; } if(additional_items){ for(i = 0; additional_items[i]; i++){ bool contained = false; for(z = 0; z < j; z++){ if(item_space[z] == additional_items[i]){ contained = true; break; } } if(!contained){ item_space[j++] = additional_items[i]; } } } item_space[j] = 0; pokemart(item_space); mart_state.end_callback = overworld_script_resume; overworld_script_halt(); return true; }
/** * Upgrades savegame from version 1.X to 2.0 */ void version_upgrade_alpha_1_X_to_2_0(){ worldmap_flag_state_set(0x892); worldmap_flag_set(0x892); tmp_hash_new_seed(); setflag(0x96B); //update entire player party int i; for(i = 0; i < pokemon_get_number_in_party(); i++){ pokemon_calculate_stats(&player_pokemon[i]); } //Give Gengarnite if chance was missed in 1.X if(checkflag(0x90A)){ item_add(ITEM_GENGARNIT, 1); } *var_access(SGM_VER) = VERSION_ALPHA_2_0; }
result_t end_tag(void *user, const char_t *name) { parserinfo_cut_t *pinfo = (parserinfo_cut_t *)user; if( pinfo ) { if( checkflag(pinfo->flags,CUT_FLAG_TAG) ) { if( memberof_intervalmgr(&pinfo->im, pinfo->std.depth) ) { write_end_tag_stdout(name); } } else { flush_stringval_stdout(pinfo); write_end_tag_stdout(name); } } return PARSER_OK; }
result_t dfault(void *user, const char_t *data, size_t buflen) { parserinfo_mv_t *pinfo = (parserinfo_mv_t *)user; if( pinfo ) { if( checkflag(pinfo->flags,MV_FLAG_TARGET) ) { cp_dfault_rcm(&pinfo->rcm, &pinfo->std, data, buflen); } else { if( pinfo->std.sel.active ) { write_tempcollect(&pinfo->sav, (byte_t *)data, buflen); } rm_dfault_rcm(&pinfo->rcm, &pinfo->std, data, buflen); } } return PARSER_OK; }
result_t chardata(void *user, const char_t *buf, size_t buflen) { parserinfo_mv_t *pinfo = (parserinfo_mv_t *)user; if( pinfo ) { if( checkflag(pinfo->flags,MV_FLAG_TARGET) ) { cp_chardata_rcm(&pinfo->rcm, &pinfo->std, buf, buflen); } else { if( pinfo->std.sel.active ) { write_coded_entities_tempcollect(&pinfo->sav, buf, buflen); } rm_chardata_rcm(&pinfo->rcm, &pinfo->std, buf, buflen); } } return PARSER_OK; }
/* can add name = NULL, but causes problems with argv_stringlist */ bool_t add_stringlist(stringlist_t *sl, const char_t *name, flag_t flags) { if( sl ) { if( sl->num >= sl->max ) { grow_mem(&sl->list, &sl->max, sizeof(char_t *), 16); } if( sl->num < sl->max ) { if( sl->flags == 0 ) { setflag(&sl->flags,flags); } if( sl->flags == flags ) { sl->list[sl->num] = (checkflag(sl->flags,STRINGLIST_STRDUP) ? (name ? strdup(name) : NULL) : (char_t *)name); sl->num++; return TRUE; } } } return FALSE; }
/* this command interferes with argv_stringlist() */ bool_t strikeout_stringlist(stringlist_t *sl, const char_t *name) { bool_t ok = FALSE; int i; if( sl ) { for(i = 0; i < sl->num; i++) { if( sl->list[i] && (strcmp(name, sl->list[i]) == 0) ) { /* keep this as is */ name = sl->list[i]; sl->list[i] = NULL; if( !checkflag(sl->flags,STRINGLIST_DONTFREE) ) { free((void *)name); } ok = TRUE; } } return ok; } return FALSE; }
result_t chardata(void *user, const char_t *buf, size_t buflen) { parserinfo_cut_t *pinfo = (parserinfo_cut_t *)user; if( pinfo ) { /* stringval is needed to save the string value of the node, as we cannot decide if we want to print it until we've seen it in its entirety */ if( checkflag(pinfo->flags,CUT_FLAG_TAG) ) { if( memberof_intervalmgr(&pinfo->im, pinfo->std.depth + 1) ) { write_coded_entities_stdout(buf, buflen); } } else { write_coded_entities_tempcollect(&pinfo->stringval, buf, buflen); } } return PARSER_OK; }
bool_t format_path_unecho(unecho_t *ue, const xpath_t *xpath) { if( ue ) { if( !equal_xpath(&ue->cp, xpath) ) { /* puts_stdout("not-identical\n"); */ reset_tempvar(&ue->sv); if( checkflag(ue->flags,UNECHO_FLAG_ABSOLUTE) ) { copy_xpath(&ue->cp, xpath); } else { retarget_xpath(&ue->cp, xpath); } putc_tempvar(&ue->sv, '['); puts_tempvar(&ue->sv, string_xpath(&ue->cp)); putc_tempvar(&ue->sv, ']'); copy_xpath(&ue->cp, xpath); return TRUE; } return TRUE; } return FALSE; }
int main(int argc, char* argv[]) { initscr(); scrollok(stdscr, TRUE); wprintw(stdscr, "Welcome to Scripted ver. %d.%d for the Brave Quest engine.\nCopyright 2012 Mad Science Inc.\nPlease do not redistrubute.\n",scriptedvernum,scriptedvernum2); stufffilename(); if(loadscript(filename) == 1) { wprintw(stdscr, "File not Found. Would you like to make a new file?\n"); if(bie() == 'y') { cleanfilebuff(); if(savescript(filename) == 1) { wprintw(stdscr, "Your disk sucks.\n"); bi(); return 1; } } else { wprintw(stdscr, "Goodbye.\n"); endwin(); return 1; } } currlinenum = linenum; menu(); wprintw(stdscr, "Press escape to go to the save menu\n"); for(;;) { wprintw(stdscr, "q= give, w= take, e= say, r= flag, t= move, y= battle, u= check flag, i= check item, o= party add, p= party remove, [ = check character\n"); wprintw(stdscr, "a= warp, s= check experience, d= give experience, f= make experience, g= exec script, h= screen effect, j= user input, k= goline, l= make health\n"); wprintw(stdscr, "b= check stat, n= make stat, m= blank, ,= show line, .= change line.\n"); input[0] = bie(); if(input[0] == 27) menu(); if(input[0] == 'q') give(); if(input[0] == 'w') take(); if(input[0] == 'e') say(); if(input[0] == 'r') flag(); if(input[0] == 't') mmove(); if(input[0] == 'y') battle(); if(input[0] == 'u') checkflag(); if(input[0] == 'i') checkitem(); if(input[0] == 'o') partyadd(); if(input[0] == 'p') partyrm(); if(input[0] == '[') checkparty(); if(input[0] == 'a') warp(); if(input[0] == 's') checkexp(); if(input[0] == 'd') giveexp(); if(input[0] == 'f') makeexp(); if(input[0] == 'g') execscript(); if(input[0] == 'h') screeneffect(); if(input[0] == 'j') userinput(); if(input[0] == 'k') goline(); if(input[0] == 'l') makehealth(); if(input[0] == 'z') teachspell(); if(input[0] == 'x') unlearnspell(); if(input[0] == 'b') checkstat(); if(input[0] == 'n') makestat(); if(input[0] == 'm') blank(); if(input[0] == ',') showline(); if(input[0] == '.') changeline(); if(currlinenum > linenum) linenum = currlinenum; } return 0; };
int main(int argc, char **argv) { signed char op; parserinfo_mv_t pinfo; filelist_t fl; struct option longopts[] = { { "version", 0, NULL, MV_VERSION }, { "help", 0, NULL, MV_HELP }, { "write-files", 0, NULL, MV_FILES }, { "prepend", 0, NULL, MV_PREPEND }, { "replace", 0, NULL, MV_REPLACE }, { "append", 0, NULL, MV_APPEND }, { 0 } }; progname = "xml-mv"; inputfile = ""; inputline = 0; if( create_parserinfo_mv(&pinfo) ) { while( (op = getopt_long(argc, argv, "", longopts, NULL)) > -1 ) { set_option_mv(op, optarg, &pinfo); } init_signal_handling(SIGNALS_DEFAULT); init_file_handling(); init_tempfile_handling(); init_rollback_handling(); if( !checkflag(pinfo.rcm.flags,RCM_CP_PREPEND|RCM_CP_APPEND) ) { setflag(&pinfo.rcm.flags,RCM_CP_APPEND); setflag(&pinfo.rcm.flags,RCM_CP_REPLACE); } if( create_filelist(&fl, -1, argv + optind, FILELIST_MIN2) ) { pinfo.files = getfiles_filelist(&fl); pinfo.xpaths = getxpaths_filelist(&fl); pinfo.n = getsize_filelist(&fl); if( pinfo.n < 2 ) { errormsg(E_FATAL, "no target specified (try --help).\n"); } pinfo.target = pinfo.files[pinfo.n - 1]; pinfo.tpaths = pinfo.xpaths[pinfo.n - 1]; if( !checkflag(pinfo.rcm.flags,RCM_WRITE_FILES) ) { /* When --write-files is not selected, we cannot write * to the files on the command line. So we use the following * trick to implement moves within the target file (last on command * line): we replace all instances of the target with a common * tempfile, which we can write to as required. The first instance * of the target is not replaced, since it must be read (to copy * its contents into the tempfile). */ substitute_target(&pinfo); } if( stdparse2(pinfo.n - 1, pinfo.files, pinfo.xpaths, &pinfo.std) ) { if( reinit_parserinfo_mv(&pinfo) ) { /* output always to stdout */ setflag(&pinfo.rcm.flags, RCM_CP_OUTPUT); clearflag(&pinfo.rcm.flags, RCM_RM_OUTPUT); stdparse2(1, &pinfo.files[pinfo.n - 1], &pinfo.xpaths[pinfo.n - 1], &pinfo.std); } } free_filelist(&fl); } exit_rollback_handling(); exit_tempfile_handling(); exit_file_handling(); exit_signal_handling(); free_parserinfo_mv(&pinfo); } return EXIT_SUCCESS; }