void outoracle(boolean special, boolean delphi) { char line[COLNO]; char *endp; dlb *oracles; int oracle_idx; char xbuf[BUFSZ]; if (oracle_flg < 0 || /* couldn't open ORACLEFILE */ (oracle_flg > 0 && oracle_cnt == 0)) /* oracles already exhausted */ return; oracles = dlb_fopen(ORACLEFILE, "r"); if (oracles) { struct menulist menu; if (oracle_flg == 0) { /* if this is the first outoracle() */ init_oracles(oracles); oracle_flg = 1; if (oracle_cnt == 0) return; } /* oracle_loc[0] is the special oracle; */ /* oracle_loc[1..oracle_cnt-1] are normal ones */ if (oracle_cnt <= 1 && !special) return; /* (shouldn't happen) */ oracle_idx = special ? 0 : rnd((int)oracle_cnt - 1); dlb_fseek(oracles, oracle_loc[oracle_idx], SEEK_SET); if (!special) oracle_loc[oracle_idx] = oracle_loc[--oracle_cnt]; init_menulist(&menu); if (delphi) add_menutext(&menu, special ? "The Oracle scornfully takes all your money and says:" : "The Oracle meditates for a moment and then intones:"); else add_menutext(&menu, "The message reads:"); add_menutext(&menu, ""); while (dlb_fgets(line, COLNO, oracles) && strcmp(line, "---\n")) { if ((endp = strchr(line, '\n')) != 0) *endp = 0; add_menutext(&menu, xcrypt(line, xbuf)); } display_menu(menu.items, menu.icount, NULL, PICK_NONE, PLHINT_ANYWHERE, NULL); free(menu.items); dlb_fclose(oracles); } else { pline("Can't open oracles file!"); oracle_flg = -1; /* don't try to open it again */ } }
void outoracle(boolean special, boolean delphi) { char line[COLNO]; char *endp; dlb *oracles; int oracle_idx; if (oracle_flg < 0 || /* couldn't open ORACLEFILE */ (oracle_flg > 0 && oracle_cnt == 0)) /* oracles already exhausted */ return; oracles = dlb_fopen(ORACLEFILE, "r"); if (oracles) { struct nh_menulist menu; if (oracle_flg == 0) { /* if this is the first outoracle() */ init_oracles(oracles); oracle_flg = 1; if (oracle_cnt == 0) return; } /* oracle_loc[0] is the special oracle; */ /* oracle_loc[1..oracle_cnt-1] are normal ones */ if (oracle_cnt <= 1 && !special) return; /* (shouldn't happen) */ oracle_idx = special ? 0 : rnd((int)oracle_cnt - 1); dlb_fseek(oracles, oracle_loc[oracle_idx], SEEK_SET); if (!special) oracle_loc[oracle_idx] = oracle_loc[--oracle_cnt]; init_menulist(&menu); if (delphi) add_menutext( &menu, special ? "Potter protests, but then takes your money and says:" : "Potter thinks for a second, and then announces in a gravelly voice:"); else add_menutext(&menu, "The message reads:"); add_menutext(&menu, ""); while (dlb_fgets(line, COLNO, oracles) && strcmp(line, "---\n")) { if ((endp = strchr(line, '\n')) != 0) *endp = 0; char decrypted_line[strlen(line) + 1]; add_menutext(&menu, xcrypt(line, decrypted_line)); } display_menu(&menu, NULL, PICK_NONE, PLHINT_ANYWHERE, NULL); dlb_fclose(oracles); } else { pline("Can't open oracles file!"); oracle_flg = -1; /* don't try to open it again */ } }