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

filesys.h File Reference

#include "pathsys.h"

Include dependency graph for filesys.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Typedefs

typedef void(* scanback )(void *closure, char *file, int found, time_t t)

Functions

void file_archscan (char *arch, scanback func, void *closure)
void file_build1 (PATHNAME *f, string *file)
void file_dirscan (char *dir, scanback func, void *closure)
int file_time (char *filename, time_t *time)


Typedef Documentation

typedef void(* scanback)(void *closure, char *file, int found, time_t t)
 

Definition at line 24 of file filesys.h.


Function Documentation

void file_archscan char *  arch,
scanback  func,
void *  closure
 

Definition at line 194 of file filent.c.

References ar_hdr::ar_date, ar_hdr::ar_fmag, ar_hdr::ar_name, ar_hdr::ar_size, ARFMAG, ARMAG, c, close, SARFMAG, SARHDR, SARMAG, and sprintf().

Referenced by timestamp().

00198 {
00199         struct ar_hdr ar_hdr;
00200         char *string_table = 0;
00201         char buf[ MAXJPATH ];
00202         long offset;
00203         int fd;
00204 
00205         if( ( fd = open( archive, O_RDONLY | O_BINARY, 0 ) ) < 0 )
00206             return;
00207 
00208         if( read( fd, buf, SARMAG ) != SARMAG ||
00209             strncmp( ARMAG, buf, SARMAG ) )
00210         {
00211             close( fd );
00212             return;
00213         }
00214 
00215         offset = SARMAG;
00216 
00217         if( DEBUG_BINDSCAN )
00218             printf( "scan archive %s\n", archive );
00219 
00220         while( read( fd, &ar_hdr, SARHDR ) == SARHDR &&
00221                !memcmp( ar_hdr.ar_fmag, ARFMAG, SARFMAG ) )
00222         {
00223             long    lar_date;
00224             long    lar_size;
00225             char    *name = 0;
00226             char    *endname;
00227             char    *c;
00228 
00229             sscanf( ar_hdr.ar_date, "%ld", &lar_date );
00230             sscanf( ar_hdr.ar_size, "%ld", &lar_size );
00231 
00232             lar_size = ( lar_size + 1 ) & ~1;
00233 
00234             if (ar_hdr.ar_name[0] == '/' && ar_hdr.ar_name[1] == '/' )
00235             {
00236                 /* this is the "string table" entry of the symbol table,
00237                 ** which holds strings of filenames that are longer than
00238                 ** 15 characters (ie. don't fit into a ar_name
00239                 */
00240 
00241                 string_table = malloc(lar_size);
00242                 if (read(fd, string_table, lar_size) != lar_size)
00243                     printf("error reading string table\n");
00244                 offset += SARHDR + lar_size;
00245                 continue;
00246             }
00247             else if (ar_hdr.ar_name[0] == '/' && ar_hdr.ar_name[1] != ' ')
00248             {
00249                 /* Long filenames are recognized by "/nnnn" where nnnn is
00250                 ** the offset of the string in the string table represented
00251                 ** in ASCII decimals.
00252                 */
00253 
00254                 name = string_table + atoi( ar_hdr.ar_name + 1 );
00255                 endname = name + strlen( name );
00256             }
00257             else
00258             {
00259                 /* normal name */
00260                 name = ar_hdr.ar_name;
00261                 endname = name + sizeof( ar_hdr.ar_name );
00262             }
00263 
00264             /* strip trailing space, slashes, and backslashes */
00265 
00266             while( endname-- > name )
00267                 if( *endname != ' ' && *endname != '\\' && *endname != '/' )
00268                     break;
00269             *++endname = 0;
00270 
00271             /* strip leading directory names, an NT specialty */
00272 
00273             if( c = strrchr( name, '/' ) )
00274                 name = c + 1;
00275             if( c = strrchr( name, '\\' ) )
00276                 name = c + 1;
00277 
00278             sprintf( buf, "%s(%.*s)", archive, endname - name, name );
00279             (*func)( closure, buf, 1 /* time valid */, (time_t)lar_date );
00280 
00281             offset += SARHDR + lar_size;
00282             lseek( fd, offset, 0 );
00283         }
00284 
00285         close( fd );
00286 }

Here is the call graph for this function:

void file_build1 PATHNAME f,
string file
 

Definition at line 6 of file filesys.c.

References f(), file, PATHNAME, string::size, string_append_range(), string_push_back(), and string::value.

Referenced by path_build().

00009 {
00010     if( DEBUG_SEARCH )
00011     {
00012         printf("build file: ");
00013         if( f->f_root.len )
00014             printf( "root = '%.*s' ", f->f_root.len, f->f_root.ptr );
00015         if( f->f_dir.len )
00016             printf( "dir = '%.*s' ", f->f_dir.len, f->f_dir.ptr );
00017         if( f->f_base.len )
00018             printf( "base = '%.*s' ", f->f_base.len, f->f_base.ptr );
00019     }
00020         
00021     /* Start with the grist.  If the current grist isn't */
00022     /* surrounded by <>'s, add them. */
00023 
00024     if( f->f_grist.len )
00025     {
00026         if( f->f_grist.ptr[0] != '<' )
00027             string_push_back( file, '<' );
00028         string_append_range(
00029             file, f->f_grist.ptr, f->f_grist.ptr + f->f_grist.len );
00030         if( file->value[file->size - 1] != '>' )
00031             string_push_back( file, '>' );
00032     }
00033 }

Here is the call graph for this function:

void file_dirscan char *  dir,
scanback  func,
void *  closure
 

Definition at line 127 of file fileunix.c.

References d, f(), path_build(), PATHNAME, string_free(), string_new(), string_truncate(), STRUCT_DIRENT, and string::value.

Referenced by builtin_glob(), and timestamp().

00131 {
00132         PATHNAME f;
00133         DIR *d;
00134         STRUCT_DIRENT *dirent;
00135         string filename[1];
00136 
00137         /* First enter directory itself */
00138 
00139         memset( (char *)&f, '\0', sizeof( f ) );
00140 
00141         f.f_dir.ptr = dir;
00142         f.f_dir.len = strlen(dir);
00143 
00144         dir = *dir ? dir : ".";
00145 
00146         /* Special case / : enter it */
00147 
00148         if( f.f_dir.len == 1 && f.f_dir.ptr[0] == '/' )
00149             (*func)( closure, dir, 0 /* not stat()'ed */, (time_t)0 );
00150 
00151         /* Now enter contents of directory */
00152 
00153         if( !( d = opendir( dir ) ) )
00154             return;
00155 
00156         if( DEBUG_BINDSCAN )
00157             printf( "scan directory %s\n", dir );
00158 
00159         string_new( filename );
00160         while( dirent = readdir( d ) )
00161         {
00162 # ifdef old_sinix
00163             /* Broken structure definition on sinix. */
00164             f.f_base.ptr = dirent->d_name - 2;
00165 # else
00166             f.f_base.ptr = dirent->d_name;
00167 # endif
00168             f.f_base.len = strlen( f.f_base.ptr );
00169 
00170             string_truncate( filename, 0 );
00171             path_build( &f, filename, 0 );
00172 
00173             (*func)( closure, filename->value, 0 /* not stat()'ed */, (time_t)0 );
00174         }
00175         string_free( filename );
00176 
00177         closedir( d );
00178 }

Here is the call graph for this function:

int file_time char *  filename,
time_t *  time
 

Definition at line 153 of file filent.c.

Referenced by timestamp().

00156 {
00157         /* On NT this is called only for C:/ */
00158 
00159         struct stat statbuf;
00160 
00161         if( stat( filename, &statbuf ) < 0 )
00162             return -1;
00163 
00164         *time = statbuf.st_mtime;
00165 
00166         return 0;
00167 }


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