author | Claus Gittinger <cg@exept.de> |
Sat, 11 Jan 1997 13:14:19 +0100 | |
changeset 2145 | d243ffafeae3 |
parent 1989 | 92b10a0e8a51 |
child 2609 | 68abf045b637 |
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 |
" |
|
12 |
||
13 |
FileStream subclass:#DirectoryStream |
|
1664 | 14 |
instanceVariableNames:'dirPointer readAheadEntry' |
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
15 |
classVariableNames:'' |
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
16 |
poolDictionaries:'' |
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
17 |
category:'Streams-External' |
1 | 18 |
! |
19 |
||
217 | 20 |
!DirectoryStream primitiveDefinitions! |
1 | 21 |
%{ |
437 | 22 |
|
1631 | 23 |
#define UNIX_LIKE |
24 |
#if defined(WIN32) |
|
25 |
# undef UNIX_LIKE |
|
26 |
#endif |
|
437 | 27 |
|
1631 | 28 |
#ifdef UNIX_LIKE |
29 |
||
30 |
# include <stdio.h> |
|
31 |
# define _STDIO_H_INCLUDED_ |
|
32 |
||
33 |
# include <errno.h> |
|
34 |
# define _ERRNO_H_INCLUDED_ |
|
10 | 35 |
|
1631 | 36 |
# ifndef transputer |
1 | 37 |
# include <sys/types.h> |
1631 | 38 |
# include <sys/stat.h> |
39 |
||
40 |
# ifdef HAS_OPENDIR |
|
41 |
# include <sys/types.h> |
|
42 |
# ifdef NEXT |
|
43 |
# include <sys/dir.h> |
|
44 |
# else |
|
45 |
# ifndef VMS |
|
46 |
# include <dirent.h> |
|
47 |
# endif /* not VMS */ |
|
48 |
# endif |
|
1 | 49 |
# endif |
50 |
# endif |
|
223 | 51 |
|
52 |
/* |
|
53 |
* on some systems errno is a macro ... check for it here |
|
54 |
*/ |
|
1631 | 55 |
# ifndef errno |
56 |
extern errno; |
|
57 |
# endif |
|
58 |
#endif /* UNIX_LIKE */ |
|
59 |
||
60 |
#ifdef WIN32 |
|
61 |
||
62 |
# ifdef i386 |
|
63 |
# define _X86_ |
|
64 |
# endif |
|
65 |
||
66 |
# undef INT |
|
67 |
# undef Array |
|
68 |
# undef Number |
|
69 |
# undef Method |
|
70 |
# undef Point |
|
71 |
# undef Context |
|
72 |
# undef Rectangle |
|
1989 | 73 |
# undef Block |
1631 | 74 |
|
1989 | 75 |
# include <types.h> /* */ |
76 |
# include <stdarg.h> /* */ |
|
77 |
# include <windef.h> /* */ |
|
78 |
# include <winbase.h> /* */ |
|
79 |
# include <wingdi.h> /* */ |
|
80 |
# include <winuser.h> /* */ |
|
1631 | 81 |
|
82 |
# ifdef __DEF_Array |
|
83 |
# define Array __DEF_Array |
|
84 |
# endif |
|
85 |
# ifdef __DEF_Number |
|
86 |
# define Number __DEF_Number |
|
87 |
# endif |
|
88 |
# ifdef __DEF_Method |
|
89 |
# define Method __DEF_Method |
|
90 |
# endif |
|
91 |
# ifdef __DEF_Point |
|
92 |
# define Point __DEF_Point |
|
93 |
# endif |
|
1989 | 94 |
# ifdef __DEF_Block |
95 |
# define Block __DEF_Block |
|
96 |
# endif |
|
1631 | 97 |
# ifdef __DEF_Context |
98 |
# define Context __DEF_Context |
|
99 |
# endif |
|
100 |
||
101 |
# define __HANDLEVal(o) (HANDLE)__MKCP(o) |
|
102 |
||
103 |
#endif /* WIN32 */ |
|
223 | 104 |
|
1 | 105 |
%} |
206 | 106 |
! ! |
1 | 107 |
|
438 | 108 |
!DirectoryStream primitiveFunctions! |
109 |
%{ |
|
110 |
#ifdef VMS |
|
111 |
||
112 |
/* |
|
113 |
** VMS readdir() routines. |
|
114 |
** Written by Rich $alz, <rsalz@bbn.com> in August, 1990. |
|
115 |
** This code has no copyright. |
|
116 |
*/ |
|
117 |
||
118 |
/* 12-NOV-1990 added d_namlen field and special case "." name -GJC@MITECH.COM |
|
119 |
*/ |
|
120 |
||
121 |
#ifndef _STDIO_H_INCLUDED_ |
|
122 |
# include <stdio.h> |
|
123 |
# define _STDIO_H_INCLUDED_ |
|
124 |
#endif |
|
125 |
||
126 |
#ifndef _CTYPE_H_INCLUDED_ |
|
127 |
# include <ctype.h> |
|
128 |
# define _CTYPE_H_INCLUDED_ |
|
129 |
#endif |
|
130 |
||
131 |
#ifndef _ERRNO_H_INCLUDED_ |
|
132 |
# include <errno.h> |
|
133 |
# define _ERRNO_H_INCLUDED_ |
|
134 |
#endif |
|
135 |
||
136 |
#ifndef _DESCRIP_H_INCLUDED_ |
|
137 |
# include <descrip.h> |
|
138 |
# define _DESCRIP_H_INCLUDED_ |
|
139 |
#endif |
|
140 |
||
141 |
#ifndef _RMSDEF_H_INCLUDED_ |
|
142 |
# include <rmsdef.h> |
|
143 |
# define _RMSDEF_H_INCLUDED_ |
|
144 |
#endif |
|
145 |
||
146 |
/* |
|
147 |
* actually, the following has to go into dirent.h ... |
|
148 |
*/ |
|
149 |
/* BEGIN dirent.h |
|
150 |
* |
|
151 |
** Header file for VMS readdir() routines. |
|
152 |
** Written by Rich $alz, <rsalz@bbn.com> in August, 1990. |
|
153 |
** This code has no copyright. |
|
154 |
** |
|
155 |
** You must #include <descrip.h> before this file. |
|
156 |
*/ |
|
157 |
||
158 |
/* 12-NOV-1990 added d_namlen field -GJC@MITECH.COM */ |
|
159 |
||
160 |
/* Data structure returned by READDIR(). */ |
|
161 |
struct dirent { |
|
162 |
char d_name[100]; /* File name */ |
|
163 |
int d_namlen; |
|
164 |
int vms_verscount; /* Number of versions */ |
|
165 |
int vms_versions[20]; /* Version numbers */ |
|
166 |
}; |
|
167 |
||
168 |
/* Handle returned by opendir(), used by the other routines. You |
|
169 |
* are not supposed to care what's inside this structure. */ |
|
170 |
typedef struct _dirdesc { |
|
171 |
long context; |
|
172 |
int vms_wantversions; |
|
173 |
char *pattern; |
|
174 |
struct dirent entry; |
|
175 |
struct dsc$descriptor_s pat; |
|
176 |
} DIR; |
|
177 |
||
178 |
||
179 |
#define rewinddir(dirp) seekdir((dirp), 0L) |
|
180 |
||
181 |
||
182 |
extern DIR *opendir(); |
|
183 |
extern struct dirent *readdir(); |
|
184 |
extern long telldir(); |
|
185 |
extern void seekdir(); |
|
186 |
extern void closedir(); |
|
187 |
extern void vmsreaddirversions(); |
|
188 |
#define _DIRENT_H_INCLUDED_ |
|
189 |
/* |
|
190 |
* END dirent.h |
|
191 |
*/ |
|
192 |
||
193 |
||
194 |
/* Number of elements in vms_versions array */ |
|
195 |
#define VERSIZE(e) (sizeof e->vms_versions / sizeof e->vms_versions[0]) |
|
196 |
||
197 |
/* Linked in later. */ |
|
198 |
extern char *strrchr(); |
|
199 |
extern char *strcpy(); |
|
200 |
/* Don't need this when all these programs are lumped together. RLD |
|
201 |
extern char *malloc(); |
|
202 |
*/ |
|
203 |
||
204 |
/* |
|
205 |
** Open a directory, return a handle for later use. |
|
206 |
*/ |
|
207 |
DIR * |
|
208 |
opendir(name) |
|
209 |
char *name; |
|
210 |
{ |
|
211 |
DIR *dd; |
|
212 |
||
213 |
/* Get memory for the handle, and the pattern. */ |
|
214 |
if ((dd = (DIR *)malloc(sizeof *dd)) == NULL) { |
|
215 |
errno = ENOMEM; |
|
216 |
return NULL; |
|
217 |
} |
|
218 |
||
219 |
if (strcmp(".",name) == 0) name = ""; |
|
220 |
||
221 |
dd->pattern = malloc((unsigned int)(strlen(name) + sizeof "*.*" + 1)); |
|
222 |
if (dd->pattern == NULL) { |
|
223 |
free((char *)dd); |
|
224 |
errno = ENOMEM; |
|
225 |
return NULL; |
|
226 |
} |
|
227 |
||
228 |
/* Fill in the fields; mainly playing with the descriptor. */ |
|
229 |
(void)sprintf(dd->pattern, "%s*.*", name); |
|
230 |
dd->context = 0; |
|
231 |
dd->vms_wantversions = 0; |
|
232 |
dd->pat.dsc$a_pointer = dd->pattern; |
|
233 |
dd->pat.dsc$w_length = strlen(dd->pattern); |
|
234 |
dd->pat.dsc$b_dtype = DSC$K_DTYPE_T; |
|
235 |
dd->pat.dsc$b_class = DSC$K_CLASS_S; |
|
236 |
||
237 |
return dd; |
|
238 |
} |
|
239 |
||
240 |
/* |
|
241 |
** Set the flag to indicate we want versions or not. |
|
242 |
*/ |
|
243 |
void |
|
244 |
vmsreaddirversions(dd, flag) |
|
245 |
DIR *dd; |
|
246 |
int flag; |
|
247 |
{ |
|
248 |
dd->vms_wantversions = flag; |
|
249 |
} |
|
250 |
||
251 |
/* |
|
252 |
** Free up an opened directory. |
|
253 |
*/ |
|
254 |
void |
|
255 |
closedir(dd) |
|
256 |
DIR *dd; |
|
257 |
{ |
|
258 |
free(dd->pattern); |
|
259 |
free((char *)dd); |
|
260 |
} |
|
261 |
||
262 |
/* |
|
263 |
** Collect all the version numbers for the current file. |
|
264 |
*/ |
|
265 |
static void |
|
266 |
collectversions(dd) |
|
267 |
DIR *dd; |
|
268 |
{ |
|
269 |
struct dsc$descriptor_s pat; |
|
270 |
struct dsc$descriptor_s res; |
|
271 |
struct dirent *e; |
|
272 |
char *p; |
|
273 |
char buff[sizeof dd->entry.d_name]; |
|
274 |
int i; |
|
275 |
char *text; |
|
276 |
long context; |
|
277 |
||
278 |
/* Convenient shorthand. */ |
|
279 |
e = &dd->entry; |
|
280 |
||
281 |
/* Add the version wildcard, ignoring the "*.*" put on before */ |
|
282 |
i = strlen(dd->pattern); |
|
283 |
text = malloc((unsigned int)(i + strlen(e->d_name)+ 2 + 1)); |
|
284 |
if (text == NULL) |
|
285 |
return; |
|
286 |
(void)strcpy(text, dd->pattern); |
|
287 |
(void)sprintf(&text[i - 3], "%s;*", e->d_name); |
|
288 |
||
289 |
/* Set up the pattern descriptor. */ |
|
290 |
pat.dsc$a_pointer = text; |
|
291 |
pat.dsc$w_length = strlen(text); |
|
292 |
pat.dsc$b_dtype = DSC$K_DTYPE_T; |
|
293 |
pat.dsc$b_class = DSC$K_CLASS_S; |
|
294 |
||
295 |
/* Set up result descriptor. */ |
|
296 |
res.dsc$a_pointer = buff; |
|
297 |
res.dsc$w_length = sizeof buff - 2; |
|
298 |
res.dsc$b_dtype = DSC$K_DTYPE_T; |
|
299 |
res.dsc$b_class = DSC$K_CLASS_S; |
|
300 |
||
301 |
/* Read files, collecting versions. */ |
|
302 |
for (context = 0; e->vms_verscount < VERSIZE(e); e->vms_verscount++) { |
|
303 |
if (lib$find_file(&pat, &res, &context) == RMS$_NMF || context == 0) |
|
304 |
break; |
|
305 |
buff[sizeof buff - 1] = '\0'; |
|
306 |
if (p = strchr(buff, ';')) |
|
307 |
e->vms_versions[e->vms_verscount] = atoi(p + 1); |
|
308 |
else |
|
309 |
e->vms_versions[e->vms_verscount] = -1; |
|
310 |
} |
|
311 |
||
312 |
free(text); |
|
313 |
} |
|
314 |
||
315 |
/* |
|
316 |
** Read the next entry from the directory. |
|
317 |
*/ |
|
318 |
struct dirent * |
|
319 |
readdir(dd) |
|
320 |
DIR *dd; |
|
321 |
{ |
|
322 |
struct dsc$descriptor_s res; |
|
323 |
char *p; |
|
324 |
char buff[sizeof dd->entry.d_name]; |
|
325 |
int i; |
|
326 |
||
327 |
/* Set up result descriptor, and get next file. */ |
|
328 |
res.dsc$a_pointer = buff; |
|
329 |
res.dsc$w_length = sizeof buff - 2; |
|
330 |
res.dsc$b_dtype = DSC$K_DTYPE_T; |
|
331 |
res.dsc$b_class = DSC$K_CLASS_S; |
|
332 |
if (lib$find_file(&dd->pat, &res, &dd->context) == RMS$_NMF |
|
333 |
|| dd->context == 0L) |
|
334 |
/* None left... */ |
|
335 |
return NULL; |
|
336 |
||
337 |
/* Force the buffer to end with a NUL. */ |
|
338 |
buff[sizeof buff - 1] = '\0'; |
|
339 |
for (p = buff; !isspace(*p); p++) |
|
340 |
; |
|
341 |
*p = '\0'; |
|
342 |
||
343 |
/* Skip any directory component and just copy the name. */ |
|
344 |
if (p = strchr(buff, ']')) |
|
345 |
(void)strcpy(dd->entry.d_name, p + 1); |
|
346 |
else |
|
347 |
(void)strcpy(dd->entry.d_name, buff); |
|
348 |
||
349 |
/* Clobber the version. */ |
|
350 |
if (p = strchr(dd->entry.d_name, ';')) |
|
351 |
*p = '\0'; |
|
352 |
||
353 |
dd->entry.d_namlen = strlen(dd->entry.d_name); |
|
354 |
||
355 |
dd->entry.vms_verscount = 0; |
|
356 |
if (dd->vms_wantversions) |
|
357 |
collectversions(dd); |
|
358 |
return &dd->entry; |
|
359 |
} |
|
360 |
||
361 |
/* |
|
362 |
** Return something that can be used in a seekdir later. |
|
363 |
*/ |
|
364 |
long |
|
365 |
telldir(dd) |
|
366 |
DIR *dd; |
|
367 |
{ |
|
368 |
return dd->context; |
|
369 |
} |
|
370 |
||
371 |
/* |
|
372 |
** Return to a spot where we used to be. |
|
373 |
*/ |
|
374 |
void |
|
375 |
seekdir(dd, pos) |
|
376 |
DIR *dd; |
|
377 |
long pos; |
|
378 |
{ |
|
379 |
dd->context = pos; |
|
380 |
} |
|
381 |
||
382 |
#endif /* VMS */ |
|
383 |
%} |
|
384 |
! ! |
|
385 |
||
613 | 386 |
!DirectoryStream class methodsFor:'documentation'! |
387 |
||
388 |
copyright |
|
389 |
" |
|
390 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
391 |
All Rights Reserved |
|
1 | 392 |
|
613 | 393 |
This software is furnished under a license and may be used |
394 |
only in accordance with the terms of that license and with the |
|
395 |
inclusion of the above copyright notice. This software may not |
|
396 |
be provided or otherwise made available to, or used by, any |
|
397 |
other person. No title to or ownership of the software is |
|
398 |
hereby transferred. |
|
399 |
" |
|
400 |
! |
|
360 | 401 |
|
613 | 402 |
documentation |
403 |
" |
|
404 |
Instances of DirectoryStream allow reading a file-directory, |
|
405 |
as if it was a stream of filenames. |
|
406 |
Basically, its an interface to opendir, readdir and closedir. |
|
1295 | 407 |
|
408 |
[author:] |
|
1631 | 409 |
Claus Gittinger |
613 | 410 |
" |
1 | 411 |
! ! |
412 |
||
413 |
!DirectoryStream class methodsFor:'instance creation'! |
|
414 |
||
415 |
directoryNamed:dirName |
|
416 |
"return a DirectoryStream for directory named dirName, aString" |
|
417 |
||
418 |
|newStream| |
|
419 |
||
420 |
newStream := (self basicNew) pathName:dirName. |
|
421 |
newStream openForReading isNil ifTrue:[^nil]. |
|
422 |
^ newStream |
|
423 |
! ! |
|
424 |
||
425 |
!DirectoryStream methodsFor:'access reading'! |
|
426 |
||
427 |
nextLine |
|
428 |
"return the next filename as a string" |
|
429 |
||
430 |
|prevEntry nextEntry| |
|
431 |
%{ |
|
77 | 432 |
#ifdef HAS_OPENDIR |
1 | 433 |
DIR *d; |
1631 | 434 |
# ifdef NEXT |
1 | 435 |
struct direct *dp; |
1631 | 436 |
# else |
1 | 437 |
struct dirent *dp; |
1631 | 438 |
# endif |
92 | 439 |
OBJ dirP; |
1 | 440 |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
441 |
if (__INST(hitEOF) != true && (dirP = __INST(dirPointer)) != nil) { |
1631 | 442 |
__INST(lastErrorNumber) = nil; |
443 |
d = (DIR *)__FILEVal(dirP); |
|
92 | 444 |
|
1631 | 445 |
__BEGIN_INTERRUPTABLE__ |
446 |
do { |
|
447 |
errno = 0; |
|
448 |
dp = readdir(d); |
|
449 |
} while ((dp == NULL) && (errno == EINTR)); |
|
450 |
__END_INTERRUPTABLE__ |
|
92 | 451 |
|
1631 | 452 |
if (dp != NULL) { |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1664
diff
changeset
|
453 |
nextEntry = __MKSTRING((char *)(dp->d_name)); |
1631 | 454 |
} else { |
455 |
if (errno) { |
|
456 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
457 |
} else { |
|
458 |
__INST(hitEOF) = true; |
|
459 |
} |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
460 |
} |
1 | 461 |
} |
1631 | 462 |
#else /* no HAS_OPENDIR */ |
463 |
# ifdef WIN32 |
|
464 |
HANDLE d; |
|
465 |
WIN32_FIND_DATA data; |
|
466 |
OBJ dirP; |
|
467 |
||
468 |
if (__INST(hitEOF) != true && (dirP = __INST(dirPointer)) != nil) { |
|
469 |
__INST(lastErrorNumber) = nil; |
|
470 |
d = __HANDLEVal(dirP); |
|
471 |
||
472 |
if (FindNextFile(d, &data)) { |
|
473 |
nextEntry = __MKSTRING( data.cFileName ); |
|
474 |
} else { |
|
475 |
__INST(hitEOF) = true; |
|
476 |
} |
|
477 |
} |
|
478 |
# endif /* WIN32 */ |
|
479 |
#endif /* HAS_OPENDIR */ |
|
155 | 480 |
%}. |
481 |
lastErrorNumber notNil ifTrue:[^ self ioError]. |
|
1664 | 482 |
prevEntry := readAheadEntry. |
483 |
readAheadEntry := nextEntry. |
|
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
484 |
prevEntry isNil ifTrue:[^ self pastEnd]. |
1 | 485 |
^ prevEntry |
486 |
! ! |
|
487 |
||
613 | 488 |
!DirectoryStream methodsFor:'closing'! |
489 |
||
490 |
close |
|
491 |
"close the stream - tell operating system" |
|
492 |
||
493 |
dirPointer notNil ifTrue:[ |
|
494 |
Lobby unregister:self. |
|
495 |
self closeFile. |
|
496 |
dirPointer := nil |
|
497 |
] |
|
498 |
! ! |
|
499 |
||
500 |
!DirectoryStream methodsFor:'instance release'! |
|
501 |
||
502 |
closeFile |
|
503 |
"low level close of a directoryStream" |
|
504 |
%{ |
|
505 |
#ifdef HAS_OPENDIR |
|
506 |
OBJ dp; |
|
507 |
||
1133 | 508 |
if ((dp = __INST(dirPointer)) != nil) { |
509 |
__INST(dirPointer) = nil; |
|
613 | 510 |
closedir( (DIR *)(__FILEVal(dp)) ); |
511 |
} |
|
1631 | 512 |
#else |
513 |
# ifdef WIN32 |
|
514 |
OBJ dp; |
|
515 |
||
516 |
if ((dp = __INST(dirPointer)) != nil) { |
|
517 |
__INST(dirPointer) = nil; |
|
518 |
FindClose( __HANDLEVal(dp) ); |
|
519 |
} |
|
520 |
# endif |
|
613 | 521 |
#endif |
522 |
%} |
|
523 |
! ! |
|
524 |
||
1 | 525 |
!DirectoryStream methodsFor:'private'! |
526 |
||
527 |
openForReading |
|
528 |
"open the file for readonly" |
|
529 |
||
1631 | 530 |
|ok entry| |
1 | 531 |
|
532 |
mode := #readonly. |
|
533 |
%{ |
|
77 | 534 |
#ifdef HAS_OPENDIR |
1 | 535 |
DIR *d; |
477
8710aba7876b
oops - making id's real objects requires a store macro
Claus Gittinger <cg@exept.de>
parents:
475
diff
changeset
|
536 |
OBJ path, dp; |
1 | 537 |
|
155 | 538 |
ok = false; |
1133 | 539 |
if (__INST(dirPointer) == nil) { |
540 |
path = __INST(pathName); |
|
155 | 541 |
if (__isString(path)) { |
362 | 542 |
__BEGIN_INTERRUPTABLE__ |
92 | 543 |
errno = 0; |
155 | 544 |
do { |
1133 | 545 |
d = opendir((char *) __stringVal(path)); |
155 | 546 |
} while ((d == NULL) && (errno == EINTR)); |
362 | 547 |
__END_INTERRUPTABLE__ |
92 | 548 |
|
155 | 549 |
if (d == NULL) { |
1133 | 550 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
155 | 551 |
} else { |
1133 | 552 |
__INST(dirPointer) = dp = __MKOBJ(d); __STORE(self, dp); |
155 | 553 |
ok = true; |
554 |
} |
|
555 |
} |
|
1 | 556 |
} |
1631 | 557 |
#else |
558 |
# ifdef WIN32 |
|
559 |
HANDLE d; |
|
560 |
OBJ path, dp; |
|
561 |
char pattern[512]; |
|
562 |
WIN32_FIND_DATA data; |
|
563 |
||
564 |
ok = false; |
|
565 |
if (__INST(dirPointer) == nil) { |
|
566 |
path = __INST(pathName); |
|
567 |
if (__isString(path)) { |
|
568 |
strcpy(pattern, __stringVal(path)); |
|
569 |
strcat(pattern, "\\*"); |
|
570 |
d = FindFirstFile(pattern, &data); |
|
571 |
if (d == INVALID_HANDLE_VALUE) { |
|
572 |
__INST(lastErrorNumber) = __MKSMALLINT(GetLastError()); |
|
573 |
} else { |
|
574 |
__INST(dirPointer) = dp = __MKOBJ(d); __STORE(self, dp); |
|
575 |
entry = __MKSTRING( data.cFileName ); |
|
576 |
ok = true; |
|
577 |
} |
|
578 |
} |
|
579 |
} |
|
580 |
# endif |
|
1 | 581 |
#endif |
155 | 582 |
%}. |
583 |
ok isNil ifTrue:[ |
|
584 |
" |
|
585 |
opendir not avalable - use slower pipe |
|
586 |
" |
|
587 |
^ PipeStream readingFrom:('cd ' , pathName , '; ls -a') |
|
1 | 588 |
]. |
155 | 589 |
|
590 |
(ok == true) ifTrue:[ |
|
591 |
Lobby register:self. |
|
1631 | 592 |
entry isNil ifTrue:[ |
1664 | 593 |
self nextLine. "read 1st entry into readAheadEntry buffer" |
1631 | 594 |
] ifFalse:[ |
1664 | 595 |
readAheadEntry := entry. |
1631 | 596 |
]. |
155 | 597 |
^ self |
1 | 598 |
]. |
155 | 599 |
dirPointer notNil ifTrue:[^ self errorOpen]. |
600 |
lastErrorNumber notNil ifTrue:[^ self openError]. |
|
1 | 601 |
^ nil |
602 |
! |
|
603 |
||
604 |
reOpen |
|
38 | 605 |
"reOpen the stream after image restart" |
606 |
||
2 | 607 |
dirPointer := nil. |
608 |
super reOpen |
|
1 | 609 |
! ! |
610 |
||
611 |
!DirectoryStream methodsFor:'testing'! |
|
612 |
||
613 |
atEnd |
|
614 |
"return true, if position is at end" |
|
615 |
||
1664 | 616 |
^ readAheadEntry == nil |
1 | 617 |
! ! |
618 |
||
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
619 |
!DirectoryStream class methodsFor:'documentation'! |
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
620 |
|
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
621 |
version |
1989 | 622 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/DirStr.st,v 1.34 1996-11-21 18:33:16 cg Exp $' |
1281
b4b3abffdf32
Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
623 |
! ! |