The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13974 hornik 1
/*
2
 *  R : A Computer Langage for Statistical Data Analysis
18793 ripley 3
 *  Copyright (C) 1998-2002   Lyndon Drake
13974 hornik 4
 *                            and the R Development Core Team
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
20
 
18793 ripley 21
#ifdef HAVE_CONFIG_H
22
# include <config.h>
23
#endif
24
 
13974 hornik 25
#include "Defn.h"
26
#include "Fileio.h"
27
 
28
#include "terminal.h"
29
#include "gtkconsole.h"
30
 
31
#include <gnome.h>
32
 
33
	/*--- I/O Support Code ---*/
34
 
35
	/* These routines provide hooks for supporting console I/O.
36
	 * Under raw Unix these routines simply provide a
37
	 * connection to the stdio library.
38
	 * Under the GNOME interface the routines hook into
39
	 * the GtkConsole widget.
40
	 */
41
 
18175 pd 42
extern int (*R_timeout_handler)();
43
extern long R_timeout_val;
13974 hornik 44
 
45
/* Catch input in the console window */
16945 pd 46
void
47
R_gtk_terminal_line_event (GtkWidget * widget)
13974 hornik 48
{
16945 pd 49
  gtk_main_quit ();
13974 hornik 50
}
51
 
52
/* Fill a text buffer with user typed console input. */
16945 pd 53
int
20053 martyn 54
Rgnome_ReadConsole (char *prompt, char *buf, int len,
16945 pd 55
		    int addtohistory)
13974 hornik 56
{
16945 pd 57
  if (!R_Interactive)
58
    {
59
      if (!R_Slave)
60
	fputs (prompt, stdout);
61
      if (fgets (buf, len, stdin) == NULL)
62
	return 0;
63
      if (!R_Slave)
64
	fputs (buf, stdout);
13974 hornik 65
    }
18175 pd 66
   else
16945 pd 67
    {
68
      gtk_console_enable_input (GTK_CONSOLE (R_gtk_terminal_text), prompt,
69
				strlen (prompt));
70
      gtk_signal_connect (GTK_OBJECT (R_gtk_terminal_text),
71
			  "console_line_ready",
72
			  GTK_SIGNAL_FUNC (R_gtk_terminal_line_event), NULL);
13974 hornik 73
 
18175 pd 74
      if (R_timeout_handler && R_timeout_val)
75
	  gtk_timeout_add(R_timeout_val, R_timeout_handler, NULL);
16945 pd 76
      gtk_main ();
13974 hornik 77
 
16945 pd 78
      gtk_console_read (GTK_CONSOLE (R_gtk_terminal_text), buf, len,
79
			addtohistory);
13974 hornik 80
    }
81
 
16945 pd 82
  return 1;
13974 hornik 83
}
84
 
85
/* Write a text buffer to the console. */
86
/* All system output is filtered through this routine. */
16945 pd 87
void
88
Rgnome_WriteConsole (char *buf, int len)
13974 hornik 89
{
16945 pd 90
  gtk_console_write (GTK_CONSOLE (R_gtk_terminal_text), buf, len);
13974 hornik 91
}
92
 
93
/* Indicate that input is coming from the console */
16945 pd 94
void
95
Rgnome_ResetConsole ()
13974 hornik 96
{
97
}
98
 
99
/* Stdio support to ensure the console file buffer is flushed */
16945 pd 100
void
101
Rgnome_FlushConsole ()
13974 hornik 102
{
16945 pd 103
  gtk_console_flush (GTK_CONSOLE (R_gtk_terminal_text));
13974 hornik 104
}
105
 
106
 
107
/* Reset stdin if the user types EOF on the console. */
16945 pd 108
void
109
Rgnome_ClearerrConsole ()
13974 hornik 110
{
111
}