Mercurial > dwindows
annotate win/dirent.c @ 2608:a11522c30345
Android: Add initial code to handle button presses and long clicks on DWRender.
Android Studio seems to think there is something wrong with the
setOnTouchListener() code but it seems to work.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 16 Jul 2021 18:55:05 +0000 |
parents | 22e3e829be13 |
children |
rev | line source |
---|---|
1617
f8d1da63fb77
Add code to allow building DW.DLL as Unicode on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1601
diff
changeset
|
1 #undef UNICODE |
f8d1da63fb77
Add code to allow building DW.DLL as Unicode on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1601
diff
changeset
|
2 #undef _UNICODE |
f8d1da63fb77
Add code to allow building DW.DLL as Unicode on Windows.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1601
diff
changeset
|
3 |
3 | 4 #include <stdio.h> |
5 #include <stdlib.h> | |
6 #include <string.h> | |
7 #include <ctype.h> | |
8 | |
1960
22e3e829be13
Win: Switch to using winsock 2.x, this will remove support for ancient versions of Windows like 95 and NT 3.5 and older...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1864
diff
changeset
|
9 #include <winsock2.h> |
3 | 10 #include <windows.h> |
11 | |
1839
22225eb286e5
Fixes for building with MINGW64 (specifically http://tdm-gcc.tdragon.net/).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1617
diff
changeset
|
12 #define _DW_INTERNAL |
1594
6baf177f335c
Rename compat.c/h dwcompat.c/h and configure option to --with-dwcompat.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1362
diff
changeset
|
13 #include "dwcompat.h" |
3 | 14 #include <errno.h> |
1362
412af8059331
Attempt to get it building with Mingw again... builds but crashes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
572
diff
changeset
|
15 #include <direct.h> |
3 | 16 |
17 #define error(rc) errno = 255 | |
18 | |
19 struct _dirdescr { | |
20 HANDLE handle; /* DosFindFirst handle */ | |
21 char fstype; /* filesystem type */ | |
22 long count; /* valid entries in <ffbuf> */ | |
23 long number; /* absolute number of next entry */ | |
24 int index; /* relative number of next entry */ | |
25 char name[MAXPATHLEN+3]; /* directory name */ | |
26 unsigned attrmask; /* attribute mask for seekdir */ | |
27 struct dirent entry; /* buffer for directory entry */ | |
28 WIN32_FIND_DATA data; | |
29 }; | |
30 | |
31 /* | |
32 * Return first char of filesystem type, or 0 if unknown. | |
33 */ | |
1864
3816d76835e9
Some more MinGW build fixes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1839
diff
changeset
|
34 static char getFSType(const char *path) |
3 | 35 { |
36 static char cache[1+26]; | |
37 char drive[3]; | |
1601
71e0a3ad07f7
Enable level 3 warnings in DEBUG mode with Visual C to show deprecation warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1594
diff
changeset
|
38 UCHAR unit; |
3 | 39 char r; |
40 | |
41 if (isalpha(path[0]) && path[1] == ':') { | |
42 unit = toupper(path[0]) - '@'; | |
43 path += 2; | |
44 } else { | |
45 return 0; | |
46 } | |
47 | |
48 if ((path[0] == '\\' || path[0] == '/') | |
49 && (path[1] == '\\' || path[1] == '/')) | |
50 return 0; | |
51 | |
52 if (cache [unit]) | |
53 return cache [unit]; | |
54 | |
55 drive[0] = '@' + unit; | |
56 drive[1] = ':'; | |
57 drive[2] = '\0'; | |
58 | |
59 r = GetDriveType(drive); | |
60 | |
61 return cache [unit] = r; | |
62 } | |
63 | |
527
e0ea29c3d1eb
Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
260
diff
changeset
|
64 char * API abs_path(const char *name, char *buffer, int len) |
3 | 65 { |
260
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
66 LPTSTR file; |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
67 |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
68 if(isalpha(name[0]) && name[1] == ':' && name[2] == '\0') |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
69 { |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
70 int drive = _getdrive(); |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
71 char newdrive = toupper(name[0]); |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
72 |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
73 _chdrive((newdrive - 'A')+1); |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
74 |
1601
71e0a3ad07f7
Enable level 3 warnings in DEBUG mode with Visual C to show deprecation warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1594
diff
changeset
|
75 if(_getcwd(buffer, len)) |
260
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
76 { |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
77 _chdrive(drive); |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
78 return buffer; |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
79 } |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
80 _chdrive(drive); |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
81 return NULL; |
3 | 82 } |
260
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
83 if(GetFullPathName(name, len, buffer, &file)) |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
84 return buffer; |
e320dc29bfcd
Rewrote abs_path() so the code will work on NT 4.0.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
184
diff
changeset
|
85 return NULL; |
3 | 86 } |
87 | |
527
e0ea29c3d1eb
Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
260
diff
changeset
|
88 DIR * API openxdir(const char *path, unsigned att_mask) |
3 | 89 { |
90 DIR *dir; | |
91 char name[MAXPATHLEN+3]; | |
92 | |
93 dir = malloc(sizeof(DIR)); | |
94 if (dir == NULL) { | |
95 errno = ENOMEM; | |
96 return NULL; | |
97 } | |
98 | |
99 strncpy(name, path, MAXPATHLEN); | |
100 name[MAXPATHLEN] = '\0'; | |
101 switch (name[strlen(name)-1]) { | |
102 default: | |
103 strcat(name, "\\"); | |
104 case '\\': | |
105 case '/': | |
106 case ':': | |
107 ; | |
108 } | |
109 strcat(name, "."); | |
110 if (!abs_path(name, dir->name, MAXPATHLEN+1)) | |
111 strcpy(dir->name, name); | |
112 if (dir->name[strlen(dir->name)-1] == '\\') | |
113 strcat(dir->name, "*"); | |
114 else | |
115 strcat(dir->name, "\\*"); | |
116 | |
117 dir->fstype = getFSType(dir->name); | |
118 dir->attrmask = att_mask | A_DIR; | |
119 | |
120 dir->count = 100; | |
184
4ec906d40ce2
FindFirstFile returns INVALID_HANDLE_VALUE on error, not NULL.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
121 if((dir->handle = FindFirstFile(dir->name, &dir->data))==INVALID_HANDLE_VALUE) |
3 | 122 { |
123 free(dir); | |
124 error(rc); | |
125 return NULL; | |
126 } | |
127 | |
128 dir->number = 0; | |
129 dir->index = 0; | |
130 | |
131 return (DIR *)dir; | |
132 } | |
133 | |
527
e0ea29c3d1eb
Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
260
diff
changeset
|
134 DIR * API opendir(const char *pathname) |
3 | 135 { |
136 return openxdir(pathname, 0); | |
137 } | |
138 | |
527
e0ea29c3d1eb
Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
260
diff
changeset
|
139 struct dirent * API readdir(DIR *dir) |
3 | 140 { |
141 static int dummy_ino = 2; | |
142 | |
143 if (dir->number) | |
144 { | |
145 dir->count = 100; | |
146 if(!FindNextFile(dir->handle, &(dir->data))) | |
147 { | |
148 error(rc); | |
149 return NULL; | |
150 } | |
151 | |
152 dir->index = 0; | |
153 } | |
154 | |
155 strcpy(dir->entry.d_name, dir->data.cFileName); | |
156 dir->entry.d_ino = dummy_ino++; | |
1601
71e0a3ad07f7
Enable level 3 warnings in DEBUG mode with Visual C to show deprecation warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1594
diff
changeset
|
157 dir->entry.d_reclen = (int)strlen(dir->data.cFileName); |
71e0a3ad07f7
Enable level 3 warnings in DEBUG mode with Visual C to show deprecation warnings.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1594
diff
changeset
|
158 dir->entry.d_namlen = (int)strlen(dir->data.cFileName); |
3 | 159 dir->entry.d_size = dir->data.nFileSizeLow; |
160 dir->entry.d_attribute = dir->data.dwFileAttributes; | |
161 #if 0 | |
162 dir->entry.d_time = *(USHORT *)&dir->next->ftimeLastWrite; | |
163 dir->entry.d_date = *(USHORT *)&dir->next->fdateLastWrite; | |
164 #endif | |
165 | |
166 dir->number++; | |
167 dir->index++; | |
168 return &dir->entry; | |
169 } | |
170 | |
527
e0ea29c3d1eb
Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
260
diff
changeset
|
171 long API telldir(DIR *dir) |
3 | 172 { |
173 return dir->number; | |
174 } | |
175 | |
527
e0ea29c3d1eb
Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
260
diff
changeset
|
176 void API seekdir(DIR *dir, long off) |
3 | 177 { |
178 if (dir->number > off) { | |
179 char name[MAXPATHLEN+2]; | |
180 | |
181 FindClose(dir->handle); | |
182 | |
183 strcpy(name, dir->name); | |
184 strcat(name, "*"); | |
185 | |
186 if((dir->handle = FindFirstFile(name, &(dir->data)))==NULL) | |
187 { | |
188 error(rc); | |
189 return; | |
190 } | |
191 | |
192 dir->number = 0; | |
193 dir->index = 0; | |
194 } | |
195 | |
196 while (dir->number < off && readdir(dir)) | |
197 ; | |
198 } | |
199 | |
527
e0ea29c3d1eb
Fixed dw_window_pointer() so it works on Windows. Tried to fix the
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
260
diff
changeset
|
200 void API closedir(DIR *dir) |
3 | 201 { |
202 FindClose(dir->handle); | |
203 free(dir); | |
204 } | |
205 | |
206 /*****************************************************************************/ | |
207 | |
208 #ifdef TEST | |
209 | |
210 main(int argc, char **argv) | |
211 { | |
212 int i; | |
213 DIR *dir; | |
214 struct dirent *ep; | |
215 | |
216 for (i = 1; i < argc; ++i) { | |
217 dir = opendir(argv[i]); | |
218 if (!dir) | |
219 continue; | |
220 while (ep = readdir(dir)) | |
221 if (strchr("\\/:", argv[i] [strlen(argv[i]) - 1])) | |
222 printf("%s%s\n", argv[i], ep->d_name); | |
223 else | |
224 printf("%s/%s\n", argv[i], ep->d_name); | |
225 closedir(dir); | |
226 } | |
227 | |
228 return 0; | |
229 } | |
230 | |
231 #endif |