The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

filemac.c

Go to the documentation of this file.
00001 /*
00002  * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
00003  *
00004  * This file is part of Jam - see jam.c for Copyright information.
00005  */
00006  
00007 /*  This file is ALSO:
00008  *  (C) Copyright David Abrahams 2001. Permission to copy, use,
00009  *  modify, sell and distribute this software is granted provided this
00010  *  copyright notice appears in all copies. This software is provided
00011  *  "as is" without express or implied warranty, and with no claim as
00012  *  to its suitability for any purpose.
00013  */
00014 
00015 # include "jam.h"
00016 # include "filesys.h"
00017 # include "pathsys.h"
00018 
00019 # ifdef OS_MAC
00020 
00021 #include <Files.h>
00022 #include <Folders.h>
00023 
00024 # include <:sys:stat.h>
00025 
00026 /*
00027  * filemac.c - manipulate file names and scan directories on macintosh
00028  *
00029  * External routines:
00030  *
00031  *      file_dirscan() - scan a directory for files
00032  *      file_time() - get timestamp of file, if not done by file_dirscan()
00033  *      file_archscan() - scan an archive for files
00034  *
00035  * File_dirscan() and file_archscan() call back a caller provided function
00036  * for each file found.  A flag to this callback function lets file_dirscan()
00037  * and file_archscan() indicate that a timestamp is being provided with the
00038  * file.   If file_dirscan() or file_archscan() do not provide the file's
00039  * timestamp, interested parties may later call file_time().
00040  *
00041  * 04/08/94 (seiwald) - Coherent/386 support added.
00042  * 12/19/94 (mikem) - solaris string table insanity support
00043  * 02/14/95 (seiwald) - parse and build /xxx properly
00044  * 05/03/96 (seiwald) - split into pathunix.c
00045  * 11/21/96 (peterk) - BEOS does not have Unix-style archives
00046  */
00047 
00048 void CopyC2PStr(const char * cstr, StringPtr pstr)
00049 {
00050         int     len;
00051         
00052         for (len = 0; *cstr && len<255; pstr[++len] = *cstr++)
00053                 ;
00054         
00055         pstr[0] = len;
00056 }
00057 
00058 /*
00059  * file_dirscan() - scan a directory for files
00060  */
00061 
00062 void
00063 file_dirscan( 
00064         char    *dir,
00065         scanback func,
00066         void    *closure )
00067 {
00068     PATHNAME f;
00069     string filename[1];
00070     unsigned char fullPath[ 512 ];
00071 
00072     FSSpec spec;
00073     WDPBRec vol;
00074     Str63 volName;      
00075     CInfoPBRec lastInfo;
00076     int index = 1;
00077         
00078     /* First enter directory itself */
00079 
00080     memset( (char *)&f, '\0', sizeof( f ) );
00081 
00082     f.f_dir.ptr = dir;
00083     f.f_dir.len = strlen(dir);
00084 
00085     if( DEBUG_BINDSCAN )
00086         printf( "scan directory %s\n", dir );
00087                 
00088     /* Special case ":" - enter it */
00089 
00090     if( f.f_dir.len == 1 && f.f_dir.ptr[0] == ':' )
00091             (*func)( closure, dir, 0 /* not stat()'ed */, (time_t)0 );
00092 
00093     /* Now enter contents of directory */
00094 
00095     vol.ioNamePtr = volName;
00096         
00097     if( PBHGetVolSync( &vol ) )
00098         return;
00099 
00100     CopyC2PStr( dir, fullPath );
00101         
00102     if( FSMakeFSSpec( vol.ioWDVRefNum, vol.ioWDDirID, fullPath, &spec ) )
00103         return;
00104         
00105     lastInfo.dirInfo.ioVRefNum  = spec.vRefNum;
00106     lastInfo.dirInfo.ioDrDirID  = spec.parID;
00107     lastInfo.dirInfo.ioNamePtr  = spec.name;
00108     lastInfo.dirInfo.ioFDirIndex        = 0;
00109     lastInfo.dirInfo.ioACUser   = 0;
00110                         
00111     if( PBGetCatInfoSync(&lastInfo) )
00112         return;
00113 
00114     if (!(lastInfo.dirInfo.ioFlAttrib & 0x10))
00115         return;
00116 
00117     // ioDrDirID must be reset each time.
00118         
00119     spec.parID = lastInfo.dirInfo.ioDrDirID;
00120 
00121     string_new( filename );
00122     for( ;; )
00123     {
00124         lastInfo.dirInfo.ioVRefNum      = spec.vRefNum;
00125         lastInfo.dirInfo.ioDrDirID      = spec.parID;
00126         lastInfo.dirInfo.ioNamePtr      = fullPath;
00127         lastInfo.dirInfo.ioFDirIndex = index++;
00128                         
00129         if( PBGetCatInfoSync(&lastInfo) )
00130             return;
00131                         
00132         f.f_base.ptr = (char *)fullPath + 1;
00133         f.f_base.len = *fullPath;
00134 
00135         string_truncate( filename, 0 );
00136         path_build( &f, filename, 0 );
00137         (*func)( closure, filename->value, 0 /* not stat()'ed */, (time_t)0 );
00138     }
00139     string_free( filename );
00140 }
00141 
00142 /*
00143  * file_time() - get timestamp of file, if not done by file_dirscan()
00144  */
00145 
00146 int
00147 file_time( 
00148         char    *filename,
00149         time_t  *time )
00150 {
00151         struct stat statbuf;
00152 
00153         if( stat( filename, &statbuf ) < 0 )
00154             return -1;
00155 
00156         *time = statbuf.st_mtime;
00157         
00158         return 0;
00159 }
00160 
00161 /*
00162  * file_archscan() - scan an archive for files
00163  */
00164 
00165 void
00166 file_archscan(
00167         char    *archive,
00168         scanback func,
00169         void    *closure )
00170 {
00171 }
00172 
00173 
00174 # endif /* macintosh */
00175 

Generated on Mon Nov 8 17:07:33 2004 for MPT by  doxygen 1.3.9.1