This is customAppInit.c in view mode; [Download] [Up]
/* customAppInit.c for pencilTCL ptcl */
/* compile with cc customAppInit.c -ObjC -ltcl -lNeXT_s -u _main -o ptcl */
/*
* tclAppInit --
*
* Provides a default version of the Tcl_AppInit procedure.
*
* Copyright (c) 1993 The Regents of the University of California.
* All rights reserved.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the
* above copyright notice and the following two paragraphs appear in
* all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/
#ifndef lint
static char rcsid[] = "$Header: /user6/ouster/tcl/RCS/tclAppInit.c,v 1.6 93/08/26 14:34:55 ouster Exp $ SPRITE (Berkeley)";
#endif /* not lint */
/* Changed this from "tcl.h" to <tcl.h>. Maybe you have to change this. */
#import <tcl.h>
/*
* The following variable is a special hack that allows applications
* to be linked using the procedure "main" from the Tcl library. The
* variable generates a reference to "main", which causes main to
* be brought in from the library (and all of Tcl with it).
*/
extern int main();
int *tclDummyMainPtr = (int *) main;
/* BEGIN of PencilTCL specific functions */
#import <appkit/appkit.h>
#import <remote/NXConnection.h>
#import <remote/NXProxy.h>
/* Global variable: the server (Inspector in Pencil.app) */
id server;
/* Interface declaration for the server-object */
@interface PencilInspector:Object
{
}
- (char *)performCommand:(const char *)cmd;
@end
int
Tcl_ForToCmd(dummy, interp, argc, argv)
ClientData dummy; /* Not used. */
Tcl_Interp *interp; /* Current interpreter. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
char mystring[20];
if(argc>=5)
{
int s,z,i;
Tcl_ExprLong(interp, argv[2], &s);
Tcl_ExprLong(interp, argv[3], &z);
for(i=s;i<=z;i++)
{
sprintf(mystring,"%d",i);
Tcl_SetVar(interp, argv[1], mystring, 0);
Tcl_Eval(interp, argv[4]);
}
}
return TCL_OK;
}
int
Tcl_PencilCmd(dummy, interp, argc, argv)
ClientData dummy; /* Not used. */
Tcl_Interp *interp; /* Current interpreter. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
if(argc>=2)
{
char *theresult;
theresult=[server performCommand:argv[1]];
Tcl_SetResult(interp,theresult, TCL_VOLATILE);
free(theresult);
}
return TCL_OK;
}
int
Tcl_MyExitCmd(dummy, interp, argc, argv)
ClientData dummy; /* Not used. */
Tcl_Interp *interp; /* Current interpreter. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
[NXApp free];
return Tcl_ExitCmd(dummy,interp,argc,argv);
}
int
Init_PencilTCL(Tcl_Interp *interp)
{
Tcl_CreateCommand(interp, "forto", Tcl_ForToCmd, 0, NULL);
Tcl_CreateCommand(interp, "pencil", Tcl_PencilCmd, 0, NULL);
Tcl_CreateCommand(interp, "exit", Tcl_MyExitCmd, 0, NULL);
[Application new];
/* DO is great! ONE line to connect to Server: */
/* Connection on current host. If you want to send commands to Pencil */
/* over the network, change NULL to "*" */
if(!(server=[NXConnection connectToName:"pencilTCLServer" onHost:NULL])) {
puts("Connection failed.\n");
puts("Please enter 'exit', start Pencil and choose \"Info>Register as TCL Server\"\n");
[Application free];
return TCL_ERROR;
}
return TCL_OK;
}
/* END of PencilTCL specific commands */
/*
*----------------------------------------------------------------------
*
* Tcl_AppInit --
*
* This procedure performs application-specific initialization.
* Most applications, especially those that incorporate additional
* packages, will have their own version of this procedure.
*
* Results:
* Returns a standard Tcl completion code, and leaves an error
* message in interp->result if an error occurs.
*
* Side effects:
* Depends on the startup script.
*
*----------------------------------------------------------------------
*/
int
Tcl_AppInit(interp)
Tcl_Interp *interp; /* Interpreter for application. */
{
static char initCmd[] =
"if [file exists [info library]/init.tcl] {\n\
source [info library]/init.tcl\n\
}";
/*
* 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.
*/
// source init.tcl:
Tcl_Eval(interp, initCmd);
/*
* 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.
*/
tcl_RcFileName = "pencilTCL_startup.tcl";
return (Init_PencilTCL(interp));
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.