[29] | 1 | /* |
---|
| 2 | * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc. |
---|
| 3 | * |
---|
| 4 | * This file is part of Jam - see jam.c for Copyright information. |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | /* This file is ALSO: |
---|
| 8 | * Copyright 2001-2004 David Abrahams. |
---|
| 9 | * Distributed under the Boost Software License, Version 1.0. |
---|
| 10 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | # include "jam.h" |
---|
| 14 | # include "filesys.h" |
---|
| 15 | # include "pathsys.h" |
---|
| 16 | |
---|
| 17 | # ifdef OS_VMS |
---|
| 18 | |
---|
| 19 | /* |
---|
| 20 | * filevms.c - scan directories and libaries on VMS |
---|
| 21 | * |
---|
| 22 | * External routines: |
---|
| 23 | * |
---|
| 24 | * file_dirscan() - scan a directory for files |
---|
| 25 | * file_time() - get timestamp of file, if not done by file_dirscan() |
---|
| 26 | * file_archscan() - scan an archive for files |
---|
| 27 | * |
---|
| 28 | * File_dirscan() and file_archscan() call back a caller provided function |
---|
| 29 | * for each file found. A flag to this callback function lets file_dirscan() |
---|
| 30 | * and file_archscan() indicate that a timestamp is being provided with the |
---|
| 31 | * file. If file_dirscan() or file_archscan() do not provide the file's |
---|
| 32 | * timestamp, interested parties may later call file_time(). |
---|
| 33 | * |
---|
| 34 | * 02/09/95 (seiwald) - bungled R=[xxx] - was using directory length! |
---|
| 35 | * 05/03/96 (seiwald) - split into pathvms.c |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | # include <rms.h> |
---|
| 39 | # include <iodef.h> |
---|
| 40 | # include <ssdef.h> |
---|
| 41 | # include <string.h> |
---|
| 42 | # include <stdlib.h> |
---|
| 43 | # include <stdio.h> |
---|
| 44 | # include <descrip.h> |
---|
| 45 | |
---|
| 46 | #include <lbrdef.h> |
---|
| 47 | #include <credef.h> |
---|
| 48 | #include <mhddef.h> |
---|
| 49 | #include <lhidef.h> |
---|
| 50 | #include <lib$routines.h> |
---|
| 51 | #include <starlet.h> |
---|
| 52 | |
---|
| 53 | /* Supply missing prototypes for lbr$-routines*/ |
---|
| 54 | |
---|
| 55 | #ifdef __cplusplus |
---|
| 56 | extern "C" { |
---|
| 57 | #endif /* __cplusplus */ |
---|
| 58 | |
---|
| 59 | int lbr$set_module( |
---|
| 60 | void **, |
---|
| 61 | unsigned long *, |
---|
| 62 | struct dsc$descriptor_s *, |
---|
| 63 | unsigned short *, |
---|
| 64 | void * ); |
---|
| 65 | |
---|
| 66 | int lbr$open( void **, |
---|
| 67 | struct dsc$descriptor_s *, |
---|
| 68 | void *, |
---|
| 69 | void *, |
---|
| 70 | void *, |
---|
| 71 | void *, |
---|
| 72 | void * ); |
---|
| 73 | |
---|
| 74 | int lbr$ini_control( |
---|
| 75 | void **, |
---|
| 76 | unsigned long *, |
---|
| 77 | unsigned long *, |
---|
| 78 | void * ); |
---|
| 79 | |
---|
| 80 | int lbr$get_index( |
---|
| 81 | void **, |
---|
| 82 | unsigned long *, |
---|
| 83 | int (*func)( struct dsc$descriptor_s *, unsigned long *), |
---|
| 84 | void * ); |
---|
| 85 | |
---|
| 86 | int lbr$close( |
---|
| 87 | void ** ); |
---|
| 88 | |
---|
| 89 | #ifdef __cplusplus |
---|
| 90 | } |
---|
| 91 | #endif /* __cplusplus */ |
---|
| 92 | |
---|
| 93 | static void |
---|
| 94 | file_cvttime( |
---|
| 95 | unsigned int *curtime, |
---|
| 96 | time_t *unixtime ) |
---|
| 97 | { |
---|
| 98 | static const size_t divisor = 10000000; |
---|
| 99 | static unsigned int bastim[2] = { 0x4BEB4000, 0x007C9567 }; /* 1/1/1970 */ |
---|
| 100 | int delta[2], remainder; |
---|
| 101 | |
---|
| 102 | lib$subx( curtime, bastim, delta ); |
---|
| 103 | lib$ediv( &divisor, delta, unixtime, &remainder ); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | # define DEFAULT_FILE_SPECIFICATION "[]*.*;0" |
---|
| 107 | |
---|
| 108 | # define min( a,b ) ((a)<(b)?(a):(b)) |
---|
| 109 | |
---|
| 110 | void |
---|
| 111 | file_dirscan( |
---|
| 112 | char *dir, |
---|
| 113 | scanback func, |
---|
| 114 | void *closure ) |
---|
| 115 | { |
---|
| 116 | |
---|
| 117 | struct FAB xfab; |
---|
| 118 | struct NAM xnam; |
---|
| 119 | struct XABDAT xab; |
---|
| 120 | char esa[256]; |
---|
| 121 | char filename[256]; |
---|
| 122 | string filename2[1]; |
---|
| 123 | char dirname[256]; |
---|
| 124 | register int status; |
---|
| 125 | PATHNAME f; |
---|
| 126 | |
---|
| 127 | memset( (char *)&f, '\0', sizeof( f ) ); |
---|
| 128 | |
---|
| 129 | f.f_root.ptr = dir; |
---|
| 130 | f.f_root.len = strlen( dir ); |
---|
| 131 | |
---|
| 132 | /* get the input file specification |
---|
| 133 | */ |
---|
| 134 | xnam = cc$rms_nam; |
---|
| 135 | xnam.nam$l_esa = esa; |
---|
| 136 | xnam.nam$b_ess = sizeof( esa ) - 1; |
---|
| 137 | xnam.nam$l_rsa = filename; |
---|
| 138 | xnam.nam$b_rss = min( sizeof( filename ) - 1, NAM$C_MAXRSS ); |
---|
| 139 | |
---|
| 140 | xab = cc$rms_xabdat; /* initialize extended attributes */ |
---|
| 141 | xab.xab$b_cod = XAB$C_DAT; /* ask for date */ |
---|
| 142 | xab.xab$l_nxt = NULL; /* terminate XAB chain */ |
---|
| 143 | |
---|
| 144 | xfab = cc$rms_fab; |
---|
| 145 | xfab.fab$l_dna = DEFAULT_FILE_SPECIFICATION; |
---|
| 146 | xfab.fab$b_dns = sizeof( DEFAULT_FILE_SPECIFICATION ) - 1; |
---|
| 147 | xfab.fab$l_fop = FAB$M_NAM; |
---|
| 148 | xfab.fab$l_fna = dir; /* address of file name */ |
---|
| 149 | xfab.fab$b_fns = strlen( dir ); /* length of file name */ |
---|
| 150 | xfab.fab$l_nam = &xnam; /* address of NAB block */ |
---|
| 151 | xfab.fab$l_xab = (char *)&xab; /* address of XAB block */ |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | status = sys$parse( &xfab ); |
---|
| 155 | |
---|
| 156 | if( DEBUG_BINDSCAN ) |
---|
| 157 | printf( "scan directory %s\n", dir ); |
---|
| 158 | |
---|
| 159 | if ( !( status & 1 ) ) |
---|
| 160 | return; |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | /* Add bogus directory for [000000] */ |
---|
| 165 | |
---|
| 166 | if( !strcmp( dir, "[000000]" ) ) |
---|
| 167 | { |
---|
| 168 | (*func)( closure, "[000000]", 1 /* time valid */, 1 /* old but true */ ); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | /* Add bogus directory for [] */ |
---|
| 172 | |
---|
| 173 | if( !strcmp( dir, "[]" ) ) |
---|
| 174 | { |
---|
| 175 | (*func)( closure, "[]", 1 /* time valid */, 1 /* old but true */ ); |
---|
| 176 | (*func)( closure, "[-]", 1 /* time valid */, 1 /* old but true */ ); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | string_new( filename2 ); |
---|
| 180 | while ( (status = sys$search( &xfab )) & 1 ) |
---|
| 181 | { |
---|
| 182 | char *s; |
---|
| 183 | time_t time; |
---|
| 184 | |
---|
| 185 | /* "I think that might work" - eml */ |
---|
| 186 | |
---|
| 187 | sys$open( &xfab ); |
---|
| 188 | sys$close( &xfab ); |
---|
| 189 | |
---|
| 190 | file_cvttime( (unsigned int *)&xab.xab$q_rdt, &time ); |
---|
| 191 | |
---|
| 192 | filename[xnam.nam$b_rsl] = '\0'; |
---|
| 193 | |
---|
| 194 | /* What we do with the name depends on the suffix: */ |
---|
| 195 | /* .dir is a directory */ |
---|
| 196 | /* .xxx is a file with a suffix */ |
---|
| 197 | /* . is no suffix at all */ |
---|
| 198 | |
---|
| 199 | if( xnam.nam$b_type == 4 && !strncmp( xnam.nam$l_type, ".DIR", 4 ) ) |
---|
| 200 | { |
---|
| 201 | /* directory */ |
---|
| 202 | sprintf( dirname, "[.%.*s]", xnam.nam$b_name, xnam.nam$l_name ); |
---|
| 203 | f.f_dir.ptr = dirname; |
---|
| 204 | f.f_dir.len = strlen( dirname ); |
---|
| 205 | f.f_base.ptr = 0; |
---|
| 206 | f.f_base.len = 0; |
---|
| 207 | f.f_suffix.ptr = 0; |
---|
| 208 | f.f_suffix.len = 0; |
---|
| 209 | } |
---|
| 210 | else |
---|
| 211 | { |
---|
| 212 | /* normal file with a suffix */ |
---|
| 213 | f.f_dir.ptr = 0; |
---|
| 214 | f.f_dir.len = 0; |
---|
| 215 | f.f_base.ptr = xnam.nam$l_name; |
---|
| 216 | f.f_base.len = xnam.nam$b_name; |
---|
| 217 | f.f_suffix.ptr = xnam.nam$l_type; |
---|
| 218 | f.f_suffix.len = xnam.nam$b_type; |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | string_truncate( filename2, 0 ); |
---|
| 222 | path_build( &f, filename2, 0 ); |
---|
| 223 | |
---|
| 224 | /* |
---|
| 225 | if( DEBUG_SEARCH ) |
---|
| 226 | printf("root '%s' base %.*s suf %.*s = %s\n", |
---|
| 227 | dir, |
---|
| 228 | xnam.nam$b_name, xnam.nam$l_name, |
---|
| 229 | xnam.nam$b_type, xnam.nam$l_type, |
---|
| 230 | filename2); |
---|
| 231 | */ |
---|
| 232 | |
---|
| 233 | (*func)( closure, filename2->value, 1 /* time valid */, time ); |
---|
| 234 | } |
---|
| 235 | string_free( filename2 ); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | int |
---|
| 239 | file_time( |
---|
| 240 | char *filename, |
---|
| 241 | time_t *time ) |
---|
| 242 | { |
---|
| 243 | /* This should never be called, as all files are */ |
---|
| 244 | /* timestampped in file_dirscan() and file_archscan() */ |
---|
| 245 | return -1; |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | static char *VMS_archive = 0; |
---|
| 249 | static scanback VMS_func; |
---|
| 250 | static void *VMS_closure; |
---|
| 251 | static void *context; |
---|
| 252 | |
---|
| 253 | static int |
---|
| 254 | file_archmember( |
---|
| 255 | struct dsc$descriptor_s *module, |
---|
| 256 | unsigned long *rfa ) |
---|
| 257 | { |
---|
| 258 | static struct dsc$descriptor_s bufdsc = |
---|
| 259 | {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL}; |
---|
| 260 | |
---|
| 261 | struct mhddef *mhd; |
---|
| 262 | char filename[128]; |
---|
| 263 | char buf[ MAXJPATH ]; |
---|
| 264 | |
---|
| 265 | int status; |
---|
| 266 | time_t library_date; |
---|
| 267 | |
---|
| 268 | register int i; |
---|
| 269 | register char *p; |
---|
| 270 | |
---|
| 271 | bufdsc.dsc$a_pointer = filename; |
---|
| 272 | bufdsc.dsc$w_length = sizeof( filename ); |
---|
| 273 | status = lbr$set_module( &context, rfa, &bufdsc, |
---|
| 274 | &bufdsc.dsc$w_length, NULL ); |
---|
| 275 | |
---|
| 276 | if ( !(status & 1) ) |
---|
| 277 | return ( 1 ); |
---|
| 278 | |
---|
| 279 | mhd = (struct mhddef *)filename; |
---|
| 280 | |
---|
| 281 | file_cvttime( &mhd->mhd$l_datim, &library_date ); |
---|
| 282 | |
---|
| 283 | for ( i = 0, p = module->dsc$a_pointer; i < module->dsc$w_length; i++, p++ ) |
---|
| 284 | filename[i] = *p; |
---|
| 285 | |
---|
| 286 | filename[i] = '\0'; |
---|
| 287 | |
---|
| 288 | sprintf( buf, "%s(%s.obj)", VMS_archive, filename ); |
---|
| 289 | |
---|
| 290 | (*VMS_func)( VMS_closure, buf, 1 /* time valid */, (time_t)library_date ); |
---|
| 291 | |
---|
| 292 | return ( 1 ); |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | void |
---|
| 296 | file_archscan( |
---|
| 297 | char *archive, |
---|
| 298 | scanback func, |
---|
| 299 | void *closure ) |
---|
| 300 | { |
---|
| 301 | static struct dsc$descriptor_s library = |
---|
| 302 | {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL}; |
---|
| 303 | |
---|
| 304 | unsigned long lfunc = LBR$C_READ; |
---|
| 305 | unsigned long typ = LBR$C_TYP_UNK; |
---|
| 306 | unsigned long index = 1; |
---|
| 307 | |
---|
| 308 | register int status; |
---|
| 309 | |
---|
| 310 | VMS_archive = archive; |
---|
| 311 | VMS_func = func; |
---|
| 312 | VMS_closure = closure; |
---|
| 313 | |
---|
| 314 | status = lbr$ini_control( &context, &lfunc, &typ, NULL ); |
---|
| 315 | if ( !( status & 1 ) ) |
---|
| 316 | return; |
---|
| 317 | |
---|
| 318 | library.dsc$a_pointer = archive; |
---|
| 319 | library.dsc$w_length = strlen( archive ); |
---|
| 320 | |
---|
| 321 | status = lbr$open( &context, &library, NULL, NULL, NULL, NULL, NULL ); |
---|
| 322 | if ( !( status & 1 ) ) |
---|
| 323 | return; |
---|
| 324 | |
---|
| 325 | (void) lbr$get_index( &context, &index, file_archmember, NULL ); |
---|
| 326 | |
---|
| 327 | (void) lbr$close( &context ); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | # endif /* VMS */ |
---|
| 331 | |
---|