ExternalStream.st
author Claus Gittinger <cg@exept.de>
Wed, 04 Aug 1999 16:13:11 +0200
changeset 4526 a42dc8e09586
parent 4468 8c67b4f973d8
child 4597 9628a80e23ec
permissions -rw-r--r--
errorOpen renamed to errorAlreadyOpen
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) 1988 by Claus Gittinger
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
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
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
ReadWriteStream subclass:#ExternalStream
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
    14
	instanceVariableNames:'filePointer mode buffered binary eolMode hitEOF didWrite
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    15
		lastErrorNumber readAhead'
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    16
	classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    17
		InvalidModeSignal OpenErrorSignal StreamNotOpenSignal
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
    18
		InvalidOperationSignal DefaultEOLMode ReadMode ReadWriteMode
3474
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
    19
		WriteMode AppendMode CreateReadWriteMode StreamIOErrorSignal'
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    20
	poolDictionaries:''
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    21
	category:'Streams-External'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    24
!ExternalStream primitiveDefinitions!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    25
%{
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
    26
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    27
#include <stdio.h>
437
claus
parents: 436
diff changeset
    28
#define _STDIO_H_INCLUDED_
claus
parents: 436
diff changeset
    29
3956
51f1a9a4d63f changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents: 3949
diff changeset
    30
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    31
#ifndef NO_FCNTL_H
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    32
# include <fcntl.h>
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    33
# define _FCNTL_H_INCLUDED_
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    34
#endif
437
claus
parents: 436
diff changeset
    35
10
claus
parents: 5
diff changeset
    36
#include <errno.h>
437
claus
parents: 436
diff changeset
    37
#define _ERRNO_H_INCLUDED_
42
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    38
1141
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    39
#ifdef LINUX
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    40
  /* use inline string macros */
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    41
# define __STRINGDEFS__
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    42
# include <linuxIntern.h>
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    43
#endif
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    44
42
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    45
#ifdef hpux
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    46
# define fileno(f)      ((f->__fileH << 8) | (f->__fileL))
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    47
#endif
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    48
933
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    49
#ifndef SEEK_SET
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    50
# define SEEK_SET 0
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    51
#endif
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    52
#ifndef SEEK_CUR
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    53
# define SEEK_CUR 1
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    54
#endif
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    55
#ifndef SEEK_END
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    56
# define SEEK_END 2
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    57
#endif
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    58
4093
1821420b41d4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4092
diff changeset
    59
#if defined(__VMS__) || defined(sparc)
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
    60
# define CLEAR_ERRNO            errno = 0;
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    61
#else
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
    62
# define CLEAR_ERRNO            /* nothing */
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    63
#endif
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    64
3420
4dc6667afda9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3419
diff changeset
    65
#ifdef LATER
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
    66
#define __isFilePointer(x)      (__Class(x) == ExternalStream__FilePointer)
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
    67
#define __CHANGECLASS(o, x)     (__qClass(o) = (x), o)
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
    68
#define __MKFILEPOINTER(f)      __CHANGECLASS(__MKEXTERNALADDRESS(f), ExternalStream__FilePointer)
3420
4dc6667afda9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3419
diff changeset
    69
#else
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
    70
#define __MKFILEPOINTER(f)      __MKEXTERNALADDRESS(f)
3420
4dc6667afda9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3419
diff changeset
    71
#endif
4dc6667afda9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3419
diff changeset
    72
4092
fee552eb3418 removed win32 stuff
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
    73
#define STDIO_NEEDS_FSEEK
fee552eb3418 removed win32 stuff
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
    74
#define FILEPOINTER            FILE *
fee552eb3418 removed win32 stuff
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
    75
#define READ(f, cp, n)         read(f, cp, n)
fee552eb3418 removed win32 stuff
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
    76
#define WRITE(f, cp, n)        write(f, cp, n)
fee552eb3418 removed win32 stuff
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
    77
#define FFLUSH(fp)             fflush(fp)
fee552eb3418 removed win32 stuff
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
    78
#define FILENO(f)              fileno(f)
3681
55dc17d40aab fixed nextAvail
Claus Gittinger <cg@exept.de>
parents: 3674
diff changeset
    79
3682
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
    80
#ifdef DEBUGGING
4092
fee552eb3418 removed win32 stuff
Claus Gittinger <cg@exept.de>
parents: 3980
diff changeset
    81
  extern char *__survStartPtr, *__survEndPtr;
3682
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
    82
# define DEBUGBUFFER(buf)  \
3681
55dc17d40aab fixed nextAvail
Claus Gittinger <cg@exept.de>
parents: 3674
diff changeset
    83
    if (((char *)(buf) >= __survStartPtr) \
55dc17d40aab fixed nextAvail
Claus Gittinger <cg@exept.de>
parents: 3674
diff changeset
    84
     && ((char *)(buf) < __survEndPtr)) { \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
    85
	__fatal0("read into survivor\n"); \
3681
55dc17d40aab fixed nextAvail
Claus Gittinger <cg@exept.de>
parents: 3674
diff changeset
    86
    }
55dc17d40aab fixed nextAvail
Claus Gittinger <cg@exept.de>
parents: 3674
diff changeset
    87
3682
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
    88
#else
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
    89
# define DEBUGBUFFER(buf) /* nothing */
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
    90
#endif
Claus Gittinger <cg@exept.de>
parents: 3681
diff changeset
    91
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    92
/*
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    93
 * stdio library requires an fseek before reading whenever a file
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    94
 * is open for read/write and the last operation was a write.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    95
 * (also vice-versa).
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    96
 * All code should use the following macro before doing reads:
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    97
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    98
#ifdef STDIO_NEEDS_FSEEK
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
    99
# define OPT_FSEEK(f, pos, whence)      fseek(f, pos, whence)
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   100
#else
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   101
# define OPT_FSEEK(f, pos, whence)      /* nothing */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   102
#endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   103
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   104
#define __READING__(f)                          \
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   105
    if ((__INST(didWrite) != false)              \
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   106
     && (__INST(mode) == @symbol(readwrite))) {  \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   107
	__INST(didWrite) = false;                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   108
	OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   109
    }
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   110
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   111
#define __WRITING__(f)                          \
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   112
    if ((__INST(didWrite) != true)               \
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   113
     && (__INST(mode) == @symbol(readwrite))) {  \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   114
	__INST(didWrite) = true;                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   115
	OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   116
    }
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   117
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   118
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   119
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   120
#define __UNGETC__(c, f, isBuffered)                    \
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   121
    __INST(readAhead) = __MKSMALLINT((c));
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   122
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   123
#define __UNGETC__(c, f, isBuffered)                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   124
    if (isBuffered) {                                   \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   125
	ungetc((c), (f));                               \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   126
    } else {                                            \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   127
	__INST(readAhead) = __MKSMALLINT((c));          \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   128
    }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   129
#endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   130
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   131
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   132
#define __READBYTE__(ret, f, buf, isBuffered)           \
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   133
    {                                                   \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   134
	OBJ rA = __INST(readAhead);                     \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   135
	if (rA != nil) {                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   136
	    *(buf) = __intVal(rA);                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   137
	    DEBUGBUFFER(buf);                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   138
	    __INST(readAhead) = nil;                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   139
	    (ret) = 1;                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   140
	} else {                                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   141
	    for (;;) {                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   142
		CLEAR_ERRNO;                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   143
		(ret) = READ(f, buf, 1);                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   144
		DEBUGBUFFER(buf);                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   145
		if ((ret) >= 0 || errno != EINTR)       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   146
		    break;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   147
		__HANDLE_INTERRUPTS__;                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   148
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   149
	}                                               \
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   150
    }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   151
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   152
#define __READBYTE__(ret, f, buf, isBuffered)           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   153
    if (isBuffered) {                                   \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   154
	for (;;) {                                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   155
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   156
	    (ret) = getc(f);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   157
	    if ((ret) >= 0) {                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   158
		DEBUGBUFFER(buf);                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   159
		*(buf) = (ret);                         \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   160
		(ret) = 1;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   161
	    } else if (ferror(f)) {                     \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   162
		if (errno == EINTR) {                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   163
		    __HANDLE_INTERRUPTS__;              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   164
		    clearerr(f);                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   165
		    continue;                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   166
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   167
	    } else                                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   168
		(ret) = 0;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   169
	    break;                                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   170
	}                                               \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   171
    } else {                                            \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   172
	OBJ rA = __INST(readAhead);                     \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   173
	if (rA != nil) {                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   174
	    *(buf) = __intVal(rA);                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   175
	    DEBUGBUFFER(buf);                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   176
	    __INST(readAhead) = nil;                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   177
	    (ret) = 1;                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   178
	} else {                                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   179
	    for (;;) {                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   180
		CLEAR_ERRNO;                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   181
		(ret) = read(fileno(f), buf, 1);        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   182
		DEBUGBUFFER(buf);                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   183
		if ((ret) >= 0 || errno != EINTR)       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   184
		    break;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   185
		__HANDLE_INTERRUPTS__;                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   186
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   187
	}                                               \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   188
   }                                                                          
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   189
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   190
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   191
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   192
 * read_bytes into a c-buffer
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   193
 * (which may NOT move)
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   194
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   195
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   196
#define __READBYTES__(ret, f, buf, cnt, isBuffered)     \
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   197
    {                                                   \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   198
	int __offs = 0;                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   199
							\
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   200
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   201
	    OBJ rA = __INST(readAhead);                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   202
	    if (rA != nil) {                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   203
		(buf)[__offs] = __intVal(rA);           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   204
		DEBUGBUFFER(buf);                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   205
		__INST(readAhead) = nil;                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   206
		(ret) = 1;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   207
	    } else {                                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   208
		CLEAR_ERRNO;                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   209
		(ret) = READ(f, (buf)+__offs, (cnt)-__offs); \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   210
		DEBUGBUFFER(buf);                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   211
		if ((ret) <= 0) {                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   212
		    if ((ret) < 0 && errno == EINTR) {  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   213
			__HANDLE_INTERRUPTS__;          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   214
			continue;                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   215
		    }                                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   216
		    break;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   217
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   218
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   219
	    __offs += (ret);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   220
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   221
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   222
	    (ret) = __offs;                             \
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   223
   }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   224
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   225
#define __READBYTES__(ret, f, buf, cnt, isBuffered)     \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   226
    (ret) = 0;                                          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   227
    if (isBuffered) {                                   \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   228
	int __offs = 0;                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   229
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   230
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   231
	    (ret) = getc(f);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   232
	    if ((ret) < 0) {                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   233
		if (ferror(f)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   234
		    if (errno == EINTR) {               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   235
			__HANDLE_INTERRUPTS__;          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   236
			clearerr(f);                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   237
			continue;                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   238
		    }                                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   239
		} else {                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   240
		    (ret) = 0;                          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   241
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   242
		break;                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   243
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   244
	    DEBUGBUFFER(buf);                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   245
	    (buf)[__offs++] = (ret);                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   246
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   247
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   248
	    (ret) = __offs;                             \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   249
    } else {                                            \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   250
	int __offs = 0;                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   251
	int fd = fileno(f);                             \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   252
							\
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   253
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   254
	    OBJ rA = __INST(readAhead);                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   255
	    if (rA != nil) {                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   256
		DEBUGBUFFER(buf);                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   257
		(buf)[__offs] = __intVal(rA);           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   258
		__INST(readAhead) = nil;                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   259
		(ret) = 1;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   260
	    } else {                                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   261
		CLEAR_ERRNO;                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   262
		(ret) = read(fd, (buf)+__offs, (cnt)-__offs);                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   263
		DEBUGBUFFER(buf);                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   264
		if ((ret) <= 0) {                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   265
		    if ((ret) < 0 && errno == EINTR) {  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   266
			__HANDLE_INTERRUPTS__;          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   267
			continue;                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   268
		    }                                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   269
		    break;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   270
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   271
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   272
	    __offs += (ret);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   273
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   274
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   275
	    (ret) = __offs;                             \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   276
   }
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   277
3554
320cbfef9382 made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   278
#if defined(F_GETFL) && defined(F_SETFL) && defined(FNDELAY)
320cbfef9382 made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   279
# define GETFLAGS(fd) \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   280
	fcntl(fd, F_GETFL, 0);
3554
320cbfef9382 made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   281
320cbfef9382 made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   282
# define SETFLAGS(fd, flags) \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   283
	fcntl(fd, F_SETFL, flags)
3554
320cbfef9382 made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   284
320cbfef9382 made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   285
# define SETNONBLOCKING(fd) \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   286
	{ \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   287
	    int flags; \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   288
	    flags = fcntl(fd, F_GETFL, 0); \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   289
	    if (flags >= 0) { \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   290
		fcntl(fd, F_SETFL, flags | FNDELAY); \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   291
	    } \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   292
	}
3554
320cbfef9382 made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   293
#else
320cbfef9382 made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   294
# define GETFLAGS(fd) 0
320cbfef9382 made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   295
# define SETFLAGS(fd, flags) /* nothing */
320cbfef9382 made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   296
# define SETNONBLOCKING(fd) /* nothing */
320cbfef9382 made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   297
#endif                                                        
320cbfef9382 made nextAvail really unblocking
Claus Gittinger <cg@exept.de>
parents: 3551
diff changeset
   298
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   299
#define __READAVAILBYTES__(ret, f, buf, cnt, isBuffered) \
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   300
  {                                                     \
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   301
    int __offs = 0;                                     \
3681
55dc17d40aab fixed nextAvail
Claus Gittinger <cg@exept.de>
parents: 3674
diff changeset
   302
    int oldFlags;                                       \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   303
							\
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   304
    (ret) = 0;                                          \
3681
55dc17d40aab fixed nextAvail
Claus Gittinger <cg@exept.de>
parents: 3674
diff changeset
   305
    oldFlags = GETFLAGS(fileno(f));                     \
55dc17d40aab fixed nextAvail
Claus Gittinger <cg@exept.de>
parents: 3674
diff changeset
   306
    SETNONBLOCKING(fileno(f));                          \
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   307
    if (isBuffered) {                                   \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   308
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   309
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   310
	    (ret) = getc(f);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   311
	    if ((ret) < 0) {                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   312
		if (ferror(f)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   313
		    if (errno == EINTR) {               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   314
			(ret) = 0;                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   315
			clearerr(f);                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   316
			break;                          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   317
		    }                                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   318
		} else {                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   319
		    (ret) = 0;                          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   320
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   321
		break;                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   322
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   323
	    (buf)[__offs++] = (ret);                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   324
	    DEBUGBUFFER(buf);                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   325
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   326
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   327
	    (ret) = __offs;                             \
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   328
    } else {                                            \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   329
	int fd = fileno(f);                             \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   330
							\
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   331
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   332
	    OBJ rA = __INST(readAhead);                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   333
	    if (rA != nil) {                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   334
		(buf)[__offs] = __intVal(rA);           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   335
		DEBUGBUFFER(buf);                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   336
		__INST(readAhead) = nil;                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   337
		(ret) = 1;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   338
		__offs += (ret);                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   339
		continue;                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   340
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   341
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   342
	    (ret) = read(fd, (buf)+__offs, (cnt)-__offs); \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   343
	    DEBUGBUFFER(buf);                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   344
	    if ((ret) < 0) {                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   345
		if (errno == EINTR) {                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   346
		    (ret) = 0;                          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   347
		    break;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   348
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   349
		break;                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   350
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   351
	    __offs += (ret);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   352
	    break;                                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   353
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   354
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   355
	    (ret) = __offs;                             \
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   356
    }                                                   \
3681
55dc17d40aab fixed nextAvail
Claus Gittinger <cg@exept.de>
parents: 3674
diff changeset
   357
    SETFLAGS(fileno(f), oldFlags);                      \
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   358
  }
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   359
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   360
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   361
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   362
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   363
 * read_bytes into an object
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   364
 * (which may be moved by GC)
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   365
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   366
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   367
#define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)     \
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   368
  {                                                     \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   369
    int __ooffs = obj_offs;                             \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   370
    int __offs = 0;                                     \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   371
    char *buf = (char *)(obj);                          \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   372
							\
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   373
    (ret) = 0;                                          \
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   374
    {                                                   \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   375
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   376
	    OBJ rA = __INST(readAhead);                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   377
	    if (rA != nil) {                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   378
		(buf)[__ooffs+__offs] = __intVal(rA);   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   379
		DEBUGBUFFER(buf);                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   380
		__INST(readAhead) = nil;                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   381
		(ret) = 1;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   382
	    } else {                                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   383
		CLEAR_ERRNO;                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   384
		(ret) = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs); \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   385
		DEBUGBUFFER(buf);                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   386
		if ((ret) <= 0) {                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   387
		    if ((ret) < 0 && errno == EINTR) {  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   388
			__HANDLE_INTERRUPTS__;          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   389
			/* refetch */                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   390
			buf = (char *)(obj);            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   391
			continue;                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   392
		    }                                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   393
		    break;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   394
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   395
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   396
	    __offs += (ret);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   397
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   398
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   399
	    (ret) = __offs;                             \
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   400
    }                                                   \
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   401
  }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   402
#else
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   403
#define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)     \
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   404
  {                                                     \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   405
    int __ooffs = obj_offs;                             \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   406
    int __offs = 0;                                     \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   407
    char *buf = (char *)(obj);                          \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   408
							\
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   409
    (ret) = 0;                                          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   410
    if (isBuffered) {                                   \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   411
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   412
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   413
	    (ret) = getc(f);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   414
	    if ((ret) < 0) {                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   415
		if (ferror(f)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   416
		    if (errno == EINTR) {               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   417
			__HANDLE_INTERRUPTS__;          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   418
			clearerr(f);                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   419
			/* refetch */                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   420
			buf = (char *)(obj);            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   421
			DEBUGBUFFER(buf);               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   422
			continue;                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   423
		    }                                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   424
		} else {                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   425
		    (ret) = 0;                          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   426
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   427
		break;                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   428
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   429
	    (buf)[__ooffs+__offs] = (ret);              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   430
	    DEBUGBUFFER(buf);                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   431
	    __offs++;                                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   432
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   433
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   434
	    (ret) = __offs;                             \
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   435
    } else {                                            \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   436
	int fd = fileno(f);                             \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   437
							\
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   438
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   439
	    OBJ rA = __INST(readAhead);                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   440
	    if (rA != nil) {                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   441
		(buf)[__ooffs+__offs] = __intVal(rA);   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   442
		DEBUGBUFFER(buf);                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   443
		__INST(readAhead) = nil;                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   444
		(ret) = 1;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   445
	    } else {                                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   446
		CLEAR_ERRNO;                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   447
		(ret) = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   448
		DEBUGBUFFER(buf);                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   449
		if ((ret) <= 0) {                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   450
		    if ((ret) < 0 && errno == EINTR) {  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   451
			__HANDLE_INTERRUPTS__;          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   452
			/* refetch */                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   453
			buf = (char *)(obj);            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   454
			continue;                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   455
		    }                                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   456
		    break;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   457
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   458
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   459
	    __offs += (ret);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   460
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   461
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   462
	    (ret) = __offs;                             \
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   463
    }                                                   \
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   464
  }
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   465
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   466
#define __READAVAILBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)     \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   467
  {                                                     \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   468
    int __ooffs = obj_offs;                             \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   469
    int __offs = 0;                                     \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   470
    char *buf = (char *)(obj);                          \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   471
							\
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   472
    (ret) = 0;                                          \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   473
    if (isBuffered) {                                   \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   474
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   475
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   476
	    (ret) = getc(f);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   477
	    if ((ret) < 0) {                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   478
		if (ferror(f)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   479
		    if (errno == EINTR) {               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   480
			clearerr(f);                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   481
			/* refetch */                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   482
			buf = (char *)(obj);            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   483
			(ret) = 0;                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   484
			break;                          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   485
		    }                                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   486
		} else {                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   487
		    (ret) = 0;                          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   488
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   489
		break;                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   490
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   491
	    (buf)[__ooffs+__offs] = (ret);              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   492
	    DEBUGBUFFER(buf);                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   493
	    __offs++;                                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   494
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   495
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   496
	    (ret) = __offs;                             \
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   497
    } else {                                            \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   498
	int fd = fileno(f);                             \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   499
							\
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   500
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   501
	    OBJ rA = __INST(readAhead);                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   502
	    if (rA != nil) {                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   503
		(buf)[__ooffs+__offs] = __intVal(rA);   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   504
		DEBUGBUFFER(buf);                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   505
		__INST(readAhead) = nil;                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   506
		(ret) = 1;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   507
		__offs += (ret);                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   508
		continue;                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   509
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   510
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   511
	    (ret) = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   512
	    DEBUGBUFFER(buf);                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   513
	    if ((ret) < 0 && errno == EINTR) {          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   514
		/* refetch */                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   515
		(ret) = 0;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   516
		buf = (char *)(obj);                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   517
		break;                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   518
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   519
	    __offs += (ret);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   520
	    break;                                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   521
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   522
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   523
	    (ret) = __offs;                             \
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   524
    }                                                   \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   525
  }
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   526
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   527
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   528
#endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   529
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   530
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   531
#define __WRITEBYTE__(ret, f, buf, isBuffered)          \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   532
	for (;;) {                                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   533
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   534
	    (ret) = WRITE(f, buf, 1);                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   535
	    if ((ret) >= 0 || errno != EINTR)           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   536
		break;                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   537
	    __HANDLE_INTERRUPTS__;                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   538
	}
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   539
#else
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   540
#define __WRITEBYTE__(ret, f, buf, isBuffered)          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   541
    if (isBuffered) {                                   \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   542
	for (;;) {                                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   543
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   544
	    ret = putc(*(buf), f);                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   545
	    if ((ret) >= 0) {                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   546
		(ret) = 1;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   547
	    } else if (ferror(f)) {                     \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   548
		if (errno == EINTR) {                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   549
		    __HANDLE_INTERRUPTS__;              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   550
		    clearerr(f);                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   551
		    continue;                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   552
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   553
	    } else                                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   554
		(ret) = 0;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   555
	    break;                                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   556
	}                                               \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   557
    } else {                                            \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   558
	for (;;) {                                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   559
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   560
	    (ret) = write(fileno(f), buf, 1);           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   561
	    if ((ret) >= 0 || errno != EINTR)           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   562
		break;                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   563
	    __HANDLE_INTERRUPTS__;                      \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   564
	}                                               \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   565
   }                                                                          
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   566
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   567
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   568
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   569
 * write_bytes from a c-buffer
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   570
 * (which may NOT move)
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   571
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   572
#ifdef NO_STDIO
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   573
#define __WRITEBYTES__(ret, f, buf, cnt, isBuffered)    \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   574
    (ret) = 0;                                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   575
    {                                                   \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   576
	int __offs = 0;                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   577
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   578
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   579
	    ret = WRITE(f, (buf)+__offs, (cnt)-__offs); \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   580
	    if (ret <= 0) {                             \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   581
		if (ret < 0 && errno == EINTR) {        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   582
		    __HANDLE_INTERRUPTS__;              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   583
		    continue;                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   584
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   585
		break;                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   586
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   587
	    __offs += (ret);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   588
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   589
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   590
	    (ret) = __offs;                             \
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   591
   }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   592
#else
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   593
#define __WRITEBYTES__(ret, f, buf, cnt, isBuffered)    \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   594
    (ret) = 0;                                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   595
    if (isBuffered) {                                   \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   596
	int __offs = 0;                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   597
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   598
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   599
	    ret = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   600
	    if ((ret) <= 0) {                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   601
		if (ferror(f)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   602
		    if (errno == EINTR) {               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   603
			__HANDLE_INTERRUPTS__;          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   604
			clearerr(f);                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   605
			continue;                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   606
		    }                                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   607
		    break;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   608
		} else {                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   609
		    (ret) = 0;                          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   610
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   611
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   612
	    __offs += (ret);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   613
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   614
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   615
	    (ret) = __offs;                             \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   616
    } else {                                            \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   617
	int __offs = 0;                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   618
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   619
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   620
	    ret = write(fileno(f), (buf)+__offs, (cnt)-__offs);\
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   621
	    if (ret <= 0) {                             \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   622
		if (ret < 0 && errno == EINTR) {        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   623
		    __HANDLE_INTERRUPTS__;              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   624
		    continue;                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   625
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   626
		break;                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   627
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   628
	    __offs += (ret);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   629
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   630
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   631
	    (ret) = __offs;                             \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   632
   }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   633
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   634
223
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   635
/*
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   636
 * write_bytes from an object
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   637
 * (which may be moved around by GC)
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   638
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   639
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   640
#define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)            \
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   641
  {                                                     \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   642
    int __ooffs = obj_offs;                             \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   643
    int __offs = 0;                                     \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   644
    char *buf = (char *)(obj);                          \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   645
							\
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   646
    (ret) = 0;                                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   647
    {                                                   \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   648
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   649
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   650
	    ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs);               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   651
	    if (ret <= 0) {                             \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   652
		if (ret < 0 && errno == EINTR) {        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   653
		    __HANDLE_INTERRUPTS__;              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   654
		    /* refetch */                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   655
		    buf = (char *)(obj);                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   656
		    continue;                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   657
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   658
		break;                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   659
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   660
	    __offs += (ret);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   661
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   662
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   663
	    (ret) = __offs;                             \
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   664
    }                                                   \
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   665
  }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   666
#else
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   667
#define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)            \
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   668
  {                                                     \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   669
    int __ooffs = obj_offs;                             \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   670
    int __offs = 0;                                     \
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   671
    char *buf = (char *)(obj);                          \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   672
							\
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   673
    (ret) = 0;                                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   674
    if (isBuffered) {                                   \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   675
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   676
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   677
	    ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f);           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   678
	    if ((ret) <= 0) {                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   679
		if (ferror(f)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   680
		    if (errno == EINTR) {               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   681
			__HANDLE_INTERRUPTS__;          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   682
			/* refetch */                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   683
			buf = (char *)(obj);            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   684
			clearerr(f);                    \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   685
			continue;                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   686
		    }                                   \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   687
		    break;                              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   688
		} else {                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   689
		    (ret) = 0;                          \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   690
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   691
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   692
	    __offs += (ret);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   693
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   694
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   695
	    (ret) = __offs;                             \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   696
    } else {                                            \
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   697
	while (__offs < (cnt)) {                        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   698
	    CLEAR_ERRNO;                                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   699
	    ret = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs);       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   700
	    if (ret <= 0) {                             \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   701
		if (ret < 0 && errno == EINTR) {        \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   702
		    __HANDLE_INTERRUPTS__;              \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   703
		    /* refetch */                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   704
		    buf = (char *)(obj);                \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   705
		    continue;                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   706
		}                                       \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   707
		break;                                  \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   708
	    }                                           \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   709
	    __offs += (ret);                            \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   710
	}                                               \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   711
	if (__offs > 0)                                 \
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   712
	    (ret) = __offs;                             \
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
   713
    }                                                   \
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   714
  }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   715
#endif
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   716
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   717
/*
223
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   718
 * on some systems errno is a macro ... check for it here
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   719
 */
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   720
#ifndef errno
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   721
 extern errno;
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   722
#endif
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   723
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   724
%}
188
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   725
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   726
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   727
!ExternalStream class methodsFor:'documentation'!
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   728
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   729
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   730
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   731
 COPYRIGHT (c) 1988 by Claus Gittinger
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   732
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   733
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   734
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   735
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   736
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   737
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   738
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   739
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   740
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   741
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   742
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   743
documentation
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   744
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   745
    ExternalStream defines protocol common to Streams which have a file-descriptor and 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   746
    represent some file or communicationChannel of the underlying OperatingSystem.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   747
    ExternalStream is abstract; concrete classes are FileStream, PipeStream etc.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   748
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   749
    ExternalStreams can be in two modes: text- (the default) and binary-mode.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   750
    In text-mode, the elements read/written are characters; 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   751
    while in binary-mode the basic elements are bytes which read/write as SmallIntegers 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   752
    in the range 0..255.
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   753
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   754
    Also, the stream can be either in buffered or unbuffered mode. In buffered mode,
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   755
    data is not written until either a cr is written (in text mode) or a synchronizeOutput
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   756
    is sent (in both modes).
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   757
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   758
    The underlying OperatingSystem streams may either be closed explicitely (sending a close)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   759
    or just forgotten - in this case, the garbage collector will eventually collect the
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   760
    object AND a close will be performed automatically (but you will NOT know when this 
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   761
    happens - so it is recommended, that you close your files when no longer needed).
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   762
    Closing is also suggested, since if smalltalk is finished (be it by purpose, or due to
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   763
    some crash) the data will not be in the file, if unclosed. 
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   764
    All streams understand the close message, so it never hurts to use it (it is defined as 
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   765
    a noop in one of the superclasses).
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   766
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   767
    Most of the methods found here redefine inherited methods for better performance,
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   768
    since I/O from/to files should be fast.
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   769
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   770
    Recovering a snapshot:
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   771
      not all streams can be restored to the state they had before - see the implementation of
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   772
      reOpen in subclasses for more information.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   773
      For streams sitting on some communication channel (i.e. Pipes and Sockets) you should
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   774
      reestablish the stream upon image restart (make someone dependent on ObjectMemory).
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   775
      FileStreams are reopened and positioned to their offset they had at snapshot time.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   776
      This may fail, if the file was removed or renamed - or lead to confusion
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   777
      if the contents changed in the meantime.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   778
      Therefore, it is a good idea to reopen files and check for these things at restart time.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   779
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   780
    [Instance variables:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   781
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   782
	filePointer     <Integer>       the unix FILE*; somehow mapped to an integer
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   783
					(notice: not the fd)
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   784
					on Windows: the fileHandle
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   785
	mode            <Symbol>        #readwrite, #readonly or #writeonly
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   786
	buffered        <Boolean>       true, if buffered (i.e. collects characters - does
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   787
					not output immediately)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   788
	binary          <Boolean>       true if in binary mode (reads bytes instead of chars)
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   789
	eolMode         <Symbol>        one of nil, #cr or #crlf.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   790
					determines how lines should be terminated.
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   791
					nil -> newLine (as in Unix);
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   792
					#crlf -> with cr-lf (as in MSDOS)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   793
					#cr -> with cr (as in VMS)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   794
	hitEOF          <Boolean>       true, if EOF was reached
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   795
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   796
	lastErrorNumber <Integer>       the value of errno (only valid right after the error -
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   797
					updated with next i/o operation)
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   798
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   799
    [Class variables:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   800
	Lobby           <Registry>      keeps track of used ext-streams (to free up FILE*'s)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   801
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   802
	StreamErrorSignal       <Signal> parent of all stream errors (see Stream class)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   803
	InvalidReadSignal       <Signal> raised on read from writeonly stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   804
	InvalidWriteSignal      <Signal> raised on write to readonly stream 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   805
	InvalidModeSignal       <Signal> raised on text I/O with binary-stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   806
					 or binary I/O with text-stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   807
	OpenErrorSignal         <Signal> raised if open fails
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   808
	StreamNotOpenSignal     <Signal> raised on I/O with non-open stream
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   809
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   810
    Additional notes:
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   811
      This class is implemented using the underlying stdio-c library package, which
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   812
      has both advantages and disadvantages: since it is portable (posix defined), porting
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   813
      ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   814
      has big problems handling unbounded Streams, since the EOF handling in stdio is
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   815
      not prepared for data to arrive after EOF has been reached - time will show, if we need
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   816
      a complete rewrite for UnboundedStream ...
325
claus
parents: 308
diff changeset
   817
188
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   818
      Also, depending on the system, the stdio library behaves infriendly when signals
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   819
      occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   820
      is handled transparently - on SYS5.3 (i.e. non unixes :-) the read operation returns
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   821
      an error and errno is set to EINTR. 
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   822
      Thats what the ugly code around all getc-calls is for ...
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   823
      Since things get more and more ugly - we will rewrite ExternalStream
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   824
      completely, to NOT use any stdio stuff (and do its buffering itself).
325
claus
parents: 308
diff changeset
   825
claus
parents: 308
diff changeset
   826
      Notice that typical stdio's use a single errno global variable to return an error code,
claus
parents: 308
diff changeset
   827
      this was bad design in the stdio lib (right from the very beginning), since its much
claus
parents: 308
diff changeset
   828
      harder to deal with this in the presence of lightweight processes, where errno gets
claus
parents: 308
diff changeset
   829
      overwritten by an I/O operation done in another thread. (stdio should have been written
claus
parents: 308
diff changeset
   830
      to return errno as a negative number ...).
claus
parents: 308
diff changeset
   831
      To deal with this, the scheduler treats errno like a per-thread private variable,
claus
parents: 308
diff changeset
   832
      and saves/restores the errno setting when switching to another thread.
claus
parents: 308
diff changeset
   833
      (Notice that some thread packages do this also, but ST/X's thread implementation
claus
parents: 308
diff changeset
   834
      does not depend on those, but instead uses a portable private package).
claus
parents: 308
diff changeset
   835
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   836
      Finally, if an stdio-stream is open for both reading and writing, we have to call
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   837
      fseek whenever we are about to read after write and vice versa.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   838
      Two macros (__READING__ and __WRITING__) have been defined to be used before every
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   839
      fread/fgetc and fwrite/putc respectively.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   840
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   841
    [author:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   842
	Claus Gittinger
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   843
	Stefan Vogel (many, many fixes ...)
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   844
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   845
    [see also:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   846
	FileStream Socket PipeStream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   847
	Filename OperatingSystem
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   848
"
3255
eb76cba071a1 example
Claus Gittinger <cg@exept.de>
parents: 3235
diff changeset
   849
!
eb76cba071a1 example
Claus Gittinger <cg@exept.de>
parents: 3235
diff changeset
   850
eb76cba071a1 example
Claus Gittinger <cg@exept.de>
parents: 3235
diff changeset
   851
examples
eb76cba071a1 example
Claus Gittinger <cg@exept.de>
parents: 3235
diff changeset
   852
"
eb76cba071a1 example
Claus Gittinger <cg@exept.de>
parents: 3235
diff changeset
   853
    open a file, read the contents and display it in a textView:
eb76cba071a1 example
Claus Gittinger <cg@exept.de>
parents: 3235
diff changeset
   854
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   855
	|topView scrollPane textView fileStream text|
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   856
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   857
	topView := StandardSystemView new.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   858
	topView label:'contents of Makefile'.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   859
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   860
	scrollPane := HVScrollableView in:topView.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   861
	scrollPane origin:0.0@0.0 corner:1.0@1.0.
3255
eb76cba071a1 example
Claus Gittinger <cg@exept.de>
parents: 3235
diff changeset
   862
        
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   863
	textView := EditTextView new.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   864
	scrollPane scrolledView:textView.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   865
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   866
	fileStream := 'Makefile' asFilename readStream.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   867
	text := fileStream upToEnd.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   868
	fileStream close.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   869
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   870
	textView contents:text.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   871
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   872
	topView open.
3255
eb76cba071a1 example
Claus Gittinger <cg@exept.de>
parents: 3235
diff changeset
   873
eb76cba071a1 example
Claus Gittinger <cg@exept.de>
parents: 3235
diff changeset
   874
eb76cba071a1 example
Claus Gittinger <cg@exept.de>
parents: 3235
diff changeset
   875
eb76cba071a1 example
Claus Gittinger <cg@exept.de>
parents: 3235
diff changeset
   876
    Notice, all of the above can also be done (simply) as:
eb76cba071a1 example
Claus Gittinger <cg@exept.de>
parents: 3235
diff changeset
   877
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   878
	EditTextView openOn:'Makefile'
3255
eb76cba071a1 example
Claus Gittinger <cg@exept.de>
parents: 3235
diff changeset
   879
"
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   880
! !
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   881
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   882
!ExternalStream class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   883
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   884
initDefaultEOLMode
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   885
    OperatingSystem isUNIXlike ifTrue:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   886
	"/ unix EOL conventions
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   887
	DefaultEOLMode := #nl
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   888
    ] ifFalse:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   889
	OperatingSystem isVMSlike ifTrue:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   890
	    "/ vms EOL conventions
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   891
	    DefaultEOLMode := #cr
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   892
	] ifFalse:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   893
	    "/ msdos EOL conventions
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   894
	    DefaultEOLMode := #crlf
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   895
	]
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   896
    ]
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   897
!
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   898
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   899
initModeStrings
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   900
    "initialize modeStrings which are passed down to the underlying
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   901
     fopen/fdopen functions."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   902
3132
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   903
    OperatingSystem isMSDOSlike ifTrue:[
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   904
	ReadMode := 'rb'.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   905
	ReadWriteMode := 'rb+'.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   906
	WriteMode := 'wb'.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   907
	AppendMode := 'ab+'.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   908
	CreateReadWriteMode := 'wb+'.
3132
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   909
    ] ifFalse:[
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   910
	ReadMode := 'r'.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   911
	ReadWriteMode := 'r+'.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   912
	WriteMode := 'w'.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   913
	AppendMode := 'a+'.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
   914
	CreateReadWriteMode := 'w+'.
3132
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   915
    ]
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   916
!
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   917
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   918
initialize
593
19d568779cf7 moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   919
    OpenErrorSignal isNil ifTrue:[
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   920
	OpenErrorSignal := StreamErrorSignal newSignalMayProceed:true.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   921
	OpenErrorSignal nameClass:self message:#openErrorSignal.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   922
	OpenErrorSignal notifierString:'open error'.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   923
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   924
	InvalidReadSignal := ReadErrorSignal newSignalMayProceed:false.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   925
	InvalidReadSignal nameClass:self message:#invalidReadSignal.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   926
	InvalidReadSignal notifierString:'read error'.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   927
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   928
	InvalidWriteSignal := WriteErrorSignal newSignalMayProceed:false.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   929
	InvalidWriteSignal nameClass:self message:#invalidWriteSignal.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   930
	InvalidWriteSignal notifierString:'write error'.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   931
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   932
	InvalidModeSignal :=  StreamErrorSignal newSignalMayProceed:false.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   933
	InvalidModeSignal nameClass:self message:#invalidModeSignal.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   934
	InvalidModeSignal notifierString:'binary/text mode mismatch'.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   935
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   936
	InvalidOperationSignal :=  StreamErrorSignal newSignalMayProceed:false.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   937
	InvalidOperationSignal nameClass:self message:#invalidOperationSignal.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   938
	InvalidOperationSignal notifierString:'unsupported file operation'.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   939
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   940
	StreamNotOpenSignal := StreamErrorSignal newSignalMayProceed:false.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   941
	StreamNotOpenSignal nameClass:self message:#streamNotOpenSignal.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   942
	StreamNotOpenSignal notifierString:'stream is not open'.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   943
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   944
	StreamIOErrorSignal := StreamErrorSignal newSignalMayProceed:false.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   945
	StreamIOErrorSignal nameClass:self message:#streamIOErrorSignal.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   946
	StreamIOErrorSignal notifierString:'I/O error'.
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   947
    ].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   948
31
75f2b9f78be2 *** empty log message ***
claus
parents: 25
diff changeset
   949
    Lobby isNil ifTrue:[
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   950
	Lobby := Registry new.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   951
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   952
	"want to get informed when returning from snapshot"
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   953
	ObjectMemory addDependent:self
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   954
    ].
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   955
    self initDefaultEOLMode.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   956
    self initModeStrings.
3474
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
   957
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
   958
    "Modified: / 21.5.1998 / 16:33:53 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   959
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   960
a27a279701f8 Initial revision
claus
parents:
diff changeset
   961
reOpenFiles
4108
8c4a45bc70eb perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents: 4093
diff changeset
   962
    "reopen all files (if possible) after a snapShot load.
8c4a45bc70eb perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents: 4093
diff changeset
   963
     This is invoked via the #earlyRestart change notification."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   964
301
35e40a6fc72b *** empty log message ***
claus
parents: 269
diff changeset
   965
    Lobby do:[:aFileStream |
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   966
	aFileStream reOpen
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   967
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   968
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   969
1469
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   970
update:something with:aParameter from:changedObject
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   971
    "have to reopen files when returning from snapshot"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   972
4108
8c4a45bc70eb perform reOpen of streams earlier (before doing the view-reinit)
Claus Gittinger <cg@exept.de>
parents: 4093
diff changeset
   973
    something == #earlyRestart ifTrue:[
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   974
	self reOpenFiles.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   975
	self initDefaultEOLMode
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   976
    ]
1469
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   977
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   978
    "Created: 15.6.1996 / 15:19:59 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   979
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   980
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   981
!ExternalStream class methodsFor:'instance creation'!
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   982
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   983
forFileDescriptor:aFileDescriptor mode:modeString
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   984
    "given a fileDescriptor, create an ExternalStream object
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   985
     to operate on this fd. 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   986
     The mode-argument is passed to the fdopen call.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   987
     This may be used to wrap fd's as returned by user 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   988
     primitive code, or to wrap pipe-fds into externalStreams."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   989
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   990
    |newStream|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   991
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   992
    newStream := self basicNew.
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   993
    newStream text; buffered:true; eolMode:DefaultEOLMode; clearEOF.
3535
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
   994
    ^ newStream connectTo:aFileDescriptor withMode:modeString
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   995
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   996
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   997
     the example below will probably fail (15 is a random FD):
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   998
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   999
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1000
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1001
     s := ExternalStream forFileDescriptor:15 mode:'r'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1002
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1003
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1004
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1005
    "Created: 29.2.1996 / 18:05:00 / cg"
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1006
    "Modified: 29.2.1996 / 18:17:07 / cg"
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1007
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1008
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1009
forReadWriteToFileDescriptor:aFileDescriptor
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1010
    "given a fileDescriptor, create an ExternalStream object
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1011
     to read/write from/to this fd. This may be used to wrap fd's
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1012
     as returned by user primitive code, or to wrap pipe-
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1013
     filedescriptors into externalStreams."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1014
3535
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1015
    ^ (self forFileDescriptor:aFileDescriptor mode:ReadWriteMode) readwrite
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1016
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1017
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1018
     the example below will probably fail (15 is a random FD):
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1019
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1020
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1021
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1022
     s := ExternalStream forReadWriteToFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1023
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1024
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1025
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1026
    "Created: 29.2.1996 / 18:15:08 / cg"
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1027
    "Modified: 29.2.1996 / 18:16:25 / cg"
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1028
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1029
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1030
forReadingFromFileDescriptor:aFileDescriptor
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1031
    "given a fileDescriptor, create an ExternalStream object
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1032
     to read from this fd. This may be used to wrap fd's
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1033
     as returned by user primitive code, or to wrap pipe-
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1034
     filedescriptors into externalStreams."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1035
3535
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1036
    ^ (self forFileDescriptor:aFileDescriptor mode:ReadMode) readonly
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1037
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1038
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1039
     the example below will probably fail (15 is a random FD):
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1040
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1041
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1042
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1043
     s := ExternalStream forReadingFromFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1044
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1045
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1046
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1047
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1048
     |pipe readFd writeFd rs ws|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1049
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1050
     'create OS pipe ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1051
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1052
     pipe := OperatingSystem makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1053
     readFd := pipe at:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1054
     writeFd := pipe at:2.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1055
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1056
     'connect Smalltalk streams ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1057
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1058
     rs := ExternalStream forReadingFromFileDescriptor:readFd.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1059
     ws := ExternalStream forWritingToFileDescriptor:writeFd.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1060
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1061
     'read ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1062
     [
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1063
	 1 to:10 do:[:i |
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1064
	     Transcript showCR:rs nextLine
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1065
	 ].
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1066
	 rs close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1067
     ] forkAt:7.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1068
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1069
     'write ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1070
     [
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1071
	 1 to:10 do:[:i |
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1072
	     ws nextPutAll:'hello world '; nextPutAll:i printString; cr
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1073
	 ].
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1074
	 ws close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1075
     ] fork.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1076
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1077
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1078
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1079
    "Created: 29.2.1996 / 18:14:24 / cg"
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1080
    "Modified: 29.2.1996 / 18:25:02 / cg"
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1081
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1082
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1083
forWritingToFileDescriptor:aFileDescriptor
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1084
    "given a fileDescriptor, create an ExternalStream object
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1085
     to write to this fd. This may be used to wrap fd's
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1086
     as returned by user primitive code, or to wrap pipe-
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1087
     filedescriptors into externalStreams."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1088
3535
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1089
    ^ (self forFileDescriptor:aFileDescriptor mode:WriteMode) writeonly
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1090
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1091
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1092
     the example below will probably fail (15 is a random FD):
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1093
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1094
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1095
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1096
     s := ExternalStream forWritingToFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1097
     s binary.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1098
     s nextPut:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1099
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1100
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1101
    "Created: 29.2.1996 / 18:14:43 / cg"
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1102
    "Modified: 29.2.1996 / 18:15:54 / cg"
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1103
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1104
3535
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1105
makePTYPair
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1106
    "return an array with two streams - the first one is the master, 
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1107
     the second the slave of a ptym/ptys pair.
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1108
     This is much like a bidirectional pipe, but allows signals &
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1109
     control chars to be passed through the connection.
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1110
     This is needed to execute a shell in a view.
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1111
     This is the higher level equivalent of OperatingSystem>>makePTYPair
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1112
     (which returns an array of file-descriptors)."
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1113
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1114
     |ptyPair m s|
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1115
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1116
     ptyPair := OperatingSystem makePTYPair.
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1117
     ptyPair notNil ifTrue:[
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1118
	 m := self forReadWriteToFileDescriptor:(ptyPair at:1).
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1119
	 s := self forReadWriteToFileDescriptor:(ptyPair at:2).
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1120
	 ptyPair at:1 put:m.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1121
	 ptyPair at:2 put:s.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1122
	 ^ ptyPair
3535
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1123
     ].
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1124
     ^ nil
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1125
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1126
    "
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1127
     ExternalStream makePTYPair.
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1128
    "
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1129
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1130
    "Modified: 29.2.1996 / 18:28:36 / cg"
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1131
!
03890e8be43d added #makePTYPair
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  1132
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1133
makePipe
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1134
    "return an array with two streams - the first one for reading, 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1135
     the second for writing. 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1136
     This is the higher level equivalent of OperatingSystem>>makePipe
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1137
     (which returns an array of file-descriptors)."
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1138
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1139
     |pipe rs ws|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1140
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1141
     pipe := OperatingSystem makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1142
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1143
     pipe notNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1144
	 rs := self forReadingFromFileDescriptor:(pipe at:1).
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1145
	 ws := self forWritingToFileDescriptor:(pipe at:2).
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1146
	 ^ Array with:rs with:ws
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1147
     ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1148
     ^ nil
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1149
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1150
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1151
     |pipe rs ws|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1152
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1153
     pipe := ExternalStream makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1154
     rs := pipe at:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1155
     ws := pipe at:2.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1156
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1157
     'read ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1158
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1159
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1160
	     Transcript showCR:rs nextLine
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1161
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1162
	 rs close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1163
     ] forkAt:7.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1164
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1165
     'write ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1166
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1167
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1168
	     ws nextPutAll:'hello world '; nextPutAll:i printString; cr
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1169
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1170
	 ws close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1171
     ] fork.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1172
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1173
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1174
    "Modified: 29.2.1996 / 18:28:36 / cg"
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1175
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  1176
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1177
new
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1178
    |newStream|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1179
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1180
    newStream := self basicNew.
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1181
    newStream text; buffered:true; eolMode:DefaultEOLMode; clearEOF.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1182
    ^ newStream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1183
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1184
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1185
!ExternalStream class methodsFor:'Signal constants'!
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1186
1522
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1187
inaccessibleSignal
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1188
    "ST-80 compatibility: return openErrorSignal"
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1189
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1190
    ^ self openErrorSignal
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1191
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1192
    "Created: 2.7.1996 / 12:27:16 / stefan"
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1193
!
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1194
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1195
invalidModeSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1196
    "return the signal raised when doing text-I/O with a binary stream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1197
     or binary-I/O with a text stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1198
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1199
    ^ InvalidModeSignal
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1200
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1201
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1202
invalidOperationSignal
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1203
    "return the signal raised when an unsupported or invalid
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1204
     I/O operation is attempted"
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1205
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1206
    ^ InvalidOperationSignal
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1207
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1208
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1209
invalidReadSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1210
    "return the signal raised when reading from writeonly streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1211
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1212
    ^ InvalidReadSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1213
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1214
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1215
invalidWriteSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1216
    "return the signal raised when writing to readonly streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1217
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1218
    ^ InvalidWriteSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1219
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1220
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1221
openErrorSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1222
    "return the signal raised when a file open failed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1223
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1224
    ^ OpenErrorSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1225
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1226
3474
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1227
streamIOErrorSignal
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1228
    "return the signal raised when an I/O error occurs.
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1229
     (for example, a device-IO-error, or reading an NFS-dir,
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1230
     which is no longer available and has been mounted soft)"
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1231
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1232
    ^ StreamIOErrorSignal
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1233
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1234
    "Created: / 21.5.1998 / 16:32:55 / cg"
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1235
!
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1236
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1237
streamNotOpenSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1238
    "return the signal raised on I/O with closed streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1239
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1240
    ^ StreamNotOpenSignal
2
claus
parents: 1
diff changeset
  1241
! !
claus
parents: 1
diff changeset
  1242
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1243
!ExternalStream class methodsFor:'error handling'!
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1244
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1245
lastErrorNumber
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1246
    "return the errno of the last error"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1247
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1248
    ^ LastErrorNumber
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1249
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1250
    "
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1251
     ExternalStream lastErrorNumber
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1252
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1253
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1254
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1255
lastErrorString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1256
    "return a message string describing the last error"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1257
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1258
    ^ OperatingSystem errorTextForNumber:LastErrorNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1259
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1260
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1261
     ExternalStream lastErrorString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1262
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1263
! !
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1264
3939
52e4ebbde474 oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents: 3938
diff changeset
  1265
!ExternalStream methodsFor:'Signal constants'!
52e4ebbde474 oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents: 3938
diff changeset
  1266
52e4ebbde474 oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents: 3938
diff changeset
  1267
invalidReadSignal
52e4ebbde474 oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents: 3938
diff changeset
  1268
    ^ self class invalidReadSignal
52e4ebbde474 oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents: 3938
diff changeset
  1269
52e4ebbde474 oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents: 3938
diff changeset
  1270
    "Created: / 3.12.1998 / 15:12:06 / cg"
52e4ebbde474 oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents: 3938
diff changeset
  1271
!
52e4ebbde474 oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents: 3938
diff changeset
  1272
52e4ebbde474 oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents: 3938
diff changeset
  1273
invalidWriteSignal
52e4ebbde474 oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents: 3938
diff changeset
  1274
    ^ self class invalidWriteSignal
52e4ebbde474 oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents: 3938
diff changeset
  1275
52e4ebbde474 oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents: 3938
diff changeset
  1276
    "Created: / 3.12.1998 / 15:12:10 / cg"
52e4ebbde474 oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents: 3938
diff changeset
  1277
! !
52e4ebbde474 oops - missing signal accessors
Claus Gittinger <cg@exept.de>
parents: 3938
diff changeset
  1278
3044
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1279
!ExternalStream methodsFor:'Squeak compatibility'!
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1280
3872
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1281
nextInto:aByteArrayOrString
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1282
    "read elements into the argument, whose size determines the amount
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1283
     of bytes to read. If not enough elements could be read, return
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1284
     a copy of the argument; otherwise, return the filled argument."
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1285
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1286
    |n nWanted|
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1287
4368
d69568f9ad95 squeak compatibility fixes
Claus Gittinger <cg@exept.de>
parents: 4161
diff changeset
  1288
    nWanted := aByteArrayOrString byteSize.
3872
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1289
    n := self nextAvailableBytes:nWanted into:aByteArrayOrString startingAt:1.
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1290
    n == nWanted ifTrue:[^ aByteArrayOrString].
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1291
    ^ aByteArrayOrString copyTo:n
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1292
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1293
!
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1294
4368
d69568f9ad95 squeak compatibility fixes
Claus Gittinger <cg@exept.de>
parents: 4161
diff changeset
  1295
readInto:aContainer startingAt:index count:nElements
d69568f9ad95 squeak compatibility fixes
Claus Gittinger <cg@exept.de>
parents: 4161
diff changeset
  1296
    "same as #nextBytes:into:startingAt: for ByteArrays;
d69568f9ad95 squeak compatibility fixes
Claus Gittinger <cg@exept.de>
parents: 4161
diff changeset
  1297
     for LongArrays, nelements longs are read.
3872
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1298
     Squeak compatibility."
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1299
4368
d69568f9ad95 squeak compatibility fixes
Claus Gittinger <cg@exept.de>
parents: 4161
diff changeset
  1300
    |elementSize n|
d69568f9ad95 squeak compatibility fixes
Claus Gittinger <cg@exept.de>
parents: 4161
diff changeset
  1301
d69568f9ad95 squeak compatibility fixes
Claus Gittinger <cg@exept.de>
parents: 4161
diff changeset
  1302
    elementSize := aContainer class elementByteSize.
d69568f9ad95 squeak compatibility fixes
Claus Gittinger <cg@exept.de>
parents: 4161
diff changeset
  1303
    n := self nextBytes:nElements*elementSize into:aContainer startingAt:1.
d69568f9ad95 squeak compatibility fixes
Claus Gittinger <cg@exept.de>
parents: 4161
diff changeset
  1304
    ^ n // elementSize
3872
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1305
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1306
!
cab901645d2a added #nextInto: and #readInto: for Squeak compatibility.
Claus Gittinger <cg@exept.de>
parents: 3863
diff changeset
  1307
3044
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1308
readOnly
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1309
    "Squeak compatibility: make the stream readOnly"
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1310
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1311
    mode := #readonly
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1312
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1313
    "Modified: 20.10.1997 / 19:23:04 / cg"
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1314
    "Created: 20.10.1997 / 19:23:19 / cg"
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1315
! !
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1316
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1317
!ExternalStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1318
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1319
binary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1320
    "switch to binary mode - default is text"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1321
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1322
    binary := true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1323
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1324
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1325
buffered:aBoolean
10
claus
parents: 5
diff changeset
  1326
    "turn buffering on or off - default is on"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1327
10
claus
parents: 5
diff changeset
  1328
    buffered := aBoolean
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1329
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1330
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1331
contents
2
claus
parents: 1
diff changeset
  1332
    "return the contents of the file from the current position up-to
claus
parents: 1
diff changeset
  1333
     the end. If the stream is in binary mode, a ByteArray containing
claus
parents: 1
diff changeset
  1334
     the byte values is returned.
claus
parents: 1
diff changeset
  1335
     In text-mode, a collection of strings, each representing one line,
claus
parents: 1
diff changeset
  1336
     is returned."
claus
parents: 1
diff changeset
  1337
claus
parents: 1
diff changeset
  1338
    |text l chunks sizes chunk byteCount cnt bytes offset|
claus
parents: 1
diff changeset
  1339
claus
parents: 1
diff changeset
  1340
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1341
	"adding to a ByteArray produces quadratic time-space
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1342
	 behavior - therefore we allocate chunks, and concatenate them
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1343
	 at the end."
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1344
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1345
	chunks := OrderedCollection new.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1346
	sizes := OrderedCollection new.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1347
	byteCount := 0.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1348
	[self atEnd] whileFalse:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1349
	    chunk := ByteArray uninitializedNew:4096.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1350
	    cnt := self nextBytes:(chunk size) into:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1351
	    cnt notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1352
		chunks add:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1353
		sizes add:cnt.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1354
		byteCount := byteCount + cnt
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1355
	    ]
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1356
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1357
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1358
	"now, create one big ByteArray"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1359
	bytes := ByteArray uninitializedNew:byteCount.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1360
	offset := 1.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1361
	1 to:chunks size do:[:index |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1362
	    chunk := chunks at:index.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1363
	    cnt := sizes at:index. 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1364
	    bytes replaceFrom:offset to:(offset + cnt - 1) with:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1365
	    offset := offset + cnt
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1366
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1367
	^ bytes
2
claus
parents: 1
diff changeset
  1368
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1369
244
9faa2da0650a Text <-> StringCollection
claus
parents: 223
diff changeset
  1370
    text := StringCollection new.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1371
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1372
	l := self nextLine.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1373
	l isNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1374
	    ^ text
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1375
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1376
	text add:l
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1377
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1378
    ^ text
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1379
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1380
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1381
contentsOfEntireFile
3938
4e7d1880336b oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  1382
    "ST-80 compatibility: return contents as a String (or byteArray, if in binary mode).
3876
a680b41a014c comment
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1383
     See also #contents, which returns the lines as stringCollection for text files."
1522
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1384
3938
4e7d1880336b oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  1385
    |data|
4e7d1880336b oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  1386
4e7d1880336b oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  1387
    data := self contents.
4e7d1880336b oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  1388
    binary ifFalse:[
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1389
	^ data asString.
3938
4e7d1880336b oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  1390
    ].
4e7d1880336b oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  1391
    ^ data
1522
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1392
3876
a680b41a014c comment
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1393
    "Modified: / 3.7.1996 / 13:22:16 / stefan"
3938
4e7d1880336b oops - #contentsOfEntireFile must return a byteArray if in binaryMode.
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  1394
    "Modified: / 27.11.1998 / 16:29:43 / cg"
2
claus
parents: 1
diff changeset
  1395
!
claus
parents: 1
diff changeset
  1396
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1397
contentsSpecies
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1398
    "return the kind of object to be returned by sub-collection builders
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1399
     (such as upTo)"
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1400
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1401
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1402
	^ ByteArray
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1403
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1404
    ^ String
2
claus
parents: 1
diff changeset
  1405
!
claus
parents: 1
diff changeset
  1406
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1407
eolMode:aSymbolOrNil
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1408
    "specify how end-of-line (EOL) is to be marked.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1409
     The argument may be one of:
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1410
	#crlf         -> add a CR-NL, as in MSDOS
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1411
	#cr           -> add a CR, as in VMS
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1412
	#nl           -> add a NL, as in Unix
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1413
	anyOther      -> like #nl
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1414
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1415
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1416
    eolMode := aSymbolOrNil
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1417
!
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1418
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1419
fileDescriptor
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1420
    "return the fileDescriptor of the receiver -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1421
     notice: this one returns the underlying OSs fileDescriptor -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1422
     this may not be available on all platforms (i.e. non unix systems)."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1423
3971
aad506cdc5d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3956
diff changeset
  1424
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1425
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1426
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1427
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1428
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1429
	f = __FILEVal(fp);
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1430
	RETURN ( __MKINT(fileno(f)) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1431
    }
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1432
%}.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1433
    ^ self errorNotOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1434
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1435
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1436
filePointer
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1437
    "return the filePointer of the receiver -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1438
     notice: for portability stdio is used; this means you will get
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1439
     a FILE * - not a fileDescriptor. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1440
     (what you really get is a corresponding integer).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1441
     You cannot do much with the returned value 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1442
     - except passing it to a primitive, for example."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1443
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1444
    ^ filePointer
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1445
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1446
3016
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  1447
lineEndTransparent
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  1448
    eolMode := #cr
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  1449
!
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  1450
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1451
readonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1452
    "set access mode to readonly"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1453
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1454
    mode := #readonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1455
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1456
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1457
readwrite
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1458
    "set access mode to readwrite"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1459
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1460
    mode := #readwrite
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1461
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1462
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1463
text
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1464
    "switch to text mode - default is text"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1465
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1466
    binary := false
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1467
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1468
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1469
useCRLF:aBoolean
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1470
    "turn on or off CRLF sending (instead of LF only) - default is off.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1471
     This method is provided for backward compatibility - see #eolMode:
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1472
     which offers another choice."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1473
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1474
    aBoolean ifTrue:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1475
	eolMode := #crlf
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1476
    ] ifFalse:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1477
	eolMode := #nl
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1478
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1479
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1480
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1481
writeonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1482
    "set access mode to writeonly"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1483
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1484
    mode := #writeonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1485
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1486
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1487
!ExternalStream methodsFor:'error handling'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1488
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1489
argumentMustBeCharacter
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1490
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1491
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1492
    "report an error, that the argument must be a character"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1493
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1494
    ^ self error:'argument must be a character'
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1495
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1496
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1497
argumentMustBeInteger
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1498
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1499
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1500
    "report an error, that the argument must be an integer"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1501
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1502
    ^ self error:'argument must be an integer'
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1503
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1504
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1505
argumentMustBeString
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1506
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1507
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1508
    "report an error, that the argument must be a string"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1509
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1510
    ^ self error:'argument must be a string'
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1511
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1512
4526
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  1513
errorAlreadyOpen
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  1514
    "{ Pragma: +optSpace }"
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  1515
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  1516
    "report an error, that the stream is already opened"
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  1517
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  1518
    ^ self class openErrorSignal
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  1519
        raiseRequestWith:self
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  1520
        errorString:(self class name , ' is already open')
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  1521
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  1522
    "Modified: / 8.5.1999 / 20:12:30 / cg"
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  1523
!
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  1524
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1525
errorBinary
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1526
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1527
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1528
    "report an error, that the stream is in binary mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1529
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1530
    ^ self invalidModeSignal
4161
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1531
        raiseRequestWith:self
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1532
             errorString:(self class name , ' is in binary mode')
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1533
                      "/ in:thisContext sender
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1534
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1535
    "Modified: / 8.5.1999 / 20:12:43 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1536
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1537
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1538
errorNotBinary
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1539
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1540
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1541
    "report an error, that the stream is not in binary mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1542
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1543
    ^ self invalidModeSignal
4161
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1544
        raiseRequestWith:self
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1545
             errorString:(self class name , ' is not in binary mode')
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1546
                      "/ in:thisContext sender
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1547
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1548
    "Modified: / 8.5.1999 / 20:12:40 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1549
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1550
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1551
errorNotBuffered
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1552
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1553
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1554
    "report an error, that the stream is not in buffered mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1555
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1556
    ^ StreamErrorSignal
4161
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1557
        raiseRequestWith:self
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1558
             errorString:(self class name , ' is unbuffered - operation not allowed')
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1559
                      "/ in:thisContext sender
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1560
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1561
    "Modified: / 8.5.1999 / 20:12:36 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1562
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1563
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1564
errorNotOpen
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1565
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1566
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1567
    "report an error, that the stream has not been opened"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1568
3467
54ccb6f7d886 oops - streamNotOpenSignal
Claus Gittinger <cg@exept.de>
parents: 3456
diff changeset
  1569
    ^ StreamNotOpenSignal
4161
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1570
        raiseRequestWith:self
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1571
             errorString:(self class name , ' not open')
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1572
                      "/ in:thisContext sender
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1573
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1574
    "Modified: / 8.5.1999 / 20:12:33 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1575
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1576
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1577
errorReadOnly
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1578
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1579
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1580
    "report an error, that the stream is a readOnly stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1581
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1582
    ^ self invalidWriteSignal
4468
8c67b4f973d8 raise vs. raiseRequest
Claus Gittinger <cg@exept.de>
parents: 4456
diff changeset
  1583
          raiseWith:self
8c67b4f973d8 raise vs. raiseRequest
Claus Gittinger <cg@exept.de>
parents: 4456
diff changeset
  1584
          errorString:(self class name , ' is readonly')
4161
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1585
                      "/ in:thisContext sender
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1586
4468
8c67b4f973d8 raise vs. raiseRequest
Claus Gittinger <cg@exept.de>
parents: 4456
diff changeset
  1587
    "Modified: / 30.7.1999 / 17:08:19 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1588
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1589
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1590
errorUnsupportedOperation
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1591
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1592
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1593
    "report an error, that some unsupported operation was attempted"
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1594
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1595
    ^ self invalidOperationSignal
4161
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1596
        raiseRequestWith:self
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1597
        errorString:'unsupported operation'
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1598
                 "/ in:thisContext sender
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1599
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1600
    "Modified: / 8.5.1999 / 20:12:24 / cg"
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1601
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1602
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1603
errorWriteOnly
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1604
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1605
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1606
    "report an error, that the stream is a writeOnly stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1607
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1608
    ^ self invalidReadSignal
4161
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1609
        raiseRequestWith:self
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1610
             errorString:(self class name , ' is writeonly')
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1611
                      "/ in:thisContext sender
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1612
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1613
    "Modified: / 8.5.1999 / 20:12:20 / cg"
2
claus
parents: 1
diff changeset
  1614
!
claus
parents: 1
diff changeset
  1615
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1616
ioError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1617
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1618
3474
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1619
    "report an error, that some I/O error occured.
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1620
     (for example, a device-IO-error, or reading an NFS-dir,
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1621
     which is no longer available and has been mounted soft)"
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1622
1af4d150dab4 added extra streamIOError signal.
Claus Gittinger <cg@exept.de>
parents: 3467
diff changeset
  1623
    ^ StreamIOErrorSignal
4161
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1624
        raiseRequestWith:self
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1625
             errorString:('I/O error: ' , self lastErrorString)
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1626
                      "/ in:thisContext sender
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1627
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1628
    "Modified: / 8.5.1999 / 20:12:16 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1629
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1630
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1631
lastErrorNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1632
    "return the last error"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1633
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1634
    ^ lastErrorNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1635
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1636
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1637
lastErrorString
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1638
    "return a message string describing the last error"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1639
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1640
    (lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1641
	^ 'I/O error'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1642
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1643
    ^ OperatingSystem errorTextForNumber:lastErrorNumber
2
claus
parents: 1
diff changeset
  1644
!
claus
parents: 1
diff changeset
  1645
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1646
openError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1647
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1648
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1649
    "report an error, that the open failed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1650
3235
cc254b307159 FileStream redefines #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3221
diff changeset
  1651
    ^ self class openErrorSignal
4161
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1652
        raiseRequestWith:self
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1653
             errorString:('error on open: ' , self lastErrorString)
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1654
                      "/ in:thisContext sender
3235
cc254b307159 FileStream redefines #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3221
diff changeset
  1655
cc254b307159 FileStream redefines #openErrorSignal.
Stefan Vogel <sv@exept.de>
parents: 3221
diff changeset
  1656
    "Modified: / 28.1.1998 / 14:37:42 / stefan"
4161
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1657
    "Modified: / 8.5.1999 / 20:12:12 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1658
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1659
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1660
readError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1661
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1662
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1663
    "report an error, that some read error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1664
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1665
    ^ ReadErrorSignal
4161
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1666
        raiseRequestWith:self
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1667
             errorString:('read error: ' , self lastErrorString)
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1668
                      "/ in:thisContext sender
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1669
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1670
    "Modified: / 8.5.1999 / 20:12:00 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1671
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1672
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1673
writeError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1674
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1675
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1676
    "report an error, that some write error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1677
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1678
    ^ WriteErrorSignal
4161
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1679
        raiseRequestWith:self
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1680
             errorString:('write error: ' , self lastErrorString)
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1681
                      "/ in:thisContext sender
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1682
3f2758cfeff5 raise errors in thisContext (not in sender context)
Claus Gittinger <cg@exept.de>
parents: 4152
diff changeset
  1683
    "Modified: / 8.5.1999 / 20:12:09 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1684
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1685
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1686
!ExternalStream methodsFor:'instance release'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1687
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1688
closeFile
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1689
    "low level close - may be redefined in subclasses"
2
claus
parents: 1
diff changeset
  1690
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1691
%{
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1692
    OBJ fp;
2
claus
parents: 1
diff changeset
  1693
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1694
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1695
	__INST(filePointer) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1696
	__BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1697
	fclose(__FILEVal(fp));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1698
	__END_INTERRUPTABLE__
10
claus
parents: 5
diff changeset
  1699
    }
claus
parents: 5
diff changeset
  1700
%}
claus
parents: 5
diff changeset
  1701
!
claus
parents: 5
diff changeset
  1702
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1703
disposed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1704
    "some Stream has been collected - close the file if not already done"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1705
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1706
    self closeFile
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1707
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1708
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1709
setFileDescriptor:anInteger mode:openMode
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1710
    "set the filePointer based upon a given fileDescriptor -
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1711
     notice: this one is based on the underlying OSs fileDescriptor -
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1712
     this may not be available on all platforms (i.e. non unix systems)."
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1713
3681
55dc17d40aab fixed nextAvail
Claus Gittinger <cg@exept.de>
parents: 3674
diff changeset
  1714
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1715
    FILEPOINTER f;
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1716
    OBJ fp;
2765
a56668774ad7 more alpha64 fixes
Claus Gittinger <cg@exept.de>
parents: 2764
diff changeset
  1717
    FILE *fdopen();
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1718
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1719
    if (__isSmallInteger(anInteger) &&
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1720
	__isString(openMode) &&
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1721
	(f = fdopen(__intVal(anInteger), __stringVal(openMode))) != 0
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1722
    ) {
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1723
	__PROTECT__(self);
3420
4dc6667afda9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3419
diff changeset
  1724
	fp = __MKFILEPOINTER(f);
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1725
	__UNPROTECT__(self);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1726
	__INST(filePointer) = fp; __STORE(self, fp);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1727
	RETURN (self);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1728
    }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1729
%}.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1730
    ^ self primitiveFailed
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1731
!
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1732
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1733
setFilePointer:something
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1734
    "set the filePointer to the given one;
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1735
     low level private & friend interface; may also be used to connect to some
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1736
     externally provided file handle."
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1737
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1738
    filePointer := something
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1739
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1740
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1741
shallowCopyForFinalization
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1742
    "return a copy for finalization-registration;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1743
     since all we need at finalization time is the fileDescriptor,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1744
     a cheaper copy is possible."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1745
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1746
    ^ self class basicNew setFilePointer:filePointer
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1747
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1748
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1749
shutDown
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1750
    "close the stream - added for protocol compatibility with PipeStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1751
     see comment there"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1752
3949
904575569fb4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3939
diff changeset
  1753
    self isOpen ifTrue:[
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1754
	Lobby unregister:self.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1755
	self closeFile
3949
904575569fb4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3939
diff changeset
  1756
    ]
1642
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1757
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1758
    "Modified: 30.8.1996 / 00:39:21 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1759
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1760
2
claus
parents: 1
diff changeset
  1761
!ExternalStream methodsFor:'line reading/writing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1762
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1763
nextLine
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1764
    "read the next line (characters up to newline).
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1765
     Return a string containing those characters excluding the newline.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1766
     If the previous-to-last character is a cr, this is also removed,
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1767
     so its possible to read alien (i.e. ms-dos) text as well.
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1768
     The line must be shorter than 16K characters - otherwise an error is signalled."
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1769
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1770
    |line|
971
eb70f5674303 max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
  1771
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1772
%{  /* STACK:34000 */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1773
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1774
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1775
    int len, ret;
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1776
    char buffer[32*1024];
521
70533ec40482 use new MKSTRING_L if length is known (avoids a useless strlen)
Claus Gittinger <cg@exept.de>
parents: 481
diff changeset
  1777
    char *rslt, *nextPtr, *limit;
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1778
    int fd, ch;
1068
92fdcccf12a3 alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1779
    int _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1780
    OBJ fp;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1781
    int lineTooLong = 0;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1782
    int cutOff = 0;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1783
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1784
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1785
    if (((fp = __INST(filePointer)) != nil)
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1786
	&& (__INST(mode) != @symbol(writeonly))
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1787
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1788
    ) {
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1789
	f = __FILEVal(fp);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1790
	buffer[0] = '\0';
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1791
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1792
	_buffered = (__INST(buffered) == true);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1793
	if (_buffered) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1794
	    __READING__(f);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1795
	} 
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1796
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1797
	rslt = nextPtr = buffer;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1798
	limit = buffer + sizeof(buffer) - 2;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1799
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1800
	for (;;) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1801
	    __READBYTE__(ret, f, nextPtr, _buffered);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1802
	    if (ret <= 0) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1803
		if (nextPtr == buffer)
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1804
		    rslt = NULL;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1805
		if (ret == 0) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1806
		    __INST(hitEOF) = true;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1807
		    break;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1808
		} else {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1809
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1810
		    goto err;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1811
		}
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1812
	    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1813
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1814
	    if (*nextPtr == '\n') {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1815
		cutOff = 1;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1816
		*nextPtr = '\0';
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1817
		break;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1818
	    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1819
	    if (*nextPtr == '\r') {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1820
		char peekChar;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1821
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1822
		/*
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1823
		 * peek ahead for a newLine ...
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1824
		 */
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1825
		__READBYTE__(ret, f, &peekChar, _buffered);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1826
		if (ret <= 0) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1827
		    cutOff = 1;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1828
		    *nextPtr = '\0';
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1829
		    if (ret == 0) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1830
			__INST(hitEOF) = true;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1831
			break;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1832
		    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1833
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1834
		    goto err;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1835
		}
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1836
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1837
		if (peekChar == '\n') {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1838
		    cutOff = 2;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1839
		    *nextPtr = '\0';
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1840
		    break;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1841
		}
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1842
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1843
		__UNGETC__(peekChar, f, _buffered);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1844
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1845
		cutOff = 1;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1846
		*nextPtr = '\0';
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1847
		break;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1848
	    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1849
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1850
	    nextPtr++;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1851
	    if (nextPtr >= limit) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1852
		*nextPtr = '\0';
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1853
		lineTooLong = 1;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1854
		if (@global(InfoPrinting) == true) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1855
		    fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n");
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1856
		}
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1857
		break;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1858
	    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1859
	}
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1860
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1861
	if (rslt != NULL) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1862
	    len = nextPtr-buffer;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1863
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1864
	    if (__INST(position) != nil) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1865
		int __p;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1866
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1867
		__p = __intVal(__INST(position)) + len + cutOff;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1868
		__INST(position) = __MKSMALLINT(__p);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1869
	    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1870
	    /* remove any EOL character */
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1871
	    if (len != 0) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1872
		if (buffer[len-1] == '\n') {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1873
		    buffer[--len] = '\0';
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1874
		}
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1875
		if ((len != 0) && (buffer[len-1] == '\r')) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1876
		    buffer[--len] = '\0';
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1877
		}
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1878
	    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1879
	    line = __MKSTRING_L(buffer, len);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1880
	    if (! lineTooLong) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1881
		RETURN ( line );
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1882
	    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1883
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1884
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1885
err: ;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1886
%}.
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1887
    line notNil ifTrue:[
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1888
	"/ the line as read is longer than 32k characters (boy - what a line)
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1889
	"/ The exception could be handled by reading more and returning the
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1890
	"/ concatenation in your exception handler (the receiver and the partial
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1891
	"/ line are passed as parameter)
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1892
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1893
	^ LineTooLongErrorSignal
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1894
	    raiseRequestWith:(Array with:self with:line)
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  1895
		 errorString:('line too long read error')
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1896
    ].
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1897
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1898
    hitEOF ifTrue:[^ self pastEnd].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1899
    lastErrorNumber notNil ifTrue:[^ self readError].
2
claus
parents: 1
diff changeset
  1900
    filePointer isNil ifTrue:[^ self errorNotOpen].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1901
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1902
    ^ self errorBinary
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1903
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1904
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1905
nextPutLine:aString
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1906
    "write the characters in aString and append an end-of-Line marker
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1907
     (LF, CR or CRLF - depending in the setting of eolMode)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1908
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1909
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1910
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1911
    int len, cnt, len1, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1912
    OBJ pos, fp;
537
dc4dad8a5ddd many ExtStream rewrites - has to be reevaluated in all platforms
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1913
    char *cp;
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1914
    int o_offs;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1915
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1916
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1917
    if (((fp = __INST(filePointer)) != nil) 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1918
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1919
	&& (__INST(binary) != true)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1920
	&& __isString(aString)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1921
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1922
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1923
	len = __stringSize(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1924
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1925
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1926
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1927
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1928
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1929
	__WRITEBYTES__(cnt, f, __stringVal(aString), len, _buffered);
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1930
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1931
	o_offs = (char *)__stringVal(aString)-(char *)aString;
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1932
	__WRITEBYTES_OBJ__(cnt, f, aString, o_offs, len, _buffered);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1933
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1934
	if (cnt == len) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1935
	    OBJ mode = __INST(eolMode);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1936
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1937
	    len1 = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1938
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1939
	    if (mode == @symbol(cr)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1940
		cp = "\r"; len = 1;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1941
	    } else if (mode == @symbol(crlf)) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1942
		cp = "\r\n"; len = 2;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1943
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1944
		cp = "\n"; len = 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1945
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1946
	    __WRITEBYTES__(cnt, f, cp, len, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1947
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1948
	    if (cnt > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1949
		pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1950
		if (pos != nil) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1951
		    int __p;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1952
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1953
		    __p = __intVal(pos) + len1 + cnt;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1954
		    __INST(position) = __MKSMALLINT(__p);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1955
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1956
		RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1957
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1958
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1959
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1960
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1961
%}.
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1962
    super nextPutLine:aString.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1963
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1964
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1965
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1966
    "read from aStream up to and including a line starting with aStringOrNil
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1967
     and append all lines to self. 
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1968
     Can be used to copy/create large files or copy from a pipe/socket.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1969
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1970
     If aStringOrNil is nil or not matched, copy preceeds to the end.
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1971
     (this allows for example to read a Socket and transfer the data quickly
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1972
      into a file - without creating zillions of temporary strings)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1973
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1974
    |srcFilePointer readError line|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1975
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1976
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1977
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1978
    srcFilePointer := aStream filePointer.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1979
    srcFilePointer isNil ifTrue:[aStream errorNotOpen. ^ self].
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1980
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1981
%{  /* STACK:2000 */
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1982
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1983
#ifndef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1984
    FILEPOINTER dst;
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1985
    FILEPOINTER src;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1986
    char *matchString;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1987
    int matchLen = 0;
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1988
    char buffer[1024];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1989
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1990
    __INST(lastErrorNumber) = nil;
249
claus
parents: 244
diff changeset
  1991
    if (__isSmallInteger(srcFilePointer)) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1992
	if ((aStringOrNil == nil) || __isString(aStringOrNil)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1993
	    if (aStringOrNil != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1994
		matchString = (char *) __stringVal(aStringOrNil);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1995
		matchLen = __stringSize(aStringOrNil);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1996
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1997
	    dst = __FILEVal(__INST(filePointer));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1998
	    src = __FILEVal(srcFilePointer);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1999
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2000
	    errno = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2001
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2002
	    __WRITING__(dst)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2003
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2004
	    for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2005
		if (fgets(buffer, sizeof(buffer)-1, src) == NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2006
		    if (ferror(src)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2007
			readError = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2008
			__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2009
			goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2010
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2011
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2012
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2013
		if (fputs(buffer, dst) == EOF) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2014
		    if (ferror(dst)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2015
			__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2016
			__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2017
			goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2018
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2019
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2020
		}
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  2021
#ifndef OLD
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2022
		if (__INST(buffered) == false) {
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2023
		    FFLUSH(dst);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2024
		}
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  2025
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2026
		if (matchLen) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2027
		    if (strncmp(matchString, buffer, matchLen) == 0) 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2028
			break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2029
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2030
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2031
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2032
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2033
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2034
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2035
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2036
err: ;
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2037
#endif /* ! NO_STDIO */
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2038
%}.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2039
    readError ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2040
	aStream setLastErrorNumber:readError.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2041
	aStream readError.
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2042
	^ self
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2043
    ].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2044
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2045
    buffered ifFalse:[self errorNotBuffered. ^ self].
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2046
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2047
    "
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2048
     argument error or unimplemented; try it linewise
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2049
    "
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2050
    [aStream atEnd] whileFalse:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2051
	line := aStream nextLine.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2052
	line isNil ifTrue:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2053
	    ^ self.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2054
	].
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2055
	self nextPutLine:line.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2056
	(aStringOrNil notNil and:[line startsWith:aStringOrNil]) ifTrue:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2057
	    ^ self
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2058
	]
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2059
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2060
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2061
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2062
peekForLineStartingWith:aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2063
    "read ahead for next line starting with aString;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2064
     return the line-string if found, or nil if EOF is encountered.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2065
     If matched, not advance position behond that line
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2066
     i.e. nextLine will read the matched line.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2067
     If not matched, reposition to original position for firther reading."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2068
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2069
    |firstPos lastPos line|
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2070
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2071
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2072
    filePointer isNil ifTrue:[^ self errorNotOpen].
2
claus
parents: 1
diff changeset
  2073
    binary ifTrue:[^ self errorBinary].
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2074
    buffered ifFalse:[^ self errorNotBuffered].
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  2075
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  2076
%{  /* STACK: 2000 */
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2077
#ifndef NO_STDIO
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2078
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2079
    FILEPOINTER f;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2080
    int l;
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  2081
    char buffer[1024];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2082
    char *cp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2083
    char *matchString;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2084
    int gotFirst = 0;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2085
#ifdef __VMS__
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2086
    fpos_t firstpos, lastpos;
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2087
#   define FTELL(__f__, __pos__)        fgetpos(__f__, &(__pos__))
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2088
#   define FSEEK(__f__, __pos__)        fsetpos(__f__, &(__pos__))
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2089
#else
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2090
    long firstpos, lastpos;
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2091
#   define FTELL(__f__, __pos__)        __pos__ = ftell(__f__)
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2092
#   define FSEEK(__f__, __pos__)        fseek(__f__, __pos__, SEEK_SET)
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2093
#endif
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2094
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2095
    __INST(lastErrorNumber) = nil;
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
  2096
    if (__isString(aString)) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2097
	matchString = (char *) __stringVal(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2098
	l = __stringSize(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2099
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2100
	f = __FILEVal(__INST(filePointer));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2101
	__READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2102
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2103
	for (;;) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2104
	    FTELL(f, lastpos);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2105
	    if (!gotFirst) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2106
		firstpos = lastpos;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2107
		gotFirst = 1;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2108
	    }
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2109
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2110
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2111
	    do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2112
		cp = fgets(buffer, sizeof(buffer)-1, f);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2113
	    } while ((cp == NULL) && ferror(f) && (errno == EINTR) && (clearerr(f), 1));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2114
	    buffer[sizeof(buffer)-1] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2115
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2116
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2117
	    if (cp == NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2118
		if (ferror(f)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2119
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2120
		    goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2121
		} else {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2122
		    FSEEK(f, firstpos);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2123
		    RETURN (nil);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2124
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2125
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2126
	    if (strncmp(cp, matchString, l) == 0) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2127
		FSEEK(f, lastpos);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2128
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2129
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2130
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2131
	/* remove EOL character */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2132
	cp = buffer;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2133
	while (*cp && (*cp != '\n') && (*cp != '\r')) cp++;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2134
	*cp = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2135
	RETURN ( __MKSTRING(buffer) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2136
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2137
err: ;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2138
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2139
# undef FTELL
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2140
# undef FSEEK
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2141
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2142
#endif
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2143
%}.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2144
    lastErrorNumber notNil ifTrue:[^ self readError].
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2145
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2146
    "/ try using generic code ...
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2147
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2148
    firstPos := self position.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2149
    [self atEnd] whileFalse:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2150
	lastPos := self position.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2151
	line := self nextLine.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2152
	line isNil ifTrue:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2153
	    self position:firstPos.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2154
	    ^ nil
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2155
	].
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2156
	(line startsWith:aString) ifTrue:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2157
	    self position:lastPos.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2158
	    ^ line
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2159
	]
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2160
    ].
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2161
    self position:firstPos.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2162
    ^ nil
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2163
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2164
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2165
peekForLineStartingWithAny:aCollectionOfStrings
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2166
    "read ahead for next line starting with any of aCollectionOfStrings;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2167
     return the index in aCollection if found, nil otherwise..
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2168
     If no match, do not change position; otherwise advance right before the
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2169
     matched line so that nextLine will return this line."
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2170
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2171
    |line startPos linePos index|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2172
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2173
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2174
    filePointer isNil ifTrue:[^ self errorNotOpen].
2
claus
parents: 1
diff changeset
  2175
    binary ifTrue:[^ self errorBinary].
claus
parents: 1
diff changeset
  2176
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2177
    startPos := self position.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2178
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2179
	linePos := self position.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2180
	line := self nextLine.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2181
	line notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2182
	    index := 1.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2183
	    aCollectionOfStrings do:[:prefix |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2184
		(line startsWith:prefix) ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2185
		    self position:linePos.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2186
		    ^ index
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2187
		].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2188
		index := index + 1
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2189
	    ]
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2190
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2191
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2192
    self position:startPos.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2193
    ^ nil
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2194
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2195
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2196
!ExternalStream methodsFor:'misc functions'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2197
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2198
async:aBoolean
779
0e41a665038a commentary
Claus Gittinger <cg@exept.de>
parents: 730
diff changeset
  2199
    "set/clear the async attribute - if set, the availability of data on 
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2200
     the receiver will trigger an ioInterrupt.
779
0e41a665038a commentary
Claus Gittinger <cg@exept.de>
parents: 730
diff changeset
  2201
     If cleared (which is the default) no special notification is made.
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2202
     Notice: 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2203
	not every OS supports this 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2204
	- check with OS>>supportsIOInterrupts before using"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2205
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2206
    |fd|
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2207
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2208
    filePointer isNil ifTrue:[^ self errorNotOpen].
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2209
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2210
    OperatingSystem supportsIOInterrupts ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2211
	^ self errorUnsupportedOperation
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2212
    ].
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2213
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2214
    fd := self fileDescriptor.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2215
    aBoolean ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2216
	^ OperatingSystem enableIOInterruptsOn:fd
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2217
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2218
    ^ OperatingSystem disableIOInterruptsOn:fd
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2219
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2220
    "Modified: 11.1.1997 / 17:50:21 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2221
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2222
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2223
backStep
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2224
    "step back one element -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2225
     redefined, since position is redefined here"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2226
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2227
    self position:(self position - 1)
362
claus
parents: 360
diff changeset
  2228
!
claus
parents: 360
diff changeset
  2229
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2230
blocking:aBoolean
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2231
    "set/clear the blocking attribute - if set (which is the default)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2232
     a read (using next) on the receiver will block until data is available.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2233
     If cleared, a read operation will immediately return with a value of
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2234
     nil.
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2235
     Turning off blocking is useful when reading from PipeStreams
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2236
     or Sockets, and the amount of data to be read is not known
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2237
     in advance. However, the data must then be read using #nextBytes:
3174
668414a73de9 Typo in comment
Stefan Vogel <sv@exept.de>
parents: 3132
diff changeset
  2238
     methods, in order to avoid other (pastEnd) exceptions."
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2239
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2240
    filePointer isNil ifTrue:[^ self errorNotOpen].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2241
    ^ OperatingSystem setBlocking:aBoolean on:(self fileDescriptor)
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2242
3174
668414a73de9 Typo in comment
Stefan Vogel <sv@exept.de>
parents: 3132
diff changeset
  2243
    "Modified: / 11.1.1997 / 17:48:01 / cg"
668414a73de9 Typo in comment
Stefan Vogel <sv@exept.de>
parents: 3132
diff changeset
  2244
    "Modified: / 15.1.1998 / 11:49:48 / stefan"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2245
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2246
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2247
close
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2248
    "close the stream - tell operating system"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2249
3949
904575569fb4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3939
diff changeset
  2250
    self isOpen ifTrue:[
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2251
	Lobby unregister:self.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2252
	self closeFile.
3949
904575569fb4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3939
diff changeset
  2253
    ]
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2254
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2255
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2256
create
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2257
    "create the stream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2258
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2259
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2260
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2261
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2262
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2263
ioctl:ioctlNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2264
    "to provide a simple ioctl facility - an ioctl is performed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2265
     on the underlying file; no arguments are passed."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2266
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2267
    ^ self ioctl:ioctlNumber with:nil
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2268
!
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2269
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2270
ioctl:ioctlNumber with:arg
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2271
    "to provide a simple ioctl facility - an ioctl is performed
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2272
     on the underlying file; the argument is passed as argument.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2273
     This is not used by ST/X, but provided for special situations 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2274
     - for example, to control proprietrary I/O devices.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2275
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2276
     Since the type of the argument depends on the ioctl being
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2277
     performed, different arg types are allowed here.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2278
     If the argument is nil, an ioctl without argument is performed.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2279
     If the argument is an integral number, its directly passed; 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2280
     if its a kind of ByteArray (ByteArray, String or Structure),
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2281
     or external data (ExternalBytes or ExternalAddress),
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2282
     a pointer to the data is passed. 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2283
     This allows performing most ioctls 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2284
     - however, it might be tricky to setup the buffer.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2285
     Be careful in what you pass - ST/X cannot validate its correctness."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2286
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2287
%{
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
  2288
#if !defined(MSDOS_LIKE)
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
  2289
# if !defined(__openVMS__)
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2290
    FILEPOINTER f;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2291
    int ret, ioNum;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2292
    OBJ fp;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2293
    INT ioArg;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2294
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2295
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2296
    if ((fp = __INST(filePointer)) != nil) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2297
	if (__isSmallInteger(ioctlNumber) 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2298
	 && (__isSmallInteger(arg) 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2299
	     || (arg == nil)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2300
	     || __isBytes(arg)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2301
	     || __isExternalBytes(arg)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2302
	     || __isExternalAddress(arg))) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2303
	    f = __FILEVal(fp);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2304
	    ioNum = __intVal(ioctlNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2305
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2306
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2307
	    do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2308
		errno = 0;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2309
		if (arg == nil) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2310
		    ioArg = 0;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2311
		} else if (__isSmallInteger(arg)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2312
		    ioArg = __intVal(arg);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2313
		} else if (__isExternalBytes(arg)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2314
		    ioArg = (INT)(__externalBytesAddress(arg));
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2315
		} else if (__isExternalAddress(arg)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2316
		    ioArg = (INT)(__externalAddressVal(arg));
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2317
		} else {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2318
		    ioArg = (INT)(__ByteArrayInstPtr(arg)->ba_element);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2319
		}
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2320
		ret = ioctl(fileno(f), ioNum, ioArg);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2321
	    } while ((ret < 0) && (errno == EINTR));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2322
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2323
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2324
	    if (ret >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2325
		RETURN ( __MKSMALLINT(ret) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2326
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2327
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2328
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2329
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2330
    }
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
  2331
# endif
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  2332
#endif
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2333
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2334
    lastErrorNumber notNil ifTrue:[^ self ioError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2335
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2336
    "
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2337
     argument is not an integer
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2338
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2339
    (ioctlNumber isMemberOf:SmallInteger) ifFalse:[^ self primitiveFailed].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2340
    "
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2341
     the system does not support ioctl (MSDOS or VMS)
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2342
    "
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2343
    ^ self errorUnsupportedOperation
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2344
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2345
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2346
open
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2347
    "open the stream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2348
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2349
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2350
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2351
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2352
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2353
position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2354
    "return the position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2355
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2356
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2357
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2358
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2359
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2360
position:anInteger
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2361
    "set the position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2362
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2363
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2364
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2365
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2366
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2367
reset
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2368
    "set the read position to the beginning of the collection"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2369
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2370
    self position:"0" 1
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2371
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2372
1044
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2373
setToEnd
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2374
    "redefined since it must be implemented differently"
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2375
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2376
    ^ self subclassResponsibility
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2377
!
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2378
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2379
truncateTo:newSize
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2380
    "truncate the underlying OS file to newSize.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2381
     Warning: this may not be implemented on all platforms."
1066
cffbbdea7e01 care for GC while being interruptable
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2382
1068
92fdcccf12a3 alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  2383
%{
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2384
#ifdef HAS_FTRUNCATE
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2385
    FILEPOINTER f;
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2386
    OBJ fp;
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2387
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2388
    if (((fp = __INST(filePointer)) != nil)
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2389
     && (__INST(mode) != @symbol(readonly))) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2390
	if (__isSmallInteger(newSize)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2391
	    f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2392
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2393
	    if (__INST(buffered) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2394
		__READING__(f)
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2395
		FFLUSH(f);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2396
		OPT_FSEEK(f, 0L, SEEK_END); /* needed in stdio */
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2397
	    }
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2398
	    ftruncate(fileno(f), __intVal(newSize));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2399
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2400
	}
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2401
    }
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2402
#endif
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2403
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2404
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2405
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2406
    self errorUnsupportedOperation
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2407
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2408
    "
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2409
     |s|
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2410
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2411
     s := 'test' asFilename writeStream.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2412
     s next:1000 put:$a.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2413
     s truncateTo:100.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2414
     s close.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2415
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2416
     ('test' asFilename fileSize) printNL
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2417
    "
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2418
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2419
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2420
!ExternalStream methodsFor:'non homogenous reading'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2421
3674
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2422
nextAvailable:count
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2423
    "return the next count elements of the stream as aCollection.
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2424
     If the stream reaches the end before count elements have been read,
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2425
     return what is available. (i.e. a shorter collection).
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2426
     The type of collection is specified in #contentsSpecies."
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2427
3956
51f1a9a4d63f changes for egcs (stdio uses __new / utsname)
Claus Gittinger <cg@exept.de>
parents: 3949
diff changeset
  2428
    |buffer n|
3674
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2429
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2430
    binary ifTrue:[
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2431
	buffer := ByteArray new:count
3674
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2432
    ] ifFalse:[
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2433
	buffer := String new:count
3674
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2434
    ].
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2435
    n := self nextAvailableBytes:count into:buffer startingAt:1.
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2436
    n == 0 ifTrue:[^ nil].
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2437
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2438
    n ~~ count ifTrue:[
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2439
	^ buffer copyTo:n
3674
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2440
    ].
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2441
    ^ buffer.
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2442
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2443
    "
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2444
     (ReadStream on:#(1 2 3 4 5)) nextAvailable:3 
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2445
     (ReadStream on:#(1 2 3 4 5)) nextAvailable:10 
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2446
     (ReadStream on:'hello') nextAvailable:3
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2447
     (ReadStream on:'hello') nextAvailable:10 
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2448
    "
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2449
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2450
    "Modified: / 16.6.1998 / 15:52:41 / cg"
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2451
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2452
!
c51550d1df17 added #nextAvailable:
Claus Gittinger <cg@exept.de>
parents: 3672
diff changeset
  2453
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2454
nextAvailableBytes:count into:anObject startingAt:start
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2455
    "read the next count bytes into an object and return the number of
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2456
     bytes read or the number of bytes read, if EOF is encountered before,
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2457
     or no more bytes are available for reading (from the pipe/socket).
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2458
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2459
     If the receiver is some socket/pipe-like stream, an exception
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2460
     is raised if the connection is broken.
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2461
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2462
     Notice, that in contrast to other methods,
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2463
     this does NOT return nil on EOF, but the actual count.
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2464
     Thus allowing read of partial blocks.
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2465
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2466
     The object must have non-pointer indexed instvars 
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2467
     (i.e. it must be a ByteArray, String, Float- or DoubleArray).
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2468
     If anObject is a string or byteArray and reused, this provides the
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2469
     fastest possible physical I/O (since no new objects are allocated).
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2470
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2471
     Use with care - non object oriented I/O.
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2472
     Warning: in general, you cannot use this method to pass data from other 
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2473
     architectures since it does not care for byte order or float representation."
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2474
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2475
%{
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2476
    FILEPOINTER f;
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2477
    int cnt, offs, ret, _buffered;
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2478
    int objSize, nInstVars, nInstBytes;
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2479
    char *cp;
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2480
    char *extPtr;
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2481
    OBJ pos, fp, oClass;
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2482
    int o_offs;
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2483
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2484
    __INST(lastErrorNumber) = nil;
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2485
    if (((fp = __INST(filePointer)) != nil)
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2486
	&& (__INST(mode) != @symbol(writeonly))
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2487
	&& __bothSmallInteger(count, start)
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2488
    ) {
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2489
	f = __FILEVal(fp);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2490
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2491
	cnt = __intVal(count);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2492
	offs = __intVal(start) - 1;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2493
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2494
	oClass = __Class(anObject);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2495
	if (oClass == ExternalBytes) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2496
	    OBJ sz;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2497
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2498
	    nInstBytes = 0;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2499
	    extPtr = (char *)(__externalBytesAddress(anObject));
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2500
	    sz = __externalBytesSize(anObject);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2501
	    if (__isSmallInteger(sz)) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2502
		objSize = __intVal(sz);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2503
	    } else {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2504
		objSize = 0; /* unknown */
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2505
	    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2506
	} else {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2507
	    switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2508
		case BYTEARRAY:
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2509
		case WORDARRAY:
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2510
		case LONGARRAY:
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2511
		case SWORDARRAY:
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2512
		case SLONGARRAY:
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2513
		case FLOATARRAY:
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2514
		case DOUBLEARRAY:
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2515
		    break;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2516
		default:
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2517
		    goto bad;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2518
	    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2519
	    extPtr = (char *)0;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2520
	    nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2521
	    nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2522
	    objSize = __Size(anObject) - nInstBytes;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2523
	}
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2524
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2525
	if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2526
	    _buffered = (__INST(buffered) == true);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2527
	    if (_buffered) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2528
		__READING__(f);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2529
	    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2530
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2531
	    if (extPtr) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2532
		__READAVAILBYTES__(ret, f, extPtr+offs, cnt, _buffered);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2533
	    } else {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2534
		/*
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2535
		 * on interrupt, anObject may be moved to another location.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2536
		 * So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__,
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2537
		 * to get a new address.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2538
		 */
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2539
		offs += nInstBytes;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2540
		__READAVAILBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2541
	    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2542
	    if (ret > 0) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2543
		pos = __INST(position);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2544
		if (pos != nil) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2545
		    __INST(position) = __MKSMALLINT(__intVal(pos) + ret);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2546
		}
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2547
		RETURN (__MKSMALLINT(ret));
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2548
	    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2549
	    if (ret == 0) { 
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2550
		__INST(hitEOF) = true;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2551
	    } else /* ret < 0 */ {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2552
		__INST(position) = nil;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2553
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2554
	    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  2555
	}
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2556
    }
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2557
bad: ;
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2558
%}.
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2559
    (hitEOF and:[self pastEnd isNil]) ifTrue:[^ 0].
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2560
    lastErrorNumber notNil ifTrue:[^ self readError].
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2561
    filePointer isNil ifTrue:[^ self errorNotOpen].
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2562
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2563
    "
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2564
     count not integer or arg not bit-like (String, ByteArray etc)
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2565
    "
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2566
    ^ self primitiveFailed
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2567
!
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2568
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2569
nextByte
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2570
    "read the next byte and return it as an Integer; return nil on error.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2571
     This is allowed in both text and binary modes, always returning the
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2572
     bytes binary value as an integer in 0..255."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2573
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2574
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2575
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2576
    unsigned char byte;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2577
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2578
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2579
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2580
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2581
    if (((fp = __INST(filePointer)) != nil)
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2582
     && (__INST(mode) != @symbol(writeonly))) {
4383
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2583
        f = __FILEVal(fp);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2584
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2585
        _buffered = (__INST(buffered) == true);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2586
        if (_buffered) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2587
            __READING__(f)
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2588
        }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2589
        __READBYTE__(ret, f, &byte, _buffered);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2590
        if (ret > 0) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2591
            OBJ pos;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2592
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2593
            if ((pos = __INST(position)) != nil) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2594
                __INST(position) = __MKSMALLINT(__intVal(pos) + 1);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2595
            }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2596
            RETURN (__MKSMALLINT(byte));
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2597
        }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2598
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2599
        if (ret == 0) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2600
            __INST(hitEOF) = true;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2601
        } else /* ret < 0 */ {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2602
            __INST(position) = nil;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2603
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2604
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2605
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2606
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2607
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2608
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2609
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2610
    ^ self errorWriteOnly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2611
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2613
nextBytes:count into:anObject startingAt:start
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2614
    "read the next count bytes into an object and return the number of
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2615
     bytes read or the number of bytes read, if EOF is encountered before.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2616
     If the receiver is some socket/pipe-like stream, an exception
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2617
     is raised if the connection is broken.
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2618
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2619
     Warning: if used with a pipe/socket, this blocks until the requested number
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2620
     of bytes have been read. See #nextAvailableBytes:into:startingAt:
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2621
     to only read whats there.
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  2622
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2623
     Notice, that in contrast to other methods,
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2624
     this does NOT return nil on EOF, but the actual count.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2625
     Thus allowing read of partial blocks.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2626
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2627
     The object must have non-pointer indexed instvars 
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2628
     (i.e. it must be a ByteArray, String, Float- or DoubleArray),
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2629
     or an externalBytes object (with known size).
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2630
     If anObject is a string or byteArray and reused, this provides the
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2631
     fastest possible physical I/O (since no new objects are allocated).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2632
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2633
     Use with care - non object oriented I/O.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2634
     Warning: in general, you cannot use this method to pass data from other 
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2635
     architectures (unless you prepared the buffer with care),
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2636
     since it does not care for byte order or float representation."
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2637
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2638
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2639
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2640
    int cnt, offs, ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2641
    int objSize, nInstVars, nInstBytes;
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2642
    char *extPtr;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2643
    OBJ pos, fp, oClass;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2644
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2645
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2646
    if (((fp = __INST(filePointer)) != nil)
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2647
	&& (__INST(mode) != @symbol(writeonly))
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2648
	&& __bothSmallInteger(count, start)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2649
    ) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2650
	f = __FILEVal(fp);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2651
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2652
	cnt = __intVal(count);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2653
	offs = __intVal(start) - 1;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2654
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2655
	oClass = __Class(anObject);
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2656
	if (oClass == ExternalBytes) {
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2657
	    OBJ sz;
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2658
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2659
	    nInstBytes = 0;
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2660
	    extPtr = (char *)(__externalBytesAddress(anObject));
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2661
	    sz = __externalBytesSize(anObject);
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2662
	    if (__isSmallInteger(sz)) {
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2663
		objSize = __intVal(sz);
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2664
	    } else {
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2665
		objSize = 0; /* unknown */
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2666
	    }
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2667
	} else {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2668
	    switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2669
		case BYTEARRAY:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2670
		case WORDARRAY:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2671
		case LONGARRAY:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2672
		case SWORDARRAY:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2673
		case SLONGARRAY:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2674
		case FLOATARRAY:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2675
		case DOUBLEARRAY:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2676
		    break;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2677
		default:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2678
		    goto bad;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2679
	    }
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2680
	    extPtr = (char *)0;
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2681
	    nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2682
	    nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2683
	    objSize = __Size(anObject) - nInstBytes;
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2684
	}
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2685
	if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2686
	    _buffered = (__INST(buffered) == true);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2687
	    if (_buffered) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2688
		__READING__(f);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2689
	    }
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2690
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2691
	    if (extPtr) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2692
		__READBYTES__(ret, f, extPtr+offs, cnt, _buffered);
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2693
	    } else {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2694
		/*
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2695
		 * on interrupt, anObject may be moved to another location.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2696
		 * So we pass anObject, and the offset to the __READBYTES_OBJ__ macro.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2697
		 */
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2698
		offs += nInstBytes;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2699
		__READBYTES_OBJ__(ret, f, anObject, offs, cnt, _buffered);
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  2700
	    }
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2701
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2702
	    if (ret > 0) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2703
		pos = __INST(position);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2704
		if (pos != nil) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2705
		    __INST(position) = __MKSMALLINT(__intVal(pos) + ret);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2706
		}
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2707
		RETURN (__MKSMALLINT(ret));
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2708
	    }
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2709
	    if (ret == 0) { 
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2710
		__INST(hitEOF) = true;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2711
	    } else /* ret < 0 */ {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2712
		__INST(position) = nil;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2713
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2714
	    }
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  2715
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2716
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2717
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2718
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2719
    (hitEOF and:[self pastEnd isNil]) ifTrue:[^ 0].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2720
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2721
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2722
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2723
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2724
     count not integer or arg not bit-like (String, ByteArray etc)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2725
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2726
    ^ self primitiveFailed
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2727
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2728
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2729
nextLong
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2730
    "Read four bytes (msb-first) and return the value as a 32-bit signed Integer.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2731
     The returned value may be a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2732
     (msb-first for compatibility with other smalltalks)"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2733
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2734
    ^ self nextUnsignedLongMSB:true
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2735
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2736
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2737
nextLongMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2738
    "Read four bytes and return the value as a 32-bit signed Integer, 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2739
     which may be a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2740
     If msbFlag is true, value is read with most-significant byte first, 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2741
     otherwise least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2742
     A nil is returned, if EOF is hit before all 4 bytes have been read.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2743
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2744
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2745
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2746
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2747
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2748
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2749
    if (((fp = __INST(filePointer)) != nil)
4383
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2750
        && (__INST(mode) != @symbol(writeonly))
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2751
    ) {
4383
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2752
        FILEPOINTER f;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2753
        int ret, _buffered;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2754
        int value;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2755
        union {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2756
            unsigned char buffer[4];
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2757
            int intVal;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2758
        } u;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2759
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2760
        f = __FILEVal(fp);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2761
        _buffered = (__INST(buffered) == true);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2762
        if (_buffered) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2763
            __READING__(f)
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2764
        }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2765
        __READBYTES__(ret, f, u.buffer, 4, _buffered);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2766
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2767
        if (ret == 4) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2768
            OBJ pos;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2769
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2770
            if ((pos = __INST(position)) != nil) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2771
                __INST(position) = __MKSMALLINT(__intVal(pos) + 4);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2772
            }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2773
            if (msbFlag == true) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2774
#if defined(__MSBFIRST)
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2775
                value = u.intVal;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2776
#else
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2777
                value = (u.buffer[0] & 0xFF);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2778
                value = (value << 8) | (u.buffer[1] & 0xFF);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2779
                value = (value << 8) | (u.buffer[2] & 0xFF);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2780
                value = (value << 8) | (u.buffer[3] & 0xFF);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2781
#endif
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2782
            } else {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2783
#if defined(__LSBFIRST)
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2784
                value = u.intVal;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2785
#else
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2786
                value = (u.buffer[3] & 0xFF);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2787
                value = (value << 8) | (u.buffer[2] & 0xFF);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2788
                value = (value << 8) | (u.buffer[1] & 0xFF);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2789
                value = (value << 8) | (u.buffer[0] & 0xFF);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2790
#endif
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2791
            }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2792
#ifdef alpha64
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2793
            RETURN ( __MKSMALLINT(value));
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2794
#else
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2795
            if ((value >= _MIN_INT) && (value <= _MAX_INT)) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2796
                RETURN ( __MKSMALLINT(value));
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2797
            }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2798
            RETURN ( __MKLARGEINT(value) );
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2799
#endif
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2800
        }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2801
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2802
        if (ret < 0) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2803
            __INST(position) = nil;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2804
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2805
        } else /* ret == 0 */ {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2806
            __INST(hitEOF) = true;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2807
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2808
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2809
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2810
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2811
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2812
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2813
    ^ self readError.
1079
d47cd86b487b Make methods signal-proof.
Stefan Vogel <sv@exept.de>
parents: 1068
diff changeset
  2814
362
claus
parents: 360
diff changeset
  2815
!
claus
parents: 360
diff changeset
  2816
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2817
nextShortMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2818
    "Read two bytes and return the value as a 16-bit signed Integer.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2819
     If msbFlag is true, value is read with most-significant byte first, 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2820
     otherwise least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2821
     A nil is returned if EOF is reached (also when EOF is hit after the first byte).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2822
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2823
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2824
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2825
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2826
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2827
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2828
    if (((fp = __INST(filePointer)) != nil)
4383
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2829
        && (__INST(mode) != @symbol(writeonly))
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2830
    ) {
4383
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2831
        FILEPOINTER f;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2832
        int ret, _buffered;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2833
        short value;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2834
        union {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2835
            unsigned char buffer[2];
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2836
            short shortVal;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2837
        } u;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2838
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2839
        f = __FILEVal(fp);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2840
        _buffered = (__INST(buffered) == true);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2841
        if (_buffered) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2842
            __READING__(f)
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2843
        }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2844
        __READBYTES__(ret, f, u.buffer, 2, _buffered);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2845
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2846
        if (ret == 2) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2847
            OBJ pos;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2848
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2849
            if ((pos = __INST(position)) != nil) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2850
                __INST(position) = __MKSMALLINT(__intVal(pos) + 2);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2851
            }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2852
            if (msbFlag == true) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2853
#if defined(__MSBFIRST)
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2854
                value = u.shortVal;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2855
#else
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2856
                value = ((u.buffer[0] & 0xFF) << 8) | (u.buffer[1] & 0xFF);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2857
#endif
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2858
            } else {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2859
#if defined(__LSBFIRST)
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2860
                value = u.shortVal;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2861
#else
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2862
                value = ((u.buffer[1] & 0xFF) << 8) | (u.buffer[0] & 0xFF);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2863
#endif
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2864
            }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2865
            RETURN (__MKSMALLINT(value));
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2866
        }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2867
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2868
        if (ret < 0) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2869
            __INST(position) = nil;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2870
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2871
        } else /* ret == 0 */ {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2872
            __INST(hitEOF) = true;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2873
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2874
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2875
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2876
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2877
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2878
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2879
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2880
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2881
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2882
nextUnsignedLongMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2883
    "Read four bytes and return the value as a 32-bit unsigned Integer, which may be
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2884
     a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2885
     If msbFlag is true, value is read with most-significant byte first, otherwise
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2886
     least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2887
     A nil is returned, if endOfFile occurs before all 4 bytes have been read.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2888
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2889
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2890
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2891
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2892
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2893
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2894
    if (((fp = __INST(filePointer)) != nil)
4383
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2895
        && (__INST(mode) != @symbol(writeonly))
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2896
    ) {
4383
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2897
        FILEPOINTER f;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2898
        int ret, _buffered;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2899
        unsigned INT value;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2900
        union {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2901
            unsigned char buffer[4];
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2902
            unsigned int intVal;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2903
        } u;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2904
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2905
        f = __FILEVal(fp);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2906
        _buffered = (__INST(buffered) == true);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2907
        if (_buffered) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2908
            __READING__(f)
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2909
        }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2910
        __READBYTES__(ret, f, u.buffer, 4, _buffered);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2911
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2912
        if (ret == 4) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2913
            OBJ pos;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2914
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2915
            if ((pos = __INST(position)) != nil) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2916
                __INST(position) = __MKSMALLINT(__intVal(pos) + 4);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2917
            }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2918
            if (msbFlag == true) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2919
#if defined(__MSBFIRST)
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2920
                value = u.intVal;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2921
#else
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2922
                value = u.buffer[0];
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2923
                value = (value << 8) | u.buffer[1];
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2924
                value = (value << 8) | u.buffer[2];
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2925
                value = (value << 8) | u.buffer[3];
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2926
#endif
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2927
            } else {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2928
#if defined(__LSBFIRST)
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2929
                value = u.intVal;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2930
#else
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2931
                value = u.buffer[3];
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2932
                value = (value << 8) | u.buffer[2];
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2933
                value = (value << 8) | u.buffer[1];
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2934
                value = (value << 8) | u.buffer[0];
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2935
#endif
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2936
            }
3456
0cdf451360b9 oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents: 3445
diff changeset
  2937
#ifdef alpha64
4383
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2938
            value &= 0xFFFFFFFF;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2939
            RETURN (__MKSMALLINT(value));
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2940
#else
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2941
            if (value <= _MAX_INT) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2942
                RETURN (__MKSMALLINT(value));
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2943
            }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2944
            RETURN (__MKULARGEINT(value) );
3456
0cdf451360b9 oops - nextUnsignedLong:MSB: on alpha.
Claus Gittinger <cg@exept.de>
parents: 3445
diff changeset
  2945
#endif
4383
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2946
        }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2947
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2948
        if (ret < 0) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2949
            __INST(position) = nil;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2950
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2951
        } else /* ret == 0 */ {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2952
            __INST(hitEOF) = true;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2953
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2954
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2955
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2956
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2957
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2958
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2959
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2960
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2961
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2962
nextUnsignedShortMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2963
    "Read two bytes and return the value as a 16-bit unsigned Integer.
1079
d47cd86b487b Make methods signal-proof.
Stefan Vogel <sv@exept.de>
parents: 1068
diff changeset
  2964
     If msbFlag is true, value is read with most-significant byte first, 
d47cd86b487b Make methods signal-proof.
Stefan Vogel <sv@exept.de>
parents: 1068
diff changeset
  2965
     otherwise least-significant byte comes first.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2966
     A nil is returned if EOF is reached (also when EOF is hit after the first byte).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2967
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2968
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2969
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2970
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2971
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2972
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2973
    if (((fp = __INST(filePointer)) != nil)
4383
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2974
        && (__INST(mode) != @symbol(writeonly))
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2975
    ) {
4383
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2976
        FILEPOINTER f;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2977
        int ret, _buffered;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2978
        unsigned int value;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2979
        union {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2980
            unsigned char buffer[2];
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2981
            unsigned short shortVal;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2982
        } u;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2983
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2984
        f = __FILEVal(fp);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2985
        _buffered = (__INST(buffered) == true);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2986
        if (_buffered) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2987
            __READING__(f)
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2988
        }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2989
        __READBYTES__(ret, f, u.buffer, 2, _buffered);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2990
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2991
        if (ret == 2) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2992
            OBJ pos;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2993
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2994
            if ((pos = __INST(position)) != nil) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2995
                __INST(position) = __MKSMALLINT(__intVal(pos) + 2);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2996
            }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2997
            if (msbFlag == true) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2998
#if defined(__MSBFIRST)
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  2999
                value = u.shortVal;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3000
#else
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3001
                value = (u.buffer[0] << 8) | u.buffer[1];
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3002
#endif
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3003
            } else {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3004
#if defined(__LSBFIRST)
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3005
                value = u.shortVal;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3006
#else
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3007
                value = (u.buffer[1] << 8) | u.buffer[0];
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3008
#endif
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3009
            }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3010
            RETURN (__MKSMALLINT(value));
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3011
        }
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3012
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3013
        if (ret < 0) {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3014
            __INST(position) = nil;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3015
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3016
        } else /* ret == 0 */ {
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3017
            __INST(hitEOF) = true;
7a5abc09fb39 slightly tuned nextXXXLongMSB: and nextUnsignedXXXMSB:
Claus Gittinger <cg@exept.de>
parents: 4368
diff changeset
  3018
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3019
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3020
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3021
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3022
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3023
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3024
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3025
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3026
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3027
nextWord
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3028
    "in text-mode:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3029
	 read the alphaNumeric next word (i.e. up to non letter-or-digit).
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3030
	 return a string containing those characters.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3031
     in binary-mode:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3032
	 read two bytes (msb-first) and return the value as a 16-bit 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3033
	 unsigned Integer (for compatibility with other smalltalks)"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3034
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3035
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3036
	^ self nextUnsignedShortMSB:true
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3037
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3038
    ^ self nextAlphaNumericWord
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3039
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3040
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3041
!ExternalStream methodsFor:'non homogenous writing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3042
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3043
nextPutByte:aByteValue
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3044
    "write a byte.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3045
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3046
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3047
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3048
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3049
    char c;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3050
    OBJ pos, fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3051
    int cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3052
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3053
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3054
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3055
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3056
	&& __isSmallInteger(aByteValue)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3057
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3058
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3059
	c = __intVal(aByteValue);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3060
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3061
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3062
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3063
	} 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3064
	__WRITEBYTE__(cnt, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3065
	if (cnt == 1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3066
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3067
	    if (pos != nil)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3068
		__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3069
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3070
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3071
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3072
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3073
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3074
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3075
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3076
    self writeError.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3077
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3078
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3079
nextPutBytes:count from:anObject startingAt:start
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3080
    "write count bytes from an object starting at index start.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3081
     return the number of bytes written - which could be 0.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3082
     The object must have non-pointer indexed instvars 
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3083
     (i.e. be a ByteArray, String, Float- or DoubleArray),
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3084
     or an externalBytes object (with known size).
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3085
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3086
     Use with care - non object oriented i/o.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3087
     Warning: in general, you cannot use this method to pass data to other 
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3088
     architectures (unless you prepared the buffer with care),
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3089
     since it does not care for byte order or float representation."
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3090
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3091
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3092
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3093
    int cnt, len, offs, ret;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3094
    int objSize, nInstVars, nInstBytes, _buffered;
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3095
    char *extPtr;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3096
    OBJ oClass, pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3097
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3098
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3099
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3100
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3101
	&& __bothSmallInteger(count, start)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3102
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3103
	len = __intVal(count);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3104
	offs = __intVal(start) - 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3105
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3106
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3107
	oClass = __Class(anObject);
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3108
	if (oClass == ExternalBytes) {
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3109
	    OBJ sz;
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3110
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3111
	    nInstBytes = 0;
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3112
	    extPtr = (char *)__externalBytesAddress(anObject);
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3113
	    sz = __externalBytesSize(anObject);
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3114
	    if (__isSmallInteger(sz)) {
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3115
		objSize = __intVal(sz);
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3116
	    } else {
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3117
		objSize = 0; /* unknown */
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3118
	    }
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3119
	} else {
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3120
	    switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3121
		case BYTEARRAY:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3122
		case WORDARRAY:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3123
		case LONGARRAY:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3124
		case SWORDARRAY:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3125
		case SLONGARRAY:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3126
		case FLOATARRAY:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3127
		case DOUBLEARRAY:
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3128
		    break;
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3129
		default:
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3130
		    goto bad;
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3131
	    }
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3132
	    extPtr = (char *)0;
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3133
	    nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3134
	    nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3135
	    objSize = __Size(anObject) - nInstBytes;
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3136
	}
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3137
	if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3138
	    if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3139
		__WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3140
	    }
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3141
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3142
	    if (extPtr) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3143
		__WRITEBYTES__(cnt, f, extPtr+offs, len, _buffered); 
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3144
	    } else {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3145
		/*
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3146
		 * on interrupt, anObject may be moved to another location.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3147
		 * So we pass anObject, and the offset to the __WRITEBYTES_OBJ__ macro.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3148
		 */
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3149
		offs += nInstBytes;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3150
		__WRITEBYTES_OBJ__(cnt, f, anObject, offs, len, _buffered); 
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3151
	    }
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  3152
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3153
	    if (cnt >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3154
		pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3155
		if (pos != nil)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3156
		    __INST(position) = __MKSMALLINT(__intVal(pos) + cnt);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3157
		RETURN ( __MKSMALLINT(cnt) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3158
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3159
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3160
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3161
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3162
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3163
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3164
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3165
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3166
    (mode == #readonly) ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3167
    ^ self primitiveFailed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3168
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3169
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3170
nextPutLong:aNumber MSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3171
    "Write the argument, aNumber as a long (four bytes). If msbFlag is
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3172
     true, data is written most-significant byte first; otherwise least
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3173
     first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3174
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3175
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3176
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3177
    int num;
4384
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3178
    union {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3179
        char bytes[4];
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3180
        int intVal;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3181
    } u;
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3182
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3183
    int cnt, _buffered;
4384
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3184
    OBJ fp;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3185
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3186
    __INST(lastErrorNumber) = nil;
4384
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3187
    if (__isSmallInteger(aNumber)) {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3188
        num = __intVal(aNumber);
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3189
    } else {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3190
#ifdef alpha64
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3191
        goto badArg;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3192
#else
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3193
        num = __longIntVal(aNumber);
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3194
        if (num == 0) {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3195
            num = __signedLongIntVal(aNumber);
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3196
            if (num == 0) {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3197
                /* bad arg or out-of-range integer  
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3198
                 * (handled by the fallBack code)
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3199
                 */
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3200
                goto badArg;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3201
            }
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3202
        }
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3203
#endif
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3204
    }
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3205
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3206
    if (((fp = __INST(filePointer)) != nil)
4384
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3207
     && (__INST(mode) != @symbol(readonly))
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3208
    ) {
4384
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3209
        if (msbFlag == true) {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3210
#if defined(__MSBFIRST)
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3211
            u.intVal = num;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3212
#else
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3213
            u.bytes[0] = (num >> 24) & 0xFF;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3214
            u.bytes[1] = (num >> 16) & 0xFF;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3215
            u.bytes[2] = (num >> 8) & 0xFF;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3216
            u.bytes[3] = num & 0xFF;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3217
#endif
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3218
        } else {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3219
#if defined(__LSBFIRST)
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3220
            u.intVal = num;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3221
#else
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3222
            u.bytes[3] = (num >> 24) & 0xFF;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3223
            u.bytes[2] = (num >> 16) & 0xFF;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3224
            u.bytes[1] = (num >> 8) & 0xFF;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3225
            u.bytes[0] = num & 0xFF;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3226
#endif
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3227
        }
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3228
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3229
        f = __FILEVal(fp);
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3230
        if (_buffered = (__INST(buffered) == true)) {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3231
            __WRITING__(f)
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3232
        } 
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3233
        __WRITEBYTES__(cnt, f, u.bytes, 4, _buffered);
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3234
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3235
        if (cnt == 4) {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3236
            OBJ pos;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3237
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3238
            if ((pos = __INST(position)) != nil) {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3239
                __INST(position) = __MKSMALLINT(__intVal(pos) + 4);
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3240
            }
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3241
            RETURN ( self );
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3242
        }
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3243
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3244
    }
4384
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3245
badArg: ;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3246
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3247
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3248
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3249
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3250
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3251
    aNumber isInteger ifTrue:[
4384
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3252
        ^ super nextPutLong:aNumber MSB:msbFlag
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3253
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3254
    self argumentMustBeInteger
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3255
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3256
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3257
nextPutShort:aNumber MSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3258
    "Write the argument, aNumber as a short (two bytes). If msbFlag is
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3259
     true, data is written most-significant byte first; otherwise least
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3260
     first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3261
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3262
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3263
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3264
    int num;
4384
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3265
    union {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3266
        char bytes[2];
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3267
        short shortVal;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3268
    } u;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3269
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3270
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3271
    int cnt, _buffered;
4384
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3272
    OBJ fp;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3273
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3274
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3275
    if (((fp = __INST(filePointer)) != nil)
4384
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3276
        && (__INST(mode) != @symbol(readonly))
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3277
        && __isSmallInteger(aNumber)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3278
    ) {
4384
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3279
        num = __intVal(aNumber);
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3280
        if (msbFlag == true) {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3281
#if defined(__MSBFIRST)
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3282
            u.shortVal = num;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3283
#else
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3284
            u.bytes[0] = (num >> 8) & 0xFF;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3285
            u.bytes[1] = num & 0xFF;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3286
#endif
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3287
        } else {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3288
#if defined(__LSBFIRST)
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3289
            u.shortVal = num;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3290
#else
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3291
            u.bytes[1] = (num >> 8) & 0xFF;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3292
            u.bytes[0] = num & 0xFF;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3293
#endif
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3294
        }
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3295
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3296
        f = __FILEVal(fp);
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3297
        if (_buffered = (__INST(buffered) == true)) {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3298
            __WRITING__(f)
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3299
        } 
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3300
        __WRITEBYTES__(cnt, f, u.bytes, 2, _buffered);
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3301
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3302
        if (cnt == 2) {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3303
            OBJ pos;
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3304
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3305
            if ((pos = __INST(position)) != nil) {
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3306
                __INST(position) = __MKSMALLINT(__intVal(pos) + 2);
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3307
            }
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3308
            RETURN ( self );
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3309
        }
f8e779b99b14 slightly tuned nextPutLongMSB: and nextPutShortMSB:
Claus Gittinger <cg@exept.de>
parents: 4383
diff changeset
  3310
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3311
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3312
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3313
    lastErrorNumber notNil ifTrue:[^ self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3314
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3315
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3316
    self argumentMustBeInteger
10
claus
parents: 5
diff changeset
  3317
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3318
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3319
!ExternalStream methodsFor:'private'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3320
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3321
clearEOF
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3322
    hitEOF := false
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3323
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3324
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3325
connectTo:aFileDescriptor withMode:openmode
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3326
    "connect a fileDescriptor; openmode is the string defining the way to open.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3327
     This can be used to connect an extrnally provided fileDescriptor (from
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3328
     primitive code) or a pipeFileDescriptor (as returned by makePipe) to
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3329
     a Stream object. 
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3330
     The openMode ('r', 'w' etc.) must match the mode in which
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3331
     the fileDescriptor was originally opened (otherwise i/o errors will be reported later)."
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3332
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3333
    |retVal|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3334
4526
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3335
    filePointer notNil ifTrue:[^ self errorAlreadyOpen].
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3336
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3337
    FILEPOINTER f;
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3338
    OBJ fp;
2765
a56668774ad7 more alpha64 fixes
Claus Gittinger <cg@exept.de>
parents: 2764
diff changeset
  3339
    FILE *fdopen();
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3340
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3341
    if (__isSmallInteger(aFileDescriptor) 
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3342
     && (__qClass(openmode)== @global(String))) {
4526
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3343
        f = (FILEPOINTER) fdopen(__intVal(aFileDescriptor), (char *)__stringVal(openmode));
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3344
        if (f == NULL) {
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3345
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3346
            __INST(position) = nil;
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3347
        } else {
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3348
            __INST(filePointer) = fp = __MKFILEPOINTER(f); __STORE(self, fp);
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3349
            __INST(position) = __MKSMALLINT(1);
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3350
            retVal = self;
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3351
        }
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3352
    }
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3353
%}.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3354
    retVal notNil ifTrue:[
4526
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3355
        buffered := true.       "default is buffered"
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3356
        Lobby register:self
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3357
    ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3358
    lastErrorNumber notNil ifTrue:[
4526
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3359
        "
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3360
         the open failed for some reason ...
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3361
        "
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  3362
        ^ self openError
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3363
    ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3364
    ^ retVal
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3365
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  3366
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3367
open:aPath withMode:mode
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3368
    "low level open; opens the file/device and sets the filePointer instance
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3369
     variable. Careful: this does not care for any other state."
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3370
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3371
    |ok|
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3372
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3373
    ok := false.
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3374
%{
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3375
    FILE *f; 
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3376
    OBJ fp;
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3377
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3378
    if (__isString(aPath)) { 
4456
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3379
        __BEGIN_INTERRUPTABLE__
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3380
        do {
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3381
            f = fopen((char *) __stringVal(aPath), (char *) __stringVal(mode));
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3382
        } while ((f == NULL) && (errno == EINTR));
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3383
        __END_INTERRUPTABLE__
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3384
        if (f == NULL) {
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3385
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3386
        } else {
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3387
            __INST(filePointer) = fp = __MKFILEPOINTER(f); __STORE(self, fp);
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3388
            ok = true;
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3389
        }
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3390
    }
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3391
%}.
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3392
    ok ifFalse:[
4456
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3393
        "
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3394
         the open failed for some reason ...
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3395
        "
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3396
        ^ self openError
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3397
    ].
914ce6ac4052 initialize position
Claus Gittinger <cg@exept.de>
parents: 4384
diff changeset
  3398
    position := 1.
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3399
    Lobby register:self. 
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3400
!
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  3401
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3402
reOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3403
    "sent after snapin to reopen streams.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3404
     cannot reopen here since I am abstract and have no device knowledge"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3405
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  3406
    self class name errorPrint. ' [warning]: automatic reOpen not supported - stream closed' errorPrintCR.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3407
    filePointer := nil.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3408
    Lobby unregister:self.
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  3409
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  3410
    "Modified: 10.1.1997 / 17:50:44 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3411
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3412
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3413
setLastError:aNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3414
    lastErrorNumber := aNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3415
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3416
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3417
!ExternalStream methodsFor:'queries'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3418
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3419
isBinary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3420
    "return true, if the stream is in binary (as opposed to text-) mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3421
     The default when created is false."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3422
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3423
    ^ binary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3424
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3425
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3426
isExternalStream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3427
    "return true, if the receiver is some kind of externalStream;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3428
     true is returned here - the method redefined from Object."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3429
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3430
    ^ true
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3431
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3432
3863
af67e6995a4a added #isOpen query
Claus Gittinger <cg@exept.de>
parents: 3682
diff changeset
  3433
isOpen 
af67e6995a4a added #isOpen query
Claus Gittinger <cg@exept.de>
parents: 3682
diff changeset
  3434
    "return true, if this stream is open"
af67e6995a4a added #isOpen query
Claus Gittinger <cg@exept.de>
parents: 3682
diff changeset
  3435
af67e6995a4a added #isOpen query
Claus Gittinger <cg@exept.de>
parents: 3682
diff changeset
  3436
    ^ filePointer notNil
af67e6995a4a added #isOpen query
Claus Gittinger <cg@exept.de>
parents: 3682
diff changeset
  3437
!
af67e6995a4a added #isOpen query
Claus Gittinger <cg@exept.de>
parents: 3682
diff changeset
  3438
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3439
isReadable 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3440
    "return true, if this stream can be read from"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3441
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3442
    ^ (mode ~~ #writeonly)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3443
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3444
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3445
isWritable 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3446
    "return true, if this stream can be written to"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3447
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3448
    ^ (mode ~~ #readonly)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3449
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3450
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3451
!ExternalStream methodsFor:'reading'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3452
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3453
next
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3454
    "return the next element; advance read position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3455
     In binary mode, an integer is returned, otherwise a character.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3456
     If there are no more elements, nil is returned."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3457
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3458
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3459
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3460
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3461
    OBJ pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3462
    unsigned char ch;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3463
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3464
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3465
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3466
	&& (__INST(mode) != @symbol(writeonly))
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3467
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3468
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3469
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3470
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3471
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3472
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3473
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3474
	__READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3475
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3476
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3477
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3478
	    if (__isSmallInteger(pos)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3479
		__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3480
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3481
		__INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3482
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3483
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3484
		RETURN ( __MKSMALLINT(ch) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3485
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3486
	    RETURN ( __MKCHARACTER(ch) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3487
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3488
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3489
	__INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3490
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3491
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3492
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3493
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3494
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3495
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3496
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3497
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3498
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3499
    filePointer isNil ifTrue:[^ self errorNotOpen].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3500
    ^ self errorWriteOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3501
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3502
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3503
next:count
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3504
    "return the next count elements of the stream as a collection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3505
     Redefined to return a String or ByteArray instead of the default: Array."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3506
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  3507
    |coll nRead|
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3508
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3509
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3510
	coll := ByteArray uninitializedNew:count
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3511
    ] ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3512
	coll := String new:count
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3513
    ].
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  3514
    nRead := self nextBytes:count into:coll startingAt:1.
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  3515
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  3516
    "/ for readStream protocol compatibility, 
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  3517
    "/ we must raise an exception here.
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  3518
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  3519
    nRead < count ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3520
	^ self pastEnd
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  3521
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3522
    ^ coll
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  3523
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  3524
    "Modified: 11.1.1997 / 17:44:17 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3525
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3526
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3527
peek
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3528
    "return the element to be read next without advancing read position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3529
     In binary mode, an integer is returned, otherwise a character.
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  3530
     If there are no more elements, nil is returned."
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3531
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3532
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3533
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3534
    unsigned char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3535
    int ret, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3536
    OBJ fp;
3672
49dff0652a2c fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents: 3569
diff changeset
  3537
    OBJ ra;
49dff0652a2c fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents: 3569
diff changeset
  3538
49dff0652a2c fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents: 3569
diff changeset
  3539
    if ((ra = __INST(readAhead)) != nil) {
49dff0652a2c fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents: 3569
diff changeset
  3540
	if (__INST(binary) == true) {
49dff0652a2c fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents: 3569
diff changeset
  3541
	    RETURN ( ra );
49dff0652a2c fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents: 3569
diff changeset
  3542
	}
49dff0652a2c fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents: 3569
diff changeset
  3543
	c = __intVal(ra);
49dff0652a2c fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents: 3569
diff changeset
  3544
	RETURN ( __MKCHARACTER(c) );
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3545
    }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3546
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3547
    __INST(lastErrorNumber) = nil;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3548
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3549
    if (((fp = __INST(filePointer)) != nil)
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3550
	&& (__INST(mode) != @symbol(writeonly))
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3551
    ) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3552
	f = __FILEVal(fp);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3553
	_buffered = (__INST(buffered) == true);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3554
	if (_buffered) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3555
	    __READING__(f)
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3556
	}
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3557
	__READBYTE__(ret, f, &c, _buffered);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3558
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3559
	if (ret > 0) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3560
	    __UNGETC__(c, f, _buffered);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3561
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3562
	    if (__INST(binary) == true) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3563
		RETURN ( __MKSMALLINT(c) );
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3564
	    }
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3565
	    RETURN ( __MKCHARACTER(c) );
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3566
	}
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3567
	if (ret < 0) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3568
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3569
	} else /* ret == 0 */ {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3570
	    __INST(hitEOF) = true;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3571
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3572
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3573
%}.
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3574
    hitEOF ifTrue:[^ self pastEnd]. 
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3575
    lastErrorNumber notNil ifTrue:[^ self readError].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3576
    filePointer isNil ifTrue:[^ self errorNotOpen].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3577
    ^ self errorWriteOnly
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  3578
!
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  3579
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  3580
upToEnd
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  3581
    "return a collection of the elements up-to the end.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  3582
     Return nil if the stream-end is reached before."
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  3583
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  3584
    |answerStream ch|
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  3585
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  3586
    answerStream := WriteStream on:(self contentsSpecies new).
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  3587
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3588
	ch := self next.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3589
	ch notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3590
	    answerStream nextPut:ch
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3591
	]
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  3592
    ].
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  3593
    ^ answerStream contents
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  3594
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  3595
    "Created: 25.4.1996 / 14:40:31 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3596
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3597
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3598
!ExternalStream methodsFor:'reimplemented for speed'!
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3599
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3600
nextAlphaNumericWord
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3601
    "read the next word (i.e. up to non letter-or-digit) after first
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3602
     skipping any whiteSpace.
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3603
     Return a string containing those characters.
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3604
     There is a limit of 1023 characters in the word - if longer,
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3605
     it is truncated."
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3606
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3607
%{  /* STACK: 2000 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3608
    FILEPOINTER f;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3609
    int len;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3610
    char buffer[1024];
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3611
    unsigned char ch;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3612
    int cnt = 0;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3613
    int ret, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3614
    OBJ fp;
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3615
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3616
    if (((fp = __INST(filePointer)) != nil)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3617
     && (__INST(mode) != @symbol(writeonly))
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3618
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3619
	f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3620
	_buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3621
	if (_buffered) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3622
	    __READING__(f)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3623
	}
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3624
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3625
	/*
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3626
	 * skip whiteSpace first ...
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3627
	 */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3628
	do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3629
	    __READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3630
	    if (ret > 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3631
		cnt++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3632
	    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3633
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3634
	} while (
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3635
#ifndef NON_ASCII
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3636
		 (ch < ' ') ||
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3637
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3638
		 (ch == ' ' ) || (ch == '\t') || (ch == '\r')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3639
	      || (ch == '\n') || (ch == 0x0b));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3640
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3641
	len = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3642
	while (ret > 0 && 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3643
	       (((ch >= 'a') && (ch <= 'z')) ||
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3644
		((ch >= 'A') && (ch <= 'Z')) ||
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3645
		((ch >= '0') && (ch <= '9')))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3646
	) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3647
	    buffer[len++] = ch;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3648
	    if (len >= (sizeof(buffer)-1)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3649
		/* emergency */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3650
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3651
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3652
	    __READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3653
	    if (ret > 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3654
		cnt++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3655
	    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3656
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3657
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3658
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3659
	if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3660
	    if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3661
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3662
		goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3663
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3664
	    else if (ret == 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3665
		__INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3666
	} else {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3667
	    __UNGETC__(ch, f, _buffered);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3668
	    cnt--;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3669
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3670
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3671
	if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3672
	    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + cnt);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3673
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3674
	if (len != 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3675
	    buffer[len] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3676
	    RETURN ( __MKSTRING_L(buffer, len) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3677
	}
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3678
    }
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3679
err: ;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3680
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3681
    hitEOF ifTrue:[^ self pastEnd].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3682
    lastErrorNumber notNil ifTrue:[^ self readError].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3683
    filePointer isNil ifTrue:[^ self errorNotOpen].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3684
    ^ self errorWriteOnly
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3685
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3686
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3687
nextChunk
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3688
    "return the next chunk, i.e. all characters up to the next
668
73165201a9da nextChunk: %{ is only recognized if at begin-of-line
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  3689
     exclamation mark. Within the chunk, exclamation marks have to be doubled -
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3690
     except within primitive code (this exception was added to make it easier
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3691
     to edit primitive code with external editors). This means, that other
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3692
     Smalltalks cannot always read chunks containing primitive code - but that
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3693
     doesnt really matter, since C-primitives are an ST/X feature anyway.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3694
     Reimplemented here for more speed."
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3695
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3696
    |retVal outOfMemory buffer|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3697
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3698
    filePointer isNil ifTrue:[^ self errorNotOpen].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3699
    binary ifTrue:[^ self errorBinary].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3700
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3701
2854
3c8bf66e4e7d give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents: 2766
diff changeset
  3702
%{  /* STACK: 12000 */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3703
    /*
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3704
     * the main trick (and a bit of complication) here
2874
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3705
     * is to read the first 8k into a stack-buffer.
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3706
     * Since most chunks fit into that, 
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3707
     * this avoids creating lots of garbage for thos small chunks.
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3708
     */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3709
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3710
    int nread = 0, done = 0;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3711
    unsigned char c, lastC, peekC;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3712
    int ret;
1823
51ffb7231437 type casts
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  3713
    unsigned char *bufferPtr = (unsigned char *)0;
2874
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3714
    unsigned char fastBuffer[8000];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3715
    REGISTER int index;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3716
    int currSize, fastFlag, _buffered;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3717
    int atBeginOfLine = 1, inPrimitive = 0;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3718
    int haveCR = 0, haveNL = 0;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3719
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3720
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3721
    f = __FILEVal(__INST(filePointer));
668
73165201a9da nextChunk: %{ is only recognized if at begin-of-line
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  3722
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3723
    _buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3724
    if (_buffered) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3725
	__READING__(f)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3726
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3727
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3728
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3729
     * skip spaces
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3730
     */
673
2c3a4a536cd1 oops - handling of exclas within primitives was wrong
Claus Gittinger <cg@exept.de>
parents: 671
diff changeset
  3731
    c = '\n';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3732
    while (! done) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3733
	lastC = c;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3734
	__READBYTE__(ret, f, &c, _buffered);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3735
	if (ret <= 0) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3736
	    goto err;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3737
	}
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3738
	nread++;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3739
	atBeginOfLine = 0;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3740
	switch (c) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3741
	    case '\n':
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3742
	    case ' ':
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3743
	    case '\t':
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3744
	    case '\r':
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3745
	    case '\b':
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3746
	    case '\014':
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3747
		break;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3748
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3749
	    default:
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3750
		atBeginOfLine = (lastC == '\n');
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3751
		done = 1;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3752
		break;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3753
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3754
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3755
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3756
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3757
     * read chunk into a buffer
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3758
     */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3759
    bufferPtr = fastBuffer; fastFlag = 1;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3760
    currSize = sizeof(fastBuffer);
362
claus
parents: 360
diff changeset
  3761
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3762
    index = 0;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3763
    for (;;) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3764
	__READBYTE__(ret, f, &peekC, _buffered);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3765
	if ((c == '%') && atBeginOfLine && ret > 0) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3766
	    if (peekC == '{') {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3767
		inPrimitive = 1;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3768
	    } else if (peekC == '}') {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3769
		inPrimitive = 0;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3770
	    }
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3771
	} else if (c == '!' && !inPrimitive) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3772
	    if (ret > 0 && peekC == '!') {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3773
		/*
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3774
		 * convert double-! to a single !
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3775
		 */
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3776
		__READBYTE__(ret, f, &peekC, _buffered);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3777
		if (ret > 0)
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3778
		    nread++;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3779
	    } else {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3780
		/*
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3781
		 * End of chunk, push back lookahead character
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3782
		 * and leave loop.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3783
		 */
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3784
		if (ret > 0) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3785
		    __UNGETC__(peekC, f, _buffered);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3786
		} else
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3787
		    ret = 1;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3788
		break; 
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3789
	    }
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3790
	}
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3791
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3792
	/* 
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3793
	 * do we have to resize the buffer ? 
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3794
	 */
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3795
	if ((index+2) >= currSize) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3796
	    OBJ newBuffer;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3797
	    unsigned char *nbp;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3798
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3799
	    newBuffer = __MKEMPTYSTRING(currSize * 2);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3800
	    if (!fastFlag) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3801
		/*
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3802
		 * refetch - buffer could be moved by GC
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3803
		 */
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3804
		bufferPtr = __stringVal(buffer);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3805
	    }
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3806
	    if (newBuffer == nil) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3807
		/*
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3808
		 * mhmh - chunk seems to be very big ....
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3809
		 */
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3810
		outOfMemory = true;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3811
		goto err;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3812
	    }
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3813
	    nbp = __stringVal(newBuffer);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3814
	    bcopy(bufferPtr, nbp, index);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3815
	    bufferPtr = nbp;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3816
	    bufferPtr[index] = '\0';
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3817
	    buffer = newBuffer;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3818
	    fastFlag = 0;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3819
	    currSize = currSize * 2;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3820
	}
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3821
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3822
	if (!fastFlag) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3823
	    /*
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3824
	     * old buffer may have moved (interrupt while reading)
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3825
	     * - refetch pointer
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3826
	     */
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3827
	    bufferPtr = __stringVal(buffer);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3828
	}
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3829
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3830
	/*
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3831
	 * filter out cr-nl; make it nl
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3832
	 */
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3833
	if (c == '\n') {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3834
	    haveNL = 1;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3835
	    if (index > 0) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3836
		if (bufferPtr[index-1] == '\r') {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3837
		    index--;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3838
		}
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3839
	    }
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3840
	} else {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3841
	    if (c == '\r') {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3842
		haveCR = 1;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3843
	    }
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3844
	}
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3845
	bufferPtr[index++] = c;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3846
	if (ret <= 0) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3847
	    if (ret == 0)
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3848
		break;          /* End of chunk reached */
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3849
	    goto err;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3850
	}
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3851
	nread++;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3852
	atBeginOfLine = (c == '\n');
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3853
	c = peekC;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3854
    }
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3855
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3856
    /*
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3857
     * care for CR-limited files.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3858
     * Replace CR's by NL's
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3859
     */
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3860
    if (!haveNL && haveCR) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3861
	int i;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3862
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3863
	for (i=index-1; i>=0; i--) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3864
	    if (bufferPtr[i] == '\r') {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3865
		bufferPtr[i] = '\n';
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3866
	    }
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3867
	}
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3868
    }
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3869
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3870
    /*
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3871
     * make it a string
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3872
     * be careful here - allocating a new string may make the
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3873
     * existing buffer move around. Need to check if copying from
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3874
     * fast (C) buffer or from real (ST) buffer.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3875
     */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3876
    if (fastFlag) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3877
	retVal = __MKSTRING_L(bufferPtr, index);
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3878
    } else {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3879
	retVal = __MKSTRING_ST_L(buffer, index);
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3880
    }
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3881
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  3882
err: ;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3883
    if (ret <= 0) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3884
	if (ret == 0)
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3885
	    __INST(hitEOF) = true;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3886
	else /* ret < 0 */
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3887
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3888
    }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3889
    if (__INST(position) != nil) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3890
	__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + nread);
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3891
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3892
%}.
370
claus
parents: 369
diff changeset
  3893
    retVal isNil ifTrue:[
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3894
	"/
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3895
	"/ arrive here with retVal==nil either on error or premature EOF
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3896
	"/ or if running out of malloc-memory
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3897
	"/
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3898
	hitEOF ifTrue:[^ self pastEnd].
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3899
	lastErrorNumber notNil ifTrue:[^ self readError].
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3900
	outOfMemory == true ifTrue:[
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3901
	    "
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3902
	     buffer memory allocation failed.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3903
	     When we arrive here, there was no memory available for the
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3904
	     chunk. (seems to be too big of a chunk ...)
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3905
	     Bad luck - you should increase the ulimit and/or swap space on your machine.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3906
	    "
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3907
	    ^ ObjectMemory allocationFailureSignal raise.
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3908
	]
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3909
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3910
    ^ retVal
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3911
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3912
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3913
nextMatchFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3914
    "skip all objects up-to and including anObject, return anObject on success,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3915
     nil if end-of-file is reached before. The next read operation will return
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3916
     the element after anObject.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3917
     Only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3918
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3919
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3920
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3921
    int ret, peekValue;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3922
    char c;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3923
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3924
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3925
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3926
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3927
	&& (__INST(mode) != @symbol(writeonly))
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3928
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3929
	if ((__INST(binary) == true) && __isSmallInteger(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3930
	    peekValue = __intVal(anObject) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3931
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3932
	    if ((__INST(binary) != true) && __isCharacter(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3933
		peekValue = __intVal(_characterVal(anObject)) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3934
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3935
		peekValue = -1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3936
	    }   
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3937
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3938
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3939
	if (peekValue >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3940
	    int _buffered;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3941
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3942
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3943
	    f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3944
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3945
	    if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3946
		__READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3947
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3948
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3949
	    for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3950
		__READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3951
		if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3952
		    if (ret < 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3953
			__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3954
		    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3955
			__INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3956
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3957
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3958
		if (c == peekValue) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3959
		    RETURN (anObject);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3960
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3961
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3962
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3963
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3964
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3965
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3966
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3967
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3968
    ^ super nextMatchFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3969
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3970
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3971
peekFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3972
    "return true and move past next element, if next == something.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3973
     Otherwise, stay and return false. False is also returned
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3974
     when EOF is encountered.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3975
     The argument must be an integer if in binary, a character if in
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3976
     text mode; only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3977
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3978
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3979
    FILEPOINTER f;
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3980
    unsigned char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3981
    int ret, peekValue, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3982
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3983
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3984
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3985
    if (((fp = __INST(filePointer)) != nil)
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3986
	&& (__INST(mode) != @symbol(writeonly))
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3987
    ) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3988
	if (__INST(binary) == true) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3989
	    if (__isSmallInteger(anObject)) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3990
		peekValue = __intVal(anObject) & 0xFF;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3991
	    } else {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3992
		goto bad;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3993
	    }
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3994
	} else {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3995
	    if (__isCharacter(anObject)) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3996
		peekValue = __intVal(_characterVal(anObject)) & 0xFF;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3997
	    } else {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3998
		goto bad;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  3999
	    }
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4000
	}
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4001
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4002
	f = __FILEVal(fp);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4003
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4004
	_buffered = (__INST(buffered) == true);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4005
	if (_buffered) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4006
	    __READING__(f)
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4007
	}
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4008
	__READBYTE__(ret, f, &c, _buffered);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4009
	if (ret > 0) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4010
	    if (c == peekValue) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4011
		OBJ pos;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4012
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4013
		if ((pos = __INST(position)) != nil) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4014
		    __INST(position) = __MKSMALLINT(__intVal(pos) + 1);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4015
		}
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4016
		RETURN (true);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4017
	    }
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4018
	    __UNGETC__(c, f, _buffered);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4019
	    RETURN (false);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4020
	} 
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4021
	if (ret < 0) {
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4022
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4023
	} else /* ret == 0 */
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4024
	    __INST(hitEOF) = true;
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4025
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4026
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4027
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4028
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  4029
    hitEOF ifTrue:[self pastEnd. ^ false].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4030
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4031
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4032
    ^ super peekFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4033
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4034
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4035
skipLine
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4036
    "read the next line (characters up to newline) skip only;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4037
     return nil if EOF reached, self otherwise. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4038
     Not allowed in binary mode."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4039
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4040
%{  /* STACK:2000 */
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4041
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  4042
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4043
    OBJ fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4044
    int ret, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4045
    char c;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4046
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4047
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4048
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4049
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4050
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4051
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4052
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4053
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4054
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4055
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4056
	for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4057
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4058
	    if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4059
		if (c == '\n')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4060
		    RETURN(self) 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4061
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4062
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4063
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4064
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4065
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4066
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4067
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4068
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4069
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4070
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  4071
    hitEOF ifTrue:[^ self pastEnd].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4072
    lastErrorNumber notNil ifTrue:[self readError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4073
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4074
    binary ifTrue:[self errorBinary. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4075
    self errorWriteOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4076
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4077
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4078
skipSeparators
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4079
    "skip all whitespace; next will return next non-white-space character
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4080
     or nil if endOfFile reached. Not allowed in binary mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4081
     - reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4082
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  4083
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  4084
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4085
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  4086
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4087
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4088
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4089
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4090
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4091
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4092
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4093
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4094
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4095
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4096
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4097
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4098
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4099
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4100
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4101
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4102
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4103
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4104
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4105
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4106
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4107
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4108
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4109
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4110
	    switch (c) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4111
		case ' ':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4112
		case '\t':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4113
		case '\n':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4114
		case '\r':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4115
		case '\b':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4116
		case '\f':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4117
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4118
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4119
		default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4120
		    __UNGETC__(c, f, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4121
		    RETURN ( __MKCHARACTER(c & 0xFF) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4122
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4123
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4124
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4125
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  4126
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4127
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4128
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4129
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4130
    ^ self errorBinary.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4131
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4132
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4133
skipSeparatorsExceptCR
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4134
    "skip all whitespace but no newlines;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4135
     next will return next non-white-space character
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4136
     or nil if endOfFile reached. Not allowed in binary mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4137
     - reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4138
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  4139
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  4140
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4141
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  4142
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4143
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4144
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4145
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4146
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4147
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4148
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4149
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4150
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4151
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4152
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4153
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4154
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4155
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4156
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4157
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4158
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4159
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4160
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4161
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4162
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4163
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4164
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4165
	    switch (c) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4166
		case ' ':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4167
		case '\t':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4168
		case '\b':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4169
		case '\f':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4170
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4171
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4172
		default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4173
		    __UNGETC__(c, f, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4174
		    RETURN ( __MKCHARACTER(c & 0xFF) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4175
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4176
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4177
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4178
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  4179
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4180
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4181
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4182
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4183
    ^ self errorBinary.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4184
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4185
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4186
skipThrough:aCharacter
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4187
    "skip all characters up-to and including aCharacter. Return the receiver if
671
53de87163ad5 spelling
Claus Gittinger <cg@exept.de>
parents: 668
diff changeset
  4188
     skip was successful, otherwise (i.e. if not found) return nil.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4189
     The next read operation will return the character after aCharacter.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4190
     The argument, aCharacter must be character, or integer when in binary mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4191
     Only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4192
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  4193
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  4194
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4195
    REGISTER int cSearch;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4196
    unsigned char c;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4197
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4198
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4199
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4200
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4201
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4202
	&& (__INST(mode) != @symbol(writeonly))
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4203
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4204
	if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4205
	    /* searched for object must be a smallInteger */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4206
	    if (! __isSmallInteger(aCharacter)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4207
	    cSearch = __intVal(aCharacter);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4208
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4209
	    /* searched for object must be a character */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4210
	    if (! __isCharacter(aCharacter)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4211
	    cSearch = __intVal(_characterVal(aCharacter));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4212
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4213
	/* Q: should we just say: "not found" ? */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4214
	if ((cSearch < 0) || (cSearch > 255)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4215
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4216
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4217
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4218
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4219
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4220
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4221
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4222
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4223
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4224
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4225
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4226
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4227
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4228
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4229
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4230
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4231
	    if (c == cSearch) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4232
		RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4233
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4234
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4235
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4236
badArgument: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4237
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  4238
    hitEOF ifTrue:[^ self pastEnd].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4239
    lastErrorNumber notNil ifTrue:[self readError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4240
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4241
    (mode == #writeonly) ifTrue:[self errorWriteOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4242
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4243
     argument must be integer/character in binary mode, 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4244
     character in text mode
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4245
    "
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4246
    self error:'invalid argument'.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4247
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4248
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4249
     |s|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4250
     s := 'Makefile' asFilename readStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4251
     s skipThrough:$=.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4252
     s next:10
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4253
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4254
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4255
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4256
skipToAll:aString
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4257
    "skip for the sequence given by the argument, aCollection;
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  4258
     return nil if not found, self otherwise. 
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  4259
     On a successful match, the next read will return characters of aString."
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4260
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4261
    |oldPos|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4262
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4263
    oldPos := self position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4264
    (self skipThroughAll:aString) isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4265
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4266
	 restore position
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4267
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4268
	self position:oldPos.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4269
	^ nil
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4270
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4271
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4272
     position before match-string
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4273
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4274
    self position:(self position - aString size).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4275
    ^ self
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4276
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4277
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4278
     |s|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4279
     s := 'Makefile' asFilename readStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4280
     s skipToAll:'are'.
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  4281
     s next:10 
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4282
    "
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  4283
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  4284
    "Modified: 26.6.1996 / 09:22:05 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4285
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4286
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4287
!ExternalStream methodsFor:'testing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4288
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4289
atEnd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4290
    "return true, if position is at end"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4291
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  4292
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  4293
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4294
    OBJ fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4295
    char c;
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  4296
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4297
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4298
    if (__INST(hitEOF) == true) {
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4299
	RETURN (true);
3906
7f2d4a3b63e2 oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents: 3878
diff changeset
  4300
    }
7f2d4a3b63e2 oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents: 3878
diff changeset
  4301
    if (__bothSmallInteger(__INST(position), __INST(readLimit))) {
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4302
	if (__intVal(__INST(position)) > __intVal(__INST(readLimit))) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4303
	    RETURN (true);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4304
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4305
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4306
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4307
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4308
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4309
    if ((fp = __INST(filePointer)) != nil) {
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4310
	f = __FILEVal(fp);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4311
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4312
	if (_buffered = (__INST(buffered) == true)) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4313
	    __READING__(f);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4314
	} else {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4315
	    if (__INST(readAhead) != nil) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4316
		RETURN (false);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4317
	    }
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4318
	}
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4319
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4320
	/*
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4321
	 * read ahead ...
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4322
	 */
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4323
	do {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4324
	    __BEGIN_INTERRUPTABLE__
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4325
	    __READBYTE__(ret, f, &c, _buffered);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4326
	    __END_INTERRUPTABLE__
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4327
	} while ((ret < 0) && (errno == EINTR));
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4328
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4329
	if (ret > 0) {
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4330
	    __UNGETC__(c&0xff, f, _buffered);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4331
	    RETURN (false);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4332
	}
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4333
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4334
	if (ret == 0) { 
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4335
	    __INST(hitEOF) = true;
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4336
	    RETURN (true);
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4337
	}
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4338
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4339
	/* ret < 0 */
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4340
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4341
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4342
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4343
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4344
    ^ self errorNotOpen
3906
7f2d4a3b63e2 oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents: 3878
diff changeset
  4345
7f2d4a3b63e2 oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents: 3878
diff changeset
  4346
    "Modified: / 30.10.1998 / 20:16:06 / cg"
7f2d4a3b63e2 oops - readLimit was not handled in #atEnd
Claus Gittinger <cg@exept.de>
parents: 3878
diff changeset
  4347
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4348
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4349
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4350
canReadWithoutBlocking
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4351
    "return true, if any data is available for reading (i.e.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4352
     a read operation will not block the smalltalk process), false otherwise."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4353
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4354
    |fd|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4355
2986
c6957cf6128f Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents: 2963
diff changeset
  4356
    readAhead notNil ifTrue:[^ true].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4357
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4358
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4359
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4360
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4361
    ^ OperatingSystem readCheck:fd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4362
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4363
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4364
     |pipe|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4365
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4366
     pipe := PipeStream readingFrom:'(sleep 10; echo hello)'.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4367
     pipe canReadWithoutBlocking ifTrue:[
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4368
	 Transcript showCR:'data available'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4369
     ] ifFalse:[
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4370
	 Transcript showCR:'no data available'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4371
     ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4372
     pipe close
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4373
    "
2986
c6957cf6128f Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents: 2963
diff changeset
  4374
c6957cf6128f Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents: 2963
diff changeset
  4375
    "Modified: 25.9.1997 / 13:08:45 / stefan"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4376
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4377
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4378
canWriteWithoutBlocking
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4379
    "return true, if data can be written into the stream 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4380
     (i.e. a write operation will not block the smalltalk process)."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4381
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4382
    |fd|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4383
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4384
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4385
    mode == #readonly ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4386
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4387
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4388
    ^ OperatingSystem writeCheck:fd
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4389
!
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4390
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4391
numAvailable
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4392
    "return the number of bytes available for reading"
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4393
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4394
    |fd|
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4395
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4396
    filePointer isNil ifTrue:[^ self errorNotOpen].
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4397
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4398
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4399
    fd := self fileDescriptor.
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4400
    ^ OperatingSystem numAvailableForReadOn:fd.
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4401
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4402
"/    self atEnd ifTrue:[^ 0].
3432
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  4403
"/    self canReadWithoutBlocking ifTrue:[
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  4404
"/        ^ 1
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  4405
"/    ].
1228d4ba9518 allow reading/writing from/to ExternalBytes
Claus Gittinger <cg@exept.de>
parents: 3420
diff changeset
  4406
"/    ^ 0
3274
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4407
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4408
    "Created: / 4.2.1998 / 16:56:01 / cg"
92a24829f14a added #nextAvailableBytes - very useful for pipes & sockets.
Claus Gittinger <cg@exept.de>
parents: 3255
diff changeset
  4409
    "Modified: / 4.2.1998 / 17:31:11 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4410
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4411
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4412
!ExternalStream methodsFor:'waiting for I/O'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4413
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4414
readWait
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4415
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4416
     becomes ready for reading. If data is already available,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4417
     return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4418
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4419
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4420
    self readWaitWithTimeoutMs:nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4421
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4422
3016
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  4423
readWaitTimeoutMs:timeout
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  4424
    "ST-80 compatibility"
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  4425
    ^ self readWaitWithTimeoutMs:timeout 
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  4426
!
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  4427
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4428
readWaitWithTimeout:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4429
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4430
     becomes ready for reading or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4431
     If data is already available, return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4432
     Return true if a timeout occured (i.e. false, if data is available).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4433
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4434
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4435
    ^ self readWaitWithTimeoutMs:timeout * 1000
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4436
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4437
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4438
readWaitWithTimeoutMs:timeout 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4439
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4440
     becomes ready for reading or a timeout (in milliseconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4441
     If data is already available, return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4442
     Return true if a timeout occured (i.e. false, if data is available).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4443
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4444
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4445
    |fd inputSema hasData wasBlocked|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4446
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  4447
    readAhead notNil ifTrue:[^ false].
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  4448
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4449
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4450
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4451
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4452
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4453
    (OperatingSystem readCheck:fd) ifTrue:[^ false].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4454
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4455
    wasBlocked := OperatingSystem blockInterrupts.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4456
    hasData := OperatingSystem readCheck:fd.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4457
    hasData ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4458
	inputSema := Semaphore new name:'readWait'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4459
	[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4460
	    timeout notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4461
		Processor signal:inputSema afterMilliseconds:timeout 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4462
	    ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4463
	    Processor signal:inputSema onInput:fd.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4464
	    Processor activeProcess state:#ioWait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4465
	    inputSema wait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4466
	    Processor disableSemaphore:inputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4467
	    hasData := OperatingSystem readCheck:fd
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4468
	] valueOnUnwindDo:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4469
	    Processor disableSemaphore:inputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4470
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4471
	]
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4472
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4473
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4474
    ^ hasData not
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4475
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4476
3490
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4477
readWriteWait
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4478
    "suspend the current process, until the receiver
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4479
     becomes ready for writing or reading.
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4480
     Return immediate if the receiver is already ready. 
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4481
     The other threads are not affected by the wait.
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4482
     This is actually only used with sockets, to wait for a connect to
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4483
     be finished."
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4484
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4485
    self readWriteWaitWithTimeoutMs:nil
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4486
!
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4487
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4488
readWriteWaitWithTimeoutMs:timeout
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4489
    "suspend the current process, until the receiver
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4490
     becomes ready for reading or writing or a timeout (in seconds) expired. 
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4491
     Return true if a timeout occured (i.e. false, if data is available).
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4492
     Return immediate if the receiver is already ready. 
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4493
     The other threads are not affected by the wait.
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4494
     This is actually only used with sockets, to wait for a connect to
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4495
     be finished."
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4496
3672
49dff0652a2c fixed readAhead in peek with non-binary mode
Claus Gittinger <cg@exept.de>
parents: 3569
diff changeset
  4497
    |fd sema canReadWrite wasBlocked|
3490
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4498
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4499
    filePointer isNil ifTrue:[
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4500
	^ self errorNotOpen
3490
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4501
    ].
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4502
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4503
    fd := self fileDescriptor.
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4504
    (OperatingSystem readWriteCheck:fd) ifTrue:[^ false].
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4505
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4506
    wasBlocked := OperatingSystem blockInterrupts.
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4507
    canReadWrite := OperatingSystem readWriteCheck:fd.
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4508
    canReadWrite ifFalse:[
4152
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4509
	sema := Semaphore new name:'readWriteWait'.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4510
	[
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4511
	    timeout notNil ifTrue:[
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4512
		Processor signal:sema afterMilliseconds:timeout
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4513
	    ].
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4514
	    Processor signal:sema onOutput:fd.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4515
	    Processor signal:sema onInput:fd.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4516
	    Processor activeProcess state:#ioWait.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4517
	    sema wait.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4518
	    Processor disableSemaphore:sema.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4519
	    canReadWrite := OperatingSystem readWriteCheck:fd
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4520
	] valueOnUnwindDo:[
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4521
	    Processor disableSemaphore:sema.
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4522
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
0c1780ae527f dont return an error when interrupted in NEXTAVAILBYTES (return 0)
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
  4523
	]
3490
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4524
    ].
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4525
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4526
    ^ canReadWrite not
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4527
!
6a87c2b37fd4 added #readWriteWait methods.
Claus Gittinger <cg@exept.de>
parents: 3474
diff changeset
  4528
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4529
writeWait
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4530
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4531
     becomes ready for writing.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4532
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4533
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4534
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4535
    self writeWaitWithTimeoutMs:nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4536
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4537
3016
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  4538
writeWaitTimeoutMs:timeout
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  4539
    "ST-80 compatibility"
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  4540
    ^ self writeWaitWithTimeoutMs:timeout 
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  4541
!
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  4542
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4543
writeWaitWithTimeout:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4544
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4545
     becomes ready for writing or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4546
     Return true if a timeout occured (i.e. false, if data is available).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4547
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4548
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4549
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4550
    ^ self writeWaitWithTimeoutMs:timeout * 1000
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4551
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4552
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4553
writeWaitWithTimeoutMs:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4554
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4555
     becomes ready for writing or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4556
     Return true if a timeout occured (i.e. false, if data is available).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4557
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4558
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4559
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4560
    |fd outputSema canWrite wasBlocked|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4561
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4562
    filePointer isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4563
	^ self errorNotOpen
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4564
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4565
    mode == #readonly ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4566
	^ self errorReadOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4567
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4568
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4569
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4570
    (OperatingSystem writeCheck:fd) ifTrue:[^ false].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4571
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4572
    wasBlocked := OperatingSystem blockInterrupts.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4573
    canWrite := OperatingSystem writeCheck:fd.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4574
    canWrite ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4575
	outputSema := Semaphore new name:'writeWait'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4576
	[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4577
	    timeout notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4578
		Processor signal:outputSema afterMilliseconds:timeout
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4579
	    ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4580
	    Processor signal:outputSema onOutput:fd.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4581
	    Processor activeProcess state:#ioWait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4582
	    outputSema wait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4583
	    Processor disableSemaphore:outputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4584
	    canWrite := OperatingSystem writeCheck:fd
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4585
	] valueOnUnwindDo:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4586
	    Processor disableSemaphore:outputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4587
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4588
	]
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4589
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4590
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4591
    ^ canWrite not
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4592
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4593
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4594
!ExternalStream methodsFor:'writing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4595
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4596
cr
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4597
    "append an end-of-line character (or CRLF if in crlf mode).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4598
     reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4599
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  4600
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  4601
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4602
    int len, cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4603
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4604
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4605
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4606
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4607
    if (((fp = __INST(filePointer)) != nil)
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4608
	&& (__INST(mode) != @symbol(readonly))
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4609
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4610
    ) {
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4611
	f = __FILEVal(fp);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4612
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4613
	if (_buffered = (__INST(buffered) == true)) { 
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4614
	    __WRITING__(f)
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4615
	}
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4616
	{
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4617
	    OBJ mode = __INST(eolMode);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4618
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4619
	    if (mode == @symbol(cr)) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4620
		cp = "\r"; len = 1;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4621
	    } else if (mode == @symbol(crlf)) {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4622
		cp = "\r\n"; len = 2;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4623
	    } else {
3445
2639c1e3fd0b nextAvail also for externalBytes
Claus Gittinger <cg@exept.de>
parents: 3432
diff changeset
  4624
		cp = "\n"; len = 1;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4625
	    }
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4626
	}
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4627
	__WRITEBYTES__(cnt, f, cp, len, _buffered);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4628
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4629
	if (cnt == len) {
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4630
	    if (__INST(position) != nil) {
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4631
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + len);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4632
	    }
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4633
	    RETURN ( self );
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4634
	}
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4635
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4636
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4637
%}.
2326
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  4638
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  4639
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  4640
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  4641
    self errorBinary
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4642
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4643
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4644
flush
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4645
    "write all buffered data - ignored if unbuffered"
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4646
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4647
%{
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4648
    OBJ fp;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4649
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4650
    __INST(lastErrorNumber) = nil;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4651
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4652
	if (__INST(mode) != @symbol(readonly)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4653
	    if (__INST(buffered) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4654
		__BEGIN_INTERRUPTABLE__
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  4655
		FFLUSH( __FILEVal(fp) );
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4656
		__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4657
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4658
	}
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4659
    }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4660
%}
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4661
!
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4662
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4663
nextPut:aCharacter
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4664
    "write the argument, aCharacter - return nil if failed, self if ok.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4665
     Only single-byte characters are currently supported"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4666
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  4667
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  4668
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4669
    char c;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4670
    int cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4671
    OBJ pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4672
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4673
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4674
    if (((fp = __INST(filePointer)) != nil) 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4675
	&& (__INST(mode) != @symbol(readonly))
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4676
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4677
	if (__INST(binary) != true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4678
	    if (__isCharacter(aCharacter)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4679
		c = __intVal(__characterVal(aCharacter)) & 0xFF;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4680
    doWrite:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4681
		f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4682
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4683
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4684
		if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4685
		    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4686
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4687
		__WRITEBYTE__(cnt, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4688
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4689
		if (cnt == 1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4690
		    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4691
		    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4692
			__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4693
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4694
		    RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4695
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4696
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4697
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4698
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4699
	    if (__isSmallInteger(aCharacter)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4700
		c = __intVal(aCharacter);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4701
		goto doWrite;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4702
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4703
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4704
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4705
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4706
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4707
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4708
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4709
    binary ifFalse:[self argumentMustBeCharacter. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4710
    self argumentMustBeInteger.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4711
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4712
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4713
nextPutAll:aCollection
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4714
    "write all elements of the argument, aCollection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4715
     Reimplemented for speed when writing strings or byteArrays.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4716
     For others, falls back to general method in superclass."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4717
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  4718
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  4719
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4720
    int len, cnt;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4721
    OBJ pos, fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4722
    int _buffered;
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4723
    int o_offs;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4724
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4725
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4726
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4727
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4728
	&& (__INST(mode) != @symbol(readonly))
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4729
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4730
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4731
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4732
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4733
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4734
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4735
	if (__isString(aCollection) || __isSymbol(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4736
	    len = __stringSize(aCollection);
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4737
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4738
	    __WRITEBYTES__(cnt, f, __stringVal(aCollection), len, _buffered);
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4739
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4740
	    o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4741
	    __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4742
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4743
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4744
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4745
		int offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4746
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4747
		if (__isByteArray(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4748
		    offs = 0;
3221
21085ae8e1be eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents: 3200
diff changeset
  4749
		    len = __byteArraySize(aCollection);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4750
		} else if (__isBytes(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4751
		    offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
3221
21085ae8e1be eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents: 3200
diff changeset
  4752
		    len = __byteArraySize(aCollection) - offs;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4753
		} else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4754
		    goto out;
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4755
#ifdef BUGGY
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4756
		__WRITEBYTES__(cnt, f, __ByteArrayInstPtr(aCollection)->ba_element+offs, len, _buffered);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4757
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4758
		o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element) - (char *)__InstPtr(aCollection);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4759
		o_offs += offs;
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4760
		__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4761
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4762
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4763
		goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4764
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4765
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4766
	if (cnt == len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4767
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4768
	    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4769
		__INST(position) = __MKSMALLINT(__intVal(pos) + len);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4770
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4771
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4772
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4773
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4774
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  4775
out: ;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4776
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4777
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4778
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4779
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4780
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4781
    ^ super nextPutAll:aCollection
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4782
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4783
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4784
nextPutAll:aCollection startingAt:start to:stop
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4785
    "write a range of elements of the argument, aCollection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4786
     Reimplemented for speed when writing strings or byteArrays.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4787
     For others, falls back to general method in superclass."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4788
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  4789
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  4790
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4791
    int offs, len, cnt, iStart, iStop, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4792
    OBJ fp, pos;
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4793
    int o_offs;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4794
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4795
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4796
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4797
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4798
	&& __bothSmallInteger(start, stop)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4799
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4800
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4801
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4802
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4803
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4804
	iStart = __intVal(start);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4805
	iStop = __intVal(stop);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4806
	if ((iStart < 1) || (iStop < iStart)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4807
	    RETURN(self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4808
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4809
	if (__isString(aCollection) || __isSymbol(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4810
	    len = __stringSize(aCollection);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4811
	    if (iStop > len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4812
		RETURN(self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4813
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4814
	    if (iStop > len)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4815
		iStop = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4816
	    len = iStop - iStart + 1;
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4817
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4818
	    __WRITEBYTES__(cnt, f, __stringVal(aCollection)+iStart-1, len, _buffered);
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4819
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4820
	    o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4821
	    __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+iStart-1, len, _buffered);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4822
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4823
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4824
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4825
		int offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4826
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4827
		if (__isByteArray(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4828
		    offs = 0;
3221
21085ae8e1be eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents: 3200
diff changeset
  4829
		    len = __byteArraySize(aCollection);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4830
		} else if (__isBytes(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4831
		    offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
3221
21085ae8e1be eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents: 3200
diff changeset
  4832
		    len = __byteArraySize(aCollection) - offs;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4833
		} else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4834
		    goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4835
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4836
		if (iStop > len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4837
		    RETURN(self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4838
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4839
		if (iStop > len)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4840
		    iStop = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4841
		len = iStop - iStart + 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4842
		offs += iStart - 1;
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4843
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4844
		__WRITEBYTES__(cnt, f,  __ByteArrayInstPtr(aCollection)->ba_element+offs, len, _buffered);
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4845
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4846
		o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element)-(char *)__InstPtr(aCollection);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4847
		__WRITEBYTES_OBJ__(cnt, f,  aCollection, o_offs+offs, len, _buffered);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4848
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4849
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4850
		goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4851
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4852
	if (cnt == len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4853
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4854
	    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4855
		__INST(position) = __MKSMALLINT(__intVal(pos) + len);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4856
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4857
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4858
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4859
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4860
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  4861
out: ;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4862
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4863
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4864
    ^ super nextPutAll:aCollection startingAt:start to:stop
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4865
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4866
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  4867
!ExternalStream class methodsFor:'documentation'!
730
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  4868
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  4869
version
4526
a42dc8e09586 errorOpen renamed to errorAlreadyOpen
Claus Gittinger <cg@exept.de>
parents: 4468
diff changeset
  4870
    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.196 1999-08-04 14:12:48 cg Exp $'
730
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  4871
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4872
ExternalStream initialize!