ExtStream.st
author Claus Gittinger <cg@exept.de>
Thu, 24 Apr 1997 16:23:20 +0200
changeset 2585 6c25622320aa
parent 2577 258f5df3f054
child 2591 9faeea99f45b
permissions -rw-r--r--
checkin from browser
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
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    14
	instanceVariableNames:'filePointer mode buffered binary useCRLF hitEOF didWrite
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
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    18
		InvalidOperationSignal'
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    19
	poolDictionaries:''
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    20
	category:'Streams-External'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    23
!ExternalStream primitiveDefinitions!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
%{
a27a279701f8 Initial revision
claus
parents:
diff changeset
    25
#include <stdio.h>
437
claus
parents: 436
diff changeset
    26
#define _STDIO_H_INCLUDED_
claus
parents: 436
diff changeset
    27
10
claus
parents: 5
diff changeset
    28
#include <fcntl.h>
437
claus
parents: 436
diff changeset
    29
#define _FCNTL_H_INCLUDED_
claus
parents: 436
diff changeset
    30
10
claus
parents: 5
diff changeset
    31
#include <errno.h>
437
claus
parents: 436
diff changeset
    32
#define _ERRNO_H_INCLUDED_
42
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    33
1141
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    34
#ifdef LINUX
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    35
  /* use inline string macros */
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    36
# define __STRINGDEFS__
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    37
# include <linuxIntern.h>
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    38
#endif
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    39
42
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    40
#ifdef hpux
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    41
# define fileno(f)      ((f->__fileH << 8) | (f->__fileL))
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    42
#endif
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    43
933
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    44
#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
    45
# 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
    46
#endif
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    47
#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
    48
# 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
    49
#endif
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    50
#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
    51
# 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
    52
#endif
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    53
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    54
/*
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    55
 * stdio library requires an fseek before reading whenever a file
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    56
 * is open for read/write and the last operation was a write.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    57
 * (also vice-versa).
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    58
 * All code should use the following macro before doing reads:
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    59
 */
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    60
#define __READING__(f)                          \
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
    61
    if ((__INST(didWrite) != false)              \
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
    62
     && (__INST(mode) == @symbol(readwrite))) {  \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    63
	__INST(didWrite) = false;                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    64
	fseek(f, 0L, SEEK_CUR); /* needed in stdio */  \
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    65
    }
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    66
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    67
#define __WRITING__(f)                          \
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
    68
    if ((__INST(didWrite) != true)               \
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
    69
     && (__INST(mode) == @symbol(readwrite))) {  \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    70
	__INST(didWrite) = true;                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    71
	fseek(f, 0L, SEEK_CUR); /* needed in stdio */  \
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    72
    }
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    73
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
    74
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    75
#define __UNGETC__(c, f, isBuffered)                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    76
    if (isBuffered) {                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    77
	ungetc((c), (f));                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    78
    } else {                                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    79
	__INST(readAhead) = __MKSMALLINT((c));          \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    80
    }
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    81
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    82
#define __READBYTE__(ret, f, buf, isBuffered)           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    83
    if (isBuffered) {                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    84
	for (;;) {                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    85
	    (ret) = getc(f);                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    86
	    if ((ret) >= 0) {                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    87
		*(buf) = (ret);                         \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    88
		(ret) = 1;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    89
	    } else if (ferror(f)) {                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    90
		if (errno == EINTR) {                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    91
		    __HANDLE_INTERRUPTS__;              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    92
		    clearerr(f);                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    93
		    continue;                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    94
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    95
	    } else                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    96
		(ret) = 0;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    97
	    break;                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    98
	}                                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
    99
    } else {                                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   100
	OBJ rA = __INST(readAhead);                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   101
	if (rA != nil) {                                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   102
	    *(buf) = __intVal(rA);                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   103
	    __INST(readAhead) = nil;                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   104
	    (ret) = 1;                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   105
	} else {                                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   106
	    for (;;) {                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   107
		(ret) = read(fileno(f), buf, 1);        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   108
		if ((ret) >= 0 || errno != EINTR)       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   109
		    break;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   110
		__HANDLE_INTERRUPTS__;                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   111
	    }                                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   112
	}                                               \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   113
   }                                                                          
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   114
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   115
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   116
 * 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
   117
 * (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
   118
 */
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   119
#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
   120
    (ret) = 0;                                          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   121
    if (isBuffered) {                                   \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   122
	int __offs = 0;                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   123
	while (__offs < (cnt)) {                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   124
	    (ret) = getc(f);                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   125
	    if ((ret) < 0) {                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   126
		if (ferror(f)) {                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   127
		    if (errno == EINTR) {               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   128
			__HANDLE_INTERRUPTS__;          \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   129
			clearerr(f);                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   130
			continue;                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   131
		    }                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   132
		} else {                                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   133
		    (ret) = 0;                          \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   134
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   135
		break;                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   136
	    }                                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   137
	    (buf)[__offs++] = (ret);                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   138
	}                                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   139
	if (__offs > 0)                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   140
	    (ret) = __offs;                             \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   141
    } else {                                            \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   142
	int __offs = 0;                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   143
	int fd = fileno(f);                             \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   144
							\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   145
	while (__offs < (cnt)) {                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   146
	    OBJ rA = __INST(readAhead);                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   147
	    if (rA != nil) {                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   148
		(buf)[__offs] = __intVal(rA);           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   149
		__INST(readAhead) = nil;                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   150
		(ret) = 1;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   151
	    } else {                                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   152
		(ret) = read(fd, (buf)+__offs, (cnt)-__offs);                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   153
		if ((ret) <= 0) {                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   154
		    if ((ret) < 0 && errno == EINTR) {  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   155
			__HANDLE_INTERRUPTS__;          \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   156
			continue;                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   157
		    }                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   158
		    break;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   159
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   160
	    }                                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   161
	    __offs += (ret);                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   162
	}                                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   163
	if (__offs > 0)                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   164
	    (ret) = __offs;                             \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   165
   }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   166
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   167
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   168
 * 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
   169
 * (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
   170
 */
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   171
#define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)     \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   172
  {							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   173
    int __ooffs = obj_offs;				\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   174
    int __offs = 0;					\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   175
    char *buf = (char *)(obj);				\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   176
							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   177
    (ret) = 0;                                          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   178
    if (isBuffered) {                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   179
	while (__offs < (cnt)) {                        \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   180
	    (ret) = getc(f);                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   181
	    if ((ret) < 0) {                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   182
		if (ferror(f)) {                        \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   183
		    if (errno == EINTR) {               \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   184
			__HANDLE_INTERRUPTS__;          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   185
			clearerr(f);                    \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   186
			/* refetch */                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   187
			buf = (char *)(obj);            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   188
			continue;                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   189
		    }                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   190
		} else {                                \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   191
		    (ret) = 0;                          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   192
		}                                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   193
		break;                                  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   194
	    }                                           \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   195
	    (buf)[__ooffs+__offs] = (ret);              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   196
	    __offs++;					\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   197
	}                                               \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   198
	if (__offs > 0)                                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   199
	    (ret) = __offs;                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   200
    } else {                                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   201
	int fd = fileno(f);                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   202
							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   203
	while (__offs < (cnt)) {                        \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   204
	    OBJ rA = __INST(readAhead);                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   205
	    if (rA != nil) {                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   206
		(buf)[__ooffs+__offs] = __intVal(rA);   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   207
		__INST(readAhead) = nil;                \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   208
		(ret) = 1;                              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   209
	    } else {                                    \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   210
		(ret) = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   211
		if ((ret) <= 0) {                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   212
		    if ((ret) < 0 && errno == EINTR) {  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   213
			__HANDLE_INTERRUPTS__;          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   214
			/* refetch */                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   215
			buf = (char *)(obj);            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   216
			continue;                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   217
		    }                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   218
		    break;                              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   219
		}                                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   220
	    }                                           \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   221
	    __offs += (ret);                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   222
	}                                               \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   223
	if (__offs > 0)                                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   224
	    (ret) = __offs;                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   225
    }							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   226
  }
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   227
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   228
#define __WRITEBYTE__(ret, f, buf, isBuffered)          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   229
    if (isBuffered) {                                   \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   230
	for (;;) {                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   231
	    ret = putc(*(buf), f);                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   232
	    if ((ret) >= 0) {                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   233
		(ret) = 1;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   234
	    } else if (ferror(f)) {                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   235
		if (errno == EINTR) {                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   236
		    __HANDLE_INTERRUPTS__;              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   237
		    clearerr(f);                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   238
		    continue;                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   239
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   240
	    } else                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   241
		(ret) = 0;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   242
	    break;                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   243
	}                                               \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   244
    } else {                                            \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   245
	for (;;) {                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   246
	    (ret) = write(fileno(f), buf, 1);           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   247
	    if ((ret) >= 0 || errno != EINTR)           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   248
		break;                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   249
	    __HANDLE_INTERRUPTS__;                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   250
	}                                               \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   251
   }                                                                          
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   252
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   253
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   254
 * 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
   255
 * (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
   256
 */
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   257
#define __WRITEBYTES__(ret, f, buf, cnt, isBuffered)                          \
1464
6d533b5e5de3 Fix reads and writes with cnt==0.
Stefan Vogel <sv@exept.de>
parents: 1463
diff changeset
   258
    (ret) = 0;                                                                \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   259
    if (isBuffered) {                                                         \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   260
	int __offs = 0;                                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   261
	while (__offs < (cnt)) {                                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   262
	    ret = fwrite((buf)+__offs, 1, (cnt)-__offs, f);                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   263
	    if ((ret) < 0) {                                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   264
		if (ferror(f)) {                                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   265
		    if (errno == EINTR) {                                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   266
			__HANDLE_INTERRUPTS__;                                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   267
			clearerr(f);                                          \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   268
			continue;                                             \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   269
		    }                                                         \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   270
		} else {                                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   271
		    (ret) = 0;                                                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   272
		}                                                             \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   273
		break;                                                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   274
	    }                                                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   275
	    __offs += (ret);                                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   276
	}                                                                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   277
	if (__offs > 0)                                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   278
	    (ret) = __offs;                                                   \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   279
    } else {                                                                  \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   280
	int __offs = 0;                                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   281
	while (__offs < (cnt)) {                                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   282
	    ret = write(fileno(f), (buf)+__offs, (cnt)-__offs);               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   283
	    if (ret <= 0) {                                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   284
		if (ret < 0 && errno == EINTR) {                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   285
		    __HANDLE_INTERRUPTS__;                                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   286
		    continue;                                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   287
		}                                                             \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   288
		break;                                                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   289
	    }                                                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   290
	    __offs += (ret);                                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   291
	}                                                                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   292
	if (__offs > 0)                                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   293
	    (ret) = __offs;                                                   \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   294
   }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   295
223
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   296
/*
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   297
 * 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
   298
 * (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
   299
 */
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   300
#define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   301
  {									      \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   302
    int __ooffs = obj_offs;						      \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   303
    int __offs = 0;							      \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   304
    char *buf = (char *)(obj);						      \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   305
									      \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   306
    (ret) = 0;                                                                \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   307
    if (isBuffered) {                                                         \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   308
	while (__offs < (cnt)) {                                              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   309
	    ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f);           \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   310
	    if ((ret) < 0) {                                                  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   311
		if (ferror(f)) {                                              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   312
		    if (errno == EINTR) {                                     \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   313
			__HANDLE_INTERRUPTS__;                                \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   314
			/* refetch */                                         \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   315
			buf = (char *)(obj);                                  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   316
			clearerr(f);                                          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   317
			continue;                                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   318
		    }                                                         \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   319
		} else {                                                      \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   320
		    (ret) = 0;                                                \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   321
		}                                                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   322
		break;                                                        \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   323
	    }                                                                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   324
	    __offs += (ret);                                                  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   325
	}                                                                     \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   326
	if (__offs > 0)                                                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   327
	    (ret) = __offs;                                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   328
    } else {                                                                  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   329
	while (__offs < (cnt)) {                                              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   330
	    ret = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs);       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   331
	    if (ret <= 0) {                                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   332
		if (ret < 0 && errno == EINTR) {                              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   333
		    __HANDLE_INTERRUPTS__;                                    \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   334
		    /* refetch */                                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   335
		    buf = (char *)(obj);                                      \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   336
		    continue;                                                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   337
		}                                                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   338
		break;                                                        \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   339
	    }                                                                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   340
	    __offs += (ret);                                                  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   341
	}                                                                     \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   342
	if (__offs > 0)                                                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   343
	    (ret) = __offs;                                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   344
    }									      \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   345
  }
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   346
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   347
/*
223
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   348
 * on some systems errno is a macro ... check for it here
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   349
 */
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   350
#ifndef errno
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   351
 extern errno;
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   352
#endif
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   353
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   354
%}
188
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   355
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   356
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   357
!ExternalStream class methodsFor:'documentation'!
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   358
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   359
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   360
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   361
 COPYRIGHT (c) 1988 by Claus Gittinger
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   362
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   363
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   364
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   365
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   366
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   367
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   368
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   369
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   370
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   371
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   372
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   373
documentation
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   374
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   375
    ExternalStream defines protocol common to Streams which have a file-descriptor and 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   376
    represent some file or communicationChannel of the underlying OperatingSystem.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   377
    ExternalStream is abstract; concrete classes are FileStream, PipeStream etc.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   378
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   379
    ExternalStreams can be in two modes: text- (the default) and binary-mode.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   380
    In text-mode, the elements read/written are characters; 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   381
    while in binary-mode the basic elements are bytes which read/write as SmallIntegers 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   382
    in the range 0..255.
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   383
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   384
    Also, the stream can be either in buffered or unbuffered mode. In buffered mode,
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   385
    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
   386
    is sent (in both modes).
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   387
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   388
    The underlying OperatingSystem streams may either be closed explicitely (sending a close)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   389
    or just forgotten - in this case, the garbage collector will eventually collect the
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   390
    object AND a close will be performed automatically (but you will NOT know when this 
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   391
    happens - so it is recommended, that you close your files when no longer needed).
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   392
    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
   393
    some crash) the data will not be in the file, if unclosed. 
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   394
    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
   395
    a noop in one of the superclasses).
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   396
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   397
    Most of the methods found here redefine inherited methods for better performance,
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   398
    since I/O from/to files should be fast.
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   399
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   400
    Recovering a snapshot:
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   401
      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
   402
      reOpen in subclasses for more information.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   403
      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
   404
      reestablish the stream upon image restart (make someone dependent on ObjectMemory).
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   405
      FileStreams are reopened and positioned to their offset they had at snapshot time.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   406
      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
   407
      if the contents changed in the meantime.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   408
      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
   409
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   410
    [Instance variables:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   411
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   412
	filePointer     <Integer>       the unix FILE*; somehow mapped to an integer
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   413
					(notice: not the fd)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   414
	mode            <Symbol>        #readwrite, #readonly or #writeonly
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   415
	buffered        <Boolean>       true, if buffered (i.e. collects characters - does
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   416
					not output immediately)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   417
	binary          <Boolean>       true if in binary mode (reads bytes instead of chars)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   418
	useCRLF         <Boolean>       true, if lines should be terminated with crlf instead
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   419
					of lf. (i.e. if file is an MSDOS-type file)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   420
	hitEOF          <Boolean>       true, if EOF was reached
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   421
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   422
	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
   423
					updated with next i/o operation)
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   424
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   425
    [Class variables:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   426
	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
   427
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   428
	StreamErrorSignal       <Signal> parent of all stream errors (see Stream class)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   429
	InvalidReadSignal       <Signal> raised on read from writeonly stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   430
	InvalidWriteSignal      <Signal> raised on write to readonly stream 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   431
	InvalidModeSignal       <Signal> raised on text I/O with binary-stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   432
					 or binary I/O with text-stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   433
	OpenErrorSignal         <Signal> raised if open fails
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   434
	StreamNotOpenSignal     <Signal> raised on I/O with non-open stream
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   435
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   436
    Additional notes:
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   437
      This class is implemented using the underlying stdio-c library package, which
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   438
      has both advantages and disadvantages: since it is portable (posix defined), porting
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   439
      ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   440
      has big problems handling unbounded Streams, since the EOF handling in stdio is
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   441
      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
   442
      a complete rewrite for UnboundedStream ...
325
claus
parents: 308
diff changeset
   443
188
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   444
      Also, depending on the system, the stdio library behaves infriendly when signals
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   445
      occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   446
      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
   447
      an error and errno is set to EINTR. 
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   448
      Thats what the ugly code around all getc-calls is for ...
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   449
      Since things get more and more ugly - we will rewrite ExternalStream
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   450
      completely, to NOT use any stdio stuff (and do its buffering itself).
325
claus
parents: 308
diff changeset
   451
claus
parents: 308
diff changeset
   452
      Notice that typical stdio's use a single errno global variable to return an error code,
claus
parents: 308
diff changeset
   453
      this was bad design in the stdio lib (right from the very beginning), since its much
claus
parents: 308
diff changeset
   454
      harder to deal with this in the presence of lightweight processes, where errno gets
claus
parents: 308
diff changeset
   455
      overwritten by an I/O operation done in another thread. (stdio should have been written
claus
parents: 308
diff changeset
   456
      to return errno as a negative number ...).
claus
parents: 308
diff changeset
   457
      To deal with this, the scheduler treats errno like a per-thread private variable,
claus
parents: 308
diff changeset
   458
      and saves/restores the errno setting when switching to another thread.
claus
parents: 308
diff changeset
   459
      (Notice that some thread packages do this also, but ST/X's thread implementation
claus
parents: 308
diff changeset
   460
      does not depend on those, but instead uses a portable private package).
claus
parents: 308
diff changeset
   461
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   462
      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
   463
      fseek whenever we are about to read after write and vice versa.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   464
      Two macros (__READING__ and __WRITING__) have been defined to be used before every
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   465
      fread/fgetc and fwrite/putc respectively.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   466
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   467
    [author:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   468
	Claus Gittinger
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   469
	Stefan Vogel (many, many fixes ...)
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   470
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   471
    [see also:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   472
	FileStream Socket PipeStream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   473
	Filename OperatingSystem
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   474
"
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   475
! !
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   476
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   477
!ExternalStream class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   478
a27a279701f8 Initial revision
claus
parents:
diff changeset
   479
initialize
593
19d568779cf7 moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   480
    OpenErrorSignal isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   481
	OpenErrorSignal := StreamErrorSignal newSignalMayProceed:true.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   482
	OpenErrorSignal nameClass:self message:#openErrorSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   483
	OpenErrorSignal notifierString:'open error'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   484
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   485
	InvalidReadSignal := ReadErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   486
	InvalidReadSignal nameClass:self message:#invalidReadSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   487
	InvalidReadSignal notifierString:'read error'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   488
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   489
	InvalidWriteSignal := WriteErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   490
	InvalidWriteSignal nameClass:self message:#invalidWriteSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   491
	InvalidWriteSignal notifierString:'write error'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   492
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   493
	InvalidModeSignal :=  StreamErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   494
	InvalidModeSignal nameClass:self message:#invalidModeSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   495
	InvalidModeSignal notifierString:'binary/text mode mismatch'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   496
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   497
	InvalidOperationSignal :=  StreamErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   498
	InvalidOperationSignal nameClass:self message:#invalidOperationSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   499
	InvalidOperationSignal notifierString:'unsupported file operation'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   500
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   501
	StreamNotOpenSignal := StreamErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   502
	StreamNotOpenSignal nameClass:self message:#streamNotOpenSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   503
	StreamNotOpenSignal notifierString:'stream is not open'.
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   504
    ].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   505
31
75f2b9f78be2 *** empty log message ***
claus
parents: 25
diff changeset
   506
    Lobby isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   507
	Lobby := Registry new.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   508
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   509
	"want to get informed when returning from snapshot"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   510
	ObjectMemory addDependent:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   511
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
   512
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   513
a27a279701f8 Initial revision
claus
parents:
diff changeset
   514
reOpenFiles
a27a279701f8 Initial revision
claus
parents:
diff changeset
   515
    "reopen all files (if possible) after a snapShot load"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   516
301
35e40a6fc72b *** empty log message ***
claus
parents: 269
diff changeset
   517
    Lobby do:[:aFileStream |
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   518
	aFileStream reOpen
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   519
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
   520
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   521
1469
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   522
update:something with:aParameter from:changedObject
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   523
    "have to reopen files when returning from snapshot"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   524
a27a279701f8 Initial revision
claus
parents:
diff changeset
   525
    something == #returnFromSnapshot ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   526
	self reOpenFiles
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   527
    ]
1469
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   528
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   529
    "Created: 15.6.1996 / 15:19:59 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   530
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   531
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   532
!ExternalStream class methodsFor:'instance creation'!
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   533
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   534
forFileDescriptor:aFileDescriptor mode:mode
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   535
    |newStream|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   536
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   537
    newStream := self basicNew.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   538
    newStream text; buffered:true; useCRLF:false; clearEOF.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   539
    ^ newStream connectTo:aFileDescriptor withMode:mode
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   540
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   541
    "this will probably fail (15 is a random FD):
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   542
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   543
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   544
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   545
     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
   546
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   547
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   548
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   549
    "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
   550
    "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
   551
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   552
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   553
forReadWriteToFileDescriptor:aFileDescriptor
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   554
    ^ self forFileDescriptor:aFileDescriptor mode:'r+'
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   555
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   556
    "this will probably fail (15 is a random FD):
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   557
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   558
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   559
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   560
     s := ExternalStream forReadWriteToFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   561
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   562
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   563
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   564
    "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
   565
    "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
   566
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   567
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   568
forReadingFromFileDescriptor:aFileDescriptor
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   569
    ^ self forFileDescriptor:aFileDescriptor mode:'r'
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   570
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   571
    "this will probably fail (15 is a random FD):
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   572
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   573
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   574
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   575
     s := ExternalStream forReadingFromFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   576
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   577
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   578
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   579
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   580
     |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
   581
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   582
     'create OS pipe ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   583
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   584
     pipe := OperatingSystem makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   585
     readFd := pipe at:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   586
     writeFd := pipe at:2.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   587
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   588
     'connect Smalltalk streams ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   589
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   590
     rs := ExternalStream forReadingFromFileDescriptor:readFd.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   591
     ws := ExternalStream forWritingToFileDescriptor:writeFd.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   592
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   593
     'read ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   594
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   595
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   596
	     Transcript showCR:rs nextLine
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   597
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   598
	 rs close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   599
     ] forkAt:7.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   600
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   601
     'write ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   602
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   603
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   604
	     ws nextPutAll:'hello world '; nextPutAll:i printString; cr
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   605
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   606
	 ws close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   607
     ] fork.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   608
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   609
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   610
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   611
    "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
   612
    "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
   613
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   614
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   615
forWritingToFileDescriptor:aFileDescriptor
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   616
    ^ self forFileDescriptor:aFileDescriptor mode:'w'
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   617
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   618
    "this will probably fail (15 is a random FD):
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   619
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   620
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   621
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   622
     s := ExternalStream forWritingToFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   623
     s binary.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   624
     s nextPut:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   625
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   626
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   627
    "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
   628
    "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
   629
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   630
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   631
makePipe
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   632
    "return an array with two streams - the first one for reading, the second
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   633
     for writing. This is the higher level equivalent of OperatingSystem>>makePipe."
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   634
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   635
     |pipe rs ws|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   636
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   637
     pipe := OperatingSystem makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   638
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   639
     pipe notNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   640
	 rs := self forReadingFromFileDescriptor:(pipe at:1).
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   641
	 ws := self forWritingToFileDescriptor:(pipe at:2).
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   642
	 ^ 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
   643
     ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   644
     ^ nil
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   645
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   646
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   647
     |pipe rs ws|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   648
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   649
     pipe := ExternalStream makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   650
     rs := pipe at:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   651
     ws := pipe at:2.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   652
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   653
     'read ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   654
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   655
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   656
	     Transcript showCR:rs nextLine
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   657
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   658
	 rs close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   659
     ] forkAt:7.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   660
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   661
     'write ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   662
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   663
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   664
	     ws nextPutAll:'hello world '; nextPutAll:i printString; cr
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   665
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   666
	 ws close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   667
     ] fork.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   668
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   669
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   670
    "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
   671
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   672
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   673
new
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   674
    |newStream|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   675
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   676
    newStream := self basicNew.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   677
    newStream text; buffered:true; useCRLF:false; clearEOF.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   678
    ^ newStream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   679
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   680
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   681
!ExternalStream class methodsFor:'Signal constants'!
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   682
1522
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   683
inaccessibleSignal
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   684
    "ST-80 compatibility: return openErrorSignal"
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   685
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   686
    ^ self openErrorSignal
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   687
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   688
    "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
   689
!
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   690
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   691
invalidModeSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   692
    "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
   693
     or binary-I/O with a text stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   694
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   695
    ^ InvalidModeSignal
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   696
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   697
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   698
invalidOperationSignal
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   699
    "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
   700
     I/O operation is attempted"
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   701
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   702
    ^ InvalidOperationSignal
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   703
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   704
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   705
invalidReadSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   706
    "return the signal raised when reading from writeonly streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   707
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   708
    ^ InvalidReadSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   709
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   710
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   711
invalidWriteSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   712
    "return the signal raised when writing to readonly streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   713
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   714
    ^ InvalidWriteSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   715
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   716
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   717
openErrorSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   718
    "return the signal raised when a file open failed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   719
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   720
    ^ OpenErrorSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   721
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   722
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   723
streamNotOpenSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   724
    "return the signal raised on I/O with closed streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   725
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   726
    ^ StreamNotOpenSignal
2
claus
parents: 1
diff changeset
   727
! !
claus
parents: 1
diff changeset
   728
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   729
!ExternalStream class methodsFor:'error handling'!
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   730
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   731
lastErrorNumber
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   732
    "return the errno of the last error"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   733
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   734
    ^ LastErrorNumber
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   735
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   736
    "
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   737
     ExternalStream lastErrorNumber
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   738
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   739
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   740
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   741
lastErrorString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   742
    "return a message string describing the last error"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   743
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   744
    ^ OperatingSystem errorTextForNumber:LastErrorNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   745
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   746
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   747
     ExternalStream lastErrorString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   748
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   749
! !
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   750
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   751
!ExternalStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   752
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   753
binary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   754
    "switch to binary mode - default is text"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   755
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   756
    binary := true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   757
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   758
a27a279701f8 Initial revision
claus
parents:
diff changeset
   759
buffered:aBoolean
10
claus
parents: 5
diff changeset
   760
    "turn buffering on or off - default is on"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   761
10
claus
parents: 5
diff changeset
   762
    buffered := aBoolean
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   763
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   764
a27a279701f8 Initial revision
claus
parents:
diff changeset
   765
contents
2
claus
parents: 1
diff changeset
   766
    "return the contents of the file from the current position up-to
claus
parents: 1
diff changeset
   767
     the end. If the stream is in binary mode, a ByteArray containing
claus
parents: 1
diff changeset
   768
     the byte values is returned.
claus
parents: 1
diff changeset
   769
     In text-mode, a collection of strings, each representing one line,
claus
parents: 1
diff changeset
   770
     is returned."
claus
parents: 1
diff changeset
   771
claus
parents: 1
diff changeset
   772
    |text l chunks sizes chunk byteCount cnt bytes offset|
claus
parents: 1
diff changeset
   773
claus
parents: 1
diff changeset
   774
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   775
	"adding to a ByteArray produces quadratic time-space
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   776
	 behavior - therefore we allocate chunks, and concatenate them
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   777
	 at the end."
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   778
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   779
	chunks := OrderedCollection new.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   780
	sizes := OrderedCollection new.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   781
	byteCount := 0.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   782
	[self atEnd] whileFalse:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   783
	    chunk := ByteArray uninitializedNew:4096.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   784
	    cnt := self nextBytes:(chunk size) into:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   785
	    cnt notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   786
		chunks add:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   787
		sizes add:cnt.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   788
		byteCount := byteCount + cnt
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   789
	    ]
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   790
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   791
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   792
	"now, create one big ByteArray"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   793
	bytes := ByteArray uninitializedNew:byteCount.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   794
	offset := 1.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   795
	1 to:chunks size do:[:index |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   796
	    chunk := chunks at:index.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   797
	    cnt := sizes at:index. 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   798
	    bytes replaceFrom:offset to:(offset + cnt - 1) with:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   799
	    offset := offset + cnt
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   800
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   801
	^ bytes
2
claus
parents: 1
diff changeset
   802
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   803
244
9faa2da0650a Text <-> StringCollection
claus
parents: 223
diff changeset
   804
    text := StringCollection new.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   805
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   806
	l := self nextLine.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   807
	l isNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   808
	    ^ text
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   809
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   810
	text add:l
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   811
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   812
    ^ text
a27a279701f8 Initial revision
claus
parents:
diff changeset
   813
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   814
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   815
contentsOfEntireFile
1522
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   816
    "ST-80 compatibility: return contents as String"
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   817
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   818
    ^ self contents asString.
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   819
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   820
    "Modified: 3.7.1996 / 13:22:16 / stefan"
2
claus
parents: 1
diff changeset
   821
!
claus
parents: 1
diff changeset
   822
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   823
contentsSpecies
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   824
    "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
   825
     (such as upTo)"
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   826
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   827
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   828
	^ ByteArray
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   829
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   830
    ^ String
2
claus
parents: 1
diff changeset
   831
!
claus
parents: 1
diff changeset
   832
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   833
fileDescriptor
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   834
    "return the fileDescriptor of the receiver -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   835
     notice: this one returns the underlying OSs fileDescriptor -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   836
     this may not be available on all platforms (i.e. non unix systems)."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   837
a27a279701f8 Initial revision
claus
parents:
diff changeset
   838
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   839
a27a279701f8 Initial revision
claus
parents:
diff changeset
   840
    FILE *f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   841
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   842
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   843
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   844
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   845
	RETURN ( __MKSMALLINT(fileno(f)) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   846
    }
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
   847
%}.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   848
    ^ self errorNotOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   849
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   850
826
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   851
fileDescriptor:anInteger withMode:openMode
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   852
    "set the filePointer from the receiver based on the fileDescriptor-
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   853
     notice: this one is based on the underlying OSs fileDescriptor -
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   854
     this may not be available on all platforms (i.e. non unix systems)."
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   855
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   856
%{  /* NOCONTEXT */
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   857
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   858
    FILE *f;
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   859
    OBJ fp;
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   860
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   861
    if (__isSmallInteger(anInteger) &&
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   862
	__isString(openMode) &&
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   863
	(f = fdopen(__intVal(anInteger), __stringVal(openMode))) != 0
826
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   864
    ) {
2560
d5b6c661718b oops - self reference after MKOBJ may lead to trouble with garbage collector,
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   865
	__PROTECT__(self);
d5b6c661718b oops - self reference after MKOBJ may lead to trouble with garbage collector,
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   866
	fp = __MKOBJ((int)f); 
d5b6c661718b oops - self reference after MKOBJ may lead to trouble with garbage collector,
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   867
	__UNPROTECT__(self);
d5b6c661718b oops - self reference after MKOBJ may lead to trouble with garbage collector,
Claus Gittinger <cg@exept.de>
parents: 2513
diff changeset
   868
	__INST(filePointer) = fp; __STORE(self, fp);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   869
	RETURN (self);
826
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   870
    }
1068
92fdcccf12a3 alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   871
%}.
826
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   872
    ^ self primitiveFailed
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   873
!
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   874
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   875
filePointer
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   876
    "return the filePointer of the receiver -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   877
     notice: for portability stdio is used; this means you will get
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   878
     a FILE * - not a fileDescriptor. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   879
     (what you really get is a corresponding integer).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   880
     You cannot do much with the returned value 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   881
     - except passing it to a primitive, for example."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   882
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   883
    ^ filePointer
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   884
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   885
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   886
readonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   887
    "set access mode to readonly"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   888
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   889
    mode := #readonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   890
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   891
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   892
readwrite
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   893
    "set access mode to readwrite"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   894
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   895
    mode := #readwrite
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   896
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   897
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   898
text
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   899
    "switch to text mode - default is text"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   900
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   901
    binary := false
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   902
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   903
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   904
useCRLF:aBoolean
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   905
    "turn on or off CRLF sending (instead of LF only) - default is off"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   906
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   907
    useCRLF := aBoolean
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   908
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   909
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   910
writeonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   911
    "set access mode to writeonly"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   912
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   913
    mode := #writeonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   914
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   915
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   916
!ExternalStream methodsFor:'error handling'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   917
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   918
argumentMustBeCharacter
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   919
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   920
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   921
    "report an error, that the argument must be a character"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   922
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   923
    ^ self error:'argument must be a character'
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   924
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   925
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   926
argumentMustBeInteger
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   927
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   928
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   929
    "report an error, that the argument must be an integer"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   930
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   931
    ^ self error:'argument must be an integer'
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   932
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   933
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   934
argumentMustBeString
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   935
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   936
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   937
    "report an error, that the argument must be a string"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   938
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   939
    ^ self error:'argument must be a string'
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   940
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   941
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   942
errorBinary
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   943
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   944
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   945
    "report an error, that the stream is in binary mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   946
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   947
    ^ InvalidModeSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   948
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   949
	     errorString:(self class name , ' is in binary mode')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   950
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   951
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   952
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   953
errorNotBinary
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   954
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   955
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   956
    "report an error, that the stream is not in binary mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   957
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   958
    ^ InvalidModeSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   959
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   960
	     errorString:(self class name , ' is not in binary mode')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   961
		      in:thisContext sender
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   962
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   963
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   964
errorNotBuffered
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   965
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   966
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   967
    "report an error, that the stream is not in buffered mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   968
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   969
    ^ StreamErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   970
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   971
	     errorString:(self class name , ' is unbuffered - operation not allowed')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   972
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   973
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   974
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   975
errorNotOpen
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   976
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   977
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   978
    "report an error, that the stream has not been opened"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   979
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   980
    ^ StreamNotOpenSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   981
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   982
	     errorString:(self class name , ' not open')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   983
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   984
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   985
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   986
errorOpen
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   987
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   988
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   989
    "report an error, that the stream is already opened"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   990
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   991
    ^ OpenErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   992
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   993
	errorString:(self class name , ' is already open')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   994
		 in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   995
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   996
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   997
errorReadOnly
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   998
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   999
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1000
    "report an error, that the stream is a readOnly stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1001
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1002
    ^ InvalidWriteSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1003
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1004
	     errorString:(self class name , ' is readonly')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1005
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1006
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1007
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1008
errorUnsupportedOperation
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1009
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1010
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1011
    "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
  1012
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1013
    ^ InvalidOperationSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1014
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1015
	errorString:'unsupported operation'
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1016
		 in:thisContext sender
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1017
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1018
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1019
errorWriteOnly
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1020
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1021
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1022
    "report an error, that the stream is a writeOnly stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1023
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1024
    ^ InvalidReadSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1025
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1026
	     errorString:(self class name , ' is writeonly')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1027
		      in:thisContext sender
2
claus
parents: 1
diff changeset
  1028
!
claus
parents: 1
diff changeset
  1029
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1030
ioError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1031
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1032
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1033
    "report an error, that some I/O error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1034
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1035
    ^ StreamErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1036
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1037
	     errorString:('I/O error: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1038
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1039
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1040
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1041
lastErrorNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1042
    "return the last error"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1043
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1044
    ^ lastErrorNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1045
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1046
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1047
lastErrorString
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1048
    "return a message string describing the last error"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1049
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1050
    (lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1051
	^ 'I/O error'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1052
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1053
    ^ OperatingSystem errorTextForNumber:lastErrorNumber
2
claus
parents: 1
diff changeset
  1054
!
claus
parents: 1
diff changeset
  1055
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1056
openError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1057
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1058
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1059
    "report an error, that the open failed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1060
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1061
    ^ OpenErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1062
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1063
	     errorString:('error on open: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1064
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1065
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1066
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1067
readError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1068
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1069
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1070
    "report an error, that some read error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1071
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1072
    ^ ReadErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1073
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1074
	     errorString:('read error: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1075
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1076
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1077
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1078
writeError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1079
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1080
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1081
    "report an error, that some write error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1082
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1083
    ^ WriteErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1084
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1085
	     errorString:('write error: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1086
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1087
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1088
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1089
!ExternalStream methodsFor:'instance release'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1090
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1091
closeFile
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1092
    "low level close - may be redefined in subclasses"
2
claus
parents: 1
diff changeset
  1093
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1094
%{
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1095
    OBJ fp;
2
claus
parents: 1
diff changeset
  1096
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1097
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1098
	__INST(filePointer) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1099
	__BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1100
	fclose(__FILEVal(fp));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1101
	__END_INTERRUPTABLE__
10
claus
parents: 5
diff changeset
  1102
    }
claus
parents: 5
diff changeset
  1103
%}
claus
parents: 5
diff changeset
  1104
!
claus
parents: 5
diff changeset
  1105
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1106
disposed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1107
    "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
  1108
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1109
    self closeFile
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1110
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1111
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1112
setFilePointer:anInteger
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1113
    filePointer := anInteger
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1114
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1115
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1116
shallowCopyForFinalization
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1117
    "return a copy for finalization-registration;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1118
     since all we need at finalization time is the fileDescriptor,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1119
     a cheaper copy is possible."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1120
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1121
    ^ self class basicNew setFilePointer:filePointer
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1122
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1123
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1124
shutDown
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1125
    "close the stream - added for protocol compatibility with PipeStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1126
     see comment there"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1127
1642
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1128
    filePointer isNil ifTrue:[^ self].
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1129
    Lobby unregister:self.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1130
    self closeFile
1642
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1131
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1132
    "Modified: 30.8.1996 / 00:39:21 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1133
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1134
2
claus
parents: 1
diff changeset
  1135
!ExternalStream methodsFor:'line reading/writing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1136
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1137
nextLine
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1138
    "read the next line (characters up to newline).
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1139
     Return a string containing those characters excluding the newline.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1140
     If the previous-to-last character is a cr, this is also removed,
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1141
     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
  1142
     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
  1143
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1144
    |line|
971
eb70f5674303 max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
  1145
eb70f5674303 max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
  1146
%{  /* STACK:17000 */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1147
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1148
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1149
    int len, ret;
971
eb70f5674303 max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
  1150
    char buffer[16*1024];
521
70533ec40482 use new MKSTRING_L if length is known (avoids a useless strlen)
Claus Gittinger <cg@exept.de>
parents: 481
diff changeset
  1151
    char *rslt, *nextPtr, *limit;
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1152
    int fd, ch;
1068
92fdcccf12a3 alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1153
    int _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1154
    OBJ fp;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1155
    int lineTooLong = 0;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1156
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1157
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1158
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1159
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1160
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1161
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1162
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1163
	buffer[0] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1164
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1165
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1166
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1167
	    __READING__(f);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1168
	} 
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
	rslt = nextPtr = buffer;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1171
	limit = buffer + sizeof(buffer) - 2;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1172
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1173
	for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1174
	    __READBYTE__(ret, f, nextPtr, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1175
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1176
		if (nextPtr == buffer)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1177
		    rslt = NULL;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1178
		if (ret == 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1179
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1180
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1181
		} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1182
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1183
		    goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1184
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1185
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1186
	    if (*nextPtr == '\n') {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1187
		*nextPtr = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1188
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1189
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1190
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1191
	    nextPtr++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1192
	    if (nextPtr >= limit) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1193
		*nextPtr = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1194
		lineTooLong = 1;
2293
aec11c3274cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2264
diff changeset
  1195
		if (@global(InfoPrinting) == true) {
aec11c3274cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2264
diff changeset
  1196
		    fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n");
aec11c3274cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2264
diff changeset
  1197
		}
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1198
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1199
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1200
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1201
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1202
	if (rslt != NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1203
	    len = nextPtr-buffer;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1204
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1205
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1206
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + len);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1207
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1208
	    /* remove EOL character */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1209
	    if (len != 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1210
		if (buffer[len-1] == '\n') {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1211
		    buffer[--len] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1212
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1213
		if ((len != 0) && (buffer[len-1] == '\r')) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1214
		    buffer[--len] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1215
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1216
	    }
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1217
	    line = __MKSTRING_L(buffer, len);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1218
	    if (! lineTooLong) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1219
		RETURN ( line );
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1220
	    }
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1221
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1222
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1223
err: ;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1224
%}.
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1225
    line notNil ifTrue:[
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1226
	"/ the line as read is longer than 16k characters (boy - what a line)
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1227
	"/ The exception could be handled by reading more and returning the
2293
aec11c3274cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2264
diff changeset
  1228
	"/ concatenation in your exception handler (the receiver and the partial
aec11c3274cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2264
diff changeset
  1229
	"/ line are passed as parameter)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1230
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1231
	^ ReadErrorSignal
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1232
	    raiseRequestWith:(Array with:self with:line)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1233
		 errorString:('line too long read error')
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1234
    ].
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1235
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1236
    hitEOF ifTrue:[^ self pastEnd].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1237
    lastErrorNumber notNil ifTrue:[^ self readError].
2
claus
parents: 1
diff changeset
  1238
    filePointer isNil ifTrue:[^ self errorNotOpen].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1239
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1240
    ^ self errorBinary
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1241
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1242
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1243
nextPutLine:aString
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1244
    "write the characters in aString and append a newline or CRLF if useCRLF is set"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1245
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1246
%{
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1247
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1248
    int len, cnt, len1, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1249
    OBJ pos, fp;
537
dc4dad8a5ddd many ExtStream rewrites - has to be reevaluated in all platforms
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1250
    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
  1251
    int o_offs;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1252
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1253
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1254
    if (((fp = __INST(filePointer)) != nil) 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1255
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1256
	&& (__INST(binary) != true)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1257
	&& __isString(aString)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1258
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1259
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1260
	len = __stringSize(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1261
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1262
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1263
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1264
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1265
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1266
	__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
  1267
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1268
	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
  1269
	__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
  1270
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1271
	if (cnt == len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1272
	    len1 = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1273
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1274
	    if (__INST(useCRLF) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1275
		cp = "\r\n"; len = 2;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1276
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1277
		cp = "\n"; len = 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1278
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1279
	    __WRITEBYTES__(cnt, f, cp, len, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1280
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1281
	    if (cnt > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1282
		pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1283
		if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1284
		    __INST(position) = __MKSMALLINT(__intVal(pos)+len1+cnt);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1285
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1286
		RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1287
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1288
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1289
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1290
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1291
%}.
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1292
    super nextPutLine:aString.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1293
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1294
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1295
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1296
    "read from aStream up to and including a line starting with aStringOrNil
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1297
     and append it to self. 
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1298
     Can be used to copy/create large files or copy from a pipe/socket.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1299
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1300
     If aStringOrNil is nil or not matched, copy preceeds to the end.
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1301
     (this allows for example to read a Socket and transfer the data quickly
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1302
      into a file - without creating zillions of temporary strings)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1303
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1304
    |srcFilePointer readError|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1305
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1306
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1307
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1308
    srcFilePointer := aStream filePointer.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1309
    srcFilePointer isNil ifTrue:[aStream errorNotOpen. ^ self].
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1310
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1311
%{  /* STACK:2000 */
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1312
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1313
    FILE *dst, *src;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1314
    char *matchString;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1315
    int matchLen = 0;
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1316
    char buffer[1024];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1317
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1318
    __INST(lastErrorNumber) = nil;
249
claus
parents: 244
diff changeset
  1319
    if (__isSmallInteger(srcFilePointer)) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1320
	if ((aStringOrNil == nil) || __isString(aStringOrNil)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1321
	    if (aStringOrNil != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1322
		matchString = (char *) __stringVal(aStringOrNil);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1323
		matchLen = __stringSize(aStringOrNil);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1324
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1325
	    dst = __FILEVal(__INST(filePointer));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1326
	    src = __FILEVal(srcFilePointer);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1327
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1328
	    errno = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1329
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1330
	    __WRITING__(dst)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1331
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1332
	    for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1333
		if (fgets(buffer, sizeof(buffer)-1, src) == NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1334
		    if (ferror(src)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1335
			readError = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1336
			__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1337
			goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1338
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1339
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1340
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1341
		if (fputs(buffer, dst) == EOF) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1342
		    if (ferror(dst)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1343
			__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1344
			__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1345
			goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1346
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1347
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1348
		}
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1349
#ifndef OLD
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1350
		if (__INST(buffered) == false) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1351
		    fflush(dst);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1352
		}
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1353
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1354
		if (matchLen) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1355
		    if (strncmp(matchString, buffer, matchLen) == 0) 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1356
			break;
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
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1359
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1360
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1361
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1362
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1363
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1364
err: ;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1365
%}.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1366
    readError ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1367
	aStream setLastErrorNumber:readError.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1368
	aStream readError.
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1369
	^ self
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1370
    ].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1371
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1372
    buffered ifFalse:[self errorNotBuffered. ^ self].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1373
    "
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1374
     argument error
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1375
    "
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1376
    self primitiveFailed
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1377
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1378
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1379
peekForLineStartingWith:aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1380
    "read ahead for next line starting with aString;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1381
     return the line-string if found, or nil if EOF is encountered.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1382
     If matched, not advance position behond that line
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1383
     i.e. nextLine will read the matched line.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1384
     If not matched, reposition to original position for firther reading."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1385
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1386
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1387
    filePointer isNil ifTrue:[^ self errorNotOpen].
2
claus
parents: 1
diff changeset
  1388
    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
  1389
    buffered ifFalse:[^ self errorNotBuffered].
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1390
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1391
%{  /* STACK: 2000 */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1392
    FILE *f;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1393
    int l;
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1394
    char buffer[1024];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1395
    char *cp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1396
    char *matchString;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1397
    int  firstpos = -1, lastpos;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1398
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1399
    __INST(lastErrorNumber) = nil;
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
  1400
    if (__isString(aString)) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1401
	matchString = (char *) __stringVal(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1402
	l = __stringSize(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1403
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1404
	f = __FILEVal(__INST(filePointer));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1405
	__READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1406
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1407
	for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1408
	    lastpos = ftell(f);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1409
	    if (firstpos == -1) firstpos = lastpos;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1410
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1411
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1412
	    do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1413
		cp = fgets(buffer, sizeof(buffer)-1, f);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1414
	    } while ((cp == NULL) && ferror(f) && (errno == EINTR) && (clearerr(f), 1));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1415
	    buffer[sizeof(buffer)-1] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1416
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1417
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1418
	    if (cp == NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1419
		if (ferror(f)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1420
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1421
		    goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1422
		} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1423
		    fseek(f, firstpos, SEEK_SET);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1424
		    RETURN (nil);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1425
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1426
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1427
	    if (strncmp(cp, matchString, l) == 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1428
		fseek(f, lastpos, SEEK_SET);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1429
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1430
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1431
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1432
	/* remove EOL character */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1433
	cp = buffer;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1434
	while (*cp && (*cp != '\n')) cp++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1435
	*cp = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1436
	RETURN ( __MKSTRING(buffer) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1437
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1438
err: ;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1439
%}.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1440
    lastErrorNumber notNil ifTrue:[^ self readError].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1441
    ^ self argumentMustBeString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1442
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1443
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1444
peekForLineStartingWithAny:aCollectionOfStrings
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1445
    "read ahead for next line starting with any of aCollectionOfStrings;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1446
     return the index in aCollection if found, nil otherwise..
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1447
     If no match, do not change position; otherwise advance right before the
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1448
     matched line so that nextLine will return this line."
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1449
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1450
    |line startPos linePos index|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1451
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1452
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1453
    filePointer isNil ifTrue:[^ self errorNotOpen].
2
claus
parents: 1
diff changeset
  1454
    binary ifTrue:[^ self errorBinary].
claus
parents: 1
diff changeset
  1455
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1456
    startPos := self position.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1457
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1458
	linePos := self position.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1459
	line := self nextLine.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1460
	line notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1461
	    index := 1.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1462
	    aCollectionOfStrings do:[:prefix |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1463
		(line startsWith:prefix) ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1464
		    self position:linePos.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1465
		    ^ index
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1466
		].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1467
		index := index + 1
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1468
	    ]
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1469
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1470
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1471
    self position:startPos.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1472
    ^ nil
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1473
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1474
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1475
!ExternalStream methodsFor:'misc functions'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1476
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1477
async:aBoolean
779
0e41a665038a commentary
Claus Gittinger <cg@exept.de>
parents: 730
diff changeset
  1478
    "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
  1479
     the receiver will trigger an ioInterrupt.
779
0e41a665038a commentary
Claus Gittinger <cg@exept.de>
parents: 730
diff changeset
  1480
     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
  1481
     Notice: 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1482
	not every OS supports this 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1483
	- check with OS>>supportsIOInterrupts before using"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1484
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1485
    |fd|
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1486
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1487
    filePointer isNil ifTrue:[^ self errorNotOpen].
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1488
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1489
    OperatingSystem supportsIOInterrupts ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1490
	^ self errorUnsupportedOperation
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1491
    ].
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1492
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1493
    fd := self fileDescriptor.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1494
    aBoolean ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1495
	^ OperatingSystem enableIOInterruptsOn:fd
612
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
    ^ OperatingSystem disableIOInterruptsOn:fd
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1498
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1499
    "Modified: 11.1.1997 / 17:50:21 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1500
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1501
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1502
backStep
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1503
    "step back one element -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1504
     redefined, since position is redefined here"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1505
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1506
    self position:(self position - 1)
362
claus
parents: 360
diff changeset
  1507
!
claus
parents: 360
diff changeset
  1508
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1509
blocking:aBoolean
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1510
    "set/clear the blocking attribute - if set (which is the default)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1511
     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
  1512
     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
  1513
     nil.
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1514
     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
  1515
     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
  1516
     in advance. However, the data must then be read using #nextBytes:
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1517
     methods, in order to avoid other (pasEnd) exceptions."
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1518
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1519
    filePointer isNil ifTrue:[^ self errorNotOpen].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1520
    ^ 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
  1521
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1522
    "Modified: 11.1.1997 / 17:48:01 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1523
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1524
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1525
close
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1526
    "close the stream - tell operating system"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1527
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1528
    filePointer isNil ifTrue:[^ self].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1529
    Lobby unregister:self.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1530
    self closeFile.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1531
    filePointer := nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1532
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1533
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1534
create
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1535
    "create the stream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1536
     - this must be redefined in subclass"
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
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1539
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1540
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1541
ioctl:ioctlNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1542
    "to provide a simple ioctl facility - an ioctl is performed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1543
     on the underlying file; no arguments are passed."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1544
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1545
%{
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1546
#ifndef MSDOS_LIKE
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1547
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1548
    int ret, ioNum, ioArg;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1549
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1550
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1551
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1552
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1553
	if (__isSmallInteger(ioctlNumber)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1554
	    ioNum = __intVal(ioctlNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1555
	    f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1556
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1557
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1558
	    do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1559
		errno = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1560
		ret = ioctl(fileno(f), ioNum);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1561
	    } while ((ret < 0) && (errno == EINTR));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1562
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1563
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1564
	    if (ret >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1565
		RETURN ( __MKSMALLINT(ret) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1566
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1567
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1568
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1569
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1570
    }
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1571
#endif
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1572
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1573
    lastErrorNumber notNil ifTrue:[^ self ioError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1574
    filePointer isNil ifTrue:[^ self errorNotOpen].
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
     ioctl-number is not an integer
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1577
     or the system does not support ioctl (MSDOS)
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1578
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1579
    ^ self primitiveFailed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1580
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1581
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1582
ioctl:ioctlNumber with:arg
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1583
    "to provide a simple ioctl facility - an ioctl is performed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1584
     on the underlying file; the argument is passed as argument.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1585
     If the argument is a number, its directly passed; if its a
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1586
     kind of ByteArray (ByteArray, String or Structure) a pointer to
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1587
     the data is passed. This allows performing most ioctls - however,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1588
     it might be tricky to setup the buffer."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1589
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1590
%{
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1591
#ifndef MSDOS_LIKE
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1592
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1593
    int ret, ioNum;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1594
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1595
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1596
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1597
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1598
	if (__isSmallInteger(ioctlNumber) 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1599
	 && (__isSmallInteger(arg) || __isBytes(arg))) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1600
	    f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1601
	    ioNum = __intVal(ioctlNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1602
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1603
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1604
	    do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1605
		errno = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1606
		if (__isSmallInteger(arg)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1607
		    ret = ioctl(fileno(f), ioNum, __intVal(arg));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1608
		} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1609
		    ret = ioctl(fileno(f), ioNum, __ByteArrayInstPtr(arg)->ba_element);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1610
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1611
	    } while ((ret < 0) && (errno == EINTR));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1612
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1613
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1614
	    if (ret >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1615
		RETURN ( __MKSMALLINT(ret) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1616
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1617
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1618
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1619
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1620
    }
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1621
#endif
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1622
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1623
    lastErrorNumber notNil ifTrue:[^ self ioError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1624
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1625
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1626
     ioctl-number is not an integer or argument is not byteArray-like
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1627
     or the system does not support ioctl (MSDOS)
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1628
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1629
    ^ self primitiveFailed
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1632
open
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1633
    "open the stream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1634
     - this must be redefined in subclass"
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
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1637
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1638
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1639
position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1640
    "return the position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1641
     - this must be redefined in subclass"
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
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1644
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1645
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1646
position:anInteger
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1647
    "set the position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1648
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1649
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1650
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1651
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1652
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1653
reset
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1654
    "set the read position to the beginning of the collection"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1655
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1656
    self position:"0" 1
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1657
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1658
1044
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1659
setToEnd
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1660
    "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
  1661
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1662
    ^ self subclassResponsibility
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1663
!
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1664
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1665
truncateTo:newSize
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1666
    "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
  1667
     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
  1668
1068
92fdcccf12a3 alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1669
%{
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1670
#ifdef HAS_FTRUNCATE
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1671
    FILE *f;
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1672
    OBJ fp;
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1673
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1674
    if (((fp = __INST(filePointer)) != nil)
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1675
     && (__INST(mode) != @symbol(readonly))) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1676
	if (__isSmallInteger(newSize)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1677
	    f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1678
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1679
	    if (__INST(buffered) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1680
		__READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1681
		fflush(f);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1682
		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
  1683
	    }
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1684
	    ftruncate(fileno(f), __intVal(newSize));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1685
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1686
	}
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1687
    }
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1688
#endif
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1689
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1690
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1691
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1692
    self errorUnsupportedOperation
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1693
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1694
    "
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1695
     |s|
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1696
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1697
     s := 'test' asFilename writeStream.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1698
     s next:1000 put:$a.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1699
     s truncateTo:100.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1700
     s close.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1701
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1702
     ('test' asFilename fileSize) printNL
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1703
    "
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1704
! !
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
!ExternalStream methodsFor:'non homogenous reading'!
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
nextByte
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1709
    "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
  1710
     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
  1711
     bytes binary value as an integer in 0..255."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1712
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1713
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1714
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1715
    unsigned char byte;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1716
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1717
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1718
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1719
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1720
    if (((fp = __INST(filePointer)) != nil)
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1721
     && (__INST(mode) != @symbol(writeonly))) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1722
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1723
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1724
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1725
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1726
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1727
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1728
	__READBYTE__(ret, f, &byte, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1729
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1730
	    if (__INST(position) != nil)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1731
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1732
	    RETURN (__MKSMALLINT(byte));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1733
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1734
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1735
	if (ret == 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1736
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1737
	} else /* ret < 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1738
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1739
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1740
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1741
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1742
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1743
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1744
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1745
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1746
    ^ self errorWriteOnly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1747
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1748
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1749
nextBytes:count into:anObject startingAt:start
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1750
    "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
  1751
     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
  1752
     If the receiver is some socket/pipe-like stream, an exception
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1753
     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
  1754
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1755
     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
  1756
     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
  1757
     Thus allowing read of partial blocks.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1758
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1759
     The object must have non-pointer indexed instvars 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1760
     (i.e. it must be a ByteArray, String, Float- or DoubleArray).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1761
     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
  1762
     fastest possible physical I/O (since no new objects are allocated).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1763
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1764
     Use with care - non object oriented I/O.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1765
     Warning: in general, you cannot use this method to pass data from other 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1766
     architectures since it does not care for byte order or float representation."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1767
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1768
%{
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1769
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1770
    int cnt, offs, ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1771
    int objSize, nInstVars, nInstBytes;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1772
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1773
    OBJ pos, fp, oClass;
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1774
    int o_offs;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1775
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1776
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1777
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1778
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1779
	&& __bothSmallInteger(count, start)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1780
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1781
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1782
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1783
	oClass = __Class(anObject);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1784
	switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1785
	    case BYTEARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1786
	    case WORDARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1787
	    case LONGARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1788
	    case SWORDARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1789
	    case SLONGARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1790
	    case FLOATARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1791
	    case DOUBLEARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1792
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1793
	    default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1794
		goto bad;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1795
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1796
	cnt = __intVal(count);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1797
	offs = __intVal(start) - 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1798
	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1799
	nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1800
	objSize = __Size(anObject) - nInstBytes;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1801
	if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1802
	    char *cp;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1803
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1804
	    /* 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1805
	     * mhmh - since we are interruptable, anObject may move.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1806
	     * therefore, fetch the cp-pointer within the loop
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1807
	     */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1808
	    _buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1809
	    if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1810
		__READING__(f);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1811
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1812
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1813
	    /*
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1814
	     * on interrupt, anObject may be moved to another location.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1815
	     * So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__,
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1816
	     * to get a new address.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1817
	     */
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1818
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1819
	    cp = (char *)__InstPtr(anObject)+nInstBytes+offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1820
	    __READBYTES__(ret, f, cp, cnt, _buffered);
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1821
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1822
	    o_offs = nInstBytes+offs;
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1823
	    __READBYTES_OBJ__(ret, f, anObject, o_offs, cnt, _buffered);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1824
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1825
	    if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1826
		pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1827
		if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1828
		    __INST(position) = __MKSMALLINT(__intVal(pos) + ret);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1829
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1830
		RETURN (__MKSMALLINT(ret));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1831
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1832
	    if (ret == 0) { 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1833
		__INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1834
	    } else /* ret < 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1835
		__INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1836
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1837
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1838
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1839
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1840
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1841
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1842
    (hitEOF and:[self pastEnd isNil]) ifTrue:[^ 0].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1843
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1844
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1845
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1846
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1847
     count not integer or arg not bit-like (String, ByteArray etc)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1848
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1849
    ^ self primitiveFailed
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1850
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1851
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1852
nextLong
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1853
    "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
  1854
     The returned value may be a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1855
     (msb-first for compatibility with other smalltalks)"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1856
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1857
    ^ self nextUnsignedLongMSB:true
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1858
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1859
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1860
nextLongMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1861
    "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
  1862
     which may be a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1863
     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
  1864
     otherwise least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1865
     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
  1866
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1867
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1868
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1869
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1870
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1871
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1872
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1873
	&& (__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
  1874
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1875
	FILE *f;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1876
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1877
	int value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1878
	char buffer[4];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1879
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1880
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1881
	__READBYTES__(ret, f, buffer, 4, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1882
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1883
	if (ret == 4) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1884
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1885
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 4);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1886
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1887
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1888
		value = (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1889
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1890
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1891
		value = (value << 8) | (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1892
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1893
		value = (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1894
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1895
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1896
		value = (value << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1897
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1898
	    if ((value >= _MIN_INT) && (value <= _MAX_INT)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1899
		RETURN ( __MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1900
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1901
	    RETURN ( __MKLARGEINT(value) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1902
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1903
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1904
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1905
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1906
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1907
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1908
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1909
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1910
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1911
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1912
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1913
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1914
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1915
    ^ self readError.
1079
d47cd86b487b Make methods signal-proof.
Stefan Vogel <sv@exept.de>
parents: 1068
diff changeset
  1916
362
claus
parents: 360
diff changeset
  1917
!
claus
parents: 360
diff changeset
  1918
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1919
nextShortMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1920
    "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
  1921
     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
  1922
     otherwise least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1923
     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
  1924
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1925
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1926
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1927
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1928
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1929
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1930
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1931
	&& (__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
  1932
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1933
	FILE *f;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1934
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1935
	short value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1936
	char buffer[2];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1937
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1938
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1939
	__READBYTES__(ret, f, buffer, 2, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1940
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1941
	if (ret == 2) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1942
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1943
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 2);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1944
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1945
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1946
		value = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1947
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1948
		value = ((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1949
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1950
	    RETURN (__MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1951
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1952
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1953
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1954
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1955
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1956
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1957
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1958
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1959
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1960
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1961
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1962
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1963
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1964
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1965
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1966
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1967
nextUnsignedLongMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1968
    "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
  1969
     a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1970
     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
  1971
     least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1972
     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
  1973
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1974
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1975
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1976
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1977
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1978
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1979
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1980
	&& (__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
  1981
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1982
	FILE *f;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1983
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1984
	unsigned int value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1985
	char buffer[4];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1986
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1987
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1988
	__READBYTES__(ret, f, buffer, 4, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1989
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1990
	if (ret == 4) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1991
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1992
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 4);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1993
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1994
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1995
		value = (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1996
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1997
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1998
		value = (value << 8) | (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1999
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2000
		value = (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2001
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2002
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2003
		value = (value << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2004
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2005
	    if (value <= _MAX_INT) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2006
		RETURN ( __MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2007
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2008
	    RETURN ( __MKULARGEINT(value) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2009
	}
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
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2012
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2013
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2014
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2015
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2016
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2017
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2018
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2019
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2020
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2021
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2022
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2023
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2024
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2025
nextUnsignedShortMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2026
    "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
  2027
     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
  2028
     otherwise least-significant byte comes first.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2029
     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
  2030
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2031
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2032
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2033
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2034
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2035
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2036
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2037
	&& (__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
  2038
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2039
	FILE *f;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2040
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2041
	unsigned int value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2042
	char buffer[2];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2043
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2044
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2045
	__READBYTES__(ret, f, buffer, 2, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2046
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2047
	if (ret == 2) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2048
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2049
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 2);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2050
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2051
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2052
		value = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2053
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2054
		value = ((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2055
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2056
	    RETURN (__MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2057
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2058
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2059
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2060
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2061
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2062
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2063
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2064
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2065
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2066
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2067
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2068
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2069
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2070
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2071
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2072
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2073
nextWord
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2074
    "in text-mode:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2075
	 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
  2076
	 return a string containing those characters.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2077
     in binary-mode:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2078
	 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
  2079
	 unsigned Integer (for compatibility with other smalltalks)"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2080
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2081
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2082
	^ self nextUnsignedShortMSB:true
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2083
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2084
    ^ self nextAlphaNumericWord
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2085
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2086
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2087
!ExternalStream methodsFor:'non homogenous writing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2088
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2089
nextPutByte:aByteValue
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2090
    "write a byte.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2091
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2092
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2093
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2094
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2095
    char c;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2096
    OBJ pos, fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2097
    int cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2098
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2099
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2100
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2101
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2102
	&& __isSmallInteger(aByteValue)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2103
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2104
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2105
	c = __intVal(aByteValue);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2106
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2107
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2108
	    __WRITING__(f)
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
	__WRITEBYTE__(cnt, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2111
	if (cnt == 1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2112
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2113
	    if (pos != nil)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2114
		__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2115
	    RETURN (self);
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
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2118
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2119
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2120
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2121
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2122
    self writeError.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2123
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2124
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2125
nextPutBytes:count from:anObject startingAt:start
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2126
    "write count bytes from an object starting at index start.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2127
     return the number of bytes written - which could be 0.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2128
     The object must have non-pointer indexed instvars 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2129
     (i.e. be a ByteArray, String, Float- or DoubleArray).     
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2130
     Use with care - non object oriented i/o.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2131
     Warning: in general, you cannot use this method to pass data to other 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2132
     architectures since it does not care for byte order or float representation."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2133
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2134
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2135
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2136
    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
  2137
    int objSize, nInstVars, nInstBytes, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2138
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2139
    OBJ oClass, pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2140
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2141
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2142
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2143
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2144
	&& __bothSmallInteger(count, start)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2145
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2146
	oClass = __Class(anObject);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2147
	switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2148
	    case BYTEARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2149
	    case WORDARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2150
	    case LONGARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2151
	    case SWORDARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2152
	    case SLONGARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2153
	    case FLOATARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2154
	    case DOUBLEARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2155
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2156
	    default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2157
		goto bad;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2158
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2159
	len = __intVal(count);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2160
	offs = __intVal(start) - 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2161
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2162
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2163
	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2164
	nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2165
	objSize = __Size(anObject) - nInstBytes;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2166
	if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2167
	    offs += nInstBytes;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2168
	    if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2169
		__WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2170
	    }
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  2171
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2172
	    __WRITEBYTES__(cnt, f, (char *)__InstPtr(anObject)+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
  2173
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  2174
	    __WRITEBYTES_OBJ__(cnt, f, anObject, 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
  2175
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2176
	    if (cnt >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2177
		pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2178
		if (pos != nil)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2179
		    __INST(position) = __MKSMALLINT(__intVal(pos) + cnt);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2180
		RETURN ( __MKSMALLINT(cnt) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2181
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2182
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2183
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2184
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2185
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2186
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2187
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2188
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2189
    (mode == #readonly) ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2190
    ^ self primitiveFailed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2191
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2192
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2193
nextPutLong:aNumber MSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2194
    "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
  2195
     true, data is written most-significant byte first; otherwise least
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2196
     first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2197
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2198
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2199
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2200
    int num;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2201
    char bytes[4];
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2202
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2203
    int cnt, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2204
    OBJ fp, pos;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2205
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2206
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2207
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2208
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2209
	&& __isSmallInteger(aNumber)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2210
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2211
	num = __intVal(aNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2212
	if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2213
	    bytes[0] = (num >> 24) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2214
	    bytes[1] = (num >> 16) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2215
	    bytes[2] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2216
	    bytes[3] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2217
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2218
	    bytes[3] = (num >> 24) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2219
	    bytes[2] = (num >> 16) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2220
	    bytes[1] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2221
	    bytes[0] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2222
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2223
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2224
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2225
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2226
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2227
	} 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2228
	__WRITEBYTES__(cnt, f, bytes, 4, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2229
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2230
	if (cnt == 4) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2231
	    if ((pos = __INST(position)) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2232
		__INST(position) = __MKSMALLINT(__intVal(pos) + 4);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2233
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2234
	    RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2235
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2236
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2237
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2238
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2239
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2240
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2241
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2242
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2243
    aNumber isInteger ifTrue:[
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2244
	^ super nextPutLong:aNumber MSB:msbFlag
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2245
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2246
    self argumentMustBeInteger
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2247
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2248
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2249
nextPutShort:aNumber MSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2250
    "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
  2251
     true, data is written most-significant byte first; otherwise least
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2252
     first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2253
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2254
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2255
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2256
    int num;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2257
    char bytes[2];
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2258
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2259
    int cnt, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2260
    OBJ fp, pos;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2261
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2262
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2263
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2264
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2265
	&& __isSmallInteger(aNumber)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2266
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2267
	num = __intVal(aNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2268
	if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2269
	    bytes[0] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2270
	    bytes[1] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2271
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2272
	    bytes[1] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2273
	    bytes[0] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2274
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2275
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2276
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2277
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2278
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2279
	} 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2280
	__WRITEBYTES__(cnt, f, bytes, 2, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2281
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2282
	if (cnt == 2) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2283
	    if ((pos = __INST(position)) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2284
		__INST(position) = __MKSMALLINT(__intVal(pos) + 2);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2285
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2286
	    RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2287
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2288
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2289
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2290
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2291
    lastErrorNumber notNil ifTrue:[^ self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2292
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2293
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2294
    self argumentMustBeInteger
10
claus
parents: 5
diff changeset
  2295
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2296
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2297
!ExternalStream methodsFor:'private'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2298
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2299
clearEOF
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2300
    hitEOF := false
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2301
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2302
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2303
connectTo:aFileDescriptor withMode:openmode
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2304
    "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
  2305
     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
  2306
     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
  2307
     a Stream object. 
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2308
     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
  2309
     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
  2310
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2311
    |retVal|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2312
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2313
    filePointer notNil ifTrue:[^ self errorOpen].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2314
%{
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2315
    FILE *f;
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2316
    OBJ fp;
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2317
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2318
    if (__isSmallInteger(aFileDescriptor) 
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2319
     && (__qClass(openmode)== @global(String))) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2320
	f = (FILE *) fdopen(__intVal(aFileDescriptor), (char *)__stringVal(openmode));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2321
	if (f == NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2322
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2323
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2324
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2325
	    __INST(filePointer) = fp = __MKOBJ((int)f); __STORE(self, fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2326
	    __INST(position) = __MKSMALLINT(1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2327
	    retVal = self;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2328
	}
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2329
    }
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2330
%}.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2331
    retVal notNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2332
	buffered := true.       "default is buffered"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2333
	Lobby register:self
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2334
    ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2335
    lastErrorNumber notNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2336
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2337
	 the open failed for some reason ...
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2338
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2339
	^ self openError
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2340
    ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2341
    ^ retVal
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2342
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2343
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2344
reOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2345
    "sent after snapin to reopen streams.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2346
     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
  2347
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  2348
    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
  2349
    filePointer := nil.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2350
    Lobby unregister:self.
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  2351
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  2352
    "Modified: 10.1.1997 / 17:50:44 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2353
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2354
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2355
setLastError:aNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2356
    lastErrorNumber := aNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2357
! !
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
!ExternalStream methodsFor:'queries'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2360
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2361
isBinary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2362
    "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
  2363
     The default when created is false."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2364
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2365
    ^ binary
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2368
isExternalStream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2369
    "return true, if the receiver is some kind of externalStream;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2370
     true is returned here - the method redefined from Object."
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
    ^ true
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2373
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2374
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2375
isReadable 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2376
    "return true, if this stream can be read from"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2377
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2378
    ^ (mode ~~ #writeonly)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2379
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2380
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2381
isWritable 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2382
    "return true, if this stream can be written to"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2383
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2384
    ^ (mode ~~ #readonly)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2385
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2386
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2387
!ExternalStream methodsFor:'reading'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2388
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2389
next
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2390
    "return the next element; advance read position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2391
     In binary mode, an integer is returned, otherwise a character.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2392
     If there are no more elements, nil is returned."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2393
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2394
%{
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2395
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2396
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2397
    OBJ pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2398
    unsigned char ch;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2399
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2400
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2401
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2402
	&& (__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
  2403
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2404
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2405
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2406
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2407
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2408
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2409
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2410
	__READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2411
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2412
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2413
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2414
	    if (__isSmallInteger(pos)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2415
		__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2416
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2417
		__INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2418
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2419
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2420
		RETURN ( __MKSMALLINT(ch) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2421
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2422
	    RETURN ( __MKCHARACTER(ch) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2423
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2424
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2425
	__INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2426
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2427
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2428
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2429
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2430
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2431
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2432
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2433
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2434
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2435
    filePointer isNil ifTrue:[^ self errorNotOpen].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2436
    ^ self errorWriteOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2437
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2438
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2439
next:count
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2440
    "return the next count elements of the stream as a collection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2441
     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
  2442
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2443
    |coll nRead|
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2444
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2445
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2446
	coll := ByteArray uninitializedNew:count
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2447
    ] ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2448
	coll := String new:count
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2449
    ].
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2450
    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
  2451
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2452
    "/ for readStream protocol compatibility, 
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2453
    "/ we must raise an exception here.
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2454
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2455
    nRead < count ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2456
	^ self pastEnd
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2457
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2458
    ^ coll
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2459
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2460
    "Modified: 11.1.1997 / 17:44:17 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2461
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2462
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2463
peek
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2464
    "return the element to be read next without advancing read position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2465
     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
  2466
     If there are no more elements, nil is returned."
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2467
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2468
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2469
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2470
    unsigned char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2471
    int ret, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2472
    OBJ fp;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2473
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2474
    __INST(lastErrorNumber) = nil;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2475
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2476
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2477
	&& (__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
  2478
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2479
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2480
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2481
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2482
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2483
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2484
	__READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2485
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2486
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2487
	    __UNGETC__(c, f, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2488
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2489
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2490
		RETURN ( __MKSMALLINT(c) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2491
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2492
	    RETURN ( __MKCHARACTER(c) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2493
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2494
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2495
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2496
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2497
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2498
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2499
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2500
%}.
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2501
    hitEOF ifTrue:[^ self pastEnd]. 
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2502
    lastErrorNumber notNil ifTrue:[^ self readError].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2503
    filePointer isNil ifTrue:[^ self errorNotOpen].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2504
    ^ self errorWriteOnly
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2505
!
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2506
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2507
upToEnd
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2508
    "return a collection of the elements up-to the end.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2509
     Return nil if the stream-end is reached before."
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2510
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2511
    |answerStream ch|
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2512
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2513
    answerStream := WriteStream on:(self contentsSpecies new).
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2514
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2515
	ch := self next.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2516
	ch notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2517
	    answerStream nextPut:ch
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2518
	]
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2519
    ].
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2520
    ^ answerStream contents
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2521
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2522
    "Created: 25.4.1996 / 14:40:31 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2523
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2524
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2525
!ExternalStream methodsFor:'reimplemented for speed'!
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2526
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2527
nextAlphaNumericWord
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2528
    "read the next word (i.e. up to non letter-or-digit) after first
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2529
     skipping any whiteSpace.
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2530
     Return a string containing those characters.
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2531
     There is a limit of 1023 characters in the word - if longer,
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2532
     it is truncated."
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2533
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2534
%{  /* STACK: 2000 */
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2535
    FILE *f;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2536
    int len;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2537
    char buffer[1024];
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2538
    unsigned char ch;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2539
    int cnt = 0;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2540
    int ret, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2541
    OBJ fp;
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2542
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2543
    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
  2544
     && (__INST(mode) != @symbol(writeonly))
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2545
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2546
	f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2547
	_buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2548
	if (_buffered) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2549
	    __READING__(f)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2550
	}
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2551
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2552
	/*
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2553
	 * skip whiteSpace first ...
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2554
	 */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2555
	do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2556
	    __READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2557
	    if (ret > 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2558
		cnt++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2559
	    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2560
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2561
	} while (
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2562
#ifndef NON_ASCII
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2563
		 (ch < ' ') ||
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2564
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2565
		 (ch == ' ' ) || (ch == '\t') || (ch == '\r')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2566
	      || (ch == '\n') || (ch == 0x0b));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2567
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2568
	len = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2569
	while (ret > 0 && 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2570
	       (((ch >= 'a') && (ch <= 'z')) ||
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2571
		((ch >= 'A') && (ch <= 'Z')) ||
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2572
		((ch >= '0') && (ch <= '9')))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2573
	) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2574
	    buffer[len++] = ch;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2575
	    if (len >= (sizeof(buffer)-1)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2576
		/* emergency */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2577
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2578
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2579
	    __READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2580
	    if (ret > 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2581
		cnt++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2582
	    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2583
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2584
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2585
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2586
	if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2587
	    if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2588
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2589
		goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2590
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2591
	    else if (ret == 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2592
		__INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2593
	} else {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2594
	    __UNGETC__(ch, f, _buffered);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2595
	    cnt--;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2596
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2597
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2598
	if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2599
	    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + cnt);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2600
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2601
	if (len != 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2602
	    buffer[len] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2603
	    RETURN ( __MKSTRING_L(buffer, len) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2604
	}
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2605
    }
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2606
err: ;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2607
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2608
    hitEOF ifTrue:[^ self pastEnd].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2609
    lastErrorNumber notNil ifTrue:[^ self readError].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2610
    filePointer isNil ifTrue:[^ self errorNotOpen].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2611
    ^ self errorWriteOnly
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2612
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2613
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2614
nextChunk
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2615
    "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
  2616
     exclamation mark. Within the chunk, exclamation marks have to be doubled -
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2617
     except within primitive code (this exception was added to make it easier
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2618
     to edit primitive code with external editors). This means, that other
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2619
     Smalltalks cannot always read chunks containing primitive code - but that
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2620
     doesnt really matter, since C-primitives are an ST/X feature anyway.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2621
     Reimplemented here for more speed."
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2622
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  2623
    |retVal outOfMemory buffer|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2624
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2625
    filePointer isNil ifTrue:[^ self errorNotOpen].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2626
    binary ifTrue:[^ self errorBinary].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2627
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2628
443
Claus Gittinger <cg@exept.de>
parents: 441
diff changeset
  2629
%{  /* STACK: 8000 */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  2630
    /*
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  2631
     * the main trick (and a bit of complication) here
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2632
     * is to read the first 7k 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
  2633
     * 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
  2634
     * 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
  2635
     */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2636
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2637
    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
  2638
    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
  2639
    int ret;
1823
51ffb7231437 type casts
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  2640
    unsigned char *bufferPtr = (unsigned char *)0;
668
73165201a9da nextChunk: %{ is only recognized if at begin-of-line
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  2641
    char fastBuffer[7000];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2642
    REGISTER int index;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2643
    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
  2644
    int atBeginOfLine = 1, inPrimitive = 0;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2645
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2646
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2647
    f = __FILEVal(__INST(filePointer));
668
73165201a9da nextChunk: %{ is only recognized if at begin-of-line
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  2648
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2649
    _buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2650
    if (_buffered) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2651
	__READING__(f)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2652
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2653
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2654
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2655
     * skip spaces
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2656
     */
673
2c3a4a536cd1 oops - handling of exclas within primitives was wrong
Claus Gittinger <cg@exept.de>
parents: 671
diff changeset
  2657
    c = '\n';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2658
    while (! done) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2659
	lastC = c;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2660
	__READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2661
	if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2662
	    goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2663
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2664
	nread++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2665
	atBeginOfLine = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2666
	switch (c) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2667
	    case '\n':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2668
	    case ' ':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2669
	    case '\t':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2670
	    case '\r':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2671
	    case '\b':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2672
	    case '\014':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2673
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2674
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2675
	    default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2676
		atBeginOfLine = (lastC == '\n');
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2677
		done = 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2678
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2679
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2680
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2681
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2682
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2683
     * read chunk into a buffer
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2684
     */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  2685
    bufferPtr = fastBuffer; fastFlag = 1;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2686
    currSize = sizeof(fastBuffer);
362
claus
parents: 360
diff changeset
  2687
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2688
    index = 0;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2689
    for (;;) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2690
	__READBYTE__(ret, f, &peekC, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2691
	if ((c == '%') && atBeginOfLine && ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2692
	    if (peekC == '{') {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2693
		inPrimitive = 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2694
	    } else if (peekC == '}') {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2695
		inPrimitive = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2696
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2697
	} else if (c == '!' && !inPrimitive) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2698
	    if (ret > 0 && peekC == '!') {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2699
		/*
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2700
		 * convert double-! to a single !
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2701
		 */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2702
		__READBYTE__(ret, f, &peekC, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2703
		if (ret > 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2704
		    nread++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2705
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2706
		/*
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2707
		 * End of chunk, push back lookahead character
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2708
		 * and leave loop.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2709
		 */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2710
		if (ret > 0) {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2711
		    __UNGETC__(peekC, f, _buffered);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2712
		} else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2713
		    ret = 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2714
		break; 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2715
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2716
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2717
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2718
	/* 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2719
	 * do we have to resize the buffer ? 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2720
	 */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2721
	if ((index+2) >= currSize) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2722
	    OBJ newBuffer;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2723
	    unsigned char *nbp;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2724
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2725
	    newBuffer = __MKEMPTYSTRING(currSize * 2);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2726
	    if (newBuffer == nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2727
		/*
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2728
		 * mhmh - chunk seems to be very big ....
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2729
		 */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2730
		outOfMemory = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2731
		goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2732
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2733
	    nbp = __stringVal(newBuffer);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2734
	    if (!fastFlag) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2735
		/*
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2736
		 * old buffer may have moved - refetch pointer
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2737
		 */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2738
		bufferPtr = __stringVal(buffer);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2739
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2740
	    bcopy(bufferPtr, nbp, index);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2741
	    bufferPtr = nbp;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2742
	    bufferPtr[index] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2743
	    buffer = newBuffer;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2744
	    fastFlag = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2745
	    currSize = currSize * 2;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2746
	} else if (!fastFlag) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2747
	    /*
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2748
	     * old buffer may have moved - refetch pointer
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2749
	     */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2750
	    bufferPtr = __stringVal(buffer);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2751
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2752
	bufferPtr[index++] = c;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2753
	if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2754
	    if (ret == 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2755
		break;          /* End of chunk reached */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2756
	    goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2757
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2758
	nread++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2759
	atBeginOfLine = (c == '\n');
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2760
	c = peekC;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2761
    }
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2762
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2763
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2764
     * 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
  2765
     * 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
  2766
     * 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
  2767
     * fast (C) buffer or from real (ST) buffer.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2768
     */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  2769
    if (fastFlag) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2770
	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
  2771
    } else {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2772
	retVal = __MKSTRING_ST_L(buffer, index);
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2773
    }
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2774
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2775
err: ;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2776
    if (ret <= 0) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2777
	if (ret == 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2778
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2779
	else /* ret < 0 */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2780
	    __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
  2781
    }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2782
    if (__INST(position) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2783
	__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
  2784
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2785
%}.
370
claus
parents: 369
diff changeset
  2786
    retVal isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2787
	"/
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2788
	"/ arrive here with retVal==nil either on error or premature EOF
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2789
	"/ or if running out of malloc-memory
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2790
	"/
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2791
	hitEOF ifTrue:[^ self pastEnd].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2792
	lastErrorNumber notNil ifTrue:[^ self readError].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2793
	outOfMemory == true ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2794
	    "
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2795
	     buffer memory allocation failed.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2796
	     When we arrive here, there was no memory available for the
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2797
	     chunk. (seems to be too big of a chunk ...)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2798
	     Bad luck - you should increase the ulimit and/or swap space on your machine.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2799
	    "
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2800
	    ^ ObjectMemory allocationFailureSignal raise.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2801
	]
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2802
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2803
    ^ retVal
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2804
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2805
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2806
nextMatchFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2807
    "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
  2808
     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
  2809
     the element after anObject.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2810
     Only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2811
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2812
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2813
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2814
    int ret, peekValue;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2815
    char c;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2816
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2817
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2818
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2819
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2820
	&& (__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
  2821
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2822
	if ((__INST(binary) == true) && __isSmallInteger(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2823
	    peekValue = __intVal(anObject) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2824
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2825
	    if ((__INST(binary) != true) && __isCharacter(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2826
		peekValue = __intVal(_characterVal(anObject)) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2827
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2828
		peekValue = -1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2829
	    }   
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2830
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2831
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2832
	if (peekValue >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2833
	    int _buffered;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2834
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2835
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2836
	    f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2837
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2838
	    if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2839
		__READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2840
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2841
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2842
	    for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2843
		__READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2844
		if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2845
		    if (ret < 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2846
			__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2847
		    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2848
			__INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2849
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2850
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2851
		if (c == peekValue) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2852
		    RETURN (anObject);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2853
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2854
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2855
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2856
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2857
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2858
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2859
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2860
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2861
    ^ super nextMatchFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2862
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2863
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2864
peekFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2865
    "return true and move past next element, if next == something.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2866
     Otherwise, stay and return false. False is also returned
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2867
     when EOF is encountered.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2868
     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
  2869
     text mode; only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2870
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2871
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2872
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2873
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2874
    int ret, peekValue, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2875
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2876
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2877
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2878
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2879
	&& (__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
  2880
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2881
	if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2882
	    if (__isSmallInteger(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2883
		peekValue = __intVal(anObject) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2884
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2885
		goto bad;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2886
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2887
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2888
	    if (__isCharacter(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2889
		peekValue = __intVal(_characterVal(anObject)) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2890
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2891
		goto bad;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2892
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2893
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2894
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2895
	f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2896
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2897
	_buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2898
	if (_buffered) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2899
	    __READING__(f)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2900
	}
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2901
	__READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2902
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2903
	    if (c == peekValue) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2904
		OBJ pos;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2905
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2906
		if ((pos = __INST(position)) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2907
		    __INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2908
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2909
		RETURN (true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2910
	    }
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2911
	    __UNGETC__(c, f, _buffered);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2912
	    RETURN (false);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2913
	} 
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2914
	if (ret < 0) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2915
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2916
	} else /* ret == 0 */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2917
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2918
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2919
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2920
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2921
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2922
    hitEOF ifTrue:[self pastEnd. ^ false].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2923
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2924
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2925
    ^ super peekFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2926
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2927
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2928
skipLine
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2929
    "read the next line (characters up to newline) skip only;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2930
     return nil if EOF reached, self otherwise. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2931
     Not allowed in binary mode."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2932
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2933
%{  /* STACK:2000 */
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2934
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2935
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2936
    OBJ fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2937
    int ret, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2938
    char c;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2939
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2940
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2941
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2942
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2943
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2944
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2945
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2946
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2947
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2948
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2949
	for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2950
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2951
	    if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2952
		if (c == '\n')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2953
		    RETURN(self) 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2954
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2955
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2956
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2957
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2958
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2959
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2960
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2961
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2962
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2963
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2964
    hitEOF ifTrue:[^ self pastEnd].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2965
    lastErrorNumber notNil ifTrue:[self readError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2966
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2967
    binary ifTrue:[self errorBinary. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2968
    self errorWriteOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2969
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2970
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2971
skipSeparators
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2972
    "skip all whitespace; next will return next non-white-space character
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2973
     or nil if endOfFile reached. Not allowed in binary mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2974
     - reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2975
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2976
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2977
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2978
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2979
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2980
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2981
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2982
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2983
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2984
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2985
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2986
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2987
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2988
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2989
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2990
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2991
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2992
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2993
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2994
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2995
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2996
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2997
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2998
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2999
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3000
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3001
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3002
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3003
	    switch (c) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3004
		case ' ':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3005
		case '\t':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3006
		case '\n':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3007
		case '\r':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3008
		case '\b':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3009
		case '\f':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3010
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3011
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3012
		default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3013
		    __UNGETC__(c, f, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3014
		    RETURN ( __MKCHARACTER(c & 0xFF) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3015
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3016
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3017
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3018
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3019
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3020
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3021
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3022
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3023
    ^ self errorBinary.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3024
!
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
skipSeparatorsExceptCR
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3027
    "skip all whitespace but no newlines;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3028
     next will return next non-white-space character
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3029
     or nil if endOfFile reached. Not allowed in binary mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3030
     - reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3031
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3032
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3033
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3034
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3035
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3036
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3037
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3038
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3039
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3040
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3041
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3042
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3043
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3044
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3045
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3046
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3047
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3048
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3049
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3050
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3051
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3052
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3053
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3054
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3055
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3056
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3057
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3058
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3059
	    switch (c) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3060
		case ' ':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3061
		case '\t':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3062
		case '\b':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3063
		case '\f':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3064
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3065
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3066
		default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3067
		    __UNGETC__(c, f, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3068
		    RETURN ( __MKCHARACTER(c & 0xFF) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3069
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3070
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3071
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3072
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3073
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3074
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3075
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3076
    (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
  3077
    ^ self errorBinary.
612
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3080
skipThrough:aCharacter
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3081
    "skip all characters up-to and including aCharacter. Return the receiver if
671
53de87163ad5 spelling
Claus Gittinger <cg@exept.de>
parents: 668
diff changeset
  3082
     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
  3083
     The next read operation will return the character after aCharacter.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3084
     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
  3085
     Only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3086
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3087
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3088
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3089
    REGISTER int cSearch;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3090
    unsigned char c;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3091
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3092
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3093
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3094
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3095
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3096
	&& (__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
  3097
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3098
	if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3099
	    /* searched for object must be a smallInteger */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3100
	    if (! __isSmallInteger(aCharacter)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3101
	    cSearch = __intVal(aCharacter);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3102
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3103
	    /* searched for object must be a character */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3104
	    if (! __isCharacter(aCharacter)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3105
	    cSearch = __intVal(_characterVal(aCharacter));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3106
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3107
	/* Q: should we just say: "not found" ? */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3108
	if ((cSearch < 0) || (cSearch > 255)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3109
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3110
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3111
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3112
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3113
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3114
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3115
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3116
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3117
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3118
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3119
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3120
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3121
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3122
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3123
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3124
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3125
	    if (c == cSearch) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3126
		RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3127
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3128
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3129
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3130
badArgument: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3131
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3132
    hitEOF ifTrue:[^ self pastEnd].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3133
    lastErrorNumber notNil ifTrue:[self readError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3134
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3135
    (mode == #writeonly) ifTrue:[self errorWriteOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3136
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3137
     argument must be integer/character in binary mode, 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3138
     character in text mode
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3139
    "
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3140
    self error:'invalid argument'.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3141
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3142
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3143
     |s|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3144
     s := 'Makefile' asFilename readStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3145
     s skipThrough:$=.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3146
     s next:10
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3147
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3148
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3149
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3150
skipToAll:aString
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3151
    "skip for the sequence given by the argument, aCollection;
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3152
     return nil if not found, self otherwise. 
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3153
     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
  3154
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3155
    |oldPos|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3156
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3157
    oldPos := self position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3158
    (self skipThroughAll:aString) isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3159
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3160
	 restore position
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3161
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3162
	self position:oldPos.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3163
	^ nil
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3164
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3165
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3166
     position before match-string
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3167
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3168
    self position:(self position - aString size).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3169
    ^ self
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3170
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3171
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3172
     |s|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3173
     s := 'Makefile' asFilename readStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3174
     s skipToAll:'are'.
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3175
     s next:10 
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3176
    "
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3177
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3178
    "Modified: 26.6.1996 / 09:22:05 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3179
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3180
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3181
!ExternalStream methodsFor:'testing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3182
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3183
atEnd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3184
    "return true, if position is at end"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3185
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3186
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3187
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3188
    OBJ fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3189
    char c;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3190
    int ret;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3191
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3192
    if (__INST(hitEOF) == true) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3193
	RETURN (true);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3194
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3195
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3196
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3197
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3198
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3199
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3200
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3201
	if (__INST(buffered) == false) {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3202
	    if (__INST(readAhead) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3203
		RETURN (false);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3204
	    }
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3205
	    /*
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3206
	     * read ahead ...
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3207
	     */
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3208
	    __READBYTE__(ret, f, &c, 0);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3209
	    if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3210
		__UNGETC__(c, f, 0);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3211
	    }
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3212
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3213
	    /*
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3214
	     * This does not work:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3215
	     *  RETURN ( feof(f) ? true : false );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3216
	     *     libc tests, if EOF has already bean read,
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3217
	     *     smallatalk asks, if next read will return EOF
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3218
	     */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3219
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3220
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3221
	    __READBYTE__(ret, f, &c, 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3222
	    if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3223
		__UNGETC__(c, f, 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3224
	    }
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3225
	}
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3226
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3227
	if (ret > 0) {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3228
	    RETURN (false);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3229
	}
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3230
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3231
	if (ret == 0) { 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3232
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3233
	    RETURN (true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3234
	}
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3235
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3236
	/* ret < 0 */
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3237
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3238
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3239
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3240
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3241
    ^ self errorNotOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3242
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3243
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3244
canReadWithoutBlocking
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3245
    "return true, if any data is available for reading (i.e.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3246
     a read operation will not block the smalltalk process), false otherwise."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3247
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3248
    |fd|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3249
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3250
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3251
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3252
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3253
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3254
    ^ OperatingSystem readCheck:fd
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
     |pipe|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3258
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3259
     pipe := PipeStream readingFrom:'(sleep 10; echo hello)'.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3260
     pipe canReadWithoutBlocking ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3261
	 Transcript showCR:'data available'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3262
     ] ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3263
	 Transcript showCR:'no data available'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3264
     ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3265
     pipe close
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3266
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3267
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3268
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3269
canWriteWithoutBlocking
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3270
    "return true, if data can be written into the stream 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3271
     (i.e. a write operation will not block the smalltalk process)."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3272
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3273
    |fd|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3274
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3275
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3276
    mode == #readonly ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3277
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3278
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3279
    ^ OperatingSystem writeCheck:fd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3280
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3281
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3282
!ExternalStream methodsFor:'waiting for I/O'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3283
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3284
readWait
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3285
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3286
     becomes ready for reading. If data is already available,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3287
     return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3288
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3289
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3290
    self readWaitWithTimeoutMs:nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3291
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3292
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3293
readWaitWithTimeout:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3294
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3295
     becomes ready for reading or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3296
     If data is already available, return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3297
     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
  3298
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3299
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3300
    ^ self readWaitWithTimeoutMs:timeout * 1000
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3301
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3302
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3303
readWaitWithTimeoutMs:timeout 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3304
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3305
     becomes ready for reading or a timeout (in milliseconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3306
     If data is already available, return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3307
     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
  3308
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3309
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3310
    |fd inputSema hasData wasBlocked|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3311
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3312
    readAhead notNil ifTrue:[^ false].
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3313
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3314
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3315
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3316
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3317
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3318
    (OperatingSystem readCheck:fd) ifTrue:[^ false].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3319
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3320
    wasBlocked := OperatingSystem blockInterrupts.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3321
    hasData := OperatingSystem readCheck:fd.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3322
    hasData ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3323
	inputSema := Semaphore new name:'readWait'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3324
	[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3325
	    timeout notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3326
		Processor signal:inputSema afterMilliseconds:timeout 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3327
	    ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3328
	    Processor signal:inputSema onInput:fd.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3329
	    Processor activeProcess state:#ioWait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3330
	    inputSema wait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3331
	    Processor disableSemaphore:inputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3332
	    hasData := OperatingSystem readCheck:fd
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3333
	] valueOnUnwindDo:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3334
	    Processor disableSemaphore:inputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3335
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3336
	]
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3337
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3338
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3339
    ^ hasData not
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3340
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3341
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3342
writeWait
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3343
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3344
     becomes ready for writing.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3345
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3346
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3347
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3348
    self writeWaitWithTimeoutMs:nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3349
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3350
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3351
writeWaitWithTimeout:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3352
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3353
     becomes ready for writing or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3354
     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
  3355
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3356
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3357
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3358
    ^ self writeWaitWithTimeoutMs:timeout * 1000
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3359
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3360
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3361
writeWaitWithTimeoutMs:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3362
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3363
     becomes ready for writing or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3364
     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
  3365
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3366
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3367
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3368
    |fd outputSema canWrite wasBlocked|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3369
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3370
    filePointer isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3371
	^ self errorNotOpen
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3372
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3373
    mode == #readonly ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3374
	^ self errorReadOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3375
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3376
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3377
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3378
    (OperatingSystem writeCheck:fd) ifTrue:[^ false].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3379
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3380
    wasBlocked := OperatingSystem blockInterrupts.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3381
    canWrite := OperatingSystem writeCheck:fd.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3382
    canWrite ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3383
	outputSema := Semaphore new name:'writeWait'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3384
	[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3385
	    timeout notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3386
		Processor signal:outputSema afterMilliseconds:timeout
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3387
	    ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3388
	    Processor signal:outputSema onOutput:fd.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3389
	    Processor activeProcess state:#ioWait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3390
	    outputSema wait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3391
	    Processor disableSemaphore:outputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3392
	    canWrite := OperatingSystem writeCheck:fd
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3393
	] valueOnUnwindDo:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3394
	    Processor disableSemaphore:outputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3395
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3396
	]
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3397
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3398
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3399
    ^ canWrite not
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3400
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3401
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3402
!ExternalStream methodsFor:'writing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3403
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3404
cr
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3405
    "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
  3406
     reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3407
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3408
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3409
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3410
    int len, cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3411
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3412
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3413
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3414
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3415
    if (((fp = __INST(filePointer)) != nil)
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3416
	&& (__INST(mode) != @symbol(readonly))
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3417
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3418
    ) {
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3419
	f = __FILEVal(fp);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3420
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3421
	if (_buffered = (__INST(buffered) == true)) { 
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3422
	    __WRITING__(f)
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3423
	}
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3424
	if (__INST(useCRLF) == true) {
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3425
	    cp = "\r\n"; len = 2;
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3426
	} else {
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3427
	    cp = "\n"; len = 1;
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3428
	}
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3429
	__WRITEBYTES__(cnt, f, cp, len, _buffered);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3430
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3431
	if (cnt == len) {
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3432
	    if (__INST(position) != nil) {
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3433
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + len);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3434
	    }
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3435
	    RETURN ( self );
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3436
	}
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3437
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3438
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3439
%}.
2326
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3440
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3441
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3442
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3443
    self errorBinary
612
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
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3446
flush
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3447
    "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
  3448
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3449
%{
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3450
    OBJ fp;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3451
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3452
    __INST(lastErrorNumber) = nil;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3453
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3454
	if (__INST(mode) != @symbol(readonly)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3455
	    if (__INST(buffered) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3456
		__BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3457
		fflush( __FILEVal(fp) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3458
		__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3459
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3460
	}
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3461
    }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3462
%}
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3463
!
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3464
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3465
nextPut:aCharacter
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3466
    "write the argument, aCharacter - return nil if failed, self if ok.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3467
     Only single-byte characters are currently supported"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3468
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3469
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3470
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3471
    char c;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3472
    int cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3473
    OBJ pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3474
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3475
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3476
    if (((fp = __INST(filePointer)) != nil) 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3477
	&& (__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
  3478
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3479
	if (__INST(binary) != true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3480
	    if (__isCharacter(aCharacter)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3481
		c = __intVal(__characterVal(aCharacter)) & 0xFF;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3482
    doWrite:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3483
		f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3484
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
		if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3487
		    __WRITING__(f)
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
		__WRITEBYTE__(cnt, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3490
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3491
		if (cnt == 1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3492
		    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3493
		    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3494
			__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3495
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3496
		    RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3497
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3498
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3499
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3500
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3501
	    if (__isSmallInteger(aCharacter)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3502
		c = __intVal(aCharacter);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3503
		goto doWrite;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3504
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3505
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3506
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3507
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3508
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3509
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3510
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3511
    binary ifFalse:[self argumentMustBeCharacter. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3512
    self argumentMustBeInteger.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3513
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3514
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3515
nextPutAll:aCollection
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3516
    "write all elements of the argument, aCollection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3517
     Reimplemented for speed when writing strings or byteArrays.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3518
     For others, falls back to general method in superclass."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3519
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3520
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3521
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3522
    int len, cnt;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3523
    OBJ pos, fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3524
    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
  3525
    int o_offs;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3526
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3527
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3528
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3529
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3530
	&& (__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
  3531
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3532
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3533
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3534
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3535
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  3536
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3537
	if (__isString(aCollection) || __isSymbol(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3538
	    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
  3539
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3540
	    __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
  3541
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  3542
	    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
  3543
	    __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
  3544
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3545
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3546
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3547
		int offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3548
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3549
		if (__isByteArray(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3550
		    offs = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3551
		    len = _byteArraySize(aCollection);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3552
		} else if (__isBytes(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3553
		    offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3554
		    len = _byteArraySize(aCollection) - offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3555
		} else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3556
		    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
  3557
#ifdef BUGGY
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  3558
		__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
  3559
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  3560
		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
  3561
		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
  3562
		__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
  3563
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3564
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3565
		goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3566
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  3567
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3568
	if (cnt == len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3569
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3570
	    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3571
		__INST(position) = __MKSMALLINT(__intVal(pos) + len);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3572
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3573
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3574
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3575
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3576
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  3577
out: ;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3578
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3579
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3580
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3581
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3582
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3583
    ^ super nextPutAll:aCollection
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3584
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3585
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3586
nextPutAll:aCollection startingAt:start to:stop
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3587
    "write a range of elements of the argument, aCollection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3588
     Reimplemented for speed when writing strings or byteArrays.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3589
     For others, falls back to general method in superclass."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3590
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3591
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3592
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3593
    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
  3594
    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
  3595
    int o_offs;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3596
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3597
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3598
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3599
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3600
	&& __bothSmallInteger(start, stop)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3601
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3602
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3603
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3604
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3605
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3606
	iStart = __intVal(start);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3607
	iStop = __intVal(stop);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3608
	if ((iStart < 1) || (iStop < iStart)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3609
	    RETURN(self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3610
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3611
	if (__isString(aCollection) || __isSymbol(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3612
	    len = __stringSize(aCollection);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3613
	    if (iStop > len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3614
		RETURN(self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3615
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3616
	    if (iStop > len)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3617
		iStop = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3618
	    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
  3619
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3620
	    __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
  3621
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  3622
	    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
  3623
	    __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
  3624
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3625
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3626
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3627
		int offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3628
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3629
		if (__isByteArray(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3630
		    offs = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3631
		    len = _byteArraySize(aCollection);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3632
		} else if (__isBytes(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3633
		    offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3634
		    len = _byteArraySize(aCollection) - offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3635
		} else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3636
		    goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3637
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3638
		if (iStop > len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3639
		    RETURN(self);
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
		if (iStop > len)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3642
		    iStop = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3643
		len = iStop - iStart + 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3644
		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
  3645
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3646
		__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
  3647
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  3648
		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
  3649
		__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
  3650
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3651
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3652
		goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3653
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3654
	if (cnt == len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3655
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3656
	    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3657
		__INST(position) = __MKSMALLINT(__intVal(pos) + len);
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
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3660
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3661
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3662
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  3663
out: ;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3664
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3665
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3666
    ^ super nextPutAll:aCollection startingAt:start to:stop
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3667
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3668
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3669
!ExternalStream class methodsFor:'documentation'!
730
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  3670
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  3671
version
2577
258f5df3f054 moved some non-homogenous read/write methods to Stream
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
  3672
    ^ '$Header: /cvs/stx/stx/libbasic/Attic/ExtStream.st,v 1.127 1997-04-22 08:47:20 cg Exp $'
730
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  3673
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3674
ExternalStream initialize!