void curses_view_file(const char *filename, bool must_exist) { winid wid; anything *identifier; char buf[BUFSZ]; menu_item *selected = NULL; dlb *fp = dlb_fopen(filename, "r"); if ((fp == NULL) && (must_exist)) { pline("Cannot open %s for reading!", filename); } if (fp == NULL) { return; } wid = curses_get_wid(NHW_MENU); curses_create_nhmenu(wid); identifier = malloc(sizeof(anything)); identifier->a_void = NULL; while (dlb_fgets(buf, BUFSZ, fp) != NULL) { curses_add_menu(wid, NO_GLYPH, identifier, 0, 0, A_NORMAL, buf, FALSE); } dlb_fclose(fp); curses_end_menu(wid, ""); curses_select_menu(wid, PICK_NONE, &selected); }
dummy_display_file(const char *filename, BOOLEAN_P must_exist) #endif { printf("dummy_display_file(%s, %d)\n", filename, must_exist); dlb *f; #ifdef FILE_AREAS f = dlb_fopen_area(farea, filename, "r"); #else f = dlb_fopen(filename, "r"); #endif if (!f) { if (must_exist) { printf("Warning! Could not find file: %s\n",filename); } } else { #define LLEN 128 char line[LLEN]; int num_lines, charcount; num_lines = 0; charcount = 1; while (dlb_fgets(line, LLEN, f)) { printf("%s", line); } (void) dlb_fclose(f); } }
void display_file(const char *fname, boolean complain) { dlb *fp; char *buf; int fsize; fp = dlb_fopen(fname, "r"); if (!fp) { if (complain) { pline("Cannot open \"%s\".", fname); } else if (program_state.something_worth_saving) doredraw(); } else { dlb_fseek(fp, 0, SEEK_END); fsize = dlb_ftell(fp); dlb_fseek(fp, 0, SEEK_SET); buf = malloc(fsize); dlb_fread(buf, fsize, 1, fp); dlb_fclose(fp); display_buffer(buf, complain); free(buf); } }
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 */ } }
/* called at program exit */ void unload_qtlist (void) { if (msg_file) (void) dlb_fclose(msg_file), msg_file = 0; if (qt_list.common) free((void *) qt_list.common), qt_list.common = 0; if (qt_list.chrole) free((void *) qt_list.chrole), qt_list.chrole = 0; return; }
char * dowhatdoes_core (char q, char *cbuf) { dlb *fp; char bufr[BUFSZ]; char *buf = &bufr[6], *ep, ctrl, meta; fp = dlb_fopen(CMDHELPFILE, "r"); if (!fp) { pline("Cannot open data file!"); return 0; } ctrl = ((q <= '\033') ? (q - 1 + 'A') : 0); meta = ((0x80 & q) ? (0x7f & q) : 0); while(dlb_fgets(buf,BUFSZ-6,fp)) { if ((ctrl && *buf=='^' && *(buf+1)==ctrl) || (meta && *buf=='M' && *(buf+1)=='-' && *(buf+2)==meta) || *buf==q) { ep = index(buf, '\n'); if(ep) *ep = 0; if (ctrl && buf[2] == '\t'){ buf = bufr + 1; (void) strncpy(buf, "^? ", 8); buf[1] = ctrl; } else if (meta && buf[3] == '\t'){ buf = bufr + 2; (void) strncpy(buf, "M-? ", 8); buf[2] = meta; } else if(buf[1] == '\t'){ buf = bufr; buf[0] = q; (void) strncpy(buf+1, " ", 7); } (void) dlb_fclose(fp); strcpy(cbuf, buf); return cbuf; } } (void) dlb_fclose(fp); return (char *)0; }
/* Display the file named str. Complain about missing files iff complain is TRUE. */ void dummy_display_file(const char *filename,boolean must_exist) { printf("dummy_display_file(%s, %d)\n", filename, must_exist); dlb *f; f = dlb_fopen(filename, "r"); if (!f) { if (must_exist) { printf("Warning! Could not find file: %s\n",filename); } } else { #define LLEN 128 char line[LLEN]; int num_lines, charcount; num_lines = 0; charcount = 1; while (dlb_fgets(line, LLEN, f)) { printf("%s", line); } (void) dlb_fclose(f); } }
/* exclude_cookie is a hack used because we sometimes want to get rumors in a * context where messages such as "You swallowed the fortune!" that refer to * cookies should not appear. This has no effect for true rumors since none * of them contain such references anyway. */ char * getrumor(int truth, /* 1=true, -1=false, 0=either */ char *rumor_buf, boolean exclude_cookie, int *truth_out) { dlb *rumors; int tidbit, beginning; char *endp, line[BUFSZ], xbuf[BUFSZ]; int ltruth = 0; rumor_buf[0] = '\0'; if (true_rumor_size < 0L) /* we couldn't open RUMORFILE */ return rumor_buf; rumors = dlb_fopen(RUMORFILE, "r"); if (rumors) { int count = 0; int adjtruth; do { rumor_buf[0] = '\0'; if (true_rumor_size == 0L) { /* if this is 1st outrumor() */ init_rumors(rumors); if (true_rumor_size < 0L) { /* init failed */ sprintf(rumor_buf, "Error reading \"%.80s\".", RUMORFILE); return rumor_buf; } } /* * input: 1 0 -1 * rn2 \ +1 2=T 1=T 0=F * adj./ +0 1=T 0=F -1=F */ switch (adjtruth = truth + rn2(2)) { case 2: /* (might let a bogus input arg sneak thru) */ case 1: beginning = true_rumor_start; tidbit = mt_random() % true_rumor_size; break; case 0: /* once here, 0 => false rather than "either" */ case -1: beginning = false_rumor_start; tidbit = mt_random() % false_rumor_size; break; default: impossible("strange truth value for rumor"); return strcpy(rumor_buf, "Oops..."); } dlb_fseek(rumors, beginning + tidbit, SEEK_SET); dlb_fgets(line, sizeof line, rumors); if (!dlb_fgets(line, sizeof line, rumors) || (adjtruth > 0 && dlb_ftell(rumors) > true_rumor_end)) { /* reached end of rumors -- go back to beginning */ dlb_fseek(rumors, beginning, SEEK_SET); dlb_fgets(line, sizeof line, rumors); } if ((endp = strchr(line, '\n')) != 0) *endp = 0; strcat(rumor_buf, xcrypt(line, xbuf)); } while (count++ < 50 && exclude_cookie && (strstri(rumor_buf, "fortune") || strstri(rumor_buf, "pity"))); dlb_fclose(rumors); if (count >= 50) impossible("Can't find non-cookie rumor?"); else ltruth = (adjtruth > 0) ? 1 : -1; } else { pline("Can't open rumors file!"); true_rumor_size = -1; /* don't try to open it again */ if (truth_out) *truth_out = 0; } if (truth_out) *truth_out = ltruth; return rumor_buf; }
/* Display the file named str. Complain about missing files iff complain is TRUE. */ void gnome_display_file(const char *filename,BOOLEAN_P must_exist) { /* Strange -- for some reason it makes us create a new text window * instead of reusing any existing ones -- perhaps we can work out * some way to reuse stuff -- but for now just make and destroy new * ones each time */ dlb *f; f = dlb_fopen(filename, "r"); if (!f) { if (must_exist) { GtkWidget *box; char message[90]; sprintf(message, "Warning! Could not find file: %s\n",filename); box = gnome_message_box_new (_(message), GNOME_MESSAGE_BOX_ERROR, GNOME_STOCK_BUTTON_OK, NULL); gnome_dialog_set_default( GNOME_DIALOG(box), 0); gnome_dialog_set_parent (GNOME_DIALOG (box), GTK_WINDOW (ghack_get_main_window ()) ); gtk_window_set_modal( GTK_WINDOW(box), TRUE); gtk_widget_show (box); } } else { GtkWidget *txtwin, *gless, *frametxt; #define LLEN 128 char line[LLEN], *textlines; int num_lines, charcount; txtwin = gnome_dialog_new("Text Window", GNOME_STOCK_BUTTON_OK, NULL); gtk_widget_set_usize(GTK_WIDGET(txtwin), 500, 400); gtk_window_set_policy(GTK_WINDOW(txtwin), TRUE, TRUE, FALSE); gtk_window_set_title(GTK_WINDOW(txtwin), "Text Window"); gnome_dialog_set_default( GNOME_DIALOG(txtwin), 0); gtk_window_set_modal( GTK_WINDOW(txtwin), TRUE); frametxt = gtk_frame_new (""); gtk_widget_show (frametxt); /* * Count the number of lines and characters in the file. */ num_lines = 0; charcount = 1; while (dlb_fgets(line, LLEN, f)) { num_lines++; charcount += strlen(line); } (void) dlb_fclose(f); /* Ignore empty files */ if (num_lines == 0) return; /* * Re-open the file and read the data into a buffer. */ textlines = (char *) alloc((unsigned int) charcount); textlines[0] = '\0'; f = dlb_fopen( filename, RDTMODE); while (dlb_fgets(line, LLEN, f)) { (void) strcat(textlines, line); } (void) dlb_fclose(f); gless = gnome_less_new (); gnome_less_show_string (GNOME_LESS (gless), textlines); gtk_container_add (GTK_CONTAINER (frametxt), gless); gtk_box_pack_start(GTK_BOX (GNOME_DIALOG (txtwin)->vbox), frametxt, TRUE, TRUE, 0); gtk_widget_show_all( txtwin); gtk_window_set_modal( GTK_WINDOW(txtwin), TRUE); gnome_dialog_set_parent (GNOME_DIALOG (txtwin), GTK_WINDOW (ghack_get_main_window ()) ); gnome_dialog_run_and_close (GNOME_DIALOG (txtwin)); free(textlines); } }
/* * Look in the "data" file for more info. Called if the user typed in the * whole name (user_typed_name == TRUE), or we've found a possible match * with a character/glyph. */ static void checkfile(const char *inp, struct permonst *pm, boolean user_typed_name, boolean without_asking) { dlb *fp; char buf[BUFSZ], newstr[BUFSZ]; char *ep, *dbase_str; long txt_offset = 0; int chk_skip; boolean found_in_file = FALSE, skipping_entry = FALSE; fp = dlb_fopen(DATAFILE, "r"); if (!fp) { pline("Cannot open data file!"); return; } /* To prevent the need for entries in data.base like *ngel to account for Angel and angel, make the lookup string the same for both user_typed_name and picked name. */ if (pm != NULL && !user_typed_name) dbase_str = strcpy(newstr, pm->mname); else dbase_str = strcpy(newstr, inp); for (ep = dbase_str; *ep; ep++) *ep = lowc(*ep); if (!strncmp(dbase_str, "interior of ", 12)) dbase_str += 12; if (!strncmp(dbase_str, "a ", 2)) dbase_str += 2; else if (!strncmp(dbase_str, "an ", 3)) dbase_str += 3; else if (!strncmp(dbase_str, "the ", 4)) dbase_str += 4; if (!strncmp(dbase_str, "tame ", 5)) dbase_str += 5; else if (!strncmp(dbase_str, "peaceful ", 9)) dbase_str += 9; if (!strncmp(dbase_str, "invisible ", 10)) dbase_str += 10; if (!strncmp(dbase_str, "statue of ", 10)) dbase_str[6] = '\0'; else if (!strncmp(dbase_str, "figurine of ", 12)) dbase_str[8] = '\0'; /* Make sure the name is non-empty. */ if (*dbase_str) { /* adjust the input to remove " [seen" and "named " and convert to lower case */ const char *alt = 0; /* alternate description */ if ((ep = strstri_mutable(dbase_str, " [seen")) != 0) *ep = '\0'; if ((ep = strstri_mutable(dbase_str, " named ")) != 0) alt = ep + 7; else ep = strstri_mutable(dbase_str, " called "); if (!ep) ep = strstri_mutable(dbase_str, ", "); if (ep && ep > dbase_str) *ep = '\0'; /* * If the object is named, then the name is the alternate description; * otherwise, the result of makesingular() applied to the name is. This * isn't strictly optimal, but named objects of interest to the user * will usually be found under their name, rather than under their * object type, so looking for a singular form is pointless. */ if (!alt) alt = makesingular(dbase_str); else if (user_typed_name) alt = msglowercase(alt); /* skip first record; read second */ txt_offset = 0L; if (!dlb_fgets(buf, BUFSZ, fp) || !dlb_fgets(buf, BUFSZ, fp)) { impossible("can't read 'data' file"); dlb_fclose(fp); return; } else if (sscanf(buf, "%8lx\n", &txt_offset) < 1 || txt_offset <= 0) goto bad_data_file; /* look for the appropriate entry */ while (dlb_fgets(buf, BUFSZ, fp)) { if (*buf == '.') break; /* we passed last entry without success */ if (digit(*buf)) { /* a number indicates the end of current entry */ skipping_entry = FALSE; } else if (!skipping_entry) { if (!(ep = strchr(buf, '\n'))) goto bad_data_file; *ep = 0; /* if we match a key that begins with "~", skip this entry */ chk_skip = (*buf == '~') ? 1 : 0; if (pmatch(&buf[chk_skip], dbase_str) || (alt && pmatch(&buf[chk_skip], alt))) { if (chk_skip) { skipping_entry = TRUE; continue; } else { found_in_file = TRUE; break; } } } } } if (found_in_file) { long entry_offset; int entry_count; int i; /* skip over other possible matches for the info */ do { if (!dlb_fgets(buf, BUFSZ, fp)) goto bad_data_file; } while (!digit(*buf)); if (sscanf(buf, "%ld,%d\n", &entry_offset, &entry_count) < 2) { bad_data_file:impossible("'data' file in wrong format"); dlb_fclose(fp); return; } if (user_typed_name || without_asking || yn("More info?") == 'y') { struct nh_menulist menu; if (dlb_fseek(fp, txt_offset + entry_offset, SEEK_SET) < 0) { pline("? Seek error on 'data' file!"); dlb_fclose(fp); return; } init_menulist(&menu); for (i = 0; i < entry_count; i++) { if (!dlb_fgets(buf, BUFSZ, fp)) goto bad_data_file; if ((ep = strchr(buf, '\n')) != 0) *ep = 0; if (strchr(buf + 1, '\t') != 0) tabexpand(buf + 1); add_menutext(&menu, buf + 1); } display_menu(&menu, NULL, FALSE, PLHINT_ANYWHERE, NULL); } } else if (user_typed_name) pline("I don't have any information on those things."); dlb_fclose(fp); }
void mswin_display_splash_window(BOOL show_ver) { MSG msg; int left, top; RECT splashrt; RECT clientrt; RECT controlrt; HWND hWnd; int buttop; int strsize = 0; int bufsize = BUFSZ; char *buf = malloc(bufsize); if (buf == NULL) panic("out of memory"); buf[0] = '\0'; hWnd = CreateDialog(GetNHApp()->hApp, MAKEINTRESOURCE(IDD_SPLASH), GetNHApp()->hMainWnd, NHSplashWndProc); if (!hWnd) panic("Cannot create Splash window"); mswin_init_splashfonts(hWnd); GetNHApp()->hPopupWnd = hWnd; /* Get control size */ GetWindowRect(GetDlgItem(hWnd, IDOK), &controlrt); controlrt.right -= controlrt.left; controlrt.bottom -= controlrt.top; /* Get current client area */ GetClientRect(hWnd, &clientrt); /* Get window size */ GetWindowRect(hWnd, &splashrt); splashrt.right -= splashrt.left; splashrt.bottom -= splashrt.top; /* Get difference between requested client area and current value */ splashrt.right += SPLASH_WIDTH + SPLASH_OFFSET_X * 2 - clientrt.right; splashrt.bottom += SPLASH_HEIGHT + controlrt.bottom + SPLASH_OFFSET_Y * 3 - clientrt.bottom; /* Place the window centered */ /* On the screen, not on the parent window */ left = (GetSystemMetrics(SM_CXSCREEN) - splashrt.right) / 2; top = (GetSystemMetrics(SM_CYSCREEN) - splashrt.bottom) / 2; MoveWindow(hWnd, left, top, splashrt.right, splashrt.bottom, TRUE); /* Place the OK control */ GetClientRect(hWnd, &clientrt); MoveWindow(GetDlgItem(hWnd, IDOK), (clientrt.right - clientrt.left - controlrt.right) / 2, clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y, controlrt.right, controlrt.bottom, TRUE); buttop = clientrt.bottom - controlrt.bottom - SPLASH_OFFSET_Y; /* Place the text control */ GetWindowRect(GetDlgItem(hWnd, IDC_EXTRAINFO), &controlrt); controlrt.right -= controlrt.left; controlrt.bottom -= controlrt.top; GetClientRect(hWnd, &clientrt); MoveWindow(GetDlgItem(hWnd, IDC_EXTRAINFO), clientrt.left + SPLASH_OFFSET_X, buttop - controlrt.bottom - SPLASH_OFFSET_Y, clientrt.right - 2 * SPLASH_OFFSET_X, controlrt.bottom, TRUE); /* Fill the text control */ Sprintf(buf, "%s\r\n%s\r\n%s\r\n%s\r\n\r\n", COPYRIGHT_BANNER_A, COPYRIGHT_BANNER_B, COPYRIGHT_BANNER_C, COPYRIGHT_BANNER_D); strsize = strlen(buf); if (show_ver) { /* Show complete version information */ dlb *f; char verbuf[BUFSZ]; int verstrsize = 0; getversionstring(verbuf); verstrsize = strlen(verbuf); if (verstrsize + strlen("\r\n\r\n") + 1 < BUFSZ - 1) strcat(verbuf, "\r\n\r\n"); verstrsize = strlen(verbuf); if (strsize + verstrsize + 1 > bufsize) { bufsize += BUFSZ; buf = realloc(buf, bufsize); if (buf == NULL) panic("out of memory"); } strcat(buf, verbuf); strsize = strlen(buf); /* Add compile options */ f = dlb_fopen(OPTIONS_USED, RDTMODE); if (f) { char line[LLEN + 1]; while (dlb_fgets(line, LLEN, f)) { size_t len; len = strlen(line); if (len > 0 && line[len - 1] == '\n') { line[len - 1] = '\r'; line[len] = '\n'; line[len + 1] = '\0'; len++; } if (strsize + (int) len + 1 > bufsize) { bufsize += BUFSZ; buf = realloc(buf, bufsize); if (buf == NULL) panic("out of memory"); } strcat(buf, line); strsize += len; } (void) dlb_fclose(f); } } else { /* Show news, if any */ if (iflags.news) { FILE *nf; iflags.news = 0; /* prevent newgame() from re-displaying news */ nf = fopen(NEWS, "r"); if (nf != NULL) { char line[LLEN + 1]; while (fgets(line, LLEN, nf)) { size_t len; len = strlen(line); if (len > 0 && line[len - 1] == '\n') { line[len - 1] = '\r'; line[len] = '\n'; line[len + 1] = '\0'; len++; } if (strsize + (int) len + 1 > bufsize) { bufsize += BUFSZ; buf = realloc(buf, bufsize); if (buf == NULL) panic("out of memory"); } strcat(buf, line); strsize += len; } (void) fclose(nf); } else { strcat(buf, "No news."); } } } SetWindowText(GetDlgItem(hWnd, IDC_EXTRAINFO), buf); free(buf); ShowWindow(hWnd, SW_SHOW); while (IsWindow(hWnd) && GetMessage(&msg, NULL, 0, 0) != 0) { if (!IsDialogMessage(hWnd, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } GetNHApp()->hPopupWnd = NULL; mswin_destroy_splashfonts(); }
/* exclude_cookie is a hack used because we sometimes want to get rumors in a * context where messages such as "You swallowed the fortune!" that refer to * cookies should not appear. This has no effect for true rumors since none * of them contain such references anyway. */ const char * getrumor(int truth, /* 1=true, -1=false, 0=either 3=potter (truier than true)*/ boolean exclude_cookie, int *truth_out, enum rng rng) { dlb *rumors; int tidbit, beginning; char *endp; int ltruth = 0; char line[BUFSZ]; /* for fgets */ const char *rv = ""; /* If this happens, we couldn't open the RUMORFILE. So synthesize a rumor just for the occasion :-) */ if (true_rumor_size < 0L) return ""; rumors = dlb_fopen(RUMORFILE, "r"); if (rumors) { int count = 0; int adjtruth; do { if (true_rumor_size == 0L) { /* if this is 1st outrumor() */ init_rumors(rumors); if (true_rumor_size < 0L) /* init failed */ return msgprintf("Error reading \"%.80s\".", RUMORFILE); } /* * input: 3 1 0 -1 * rn2 \ +1 4=P 2=T 1=T 0=F * adj./ +0 3=P 1=T 0=F -1=F */ switch (adjtruth = truth + rn2_on_rng(2, rng)) { case 4: /* (might let a bogus input arg sneak thru) */ case 3: beginning = potter_rumor_start; tidbit = rn2_on_rng(potter_rumor_size, rng); break; case 1: beginning = true_rumor_start; tidbit = rn2_on_rng(true_rumor_size, rng); break; case 0: /* once here, 0 => false rather than "either" */ case -1: beginning = false_rumor_start; tidbit = rn2_on_rng(false_rumor_size, rng); break; default: impossible("strange truth value for rumor"); if (truth_out) *truth_out = 0; return "Oops..."; } dlb_fseek(rumors, beginning + tidbit, SEEK_SET); dlb_fgets(line, sizeof line, rumors); if (!dlb_fgets(line, sizeof line, rumors) || ((adjtruth == 2 || adjtruth == 1) && dlb_ftell(rumors) > true_rumor_end)) { /* reached end of rumors -- go back to beginning */ dlb_fseek(rumors, beginning, SEEK_SET); dlb_fgets(line, sizeof line, rumors); } else if (!dlb_fgets(line, sizeof line, rumors) || (adjtruth < 1 && dlb_ftell(rumors) > false_rumor_end)){ dlb_fseek(rumors, beginning, SEEK_SET); dlb_fgets(line, sizeof line, rumors); } if ((endp = strchr(line, '\n')) != 0) *endp = 0; char decrypted_line[strlen(line) + 1]; xcrypt(line, decrypted_line); rv = msg_from_string(decrypted_line); } while (count++ < 50 && exclude_cookie && (strstri(rv, "fortune") || strstri(rv, "pity"))); dlb_fclose(rumors); if (count >= 50) impossible("Can't find non-cookie rumor?"); else ltruth = (adjtruth > 0) ? 1 : -1; } else { pline("Can't open rumors file!"); true_rumor_size = -1; /* don't try to open it again */ if (truth_out) *truth_out = 0; } if (truth_out) *truth_out = ltruth; return rv; }