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

filevms.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_VMS
00020 
00021 /*
00022  * filevms.c - scan directories and libaries on VMS
00023  *
00024  * External routines:
00025  *
00026  *      file_dirscan() - scan a directory for files
00027  *      file_time() - get timestamp of file, if not done by file_dirscan()
00028  *      file_archscan() - scan an archive for files
00029  *
00030  * File_dirscan() and file_archscan() call back a caller provided function
00031  * for each file found.  A flag to this callback function lets file_dirscan()
00032  * and file_archscan() indicate that a timestamp is being provided with the
00033  * file.   If file_dirscan() or file_archscan() do not provide the file's
00034  * timestamp, interested parties may later call file_time().
00035  *
00036  * 02/09/95 (seiwald) - bungled R=[xxx] - was using directory length!
00037  * 05/03/96 (seiwald) - split into pathvms.c
00038  */
00039 
00040 # include <rms.h>
00041 # include <iodef.h>
00042 # include <ssdef.h>
00043 # include <string.h>
00044 # include <stdlib.h>
00045 # include <stdio.h>
00046 # include <descrip.h>
00047 
00048 #include <lbrdef.h>
00049 #include <credef.h>
00050 #include <mhddef.h>
00051 #include <lhidef.h>
00052 #include <lib$routines.h>
00053 #include <starlet.h>
00054 
00055 /* Supply missing prototypes for lbr$-routines*/
00056 
00057 #ifdef __cplusplus
00058 extern "C" { 
00059 #endif /* __cplusplus */
00060 
00061 int lbr$set_module( 
00062         void **,
00063         unsigned long *,
00064         struct dsc$descriptor_s *,
00065         unsigned short *, 
00066         void * );
00067 
00068 int lbr$open( void **,
00069         struct dsc$descriptor_s *,
00070         void *,
00071         void *, 
00072         void *,
00073         void *,
00074         void * );
00075 
00076 int lbr$ini_control(
00077         void **,
00078         unsigned long *,
00079         unsigned long *,
00080         void * );
00081 
00082 int lbr$get_index(
00083         void **,
00084         unsigned long *,
00085         int (*func)( struct dsc$descriptor_s *, unsigned long *),
00086         void * );
00087 
00088 int lbr$close(
00089         void ** );
00090 
00091 #ifdef __cplusplus
00092 }
00093 #endif /* __cplusplus */
00094 
00095 static void
00096 file_cvttime( 
00097     unsigned int *curtime,
00098     time_t *unixtime )
00099 {
00100     static const size_t divisor = 10000000;
00101     static unsigned int bastim[2] = { 0x4BEB4000, 0x007C9567 }; /* 1/1/1970 */
00102     int delta[2], remainder;
00103 
00104     lib$subx( curtime, bastim, delta );
00105     lib$ediv( &divisor, delta, unixtime, &remainder );
00106 }
00107 
00108 # define DEFAULT_FILE_SPECIFICATION "[]*.*;0"
00109 
00110 # define min( a,b ) ((a)<(b)?(a):(b))
00111 
00112 void
00113 file_dirscan( 
00114         char *dir,
00115         scanback func,
00116         void    *closure )
00117 {
00118 
00119     struct FAB xfab;
00120     struct NAM xnam;
00121     struct XABDAT xab;
00122     char esa[256];
00123     char filename[256];
00124     string filename2[1];
00125     char dirname[256];
00126     register int status;
00127     PATHNAME f;
00128 
00129     memset( (char *)&f, '\0', sizeof( f ) );
00130 
00131     f.f_root.ptr = dir;
00132     f.f_root.len = strlen( dir );
00133 
00134         /* get the input file specification
00135          */
00136     xnam = cc$rms_nam;
00137     xnam.nam$l_esa = esa;
00138     xnam.nam$b_ess = sizeof( esa ) - 1;
00139     xnam.nam$l_rsa = filename;
00140     xnam.nam$b_rss = min( sizeof( filename ) - 1, NAM$C_MAXRSS );
00141 
00142     xab = cc$rms_xabdat;                /* initialize extended attributes */
00143     xab.xab$b_cod = XAB$C_DAT;          /* ask for date */
00144     xab.xab$l_nxt = NULL;               /* terminate XAB chain      */
00145 
00146     xfab = cc$rms_fab;
00147     xfab.fab$l_dna = DEFAULT_FILE_SPECIFICATION;
00148     xfab.fab$b_dns = sizeof( DEFAULT_FILE_SPECIFICATION ) - 1;
00149     xfab.fab$l_fop = FAB$M_NAM;
00150     xfab.fab$l_fna = dir;                       /* address of file name     */
00151     xfab.fab$b_fns = strlen( dir );             /* length of file name      */
00152     xfab.fab$l_nam = &xnam;                     /* address of NAB block     */
00153     xfab.fab$l_xab = (char *)&xab;       /* address of XAB block     */
00154 
00155 
00156     status = sys$parse( &xfab );
00157 
00158     if( DEBUG_BINDSCAN )
00159         printf( "scan directory %s\n", dir );
00160 
00161     if ( !( status & 1 ) )
00162         return;
00163 
00164 
00165 
00166     /* Add bogus directory for [000000] */
00167 
00168     if( !strcmp( dir, "[000000]" ) )
00169     {
00170         (*func)( closure, "[000000]", 1 /* time valid */, 1 /* old but true */ );
00171     }
00172 
00173     /* Add bogus directory for [] */
00174 
00175     if( !strcmp( dir, "[]" ) )
00176     {
00177         (*func)( closure, "[]", 1 /* time valid */, 1 /* old but true */ );
00178         (*func)( closure, "[-]", 1 /* time valid */, 1 /* old but true */ );
00179     }
00180 
00181     string_new( filename2 );
00182     while ( (status = sys$search( &xfab )) & 1 )
00183     {
00184         char *s;
00185         time_t time;
00186 
00187         /* "I think that might work" - eml */
00188 
00189         sys$open( &xfab );
00190         sys$close( &xfab );
00191 
00192         file_cvttime( (unsigned int *)&xab.xab$q_rdt, &time );
00193 
00194         filename[xnam.nam$b_rsl] = '\0';
00195 
00196         /* What we do with the name depends on the suffix: */
00197         /* .dir is a directory */
00198         /* .xxx is a file with a suffix */
00199         /* . is no suffix at all */
00200 
00201         if( xnam.nam$b_type == 4 && !strncmp( xnam.nam$l_type, ".DIR", 4 ) )
00202         {
00203             /* directory */
00204             sprintf( dirname, "[.%.*s]", xnam.nam$b_name, xnam.nam$l_name );
00205             f.f_dir.ptr = dirname;
00206             f.f_dir.len = strlen( dirname );
00207             f.f_base.ptr = 0;
00208             f.f_base.len = 0;
00209             f.f_suffix.ptr = 0;
00210             f.f_suffix.len = 0;
00211         }
00212         else
00213         {
00214             /* normal file with a suffix */
00215             f.f_dir.ptr = 0;
00216             f.f_dir.len = 0;
00217             f.f_base.ptr = xnam.nam$l_name;
00218             f.f_base.len = xnam.nam$b_name;
00219             f.f_suffix.ptr = xnam.nam$l_type;
00220             f.f_suffix.len = xnam.nam$b_type;
00221         }
00222 
00223         string_truncate( filename2, 0 );
00224         path_build( &f, filename2, 0 );
00225 
00226         /*
00227         if( DEBUG_SEARCH )
00228             printf("root '%s' base %.*s suf %.*s = %s\n",
00229                     dir,
00230                     xnam.nam$b_name, xnam.nam$l_name, 
00231                     xnam.nam$b_type, xnam.nam$l_type,
00232                     filename2);
00233         */
00234 
00235         (*func)( closure, filename2->value, 1 /* time valid */, time );
00236     }
00237     string_free( filename2 );
00238 }    
00239 
00240 int
00241 file_time(
00242         char    *filename,
00243         time_t  *time )
00244 {
00245         /* This should never be called, as all files are */
00246         /* timestampped in file_dirscan() and file_archscan() */
00247         return -1;
00248 }
00249 
00250 static char *VMS_archive = 0;
00251 static scanback VMS_func;
00252 static void *VMS_closure;
00253 static void *context;
00254 
00255 static int
00256 file_archmember( 
00257     struct dsc$descriptor_s *module,
00258     unsigned long *rfa )
00259 {
00260     static struct dsc$descriptor_s bufdsc =
00261                   {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL};
00262 
00263     struct mhddef *mhd;
00264     char filename[128];
00265     char buf[ MAXJPATH ];
00266 
00267     int status;
00268     time_t library_date;
00269 
00270     register int i;
00271     register char *p;
00272 
00273     bufdsc.dsc$a_pointer = filename;
00274     bufdsc.dsc$w_length = sizeof( filename );
00275     status = lbr$set_module( &context, rfa, &bufdsc,
00276                              &bufdsc.dsc$w_length, NULL );
00277 
00278     if ( !(status & 1) )
00279         return ( 1 );
00280 
00281     mhd = (struct mhddef *)filename;
00282 
00283     file_cvttime( &mhd->mhd$l_datim, &library_date );
00284 
00285     for ( i = 0, p = module->dsc$a_pointer; i < module->dsc$w_length; i++, p++ )
00286         filename[i] = *p;
00287 
00288     filename[i] = '\0';
00289 
00290     sprintf( buf, "%s(%s.obj)", VMS_archive, filename );
00291 
00292     (*VMS_func)( VMS_closure, buf, 1 /* time valid */, (time_t)library_date );
00293 
00294     return ( 1 );
00295 }
00296 
00297 void
00298 file_archscan(
00299         char *archive,
00300         scanback func,
00301         void    *closure )
00302 {
00303     static struct dsc$descriptor_s library =
00304                   {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL};
00305 
00306     unsigned long lfunc = LBR$C_READ;
00307     unsigned long typ = LBR$C_TYP_UNK;
00308     unsigned long index = 1;
00309 
00310     register int status;
00311 
00312     VMS_archive = archive;
00313     VMS_func = func;
00314     VMS_closure = closure;
00315 
00316     status = lbr$ini_control( &context, &lfunc, &typ, NULL );
00317     if ( !( status & 1 ) )
00318         return;
00319 
00320     library.dsc$a_pointer = archive;
00321     library.dsc$w_length = strlen( archive );
00322 
00323     status = lbr$open( &context, &library, NULL, NULL, NULL, NULL, NULL );
00324     if ( !( status & 1 ) )
00325         return;
00326 
00327     (void) lbr$get_index( &context, &index, file_archmember, NULL );
00328 
00329     (void) lbr$close( &context );
00330 }
00331 
00332 # endif /* VMS */
00333 

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