home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dmake40.zip / msdos / find.c < prev    next >
C/C++ Source or Header  |  1994-10-23  |  2KB  |  130 lines

  1. /*
  2.     Directory Access Library
  3.  
  4.            FIND.C taken from DIRLIB.C by M. J. Weinstein
  5.          Released to public domain 1-Jan-89
  6.  
  7.     The author may be contacted at: 
  8.     matt@cs.ucla.edu -or- POB 84524, L.A., CA  90073
  9.  
  10.     Modified by dvadura@watdragon.edu to work with dmake.
  11.     (nuked the DOS version 2 code, since dmake needs version
  12.     3.0 or greater to function).
  13.  */
  14.  
  15.  
  16. /*
  17.  * revision history:
  18.  *
  19.  *    VER    MM/DD/YY    COMMENTS
  20.  *    ----    --------    --------
  21.  *    0.99    02/24/86    Beta release to INTERNET
  22.  */
  23.  
  24. #include <stdlib.h>
  25. #include <ctype.h>
  26. #include <errno.h>
  27. #include <string.h>
  28. #include <alloc.h>
  29. #include <dos.h>
  30. #include "dosdta.h"
  31.  
  32. #ifndef MK_FP
  33. #define MK_FP(seg,ofs)    ((void far *) \
  34.                (((unsigned long)(seg) << 16) | (unsigned)(ofs)))
  35. #endif
  36. #ifndef FP_SEG
  37. #define FP_SEG(fp)    ((unsigned)((unsigned long)(fp) >> 16))
  38. #endif
  39. #ifndef FP_OFF
  40. #define FP_OFF(fp)    ((unsigned)(fp))
  41. #endif
  42.  
  43. int _err;
  44.  
  45. /*
  46.  * get/set dta address
  47.  */
  48.  
  49. static DTA far *
  50. _getsetdta(newdta)
  51. DTA far *newdta;
  52. {
  53.     DTA far *olddta;
  54.     union REGS r;
  55.     struct SREGS s;
  56.  
  57.     /* get old dta */         
  58.     r.h.ah = 0x2f;
  59.     intdos(&r, &r);
  60.     segread(&s);
  61.     olddta = (DTA far *) MK_FP(s.es, r.x.bx);
  62.  
  63.     /* conditionally set new dta */
  64.     if (newdta) {
  65.         r.h.ah = 0x1a;
  66.         s.ds    = FP_SEG(newdta);
  67.         r.x.dx    = FP_OFF(newdta);    
  68.         intdosx(&r, &r, &s);
  69.     }
  70.  
  71.     return olddta;
  72. }
  73.  
  74. /*
  75.  * dos findfirst
  76.  */
  77.  
  78. DTA *
  79. findfirst(name, dta)
  80. char *name;
  81. DTA  *dta;
  82. {
  83.     union REGS r;  
  84.     struct SREGS s;
  85.     DTA far *dtasave;
  86.     char far *nmp = (char far *)name;
  87.  
  88.     dtasave = _getsetdta((DTA far *)dta);
  89.     
  90.     /* do directory lookup */
  91.     segread(&s);
  92.     r.h.ah    = 0x4e;
  93.     r.x.cx    = 0x10;
  94.     r.x.dx    = FP_OFF(nmp);
  95.     s.ds    = FP_SEG(nmp);
  96.     intdosx(&r, &r, &s);
  97.     /* restore dta */
  98.     _getsetdta(dtasave);
  99.     _err = r.x.ax;
  100.     if (r.x.cflag)
  101.         return (DTA *) 0;
  102.  
  103.     return dta;
  104. }
  105.  
  106. /*
  107.  * dos findnext
  108.  */
  109.  
  110. DTA *
  111. findnext(dta)
  112. DTA *dta;
  113. {
  114.     union REGS r;  
  115.     DTA far *dtasave;
  116.  
  117.     dtasave = _getsetdta((DTA far *)dta);
  118.  
  119.     /* do directory lookup */
  120.     r.h.ah = 0x4f;
  121.     intdos(&r, &r);
  122.     /* restore old dta */
  123.     _getsetdta(dtasave);
  124.     _err = r.x.ax;
  125.     if (r.x.cflag)
  126.         return (DTA *) 0;
  127.  
  128.     return dta;
  129. }
  130.