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