home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / SOURCE / U4FILE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-21  |  4.8 KB  |  230 lines

  1. /* u4file.c  (c)Copyright Sequiter Software Inc., 1987-1990.  All rights reserved. */
  2.  
  3. #ifndef HC386
  4. #ifndef UNIX
  5. #ifndef OS2
  6. #define IS_DOS
  7. #endif
  8. #endif
  9. #endif
  10.  
  11. #ifdef TURBO
  12. #define  IS_DOS
  13. #endif
  14.  
  15. #ifdef IS_DOS
  16.  
  17. #include "p4misc.h"
  18. #include "d4base.h"
  19. #include <dos.h> 
  20.  
  21. typedef struct dta_st
  22. {
  23.    char  drive ;
  24.    char  pattern[12] ;
  25.    char  reserved1 ;
  26.    short file_position ;    /* File Position in Directory */
  27.    short directory_position ;
  28.    char  reserved2[3] ;
  29.    char  file_attribute ;
  30.    short file_time ;
  31.    short file_date ;
  32.    long  file_size ;
  33.    char  file_name[14] ;
  34. }  DTA ;  /* Disk Transfer Area */
  35.  
  36. static   union ptr_st
  37. {
  38.    struct p_st { int off ; short seg ; } p ;
  39.    DTA far  *far_ptr ;
  40. }  dta, ptr ;
  41.  
  42.  
  43. u4file_first( char *pattern, char *first_match )
  44. {
  45.    union  REGS   in_regs, out_regs ;
  46.    struct SREGS  sregs ;
  47.    int  i, rc ;
  48.  
  49.    /* Get the Disk Transfer Area Address */
  50.    in_regs.h.ah =  0x2F ;
  51.    #ifdef IS_386
  52.       sregs.ds = sregs.es = sregs.fs = sregs.gs = 0x1C ;
  53.       int386x( 0x21, &in_regs, &out_regs, &sregs ) ;
  54.       dta.p.off =  out_regs.x.ebx ;
  55.       dta.p.seg =  sregs.es ;
  56.  
  57.       in_regs.h.ah  =  0x4E ;
  58.       in_regs.x.ecx =  0 ;
  59.  
  60.       ptr.far_ptr   =  (DTA far *) pattern ;
  61.  
  62.       in_regs.x.edx =  ptr.p.off ;
  63.       sregs.ds      =  ptr.p.seg ;
  64.  
  65.       int386x( 0x21, &in_regs, &out_regs, &sregs ) ;
  66.       rc =  (int) (short) (out_regs.w.ax) ;
  67.    #else
  68.       int86x( 0x21, &in_regs, &out_regs, &sregs ) ;
  69.       dta.p.off =  out_regs.x.bx ;
  70.       dta.p.seg =  sregs.es ;
  71.  
  72.       in_regs.h.ah =  0x4E ;
  73.       in_regs.x.cx =  0 ;
  74.  
  75.       ptr.far_ptr  =  (DTA far *) pattern ;
  76.  
  77.       in_regs.x.dx =  ptr.p.off ;
  78.       sregs.ds  =  ptr.p.seg ;
  79.  
  80.       int86x( 0x21, &in_regs, &out_regs, &sregs ) ;
  81.       rc =  out_regs.x.ax ;
  82.    #endif
  83.  
  84.    for( i=0; i< 14; i++ )
  85.       first_match[i] =  dta.far_ptr->file_name[i] ;
  86.  
  87.    return ( rc ) ;
  88. }
  89.  
  90.  
  91. u4file_next( char *next_match )
  92. {
  93.    union  REGS   in_regs, out_regs ;
  94.    int  i, rc ;
  95.  
  96.    in_regs.h.ah =  0x4F ;
  97.  
  98.    #ifdef IS_386
  99.       int386( 0x21, &in_regs, &out_regs ) ;
  100.       rc =  (int) ((short) out_regs.w.ax) ;
  101.    #else
  102.       int86( 0x21, &in_regs, &out_regs ) ;
  103.       rc =  out_regs.x.ax ;
  104.    #endif
  105.  
  106.    for( i=0; i< 14; i++ )
  107.       next_match[i] =  dta.far_ptr->file_name[i] ;
  108.  
  109.    return ( rc ) ;
  110. }
  111. #endif
  112.  
  113.  
  114. #ifdef OS2
  115.  
  116. #include <string.h>
  117. #include "d4base.h"
  118.  
  119. struct FileFindBuf
  120. {
  121.    unsigned short  create_date ;
  122.    unsigned short  create_time ;
  123.    unsigned short  access_date ;
  124.    unsigned short  access_time ;
  125.    unsigned short  write_date ;
  126.    unsigned short  write_time ;
  127.    unsigned long   file_size ;
  128.    unsigned long   falloc_size ;
  129.    unsigned short  attributes ;
  130.    unsigned char   string_len ;
  131.    char            file_name[13] ;
  132. } ;
  133.  
  134. extern unsigned far pascal DOSFINDCLOSE( unsigned ) ;
  135. extern unsigned far pascal DOSFINDFIRST(
  136.    char far *,
  137.    unsigned far *,
  138.    unsigned,
  139.    struct FileFindBuf far *,
  140.    unsigned,
  141.    unsigned far *,
  142.    unsigned long ) ;
  143.  
  144. extern unsigned far pascal DOSFINDNEXT(
  145.    unsigned,
  146.    struct FileFindBuf far *,
  147.    unsigned,
  148.    unsigned far * ) ;
  149.  
  150. static unsigned  file_hand =  0xFFFF ;
  151.  
  152. u4file_first( char *pattern, char *first_match )
  153. {
  154.    unsigned   count ;
  155.    int i ;
  156.    struct FileFindBuf  file_info ;
  157.    char  data[14] ;
  158.  
  159.    strncpy( data, pattern, sizeof(data) ) ;
  160.    for ( i=0; i< sizeof(data); i++ )
  161.       if ( data[i] == ' ' )  data[i] = '\000' ;
  162.  
  163.    if ( file_hand < 0xFFFF )  DOSFINDCLOSE( file_hand ) ;
  164.  
  165.    file_hand  =  0xFFFF ;
  166.    count      =   1 ;
  167.    DOSFINDFIRST( (char far *) data, (unsigned far *) &file_hand, 0,
  168.            (struct FileFindBuf far *) &file_info, (unsigned) sizeof(file_info), 
  169.            (unsigned far *) &count, 0L ) ;
  170.    if ( count == 0 )  
  171.    {
  172.       DOSFINDCLOSE( file_hand ) ;
  173.       file_hand =  0xFFFF ;
  174.       return 18 ;
  175.    }
  176.    memcpy( first_match, file_info.file_name, 13 ) ;
  177.    first_match[13] = '\000' ;
  178.  
  179.    return 0 ;
  180. }
  181.  
  182. u4file_next( char *next_match )
  183. {
  184.    unsigned  count ;
  185.    struct FileFindBuf  file_info ;
  186.  
  187.    if ( file_hand == 0xFFFF )   return 18 ;
  188.  
  189.    count =   1 ;
  190.    DOSFINDNEXT(  (unsigned) file_hand,
  191.           (struct FileFindBuf far *) &file_info, (unsigned) sizeof(file_info), 
  192.           (unsigned far *) &count ) ;
  193.  
  194.    if ( count == 0 )  
  195.    {
  196.       DOSFINDCLOSE( file_hand ) ;
  197.       file_hand =  0xFFFF ;
  198.       return 18 ;
  199.    }
  200.  
  201.    memcpy( next_match, file_info.file_name, 13 ) ;
  202.    next_match[13] = '\000' ;
  203.  
  204.    return 0 ;
  205. }
  206. #endif
  207.  
  208.  
  209. #ifdef UNIX
  210. #ifndef TURBO
  211. #define DO_EMPTY
  212. #endif
  213. #endif
  214.  
  215. #ifdef HC386
  216. #define DO_EMPTY
  217. #endif
  218.  
  219. #ifdef DO_EMPTY
  220. u4file_first( char *pattern, char *first_match )
  221. {
  222.    return 18 ;
  223. }
  224.  
  225. u4file_next( char *next_match )
  226. {
  227.    return 18 ;
  228. }
  229. #endif
  230.