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