author | Claus Gittinger <cg@exept.de> |
Tue, 27 Apr 2010 14:27:33 +0200 | |
changeset 12900 | 4cda19285039 |
parent 12714 | 1b221a2eb0d8 |
child 12909 | e844bd18a3aa |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
155 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
7826 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
1 | 14 |
FileStream subclass:#DirectoryStream |
1664 | 15 |
instanceVariableNames:'dirPointer readAheadEntry' |
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
16 |
classVariableNames:'' |
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
17 |
poolDictionaries:'' |
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
18 |
category:'Streams-External' |
1 | 19 |
! |
20 |
||
217 | 21 |
!DirectoryStream primitiveDefinitions! |
1 | 22 |
%{ |
437 | 23 |
|
1631 | 24 |
#define UNIX_LIKE |
2609 | 25 |
|
1631 | 26 |
#if defined(WIN32) |
27 |
# undef UNIX_LIKE |
|
28 |
#endif |
|
437 | 29 |
|
2896 | 30 |
#if defined(transputer) |
31 |
# undef UNIX_LIKE |
|
32 |
#endif |
|
33 |
||
1631 | 34 |
#ifdef UNIX_LIKE |
7955
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
35 |
# if defined(__GLIBC__) && (__GLIBC__ == 2) |
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
36 |
# if defined(__GLIBC_MINOR__) && (__GLIBC_MINOR__ == 1) |
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
37 |
/* there is a bug there, preventing 64bit readdir. */ |
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
38 |
# undef __USE_FILE_OFFSET64 |
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
39 |
# undef __USE_LARGEFILE64 |
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
40 |
# endif |
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
41 |
# endif |
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
42 |
|
1631 | 43 |
# include <stdio.h> |
44 |
# define _STDIO_H_INCLUDED_ |
|
45 |
||
46 |
# include <errno.h> |
|
47 |
# define _ERRNO_H_INCLUDED_ |
|
10 | 48 |
|
2896 | 49 |
# include <sys/types.h> |
50 |
# include <sys/stat.h> |
|
1631 | 51 |
|
2896 | 52 |
# ifdef HAS_OPENDIR |
53 |
# include <sys/types.h> |
|
54 |
# ifdef NEXT |
|
55 |
# include <sys/dir.h> |
|
8881
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8775
diff
changeset
|
56 |
# define DIRENT_STRUCT struct direct |
2896 | 57 |
# else |
58 |
# include <dirent.h> |
|
8881
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8775
diff
changeset
|
59 |
# define DIRENT_STRUCT struct dirent |
1 | 60 |
# endif |
61 |
# endif |
|
223 | 62 |
|
63 |
/* |
|
64 |
* on some systems errno is a macro ... check for it here |
|
65 |
*/ |
|
1631 | 66 |
# ifndef errno |
67 |
extern errno; |
|
68 |
# endif |
|
2896 | 69 |
|
1631 | 70 |
#endif /* UNIX_LIKE */ |
71 |
||
2896 | 72 |
|
1631 | 73 |
#ifdef WIN32 |
74 |
||
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8881
diff
changeset
|
75 |
# ifdef __i386__ |
1631 | 76 |
# define _X86_ |
77 |
# endif |
|
78 |
||
79 |
# undef INT |
|
80 |
# undef Array |
|
81 |
# undef Number |
|
82 |
# undef Method |
|
83 |
# undef Point |
|
84 |
# undef Context |
|
85 |
# undef Rectangle |
|
1989 | 86 |
# undef Block |
4298 | 87 |
# undef Time |
88 |
# undef Date |
|
10342 | 89 |
# undef Message |
90 |
# undef Process |
|
91 |
# undef Processor |
|
92 |
# undef INT |
|
1631 | 93 |
|
2685 | 94 |
/* # include <types.h> /* */ |
1989 | 95 |
# include <stdarg.h> /* */ |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4526
diff
changeset
|
96 |
# include <errno.h> |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4526
diff
changeset
|
97 |
# define _ERRNO_H_INCLUDED_ |
1989 | 98 |
# include <windef.h> /* */ |
99 |
# include <winbase.h> /* */ |
|
4298 | 100 |
/* # include <wingdi.h> /* */ |
101 |
/* # include <winuser.h> /* */ |
|
1631 | 102 |
|
103 |
# ifdef __DEF_Array |
|
104 |
# define Array __DEF_Array |
|
105 |
# endif |
|
106 |
# ifdef __DEF_Number |
|
107 |
# define Number __DEF_Number |
|
108 |
# endif |
|
109 |
# ifdef __DEF_Method |
|
110 |
# define Method __DEF_Method |
|
111 |
# endif |
|
112 |
# ifdef __DEF_Point |
|
113 |
# define Point __DEF_Point |
|
114 |
# endif |
|
1989 | 115 |
# ifdef __DEF_Block |
116 |
# define Block __DEF_Block |
|
117 |
# endif |
|
1631 | 118 |
# ifdef __DEF_Context |
119 |
# define Context __DEF_Context |
|
120 |
# endif |
|
4298 | 121 |
# ifdef __DEF_Date |
122 |
# define Date __DEF_Date |
|
123 |
# endif |
|
124 |
# ifdef __DEF_Time |
|
125 |
# define Time __DEF_Time |
|
126 |
# endif |
|
10342 | 127 |
# ifdef __DEF_Message |
128 |
# define Message __DEF_Message |
|
129 |
# endif |
|
130 |
# ifdef __DEF_Process |
|
131 |
# define Process __DEF_Process |
|
132 |
# endif |
|
133 |
# ifdef __DEF_Processor |
|
134 |
# define Processor __DEF_Processor |
|
135 |
# endif |
|
136 |
# define INT int |
|
1631 | 137 |
|
2999
b0e55440cf12
eliminate MKOBJ & MKCP (use MKEXTERNALADDRESS & externalAddressVal)
Claus Gittinger <cg@exept.de>
parents:
2982
diff
changeset
|
138 |
# define __HANDLEVal(o) (HANDLE)__externalAddressVal(o) |
12714 | 139 |
#endif /* WIN32 */ |
1631 | 140 |
|
12714 | 141 |
#include "stxOSDefs.h" |
223 | 142 |
|
1 | 143 |
%} |
206 | 144 |
! ! |
1 | 145 |
|
438 | 146 |
!DirectoryStream primitiveFunctions! |
147 |
%{ |
|
2896 | 148 |
|
149 |
#ifndef HAS_OPENDIR |
|
7955
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
150 |
|
2896 | 151 |
# if defined(__VMS__) |
152 |
||
3816
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
153 |
# define lib$find_file LIB$FIND_FILE |
438 | 154 |
|
155 |
/* |
|
156 |
** VMS readdir() routines. |
|
157 |
** Written by Rich $alz, <rsalz@bbn.com> in August, 1990. |
|
158 |
** This code has no copyright. |
|
159 |
*/ |
|
160 |
||
8881
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8775
diff
changeset
|
161 |
/* 12-NOV-1990 added d_namlen field and special case "." name -GJC@MITECH.COM |
438 | 162 |
*/ |
163 |
||
2896 | 164 |
# ifndef _STDIO_H_INCLUDED_ |
165 |
# include <stdio.h> |
|
166 |
# define _STDIO_H_INCLUDED_ |
|
167 |
# endif |
|
438 | 168 |
|
2896 | 169 |
# ifndef _CTYPE_H_INCLUDED_ |
170 |
# include <ctype.h> |
|
171 |
# define _CTYPE_H_INCLUDED_ |
|
172 |
# endif |
|
438 | 173 |
|
2896 | 174 |
# ifndef _ERRNO_H_INCLUDED_ |
175 |
# include <errno.h> |
|
176 |
# define _ERRNO_H_INCLUDED_ |
|
177 |
# endif |
|
438 | 178 |
|
2896 | 179 |
# ifndef _DESCRIP_H_INCLUDED_ |
180 |
# include <descrip.h> |
|
181 |
# define _DESCRIP_H_INCLUDED_ |
|
182 |
# endif |
|
438 | 183 |
|
2896 | 184 |
# ifndef _RMSDEF_H_INCLUDED_ |
185 |
# include <rmsdef.h> |
|
186 |
# define _RMSDEF_H_INCLUDED_ |
|
187 |
# endif |
|
438 | 188 |
|
189 |
/* |
|
190 |
* actually, the following has to go into dirent.h ... |
|
191 |
*/ |
|
2896 | 192 |
/* BEGIN included dirent.h |
438 | 193 |
* |
194 |
** Header file for VMS readdir() routines. |
|
195 |
** Written by Rich $alz, <rsalz@bbn.com> in August, 1990. |
|
196 |
** This code has no copyright. |
|
197 |
** |
|
198 |
** You must #include <descrip.h> before this file. |
|
199 |
*/ |
|
200 |
||
201 |
/* 12-NOV-1990 added d_namlen field -GJC@MITECH.COM */ |
|
202 |
||
203 |
/* Data structure returned by READDIR(). */ |
|
204 |
struct dirent { |
|
205 |
char d_name[100]; /* File name */ |
|
206 |
int d_namlen; |
|
2957 | 207 |
int vms_verscount; /* Number of versions */ |
208 |
int vms_versions[20]; /* Version numbers */ |
|
438 | 209 |
}; |
210 |
||
211 |
/* Handle returned by opendir(), used by the other routines. You |
|
212 |
* are not supposed to care what's inside this structure. */ |
|
213 |
typedef struct _dirdesc { |
|
214 |
long context; |
|
2957 | 215 |
int vms_wantversions; |
438 | 216 |
char *pattern; |
217 |
struct dirent entry; |
|
218 |
struct dsc$descriptor_s pat; |
|
219 |
} DIR; |
|
220 |
||
221 |
||
222 |
#define rewinddir(dirp) seekdir((dirp), 0L) |
|
223 |
||
224 |
||
225 |
extern DIR *opendir(); |
|
226 |
extern struct dirent *readdir(); |
|
227 |
extern long telldir(); |
|
228 |
extern void seekdir(); |
|
229 |
extern void closedir(); |
|
230 |
extern void vmsreaddirversions(); |
|
231 |
/* |
|
232 |
* END dirent.h |
|
233 |
*/ |
|
2896 | 234 |
#define _DIRENT_H_INCLUDED_ |
438 | 235 |
|
236 |
||
237 |
/* Number of elements in vms_versions array */ |
|
238 |
#define VERSIZE(e) (sizeof e->vms_versions / sizeof e->vms_versions[0]) |
|
239 |
||
240 |
/* Linked in later. */ |
|
241 |
extern char *strrchr(); |
|
242 |
extern char *strcpy(); |
|
243 |
/* Don't need this when all these programs are lumped together. RLD |
|
244 |
extern char *malloc(); |
|
245 |
*/ |
|
246 |
||
247 |
/* |
|
248 |
** Open a directory, return a handle for later use. |
|
249 |
*/ |
|
250 |
DIR * |
|
251 |
opendir(name) |
|
252 |
char *name; |
|
253 |
{ |
|
254 |
DIR *dd; |
|
255 |
||
256 |
/* Get memory for the handle, and the pattern. */ |
|
257 |
if ((dd = (DIR *)malloc(sizeof *dd)) == NULL) { |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4526
diff
changeset
|
258 |
__threadErrno = ENOMEM; |
438 | 259 |
return NULL; |
260 |
} |
|
261 |
||
262 |
if (strcmp(".",name) == 0) name = ""; |
|
263 |
||
264 |
dd->pattern = malloc((unsigned int)(strlen(name) + sizeof "*.*" + 1)); |
|
265 |
if (dd->pattern == NULL) { |
|
266 |
free((char *)dd); |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4526
diff
changeset
|
267 |
__threadErrno = ENOMEM; |
438 | 268 |
return NULL; |
269 |
} |
|
270 |
||
271 |
/* Fill in the fields; mainly playing with the descriptor. */ |
|
272 |
(void)sprintf(dd->pattern, "%s*.*", name); |
|
273 |
dd->context = 0; |
|
274 |
dd->vms_wantversions = 0; |
|
275 |
dd->pat.dsc$a_pointer = dd->pattern; |
|
276 |
dd->pat.dsc$w_length = strlen(dd->pattern); |
|
277 |
dd->pat.dsc$b_dtype = DSC$K_DTYPE_T; |
|
278 |
dd->pat.dsc$b_class = DSC$K_CLASS_S; |
|
279 |
||
280 |
return dd; |
|
281 |
} |
|
282 |
||
283 |
/* |
|
284 |
** Set the flag to indicate we want versions or not. |
|
285 |
*/ |
|
286 |
void |
|
287 |
vmsreaddirversions(dd, flag) |
|
288 |
DIR *dd; |
|
289 |
int flag; |
|
290 |
{ |
|
291 |
dd->vms_wantversions = flag; |
|
292 |
} |
|
293 |
||
294 |
/* |
|
295 |
** Free up an opened directory. |
|
296 |
*/ |
|
297 |
void |
|
298 |
closedir(dd) |
|
299 |
DIR *dd; |
|
300 |
{ |
|
301 |
free(dd->pattern); |
|
302 |
free((char *)dd); |
|
303 |
} |
|
304 |
||
305 |
/* |
|
306 |
** Collect all the version numbers for the current file. |
|
307 |
*/ |
|
308 |
static void |
|
309 |
collectversions(dd) |
|
310 |
DIR *dd; |
|
311 |
{ |
|
312 |
struct dsc$descriptor_s pat; |
|
313 |
struct dsc$descriptor_s res; |
|
314 |
struct dirent *e; |
|
315 |
char *p; |
|
316 |
char buff[sizeof dd->entry.d_name]; |
|
317 |
int i; |
|
318 |
char *text; |
|
319 |
long context; |
|
320 |
||
321 |
/* Convenient shorthand. */ |
|
322 |
e = &dd->entry; |
|
323 |
||
324 |
/* Add the version wildcard, ignoring the "*.*" put on before */ |
|
325 |
i = strlen(dd->pattern); |
|
326 |
text = malloc((unsigned int)(i + strlen(e->d_name)+ 2 + 1)); |
|
327 |
if (text == NULL) |
|
328 |
return; |
|
329 |
(void)strcpy(text, dd->pattern); |
|
330 |
(void)sprintf(&text[i - 3], "%s;*", e->d_name); |
|
331 |
||
332 |
/* Set up the pattern descriptor. */ |
|
333 |
pat.dsc$a_pointer = text; |
|
334 |
pat.dsc$w_length = strlen(text); |
|
335 |
pat.dsc$b_dtype = DSC$K_DTYPE_T; |
|
336 |
pat.dsc$b_class = DSC$K_CLASS_S; |
|
337 |
||
338 |
/* Set up result descriptor. */ |
|
339 |
res.dsc$a_pointer = buff; |
|
340 |
res.dsc$w_length = sizeof buff - 2; |
|
341 |
res.dsc$b_dtype = DSC$K_DTYPE_T; |
|
342 |
res.dsc$b_class = DSC$K_CLASS_S; |
|
343 |
||
344 |
/* Read files, collecting versions. */ |
|
345 |
for (context = 0; e->vms_verscount < VERSIZE(e); e->vms_verscount++) { |
|
346 |
if (lib$find_file(&pat, &res, &context) == RMS$_NMF || context == 0) |
|
347 |
break; |
|
348 |
buff[sizeof buff - 1] = '\0'; |
|
349 |
if (p = strchr(buff, ';')) |
|
350 |
e->vms_versions[e->vms_verscount] = atoi(p + 1); |
|
351 |
else |
|
352 |
e->vms_versions[e->vms_verscount] = -1; |
|
353 |
} |
|
354 |
||
355 |
free(text); |
|
356 |
} |
|
357 |
||
358 |
/* |
|
359 |
** Read the next entry from the directory. |
|
360 |
*/ |
|
361 |
struct dirent * |
|
362 |
readdir(dd) |
|
2957 | 363 |
DIR *dd; |
438 | 364 |
{ |
2957 | 365 |
struct dsc$descriptor_s res; |
366 |
char *p; |
|
2982 | 367 |
char buff[sizeof dd->entry.d_name + 10]; |
2957 | 368 |
int i; |
438 | 369 |
|
370 |
/* Set up result descriptor, and get next file. */ |
|
371 |
res.dsc$a_pointer = buff; |
|
372 |
res.dsc$w_length = sizeof buff - 2; |
|
373 |
res.dsc$b_dtype = DSC$K_DTYPE_T; |
|
374 |
res.dsc$b_class = DSC$K_CLASS_S; |
|
375 |
if (lib$find_file(&dd->pat, &res, &dd->context) == RMS$_NMF |
|
376 |
|| dd->context == 0L) |
|
377 |
/* None left... */ |
|
378 |
return NULL; |
|
379 |
||
380 |
/* Force the buffer to end with a NUL. */ |
|
381 |
buff[sizeof buff - 1] = '\0'; |
|
382 |
for (p = buff; !isspace(*p); p++) |
|
383 |
; |
|
384 |
*p = '\0'; |
|
385 |
||
386 |
/* Skip any directory component and just copy the name. */ |
|
387 |
if (p = strchr(buff, ']')) |
|
388 |
(void)strcpy(dd->entry.d_name, p + 1); |
|
389 |
else |
|
390 |
(void)strcpy(dd->entry.d_name, buff); |
|
391 |
||
392 |
/* Clobber the version. */ |
|
393 |
if (p = strchr(dd->entry.d_name, ';')) |
|
394 |
*p = '\0'; |
|
395 |
||
2982 | 396 |
/* claus: empty dirs seems to leave *.* in the buffer ... */ |
397 |
if (strcmp(dd->entry.d_name, "*.*") == 0) { |
|
398 |
return NULL; |
|
399 |
} |
|
400 |
||
438 | 401 |
dd->entry.d_namlen = strlen(dd->entry.d_name); |
402 |
||
403 |
dd->entry.vms_verscount = 0; |
|
404 |
if (dd->vms_wantversions) |
|
405 |
collectversions(dd); |
|
406 |
return &dd->entry; |
|
407 |
} |
|
408 |
||
409 |
/* |
|
410 |
** Return something that can be used in a seekdir later. |
|
411 |
*/ |
|
412 |
long |
|
413 |
telldir(dd) |
|
2957 | 414 |
DIR *dd; |
438 | 415 |
{ |
416 |
return dd->context; |
|
417 |
} |
|
418 |
||
419 |
/* |
|
420 |
** Return to a spot where we used to be. |
|
421 |
*/ |
|
422 |
void |
|
423 |
seekdir(dd, pos) |
|
2957 | 424 |
DIR *dd; |
425 |
long pos; |
|
438 | 426 |
{ |
427 |
dd->context = pos; |
|
428 |
} |
|
429 |
||
2896 | 430 |
# define HAS_OPENDIR |
431 |
||
432 |
# endif /* __VMS__ */ |
|
433 |
#endif /* not HAS_OPENDIR */ |
|
438 | 434 |
%} |
435 |
! ! |
|
436 |
||
613 | 437 |
!DirectoryStream class methodsFor:'documentation'! |
438 |
||
439 |
copyright |
|
440 |
" |
|
441 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
442 |
All Rights Reserved |
|
1 | 443 |
|
613 | 444 |
This software is furnished under a license and may be used |
445 |
only in accordance with the terms of that license and with the |
|
446 |
inclusion of the above copyright notice. This software may not |
|
447 |
be provided or otherwise made available to, or used by, any |
|
448 |
other person. No title to or ownership of the software is |
|
449 |
hereby transferred. |
|
450 |
" |
|
451 |
! |
|
360 | 452 |
|
613 | 453 |
documentation |
454 |
" |
|
455 |
Instances of DirectoryStream allow reading a file-directory, |
|
456 |
as if it was a stream of filenames. |
|
457 |
Basically, its an interface to opendir, readdir and closedir. |
|
8881
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8775
diff
changeset
|
458 |
Notice: |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8775
diff
changeset
|
459 |
DirectoryStream is an ST/X special; |
2957 | 460 |
for portability, we recommend the use of Filename protocol. |
1295 | 461 |
|
462 |
[author:] |
|
1631 | 463 |
Claus Gittinger |
2957 | 464 |
|
465 |
[see also:] |
|
466 |
Filename |
|
613 | 467 |
" |
1 | 468 |
! ! |
469 |
||
470 |
!DirectoryStream class methodsFor:'instance creation'! |
|
471 |
||
472 |
directoryNamed:dirName |
|
7826 | 473 |
"return a DirectoryStream for directory named dirName, aString |
474 |
Raises an openError, if the directory does not exists." |
|
1 | 475 |
|
476 |
|newStream| |
|
477 |
||
8775 | 478 |
newStream := (self basicNew) text; pathName:dirName. |
1 | 479 |
newStream openForReading isNil ifTrue:[^nil]. |
480 |
^ newStream |
|
7826 | 481 |
|
482 |
" |
|
8881
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8775
diff
changeset
|
483 |
self directoryNamed:'adadasd' |
53e94478133f
STORE macro fix (gcc3.4 bug)
Claus Gittinger <cg@exept.de>
parents:
8775
diff
changeset
|
484 |
self directoryNamed:'.' |
7826 | 485 |
" |
1 | 486 |
! ! |
487 |
||
5245 | 488 |
!DirectoryStream methodsFor:'access-reading'! |
1 | 489 |
|
490 |
nextLine |
|
491 |
"return the next filename as a string" |
|
492 |
||
11317
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
493 |
|prevEntry nextEntry isUnix| |
1 | 494 |
%{ |
77 | 495 |
#ifdef HAS_OPENDIR |
1 | 496 |
DIR *d; |
7955
f3a24f9588ee
64bit readdir bug workaround
Claus Gittinger <cg@exept.de>
parents:
7826
diff
changeset
|
497 |
DIRENT_STRUCT *dp; |
92 | 498 |
OBJ dirP; |
1 | 499 |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
500 |
if (__INST(hitEOF) != true && (dirP = __INST(dirPointer)) != nil) { |
11317
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
501 |
__INST(lastErrorNumber) = nil; |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
502 |
d = (DIR *)__FILEVal(dirP); |
92 | 503 |
|
11317
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
504 |
__BEGIN_INTERRUPTABLE__ |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
505 |
do { |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
506 |
do { |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
507 |
__threadErrno = 0; |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
508 |
dp = readdir(d); |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
509 |
/* |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
510 |
* for compatibility with ST-80, |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
511 |
* skip entries for '.' and '..'. |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
512 |
* If wanted, these must be added synthetically. |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
513 |
*/ |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
514 |
} while (dp && ((strcmp(dp->d_name, ".")==0) || (strcmp(dp->d_name, "..")==0))); |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
515 |
} while ((dp == NULL) && (__threadErrno == EINTR)); |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
516 |
__END_INTERRUPTABLE__ |
92 | 517 |
|
11317
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
518 |
if (dp != NULL) { |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
519 |
nextEntry = __MKSTRING((char *)(dp->d_name)); |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
520 |
} else { |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
521 |
if (__threadErrno) { |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
522 |
__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno); |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
523 |
} else { |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
524 |
__INST(hitEOF) = true; |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
525 |
} |
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
526 |
} |
1 | 527 |
} |
1631 | 528 |
#else /* no HAS_OPENDIR */ |
529 |
# ifdef WIN32 |
|
530 |
HANDLE d; |
|
11288 | 531 |
WIN32_FIND_DATAW data; |
1631 | 532 |
OBJ dirP; |
3816
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
533 |
int rslt; |
1631 | 534 |
|
535 |
if (__INST(hitEOF) != true && (dirP = __INST(dirPointer)) != nil) { |
|
11317
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
536 |
__INST(lastErrorNumber) = nil; |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
537 |
d = __HANDLEVal(dirP); |
1631 | 538 |
|
11317
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
539 |
do { |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
540 |
__threadErrno = 0; |
12713
98b31733e9c1
Make most win32 wrap calls non-interruptable
Stefan Vogel <sv@exept.de>
parents:
12655
diff
changeset
|
541 |
rslt = STX_API_NOINT_CALL2( "FindNextFileW", FindNextFileW, d, &data ); |
11317
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
542 |
} while ((rslt < 0) && (__threadErrno == EINTR)); |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
5245
diff
changeset
|
543 |
|
11317
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
544 |
if (rslt > 0) { |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
545 |
nextEntry = __MKU16STRING( data.cFileName ); |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
546 |
} else { |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
547 |
__INST(hitEOF) = true; |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
548 |
} |
1631 | 549 |
} |
550 |
# endif /* WIN32 */ |
|
551 |
#endif /* HAS_OPENDIR */ |
|
12414 | 552 |
|
553 |
#ifdef unix |
|
554 |
isUnix = true; |
|
555 |
#endif |
|
556 |
||
155 | 557 |
%}. |
558 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
|
11317
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
559 |
nextEntry notNil ifTrue:[ |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
560 |
isUnix == true ifTrue:[ |
11327
37b813ab86e9
changed #nextLine - handle utf8 decoding errors
Stefan Vogel <sv@exept.de>
parents:
11317
diff
changeset
|
561 |
"linux strings are in UTF8 (in contemporary linux versions)" |
37b813ab86e9
changed #nextLine - handle utf8 decoding errors
Stefan Vogel <sv@exept.de>
parents:
11317
diff
changeset
|
562 |
[ |
37b813ab86e9
changed #nextLine - handle utf8 decoding errors
Stefan Vogel <sv@exept.de>
parents:
11317
diff
changeset
|
563 |
nextEntry := nextEntry utf8Decoded. |
37b813ab86e9
changed #nextLine - handle utf8 decoding errors
Stefan Vogel <sv@exept.de>
parents:
11317
diff
changeset
|
564 |
] on:InvalidEncodingError do:[:ex| |
12655
6a86bde3f087
comment/format in: #nextLine
Claus Gittinger <cg@exept.de>
parents:
12468
diff
changeset
|
565 |
"maybe there are old filenames in ISO8859-x, |
11327
37b813ab86e9
changed #nextLine - handle utf8 decoding errors
Stefan Vogel <sv@exept.de>
parents:
11317
diff
changeset
|
566 |
just keep them untranslated" |
37b813ab86e9
changed #nextLine - handle utf8 decoding errors
Stefan Vogel <sv@exept.de>
parents:
11317
diff
changeset
|
567 |
]. |
11317
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
568 |
] ifFalse:[ |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
569 |
nextEntry := nextEntry asSingleByteStringIfPossible. |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
570 |
] |
c634e925111f
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
11302
diff
changeset
|
571 |
]. |
1664 | 572 |
prevEntry := readAheadEntry. |
573 |
readAheadEntry := nextEntry. |
|
8614 | 574 |
prevEntry isNil ifTrue:[^ self pastEndRead]. |
1 | 575 |
^ prevEntry |
576 |
! ! |
|
577 |
||
613 | 578 |
!DirectoryStream methodsFor:'closing'! |
579 |
||
580 |
close |
|
581 |
"close the stream - tell operating system" |
|
582 |
||
583 |
dirPointer notNil ifTrue:[ |
|
584 |
Lobby unregister:self. |
|
585 |
self closeFile. |
|
586 |
dirPointer := nil |
|
587 |
] |
|
588 |
! ! |
|
589 |
||
8519 | 590 |
!DirectoryStream protectedMethodsFor:'instance release'! |
613 | 591 |
|
592 |
closeFile |
|
593 |
"low level close of a directoryStream" |
|
594 |
%{ |
|
595 |
#ifdef HAS_OPENDIR |
|
596 |
OBJ dp; |
|
597 |
||
1133 | 598 |
if ((dp = __INST(dirPointer)) != nil) { |
599 |
__INST(dirPointer) = nil; |
|
613 | 600 |
closedir( (DIR *)(__FILEVal(dp)) ); |
601 |
} |
|
1631 | 602 |
#else |
603 |
# ifdef WIN32 |
|
604 |
OBJ dp; |
|
605 |
||
606 |
if ((dp = __INST(dirPointer)) != nil) { |
|
607 |
__INST(dirPointer) = nil; |
|
608 |
FindClose( __HANDLEVal(dp) ); |
|
609 |
} |
|
610 |
# endif |
|
613 | 611 |
#endif |
612 |
%} |
|
613 |
! ! |
|
614 |
||
1 | 615 |
!DirectoryStream methodsFor:'private'! |
616 |
||
617 |
openForReading |
|
618 |
"open the file for readonly" |
|
619 |
||
1631 | 620 |
|ok entry| |
1 | 621 |
|
622 |
mode := #readonly. |
|
623 |
%{ |
|
77 | 624 |
#ifdef HAS_OPENDIR |
1 | 625 |
DIR *d; |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
626 |
OBJ path, dp; |
1 | 627 |
|
155 | 628 |
ok = false; |
1133 | 629 |
if (__INST(dirPointer) == nil) { |
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
630 |
path = __INST(pathName); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
631 |
if (__isStringLike(path)) { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
632 |
__BEGIN_INTERRUPTABLE__ |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
633 |
__threadErrno = 0; |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
634 |
do { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
635 |
path = __INST(pathName); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
636 |
d = opendir((char *) __stringVal(path)); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
637 |
} while ((d == NULL) && (__threadErrno == EINTR)); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
638 |
__END_INTERRUPTABLE__ |
92 | 639 |
|
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
640 |
if (d == NULL) { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
641 |
__INST(lastErrorNumber) = __mkSmallInteger(__threadErrno); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
642 |
} else { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
643 |
dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
644 |
ok = true; |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
645 |
} |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
646 |
} |
1 | 647 |
} |
1631 | 648 |
#else |
649 |
# ifdef WIN32 |
|
11302 | 650 |
# ifndef MAXPATHLEN |
11294 | 651 |
# define MAXPATHLEN 1024 |
652 |
# endif |
|
1631 | 653 |
HANDLE d; |
654 |
OBJ path, dp; |
|
11294 | 655 |
union { |
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
656 |
char pattern[MAXPATHLEN]; |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
657 |
wchar_t wpattern[MAXPATHLEN]; |
11294 | 658 |
} uP; |
659 |
union { |
|
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
660 |
WIN32_FIND_DATAA data; |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
661 |
WIN32_FIND_DATAW wdata; |
11294 | 662 |
} uD; |
1631 | 663 |
|
664 |
ok = false; |
|
665 |
if (__INST(dirPointer) == nil) { |
|
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
666 |
path = __INST(pathName); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
667 |
if (__isStringLike(path)) { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
668 |
int l = __stringSize(path); |
3164
4f37ae9c8961
use strncpy to avoid buffer-overruns
Claus Gittinger <cg@exept.de>
parents:
2999
diff
changeset
|
669 |
|
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
670 |
if (l < (MAXPATHLEN-4)) { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
671 |
strncpy(uP.pattern, __stringVal(path), l); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
672 |
strcpy(uP.pattern+l, "\\*"); |
11294 | 673 |
|
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
674 |
do { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
675 |
__threadErrno = 0; |
12713
98b31733e9c1
Make most win32 wrap calls non-interruptable
Stefan Vogel <sv@exept.de>
parents:
12655
diff
changeset
|
676 |
d = STX_API_NOINT_CALL2( "FindFirstFileA", FindFirstFileA, uP.pattern, &uD.data ); |
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
677 |
} while ((d < 0) && (__threadErrno == EINTR)); |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
5245
diff
changeset
|
678 |
|
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
679 |
if (d == INVALID_HANDLE_VALUE) { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
680 |
__INST(lastErrorNumber) = __mkSmallInteger(GetLastError()); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
681 |
} else { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
682 |
dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
683 |
entry = __MKSTRING( uD.data.cFileName ); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
684 |
ok = true; |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
685 |
} |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
686 |
} |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
687 |
} |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
688 |
else if (__isUnicode16String(path)) { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
689 |
int l = __unicode16StringSize(path); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
690 |
int i; |
6259
164d7efc1eb2
api call stuff (more calls wrapped; care for EINTR)
Claus Gittinger <cg@exept.de>
parents:
5245
diff
changeset
|
691 |
|
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
692 |
if (l < (MAXPATHLEN-4)) { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
693 |
for (i=0; i<l; i++) { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
694 |
uP.wpattern[i] = __unicode16StringVal(path)[i]; |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
695 |
} |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
696 |
uP.wpattern[i++] = '\\'; |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
697 |
uP.wpattern[i++] = '*'; |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
698 |
uP.wpattern[i] = 0; |
11294 | 699 |
|
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
700 |
do { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
701 |
__threadErrno = 0; |
12713
98b31733e9c1
Make most win32 wrap calls non-interruptable
Stefan Vogel <sv@exept.de>
parents:
12655
diff
changeset
|
702 |
d = STX_API_NOINT_CALL2( "FindFirstFileW", FindFirstFileW, uP.wpattern, &uD.wdata ); |
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
703 |
} while ((d < 0) && (__threadErrno == EINTR)); |
11294 | 704 |
|
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
705 |
if (d == INVALID_HANDLE_VALUE) { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
706 |
__INST(lastErrorNumber) = __mkSmallInteger(GetLastError()); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
707 |
} else { |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
708 |
dp = __MKEXTERNALADDRESS(d); __INST(dirPointer) = dp; __STORE(self, dp); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
709 |
entry = __MKU16STRING( uD.wdata.cFileName ); |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
710 |
ok = true; |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
711 |
} |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
712 |
} |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
713 |
} |
1631 | 714 |
} |
715 |
# endif |
|
1 | 716 |
#endif |
155 | 717 |
%}. |
718 |
ok isNil ifTrue:[ |
|
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
719 |
" |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
720 |
opendir not avalable - use slower pipe |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
721 |
" |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
722 |
^ PipeStream readingFrom:('cd ' , pathName , '; ls -a') |
1 | 723 |
]. |
155 | 724 |
|
725 |
(ok == true) ifTrue:[ |
|
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
726 |
Lobby register:self. |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
727 |
entry isNil ifTrue:[ |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
728 |
self nextLine. "read 1st entry into readAheadEntry buffer" |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
729 |
] ifFalse:[ |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
730 |
readAheadEntry := entry. |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
731 |
]. |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
732 |
^ self |
1 | 733 |
]. |
4526
a42dc8e09586
errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents:
4298
diff
changeset
|
734 |
dirPointer notNil ifTrue:[^ self errorAlreadyOpen]. |
155 | 735 |
lastErrorNumber notNil ifTrue:[^ self openError]. |
1 | 736 |
^ nil |
737 |
! |
|
738 |
||
739 |
reOpen |
|
8604 | 740 |
"USERS WILL NEVER INVOKE THIS METHOD |
741 |
sent after snapin to reopen streams." |
|
38 | 742 |
|
2 | 743 |
dirPointer := nil. |
744 |
super reOpen |
|
1 | 745 |
! ! |
746 |
||
747 |
!DirectoryStream methodsFor:'testing'! |
|
748 |
||
749 |
atEnd |
|
750 |
"return true, if position is at end" |
|
751 |
||
1664 | 752 |
^ readAheadEntry == nil |
2945
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
753 |
! |
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
754 |
|
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
755 |
isEmpty |
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
756 |
"test for if the unread portion of the directory stream is empty. |
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
757 |
This query changes the readPointer of the DirectoryStream" |
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
758 |
|
2957 | 759 |
|entry| |
2945
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
760 |
|
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
761 |
[self atEnd] whileFalse:[ |
3816
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
762 |
entry := self nextLine. |
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
763 |
entry asFilename isImplicit ifFalse:[ |
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
764 |
^ false. |
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
765 |
] |
2945
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
766 |
]. |
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
767 |
^ true |
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
768 |
|
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
769 |
|
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
770 |
" |
3816
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
771 |
(DirectoryStream directoryNamed:'/') isEmpty |
af3f917c7759
use wrapCalls for FindFirstFile & FindNextFile (win32 - dir-reading)
Claus Gittinger <cg@exept.de>
parents:
3164
diff
changeset
|
772 |
(DirectoryStream directoryNamed:'/var/tmp') isEmpty |
2945
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
773 |
" |
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
774 |
|
1a4f2e0d9f1b
Add #isEmpty, to check for an empty directory.
Stefan Vogel <sv@exept.de>
parents:
2896
diff
changeset
|
775 |
"Modified: 18.9.1997 / 18:05:31 / stefan" |
1 | 776 |
! ! |
777 |
||
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
778 |
!DirectoryStream class methodsFor:'documentation'! |
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
779 |
|
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
780 |
version |
12714 | 781 |
^ '$Header: /cvs/stx/stx/libbasic/DirectoryStream.st,v 1.73 2010-02-09 18:13:24 stefan Exp $' |
12468
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
782 |
! |
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
783 |
|
cc062d075d2a
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
12414
diff
changeset
|
784 |
version_CVS |
12714 | 785 |
^ '$Header: /cvs/stx/stx/libbasic/DirectoryStream.st,v 1.73 2010-02-09 18:13:24 stefan Exp $' |
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
786 |
! ! |