Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/tools/jam/src/filemac.c @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 4.0 KB
Line 
1/*
2 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
3 *
4 * This file is part of Jam - see jam.c for Copyright information.
5 */
6 
7/*  This file is ALSO:
8 *  Copyright 2001-2004 David Abrahams.
9 *  Distributed under the Boost Software License, Version 1.0.
10 *  (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
11 */
12
13# include "jam.h"
14# include "filesys.h"
15# include "pathsys.h"
16
17# ifdef OS_MAC
18
19#include <Files.h>
20#include <Folders.h>
21
22# include <:sys:stat.h>
23
24/*
25 * filemac.c - manipulate file names and scan directories on macintosh
26 *
27 * External routines:
28 *
29 *      file_dirscan() - scan a directory for files
30 *      file_time() - get timestamp of file, if not done by file_dirscan()
31 *      file_archscan() - scan an archive for files
32 *
33 * File_dirscan() and file_archscan() call back a caller provided function
34 * for each file found.  A flag to this callback function lets file_dirscan()
35 * and file_archscan() indicate that a timestamp is being provided with the
36 * file.   If file_dirscan() or file_archscan() do not provide the file's
37 * timestamp, interested parties may later call file_time().
38 *
39 * 04/08/94 (seiwald) - Coherent/386 support added.
40 * 12/19/94 (mikem) - solaris string table insanity support
41 * 02/14/95 (seiwald) - parse and build /xxx properly
42 * 05/03/96 (seiwald) - split into pathunix.c
43 * 11/21/96 (peterk) - BEOS does not have Unix-style archives
44 */
45
46void CopyC2PStr(const char * cstr, StringPtr pstr)
47{
48        int     len;
49       
50        for (len = 0; *cstr && len<255; pstr[++len] = *cstr++)
51                ;
52       
53        pstr[0] = len;
54}
55
56/*
57 * file_dirscan() - scan a directory for files
58 */
59
60void
61file_dirscan( 
62        char    *dir,
63        scanback func,
64        void    *closure )
65{
66    PATHNAME f;
67    string filename[1];
68    unsigned char fullPath[ 512 ];
69
70    FSSpec spec;
71    WDPBRec vol;
72    Str63 volName;     
73    CInfoPBRec lastInfo;
74    int index = 1;
75       
76    /* First enter directory itself */
77
78    memset( (char *)&f, '\0', sizeof( f ) );
79
80    f.f_dir.ptr = dir;
81    f.f_dir.len = strlen(dir);
82
83    if( DEBUG_BINDSCAN )
84        printf( "scan directory %s\n", dir );
85               
86    /* Special case ":" - enter it */
87
88    if( f.f_dir.len == 1 && f.f_dir.ptr[0] == ':' )
89            (*func)( closure, dir, 0 /* not stat()'ed */, (time_t)0 );
90
91    /* Now enter contents of directory */
92
93    vol.ioNamePtr = volName;
94       
95    if( PBHGetVolSync( &vol ) )
96        return;
97
98    CopyC2PStr( dir, fullPath );
99       
100    if( FSMakeFSSpec( vol.ioWDVRefNum, vol.ioWDDirID, fullPath, &spec ) )
101        return;
102       
103    lastInfo.dirInfo.ioVRefNum  = spec.vRefNum;
104    lastInfo.dirInfo.ioDrDirID  = spec.parID;
105    lastInfo.dirInfo.ioNamePtr  = spec.name;
106    lastInfo.dirInfo.ioFDirIndex        = 0;
107    lastInfo.dirInfo.ioACUser   = 0;
108                       
109    if( PBGetCatInfoSync(&lastInfo) )
110        return;
111
112    if (!(lastInfo.dirInfo.ioFlAttrib & 0x10))
113        return;
114
115    // ioDrDirID must be reset each time.
116       
117    spec.parID = lastInfo.dirInfo.ioDrDirID;
118
119    string_new( filename );
120    for( ;; )
121    {
122        lastInfo.dirInfo.ioVRefNum      = spec.vRefNum;
123        lastInfo.dirInfo.ioDrDirID      = spec.parID;
124        lastInfo.dirInfo.ioNamePtr      = fullPath;
125        lastInfo.dirInfo.ioFDirIndex = index++;
126                       
127        if( PBGetCatInfoSync(&lastInfo) )
128            return;
129                       
130        f.f_base.ptr = (char *)fullPath + 1;
131        f.f_base.len = *fullPath;
132
133        string_truncate( filename, 0 );
134        path_build( &f, filename, 0 );
135        (*func)( closure, filename->value, 0 /* not stat()'ed */, (time_t)0 );
136    }
137    string_free( filename );
138}
139
140/*
141 * file_time() - get timestamp of file, if not done by file_dirscan()
142 */
143
144int
145file_time( 
146        char    *filename,
147        time_t  *time )
148{
149        struct stat statbuf;
150
151        if( stat( filename, &statbuf ) < 0 )
152            return -1;
153
154        *time = statbuf.st_mtime;
155       
156        return 0;
157}
158
159int file_is_file(char* filename)
160{
161        struct stat statbuf;
162
163        if( stat( filename, &statbuf ) < 0 )
164            return -1;
165
166    if (S_ISREG(statbuf.st_mode)) 
167        return 1;
168    else
169        return 0;   
170}
171
172
173/*
174 * file_archscan() - scan an archive for files
175 */
176
177void
178file_archscan(
179        char    *archive,
180        scanback func,
181        void    *closure )
182{
183}
184
185
186# endif /* macintosh */
187
Note: See TracBrowser for help on using the repository browser.