home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / NETMAIL / MSGD2SRC.ZIP / DIR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-01  |  3.2 KB  |  178 lines

  1. /*
  2.  * released into the PUBLIC DOMAIN 30 jul 1990 by jim nutt
  3. */
  4.  
  5. #include <stdlib.h>
  6. #include <errno.h>
  7. #include <dos.h>
  8.  
  9. #define _pascal pascal
  10.  
  11. #ifdef __OS2__
  12. #include <sys\types.h>
  13. #define INCL_DOSPROCESS
  14. #include <os2.h>
  15. #include <sys\stat.h>
  16. #include <ctype.h>
  17. #include <string.h>
  18. #include <io.h>
  19. #include <fcntl.h>
  20. #include <time.h>
  21.  
  22. static struct _FILEFINDBUF InfoBuf;
  23. static struct find_t dta;
  24.  
  25. HDIR    hDir;
  26. USHORT    cSearch;
  27. USHORT    usAttrib;
  28.  
  29. #define FILENAMELEN 13
  30.  
  31. int _pascal dir_findfirst(char * filename, int attribute, struct find_t * dta)
  32. {
  33.     hDir     = 0x0001;
  34.     usAttrib = attribute;
  35.     cSearch  = 1;
  36.  
  37. #ifdef DEBUG
  38.     printf("\nDIR_FINDFIRST Inputs: '%s' %d.\n", filename, attribute);
  39. #endif /* of DEBUG */
  40.  
  41.     if (DosFindFirst( filename
  42.                     , &hDir
  43.                     , usAttrib
  44.                     , &InfoBuf
  45.                     , (USHORT)( sizeof(InfoBuf) * cSearch )
  46.                     , &cSearch
  47.                     , (ULONG)NULL ) != 0 )
  48.     {
  49. #ifdef DEBUG
  50.     printf("DIR_FINDFIRST:  DosFindFirst returned <>0.\n");
  51. #endif /* of DEBUG */
  52.         DosFindClose( hDir );
  53.         errno = ENOENT;
  54.         return (-1);
  55.     } else {
  56. #ifdef DEBUG
  57.     printf("DIR_FINDFIRST:  DosFindFirst returned 0.\n");
  58.     printf("DIR_FINDFIRST:  attrFile = %d.\n", InfoBuf.attrFile);
  59. #endif /* of DEBUG */
  60.         dta->attrib    = (char)InfoBuf.attrFile;           /**OS2**/
  61.         dta->size       = InfoBuf.cbFile;
  62.         strcpy( dta->name, InfoBuf.achName);
  63.         errno = 0;
  64.         return (0);
  65.     }
  66. }
  67.  
  68. int _pascal dir_findnext(struct find_t * dta)
  69. {
  70.  
  71.     if ((DosFindNext( hDir
  72.                     , &InfoBuf
  73.                     , (USHORT)(FILENAMELEN + 23)
  74.                     , &cSearch)
  75.                     ) || (cSearch != 1))
  76.     {
  77.         DosFindClose( hDir );
  78.         errno = ENOENT;
  79.         return (-1);
  80.     } else {
  81.         dta->attrib    = (char)InfoBuf.attrFile;           /**OS2**/
  82.         dta->size       = InfoBuf.cbFile;
  83.         strcpy(  dta->name, InfoBuf.achName);
  84.         errno = 0;
  85.         return (0);
  86.     }
  87. }
  88.  
  89. #else /* of __OS2__ */
  90.  
  91. struct _dta   {
  92.     char        reserved[21];
  93.     char        attribute;
  94.     unsigned    time;
  95.     unsigned    date;
  96.     long        size;
  97.     char        name[13];
  98. };
  99.  
  100. static int olddta = 0;
  101.  
  102. int _pascal dir_findnext(struct _dta * dta);
  103. int _pascal dir_findfirst(char * filename, int attribute, struct _dta * dta);
  104.  
  105. int _pascal dir_findfirst(char * filename, int attribute, struct _dta * dta)
  106.  
  107. {
  108.     union REGS    ir;
  109.     union REGS    or;
  110. #ifndef SPTR
  111.     struct SREGS    sr;
  112. #endif
  113.  
  114.     ir.h.ah = 0x1a;
  115. #ifdef SPTR
  116.     ir.x.dx = (unsigned int) dta;
  117.     intdos(&ir,&or);
  118. #else
  119.     ir.x.dx = FP_OFF(dta);
  120.     sr.ds = FP_SEG(dta);
  121.     intdosx(&ir, &or, &sr);
  122. #endif
  123.     ir.h.ah = 0x4e;
  124.     ir.x.cx = (unsigned int) attribute;
  125. #ifdef SPTR
  126.     ir.x.dx = (unsigned int) filename;
  127.     intdos(&ir,&or);
  128. #else
  129.     ir.x.dx = FP_OFF(filename);
  130.     sr.ds = FP_SEG(filename);
  131.     intdosx(&ir, &or, &sr);
  132. #endif
  133.     if (or.x.cflag) {
  134.         errno = ENOENT;
  135.         return (-1);
  136.     }
  137.  
  138.     errno = 0;
  139.     return (0);
  140. }
  141.  
  142. int _pascal dir_findnext(struct _dta * dta)
  143.  
  144. {
  145.     union REGS ir, or;
  146. #ifndef SPTR
  147.     struct SREGS    sr;
  148. #endif
  149.  
  150.     ir.h.ah = 0x1a;
  151.  
  152.     if (!olddta) {
  153.  
  154. #ifdef SPTR
  155.         ir.x.dx = (unsigned int) dta;
  156.         intdos(&ir,&or);
  157. #else
  158.         ir.x.dx = FP_OFF(dta);
  159.         sr.ds = FP_SEG(dta);
  160.         intdosx(&ir, &or, &sr);
  161. #endif
  162.         olddta = 1;
  163.     }
  164.  
  165.     ir.h.ah = 0x4f;
  166.     intdos(&ir,&or);
  167.  
  168.     if (or.x.cflag) {
  169.         errno = ENOENT;
  170.         return (-1);
  171.     } else {
  172.         errno = 0;
  173.         return (0);
  174.     }
  175. }
  176. #endif /* of __OS2__ */
  177.  
  178.