sl@0
|
1 |
/*
|
sl@0
|
2 |
* tclMacTest.c --
|
sl@0
|
3 |
*
|
sl@0
|
4 |
* Contains commands for platform specific tests for
|
sl@0
|
5 |
* the Macintosh platform.
|
sl@0
|
6 |
*
|
sl@0
|
7 |
* Copyright (c) 1996 Sun Microsystems, Inc.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* See the file "license.terms" for information on usage and redistribution
|
sl@0
|
10 |
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* RCS: @(#) $Id: tclMacTest.c,v 1.6 2002/10/09 11:54:42 das Exp $
|
sl@0
|
13 |
*/
|
sl@0
|
14 |
|
sl@0
|
15 |
#define TCL_TEST
|
sl@0
|
16 |
#define USE_COMPAT_CONST
|
sl@0
|
17 |
#include "tclInt.h"
|
sl@0
|
18 |
#include "tclMacInt.h"
|
sl@0
|
19 |
#include "tclMacPort.h"
|
sl@0
|
20 |
#include "Files.h"
|
sl@0
|
21 |
#include <Errors.h>
|
sl@0
|
22 |
#include <Resources.h>
|
sl@0
|
23 |
#include <Script.h>
|
sl@0
|
24 |
#include <Strings.h>
|
sl@0
|
25 |
#include <FSpCompat.h>
|
sl@0
|
26 |
|
sl@0
|
27 |
/*
|
sl@0
|
28 |
* Forward declarations of procedures defined later in this file:
|
sl@0
|
29 |
*/
|
sl@0
|
30 |
|
sl@0
|
31 |
int TclplatformtestInit _ANSI_ARGS_((Tcl_Interp *interp));
|
sl@0
|
32 |
static int DebuggerCmd _ANSI_ARGS_((ClientData dummy,
|
sl@0
|
33 |
Tcl_Interp *interp, int argc, CONST char **argv));
|
sl@0
|
34 |
static int WriteTextResource _ANSI_ARGS_((ClientData dummy,
|
sl@0
|
35 |
Tcl_Interp *interp, int argc, CONST char **argv));
|
sl@0
|
36 |
|
sl@0
|
37 |
|
sl@0
|
38 |
/*
|
sl@0
|
39 |
*----------------------------------------------------------------------
|
sl@0
|
40 |
*
|
sl@0
|
41 |
* TclplatformtestInit --
|
sl@0
|
42 |
*
|
sl@0
|
43 |
* Defines commands that test platform specific functionality for
|
sl@0
|
44 |
* Unix platforms.
|
sl@0
|
45 |
*
|
sl@0
|
46 |
* Results:
|
sl@0
|
47 |
* A standard Tcl result.
|
sl@0
|
48 |
*
|
sl@0
|
49 |
* Side effects:
|
sl@0
|
50 |
* Defines new commands.
|
sl@0
|
51 |
*
|
sl@0
|
52 |
*----------------------------------------------------------------------
|
sl@0
|
53 |
*/
|
sl@0
|
54 |
|
sl@0
|
55 |
int
|
sl@0
|
56 |
TclplatformtestInit(
|
sl@0
|
57 |
Tcl_Interp *interp) /* Interpreter to add commands to. */
|
sl@0
|
58 |
{
|
sl@0
|
59 |
/*
|
sl@0
|
60 |
* Add commands for platform specific tests on MacOS here.
|
sl@0
|
61 |
*/
|
sl@0
|
62 |
|
sl@0
|
63 |
Tcl_CreateCommand(interp, "debugger", DebuggerCmd,
|
sl@0
|
64 |
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
sl@0
|
65 |
Tcl_CreateCommand(interp, "testWriteTextResource", WriteTextResource,
|
sl@0
|
66 |
(ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
|
sl@0
|
67 |
|
sl@0
|
68 |
return TCL_OK;
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
/*
|
sl@0
|
72 |
*----------------------------------------------------------------------
|
sl@0
|
73 |
*
|
sl@0
|
74 |
* DebuggerCmd --
|
sl@0
|
75 |
*
|
sl@0
|
76 |
* This procedure simply calls the low level debugger.
|
sl@0
|
77 |
*
|
sl@0
|
78 |
* Results:
|
sl@0
|
79 |
* A standard Tcl result.
|
sl@0
|
80 |
*
|
sl@0
|
81 |
* Side effects:
|
sl@0
|
82 |
* None.
|
sl@0
|
83 |
*
|
sl@0
|
84 |
*----------------------------------------------------------------------
|
sl@0
|
85 |
*/
|
sl@0
|
86 |
|
sl@0
|
87 |
static int
|
sl@0
|
88 |
DebuggerCmd(
|
sl@0
|
89 |
ClientData clientData, /* Not used. */
|
sl@0
|
90 |
Tcl_Interp *interp, /* Not used. */
|
sl@0
|
91 |
int argc, /* Not used. */
|
sl@0
|
92 |
CONST char **argv) /* Not used. */
|
sl@0
|
93 |
{
|
sl@0
|
94 |
Debugger();
|
sl@0
|
95 |
return TCL_OK;
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
/*
|
sl@0
|
99 |
*----------------------------------------------------------------------
|
sl@0
|
100 |
*
|
sl@0
|
101 |
* WriteTextResource --
|
sl@0
|
102 |
*
|
sl@0
|
103 |
* This procedure will write a text resource out to the
|
sl@0
|
104 |
* application or a given file. The format for this command is
|
sl@0
|
105 |
* textwriteresource
|
sl@0
|
106 |
*
|
sl@0
|
107 |
* Results:
|
sl@0
|
108 |
* A standard Tcl result.
|
sl@0
|
109 |
*
|
sl@0
|
110 |
* Side effects:
|
sl@0
|
111 |
* None.
|
sl@0
|
112 |
*
|
sl@0
|
113 |
*----------------------------------------------------------------------
|
sl@0
|
114 |
*/
|
sl@0
|
115 |
|
sl@0
|
116 |
static int
|
sl@0
|
117 |
WriteTextResource(
|
sl@0
|
118 |
ClientData clientData, /* Not used. */
|
sl@0
|
119 |
Tcl_Interp *interp, /* Current interpreter. */
|
sl@0
|
120 |
int argc, /* Number of arguments. */
|
sl@0
|
121 |
CONST char **argv) /* Argument strings. */
|
sl@0
|
122 |
{
|
sl@0
|
123 |
char *errNum = "wrong # args: ";
|
sl@0
|
124 |
char *errBad = "bad argument: ";
|
sl@0
|
125 |
char *errStr;
|
sl@0
|
126 |
CONST char *fileName = NULL, *rsrcName = NULL;
|
sl@0
|
127 |
CONST char *data = NULL;
|
sl@0
|
128 |
int rsrcID = -1, i, protectIt = 0;
|
sl@0
|
129 |
short fileRef = -1;
|
sl@0
|
130 |
OSErr err;
|
sl@0
|
131 |
Handle dataHandle;
|
sl@0
|
132 |
Str255 resourceName;
|
sl@0
|
133 |
FSSpec fileSpec;
|
sl@0
|
134 |
|
sl@0
|
135 |
/*
|
sl@0
|
136 |
* Process the arguments.
|
sl@0
|
137 |
*/
|
sl@0
|
138 |
for (i = 1 ; i < argc ; i++) {
|
sl@0
|
139 |
if (!strcmp(argv[i], "-rsrc")) {
|
sl@0
|
140 |
rsrcName = argv[i + 1];
|
sl@0
|
141 |
i++;
|
sl@0
|
142 |
} else if (!strcmp(argv[i], "-rsrcid")) {
|
sl@0
|
143 |
rsrcID = atoi(argv[i + 1]);
|
sl@0
|
144 |
i++;
|
sl@0
|
145 |
} else if (!strcmp(argv[i], "-file")) {
|
sl@0
|
146 |
fileName = argv[i + 1];
|
sl@0
|
147 |
i++;
|
sl@0
|
148 |
} else if (!strcmp(argv[i], "-protected")) {
|
sl@0
|
149 |
protectIt = 1;
|
sl@0
|
150 |
} else {
|
sl@0
|
151 |
data = argv[i];
|
sl@0
|
152 |
}
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
if ((rsrcName == NULL && rsrcID < 0) ||
|
sl@0
|
156 |
(fileName == NULL) || (data == NULL)) {
|
sl@0
|
157 |
errStr = errBad;
|
sl@0
|
158 |
goto sourceFmtErr;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
/*
|
sl@0
|
162 |
* Open the resource file.
|
sl@0
|
163 |
*/
|
sl@0
|
164 |
err = FSpLocationFromPath(strlen(fileName), fileName, &fileSpec);
|
sl@0
|
165 |
if (!(err == noErr || err == fnfErr)) {
|
sl@0
|
166 |
Tcl_AppendResult(interp, "couldn't validate file name", (char *) NULL);
|
sl@0
|
167 |
return TCL_ERROR;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
|
sl@0
|
170 |
if (err == fnfErr) {
|
sl@0
|
171 |
FSpCreateResFile(&fileSpec, 'WIsH', 'rsrc', smSystemScript);
|
sl@0
|
172 |
}
|
sl@0
|
173 |
fileRef = FSpOpenResFile(&fileSpec, fsRdWrPerm);
|
sl@0
|
174 |
if (fileRef == -1) {
|
sl@0
|
175 |
Tcl_AppendResult(interp, "couldn't open resource file", (char *) NULL);
|
sl@0
|
176 |
return TCL_ERROR;
|
sl@0
|
177 |
}
|
sl@0
|
178 |
|
sl@0
|
179 |
UseResFile(fileRef);
|
sl@0
|
180 |
|
sl@0
|
181 |
/*
|
sl@0
|
182 |
* Prepare data needed to create resource.
|
sl@0
|
183 |
*/
|
sl@0
|
184 |
if (rsrcID < 0) {
|
sl@0
|
185 |
rsrcID = UniqueID('TEXT');
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
strcpy((char *) resourceName, rsrcName);
|
sl@0
|
189 |
c2pstr((char *) resourceName);
|
sl@0
|
190 |
|
sl@0
|
191 |
dataHandle = NewHandle(strlen(data));
|
sl@0
|
192 |
HLock(dataHandle);
|
sl@0
|
193 |
strcpy(*dataHandle, data);
|
sl@0
|
194 |
HUnlock(dataHandle);
|
sl@0
|
195 |
|
sl@0
|
196 |
/*
|
sl@0
|
197 |
* Add the resource to the file and close it.
|
sl@0
|
198 |
*/
|
sl@0
|
199 |
AddResource(dataHandle, 'TEXT', rsrcID, resourceName);
|
sl@0
|
200 |
|
sl@0
|
201 |
UpdateResFile(fileRef);
|
sl@0
|
202 |
if (protectIt) {
|
sl@0
|
203 |
SetResAttrs(Get1Resource('TEXT', rsrcID), resProtected);
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
CloseResFile(fileRef);
|
sl@0
|
207 |
return TCL_OK;
|
sl@0
|
208 |
|
sl@0
|
209 |
sourceFmtErr:
|
sl@0
|
210 |
Tcl_AppendResult(interp, errStr, "error in \"", argv[0], "\"",
|
sl@0
|
211 |
(char *) NULL);
|
sl@0
|
212 |
return TCL_ERROR;
|
sl@0
|
213 |
}
|