home *** CD-ROM | disk | FTP | other *** search
-
- #ifndef UNIX
- #ifndef OS2
- #define IS_DOS
- #endif
- #endif
-
- #ifdef TURBO
- #define IS_DOS
- #endif
-
-
- #ifdef IS_DOS
-
- #include "d4base.h"
- #include <dos.h>
-
- typedef struct
- {
- char drive ;
- char pattern[12] ;
- char reserved1 ;
- int file_position ; /* File Position in Directory */
- int directory_position ;
- char reserved2[3] ;
- char file_attribute ;
- int file_time ;
- int file_date ;
- long file_size ;
- char file_name[14] ;
- } DTA ; /* Disk Transfer Area */
-
- static union
- {
- unsigned off_seg[2] ; /* off_seg[0] is offset, off_seg[1] is segment */
- DTA far *far_ptr ;
- } dta ;
-
-
- u4file_first( pattern, first_match )
- char *pattern ;
- char *first_match ;
- {
- union REGS regs ;
- struct SREGS sregs ;
- int i ;
- union
- {
- unsigned off_seg[2] ;
- char far *far_ptr ;
- } ptr ;
-
- ptr.far_ptr = pattern ;
-
- /* Get the Disk Transfer Area Address */
- regs.h.ah = 0x2F ;
- int86x( 0x21, ®s, ®s, &sregs ) ;
- dta.off_seg[0] = regs.x.bx ;
- dta.off_seg[1] = sregs.es ;
-
- regs.h.ah = 0x4E ;
- regs.x.cx = 0 ;
-
- regs.x.dx = ptr.off_seg[0] ;
- sregs.ds = ptr.off_seg[1] ;
-
- int86x( 0x21, ®s, ®s, &sregs ) ;
-
- for( i=0; i< 14; i++ )
- first_match[i] = dta.far_ptr->file_name[i] ;
-
- return ( regs.x.ax ) ;
- }
-
-
- u4file_next( next_match )
- char *next_match ;
- {
- union REGS regs ;
- int i ;
-
- regs.h.ah = 0x4F ;
-
- int86( 0x21, ®s, ®s ) ;
-
- for( i=0; i< 14; i++ )
- next_match[i] = dta.far_ptr->file_name[i] ;
-
- return ( regs.x.ax ) ;
- }
- #endif
-
-
- #ifdef OS2
-
- typedef struct
- {
- unsigned twosecs: 5 ;
- unsigned minutes: 6 ;
- unsigned hours: 5 ;
- } F_TIME ;
-
- typedef struct
- {
- unsigned day: 5 ;
- unsigned month: 4 ;
- unsigned year: 7 ;
- } F_DATE ;
-
- typedef struct
- {
- F_DATE date_created ;
- F_TIME time_created ;
- F_DATE date_last_access ;
- F_TIME time_last_access ;
- F_DATE date_last_write ;
- F_TIME time_last_write ;
- long cb_file ;
- long cb_file_alloc ;
- int attr_file ;
- char name_length ;
- char file_name[13] ;
- } FILE_INFO ;
-
- extern pascal far DOSFINDFIRST( char far *, int far *, int,
- FILE_INFO far *, int, int far *, long) ;
- extern pascal far DOSFINDNEXT( int, FILE_INFO far *, int, int far *) ;
- extern pascal far DOSFINDCLOSE( int ) ;
-
- static int file_hand = -1 ;
-
-
- u4file_first( pattern, first_match )
- char *pattern, *first_match ;
- {
- int rc, count ;
- FILE_INFO file_info ;
-
- if ( file_hand >= 0 ) DOSFINDCLOSE( file_hand ) ;
-
- file_hand = -1 ;
- count = 1 ;
- DOSFINDFIRST( (char far *) pattern, (int far *) &file_hand, 0,
- (FILE_INFO far *) &file_info, (int) sizeof(FILE_INFO),
- (int far *) &count, 0L ) ;
- if ( count == 0 )
- {
- DOSFINDCLOSE( file_hand ) ;
- file_hand = -1 ;
- return 18 ;
- }
- memcpy( first_match, file_info.file_name, 13 ) ;
- first_match[13] = '\0' ;
-
- return 0 ;
- }
-
- u4file_next( next_match )
- char *next_match ;
- {
- int rc, count ;
- FILE_INFO file_info ;
-
- if ( file_hand < 0 ) return 18 ;
-
- count = 1 ;
- DOSFINDNEXT( (int far *) file_hand,
- (FILE_INFO far *) &file_info, (int) sizeof(FILE_INFO),
- (int far *) &count ) ;
-
- if ( count == 0 )
- {
- DOSFINDCLOSE( file_hand ) ;
- file_hand = -1 ;
- return 18 ;
- }
-
- memcpy( next_match, file_info.file_name, 13 ) ;
- next_match[13] = '\0' ;
-
- return 0 ;
- }
- #endif
-
-
- #ifdef UNIX
- #ifndef TURBO
-
- #include <sys/ndir.h>
-
- static DIR * dir_on = (DIR *) 0 ;
-
- u4file_first( pattern, first_match )
- char *pattern ;
- char *first_match ;
- {
- if ( dir_on != (DIR *) 0 )
- closedir( dir_on ) ;
-
- dir_on = opendir( "." ) ;
- if ( dir_on == (DIR *) 0 )
- return 18 ;
-
- return( u4file_next( first_match ) ) ;
- }
-
-
- u4file_next( next_match )
- char *next_match ;
- {
- struct direct *struct_direct ;
-
- if ( dir_on == (DIR *) 0 )
- return 18 ;
-
- struct_direct = readdir( dir_on ) ;
- if ( struct_direct == (struct direct *) 0 )
- {
- closedir( dir_on ) ;
- dir_on = (DIR *) 0 ;
- return 18 ;
- }
-
- strncpy( next_match, struct_direct->d_name, 13 ) ;
- next_match[13] = '\0' ;
-
- return 0 ;
- }
- #endif
- #endif