#pragma prototyped
/*
* tkMain.c --
*
* This file contains a generic main program for Tk-based applications.
* It can be used as-is for many applications, just by supplying a
* different appInitProc procedure for each specific application.
* Or, it can be used as a template for creating new main programs
* for Tk applications.
*
* Copyright (c) 1990-1994 The Regents of the University of California.
* Copyright (c) 1994-1996 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tkMain.c 1.148 96/03/25 18:08:43
*/
#include "tksh.h"
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <tcl.h>
#include <tk.h>
#if 0
#ifdef NO_STDLIB_H
#else
# include <stdlib.h>
#endif
#endif
/*
* Declarations for various library procedures and variables (don't want
* file out of the Tk source directory to make their own modified versions).
* Note: don't declare "exit" here even though a declaration is really
* needed, because it will conflict with a declaration elsewhere on
* some systems.
*/
#if 0
#endif
/*
* Global variables used by the main program:
*/
* into Tcl commands. */
* terminal input. */
* terminal-like device. Zero means it's
* a file. */
/*
* Forward declarations for procedures defined later in this file.
*/
int mask));
/*
*----------------------------------------------------------------------
*
* Tk_Main --
*
* Main program for Wish and most other Tk-based applications.
*
* Results:
* None. This procedure never returns (it exits the process when
* it's done.
*
* Side effects:
* This procedure initializes the Tk world and then starts
* interpreting commands; almost anything could happen, depending
* on the script being interpreted.
*
*----------------------------------------------------------------------
*/
void
int argc; /* Number of arguments. */
char **argv; /* Array of argument strings. */
* procedure to call after most
* initialization but before starting
* to execute commands. */
{
int code;
#if 0
#endif
Tcl_FindExecutable(argv[0]);
interp = Tcl_CreateInterp();
#ifdef TCL_MEM_DEBUG
#endif
/*
* Parse command-line arguments. A leading "-file" argument is
* ignored (a historical relic from the distant past). If the
* next argument doesn't start with a "-" then strip it off and
* use it as the name of a script file to process.
*/
if (argc > 1) {
argc--;
argv++;
}
}
argc--;
argv++;
}
/*
* Make command-line arguments available in the Tcl variables "argc"
* and "argv".
*/
/*
* Set the "tcl_interactive" variable.
*/
/*
* For now, under Windows, we assume we are not running as a console mode
* app, so we need to use the GUI console. In order to enable this, we
* always claim to be running on a tty. This probably isn't the right
* way to do it.
*/
#ifdef __WIN32__
tty = 1;
#else
#endif
/*
* Invoke application-specific initialization.
*/
if (errChannel) {
"application-specific initialization failed: ", -1);
}
}
/*
* Invoke the script specified on the command line, if any.
*/
goto error;
}
tty = 0;
} else {
/*
* Commands will come from standard input, so set up an event
* handler for standard input. Evaluate the .rc file, if one
* has been specified, set up an event handler for standard
* input, and print a prompt if the input device is a terminal.
*/
char *fullName;
if (errChannel) {
}
} else {
/*
* NOTE: The following relies on O_RDONLY==0.
*/
if (errChannel) {
}
}
}
}
}
#if 0
/*
* Establish a channel handler for stdin.
*/
if (inChannel) {
(ClientData) inChannel);
}
if (tty) {
}
#endif
}
#if 0
if (outChannel) {
}
#endif
/*
* Loop infinitely, waiting for commands to execute. When there
* are no windows left, Tk_MainLoop returns and we exit.
*/
#if 0
Tk_MainLoop();
Tcl_Exit(0);
#else
return;
#endif
/*
* The following statement guarantees that the errorInfo
* variable is set properly.
*/
if (errChannel) {
-1);
}
Tcl_Exit(1);
}
#if 0
/*
*----------------------------------------------------------------------
*
* StdinProc --
*
* This procedure is invoked by the event dispatcher whenever
* standard input becomes readable. It grabs the next line of
* input characters, adds them to a command being assembled, and
* executes the command if it's complete.
*
* Results:
* None.
*
* Side effects:
* Could be almost arbitrary, depending on the command that's
* typed.
*
*----------------------------------------------------------------------
*/
/* ARGSUSED */
static void
int mask; /* Not used. */
{
static int gotPartial = 0;
char *cmd;
if (count < 0) {
if (!gotPartial) {
if (tty) {
Tcl_Exit(0);
} else {
}
return;
} else {
count = 0;
}
}
if (!Tcl_CommandComplete(cmd)) {
gotPartial = 1;
goto prompt;
}
gotPartial = 0;
/*
* Disable the stdin channel handler while evaluating the command;
* otherwise if the command re-enters the event loop we might
* process commands from stdin before the current command is
* finished. Among other things, this will trash the text of the
* command being evaluated.
*/
(ClientData) chan);
/*
* The statement below used to call "printf", but that resulted
* in core dumps under Solaris 2.3 if the result was very long.
*
* NOTE: This probably will not work under Windows either.
*/
}
}
/*
* Output a prompt.
*/
if (tty) {
}
}
/*
*----------------------------------------------------------------------
*
* Prompt --
*
* Issue a prompt on standard output, or invoke a script
* to issue the prompt.
*
* Results:
* None.
*
* Side effects:
* A prompt gets output, and a Tcl script may be evaluated
* in interp.
*
*----------------------------------------------------------------------
*/
static void
int partial; /* Non-zero means there already
* exists a partial command, so use
* the secondary prompt. */
{
char *promptCmd;
int code;
if (!partial) {
/*
* We must check that outChannel is a real channel - it
* is possible that someone has transferred stdout out of
* this interpreter with "interp transfer".
*/
}
}
} else {
"\n (script that generates prompt)");
/*
* We must check that errChannel is a real channel - it
* is possible that someone has transferred stderr out of
* this interpreter with "interp transfer".
*/
}
goto defaultPrompt;
}
}
}
}
#endif
/*********************************************************************/
* interpreter. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
int result;
{
{
}
return result;
}
}
{
{
/* Tcl_SetCommandInfo(interp, "bind", &bindInfo); */
}
}
{
Tk_MainLoop();
return 0;
}
{
#if 0
static char initCmd[] =
"if [[ -f $tk_library/tk.ksh ]] ; then \n\
. $tk_library/tk.ksh\n\
else \n\
msg=\"can't find $tk_library/tk.ksh; perhaps you \"\n\
msg=\"$msg need to\\ninstall Tk or set your TK_LIBRARY \"\n\
msg=\"$msg environment variable?\"\n\
print -u2 $msg\n\
fi\n";
#endif
return TCL_OK;
}
static int
{
return TCL_ERROR;
}
/* Should be current, but Tk_Init evals a script. */
return TCL_ERROR;
}
return TCL_ERROR;
}
#ifdef TK_TEST
return TCL_ERROR;
}
(Tcl_PackageInitProc *) NULL);
#endif /* TK_TEST */
/*
* Call the init procedures for included packages. Each call should
* look like this:
*
* if (Mod_Init(interp) == TCL_ERROR) {
* return TCL_ERROR;
* }
*
* where "Mod" is the name of the module.
*/
/*
* Call Tcl_CreateCommand for application-specific commands, if
* they weren't already created by the init procedures called above.
*/
/*
* Specify a user-specific startup file to invoke if the application
* is run interactively. Typically the startup file is "~/.apprc"
* where "app" is the name of the application. If this line is deleted
* then no user-specific startup file will be run under any conditions.
*/
return TCL_OK;
}
#include <signal.h>
static int gotIntr;
extern int Tcl_NumEventsFound(void);
{
}
{
return 1;
}
{
if (Tcl_NumEventsFound() < 0)
{
gotIntr = 1;;
}
}
{
*((int *)clientData) = 1;
}
{
/* Tcl_DeleteFileHandler(*filePtr); */
}
#include <wait.h>
{
gotIntr = 0;
if (fd >= 0)
{
}
if (tmout> 0)
result = Tcl_DoOneEvent(0);
if (gotIntr)
{
result = -1;
} else
{
result = 1;
}
if (tmout > 0)
if (file)
return result;
}
#if 0
static void stoptk(void)
{
Tcl_Exit(0);
}
#endif
{
if (argc == 0)
{
argc = 1;
}
/* atexit(stoptk); */
return 0;
}