Debian Codegraph @

texk/cjkutils/cjkutils-src/hbf2gf/emdir.c

raw
1 /* emdir.c -- Written by Eberhard Mattes, donated to the public domain */
2
3 #include "emdir.h"
4
5 #ifdef OS2
6
7 #undef HPS
8 #define INCL_DOSFILEMGR
9 #include <os2.h>
10 #include <string.h>
11
12 #define FHDIR(b) (*(HDIR *)(b)->reserved)
13
14 static void fconv (struct ll_findbuffer *dst, const FILEFINDBUF *src)
15 {
16 dst->attr = src->attrFile;
17 dst->time = *(unsigned *)&src->ftimeLastWrite;
18 dst->date = *(unsigned *)&src->fdateLastWrite;
19 dst->size = src->cbFile;
20 strcpy (dst->name, src->achName);
21 }
22
23
24 int ll_findfirst (const char *path, int attr, struct ll_findbuffer *buffer)
25 {
26 USHORT rc;
27 ULONG count;
28 HDIR hdir;
29 FILEFINDBUF ffbuf;
30
31 hdir = HDIR_CREATE;
32 count = 1;
33 rc = DosFindFirst ((PSZ)path, &hdir, attr, &ffbuf, sizeof (ffbuf),
34 &count, 0L);
35 if (rc != 0 || count != 1)
36 return 0;
37 FHDIR (buffer) = hdir;
38 fconv (buffer, &ffbuf);
39 return 1;
40 }
41
42
43 int ll_findnext (struct ll_findbuffer *buffer)
44 {
45 USHORT rc;
46 ULONG count;
47 HDIR hdir;
48 FILEFINDBUF ffbuf;
49
50 hdir = FHDIR (buffer);
51 count = 1;
52 rc = DosFindNext (hdir, &ffbuf, sizeof (ffbuf), &count);
53 if (rc != 0 || count != 1)
54 {
55 DosFindClose (hdir);
56 return 0;
57 }
58 fconv (buffer, &ffbuf);
59 return 1;
60 }
61
62
63 #elif defined(DJGPP)
64
65 /* djgpp support by Hartmut Schirmer ([email protected]), May 30, 1997 */
66
67 #include <dos.h>
68 #include <dir.h>
69
70 static int ll_attr = 0;
71 int ll_findnext (struct ll_findbuffer *buffer)
72 {
73 int res;
74 do {
75 res = _dos_findnext ((struct find_t *)buffer);
76 if (res != 0) return 0;
77 } while ( (buffer->attrib&ll_attr) == 0);
78 return 1;
79 }
80
81 int ll_findfirst (const char *path, int attr, struct ll_findbuffer *buffer)
82 {
83 int res;
84 ll_attr = attr;
85 res = _dos_findfirst((char *)path, attr, (struct find_t *)buffer);
86 if (res != 0) return 0;
87 if ( (buffer->attrib&ll_attr) == 0)
88 return ll_findnext(buffer);
89 return 1;
90 }
91
92 #elif !defined(__EMX__) /* if not OS2 nor DJGPP nor __EMX__ defined */
93
94 /* Not tested */
95
96 #include <dos.h>
97
98 int ll_findfirst (const char *path, int attr, struct ll_findbuffer *buffer)
99 {
100 return _dos_findfirst (path, attr, (struct find_t *)buffer) == 0;
101 }
102
103
104 int ll_findnext (struct ll_findbuffer *buffer)
105 {
106 return _dos_findnext ((struct find_t *)buffer) == 0;
107 }
108
109 #endif