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

fileunix.c File Reference

#include "jam.h"
#include "filesys.h"
#include "strings.h"
#include "pathsys.h"
#include <stdio.h>
#include <dirent.h>
#include <ar.h>

Include dependency graph for fileunix.c:

Include dependency graph

Go to the source code of this file.

Defines

#define SARFMAG   2
#define SARHDR   sizeof( struct ar_hdr )
#define STRUCT_DIRENT   struct dirent

Functions

void file_archscan (char *archive, scanback func, void *closure)
void file_dirscan (char *dir, scanback func, void *closure)
int file_time (char *filename, time_t *time)


Define Documentation

#define SARFMAG   2
 

Definition at line 210 of file fileunix.c.

#define SARHDR   sizeof( struct ar_hdr )
 

Definition at line 211 of file fileunix.c.

#define STRUCT_DIRENT   struct dirent
 

Definition at line 52 of file fileunix.c.

Referenced by file_dirscan().


Function Documentation

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

Definition at line 214 of file fileunix.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().

00218 {
00219 # ifndef NO_AR
00220         struct ar_hdr ar_hdr;
00221         char buf[ MAXJPATH ];
00222         long offset;
00223         char    *string_table = 0;
00224         int fd;
00225 
00226         if( ( fd = open( archive, O_RDONLY, 0 ) ) < 0 )
00227             return;
00228 
00229         if( read( fd, buf, SARMAG ) != SARMAG ||
00230             strncmp( ARMAG, buf, SARMAG ) )
00231         {
00232             close( fd );
00233             return;
00234         }
00235 
00236         offset = SARMAG;
00237 
00238         if( DEBUG_BINDSCAN )
00239             printf( "scan archive %s\n", archive );
00240 
00241         while( read( fd, &ar_hdr, SARHDR ) == SARHDR &&
00242                !memcmp( ar_hdr.ar_fmag, ARFMAG, SARFMAG ) )
00243         {
00244             char    lar_name_[257];
00245             char*   lar_name = lar_name_ + 1;
00246             long    lar_date;
00247             long    lar_size;
00248             long    lar_offset;
00249             char *c;
00250             char    *src, *dest;
00251 
00252             strncpy( lar_name, ar_hdr.ar_name, sizeof(ar_hdr.ar_name) );
00253 
00254             sscanf( ar_hdr.ar_date, "%ld", &lar_date );
00255             sscanf( ar_hdr.ar_size, "%ld", &lar_size );
00256 
00257             if (ar_hdr.ar_name[0] == '/')
00258             {
00259                 if (ar_hdr.ar_name[1] == '/')
00260                 {
00261                     /* this is the "string table" entry of the symbol table,
00262                     ** which holds strings of filenames that are longer than
00263                     ** 15 characters (ie. don't fit into a ar_name
00264                     */
00265 
00266                     string_table = (char *)malloc(lar_size);
00267                     lseek(fd, offset + SARHDR, 0);
00268                     if (read(fd, string_table, lar_size) != lar_size)
00269                         printf("error reading string table\n");
00270                 }
00271                 else if (string_table && ar_hdr.ar_name[1] != ' ')
00272                 {
00273                     /* Long filenames are recognized by "/nnnn" where nnnn is
00274                     ** the offset of the string in the string table represented
00275                     ** in ASCII decimals.
00276                     */
00277                     dest = lar_name;
00278                     lar_offset = atoi(lar_name + 1);
00279                     src = &string_table[lar_offset];
00280                     while (*src != '/')
00281                         *dest++ = *src++;
00282                     *dest = '/';
00283                 }
00284             }
00285 
00286             c = lar_name - 1;
00287             while( *++c != ' ' && *c != '/' )
00288                 ;
00289             *c = '\0';
00290 
00291             if ( DEBUG_BINDSCAN )
00292                 printf( "archive name %s found\n", lar_name );
00293 
00294             sprintf( buf, "%s(%s)", archive, lar_name );
00295 
00296             (*func)( closure, buf, 1 /* time valid */, (time_t)lar_date );
00297 
00298             offset += SARHDR + ( ( lar_size + 1 ) & ~1 );
00299             lseek( fd, offset, 0 );
00300         }
00301 
00302         if (string_table)
00303             free(string_table);
00304 
00305         close( fd );
00306 
00307 # endif /* NO_AR */
00308 
00309 }

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 185 of file fileunix.c.

Referenced by timestamp().

00188 {
00189         struct stat statbuf;
00190 
00191         if( stat( filename, &statbuf ) < 0 )
00192             return -1;
00193 
00194     /* Technically, existing files can have 0 as statbuf.st_mtime 
00195        --- in particular, the /cygdrive directory under cygwin. However, 
00196        though all the code jam assumes that timestamp of 0 means
00197        "does not exist" and will try to create the "missing" target, causing
00198        problems. Work around this problem by chanding 0 to 1.
00199     */
00200         *time = statbuf.st_mtime ? statbuf.st_mtime : 1 ;
00201         return 0;
00202 }


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