The R Project SVN R

Rev

Rev 18793 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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