OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [tcl/] [mac/] [tclMacTest.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.