MCPcopy Create free account
hub / github.com/NetHack/NetHack / gnome_display_file

Function gnome_display_file

outdated/win/gnome/gnbind.c:578–657  ·  view source on GitHub ↗

Display the file named str. Complain about missing files iff complain is TRUE. */

Source from the content-addressed store, hash-verified

576 iff complain is TRUE.
577*/
578void
579gnome_display_file(const char *filename, BOOLEAN_P must_exist)
580{
581 /* Strange -- for some reason it makes us create a new text window
582 * instead of reusing any existing ones -- perhaps we can work out
583 * some way to reuse stuff -- but for now just make and destroy new
584 * ones each time */
585
586 dlb *f;
587
588 f = dlb_fopen(filename, "r");
589 if (!f) {
590 if (must_exist) {
591 GtkWidget *box;
592 char message[90];
593 sprintf(message, "Warning! Could not find file: %s\n", filename);
594
595 box = gnome_message_box_new(_(message), GNOME_MESSAGE_BOX_ERROR,
596 GNOME_STOCK_BUTTON_OK, NULL);
597 gnome_dialog_set_default(GNOME_DIALOG(box), 0);
598 gnome_dialog_set_parent(GNOME_DIALOG(box),
599 GTK_WINDOW(ghack_get_main_window()));
600 gtk_window_set_modal(GTK_WINDOW(box), TRUE);
601 gtk_widget_show(box);
602 }
603 } else {
604 GtkWidget *txtwin, *gless, *frametxt;
605#define LLEN 128
606 char line[LLEN], *textlines;
607 int num_lines, charcount;
608
609 txtwin = gnome_dialog_new("Text Window", GNOME_STOCK_BUTTON_OK, NULL);
610 gtk_widget_set_usize(GTK_WIDGET(txtwin), 500, 400);
611 gtk_window_set_policy(GTK_WINDOW(txtwin), TRUE, TRUE, FALSE);
612 gtk_window_set_title(GTK_WINDOW(txtwin), "Text Window");
613 gnome_dialog_set_default(GNOME_DIALOG(txtwin), 0);
614 gtk_window_set_modal(GTK_WINDOW(txtwin), TRUE);
615 frametxt = gtk_frame_new("");
616 gtk_widget_show(frametxt);
617
618 /*
619 * Count the number of lines and characters in the file.
620 */
621 num_lines = 0;
622 charcount = 1;
623 while (dlb_fgets(line, LLEN, f)) {
624 num_lines++;
625 charcount += strlen(line);
626 }
627 (void) dlb_fclose(f);
628
629 /* Ignore empty files */
630 if (num_lines == 0)
631 return;
632
633 /*
634 * Re-open the file and read the data into a buffer.
635 */

Callers

nothing calls this directly

Calls 5

dlb_fopenFunction · 0.85
ghack_get_main_windowFunction · 0.85
dlb_fgetsFunction · 0.85
dlb_fcloseFunction · 0.85
allocFunction · 0.50

Tested by

no test coverage detected