// FIXME: idk how to keep track of the current path on the tty int cd_cmd(int argc, char **argv) { if (argc == 1) { TTY* tty = tty_getCurrentTTY(); u32int currentiNode = tty->currDirectory; fs_node_t current; fs_getFsNode(¤t, currentiNode); fs_node_t *node = finddir_fs(¤t, argv[0]); if (node != NULL) { if (FILE_TYPE(node->mask) == FS_SYMLINK) { char name[MAX_NAME_LENGTH]; read_fs(node, 0, MAX_NAME_LENGTH, (u8int*) name); char* n = name; return cd_cmd(1, (char**) &n);; } if (!permission_file_hasAccess(node, R_BIT)) { printf("cd: You don't have read access to %s\n", argv[0]); return -1; } if (FILE_TYPE(node->mask) == FS_DIRECTORY) { tty->currDirectory = node->inode; memcpy(tty->currPath, node->name, strlen(node->name) + 1); } else { printf("cd: %s is not a directory\n", argv[0]); } kfree(node); } else { printf("cd: The directory \"%s\" does not exist\n", argv[0]); } } return 0; }
int ls_cmd(int argc, char **argv) { boolean showHidden = false; int i = 2; if (argc == 1 && strcmp(argv[0], "-a") == 0) { showHidden = true; i = 0; } fs_node_t current, *node; char perm[MASK_STRING_LEN]; fs_getFsNode(¤t, tty_getCurrentTTY()->currDirectory); while ((node = readdir_fs(¤t, i)) != NULL) { // get directory i tty_setFormatToCurrTTY(video_getFormattedColor(LIGHT_BLUE, BLACK)); if (node->name[0] != '.' || (node->name[0] == '.' && showHidden)) { if (showHidden) { if (i == 0) strcpy(node->name, "."); else if (i == 1) strcpy(node->name, ".."); } mask_string(node->mask, perm); printf("%s\t%5s\t%5s", perm, user_getName(node->uid), group_getName(node->gid)); _ls_cmd_setColor(FILE_TYPE(node->mask)); printf("\t%s%s\n", node->name, _ls_cmd_EndingString(FILE_TYPE(node->mask)) ); } i++; } return 0; }
Chan* gpioopen(Chan *c, int omode) { int type; c = devopen(c, omode, 0, 0, gpiogen); type = FILE_TYPE(c->qid); switch(type) { case Qdata: c->iounit = 1; break; case Qctl: break; case Qevent: lock(&eventlock); if(eventinuse != 0){ c->flag &= ~COPEN; unlock(&eventlock); error(Einuse); } eventinuse = 1; unlock(&eventlock); eventvalue = 0; c->iounit = 4; } return c; }
static gboolean deactivate_plugin(AnjutaPlugin *plugin) { VideoFileTypePlugin *video_filetype_plugin; video_filetype_plugin = (VideoFileTypePlugin*) plugin; gtkpod_unregister_filetype(FILE_TYPE(video_filetype_plugin)); /* FALSE if plugin doesn't want to deactivate */ return TRUE; }
static gboolean activate_plugin(AnjutaPlugin *plugin) { VideoFileTypePlugin *video_filetype_plugin; video_filetype_plugin = (VideoFileTypePlugin*) plugin; g_return_val_if_fail(FILE_IS_TYPE(video_filetype_plugin), TRUE); gtkpod_register_filetype(FILE_TYPE(video_filetype_plugin)); return TRUE; /* FALSE if activation failed */ }
static gboolean activate_plugin(AnjutaPlugin *plugin) { OGGFileTypePlugin *ogg_filetype_plugin; ogg_filetype_plugin = (OGGFileTypePlugin*) plugin; g_return_val_if_fail(FILE_IS_TYPE(ogg_filetype_plugin), TRUE); gtkpod_register_filetype(FILE_TYPE(ogg_filetype_plugin)); set_default_preferences(); return TRUE; /* FALSE if activation failed */ }
int cat_cmd(int argc, char **argv) { if (argc == 1) { fs_node_t current; fs_getFsNode(¤t, tty_getCurrentTTY()->currDirectory); fs_node_t* file = finddir_fs(¤t, argv[0]); char* err = NULL; if (file == NULL) { err = "No such file or directory"; } else if (FILE_TYPE(file->mask) == FS_DIRECTORY) { err = "Is a directory"; } if (err != NULL) { printf("cat: %s: %s\n", argv[0], err); return 0; } if (!permission_file_hasAccess(file, R_BIT)) { printf("cat: You don't have read access to %s", argv[0]); return -1; } if (FILE_TYPE(file->mask) == FS_SYMLINK) { char name[MAX_NAME_LENGTH]; read_fs(file, 0, MAX_NAME_LENGTH, (u8int*) name); char* n = name; return cat_cmd(1, &n); } u8int buff[512]; int offset = 0; int read; while((read = read_fs(file, offset, 512, buff)) != 0) { printf("%s\n", buff); offset += read; } kfree(file); } return 0; }
long gpioread(Chan *c, void *va, long n, vlong off) { int type, scheme; uint pin; char *a; a = va; if(c->qid.type & QTDIR) { return devdirread(c, va, n, 0, 0, gpiogen); } type = FILE_TYPE(c->qid); scheme = SCHEME_TYPE(c->qid); if(scheme != Qgeneric && scheme != pinscheme) { error(nil); } switch(type) { case Qdata: pin = PIN_NUMBER(c->qid); a[0] = (gpioin(pin))?'1':'0'; n = 1; break; case Qctl: break; case Qevent: if(off >= 4) { off %= 4; eventvalue = 0; } sleep(&rend, isset, 0); if(off + n > 4) { n = 4 - off; } memmove(a, &eventvalue + off, n); } return n; }
void gpioclose(Chan *c) { int type; type = FILE_TYPE(c->qid); switch(type) { case Qevent: if(c->flag & COPEN) { if(c->flag & COPEN){ eventinuse = 0; } } break; } }
/* * Open a given text file in the user directory for writing. */ static FILE *my_fopen_wiz(cptr fname) { /* File type is "TEXT" */ FILE_TYPE(FILE_TYPE_TEXT); /* Drop priv's */ safe_setuid_drop(); /* Build and open the filename with the standard name. */ fff = my_fopen_path(ANGBAND_DIR_USER, fname, "w"); /* Grab priv's */ safe_setuid_grab(); /* Warn of errors. */ if (!fff) msg_print("Cannot create spoiler file."); return fff; }
/*! * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporally saved-floor data * @param sf_ptr 保存フロア参照ポインタ * @param mode 保存オプション * @return なし */ bool save_floor(saved_floor_type *sf_ptr, u32b mode) { FILE *old_fff = NULL; byte old_xor_byte = 0; u32b old_v_stamp = 0; u32b old_x_stamp = 0; char floor_savefile[1024]; int fd = -1; bool ok = FALSE; if (!(mode & SLF_SECOND)) { #ifdef SET_UID # ifdef SECURE /* Get "games" permissions */ beGames(); # endif #endif } /* We have one file already opened */ else { /* Backup original values */ old_fff = fff; old_xor_byte = xor_byte; old_v_stamp = v_stamp; old_x_stamp = x_stamp; } /* New savefile */ sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id); /* Grab permissions */ safe_setuid_grab(); /* Remove it */ fd_kill(floor_savefile); /* Drop permissions */ safe_setuid_drop(); /* Attempt to save the player */ /* No file yet */ fff = NULL; /* File type is "SAVE" */ FILE_TYPE(FILE_TYPE_SAVE); /* Grab permissions */ safe_setuid_grab(); /* Create the savefile */ fd = fd_make(floor_savefile, 0644); /* Drop permissions */ safe_setuid_drop(); /* File is okay */ if (fd >= 0) { /* Close the "fd" */ (void)fd_close(fd); /* Grab permissions */ safe_setuid_grab(); /* Open the savefile */ fff = my_fopen(floor_savefile, "wb"); /* Drop permissions */ safe_setuid_drop(); /* Successful open */ if (fff) { /* Write the savefile */ if (save_floor_aux(sf_ptr)) ok = TRUE; /* Attempt to close it */ if (my_fclose(fff)) ok = FALSE; } /* Remove "broken" files */ if (!ok) { /* Grab permissions */ safe_setuid_grab(); (void)fd_kill(floor_savefile); /* Drop permissions */ safe_setuid_drop(); } } if (!(mode & SLF_SECOND)) { #ifdef SET_UID # ifdef SECURE /* Drop "games" permissions */ bePlayer(); # endif #endif } /* We have one file already opened */ else { /* Restore original values */ fff = old_fff; xor_byte = old_xor_byte; v_stamp = old_v_stamp; x_stamp = old_x_stamp; } /* Return the result */ return ok; }
/* * Create a spoiler file for monsters -BEN- */ static void spoil_mon_desc(cptr fname) { int i, n = 0; u16b why = 2; s16b *who; char buf[1024]; char nam[80]; char lev[80]; char rar[80]; char spd[80]; char ac[80]; char hp[80]; char exp[80]; /* Build the filename */ path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname); /* File type is "TEXT" */ FILE_TYPE(FILE_TYPE_TEXT); /* Open the file */ fff = my_fopen(buf, "w"); /* Oops */ if (!fff) { msg_print("Cannot create spoiler file."); return; } /* Allocate the "who" array */ C_MAKE(who, max_r_idx, s16b); /* Dump the header */ fprintf(fff, "Spoiler File -- Monsters (PosChengband %d.%d.%d)\n\n\n", VER_MAJOR, VER_MINOR, VER_PATCH); fprintf(fff, "------------------------------------------\n\n"); /* Dump the header */ fprintf(fff, " %-38.38s%4s%4s%4s%7s%5s %11.11s\n", "Name", "Lev", "Rar", "Spd", "Hp", "Ac", "Visual Info"); fprintf(fff, "%-42.42s%4s%4s%4s%7s%5s %11.11s\n", "--------", "---", "---", "---", "--", "--", "-----------"); /* Scan the monsters */ for (i = 1; i < max_r_idx; i++) { monster_race *r_ptr = &r_info[i]; /* Use that monster */ if (r_ptr->name) who[n++] = i; } /* Select the sort method */ ang_sort_comp = ang_sort_comp_hook; ang_sort_swap = ang_sort_swap_hook; /* Sort the array by dungeon depth of monsters */ ang_sort(who, &why, n); /* Scan again */ for (i = 0; i < n; i++) { monster_race *r_ptr = &r_info[who[i]]; cptr name = (r_name + r_ptr->name); if (r_ptr->flags7 & (RF7_KAGE)) continue; /* Get the "name" */ /* else if (r_ptr->flags1 & (RF1_QUESTOR)) { sprintf(nam, "[Q] %s", name); } */ else if (r_ptr->flags1 & (RF1_UNIQUE)) { sprintf(nam, "[U] %s", name); } else { sprintf(nam, "The %s", name); } /* Level */ sprintf(lev, "%d", r_ptr->level); /* Rarity */ sprintf(rar, "%d", r_ptr->rarity); /* Speed */ if (r_ptr->speed >= 110) { sprintf(spd, "+%d", (r_ptr->speed - 110)); } else { sprintf(spd, "-%d", (110 - r_ptr->speed)); } /* Armor Class */ sprintf(ac, "%d", r_ptr->ac); /* Hitpoints */ if ((r_ptr->flags1 & (RF1_FORCE_MAXHP)) || (r_ptr->hside == 1)) { sprintf(hp, "%d", r_ptr->hdice * r_ptr->hside); } else { sprintf(hp, "%dd%d", r_ptr->hdice, r_ptr->hside); } /* Experience */ sprintf(exp, "%d", r_ptr->mexp); /* Hack -- use visual instead */ sprintf(exp, "%s '%c'", attr_to_text(r_ptr), r_ptr->d_char); /* Dump the info */ fprintf(fff, "%-42.42s%4s%4s%4s%7s%5s %11.11s\n", nam, lev, rar, spd, hp, ac, exp); } /* End it */ fprintf(fff, "\n"); /* Free the "who" array */ C_KILL(who, max_r_idx, s16b); /* Check for errors */ if (ferror(fff) || my_fclose(fff)) { msg_print("Cannot close spoiler file."); return; } /* Worked */ msg_print("Successfully created a spoiler file."); }
/* * Save a "bones" file for a dead character * * Should probably attempt some form of locking... */ void make_bones(void) { #if 0 /* DGDGDGDG */ FILE *fp; int i; char str[1024]; /* Ignore wizards and borgs */ if (!(noscore & 0x00FF)) { /* Ignore people who die in town */ if (dun_level) { int level; char tmp[128]; /* Slightly more tenacious saving routine. */ for (i = 0; i < 5; i++) { /* Ghost hovers near level of death. */ if (i == 0) level = dun_level; else level = dun_level + 5 - damroll(2, 4); if (level < 1) level = randint(4); /* XXX XXX XXX "Bones" name */ sprintf(tmp, "bone%03d.%03d", dungeon_type, level); /* Build the filename */ path_build(str, 1024, ANGBAND_DIR_BONE, tmp); /* Grab permission */ safe_setuid_grab(); /* Attempt to open the bones file */ fp = my_fopen(str, "r"); /* Drop permission */ safe_setuid_drop(); /* Close it right away */ if (fp) my_fclose(fp); /* Do not over-write a previous ghost */ if (fp) continue; /* If no file by that name exists, we can make a new one. */ if (!(fp)) break; } /* File type is "TEXT" */ FILE_TYPE(FILE_TYPE_TEXT); /* Grab permission */ safe_setuid_grab(); /* Try to write a new "Bones File" */ fp = my_fopen(str, "w"); /* Drop permission */ safe_setuid_drop(); /* Not allowed to write it? Weird. */ if (!fp) return; /* Save the info */ fprintf(fp, "%s\n", player_name); fprintf(fp, "%d\n", p_ptr->mhp); fprintf(fp, "%d\n", p_ptr->prace); fprintf(fp, "%d\n", p_ptr->pclass); /* Close and save the Bones file */ my_fclose(fp); } } #endif }
/*! * @brief セーブデータ書き込みのサブルーチン / * Medium level player saver * @return 成功すればtrue * @details * XXX XXX XXX Angband 2.8.0 will use "fd" instead of "fff" if possible */ static bool save_player_aux(char *name) { bool ok = FALSE; int fd = -1; int mode = 0644; /* No file yet */ fff = NULL; /* File type is "SAVE" */ FILE_TYPE(FILE_TYPE_SAVE); /* Grab permissions */ safe_setuid_grab(); /* Create the savefile */ fd = fd_make(name, mode); /* Drop permissions */ safe_setuid_drop(); /* File is okay */ if (fd >= 0) { /* Close the "fd" */ (void)fd_close(fd); /* Grab permissions */ safe_setuid_grab(); /* Open the savefile */ fff = my_fopen(name, "wb"); /* Drop permissions */ safe_setuid_drop(); /* Successful open */ if (fff) { /* Write the savefile */ if (wr_savefile_new()) ok = TRUE; /* Attempt to close it */ if (my_fclose(fff)) ok = FALSE; } /* Grab permissions */ safe_setuid_grab(); /* Remove "broken" files */ if (!ok) (void)fd_kill(name); /* Drop permissions */ safe_setuid_drop(); } /* Failure */ if (!ok) return (FALSE); counts_write(0, playtime); /* Successful save */ character_saved = TRUE; /* Success */ return (TRUE); }
/* * Create a spoiler file for monsters * [email protected] (Shawn McHorse) */ static void spoil_mon_info(cptr fname) { char buf[1024]; int i, n; u16b why = 2; u16b *who; int count = 0; /* Build the filename */ (void)path_build(buf, sizeof(buf), ANGBAND_DIR_INFO, fname); /* File type is "TEXT" */ FILE_TYPE(FILE_TYPE_TEXT); /* Open the file */ fff = my_fopen(buf, "w"); /* Oops */ if (!fff) { msg_print("Cannot create spoiler file."); return; } /* Dump to the spoiler file */ text_out_hook = text_out_to_file; text_out_file = fff; /* Print header */ print_header("Full Monster"); /* Allocate the "who" array */ C_MAKE(who, z_info->r_max, u16b); /* Scan the monsters */ for (i = 1; i < z_info->r_max; i++) { monster_race *r_ptr = &r_info[i]; /* Use that monster */ if (r_ptr->name) who[count++] = (u16b)i; } /* Select the sort method */ ang_sort_comp = ang_sort_comp_hook; ang_sort_swap = ang_sort_swap_hook; /* Sort the array by dungeon depth of monsters */ ang_sort(who, &why, count); /* * List all monsters in order. */ for (n = 0; n < count; n++) { int r_idx = who[n]; monster_race *r_ptr = &r_info[r_idx]; /* Prefix */ if (r_ptr->flags1 & RF1_QUESTOR) { text_out("[Q] "); } else if (r_ptr->flags1 & RF1_UNIQUE) { text_out("[U] "); } else { text_out("The "); } /* Name */ (void)strnfmt(buf, sizeof(buf), "%s (", (r_name + r_ptr->name)); /* ---)--- */ text_out(buf); /* Color */ text_out(attr_to_text(r_ptr->d_attr)); /* Symbol --(-- */ (void)strnfmt(buf, sizeof(buf), " '%c')\n", r_ptr->d_char); text_out(buf); /* Indent */ (void)strnfmt(buf, sizeof(buf), "=== "); text_out(buf); /* Number */ (void)strnfmt(buf, sizeof(buf), "Num:%d ", r_idx); text_out(buf); /* Level */ (void)strnfmt(buf, sizeof(buf), "Lev:%d ", r_ptr->level); text_out(buf); /* Rarity */ (void)strnfmt(buf, sizeof(buf), "Rar:%d ", r_ptr->rarity); text_out(buf); /* Speed */ if (r_ptr->speed >= 110) { (void)strnfmt(buf, sizeof(buf), "Spd:+%d ", (r_ptr->speed - 110)); } else { (void)strnfmt(buf, sizeof(buf), "Spd:-%d ", (110 - r_ptr->speed)); } text_out(buf); /* Hitpoints */ if (r_ptr->flags1 & (RF1_FIXED_HPS)) { (void)strnfmt(buf, sizeof(buf), "%d", r_ptr->hitpoints); } else { (void)strnfmt(buf, sizeof(buf), "~%d", r_ptr->hitpoints); } text_out(buf); /* Armor Class */ (void)strnfmt(buf, sizeof(buf), "Ac:%d ", r_ptr->ac); text_out(buf); /* Experience */ (void)strnfmt(buf, sizeof(buf), "Exp:%ld\n", (long)(r_ptr->mexp)); text_out(buf); /* Describe */ describe_monster(r_idx, TRUE); /* Terminate the entry */ text_out("\n"); } /* Free the "who" array */ FREE(who); /* Check for errors */ if (ferror(fff) || my_fclose(fff)) { msg_print("Cannot close spoiler file."); return; } msg_print("Successfully created a spoiler file."); }
/*! * @brief 現在のオプション設定をダンプ出力する / * Hack -- Dump option bits usage * @return なし */ static void do_cmd_dump_options(void) { int i, j; FILE *fff; char buf[1024]; int **exist; /* Build the filename */ path_build(buf, sizeof buf, ANGBAND_DIR_USER, "opt_info.txt"); /* File type is "TEXT" */ FILE_TYPE(FILE_TYPE_TEXT); /* Open the file */ fff = my_fopen(buf, "a"); /* Oops */ if (!fff) { msg_format(_("ファイル %s を開けませんでした。", "Failed to open file %s."), buf); msg_print(NULL); return; } /* Allocate the "exist" array (2-dimension) */ C_MAKE(exist, NUM_O_SET, int *); C_MAKE(*exist, NUM_O_BIT * NUM_O_SET, int); for (i = 1; i < NUM_O_SET; i++) exist[i] = *exist + i * NUM_O_BIT; /* Check for exist option bits */ for (i = 0; option_info[i].o_desc; i++) { const option_type *ot_ptr = &option_info[i]; if (ot_ptr->o_var) exist[ot_ptr->o_set][ot_ptr->o_bit] = i + 1; } fprintf(fff, "[Option bits usage on Hengband %d.%d.%d]\n\n", FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH); fputs("Set - Bit (Page) Option Name\n", fff); fputs("------------------------------------------------\n", fff); /* Dump option bits usage */ for (i = 0; i < NUM_O_SET; i++) { for (j = 0; j < NUM_O_BIT; j++) { if (exist[i][j]) { const option_type *ot_ptr = &option_info[exist[i][j] - 1]; fprintf(fff, " %d - %02d (%4d) %s\n", i, j, ot_ptr->o_page, ot_ptr->o_text); } else { fprintf(fff, " %d - %02d\n", i, j); } } fputc('\n', fff); } /* Free the "exist" array (2-dimension) */ C_KILL(*exist, NUM_O_BIT * NUM_O_SET, int); C_KILL(exist, NUM_O_SET, int *); /* Close it */ my_fclose(fff); msg_format(_("オプションbit使用状況をファイル %s に書き出しました。", "Option bits usage dump saved to file %s."), buf); }
/* * Show what object kinds appear on the current level */ static void spoil_obj_gen(cptr fname) { int i, j; int tmp_object_level = object_level; int old_depth = p_ptr->depth; /* Storage */ u32b artifacts = 0L; u32b egoitems = 0L; u32b object[1500]; s16b ego_item[500]; s16b artifact[ART_MIN_RANDOM + 1]; u32b tval[TV_MAX]; u32b depth[MAX_DEPTH]; object_type *i_ptr; object_type object_type_body; char o_name[DESC_LEN]; char buf[1024]; if (!get_check("This will take quite a while (as in, go read a book). Are you certain you want to print out object generation statistics (y/n)?")) { return; } /* Build the filename */ (void)path_build(buf, sizeof(buf), ANGBAND_DIR_INFO, fname); /* File type is "TEXT" */ FILE_TYPE(FILE_TYPE_TEXT); /* Open the file */ fff = my_fopen(buf, "w"); /* Oops */ if (!fff) { msg_print("Cannot create spoiler file."); return; } /* Warning */ msg_print("This will take quite a while..."); if (!fresh_after) (void)Term_fresh(); /* Dump to the spoiler file */ text_out_hook = text_out_to_file; text_out_file = fff; /* Print header */ print_header("Object Generation"); /* Initialize object level */ object_level = 0; p_ptr->depth = 0; /* Handle various possible depths */ while (TRUE) { /* Go from level 5 to level 100 inclusive */ if (object_level >= 100) break; object_level += 5; p_ptr->depth += 5; artifacts = 0L; egoitems = 0L; /* Clear storage. */ for (i = 0; i < z_info->k_max; i++) { object[i] = 0L; } /* Clear storage. */ for (i = 0; i < MAX_DEPTH; i++) { depth[i] = 0L; } /* Clear storage. */ for (i = 0; i < TV_MAX; i++) { tval[i] = 0L; } /* Clear storage. */ for (i = 0; i < ART_MIN_RANDOM + 1; i++) { artifact[i] = 0; } /* Clear storage. */ for (i = 0; i < z_info->e_max; i++) { ego_item[i] = 0; } /* Make a lot of objects */ for (i = 0L; i < 1000000L; i++) { /* Get local object */ i_ptr = &object_type_body; /* Create an object - no special conditions */ make_object(i_ptr, FALSE, FALSE, FALSE); /* Count artifacts. */ if (i_ptr->artifact_index) artifacts += 1L; /* Count ego-items. */ if (i_ptr->ego_item_index) egoitems += 1L; /* Count object by index (note quantity). */ object[i_ptr->k_idx] += i_ptr->number; /* Count objects of that level (only one at a time). */ depth[k_info[i_ptr->k_idx].level] += 1L; /* Count object kinds. */ tval[i_ptr->tval] += 1L; /* Count artifacts */ if (i_ptr->artifact_index) { if (i_ptr->artifact_index < ART_MIN_RANDOM) { artifact[i_ptr->artifact_index]++; } else { artifact[ART_MIN_RANDOM]++; } } /* Count ego-items */ else if (i_ptr->ego_item_index) { ego_item[i_ptr->ego_item_index]++; } /* Mega-Hack -- allow multiple artifacts XXX XXX XXX */ if (artifact_p(i_ptr)) a_info[i_ptr->artifact_index].cur_num = 0; } /* Print to file. */ fprintf(fff, "\n\n\n\n"); fprintf(fff, "----------------------------------------\n"); fprintf(fff, " Generation Level: %d\n\n", object_level); fprintf(fff, "Number of objects created (1,000,000 total)\n"); fprintf(fff, "\n"); for (i = 1; i < z_info->k_max; i++) { if (object[i]) { object_kind *k_ptr = &k_info[i]; char *t; cptr str = (k_name + k_ptr->name); cptr desc; if (str == "") continue; /* Skip past leading characters */ while ((*str == ' ') || (*str == '&')) str++; /* Copy useful chars */ for (t = o_name; *str; str++) { if (*str != '~') *t++ = *str; } /* Terminate the new name */ *t = '\0'; /* Try to find this tval in the list */ for (j = 0; tvals[j].tval; j++) { if (tvals[j].tval == k_ptr->tval) break; } if (!tvals[j].tval) desc = "unknown"; else desc = tvals[j].desc; fprintf(fff, "%-20s:%-40s:%6ld\n", desc, o_name, (long)object[i]); } } /* Header -- tval abundance */ fprintf(fff, "\n\n"); fprintf(fff, "Object tvals\n\n"); /* Scan all the tvals */ for (i = 1; i < TV_MAX; i++) { /* Objects with this tval never appeared */ if (!tval[i]) continue; /* Try to find this tval in the list */ for (j = 0; tvals[j].tval; j++) { if (tvals[j].tval == i) break; } /* Tval has no description -- skip it */ if (!tvals[j].tval) continue; /* Print out a description of the tval and its abundance */ fprintf(fff, "%-20s:%6ld\n", tvals[j].desc, (long)tval[i]); } fprintf(fff, "\n\n"); fprintf(fff, "Object distribution by depth\n\n"); for (i = 0; i < MAX_DEPTH; i++) { if (depth[i]) fprintf(fff, "Level %3d:%6ld\n", i, (long)depth[i]); } fprintf(fff, "\n\n"); fprintf(fff, "artifacts: %ld\n", (long)artifacts); for (i = 0; i < ART_MIN_RANDOM + 1; i++) { artifact_type *a_ptr = &a_info[i]; cptr str = (a_name + a_ptr->name); if (artifact[i]) fprintf(fff, " %-40s:%4d\n", str, artifact[i]); } fprintf(fff, "\n\n"); fprintf(fff, "ego-items: %ld\n\n", (long)egoitems); for (i = 0; i < z_info->e_max; i++) { ego_item_type *e_ptr = &e_info[i]; cptr str = (e_name + e_ptr->name); if (ego_item[i]) fprintf(fff, " %-40s:%4d\n", str, ego_item[i]); } } /* Reset object generation level */ object_level = tmp_object_level; p_ptr->depth = old_depth; /* Check for errors */ if (ferror(fff) || my_fclose(fff)) { msg_print("Cannot close spoiler file."); return; } /* Message */ msg_print("Successfully created a spoiler file."); }
/* * Create a spoiler file for items */ void spoil_obj_desc(cptr fname) { int i, k, s, t, n = 0; u16b who[256]; char buf[1024]; char wgt[DESC_LEN]; char dam[DESC_LEN]; /* We use either ascii or system-specific encoding */ int encoding = (xchars_to_file) ? SYSTEM_SPECIFIC : ASCII; /* Build the filename */ (void)path_build(buf, sizeof(buf), ANGBAND_DIR_INFO, fname); /* File type is "TEXT" */ FILE_TYPE(FILE_TYPE_TEXT); /* Open the file */ fff = my_fopen(buf, "w"); /* Oops */ if (!fff) { msg_print("Cannot create spoiler file."); return; } /* Dump to the spoiler file */ text_out_hook = text_out_to_file; text_out_file = fff; /* Print header */ print_header("Object"); /* More Header */ x_fprintf(fff, encoding, "%-45s %8s%7s%5s%9s\n", "Description", "Dam/AC", "Wgt", "Lev", "Cost"); x_fprintf(fff, encoding, "%-45s %8s%7s%5s%9s\n", "----------------------------------------", "------", "---", "---", "----"); /* List the groups */ for (i = 0; TRUE; i++) { /* Write out the group title */ if (group_item[i].name) { /* Hack -- bubble-sort by cost and then level */ for (s = 0; s < n - 1; s++) { for (t = 0; t < n - 1; t++) { int i1 = t; int i2 = t + 1; int e1; int e2; s32b t1; s32b t2; kind_info(NULL, NULL, NULL, &e1, &t1, who[i1]); kind_info(NULL, NULL, NULL, &e2, &t2, who[i2]); if ((t1 > t2) || ((t1 == t2) && (e1 > e2))) { int tmp = who[i1]; who[i1] = who[i2]; who[i2] = tmp; } } } /* Spoil each item */ for (s = 0; s < n; s++) { int e; s32b v; /* Describe the kind */ kind_info(buf, dam, wgt, &e, &v, who[s]); /* Dump it */ if (!strlen(dam)) x_fprintf(fff, encoding, " %-53s%7s%5d%9ld\n", buf, wgt, e, (long)(v)); else x_fprintf(fff, encoding, " %-45s%8s%7s%5d%9ld\n", buf, dam, wgt, e, (long)(v)); } /* Start a new set */ n = 0; /* Notice the end */ if (!group_item[i].tval) break; /* Start a new set */ x_fprintf(fff, encoding, "\n\n%s\n\n", group_item[i].name); } /* Acquire legal item types */ for (k = 1; k < z_info->k_max; k++) { object_kind *k_ptr = &k_info[k]; /* Skip objects not of this tval */ if (k_ptr->tval != group_item[i].tval) continue; /* Hack -- Skip instant-artifacts */ if (k_ptr->flags3 & (TR3_INSTA_ART)) continue; /* Save the index */ who[n++] = k; } } /* Check for errors */ if (ferror(fff) || my_fclose(fff)) { msg_print("Cannot close spoiler file."); return; } /* Message */ msg_print("Successfully created a spoiler file."); }
/* * Show what monster races appear on the current level */ static void spoil_mon_gen(cptr fname) { int i, num; /* Storage */ u32b monster[1000]; u32b depth[MAX_DEPTH]; char buf[1024]; /* We use either ascii or system-specific encoding */ int encoding = (xchars_to_file) ? SYSTEM_SPECIFIC : ASCII; /* Build the filename */ (void)path_build(buf, sizeof(buf), ANGBAND_DIR_INFO, fname); /* File type is "TEXT" */ FILE_TYPE(FILE_TYPE_TEXT); /* Open the file */ fff = my_fopen(buf, "w"); /* Oops */ if (!fff) { msg_print("Cannot create spoiler file."); return; } /* Dump to the spoiler file */ text_out_hook = text_out_to_file; text_out_file = fff; /* Print header */ print_header("Monster Generation"); /* Clear storage. */ for (i = 0; i < z_info->r_max; i++) { monster[i] = 0L; } /* Clear storage. */ for (i = 0; i < MAX_DEPTH; i++) { depth[i] = 0L; } msg_print("This may take a while..."); if (!fresh_after) (void)Term_fresh(); /* Make a lot of monsters, and print their names out. */ for (i = 0L; i < 1000000L; i++) { if (i % 10000 == 0) { prt(format("%ld monsters created", (long)i), 0, 0); if (!fresh_after) (void)Term_fresh(); } /* Get a monster index */ num = get_mon_num(p_ptr->depth); /* Count monster races. */ monster[num] += 1L; /* Count monsters of that level. */ depth[r_info[num].level] += 1L; } /* Print to file. */ fprintf(fff, "\n\n\n"); fprintf(fff, "Number of monsters of various kinds (1,000,000 total)\n"); fprintf(fff, " Generation Level: %d\n\n", p_ptr->depth); for (i = 1; i < z_info->r_max; i++) { monster_race *r_ptr = &r_info[i]; cptr name = (r_name + r_ptr->name); if (monster[i]) { x_fprintf(fff, encoding, "%-45s:%6ld\n", name, (long)monster[i]); } } fprintf(fff, "\n\n\n"); fprintf(fff, "Monster distribution by depth\n\n"); for (i = 0; i < MAX_DEPTH; i++) { if (depth[i]) fprintf(fff, "Level %3d:%6ld\n", i, (long)depth[i]); } /* Check for errors */ if (ferror(fff) || my_fclose(fff)) { msg_print("Cannot close spoiler file."); return; } /* Message */ msg_print("Successfully created a spoiler file."); }
/* * Create a spoiler file for items */ static void spoil_obj_desc(cptr fname) { int i, k, s, t, n = 0, group_start = 0; u16b who[200]; char buf[1024]; char wgt[80]; char dam[80]; /* Build the filename */ path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname); /* File type is "TEXT" */ FILE_TYPE(FILE_TYPE_TEXT); /* Open the file */ fff = my_fopen(buf, "w"); /* Oops */ if (!fff) { msg_print("Cannot create spoiler file."); return; } /* Header */ fprintf(fff, "Spoiler File -- Basic Items (PosChengband %d.%d.%d)\n\n\n", VER_MAJOR, VER_MINOR, VER_PATCH); /* More Header */ fprintf(fff, "%-45s %8s%7s%5s%9s\n", "Description", "Dam/AC", "Wgt", "Lev", "Cost"); fprintf(fff, "%-45s %8s%7s%5s%9s\n", "----------------------------------------", "------", "---", "---", "----"); /* List the groups */ for (i = 0; TRUE; i++) { /* Write out the group title */ if (group_item[i].name) { if (n) { /* Hack -- bubble-sort by cost and then level */ for (s = 0; s < n - 1; s++) { for (t = 0; t < n - 1; t++) { int i1 = t; int i2 = t + 1; int e1; int e2; s32b t1; s32b t2; kind_info(NULL, NULL, NULL, &e1, &t1, who[i1]); kind_info(NULL, NULL, NULL, &e2, &t2, who[i2]); if ((t1 > t2) || ((t1 == t2) && (e1 > e2))) { int tmp = who[i1]; who[i1] = who[i2]; who[i2] = tmp; } } } fprintf(fff, "\n\n%s\n\n", group_item[group_start].name); /* Spoil each item */ for (s = 0; s < n; s++) { int e; s32b v; /* Describe the kind */ kind_info(buf, dam, wgt, &e, &v, who[s]); /* Dump it */ fprintf(fff, " %-45s%8s%7s%5d%9d\n", buf, dam, wgt, e, v); } /* Start a new set */ n = 0; } /* Notice the end */ if (!group_item[i].tval) break; /* Start a new set */ group_start = i; } /* Acquire legal item types */ for (k = 1; k < max_k_idx; k++) { object_kind *k_ptr = &k_info[k]; /* Skip wrong tval's */ if (k_ptr->tval != group_item[i].tval) continue; /* Hack -- Skip instant-artifacts */ if (k_ptr->gen_flags & (OFG_INSTA_ART)) continue; /* Save the index */ who[n++] = k; } } /* Check for errors */ if (ferror(fff) || my_fclose(fff)) { msg_print("Cannot close spoiler file."); return; } /* Message */ msg_print("Successfully created a spoiler file."); }
/* * Create a spoiler file for artifacts */ static void spoil_artifact(cptr fname) { int i, j; object_type *i_ptr; object_type object_type_body; char buf[1024]; /* We use either ascii or system-specific encoding */ int encoding = (xchars_to_file) ? SYSTEM_SPECIFIC : ASCII; /* Build the filename */ (void)path_build(buf, sizeof(buf), ANGBAND_DIR_INFO, fname); /* File type is "TEXT" */ FILE_TYPE(FILE_TYPE_TEXT); /* Open the file */ fff = my_fopen(buf, "w"); /* Oops */ if (!fff) { msg_print("Cannot create spoiler file."); return; } /* Dump to the spoiler file */ text_out_hook = text_out_to_file; text_out_file = fff; /* Dump the header */ print_header("Artifact"); /* List the artifacts by tval */ for (i = 0; group_artifact[i].tval; i++) { /* Write out the group title */ if (group_artifact[i].name) { spoiler_blanklines(2); spoiler_underline(group_artifact[i].name); spoiler_blanklines(1); } /* Now search through all of the artifacts */ for (j = 0; j < z_info->a_max; ++j) { artifact_type *a_ptr = &a_info[j]; /* We only want objects in the current group */ if (a_ptr->tval != group_artifact[i].tval) continue; /* Get local object */ i_ptr = &object_type_body; /* Attempt to create the artifact */ if (!make_fake_artifact(i_ptr, j)) continue; /* Get this artifact */ a_ptr = &a_info[i_ptr->artifact_index]; /* Write a description of the artifact */ object_desc_store(buf, sizeof(buf), i_ptr, TRUE, 1); x_fprintf(fff, encoding, buf); fprintf(fff, "\n"); /* Write pval, flag, and activation information */ dump_obj_attrib(fff, i_ptr, 2); /* Write level, rarity, and weight */ if (use_metric) fprintf(fff, " Level %u, Rarity %u, %d.%d kgs, " "%ld Gold", a_ptr->level, a_ptr->rarity, make_metric(a_ptr->weight) / 10, make_metric(a_ptr->weight) % 10, a_ptr->cost); else fprintf(fff, " Level %u, Rarity %u, %d.%d lbs, " "%ld Gold", a_ptr->level, a_ptr->rarity, a_ptr->weight / 10, a_ptr->weight % 10, (long)a_ptr->cost); /* Insert a spacer line */ fprintf(fff, "\n\n"); } } /* Check for errors */ if (ferror(fff) || my_fclose(fff)) { msg_print("Cannot close spoiler file."); return; } /* Message */ msg_print("Successfully created a spoiler file."); }
/* * Create a spoiler file for monsters */ static void spoil_mon_desc(cptr fname) { int i, n = 0; char buf[1024]; /* We use either ascii or system-specific encoding */ int encoding = (xchars_to_file) ? SYSTEM_SPECIFIC : ASCII; char nam[DESC_LEN]; char lev[32]; char rar[32]; char spd[32]; char ac[32]; char hp[32]; char exp[32]; u16b *who; u16b why = 2; /* Build the filename */ (void)path_build(buf, sizeof(buf), ANGBAND_DIR_INFO, fname); /* File type is "TEXT" */ FILE_TYPE(FILE_TYPE_TEXT); /* Open the file */ fff = my_fopen(buf, "w"); /* Oops */ if (!fff) { msg_print("Cannot create spoiler file."); return; } /* Dump to the spoiler file */ text_out_hook = text_out_to_file; text_out_file = fff; /* Print header */ print_header("Brief Monster"); /* Dump the header */ fprintf(fff, "%-40.40s%4s%4s%6s%8s%4s %11.11s\n", "Name", "Lev", "Rar", "Spd", "Hp", "Ac", "Visual Info"); fprintf(fff, "%-40.40s%4s%4s%6s%8s%4s %11.11s\n", "----", "---", "---", "---", "--", "--", "-----------"); /* Allocate the "who" array */ C_MAKE(who, z_info->r_max, u16b); /* Scan the monsters */ for (i = 1; i < z_info->r_max; i++) { monster_race *r_ptr = &r_info[i]; /* Use that monster */ if (r_ptr->name) who[n++] = (u16b)i; } /* Select the sort method */ ang_sort_comp = ang_sort_comp_hook; ang_sort_swap = ang_sort_swap_hook; /* Sort the array by dungeon depth of monsters */ ang_sort(who, &why, n); /* Scan again */ for (i = 0; i < n; i++) { monster_race *r_ptr = &r_info[who[i]]; cptr name = (r_name + r_ptr->name); /* Get the "name" */ if (r_ptr->flags1 & (RF1_QUESTOR)) { (void)strnfmt(nam, sizeof(nam), "[Q] %s", name); } else if (r_ptr->flags1 & (RF1_UNIQUE)) { (void)strnfmt(nam, sizeof(nam), "[U] %s", name); } else { (void)strnfmt(nam, sizeof(nam), "The %s", name); } /* Level */ (void)strnfmt(lev, sizeof(lev), "%d", r_ptr->level); /* Rarity */ (void)strnfmt(rar, sizeof(rar), "%d", r_ptr->rarity); /* Speed */ (void)strnfmt(spd, sizeof(spd), "%+d", (r_ptr->speed - 110)); /* Armor Class */ (void)strnfmt(ac, sizeof(ac), "%d", r_ptr->ac); /* Hitpoints */ if (r_ptr->flags1 & (RF1_FIXED_HPS)) { (void)strnfmt(hp, sizeof(hp), "%d", (int)r_ptr->hitpoints); } else { (void)strnfmt(hp, sizeof(hp), "~%d", (int)r_ptr->hitpoints); } /* Experience */ (void)strnfmt(exp, sizeof(exp), "%ld", (long)(r_ptr->mexp)); /* Hack -- use visual instead */ (void)strnfmt(exp, sizeof(exp), "%s '%c'", attr_to_text(r_ptr->d_attr), r_ptr->d_char); /* Dump the info */ x_fprintf(fff, encoding, "%-40.40s%4s%4s%6s%8s%4s %11.11s\n", nam, lev, rar, spd, hp, ac, exp); } /* End it */ fprintf(fff, "\n"); /* Free the "who" array */ FREE(who); /* Check for errors */ if (ferror(fff) || my_fclose(fff)) { msg_print("Cannot close spoiler file."); return; } /* Worked */ msg_print("Successfully created a spoiler file."); }
/* * Initialize a "*_info" array * * Note that we let each entry have a unique "name" and "text" string, * even if the string happens to be empty (everyone has a unique '\0'). */ static errr init_info(cptr filename, header *head) { int fd; errr err = 1; FILE *fp; /* General buffer */ char buf[1024]; #ifdef ALLOW_TEMPLATES /*** Load the binary image file ***/ /* Build the filename */ path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename)); /* Attempt to open the "raw" file */ fd = fd_open(buf, O_RDONLY); /* Process existing "raw" file */ if (fd >= 0) { #ifdef CHECK_MODIFICATION_TIME err = check_modification_date(fd, format("%s.txt", filename)); #endif /* CHECK_MODIFICATION_TIME */ /* Attempt to parse the "raw" file */ if (!err) err = init_info_raw(fd, head); /* Close it */ fd_close(fd); } /* Do we have to parse the *.txt file? */ if (err) { /*** Make the fake arrays ***/ /* Allocate the "*_info" array */ C_MAKE(head->info_ptr, head->info_size, char); /* MegaHack -- make "fake" arrays */ if (z_info) { C_MAKE(head->name_ptr, z_info->fake_name_size, char); C_MAKE(head->text_ptr, z_info->fake_text_size, char); } /*** Load the ascii template file ***/ /* Build the filename */ path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename)); /* Open the file */ fp = my_fopen(buf, "r"); /* Parse it */ if (!fp) quit(format("Cannot open '%s.txt' file.", filename)); /* Parse the file */ err = init_info_txt(fp, buf, head, head->parse_info_txt); /* Close it */ my_fclose(fp); /* Errors */ if (err) display_parse_error(filename, err, buf); /*** Dump the binary image file ***/ /* File type is "DATA" */ FILE_TYPE(FILE_TYPE_DATA); /* Build the filename */ path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename)); /* Attempt to open the file */ fd = fd_open(buf, O_RDONLY); /* Failure */ if (fd < 0) { int mode = 0644; /* Grab permissions */ safe_setuid_grab(); /* Create a new file */ fd = fd_make(buf, mode); /* Drop permissions */ safe_setuid_drop(); /* Failure */ if (fd < 0) { char why[1024]; /* Message */ strnfmt(why, sizeof(why), "Cannot create the '%s' file!", buf); /* Crash and burn */ quit(why); } } /* Close it */ fd_close(fd); /* Grab permissions */ safe_setuid_grab(); /* Attempt to create the raw file */ fd = fd_open(buf, O_WRONLY); /* Drop permissions */ safe_setuid_drop(); /* Dump to the file */ if (fd >= 0) { /* Dump it */ fd_write(fd, (cptr)head, head->head_size); /* Dump the "*_info" array */ fd_write(fd, head->info_ptr, head->info_size); /* Dump the "*_name" array */ fd_write(fd, head->name_ptr, head->name_size); /* Dump the "*_text" array */ fd_write(fd, head->text_ptr, head->text_size); /* Close */ fd_close(fd); } /*** Kill the fake arrays ***/ /* Free the "*_info" array */ KILL(head->info_ptr); /* MegaHack -- Free the "fake" arrays */ if (z_info) { KILL(head->name_ptr); KILL(head->text_ptr); } #endif /* ALLOW_TEMPLATES */ /*** Load the binary image file ***/ /* Build the filename */ path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename)); /* Attempt to open the "raw" file */ fd = fd_open(buf, O_RDONLY); /* Process existing "raw" file */ if (fd < 0) quit(format("Cannot load '%s.raw' file.", filename)); /* Attempt to parse the "raw" file */ err = init_info_raw(fd, head); /* Close it */ fd_close(fd); /* Error */ if (err) quit(format("Cannot parse '%s.raw' file.", filename)); #ifdef ALLOW_TEMPLATES } #endif /* ALLOW_TEMPLATES */ /* Success */ return (0); }
long gpiowrite(Chan *c, void *va, long n, vlong) { int type, i, scheme; uint pin; char *arg; Cmdbuf *cb; Cmdtab *ct; if(c->qid.type & QTDIR) { error(Eisdir); } type = FILE_TYPE(c->qid); scheme = SCHEME_TYPE(c->qid); if(scheme != Qgeneric && scheme != pinscheme) { error(nil); } cb = parsecmd(va, n); if(waserror()) { free(cb); nexterror(); } ct = lookupcmd(cb, gpiocmd, nelem(gpiocmd)); if(ct == nil) { error(Ebadctl); } switch(type) { case Qdata: pin = PIN_NUMBER(c->qid); switch(ct->index) { case CMzero: gpioout(pin, 0); break; case CMone: gpioout(pin, 1); break; default: error(Ebadctl); } break; case Qctl: switch(ct->index) { case CMscheme: arg = cb->f[1]; for(i = 0; i < nelem(schemename); i++) { if(strncmp(schemename[i], arg, strlen(schemename[i])) == 0) { pinscheme = i; break; } } break; case CMfunc: pin = getpin(cb->f[2]); arg = cb->f[1]; if(pin == -1) { error(Ebadctl); } for(i = 0; i < nelem(funcname); i++) { if(strncmp(funcname[i], arg, strlen(funcname[i])) == 0) { gpiofuncset(pin, i); break; } } break; case CMpull: pin = getpin(cb->f[2]); if(pin == -1) { error(Ebadctl); } arg = cb->f[1]; for(i = 0; i < nelem(pudname); i++) { if(strncmp(pudname[i], arg, strlen(pudname[i])) == 0) { gpiopullset(pin, i); break; } } break; case CMevent: pin = getpin(cb->f[3]); if(pin == -1) { error(Ebadctl); } arg = cb->f[1]; for(i = 0; i < nelem(evtypename); i++) { if(strncmp(evtypename[i], arg, strlen(evtypename[i])) == 0) { gpioevent(pin, i, (cb->f[2][0] == 'e')); break; } } break; default: error(Ebadctl); } break; } free(cb); poperror(); return n; }
/* * Print monsters' evolution information to file */ static void spoil_mon_evol(cptr fname) { char buf[1024]; monster_race *r_ptr; int **evol_tree, i, j, n, r_idx; int *evol_tree_zero; /* For C_KILL() */ /* Build the filename */ path_build(buf, sizeof buf, ANGBAND_DIR_USER, fname); /* File type is "TEXT" */ FILE_TYPE(FILE_TYPE_TEXT); /* Open the file */ fff = my_fopen(buf, "w"); /* Oops */ if (!fff) { msg_print("Cannot create spoiler file."); return; } /* Dump the header */ sprintf(buf, "Monster Spoilers for PosChengband Version %d.%d.%d\n", VER_MAJOR, VER_MINOR, VER_PATCH); spoil_out(buf); spoil_out("------------------------------------------\n\n"); /* Allocate the "evol_tree" array (2-dimension) */ C_MAKE(evol_tree, max_r_idx, int *); C_MAKE(*evol_tree, max_r_idx * (MAX_EVOL_DEPTH + 1), int); for (i = 1; i < max_r_idx; i++) evol_tree[i] = *evol_tree + i * (MAX_EVOL_DEPTH + 1); evol_tree_zero = *evol_tree; /* Step 1: Build the evolution tree */ for (i = 1; i < max_r_idx; i++) { r_ptr = &r_info[i]; /* No evolution */ if (!r_ptr->next_exp) continue; /* Trace evolution */ n = 0; evol_tree[i][n++] = i; do { evol_tree[i][n++] = r_ptr->next_r_idx; r_ptr = &r_info[r_ptr->next_r_idx]; } while (r_ptr->next_exp && (n < MAX_EVOL_DEPTH)); } /* Step 2: Scan the evolution trees and remove "partial tree" */ for (i = 1; i < max_r_idx; i++) { /* Not evolution tree */ if (!evol_tree[i][0]) continue; for (j = 1; j < max_r_idx; j++) { /* Same tree */ if (i == j) continue; /* Not evolution tree */ if (!evol_tree[j][0]) continue; /* Is evolution tree[i] is part of [j]? */ if (is_partial_tree(evol_tree[j], evol_tree[i])) { /* Remove this evolution tree */ evol_tree[i][0] = 0; break; } } } /* Step 3: Sort the evolution trees */ /* Select the sort method */ ang_sort_comp = ang_sort_comp_evol_tree; ang_sort_swap = ang_sort_swap_evol_tree; /* Sort the array */ ang_sort(evol_tree, NULL, max_r_idx); /* Step 4: Print the evolution trees */ for (i = 0; i < max_r_idx; i++) { r_idx = evol_tree[i][0]; /* No evolution or removed evolution tree */ if (!r_idx) continue; /* Trace the evolution tree */ r_ptr = &r_info[r_idx]; fprintf(fff, "[%d]: %s (Level %d, '%c')\n", r_idx, r_name + r_ptr->name, r_ptr->level, r_ptr->d_char); for (n = 1; r_ptr->next_exp; n++) { fprintf(fff, "%*s-(%d)-> ", n * 2, "", r_ptr->next_exp); fprintf(fff, "[%d]: ", r_ptr->next_r_idx); r_ptr = &r_info[r_ptr->next_r_idx]; fprintf(fff, "%s (Level %d, '%c')\n", r_name + r_ptr->name, r_ptr->level, r_ptr->d_char); } /* End of evolution tree */ fputc('\n', fff); } /* Free the "evol_tree" array (2-dimension) */ C_KILL(evol_tree_zero, max_r_idx * (MAX_EVOL_DEPTH + 1), int); C_KILL(evol_tree, max_r_idx, int *); /* Check for errors */ if (ferror(fff) || my_fclose(fff)) { msg_print("Cannot close spoiler file."); return; } /* Message */ msg_print("Successfully created a spoiler file."); }