2 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
4 * This file is part of Jam - see jam.c for Copyright information.
8 * filemac.c - manipulate file names and scan directories on macintosh
12 * file_dirscan() - scan a directory for files
13 * file_time() - get timestamp of file, if not done by file_dirscan()
14 * file_archscan() - scan an archive for files
16 * File_dirscan() and file_archscan() call back a caller provided function
17 * for each file found. A flag to this callback function lets file_dirscan()
18 * and file_archscan() indicate that a timestamp is being provided with the
19 * file. If file_dirscan() or file_archscan() do not provide the file's
20 * timestamp, interested parties may later call file_time().
22 * 04/08/94 (seiwald) - Coherent/386 support added.
23 * 12/19/94 (mikem) - solaris string table insanity support
24 * 02/14/95 (seiwald) - parse and build /xxx properly
25 * 05/03/96 (seiwald) - split into pathunix.c
26 * 11/21/96 (peterk) - BEOS does not have Unix-style archives
27 * 01/21/00 (malyn) - divorced from GUSI
28 * 01/08/01 (seiwald) - closure param for file_dirscan/file_archscan
29 * 11/04/02 (seiwald) - const-ing for string literals
41 # include <:sys:stat.h>
43 void CopyC2PStr (const char * cstr
, StringPtr pstr
) {
46 for (len
= 0; *cstr
&& len
<255; pstr
[++len
] = *cstr
++) ;
52 * file_dirscan() - scan a directory for files
54 void file_dirscan (const char *dir
, scanback func
, void *closure
) {
56 char filename
[MAXJPATH
];
57 unsigned char fullPath
[512];
64 /* First enter directory itself */
65 memset((char *)&f
, '\0', sizeof(f
));
67 f
.f_dir
.len
= strlen(dir
);
68 if (DEBUG_BINDSCAN
) printf("scan directory %s\n", dir
);
69 /* Special case ":" - enter it */
70 if (f
.f_dir
.len
== 1 && f
.f_dir
.ptr
[0] == ':')
71 (*func
)(closure
, dir
, 0 /* not stat()'ed */, (time_t)0);
72 /* Now enter contents of directory */
73 vol
.ioNamePtr
= volName
;
74 if (PBHGetVolSync(&vol
)) return;
75 CopyC2PStr(dir
, fullPath
);
76 if (FSMakeFSSpec(vol
.ioWDVRefNum
, vol
.ioWDDirID
, fullPath
, &spec
)) return;
77 lastInfo
.dirInfo
.ioVRefNum
= spec
.vRefNum
;
78 lastInfo
.dirInfo
.ioDrDirID
= spec
.parID
;
79 lastInfo
.dirInfo
.ioNamePtr
= spec
.name
;
80 lastInfo
.dirInfo
.ioFDirIndex
= 0;
81 lastInfo
.dirInfo
.ioACUser
= 0;
82 if (PBGetCatInfoSync(&lastInfo
)) return;
83 if (!(lastInfo
.dirInfo
.ioFlAttrib
& 0x10)) return;
84 // ioDrDirID must be reset each time.
85 spec
.parID
= lastInfo
.dirInfo
.ioDrDirID
;
87 lastInfo
.dirInfo
.ioVRefNum
= spec
.vRefNum
;
88 lastInfo
.dirInfo
.ioDrDirID
= spec
.parID
;
89 lastInfo
.dirInfo
.ioNamePtr
= fullPath
;
90 lastInfo
.dirInfo
.ioFDirIndex
= index
++;
91 if (PBGetCatInfoSync(&lastInfo
)) return;
92 f
.f_base
.ptr
= (char *)fullPath
+1;
93 f
.f_base
.len
= *fullPath
;
94 path_build(&f
, filename
, 0);
95 (*func
)(closure
, filename
, 0 /* not stat()'ed */, (time_t)0);
101 * file_time() - get timestamp of file, if not done by file_dirscan()
103 int file_time (const char *filename
, time_t *time
) {
106 if (stat(filename
, &statbuf
) < 0) return -1;
107 *time
= statbuf
.st_mtime
;
113 * file_archscan() - scan an archive for files
115 void file_archscan (const char *archive
, scanback func
, void *closure
) {
119 # endif /* macintosh */