home *** CD-ROM | disk | FTP | other *** search
- /* u4file.c (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved. */
-
- #ifndef HC386
- #ifndef UNIX
- #ifndef OS2
- #define IS_DOS
- #endif
- #endif
- #endif
-
- #ifdef TURBO
- #define IS_DOS
- #endif
-
- #ifdef IS_DOS
-
- #include "p4misc.h"
- #include "d4base.h"
- #include <dos.h>
-
- typedef struct dta_st
- {
- char drive ;
- char pattern[12] ;
- char reserved1 ;
- short file_position ; /* File Position in Directory */
- short directory_position ;
- char reserved2[3] ;
- char file_attribute ;
- short file_time ;
- short file_date ;
- long file_size ;
- char file_name[14] ;
- } DTA ; /* Disk Transfer Area */
-
- static union ptr_st
- {
- struct p_st { int off ; short seg ; } p ;
- DTA far *far_ptr ;
- } dta, ptr ;
-
-
- u4file_first( char *pattern, char *first_match )
- {
- union REGS in_regs, out_regs ;
- struct SREGS sregs ;
- int i, rc ;
-
- /* Get the Disk Transfer Area Address */
- in_regs.h.ah = 0x2F ;
- #ifdef IS_386
- sregs.ds = sregs.es = sregs.fs = sregs.gs = 0x1C ;
- int386x( 0x21, &in_regs, &out_regs, &sregs ) ;
- dta.p.off = out_regs.x.ebx ;
- dta.p.seg = sregs.es ;
-
- in_regs.h.ah = 0x4E ;
- in_regs.x.ecx = 0 ;
-
- ptr.far_ptr = (DTA far *) pattern ;
-
- in_regs.x.edx = ptr.p.off ;
- sregs.ds = ptr.p.seg ;
-
- int386x( 0x21, &in_regs, &out_regs, &sregs ) ;
- rc = (int) (short) (out_regs.w.ax) ;
- #else
- int86x( 0x21, &in_regs, &out_regs, &sregs ) ;
- dta.p.off = out_regs.x.bx ;
- dta.p.seg = sregs.es ;
-
- in_regs.h.ah = 0x4E ;
- in_regs.x.cx = 0 ;
-
- ptr.far_ptr = (DTA far *) pattern ;
-
- in_regs.x.dx = ptr.p.off ;
- sregs.ds = ptr.p.seg ;
-
- int86x( 0x21, &in_regs, &out_regs, &sregs ) ;
- rc = out_regs.x.ax ;
- #endif
-
- for( i=0; i< 14; i++ )
- first_match[i] = dta.far_ptr->file_name[i] ;
-
- return ( rc ) ;
- }
-
-
- u4file_next( char *next_match )
- {
- union REGS in_regs, out_regs ;
- int i, rc ;
-
- in_regs.h.ah = 0x4F ;
-
- #ifdef IS_386
- int386( 0x21, &in_regs, &out_regs ) ;
- rc = (int) ((short) out_regs.w.ax) ;
- #else
- int86( 0x21, &in_regs, &out_regs ) ;
- rc = out_regs.x.ax ;
- #endif
-
- for( i=0; i< 14; i++ )
- next_match[i] = dta.far_ptr->file_name[i] ;
-
- return ( rc ) ;
- }
- #endif
-
-
- #ifdef OS2
-
- #include <string.h>
- #include "d4base.h"
-
- struct FileFindBuf
- {
- unsigned short create_date ;
- unsigned short create_time ;
- unsigned short access_date ;
- unsigned short access_time ;
- unsigned short write_date ;
- unsigned short write_time ;
- unsigned long file_size ;
- unsigned long falloc_size ;
- unsigned short attributes ;
- unsigned char string_len ;
- char file_name[13] ;
- } ;
-
- extern unsigned far pascal DOSFINDCLOSE( unsigned ) ;
- extern unsigned far pascal DOSFINDFIRST(
- char far *,
- unsigned far *,
- unsigned,
- struct FileFindBuf far *,
- unsigned,
- unsigned far *,
- unsigned long ) ;
-
- extern unsigned far pascal DOSFINDNEXT(
- unsigned,
- struct FileFindBuf far *,
- unsigned,
- unsigned far * ) ;
-
- static unsigned file_hand = 0xFFFF ;
-
- u4file_first( char *pattern, char *first_match )
- {
- unsigned count ;
- int i ;
- struct FileFindBuf file_info ;
- char data[14] ;
-
- strncpy( data, pattern, sizeof(data) ) ;
- for ( i=0; i< sizeof(data); i++ )
- if ( data[i] == ' ' ) data[i] = '\000' ;
-
- if ( file_hand < 0xFFFF ) DOSFINDCLOSE( file_hand ) ;
-
- file_hand = 0xFFFF ;
- count = 1 ;
- DOSFINDFIRST( (char far *) data, (unsigned far *) &file_hand, 0,
- (struct FileFindBuf far *) &file_info, (unsigned) sizeof(file_info),
- (unsigned far *) &count, 0L ) ;
- if ( count == 0 )
- {
- DOSFINDCLOSE( file_hand ) ;
- file_hand = 0xFFFF ;
- return 18 ;
- }
- memcpy( first_match, file_info.file_name, 13 ) ;
- first_match[13] = '\000' ;
-
- return 0 ;
- }
-
- u4file_next( char *next_match )
- {
- unsigned count ;
- struct FileFindBuf file_info ;
-
- if ( file_hand == 0xFFFF ) return 18 ;
-
- count = 1 ;
- DOSFINDNEXT( (unsigned) file_hand,
- (struct FileFindBuf far *) &file_info, (unsigned) sizeof(file_info),
- (unsigned far *) &count ) ;
-
- if ( count == 0 )
- {
- DOSFINDCLOSE( file_hand ) ;
- file_hand = 0xFFFF ;
- return 18 ;
- }
-
- memcpy( next_match, file_info.file_name, 13 ) ;
- next_match[13] = '\000' ;
-
- return 0 ;
- }
- #endif
-
-
- #ifdef UNIX
- #ifndef TURBO
- #define DO_EMPTY
- #endif
- #endif
-
- #ifdef HC386
- #define DO_EMPTY
- #endif
-
- #ifdef DO_EMPTY
- u4file_first( char *pattern, char *first_match )
- {
- return 18 ;
- }
-
- u4file_next( char *next_match )
- {
- return 18 ;
- }
- #endif
-