-
-static void reload_viewer (PsppireOutputWindow *ow);
-
-void
-psppire_output_window_reload (void)
-{
- struct stat buf;
-
- /* If there is no output, then don't do anything */
- if (0 != stat (OUTPUT_FILE_NAME, &buf))
- return ;
-
- if ( NULL == the_output_viewer )
- {
- the_output_viewer = PSPPIRE_OUTPUT_WINDOW (psppire_output_window_new ());
- gtk_widget_show (GTK_WIDGET (the_output_viewer));
- }
-
- reload_viewer (the_output_viewer);
-
-}
-
-
-static void
-reload_viewer (PsppireOutputWindow *ow)
-{
- GtkTextIter end_iter;
- GtkTextMark *mark ;
-
- static char *line = NULL;
-
- gboolean chars_inserted = FALSE;
-
- gtk_text_buffer_get_end_iter (ow->buffer, &end_iter);
-
- line = xrealloc (line, sizeof (char) * (viewer_width + 1));
-
- mark = gtk_text_buffer_create_mark (ow->buffer, NULL, &end_iter, TRUE);
-
-#ifdef __CYGWIN__
- /*
- Apparently Windoze is not capabale of writing to a file whilst
- another (or the same) process is reading from it. Therefore, we
- must close the file after reading it, and clear the entire buffer
- before writing to it.
- This will be slower for large buffers, but should work
- (in so far as anything ever works on windows).
- */
- {
- GtkTextIter start_iter;
- FILE *fp = fopen (OUTPUT_FILE_NAME, "r");
- if ( !fp)
- {
- g_print ("Cannot open %s\n", OUTPUT_FILE_NAME);
- return;
- }
-
- /* Delete all the entire buffer */
- gtk_text_buffer_get_start_iter (ov->buffer, &start_iter);
- gtk_text_buffer_delete (ov->buffer, &start_iter, &end_iter);
-
-
- gtk_text_buffer_get_start_iter (ov->buffer, &start_iter);
- /* Read in the next lot of text */
- while (fgets (line, viewer_width + 1, fp) != NULL)
- {
- chars_inserted = TRUE;
- gtk_text_buffer_insert (ov->buffer, &start_iter, line, -1);
- }
-
- fclose (fp);
- }
-#else
- {
- if ( ow->fp == NULL)
- {
- ow->fp = fopen (OUTPUT_FILE_NAME, "r");
- if ( ow->fp == NULL)
- {
- g_print ("Cannot open %s\n", OUTPUT_FILE_NAME);
- return;
- }
- }
-
- /* Read in the next lot of text */
- while (fgets (line, viewer_width + 1, ow->fp) != NULL)
- {
- chars_inserted = TRUE;
- gtk_text_buffer_insert (ow->buffer, &end_iter, line, -1);
- }
- }
-#endif
-
- /* Scroll to where the start of this lot of text begins */
- gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (ow->textview),
- mark,
- 0.1, TRUE, 0.0, 0.0);
-
-
- if ( chars_inserted )
- gtk_window_set_urgency_hint ( GTK_WINDOW (ow), TRUE);
-}
-
-
-