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

timestamp.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 "hash.h"
00017 # include "filesys.h"
00018 # include "pathsys.h"
00019 # include "timestamp.h"
00020 # include "newstr.h"
00021 # include "strings.h"
00022 
00023 /*
00024  * timestamp.c - get the timestamp of a file or archive member
00025  *
00026  * 09/22/00 (seiwald) - downshift names on OS2, too
00027  */
00028 
00029 /*
00030  * BINDING - all known files
00031  */
00032 
00033 typedef struct _binding BINDING;
00034 
00035 struct _binding {
00036         char    *name;
00037         short   flags;
00038 
00039 # define BIND_SCANNED   0x01    /* if directory or arch, has been scanned */
00040 
00041         short   progress;
00042 
00043 # define BIND_INIT      0       /* never seen */
00044 # define BIND_NOENTRY   1       /* timestamp requested but file never found */
00045 # define BIND_SPOTTED   2       /* file found but not timed yet */
00046 # define BIND_MISSING   3       /* file found but can't get timestamp */
00047 # define BIND_FOUND     4       /* file found and time stamped */
00048 
00049         time_t  time;           /* update time - 0 if not exist */
00050 } ;
00051 
00052 static struct hash *bindhash = 0;
00053 static void time_enter( void *, char *, int , time_t  );
00054 
00055 static char *time_progress[] =
00056 {
00057         "INIT",
00058         "NOENTRY",
00059         "SPOTTED",
00060         "MISSING",
00061         "FOUND"
00062 } ;
00063 
00064 
00065 /*
00066  * timestamp() - return timestamp on a file, if present
00067  */
00068 
00069 void
00070 timestamp( 
00071         char    *target,
00072         time_t  *time )
00073 {
00074         PATHNAME f1, f2;
00075         BINDING binding, *b = &binding;
00076         string buf[1];
00077 
00078 # ifdef DOWNSHIFT_PATHS
00079         string path; 
00080         char *p;
00081 
00082         string_copy( &path, target );
00083         p = path.value;
00084 
00085         do
00086     {
00087         *p = tolower( *p );
00088 #  ifdef NT
00089         /* On NT, we must use backslashes or the file won't be found. */
00090         if (*p == '/')
00091             *p = PATH_DELIM;
00092 #  endif 
00093     }
00094         while( *p++ );
00095 
00096         target = path.value;
00097 # endif
00098         string_new( buf );
00099 
00100         if( !bindhash )
00101             bindhash = hashinit( sizeof( BINDING ), "bindings" );
00102 
00103         /* Quick path - is it there? */
00104 
00105         b->name = target;
00106         b->time = b->flags = 0;
00107         b->progress = BIND_INIT;
00108 
00109         if( hashenter( bindhash, (HASHDATA **)&b ) )
00110             b->name = newstr( target );         /* never freed */
00111 
00112         if( b->progress != BIND_INIT )
00113             goto afterscanning;
00114 
00115         b->progress = BIND_NOENTRY;
00116 
00117         /* Not found - have to scan for it */
00118 
00119         path_parse( target, &f1 );
00120 
00121         /* Scan directory if not already done so */
00122 
00123         {
00124             BINDING binding, *b = &binding;
00125 
00126             f2 = f1;
00127             f2.f_grist.len = 0;
00128             path_parent( &f2 );
00129             path_build( &f2, buf, 0 );
00130 
00131             b->name = buf->value;
00132             b->time = b->flags = 0;
00133             b->progress = BIND_INIT;
00134 
00135             if( hashenter( bindhash, (HASHDATA **)&b ) )
00136                 b->name = newstr( buf->value ); /* never freed */
00137 
00138             if( !( b->flags & BIND_SCANNED ) )
00139             {
00140                 file_dirscan( buf->value, time_enter, bindhash );
00141                 b->flags |= BIND_SCANNED;
00142             }
00143         }
00144 
00145         /* Scan archive if not already done so */
00146 
00147         if( f1.f_member.len )
00148         {
00149             BINDING binding, *b = &binding;
00150 
00151             f2 = f1;
00152             f2.f_grist.len = 0;
00153             f2.f_member.len = 0;
00154             string_truncate( buf, 0 );
00155             path_build( &f2, buf, 0 );
00156 
00157             b->name = buf->value;
00158             b->time = b->flags = 0;
00159             b->progress = BIND_INIT;
00160 
00161             if( hashenter( bindhash, (HASHDATA **)&b ) )
00162                 b->name = newstr( buf->value ); /* never freed */
00163 
00164             if( !( b->flags & BIND_SCANNED ) )
00165             {
00166                 file_archscan( buf->value, time_enter, bindhash );
00167                 b->flags |= BIND_SCANNED;
00168             }
00169         }
00170 
00171     afterscanning:
00172 
00173         if( b->progress == BIND_SPOTTED )
00174         {
00175             if( file_time( b->name, &b->time ) < 0 )
00176                 b->progress = BIND_MISSING;
00177             else
00178                 b->progress = BIND_FOUND;
00179         }
00180 
00181         *time = b->progress == BIND_FOUND ? b->time : 0;
00182         string_free( buf );
00183 # ifdef DOWNSHIFT_PATHS
00184         string_free( &path );
00185 #endif
00186 }
00187 
00188 static void
00189 time_enter( 
00190         void    *closure,
00191         char    *target,
00192         int     found,
00193         time_t  time )
00194 {
00195         BINDING binding, *b = &binding;
00196         struct hash *bindhash = (struct hash *)closure;
00197 
00198 # ifdef DOWNSHIFT_PATHS
00199         char path[ MAXJPATH ];
00200         char *p = path;
00201 
00202         do *p++ = tolower( *target );
00203         while( *target++ );
00204 
00205         target = path;
00206 # endif
00207 
00208         b->name = target;
00209         b->flags = 0;
00210 
00211         if( hashenter( bindhash, (HASHDATA **)&b ) )
00212             b->name = newstr( target );         /* never freed */
00213 
00214         b->time = time;
00215         b->progress = found ? BIND_FOUND : BIND_SPOTTED;
00216 
00217         if( DEBUG_BINDSCAN )
00218             printf( "time ( %s ) : %s\n", target, time_progress[b->progress] );
00219 }
00220 
00221 /*
00222  * donestamps() - free timestamp tables
00223  */
00224 
00225 void
00226 donestamps()
00227 {
00228         hashdone( bindhash );
00229 }

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