os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/mac/tclMacTest.c
Update contrib.
4 * Contains commands for platform specific tests for
5 * the Macintosh platform.
7 * Copyright (c) 1996 Sun Microsystems, Inc.
9 * See the file "license.terms" for information on usage and redistribution
10 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 * RCS: @(#) $Id: tclMacTest.c,v 1.6 2002/10/09 11:54:42 das Exp $
16 #define USE_COMPAT_CONST
18 #include "tclMacInt.h"
19 #include "tclMacPort.h"
22 #include <Resources.h>
25 #include <FSpCompat.h>
28 * Forward declarations of procedures defined later in this file:
31 int TclplatformtestInit _ANSI_ARGS_((Tcl_Interp *interp));
32 static int DebuggerCmd _ANSI_ARGS_((ClientData dummy,
33 Tcl_Interp *interp, int argc, CONST char **argv));
34 static int WriteTextResource _ANSI_ARGS_((ClientData dummy,
35 Tcl_Interp *interp, int argc, CONST char **argv));
39 *----------------------------------------------------------------------
41 * TclplatformtestInit --
43 * Defines commands that test platform specific functionality for
47 * A standard Tcl result.
50 * Defines new commands.
52 *----------------------------------------------------------------------
57 Tcl_Interp *interp) /* Interpreter to add commands to. */
60 * Add commands for platform specific tests on MacOS here.
63 Tcl_CreateCommand(interp, "debugger", DebuggerCmd,
64 (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
65 Tcl_CreateCommand(interp, "testWriteTextResource", WriteTextResource,
66 (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
72 *----------------------------------------------------------------------
76 * This procedure simply calls the low level debugger.
79 * A standard Tcl result.
84 *----------------------------------------------------------------------
89 ClientData clientData, /* Not used. */
90 Tcl_Interp *interp, /* Not used. */
91 int argc, /* Not used. */
92 CONST char **argv) /* Not used. */
99 *----------------------------------------------------------------------
101 * WriteTextResource --
103 * This procedure will write a text resource out to the
104 * application or a given file. The format for this command is
108 * A standard Tcl result.
113 *----------------------------------------------------------------------
118 ClientData clientData, /* Not used. */
119 Tcl_Interp *interp, /* Current interpreter. */
120 int argc, /* Number of arguments. */
121 CONST char **argv) /* Argument strings. */
123 char *errNum = "wrong # args: ";
124 char *errBad = "bad argument: ";
126 CONST char *fileName = NULL, *rsrcName = NULL;
127 CONST char *data = NULL;
128 int rsrcID = -1, i, protectIt = 0;
136 * Process the arguments.
138 for (i = 1 ; i < argc ; i++) {
139 if (!strcmp(argv[i], "-rsrc")) {
140 rsrcName = argv[i + 1];
142 } else if (!strcmp(argv[i], "-rsrcid")) {
143 rsrcID = atoi(argv[i + 1]);
145 } else if (!strcmp(argv[i], "-file")) {
146 fileName = argv[i + 1];
148 } else if (!strcmp(argv[i], "-protected")) {
155 if ((rsrcName == NULL && rsrcID < 0) ||
156 (fileName == NULL) || (data == NULL)) {
162 * Open the resource file.
164 err = FSpLocationFromPath(strlen(fileName), fileName, &fileSpec);
165 if (!(err == noErr || err == fnfErr)) {
166 Tcl_AppendResult(interp, "couldn't validate file name", (char *) NULL);
171 FSpCreateResFile(&fileSpec, 'WIsH', 'rsrc', smSystemScript);
173 fileRef = FSpOpenResFile(&fileSpec, fsRdWrPerm);
175 Tcl_AppendResult(interp, "couldn't open resource file", (char *) NULL);
182 * Prepare data needed to create resource.
185 rsrcID = UniqueID('TEXT');
188 strcpy((char *) resourceName, rsrcName);
189 c2pstr((char *) resourceName);
191 dataHandle = NewHandle(strlen(data));
193 strcpy(*dataHandle, data);
197 * Add the resource to the file and close it.
199 AddResource(dataHandle, 'TEXT', rsrcID, resourceName);
201 UpdateResFile(fileRef);
203 SetResAttrs(Get1Resource('TEXT', rsrcID), resProtected);
206 CloseResFile(fileRef);
210 Tcl_AppendResult(interp, errStr, "error in \"", argv[0], "\"",