os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/mac/tclMacUnix.c
Update contrib.
4 * This file contains routines to implement several features
5 * available to the Unix implementation, but that require
6 * extra work to do on a Macintosh. These include routines
7 * Unix Tcl normally hands off to the Unix OS.
9 * Copyright (c) 1993-1994 Lockheed Missle & Space Company, AI Center
10 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
12 * See the file "license.terms" for information on usage and redistribution
13 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 * RCS: @(#) $Id: tclMacUnix.c,v 1.5 2002/10/09 11:54:45 das Exp $
20 #include <TextUtils.h>
22 #include <FSpCompat.h>
27 #include "tclMacInt.h"
30 * The following two Includes are from the More Files package
33 #include "MoreFiles.h"
34 #include "MoreFilesExtras.h"
37 * The following may not be defined in some versions of
41 #define kIsInvisible 0x4000
44 #define kIsAlias 0x8000
51 #define noSourceErr 501
56 *----------------------------------------------------------------------
60 * Implements the TCL echo command:
64 * Always returns TCL_OK.
69 *----------------------------------------------------------------------
74 ClientData dummy, /* Not used. */
75 Tcl_Interp *interp, /* Current interpreter. */
76 int argc, /* Number of arguments. */
77 CONST char **argv) /* Argument strings. */
82 chan = Tcl_GetChannel(interp, "stdout", &mode);
83 if (chan == (Tcl_Channel) NULL) {
86 for (i = 1; i < argc; i++) {
87 result = Tcl_WriteChars(chan, argv[i], -1);
89 Tcl_AppendResult(interp, "echo: ", Tcl_GetChannelName(chan),
90 ": ", Tcl_PosixError(interp), (char *) NULL);
94 Tcl_WriteChars(chan, " ", -1);
97 Tcl_WriteChars(chan, "\n", -1);
102 *----------------------------------------------------------------------
106 * This procedure is invoked to process the "ls" Tcl command.
107 * See the user documentation for details on what it does.
110 * A standard Tcl result.
113 * See the user documentation.
115 *----------------------------------------------------------------------
119 ClientData dummy, /* Not used. */
120 Tcl_Interp *interp, /* Current interpreter. */
121 int objc, /* Number of arguments. */
122 Tcl_Obj *CONST objv[]) /* Argument strings. */
124 #define STRING_LENGTH 80
127 int fieldLength, len = 0, maxLen = 0, perLine;
129 CInfoPBRec paramBlock;
130 HFileInfo *hpb = (HFileInfo *)¶mBlock;
131 DirInfo *dpb = (DirInfo *)¶mBlock;
133 char theLine[STRING_LENGTH + 2];
134 int fFlag = false, pFlag = false, aFlag = false, lFlag = false,
135 cFlag = false, hFlag = false;
137 Tcl_Obj *newObjv[2], *resultObjPtr;
140 * Process command flags. End if argument doesn't start
141 * with a dash or is a dash by itself. The remaining arguments
144 for (i = 1; i < objc; i++) {
145 argv = Tcl_GetString(objv[i]);
146 if (argv[0] != '-') {
150 if (!strcmp(argv, "-")) {
155 for (j = 1 ; argv[j] ; ++j) {
181 Tcl_AppendResult(interp, "error - unknown flag ",
182 "usage: ls -apCFHl1 ?files? ", NULL);
192 * No file specifications means we search for all files.
193 * Glob will be doing most of the work.
197 newObjv[0] = Tcl_NewStringObj("*", -1);
202 if (Tcl_GlobObjCmd(NULL, interp, objc + 1, objv - 1) != TCL_OK) {
203 Tcl_ResetResult(interp);
207 resultObjPtr = Tcl_GetObjResult(interp);
208 Tcl_IncrRefCount(resultObjPtr);
209 if (Tcl_ListObjGetElements(interp, resultObjPtr, &objc, (Tcl_Obj ***)&objv) != TCL_OK) {
210 Tcl_DecrRefCount(resultObjPtr);
214 Tcl_ResetResult(interp);
217 * There are two major methods for listing files: the long
218 * method and the normal method.
221 char creator[5], type[5], time[16], date[16];
224 unsigned short flags;
230 * Print the header for long listing.
233 sprintf(theLine, "T %7s %8s %8s %4s %4s %6s %s",
234 "Size", "ModTime", "ModDate",
235 "CRTR", "TYPE", "Flags", "Name");
236 Tcl_AppendResult(interp, theLine, "\n", NULL);
237 Tcl_AppendResult(interp,
238 "-------------------------------------------------------------\n",
242 for (i = 0; i < objc; i++) {
243 strcpy(theFile, Tcl_GetString(objv[i]));
246 hpb->ioCompletion = NULL;
248 hpb->ioFDirIndex = 0;
249 hpb->ioNamePtr = (StringPtr) theFile;
251 err = PBGetCatInfoSync(¶mBlock);
252 p2cstr((StringPtr) theFile);
254 if (hpb->ioFlAttrib & 16) {
256 * For directories use zero as the size, use no Creator
257 * type, and use 'DIR ' as the file type.
259 if ((aFlag == false) && (dpb->ioDrUsrWds.frFlags & 0x1000)) {
264 IUTimeString(dpb->ioDrMdDat, false, (unsigned char *)time);
265 p2cstr((StringPtr)time);
266 IUDateString(dpb->ioDrMdDat, shortDate, (unsigned char *)date);
267 p2cstr((StringPtr)date);
268 strcpy(creator, " ");
269 strcpy(type, "DIR ");
270 flags = dpb->ioDrUsrWds.frFlags;
271 if (fFlag || pFlag) {
272 strcat(theFile, ":");
276 * All information for files should be printed. This
277 * includes size, modtime, moddate, creator type, file
278 * type, flags, anf file name.
280 if ((aFlag == false) &&
281 (hpb->ioFlFndrInfo.fdFlags & kIsInvisible)) {
285 size = hpb->ioFlLgLen + hpb->ioFlRLgLen;
286 IUTimeString(hpb->ioFlMdDat, false, (unsigned char *)time);
287 p2cstr((StringPtr)time);
288 IUDateString(hpb->ioFlMdDat, shortDate, (unsigned char *)date);
289 p2cstr((StringPtr)date);
290 strncpy(creator, (char *) &hpb->ioFlFndrInfo.fdCreator, 4);
292 strncpy(type, (char *) &hpb->ioFlFndrInfo.fdType, 4);
294 flags = hpb->ioFlFndrInfo.fdFlags;
296 if (hpb->ioFlFndrInfo.fdFlags & kIsAlias) {
297 strcat(theFile, "@");
298 } else if (hpb->ioFlFndrInfo.fdType == 'APPL') {
299 strcat(theFile, "*");
304 sprintf(theLine, "%c %7ld %8s %8s %-4.4s %-4.4s 0x%4.4X %s",
305 lineTag, size, time, date, creator, type, flags, theFile);
307 Tcl_AppendResult(interp, theLine, "\n", NULL);
311 objPtr = Tcl_GetObjResult(interp);
312 string = Tcl_GetStringFromObj(objPtr, &length);
313 if ((length > 0) && (string[length - 1] == '\n')) {
314 Tcl_SetObjLength(objPtr, length - 1);
318 * Not in long format. We only print files names. If the
319 * -C flag is set we need to print in multiple coloumns.
321 int argCount, linePos;
322 Boolean needNewLine = false;
325 * Fiend the field length: the length each string printed
326 * to the terminal will be.
330 fieldLength = STRING_LENGTH;
332 for (i = 0; i < objc; i++) {
333 argv = Tcl_GetString(objv[i]);
339 fieldLength = maxLen + 3;
340 perLine = STRING_LENGTH / fieldLength;
345 memset(theLine, ' ', STRING_LENGTH);
346 while (argCount < objc) {
347 strcpy(theFile, Tcl_GetString(objv[argCount]));
350 hpb->ioCompletion = NULL;
352 hpb->ioFDirIndex = 0;
353 hpb->ioNamePtr = (StringPtr) theFile;
355 err = PBGetCatInfoSync(¶mBlock);
356 p2cstr((StringPtr) theFile);
358 if (hpb->ioFlAttrib & 16) {
360 * Directory. If -a show hidden files. If -f or -p
361 * denote that this is a directory.
363 if ((aFlag == false) && (dpb->ioDrUsrWds.frFlags & 0x1000)) {
367 if (fFlag || pFlag) {
368 strcat(theFile, ":");
372 * File: If -a show hidden files, if -f show links
373 * (aliases) and executables (APPLs).
375 if ((aFlag == false) &&
376 (hpb->ioFlFndrInfo.fdFlags & kIsInvisible)) {
381 if (hpb->ioFlFndrInfo.fdFlags & kIsAlias) {
382 strcat(theFile, "@");
383 } else if (hpb->ioFlFndrInfo.fdType == 'APPL') {
384 strcat(theFile, "*");
390 * Print the item, taking into account multi-
393 strncpy(theLine + (linePos * fieldLength), theFile,
397 if (linePos == perLine) {
398 theLine[STRING_LENGTH] = '\0';
400 Tcl_AppendResult(interp, "\n", theLine, NULL);
402 Tcl_AppendResult(interp, theLine, NULL);
406 memset(theLine, ' ', STRING_LENGTH);
413 theLine[STRING_LENGTH] = '\0';
415 Tcl_AppendResult(interp, "\n", theLine, NULL);
417 Tcl_AppendResult(interp, theLine, NULL);
422 Tcl_DecrRefCount(resultObjPtr);