Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / dmake / msdos / find.c
blobd35cc477ec9ee12408658b5bb6234af994a36210
1 /*
2 Directory Access Library
4 FIND.C taken from DIRLIB.C by M. J. Weinstein
5 Released to public domain 1-Jan-89
7 The author may be contacted at:
8 matt@cs.ucla.edu -or- POB 84524, L.A., CA 90073
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).
17 * revision history:
19 * VER MM/DD/YY COMMENTS
20 * ---- -------- --------
21 * 0.99 02/24/86 Beta release to INTERNET
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <ctype.h>
27 #include <errno.h>
28 #include <string.h>
29 #include <alloc.h>
30 #include <dos.h>
31 #include "dosdta.h"
33 #ifndef MK_FP
34 #define MK_FP(seg,ofs) ((void far *) \
35 (((unsigned long)(seg) << 16) | (unsigned)(ofs)))
36 #endif
37 #ifndef FP_SEG
38 #define FP_SEG(fp) ((unsigned)((unsigned long)(fp) >> 16))
39 #endif
40 #ifndef FP_OFF
41 #define FP_OFF(fp) ((unsigned)(fp))
42 #endif
44 int find_err;
47 * get/set dta address
50 static DTA far *
51 _getsetdta(newdta)
52 DTA far *newdta;
54 DTA far *olddta;
55 union REGS r;
56 struct SREGS s;
58 /* get old dta */
59 r.h.ah = 0x2f;
60 intdos(&r, &r);
61 segread(&s);
62 olddta = (DTA far *) MK_FP(s.es, r.x.bx);
64 /* conditionally set new dta */
65 if (newdta) {
66 r.h.ah = 0x1a;
67 s.ds = FP_SEG(newdta);
68 r.x.dx = FP_OFF(newdta);
69 intdosx(&r, &r, &s);
72 return olddta;
76 * dos findfirst
79 DTA *
80 findfirst(name, dta)
81 char *name;
82 DTA *dta;
84 union REGS r;
85 struct SREGS s;
86 DTA far *dtasave;
87 char far *nmp = (char far *)name;
89 dtasave = _getsetdta((DTA far *)dta);
91 /* do directory lookup */
92 segread(&s);
93 r.h.ah = 0x4e;
94 r.x.cx = 0x10;
95 r.x.dx = FP_OFF(nmp);
96 s.ds = FP_SEG(nmp);
97 intdosx(&r, &r, &s);
98 /* restore dta */
99 _getsetdta(dtasave);
100 find_err = r.x.ax;
101 if (r.x.cflag)
102 return(NULL);
104 return dta;
108 * dos findnext
111 DTA *
112 findnext(dta)
113 DTA *dta;
115 union REGS r;
116 DTA far *dtasave;
118 dtasave = _getsetdta((DTA far *)dta);
120 /* do directory lookup */
121 r.h.ah = 0x4f;
122 intdos(&r, &r);
123 /* restore old dta */
124 _getsetdta(dtasave);
125 find_err = r.x.ax;
126 if (r.x.cflag)
127 return(NULL);
129 return dta;