8
Tcl_Interp *tcliMain; /* Main and only tcl interpreter instance */
10
static Tk_Window mainWindow; /* The main window for the application. If
11
* NULL then the application no longer
14
static int tty; /* Non-zero means standard input is a
15
* terminal-like device. Zero means it's
18
static int synchronize = 1;
19
static char *szname = "TCL/TK-Scheme";
20
static char *szdisplay = NULL; /* "unix:0.0"; */
22
static Tcl_DString command; /* Used to assemble lines of terminal input
23
* into Tcl commands. */
24
static int gotPartial = 0; /* Partial command in buffer. */
26
static char exitCmd[] = "exit";
27
static char errorExitCmd[] = "destroy .";
29
extern int isatty _ANSI_ARGS_((int fd));
31
int __TclX_AppInit(Tcl_Interp *interp) { return TCL_OK; }
34
*----------------------------------------------------------------------
38
* This procedure is invoked by the event dispatcher whenever
39
* standard input becomes readable. It grabs the next line of
40
* input characters, adds them to a command being assembled, and
41
* executes the command if it's complete.
47
* Could be almost arbitrary, depending on the command that's
50
*----------------------------------------------------------------------
54
StdinProc(ClientData clientData, int mask)
56
#define BUFFER_SIZE 4000
57
char input[BUFFER_SIZE+1];
61
count = read(fileno(stdin), input, BUFFER_SIZE);
65
Tcl_VarEval(tcliMain, "exit", (char *) NULL);
69
Tk_DeleteFileHandler(0);
77
cmd = Tcl_DStringAppend(&command, input, count);
79
if ((input[count-1] != '\n') && (input[count-1] != ';')) {
83
if (!Tcl_CommandComplete(cmd)) {
91
* Disable the stdin file handler; otherwise if the command
92
* re-enters the event loop we might process commands from
93
* stdin before the current command is finished. Among other
94
* things, this will trash the text of the command being evaluated.
97
Tk_CreateFileHandler(0, 0, StdinProc, (ClientData) 0);
98
code = Tcl_RecordAndEval(tcliMain, cmd, 0);
99
Tk_CreateFileHandler(0, TK_READABLE, StdinProc, (ClientData) 0);
101
TclX_PrintResult (tcliMain, code, cmd);
102
Tcl_DStringFree(&command);
106
TclX_OutputPrompt (tcliMain, !gotPartial);
111
*----------------------------------------------------------------------
115
* Function called on a signal generating an error to clear the stdin
117
*----------------------------------------------------------------------
120
SignalProc (int signalNum)
122
tclGotErrorSignal = 0;
123
Tcl_DStringFree (&command);
126
fputc ('\n', stdout);
127
TclX_OutputPrompt (tcliMain, !gotPartial);
133
tcliMain = Tcl_CreateInterp();
135
mainWindow = Tk_CreateMainWindow(tcliMain, szdisplay, szname, "Tk");
136
if (mainWindow == NULL)
137
fprintf(stderr, "Unable to create mainWindow : %s\n", tcliMain->result);
139
Tk_SetClass(mainWindow, "Tk");
141
XSynchronize(Tk_Display(mainWindow), True);
143
Tk_GeometryRequest(mainWindow, 200, 200);
145
if (__TclX_AppInit(tcliMain) != TCL_OK)
146
TclX_ErrorExit (tcliMain, 255);
148
Tcl_AppInit(tcliMain);
156
* Set the "tcl_interactive" variable.
159
Tcl_SetVar(tcliMain, "tcl_interactive",
160
tty ? "1" : "0", TCL_GLOBAL_ONLY);
162
TclX_EvalRCFile (tcliMain);
165
* Commands will come from standard input. Set up a handler
166
* to receive those characters and print a prompt if the input
167
* device is a terminal.
169
tclErrorSignalProc = SignalProc;
170
Tk_CreateFileHandler(0, TK_READABLE, StdinProc, (ClientData) 0);
172
TclX_OutputPrompt (tcliMain, 1);
175
Tcl_GlobalEval(tcliMain, exitCmd);
187
Tcl_Interp *interp; /* Interpreter for application. */
191
main = Tk_MainWindow(interp);
194
* Call the init procedures for included packages. Each call should
197
* if (Mod_Init(interp) == TCL_ERROR) {
201
* where "Mod" is the name of the module.
204
if (Tcl_Init(interp) == TCL_ERROR) {
207
if (Tk_Init(interp) == TCL_ERROR) {
211
if (TclX_Init(interp) == TCL_ERROR)
214
if (TkX_Init(interp) == TCL_ERROR)
218
* Call Tcl_CreateCommand for application-specific commands, if
219
* they weren't already created by the init procedures called above.
223
* Specify a user-specific startup file to invoke if the application
224
* is run interactively. Typically the startup file is "~/.apprc"
225
* where "app" is the name of the application. If this line is deleted
226
* then no user-specific startup file will be run under any conditions.
229
tcl_RcFileName = "~/.wishrc";