home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
online
/
source
/
c
/
compilers
/
Tickle-4.0.sit.hqx
/
Tickle-4.0
/
src
/
tcl.c
< prev
next >
Wrap
Text File
|
1993-11-21
|
60KB
|
2,915 lines
/*
** This source code was written by Tim Endres
** Email: time@ice.com.
** USMail: 8840 Main Street, Whitmore Lake, MI 48189
**
** Some portions of this application utilize sources
** that are copyrighted by ICE Engineering, Inc., and
** ICE Engineering retains all rights to those sources.
**
** Neither ICE Engineering, Inc., nor Tim Endres,
** warrants this source code for any reason, and neither
** party assumes any responsbility for the use of these
** sources, libraries, or applications. The user of these
** sources and binaries assumes all responsbilities for
** any resulting consequences.
*/
#pragma segment TCL2
#include "tickle.h"
#include "tge.h"
#include "tcl.h"
#include "tclExtend.h"
#include "tclMac.h"
#include "XTCL.h"
#include "version.h"
#include <stdarg.h>
#include "stat.h"
#define YIELD_MAC_COMMAND_NAME "yield_mac"
extern int errno;
extern int macintoshErr;
extern char *tcl_getenv();
tcl_feedback_output(str)
char *str;
{
char *ptr, *save;
for ( ptr = str ; *ptr ; )
{
for ( save = ptr ; *ptr && *ptr != '\015' && *ptr != '\012' ; ++ptr )
;
Feedback("%.*s", (int)(save - ptr), save);
if (*ptr != '\0')
++ptr;
}
}
run_named_tcl_script(filename, interp, print_proc)
char *filename; /* Pascal */
Tcl_Interp *interp;
PFI print_proc;
{
int result = noErr;
int delete_interp = 0;
PFI saveproc;
char command[128];
TclTickle_BegYield();
WatchCursorOn();
if (interp == (Tcl_Interp *)0)
{
interp = g_interp;
}
if (print_proc != (PFI)0)
saveproc = Tcl_SetPrintProcedure(print_proc);
sprintf(command, "source \"%.*s\"\n", filename[0], &filename[1]);
result = Tcl_Eval(interp, command, 0, (char **)0);
if (result == TCL_OK)
{
result = noErr;
if (interp->result != NULL && *(interp->result) != '\0')
(* Tcl_GetPrintProcedure()) (interp->result);
}
else
{
(* Tcl_GetPrintProcedure()) ( (result == TCL_ERROR) ? "Error: " : "Bad Result: " );
(* Tcl_GetPrintProcedure()) ( (interp->result == NULL) ? "<NULL>" : interp->result );
}
if (print_proc != (PFI)0)
Tcl_SetPrintProcedure(saveproc);
TclTickle_EndYield();
UInitCursor();
return result;
}
#ifdef TCLAPPL
run_tcl_script(interp, print_proc)
Tcl_Interp *interp;
PFI print_proc;
{
int result;
int delete_interp = 0;
PFI saveproc;
char command[128];
Point mypoint;
SFReply myreply;
SFTypeList mytypes;
mypoint.h = mypoint.v = 75;
mytypes[0] = 'TEXT';
MyGetFile(mypoint, "\pScript:", NULL, (CheckOption()?-1:1), mytypes, NULL, &myreply);
if (myreply.good)
{
TclTickle_BegYield();
WatchCursorOn();
if (interp == (Tcl_Interp *)0)
{
interp = g_interp;
}
if (print_proc != (PFI)0)
saveproc = Tcl_SetPrintProcedure(print_proc);
SetVol(NULL, myreply.vRefNum);
sprintf(command, "source \"%.*s\"\n", myreply.fName[0], &myreply.fName[1]);
result = Tcl_Eval(interp, command, 0, (char **)0);
if (result == TCL_OK)
{
if (interp->result != NULL && *(interp->result) != '\0')
(* Tcl_GetPrintProcedure()) (interp->result);
}
else
{
(* Tcl_GetPrintProcedure()) ( (result == TCL_ERROR) ? "Error: " : "Bad Result: " );
(* Tcl_GetPrintProcedure()) ( (interp->result == NULL) ? "<NULL>" : interp->result );
}
if (print_proc != (PFI)0)
Tcl_SetPrintProcedure(saveproc);
TclTickle_EndYield();
UInitCursor();
}
}
#endif
/*
*----------------------------------------------------------------------
*
* Cmd_DoMenuCmd --
* Implements the TCL cd command:
* cd [directory]
* See the oscmds(TCL) manual page.
*
* Results:
* Standard TCL results, may return the UNIX system error message.
*
*----------------------------------------------------------------------
*/
int
Cmd_DoMenuCmd(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
#ifdef TCLAPPL
int menu, item;
long menu_select;
#pragma unused (clientData)
if (argc != 3)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" menuName menuItemNum\"", (char *) NULL);
return TCL_ERROR;
}
UInitCursor();
if (strcmp(argv[1], "Apple") == SAMESTR)
menu = 1;
else if (strcmp(argv[1], "File") == SAMESTR)
menu = 256;
else if (strcmp(argv[1], "Edit") == SAMESTR)
menu = 257;
else if (strcmp(argv[1], "Mac") == SAMESTR)
menu = 258;
else if (strcmp(argv[1], "Tcl") == SAMESTR)
menu = 269;
else if (strcmp(argv[1], "Text") == SAMESTR)
menu = 259;
else if (strcmp(argv[1], "UNIX") == SAMESTR)
menu = 260;
else if (strcmp(argv[1], "Tar") == SAMESTR)
menu = 296;
else if (strcmp(argv[1], "Tar!Options") == SAMESTR)
menu = 96;
else if (strcmp(argv[1], "ASD") == SAMESTR)
menu = 262;
else if (strcmp(argv[1], "StuffIt") == SAMESTR)
menu = 261;
else {
Tcl_AppendResult(interp, "unknown menu name \"", argv[1],
"\"", (char *) NULL);
return TCL_ERROR;
}
item = atoi(argv[2]);
if (item == 0)
{
Tcl_AppendResult(interp, "non-numeric menu item \"", argv[2],
"\"", (char *) NULL);
return TCL_ERROR;
}
/* UNDONE - check item# against CountMItems() */
menu_select = ((menu << 16) & 0xFFFF0000);
menu_select |= (item & 0x0000FFFF);
/* UNDONE - do I have to check for "active"? */
do_command(menu_select);
return TCL_OK;
#else
#pragma unused (clientData, interp, argc, argv)
Tcl_AppendResult(interp, "\"", argv[0], "\" unimplemented in engine", (char *) NULL);
return TCL_ERROR;
#endif
}
int
Cmd_DebugStr(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
int length;
Str255 pascal_str;
#pragma unused (clientData)
if (argc != 2)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" message\"", (char *) NULL);
return TCL_ERROR;
}
if (tcl_getenv("noMACdebugger") == NULL)
{
length = strlen(argv[1]);
strncpy(pascal_str, argv[1], 254);
pascal_str[0] = (length < 254 ? length : 254);
DebugStr(pascal_str);
}
else
{
Tcl_AppendResult(interp, "MACDEBUG - \"", argv[1], "\" ", NULL);
}
return TCL_OK;
}
int
Cmd_AskYesNoCancel(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
#ifdef TCLAPPL
int result;
#pragma unused (clientData, argc)
if ( argc != 2 )
{
Tcl_AppendResult(interp, "wrong # args: should be \"",
argv[0], " question\"", NULL);
return TCL_ERROR;
}
UInitCursor();
c2pstr(argv[1]);
ParamText(argv[1], NULL, NULL, NULL);
result = Alert(1015, (ModalFilterProcPtr)/*0*/UniversalFilter);
p2cstr(argv[1]);
if (result == 1) {
Tcl_SetResult(interp, "yes", TCL_VOLATILE);
}
else if (result == 2) {
Tcl_SetResult(interp, "no", TCL_VOLATILE);
}
else if (result == 3) {
Tcl_SetResult(interp, "cancel", TCL_VOLATILE);
}
return TCL_OK;
#else
#pragma unused (clientData, interp, argc, argv)
Tcl_AppendResult(interp, "\"", argv[0], "\" unimplemented in engine", (char *) NULL);
return TCL_ERROR;
#endif
}
int
Cmd_GetInputLine(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
#ifdef TCLAPPL
DialogPtr myDialog;
short itemhit;
char mystr[256];
#pragma unused (clientData, argc)
UInitCursor();
myDialog = GetNewDialog(2007, NULL, (WindowPtr)-1);
if (myDialog == NULL) {
Tcl_AppendResult(interp, "\"", argv[0], "\" can not load dialog 2007", (char *) NULL);
return TCL_ERROR;
}
if (argc > 1)
MySetText(myDialog, 3, argv[1]);
if (argc > 2) {
MySetText(myDialog, 4, argv[2]);
SelIText(myDialog, 4, 0, 1023);
}
for ( ; ; ) {
SetPort(myDialog);
FrameButton(myDialog, ok);
ModalDialog((ModalFilterProcPtr)/*0*/UniversalFilter, &itemhit);
if (itemhit == ok) {
MyGetText(myDialog, 4, mystr);
Tcl_SetResult(interp, mystr, TCL_VOLATILE);
break;
}
else if (itemhit == cancel) {
Tcl_SetResult(interp, "", TCL_VOLATILE);
break;
}
}
CloseDialog(myDialog);
return TCL_OK;
#else
#pragma unused (clientData, interp, argc, argv)
Tcl_AppendResult(interp, "\"", argv[0], "\" unimplemented in engine", (char *) NULL);
return TCL_ERROR;
#endif
}
int
Cmd_GetDirectory(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
#ifdef TCLAPPL
char path[256];
short vRefNum;
long dirID;
# pragma unused (clientData)
if (argc != 2)
{
Tcl_AppendResult(interp, "wrong # args: should be \"",
argv[0], " prompt\"", NULL);
return TCL_ERROR;
}
path[0] = '\0';
if ( ! GetFolderPathName(argv[1], path, &vRefNum, &dirID ) )
Tcl_SetResult(interp, "", TCL_VOLATILE);
else {
Tcl_SetResult(interp, path, TCL_VOLATILE);
}
return TCL_OK;
#else
#pragma unused (clientData, argc)
Tcl_AppendResult(interp, "\"", argv[0], "\" unimplemented in engine", (char *) NULL);
return TCL_ERROR;
#endif
}
int
Cmd_GetFile(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
#ifdef TCLAPPL
char path[256], prompt[256], *ptr, *ptr2;
int i, j;
Point mypoint;
SFReply myreply;
SFTypeList mytypes;
#pragma unused (clientData, argc, argv)
if ( argc < 2)
{
Tcl_AppendResult(interp, "wrong # args: should be \"",
argv[0], " prompt ?types...?\"", NULL);
return TCL_ERROR;
}
i = -1;
strcpy(prompt, argv[1]);
c2pstr(prompt);
if (argc > 2)
{
for ( ptr=argv[2],i=0 ; i < 4 && *ptr ; ++i )
{
ptr2 = (char *) &mytypes[i];
for ( j = 0 ; j < 4 ; ++j )
{
*ptr2++ = (*ptr) ? *ptr++ : ' ';
}
}
if (i == 0)
i = -1;
}
mypoint.h = mypoint.v = 75;
MyGetFile(mypoint, prompt, NULL, i, mytypes, NULL, &myreply);
if (myreply.good)
{
p2cstr(myreply.fName);
fullname(path, myreply.vRefNum, myreply.fName);
Tcl_SetResult(interp, path, TCL_VOLATILE);
}
else {
Tcl_SetResult(interp, "", TCL_VOLATILE);
}
return TCL_OK;
#else
#pragma unused (clientData, argc)
Tcl_AppendResult(interp, "\"", argv[0], "\" unimplemented in engine", (char *) NULL);
return TCL_ERROR;
#endif
}
int
Cmd_PutFile(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
#ifdef TCLAPPL
char path[256], prompt[256], original[128];
int i;
Point mypoint;
SFReply myreply;
#pragma unused (clientData, argc, argv)
if ( argc != 3 )
{
Tcl_AppendResult(interp, "wrong # args: should be \"",
argv[0], " prompt default\"", NULL);
return TCL_ERROR;
}
path[0] = '\0';
original[0] = '\0';
i = -1;
strcpy(prompt, argv[1]);
c2pstr(prompt);
strcpy(original, argv[2]);
c2pstr(original);
mypoint.h = mypoint.v = 75;
MyPutFile(mypoint, prompt, original, NULL, &myreply);
if (myreply.good)
{
p2cstr(myreply.fName);
fullname(path, myreply.vRefNum, myreply.fName);
Tcl_SetResult(interp, path, TCL_VOLATILE);
}
else
{
Tcl_SetResult(interp, "", TCL_VOLATILE);
}
return TCL_OK;
#else
#pragma unused (clientData, argc)
Tcl_AppendResult(interp, "\"", argv[0], "\" unimplemented in engine", (char *) NULL);
return TCL_ERROR;
#endif
}
#ifdef TCLAPPL
static ListHandle picklist = NULL;
static char string_reply[256];
#define SetCell(cell, row, column) { (cell).h = column; (cell).v = row; }
#define ROW(cell) (cell).v
pascal void
MacListUpdate(myDialog, myItem)
DialogPtr myDialog;
short myItem;
{
Rect myrect;
#pragma unused (myItem)
LUpdate(myDialog->visRgn, picklist);
myrect = (**(picklist)).rView;
InsetRect(&myrect, -1, -1);
FrameRect(&myrect);
}
pascal Boolean
MacListFilter(myDialog, myEvent, myItem)
DialogPtr myDialog;
EventRecord *myEvent;
short *myItem;
{
Rect listrect;
short myascii;
Handle myhandle;
Point mypoint;
short mytype;
SetPort(myDialog);
if (myEvent->what == keyDown) {
myascii = myEvent->message % 256;
if (myascii == '\015' || myascii == '\003') { /* This is return or enter... */
*myItem = 1;
return true;
}
}
else if (myEvent->what == mouseDown) {
mypoint = myEvent->where;
GlobalToLocal(&mypoint);
GetDItem(myDialog, 4, &mytype, &myhandle, &listrect);
if (PtInRect(mypoint, &listrect) && picklist != NULL) {
if (LClick(mypoint, (short)myEvent->modifiers, picklist)) {
/* User double-clicked in cell... */
*myItem = 1;
return true;
}
}
}
else if (myEvent->what == updateEvt) {
wind_parse((WindowPtr) myEvent->message, myEvent, wUpdate);
}
else if (myEvent->what == activateEvt) {
if (picklist != NULL && (WindowPtr)myEvent->message == myDialog)
LActivate((Boolean)((myEvent->modifiers & 0x01) != 0), picklist);
wind_parse((WindowPtr) myEvent->message, myEvent, wActivate);
}
return false;
}
#endif
int
Cmd_MacListPick(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
#ifdef TCLAPPL
short itemhit, done, row, result, length;
DialogPtr mydialog;
ListHandle mylist;
Cell mycell;
short mytype;
Handle myhandle;
Point cellsize;
Rect listrect, dbounds;
int listArgc;
char **listArgv;
#pragma unused (clientData)
if ( argc != 3 )
{
Tcl_AppendResult(interp, "wrong # args: should be \"",
argv[0], " prompt itemlist\"", NULL);
return TCL_ERROR;
}
InitCursor();
mydialog = GetNewDialog(3030, NULL, (WindowPtr)-1);
if (mydialog == NULL)
{
Tcl_AppendResult(interp, "error \"", argv[0],
"\" can not load dialog 3030", NULL);
return TCL_ERROR;
}
MySetText(mydialog, 3, argv[1]);
if (Tcl_SplitList (interp, argv[1], &listArgc, &listArgv) != TCL_OK)
{
return TCL_ERROR;
}
GetDItem(mydialog, 4, &mytype, &myhandle, &listrect);
SetDItem(mydialog, 4, mytype, (Handle)MacListUpdate, &listrect);
SetPort(mydialog);
InsetRect(&listrect, 1, 1);
SetRect(&dbounds, 0, 0, (short)1, (short)0);
cellsize.h = (listrect.right - listrect.left);
cellsize.v = 17;
listrect.right -= 15;
picklist = LNew(&listrect, &dbounds, cellsize, (short)0,
mydialog, true, false, (Boolean)0, (Boolean)1);
if (picklist == NULL) {
DisposDialog(mydialog);
Tcl_AppendResult(interp, "\"", argv[0], "\" could not create dialog list", (char *) NULL);
ckfree((char *) listArgv);
return TCL_ERROR;
}
mylist = picklist;
LDoDraw(FALSE, mylist);
for (row=0 ; listArgc > 0 ; row++, listArgc--) {
LAddRow(1, row, mylist);
SetCell(mycell, (short)row, 0);
LSetCell((Ptr)listArgv[row], (short)strlen(listArgv[row]), mycell, mylist);
}
ckfree((char *) listArgv);
LDoDraw(TRUE, mylist);
/* CenterWindow(mydialog); */
ShowWindow(mydialog);
for (done=0; ! done; ) {
SetPort(mydialog);
FrameButton(mydialog, ok);
ModalDialog(MacListFilter, &itemhit);
switch (itemhit) {
case ok:
SetCell(mycell, 0, 0);
done = 1; result = 0;
if (LGetSelect((short)true, &mycell, picklist)) {
length = 255;
LGetCell(string_reply, &length, mycell, picklist);
string_reply[length] = '\0';
result = 1;
}
break;
case cancel:
done = 1; result = 0;
break;
}
} /* Modal Loop */
if (result) {
Tcl_SetResult(interp, string_reply, TCL_VOLATILE);
}
else {
Tcl_SetResult(interp, "", TCL_VOLATILE);
}
SetPort(mydialog);
LDispose(mylist);
picklist = (ListHandle)0;
DisposDialog(mydialog);
return TCL_OK;
#else
#pragma unused (clientData, interp, argc, argv)
Tcl_AppendResult(interp, "\"", argv[0], "\" unimplemented in engine", (char *) NULL);
return TCL_ERROR;
#endif
}
int
Cmd_DoAlertNote(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
int length;
char pascal_str[256];
#pragma unused (clientData)
if (argc != 2)
{
Tcl_AppendResult(interp, "wrong # args: usage - \"", argv[0],
" message\" ", (char *) NULL);
return TCL_ERROR;
}
message_note("%.254s", argv[1]);
return TCL_OK;
}
int
Cmd_DoDeCompress(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
int result;
FILE *infile, *outfile;
#pragma unused (clientData)
if (argc != 3)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" compressedfilename newfilename\"", (char *) NULL);
return TCL_ERROR;
}
infile = fopen(argv[1], "r");
if (infile == NULL)
{
Tcl_AppendResult(interp, "\"", argv[0], "\" could not open '", argv[1], "' ",
Tcl_UnixError(interp), (char *) NULL);
return TCL_ERROR;
}
outfile = fopen(argv[2], "w");
if (outfile == NULL) {
fclose(infile);
Tcl_AppendResult(interp, "\"", argv[0], "\" could not open '", argv[2], "' ",
Tcl_UnixError(interp), (char *) NULL);
return TCL_ERROR;
}
result = cunbatch(infile, outfile);
WatchCursorOn();
fclose(infile);
fclose(outfile);
free_compress_memory();
UInitCursor();
if (result)
return TCL_OK;
else
{
Tcl_AppendResult(interp, "de-compress failed", (char *) NULL);
return TCL_ERROR;
}
}
int
Cmd_DoCompress(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
int result, getbits;
FILE *infile, *outfile;
#pragma unused (clientData)
if (argc != 4)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" bits infile outfile\"", (char *) NULL);
return TCL_ERROR;
}
getbits = atoi(argv[1]);
if (getbits == 0)
{
Tcl_AppendResult(interp, "non-numeric compress bits argument \"", argv[1],
"\"", (char *) NULL);
return TCL_ERROR;
}
infile = fopen(argv[2], "r");
if (infile == NULL)
{
Tcl_AppendResult(interp, "\"", argv[0], "\" could not open '", argv[2], "' ",
Tcl_UnixError(interp), (char *) NULL);
return TCL_ERROR;
}
outfile = fopen(argv[3], "w");
if (outfile == NULL)
{
fclose(infile);
Tcl_AppendResult(interp, "\"", argv[0], "\" could not open '", argv[3], "' ",
Tcl_UnixError(interp), (char *) NULL);
return TCL_ERROR;
}
if (! get_compress_memory(getbits))
{
SetZone(ApplicZone());
Tcl_AppendResult(interp, "not enough memory for decompress", NULL);
return TCL_ERROR;
}
result = compress(infile, outfile);
WatchCursorOn();
fclose(infile);
fclose(outfile);
set_file_type(argv[3], 0, APPL_TYPE, (OSType)'ZIVU');
free_compress_memory();
UInitCursor();
if (result)
return TCL_OK;
else
{
Tcl_AppendResult(interp, "compress failed", (char *) NULL);
return TCL_ERROR;
}
}
int
Cmd_EncodeHQX(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
short wdRefNum, push_err;
int result;
#pragma unused (clientData)
if (argc != 3)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" mac_filename hqx_filename\"", (char *) NULL);
return TCL_ERROR;
}
result = TclMac_CWDCreateWD(&wdRefNum);
if (result != noErr)
{
Tcl_AppendResult(interp, "could not create working directory - ",
Tcl_MacGetError(interp, result), NULL);
return TCL_ERROR;
}
push_err = TclMac_CWDPushVol();
result = do_encode_hqx(wdRefNum, argv[1], wdRefNum, argv[2]);
if (push_err == noErr)
TclMac_CWDPopVol();
TclMac_CWDDisposeWD(wdRefNum);
if (result == noErr)
{
return TCL_OK;
}
else
{
Tcl_AppendResult(interp, "binhex of \"", argv[1], "\" failed", (char *) NULL);
return TCL_ERROR;
}
}
int
Cmd_DecodeHQX(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
int result, push_err;
short wdRefNum;
#pragma unused (clientData)
if (argc != 3)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" infile outfile\"", (char *) NULL);
return TCL_ERROR;
}
result = TclMac_CWDCreateWD(&wdRefNum);
if (result != noErr)
{
Tcl_AppendResult(interp, "could not create working directory - ",
Tcl_MacGetError(interp, result), NULL);
return TCL_ERROR;
}
push_err = TclMac_CWDPushVol();
result = do_decode_hqx(wdRefNum, argv[1], wdRefNum, argv[2]);
if (push_err == noErr)
TclMac_CWDPopVol();
TclMac_CWDDisposeWD(wdRefNum);
if (result == noErr)
return TCL_OK;
else
{
Tcl_AppendResult(interp, "unbinhex of \"", argv[1], "\" failed", (char *) NULL);
return TCL_ERROR;
}
}
int
Cmd_UUEncode(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
int result, push_err;
short wdRefNum;
SFReply inreply;
SFReply outreply;
#pragma unused (clientData)
if (argc != 3)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" infile uufile\"", (char *) NULL);
return TCL_ERROR;
}
result = TclMac_CWDCreateWD(&wdRefNum);
if (result != noErr)
{
Tcl_AppendResult(interp, "could not create working directory - ",
Tcl_MacGetError(interp, result), NULL);
return TCL_ERROR;
}
push_err = TclMac_CWDPushVol();
inreply.vRefNum = wdRefNum;
strcpy(inreply.fName, argv[1]);
c2pstr(inreply.fName);
outreply.vRefNum = wdRefNum;
strcpy(outreply.fName, argv[2]);
c2pstr(outreply.fName);
result = uuencode(&inreply, &outreply, FALSE);
if (push_err == noErr)
TclMac_CWDPopVol();
TclMac_CWDDisposeWD(wdRefNum);
if (result == SUCCESS)
{
result = TCL_OK;
}
else {
Tcl_AppendResult(interp, "uuencode of \"", argv[1], "\" failed", (char *) 0);
result = TCL_ERROR;
}
return result;
}
int
Cmd_Mac_To_AS(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
short wdRefNum;
int result, push_err;
#pragma unused (clientData)
if (argc != 3)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" macfile asfile\"", (char *) NULL);
return TCL_ERROR;
}
UBegYield();
result = TclMac_CWDCreateWD(&wdRefNum);
if (result != noErr)
{
Tcl_AppendResult(interp, "could not create working directory - ",
Tcl_MacGetError(interp, result), NULL);
return TCL_ERROR;
}
push_err = TclMac_CWDPushVol();
result = do_mac_to_asingle(
argv[1], wdRefNum,
argv[2], wdRefNum,
FALSE, FALSE );
WatchCursorOn();
if (push_err == noErr)
TclMac_CWDPopVol();
TclMac_CWDDisposeWD(wdRefNum);
UEndYield();
UInitCursor();
if (result == noErr)
{
result = TCL_OK;
}
else {
Tcl_AppendResult(interp, "AS encode of \"", argv[1], "\" failed", (char *) 0);
result = TCL_ERROR;
}
return result;
}
int
Cmd_Mac_To_MB(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
short refnum, wdRefNum;
int result = TCL_OK, myerr, push_err;
#pragma unused (clientData)
if (argc != 3)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" macfile mbfile\"", (char *) NULL);
return TCL_ERROR;
}
myerr = TclMac_CWDCreateWD(&wdRefNum);
if (myerr != noErr)
{
Tcl_AppendResult(interp, "could not create working directory - ",
Tcl_MacGetError(interp, result), NULL);
return TCL_ERROR;
}
push_err = TclMac_CWDPushVol();
SetVol( NULL, wdRefNum );
c2pstr(argv[2]);
myerr = Create(argv[2], wdRefNum, APPL_TYPE, (ResType)'MacB');
p2cstr(argv[2]);
if (myerr == dupFNErr)
{
file_type(argv[2], (ResType)'MacB', APPL_TYPE);
}
c2pstr(argv[2]);
myerr = FSOpen(argv[2], wdRefNum, &refnum);
p2cstr(argv[2]);
if (myerr != noErr)
{
Tcl_AppendResult(interp, "error opening macintosh file \"",
argv[2], "\"", Tcl_MacGetError(interp, myerr),
(char *) 0);
result = TCL_ERROR;
}
else
{
UBegYield();
c2pstr(argv[1]);
myerr = insert_macbinary( refnum, argv[1],
TclMac_CWDVRefNum(), TclMac_CWDDirID() );
p2cstr(argv[1]);
if (myerr != noErr)
{
Tcl_AppendResult(interp, "MacBinary encode of \"", argv[1],
"\" failed ", Tcl_MacGetError(interp, myerr),
(char *) 0);
result = TCL_ERROR;
}
WatchCursorOn();
FSClose(refnum);
UEndYield();
}
if (push_err == noErr)
TclMac_CWDPopVol();
TclMac_CWDDisposeWD(wdRefNum);
UInitCursor();
return result;
}
int
Cmd_Mac_To_AD(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
short wdRefNum;
int result, push_err, myerr;
#pragma unused (clientData)
if (argc != 4)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" macfile adfile datafile\"", (char *) NULL);
return TCL_ERROR;
}
UBegYield();
myerr = TclMac_CWDCreateWD(&wdRefNum);
if (myerr != noErr)
{
Tcl_AppendResult(interp, "could not create working directory - ",
Tcl_MacGetError(interp, result), NULL);
return TCL_ERROR;
}
push_err = TclMac_CWDPushVol();
result = do_mac_to_adouble(
argv[1], wdRefNum,
argv[2], wdRefNum,
argv[3], wdRefNum,
FALSE, FALSE );
WatchCursorOn();
if (push_err == noErr)
TclMac_CWDPopVol();
TclMac_CWDDisposeWD(wdRefNum);
UEndYield();
UInitCursor();
if (result == noErr)
{
result = TCL_OK;
}
else {
Tcl_AppendResult(interp, "ASD decode of \"", argv[1], "\" failed", (char *) 0);
result = TCL_ERROR;
}
return result;
}
int
Cmd_ASD_To_Mac(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
short wdRefNum;
int result, push_err, myerr;
char asd_fname[64], *ptr, mac_fname[256];
FILE *asdfile;
#pragma unused (clientData)
if (argc != 3)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" asdfile macfile\"", (char *) NULL);
return TCL_ERROR;
}
asdfile = fopen(argv[1], "r");
if (asdfile == NULL)
{
Feedback("Error #%d opening Apple Single/Double file '%s'",
errno, argv[1]);
return FAILURE;
}
ptr = strrchr(argv[1], ':');
if (ptr != NULL)
{
strcpy(asd_fname, ptr + 1);
}
else
{
strcpy(asd_fname, argv[1]);
}
strcpy(mac_fname, argv[2]);
c2pstr(mac_fname);
myerr = TclMac_CWDCreateWD(&wdRefNum);
if (myerr != noErr)
{
Tcl_AppendResult(interp, "could not create working directory - ",
Tcl_MacGetError(interp, result), NULL);
return TCL_ERROR;
}
push_err = TclMac_CWDPushVol();
UBegYield();
result = do_asd_to_mac( asd_fname, asdfile,
mac_fname, wdRefNum, FALSE );
WatchCursorOn();
fclose(asdfile);
if (push_err == noErr)
TclMac_CWDPopVol();
TclMac_CWDDisposeWD(wdRefNum);
UEndYield();
UInitCursor();
if (result == noErr)
{
result = TCL_OK;
}
else {
Tcl_AppendResult(interp, "ASD decode of \"", argv[1], "\" failed", (char *) 0);
result = TCL_ERROR;
}
return result;
}
int
Cmd_UUDecode(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
short wdRefNum;
int result, push_err, myerr;
SFReply myreply;
#pragma unused (clientData)
if (argc != 2)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" uufile\"", (char *) NULL);
return TCL_ERROR;
}
myerr = TclMac_CWDCreateWD(&wdRefNum);
if (myerr != noErr)
{
Tcl_AppendResult(interp, "could not create working directory - ",
Tcl_MacGetError(interp, result), NULL);
return TCL_ERROR;
}
push_err = TclMac_CWDPushVol();
myreply.vRefNum = wdRefNum;
strcpy(myreply.fName, argv[1]);
c2pstr(myreply.fName);
result = uudecode(&myreply, FALSE);
if (push_err == noErr)
TclMac_CWDPopVol();
TclMac_CWDDisposeWD(wdRefNum);
if (result == SUCCESS)
{
result = TCL_OK;
}
else {
Tcl_AppendResult(interp, "uudecode of \"", argv[1], "\" failed", (char *) 0);
result = TCL_ERROR;
}
return result;
}
int
Cmd_Feedback(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
int i;
char output[256];
#pragma unused (interp, clientData, argc)
output[0] = '\0';
for (i = 1 ; i < argc && (strlen(output) + strlen(argv[i]) + 2) < 256 ; ++i)
{
strcat(output, argv[i]);
strcat(output, " ");
}
Feedback("%.256s", output);
return TCL_OK;
}
Cmd_LogControl(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char *argv[];
{
#pragma unused (clientData)
if (argc < 2 || argc > 3)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" on|off ?file?\"", (char *) NULL);
return TCL_ERROR;
}
if (strcmp(argv[1], "on") == 0)
{
if (logfile == NULL)
{
extern int errno;
if (argc == 3)
strcpy(g_log_filename, argv[2]);
SetVol(NULL, g_log_wdref);
logfile = fopen(g_log_filename, "a");
if (logfile == NULL)
{
Tcl_AppendResult(interp, "error opening logfile \"", g_log_filename,
"\"", (char *) NULL);
return TCL_ERROR;
}
else
{
SetItem(file_menu_hdl, log_item, "\pEnd Logging");
}
}
}
else
{
if (logfile != NULL)
{
fclose(logfile);
FlushVol(NULL, g_log_wdref);
logfile = (FILE *)0;
SetItem(file_menu_hdl, log_item, "\pBegin Logging");
}
}
}
space_cnt(str)
char *str;
{
int count;
for (count=0 ; *str ; str++)
if (*str == ' ')
count++;
return count;
}
int
Cmd_EscapeSpaces(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
int i, length;
char *save, *ptr, *ptr2;
#pragma unused (clientData)
if (argc < 2)
{
Tcl_SetResult(interp, "", TCL_VOLATILE);
return TCL_OK;
}
for (length = 0, i = 1 ; i < argc ; i++)
{
length += strlen(argv[i]) + 2; /* 2 for "\ " */
length += ( 2 * space_cnt(argv[i]) );
}
length += 8; /* terminator + */
save = ptr = malloc(length);
if (ptr == NULL)
{
Tcl_AppendResult(interp, "\"", argv[0], "\" out of memory", (char *) NULL);
return TCL_ERROR;
}
else {
for (length = 0, i = 1 ; i < argc ; i++)
{
if (i > 1) {
*ptr++ = '\\';
*ptr++ = ' ';
}
for (ptr2 = argv[i] ; *ptr2 ; )
{
if (*ptr2 == ' ' && ptr2 > argv[i] && *(ptr2-1) != '\\')
*ptr++ = '\\';
*ptr++ = *ptr2++;
}
}
*ptr = '\0';
Tcl_SetResult(interp, save, TCL_VOLATILE);
free(save);
}
return TCL_OK;
}
int
TclTickle_YieldMac(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
short emask;
int i,
got_event,
do_spin = 0,
do_event = 0,
event_ticks = 1;
WindowPtr whichwindow;
#pragma unused (clientData, interp)
if ( argc < 1 || argc > 4 )
{
Tcl_AppendResult(interp, "wrong # args: should be \"",
argv[0], " ?-spin? ?-event ticks?\"", NULL);
return TCL_ERROR;
}
for ( i = 1 ; i < argc ; ++i )
{
if ( strcmp(argv[i], "-spin") == 0 )
{
do_spin = 1;
}
else if ( strcmp(argv[i], "-event") == 0 )
{
do_event = 1;
if ( sscanf(argv[i+1], "%d", &event_ticks) != 1 )
{
Tcl_AppendResult(interp, "invalid ticks argument \"",
argv[i+1], "\"", NULL);
return TCL_ERROR;
}
++i;
}
else
{
Tcl_AppendResult(interp, "invalid argument \"",
argv[i], "\"", NULL);
return TCL_ERROR;
}
}
if (do_spin)
{
RotateCursor(32);
}
if (do_event)
{
DoYield();
if (cancel_current_op)
{
_tclmac_user_interrupt_ = 1;
}
else if (pause_op)
{
while (pause_op)
pausing();
}
}
return TCL_OK;
}
char *progress_expr = NULL;
Tcl_Interp *progress_interp = NULL;
void
SPTclProgress(message, start, end, pos)
char *message;
int start;
int end;
int pos;
{
int result = TCL_ERROR;
if (progress_expr != NULL && progress_interp != (Tcl_Interp *)0)
{
result = Tcl_Eval(progress_interp, progress_expr, 0, (char **)0);
}
if (result == TCL_OK)
{
strncpy(message, progress_interp->result, 254);
message[255] = '\0';
}
else
{
sprintf(message, "Completed %d of %d...", pos - start, end - start);
}
}
int
Cmd_StartProgress(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
int result, start, end, pos;
#pragma unused (clientData)
if (argc != 6)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" title start end pos msgexpr\"", (char *) NULL);
result = TCL_ERROR;
}
else
{
start = atoi(argv[2]);
end = atoi(argv[3]);
pos = atoi(argv[4]);
c2pstr(argv[1]);
StartProgressWindow(argv[1], start, end, pos, SPTclProgress);
p2cstr(argv[1]);
if (progress_expr != NULL)
free(progress_expr);
progress_expr = malloc(strlen(argv[5]) + 2);
if (progress_expr != NULL)
strcpy(progress_expr, argv[5]);
progress_interp = interp;
result = TCL_OK;
}
return result;
}
int
Cmd_UpdateProgress(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
int result, pos;
#pragma unused (clientData)
if (argc != 2)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" position\"", (char *) NULL);
result = TCL_ERROR;
}
else
{
pos = atoi(argv[1]);
UpdateProgress(pos);
result = TCL_OK;
}
return result;
}
int
Cmd_StopProgress(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
#pragma unused (clientData, interp, argc, argv)
if ( argc != 1 )
{
Tcl_AppendResult(interp, "wrong # args: should be \"",
argv[0], "\"", NULL);
return TCL_ERROR;
}
StopProgressWindow();
if (progress_expr != NULL)
free(progress_expr);
progress_expr = NULL;
progress_interp = (Tcl_Interp *)0;
return TCL_OK;
}
int
XTCL_Eval_CallBack(cpb, script_handle, result_handle, stdout_handle)
XTCLParmBlk *cpb;
Handle script_handle;
Handle result_handle;
Handle stdout_handle;
{
return Tcl_Interp_Handle(cpb->interp, script_handle, result_handle, stdout_handle);
}
int
Cmd_CallExternalCMD(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
Handle myhandle = NULL,
result_handle = NULL;
int myerr, result = TCL_OK, push_err;
short saveref, the_refnum = -1, user_ref = -1, wdRefNum;
char name[256];
XTCLParmBlk cbpb;
#pragma unused (clientData)
saveref = CurResFile();
if (argv[1][0] == '-' && argv[1][1] == 'f' && argv[1][2] == '\0')
{
myerr = TclMac_CWDCreateWD(&wdRefNum);
if (myerr != noErr)
{
Tcl_AppendResult(interp, "could not create working directory - ",
Tcl_MacGetError(interp, result), NULL);
return TCL_ERROR;
}
push_err = TclMac_CWDPushVol();
SetVol(NULL, wdRefNum);
c2pstr(argv[2]);
user_ref = OpenResFile(argv[2]);
p2cstr(argv[2]);
if (push_err == noErr)
TclMac_CWDPopVol();
TclMac_CWDDisposeWD(wdRefNum);
if (user_ref == -1)
{
macintoshErr = ResError();
Tcl_AppendResult(interp, "\"", argv[0], "\" OpenResfile(", argv[2], ") ",
Tcl_MacError(interp), (char *) NULL);
return TCL_ERROR;
}
else
the_refnum = user_ref;
strcpy(name, argv[3]);
argc -= 3;
argv += 3;
}
else
{
strcpy(name, argv[1]);
argc--;
argv++;
}
c2pstr(name);
if (user_ref != -1)
{
UseResFile(user_ref);
myhandle = GetNamedResource((ResType)'XTCL', name);
}
if (myhandle == NULL)
{
UseResFile(app_refnum);
the_refnum = app_refnum;
myhandle = GetNamedResource((ResType)'XTCL', name);
if (myhandle == NULL && xtcl_refnum != -1)
{
UseResFile(xtcl_refnum);
the_refnum = xtcl_refnum;
myhandle = GetNamedResource((ResType)'XTCL', name);
}
}
if (myhandle != NULL)
{
LoadResource(myhandle);
DetachResource(myhandle);
result_handle = NewHandle(1);
if (result_handle != NULL)
{
**result_handle = '\0';
cbpb.version = XTCL_CB_VERSION;
cbpb.result = noErr;
cbpb.resultH = result_handle;
cbpb.interp = interp;
cbpb.eval = XTCL_Eval_CallBack;
cbpb.cmdRefNum = the_refnum;
cbpb.cmdHandle = myhandle;
cbpb.modalproc = UniversalFilter;
UseResFile(the_refnum);
/* CallXTCL(argc, argv, &cbpb, *myhandle); */
HLock(myhandle);
#ifdef THINK_C
{
void (*proc)();
proc = *myhandle;
( * proc ) (argc, argv, &cbpb);
}
#else
( * ((ProcPtr) *myhandle) )(argc, argv, &cbpb);
#endif
HUnlock(myhandle);
UseResFile(saveref);
if (*result_handle != NULL && **result_handle != '\0')
{
HLock(result_handle);
Tcl_SetResult(interp, *result_handle, TCL_VOLATILE);
HUnlock(result_handle);
}
DisposHandle(result_handle);
result = cbpb.result;
}
else
{
char msg[64];
sprintf(msg, "error #%d getting result handle", MemError());
Tcl_AppendResult(interp, "\"", argv[0], "\" ", msg, (char *) NULL);
result = TCL_ERROR;
}
DisposHandle(myhandle);
}
else
{
char msg[96];
sprintf(msg, "error %d:%d:%d loading XTCL '%.*s'",
ResError(), MemError(), xtcl_refnum, name[0], &name[1]);
Tcl_AppendResult(interp, "\"", argv[0], "\" ", msg, (char *) NULL);
if (user_ref != -1)
CloseResFile(user_ref);
result = TCL_ERROR;
}
if (user_ref != -1)
CloseResFile(user_ref);
UseResFile(saveref);
return result;
}
tcl_dev_null_output(str)
char *str;
{
#pragma unused (str)
}
int
Cmd_GotoWindowLine(clientData, interp, argc, argv)
char *clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
#ifdef TCLAPPL
int linenum;
WindowPtr myWindow;
# pragma unused (clientData, argc, argv)
if (! ( (argc == 2) ||
(argc == 3 && strcmp(argv[1], "-nocomplain") == 0 ) ) )
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
"\" ?-nocomplain? linenum ", NULL);
return TCL_ERROR;
}
if ( sscanf( argv[(argc==2 ? 1 : 2)], "%d", &linenum ) != 1 )
{
Tcl_AppendResult(interp, "invalid line number \"",
argv[(argc==2 ? 1 : 2)], "\" ", NULL);
return TCL_ERROR;
}
myWindow = FrontWindow();
if (myWindow != NULL && WPeek->windowKind == tgeWKind)
{
tge_goto_line(myWindow, linenum);
}
else if (argc == 2)
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
"\" ?-nocomplain? linenum ", NULL);
return TCL_ERROR;
}
return TCL_OK;
#else
#pragma unused (clientData, argc)
Tcl_AppendResult(interp, "\"", argv[0], "\" unimplemented in engine", (char *) NULL);
return TCL_ERROR;
#endif
}
int
Cmd_OpenTextWindow(clientData, interp, argc, argv)
ClientData clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
#ifdef TCLAPPL
int type_selector;
Rect myrect;
WindowPtr myWindow;
extern WindowPtr MakeTextTGE();
if ( argc != 4 )
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" wTitle text [local|global|text]\" ", NULL);
return TCL_ERROR;
}
if ( strcmp(argv[3], "local") == 0 )
type_selector = 0;
else if ( strcmp(argv[3], "global") == 0 )
type_selector = 1;
else if ( strcmp(argv[3], "text") == 0 )
type_selector = -1;
else
{
Tcl_AppendResult(interp, "bad type selector \"", argv[2],
"\" should be one of \"local global text\" ", NULL);
return TCL_ERROR;
}
{
WindowPtr fWindow;
fWindow = FrontWindow();
if (fWindow != NULL && ((WindowPeek)fWindow)->windowKind == tgeWKind)
{
tge_activate(fWindow, 0);
}
}
SetRect(&myrect, 10, 40, 480, 280);
myWindow = MakeTextTGE( &myrect, argv[1], argv[2], strlen(argv[2]) );
if (myWindow != NULL)
{
TGEWPtr->fobject = (void *)0;
T_UNSETSTATE(TGEWPtr->state, T_TCL_STATE);
if (type_selector >= 0)
{
if ( type_selector == 0 || g_interp == NULL )
{
/* LOCAL */
T_UNSETSTATE(TGEWPtr->state, T_GLOBAL_TCL_STATE);
interp = Tcl_CreateTickleInterp();
if (interp != NULL)
TickleInitLocalShell(interp, myWindow);
}
else
{
/* GLOBAL */
T_SETSTATE(TGEWPtr->state, T_GLOBAL_TCL_STATE);
interp = g_interp;
}
TGEWPtr->fobject = (void *)interp;
if (interp != NULL)
T_SETSTATE(TGEWPtr->state, T_TCL_STATE);
}
}
#else
#pragma unused (clientData, argc)
Tcl_AppendResult(interp, "\"", argv[0], "\" unimplemented in engine", (char *) NULL);
return TCL_ERROR;
#endif
}
int
Cmd_OpenFileWindow(clientData, interp, argc, argv)
ClientData clientData;
Tcl_Interp *interp;
int argc;
char **argv;
{
#ifdef TCLAPPL
int type_selector = 0;
char *ptr;
FSSpec fileFSS;
struct stat statbuf;
if ( argc != 3 )
{
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" fileName [local|global|text]\" ", NULL);
return TCL_ERROR;
}
if ( strcmp(argv[2], "local") == 0 )
type_selector = 0;
else if ( strcmp(argv[2], "global") == 0 )
type_selector = 1;
else if ( strcmp(argv[2], "text") == 0 )
type_selector = -1;
else
{
Tcl_AppendResult(interp, "bad type selector \"", argv[2],
"\" should be one of \"local global text\" ", NULL);
return TCL_ERROR;
}
if ( stat( argv[1], &statbuf ) < 0 )
{
Tcl_AppendResult(interp, "error locating file \"", argv[1],
"\" - ", Tcl_PosixError(), NULL);
return TCL_ERROR;
}
fileFSS.parID = statbuf.st_parid;
fileFSS.vRefNum = statbuf.st_dev;
ptr = strrchr( argv[1], ':' );
if (ptr == NULL)
ptr = argv[1];
else
++ptr;
strcpy(fileFSS.name, ptr);
c2pstr(fileFSS.name);
{
GrafPtr saveport;
WindowPtr myWindow;
myWindow = FrontWindow();
if (myWindow != NULL && WPeek->windowKind == tgeWKind)
{
GetPort(&saveport);
SetPort(myWindow);
tge_activate(myWindow, 0);
tge_update(myWindow);
SetPort(saveport);
}
}
do_tge_file_open(&fileFSS, type_selector);
/* UNDONE - error handling... */
#else
#pragma unused (clientData, argc)
Tcl_AppendResult(interp, "\"", argv[0], "\" unimplemented in engine", (char *) NULL);
return TCL_ERROR;
#endif
}
static Handle _tcl_Houtput_handle = NULL;
Handle
tcl_Houtput_sethdl(handle)
Handle handle;
{
Handle result = _tcl_Houtput_handle;
_tcl_Houtput_handle = handle;
return result;
}
Handle
tcl_Houtput_gethdl()
{
return _tcl_Houtput_handle;
}
tcl_handle_output(str)
char *str;
{
long length;
length = GetHandleSize(_tcl_Houtput_handle);
SetHandleSize(_tcl_Houtput_handle, length + strlen(str));
if (MemError() == noErr)
{
memcpy( (*_tcl_Houtput_handle + length), str, strlen(str) );
}
}
int
Tcl_Interp_Handle(interp, script_handle, result_handle, stdout_handle)
Tcl_Interp *interp;
Handle script_handle;
Handle result_handle;
Handle stdout_handle;
{
int result;
PFI saveproc;
Handle saveH, myhandle = NULL;
char result_str[64]/*, *save, *ptr*/;
if (stdout_handle == NULL)
{
myhandle = NewHandle(0);
if (myhandle == NULL)
{
Feedback("Error #%d allocating a stdout handle.", MemError());
return -1770;
}
else
{
saveH = tcl_Houtput_sethdl(myhandle);
}
}
else
{
saveH = tcl_Houtput_sethdl(stdout_handle);
}
saveproc = Tcl_SetPrintProcedure(tcl_handle_output);
HLock(script_handle);
result = Tcl_RecordAndEval(interp, *script_handle, 0);
HUnlock(script_handle);
if (result != TCL_OK)
{
sprintf(result_str, "\015# Result = %d.\015", result);
tcl_handle_output(result_str);
tcl_handle_output("# ");
tcl_handle_output(interp->result);
}
else if (interp->result[0] != '\0' && result_handle != NULL)
{
tcl_Houtput_sethdl(result_handle);
tcl_handle_output(interp->result);
}
Tcl_SetPrintProcedure(saveproc);
tcl_Houtput_sethdl(saveH);
if (myhandle != NULL)
DisposHandle(myhandle);
return result;
}
#ifdef TCLAPPL
TGETCLInterp(myWindow, selector)
WindowPtr myWindow;
int selector;
{
int result, rerr, hargc;
long line;
Point cursorpt;
Rect myrect;
Handle myHandle, saveH, hargv[4];
int save_start, save_end;
int script_start, script_end;
Handle resultHandle, stdoutHandle;
PFI saveproc;
if (TGEWPtr->v_length == 0)
return;
WatchCursorOn();
TclTickle_BegYield();
SetPort(myWindow);
save_start = TGEWPtr->sel_start;
save_end = TGEWPtr->sel_end;
tge_kill_caret(myWindow);
line = tge_find_pos_line(myWindow, TGEWPtr->sel_end);
if (TGEWPtr->sel_start != TGEWPtr->sel_end)
{
script_start = TGEWPtr->sel_start;
script_end = TGEWPtr->sel_end;
}
else {
script_start = TGEWPtr->lines[line];
TGEWPtr->sel_start = script_start;
if (line >= TGEWPtr->num_lines - 1)
script_end = TGE_LAST_POSITION(myWindow) + 1;
else
script_end = TGEWPtr->lines[line + 1];
TGEWPtr->sel_end = script_end;
}
myHandle = tge_selection_handle(myWindow);
TGEWPtr->sel_start = save_start;
TGEWPtr->sel_end = save_end;
if (myHandle != NULL)
{
resultHandle = NewHandle(0);
rerr = MemError();
if (line >= TGEWPtr->num_lines - 1)
{
stdoutHandle = NewHandle(1);
if (MemError() == noErr && stdoutHandle != NULL)
**stdoutHandle = '\015';
}
else
{
stdoutHandle = NewHandle(0);
}
if (MemError() == noErr && rerr == noErr &&
resultHandle != NULL && stdoutHandle != NULL)
{
if (selector == TGE_SCRIPT)
{
saveH = tcl_Houtput_sethdl(stdoutHandle);
saveproc = Tcl_SetPrintProcedure(tcl_handle_output);
run_tcl_script((Tcl_Interp *)TGEWPtr->fobject, NULL);
Tcl_SetPrintProcedure(saveproc);
tcl_Houtput_sethdl(saveH);
}
else
{
result = Tcl_Interp_Handle( (Tcl_Interp *)TGEWPtr->fobject,
myHandle, resultHandle, stdoutHandle );
}
WatchCursorOn();
DoYield(); /* This picks up the activate event! */
DoYield(); /* Make sure.... :) */
DoYield(); /* Make certain.... */
SetPort(myWindow);
if (TGEWPtr->active)
{
tge_invert_selection(myWindow);
}
else {
tge_invert_selection(myWindow);
tge_activate_selection(myWindow);
}
TGEWPtr->sel_start =
tge_selection_line_append_pos(myWindow, line);
TGEWPtr->sel_end = TGEWPtr->sel_start;
if ( GetHandleSize(stdoutHandle) > 0 )
if (*(*stdoutHandle + GetHandleSize(stdoutHandle) - 1) != '\015')
{
SetHandleSize(stdoutHandle, GetHandleSize(stdoutHandle) + 1);
if (MemError() == noErr)
*(*stdoutHandle + GetHandleSize(stdoutHandle) - 1) = '\015';
}
if ( GetHandleSize(resultHandle) > 0 )
if (*(*resultHandle + GetHandleSize(resultHandle) - 1) != '\015')
{
SetHandleSize(resultHandle, GetHandleSize(resultHandle) + 1);
if (MemError() == noErr)
*(*resultHandle + GetHandleSize(resultHandle) - 1) = '\015';
}
hargc = 0;
if (GetHandleSize(stdoutHandle) > 0)
{
hargv[hargc++] = stdoutHandle;
}
if (GetHandleSize(resultHandle) > 0)
{
hargv[hargc++] = resultHandle;
}
if (hargc > 0)
{
hargv[hargc++] = (Handle)0;
tge_paste_handles(myWindow, hargc, hargv);
}
TGEWPtr->sel_start = TGEWPtr->sel_end -
( GetHandleSize(stdoutHandle) + GetHandleSize(resultHandle) );
DisposHandle(stdoutHandle);
DisposHandle(resultHandle);
}
else
{
message_alert("Not enough memory to store result.");
}
DisposHandle(myHandle);
}
else
{
message_alert("Not enough memory to execute selection.");
}
tge_compute_selection(myWindow);
tge_caret_on(myWindow);
tge_undo_start_typing(myWindow, TGEWPtr->sel_start);
SetPort(myWindow);
if (TGEWPtr->active)
{
tge_invert_selection(myWindow);
}
else {
tge_invert_selection(myWindow);
tge_activate_selection(myWindow);
}
myrect = myWindow->portRect;
myrect.right -= 15;
myrect.bottom -= 15;
SetPort(myWindow);
GetMouse(&cursorpt);
TclTickle_EndYield();
if (PtInRect(cursorpt, &myrect))
SetCursor(*GetCursor(iBeamCursor));
else
UInitCursor();
}
#endif
check_environment_set_of_globals(name, value)
char *name;
char *value;
{
if (strcmp("LOGLEVEL", name) == 0)
{
g_log_level = atoi(value);
Feedback("Log level now: %d.", g_log_level);
}
else if (strcmp("CRON_TICKS", name) == 0)
{
g_cron_interval = atol(value);
g_next_cron_time = TickCount() + g_cron_interval;
Feedback("Cron ticks now: %ld. Next task time: %ld.",
g_cron_interval, g_next_cron_time);
}
else if (strcmp("TEXT_CREATOR", name) == 0)
{
char tempstr[8];
sprintf(tempstr, "%-4.4s", value);
memcpy(&def_text_file_creator, tempstr, 4);
Feedback("Default text creator now: '%-4.4s'.", &def_text_file_creator);
}
#ifdef TCLENGINE
else if (strcmp("ENGINE_NOISE", name) == 0)
{
engine_verbosity = atoi(value);
if (engine_verbosity < 0 || engine_verbosity > 2)
engine_verbosity = 1;
}
#endif
}
char *
csavestr(str)
char *str;
{
char *ptr;
ptr = ckalloc(strlen(str) + 1);
if (ptr)
strcpy(ptr, str);
return ptr;
}
int
TclTickle_InitializeOnce(app_vrefnum)
short app_vrefnum;
{
extern int XPROC_Eval_CallBack();
TclMac_CWDPushVol();
SetVol(NULL, app_vrefnum);
xtcl_refnum = OpenResFile(XTCLFileName);
TclMac_CWDPopVol();
tar_initialize();
init_tcl_ctb();
#ifndef THINK_C
init_tcl_dbm();
init_tcl_cbtree();
#endif
g_interp = Tcl_CreateTickleInterp();
if (g_interp != NULL)
{
TickleInitGlobalShell(g_interp);
g_cbpb.version = XPROC_CB_VERSION;
g_cbpb.interp = g_interp;
g_cbpb.eval = XPROC_Eval_CallBack;
}
else
{
Feedback("ERROR Could not create global interpreter!");
}
return TCL_OK;
}
int
TclTickle_ShutDown()
{
tar_close();
close_tcl_ctb();
#ifndef THINK_C
close_tcl_dbm();
close_tcl_cbtree();
#endif
return TCL_OK;
}
Tcl_Interp *
Tcl_CreateTickleInterp()
{
Tcl_Interp *interp;
PFI saveproc;
extern Tcl_Interp *Tcl_CreateExtendedInterp();
interp = Tcl_CreateExtendedInterp();
if (interp != NULL)
{
Tcl_AddTickleCmds(interp);
Tcl_AddMacintoshCmds(interp);
Tcl_InitCTB(interp);
#ifndef THINK_C
Tcl_InitDBM(interp);
Tcl_InitCBTREE(interp);
#endif
if (gHasAppleEvents)
InitAEtcl(interp);
init_lcompare(interp);
TclTickle_AddTickleTracer(interp);
/*
** Above this point should be only command adds.
** Below this point perform initialization scripting.
*/
Tcl_InitMacintosh(interp);
Tcl_InitTickle(interp);
}
return interp;
}
int
Tcl_AddTickleCmds(interp)
Tcl_Interp *interp;
{
extern int Cmd_UnMacBinary();
extern int Cmd_ScriptMenu();
extern int Cmd_ASD_info();
extern int Cmd_UnMacBinary();
extern int Cmd_Extract();
extern int Cmd_Archive();
extern int Cmd_ListArchive();
Tcl_CreateCommand(interp, "mac_debug_str", Cmd_DebugStr,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "open_text_window", Cmd_OpenTextWindow,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "open_file_window", Cmd_OpenFileWindow,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "goto_window_line", Cmd_GotoWindowLine,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "alertnote", Cmd_DoAlertNote,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "askyesno", Cmd_AskYesNoCancel,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "get_directory", Cmd_GetDirectory,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "getfile", Cmd_GetFile,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "getline", Cmd_GetInputLine,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "listpick", Cmd_MacListPick,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "putfile", Cmd_PutFile,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "asdinfo", Cmd_ASD_info,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "asd2mac", Cmd_ASD_To_Mac,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "compress", Cmd_DoCompress,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "decompress", Cmd_DoDeCompress,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "hqx2mac", Cmd_DecodeHQX,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "mac2hqx", Cmd_EncodeHQX,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "mac2as", Cmd_Mac_To_AS,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "mac2ad", Cmd_Mac_To_AD,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "mb2mac", Cmd_UnMacBinary,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "mac2mb", Cmd_Mac_To_MB,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "tar", Cmd_Archive,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "untar", Cmd_Extract,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "listtar", Cmd_ListArchive,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "uudecode", Cmd_UUDecode,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "uuencode", Cmd_UUEncode,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "menucmd", Cmd_DoMenuCmd,
(ClientData)NULL, (void (*)())NULL);
#ifdef TCLAPPL
Tcl_CreateCommand(interp, "script_menu", Cmd_ScriptMenu,
(ClientData)NULL, (void (*)())NULL);
#endif
Tcl_CreateCommand(interp, "xtclcmd", Cmd_CallExternalCMD,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "espace", Cmd_EscapeSpaces,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "feedback", Cmd_Feedback,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "start_progress", Cmd_StartProgress,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "update_progress", Cmd_UpdateProgress,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "stop_progress", Cmd_StopProgress,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, YIELD_MAC_COMMAND_NAME, TclTickle_YieldMac,
(ClientData)NULL, (void (*)())NULL);
Tcl_CreateCommand(interp, "logging", Cmd_LogControl,
(ClientData)NULL, (void (*)())NULL);
return TCL_OK;
}
Tcl_InitTickle(interp)
Tcl_Interp *interp;
{
int result;
char command[128];
strcpy(command, "set TICKLE 1\n");
result = Tcl_Eval(interp, command, 0, (char **)0);
if (result != TCL_OK)
Feedback("ERROR %d on <%s>", result, command);
sprintf(command, "set TICKLEVERS {%s}\n", SHORT_VERSION_STR);
result = Tcl_Eval(interp, command, 0, (char **)0);
if (result != TCL_OK)
Feedback("ERROR %d on <%s>", result, command);
sprintf(command, "set AEVENT 0\n");
result = Tcl_Eval(interp, command, 0, (char **)0);
if (result != TCL_OK)
Feedback("ERROR %d on <%s>", result, command);
#ifdef TCLENGINE
sprintf(command, "set ENGINE 1\n");
#else
sprintf(command, "set ENGINE 0\n");
#endif
result = Tcl_Eval(interp, command, 0, (char **)0);
if (result != TCL_OK)
Feedback("ERROR %d on <%s>", result, command);
#ifdef TCLENGINE
sprintf(command, "set tcl_interactive 0\n");
#else
sprintf(command, "set tcl_interactive 1\n");
#endif
result = Tcl_Eval(interp, command, 0, (char **)0);
if (result != TCL_OK)
Feedback("ERROR %d on <%s>", result, command);
}
#ifdef TCLAPPL
TickleInitLocalShell(interp, myWindow)
Tcl_Interp *interp;
WindowPtr myWindow;
{
int result;
char command[256];
PFI saveproc;
Handle saveH, stdoutH;
extern int tcl_dev_null_output();
stdoutH = NewHandle(0);
saveH = tcl_Houtput_sethdl(stdoutH);
saveproc = Tcl_SetPrintProcedure(
(stdoutH == NULL ? tcl_dev_null_output : tcl_handle_output) );
sprintf(command, "set GLOBALTCL 0\n");
result = Tcl_Eval(interp, command, 0, (char **)0);
if (result != TCL_OK)
Feedback("ERROR %d on <%s>", result, command);
/*
** Source init.tcl
*/
if (Tcl_Init( interp ) != TCL_OK)
{
Feedback("Initialization of tcl core failed. (init.tcl) ");
Feedback("%s", (interp->result==NULL ? "" : interp->result) );
}
/*
** Source TclInit.tcl
*/
if (Tcl_ShellEnvInit( interp, TCLSH_INTERACTIVE ) != TCL_OK)
{
Feedback("Initialization of tcl extensions failed. (TclInit.tcl) ");
Feedback("%s", (interp->result==NULL ? "" : interp->result) );
}
/*
** Source the global tclshrc...
*/
sprintf(command,
"if [file exists \"[info library]:tclshrc\"] {source \"[info library]:tclshrc\"};"
);
result = Tcl_Eval(interp, command, 0, (char **)0);
if (result != TCL_OK)
{
Feedback("ERROR %d on <%s>", result, command);
if (interp->result != NULL)
Feedback(" %s", interp->result);
}
/*
** Second, perform the user's tclshrc...
*/
sprintf(command,
"if [file exists \"$env(HOME):tclshrc\"] {source \"$env(HOME):tclshrc\"};"
);
result = Tcl_Eval(interp, command, 0, (char **)0);
if (result != TCL_OK)
{
Feedback("ERROR %d on <%s>", result, command);
if (interp->result != NULL)
Feedback(" %s", interp->result);
}
Tcl_SetPrintProcedure(saveproc);
tcl_Houtput_sethdl(saveH);
if (myWindow != NULL)
{
SetPort(myWindow);
if (stdoutH != NULL)
if (GetHandleSize(stdoutH) > 0)
tge_paste_handle( myWindow, stdoutH );
if (interp->result != NULL)
tge_paste_buffer( myWindow, interp->result, strlen(interp->result) );
if ( GetHandleSize(stdoutH) > 0 ||
(interp->result != NULL && interp->result[0] != '\0') )
tge_paste_buffer( myWindow, "\015", 1 );
SetPort(myWindow);
tge_inval_all_text(myWindow);
}
if (stdoutH != NULL)
DisposHandle(stdoutH);
return result;
}
#endif /* TCLAPPL */
TickleInitGlobalShell(interp)
Tcl_Interp *interp;
{
int result;
char command[256];
PFI saveproc;
extern int tcl_dev_null_output();
saveproc = Tcl_SetPrintProcedure(tcl_dev_null_output);
sprintf(command, "set GLOBALTCL 1\n");
result = Tcl_Eval(interp, command, 0, (char **)0);
if (result != TCL_OK)
Feedback("ERROR %d on <%s>", result, command);
/*
** Source init.tcl
*/
if (Tcl_Init( interp ) != TCL_OK)
{
Feedback("Initialization of tcl core failed. (init.tcl) ");
Feedback("%s", (interp->result==NULL ? "" : interp->result) );
}
/*
** Source TclInit.tcl
*/
if (Tcl_ShellEnvInit( interp, TCLSH_INTERACTIVE ) != TCL_OK)
{
Feedback("Initialization of tcl extensions failed. (TclInit.tcl) ");
Feedback("%s", (interp->result==NULL ? "" : interp->result) );
}
/*
** Source the "global" rc file...
*/
sprintf(command, "source •tclrc\n");
result = Tcl_Eval(interp, command, 0, (char **)0);
if (result != TCL_OK)
{
Feedback("ERROR %d on <%s>", result, command);
if (interp->result != NULL)
Feedback(" %s", interp->result);
}
Tcl_SetPrintProcedure(saveproc);
return result;
}
TclTickle_BegYield()
{
_tclmac_user_interrupt_ = 0;
cancel_current_op = 0;
pause_op = 0;
UBegYield();
}
TclTickle_EndYield()
{
_tclmac_user_interrupt_ = 0;
cancel_current_op = 0;
pause_op = 0;
UEndYield();
}
static int spin_increment = 0;
void
TickleTracer(
ClientData clientData,
Tcl_Interp *interp,
int level,
char *command,
int (*cmdProc)(),
ClientData cmdClientData,
int argc,
char **argv
)
{
int myargc = 0;
char *myargv[8];
if ( (++spin_increment & 0x001F) == 0 )
{
myargv[myargc++] = YIELD_MAC_COMMAND_NAME;
myargv[myargc++] = "-spin";
myargv[myargc++] = "-event";
myargv[myargc++] = "1";
myargv[myargc] = NULL;
TclTickle_YieldMac( clientData, interp, myargc, myargv );
}
}
TclTickle_AddTickleTracer(interp)
Tcl_Interp *interp;
{
Tcl_Trace tracer;
/* UNDONE - what level should we trace to? */
tracer = Tcl_CreateTrace( interp, 999, TickleTracer, NULL );
}
/*
** This function is substituted for any "printf()" in
** the tcl libraries allowing you to control the output
** of all stdio use inside the tcl libraries. Most "normal"
** output is handled by the "print procedure", however there
** is significant debugging output that still wants to go to stdio.
*/
int
mac_printf( char *format_str, ... )
{
int result;
va_list varg;
char buffer[1024];
va_start(varg, format_str);
buffer[sizeof(buffer)-1] = '\0';
result = vsprintf(buffer, format_str, varg);
if (buffer[sizeof(buffer)-1] != '\0')
{
message_alert("FATAL: OVERFLOW On mac_printf() buffer!");
ExitToShell();
}
va_end(varg);
Feedback("%.256s", buffer);
return result;
}
/*
** This function is substituted for any "fprintf()" in
** the tcl libraries allowing you to control the output
** of all stdio use inside the tcl libraries.
*/
int
mac_fprintf( FILE *fp, char *format_str, ... )
{
int result;
va_list varg;
char buffer[1024];
va_start(varg, format_str);
buffer[sizeof(buffer)-1] = '\0';
result = vsprintf(buffer, format_str, varg);
if (buffer[sizeof(buffer)-1] != '\0')
{
message_alert("FATAL: OVERFLOW On mac_fprintf() buffer!");
ExitToShell();
}
va_end(varg);
Feedback("%.256s", buffer);
return result;
}