ExtStream.st
author Claus Gittinger <cg@exept.de>
Fri, 10 Jan 1997 14:18:25 +0100
changeset 2120 71c1870df7ba
parent 2045 1ad17ca6520f
child 2134 246a3bdab8b4
permissions -rw-r--r--
implemented 1-character readAhead for unbuffered streams; This should fix the EOF problem of PipeStreams and Sockets, when unbuffered.
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
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
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
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
    14
        instanceVariableNames:'filePointer mode buffered binary useCRLF hitEOF didWrite
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    15
                lastErrorNumber readAhead'
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
    16
        classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
    17
                InvalidModeSignal OpenErrorSignal StreamNotOpenSignal
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
    18
                InvalidOperationSignal'
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
    19
        poolDictionaries:''
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
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))) {  \
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
    63
        __INST(didWrite) = false;                \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
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))) {  \
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
    70
        __INST(didWrite) = true;                 \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
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
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    75
#define __UNGETC__(c, f, isBuffered)			\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    76
    if (isBuffered) {					\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    77
        ungetc((c), (f));				\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    78
    } else {						\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    79
        __INST(readAhead) = __MKSMALLINT((c));  	\
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
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    82
#define __READBYTE__(ret, f, buf, isBuffered)   	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    83
    if (isBuffered) {                           	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    84
        for (;;) {                              	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    85
            (ret) = getc(f);                    	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    86
            if ((ret) >= 0) {                   	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    87
                *(buf) = (ret);                 	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    88
                (ret) = 1;                      	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    89
            } else if (ferror(f)) {             	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    90
                if (errno == EINTR) {           	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    91
                    __HANDLE_INTERRUPTS__;      	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    92
                    clearerr(f);                	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    93
                    continue;                   	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    94
                }                               	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    95
            } else                              	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    96
                (ret) = 0;                      	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    97
            break;                              	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    98
        }                                       	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
    99
    } else {                                    	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   100
	OBJ rA = __INST(readAhead);			\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   101
	if (rA != nil) {				\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   102
	    *(buf) = __intVal(rA);			\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   103
	    __INST(readAhead) = nil;			\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   104
	    (ret) = 1;					\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   105
	} else {					\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   106
            for (;;) {                          	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   107
                (ret) = read(fileno(f), buf, 1);	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   108
                if ((ret) >= 0 || errno != EINTR)	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   109
                    break;                      	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   110
                __HANDLE_INTERRUPTS__;          	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   111
	    }						\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
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
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   115
#define __READBYTES__(ret, f, buf, cnt, isBuffered)	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   116
    (ret) = 0;                                          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   117
    if (isBuffered) {                                   \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   118
        int __offs = 0;                                 \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   119
        while (__offs < (cnt)) {                        \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   120
            (ret) = getc(f);                            \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   121
            if ((ret) < 0) {                            \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   122
                if (ferror(f)) {                        \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   123
                    if (errno == EINTR) {               \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   124
                        __HANDLE_INTERRUPTS__;          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   125
                        clearerr(f);                    \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   126
                        continue;                       \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   127
                    }                                   \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   128
                } else {                                \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   129
                    (ret) = 0;                          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   130
                }                                       \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   131
                break;                                  \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   132
            }                                           \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   133
            (buf)[__offs++] = (ret);                    \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   134
        }                                               \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   135
        if (__offs > 0)                                 \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   136
            (ret) = __offs;                             \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   137
    } else {                                            \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   138
        int __offs = 0;                                 \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   139
	int fd = fileno(f);				\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   140
							\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   141
        while (__offs < (cnt)) {                	\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   142
	    OBJ rA = __INST(readAhead);			\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   143
	    if (rA != nil) {				\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   144
	        (buf)[__offs] = __intVal(rA);		\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   145
	        __INST(readAhead) = nil;		\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   146
	        (ret) = 1;				\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   147
	    } else {					\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   148
                (ret) = read(fd, (buf)+__offs, (cnt)-__offs);          	      \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   149
                if ((ret) <= 0) {                       \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   150
                    if ((ret) < 0 && errno == EINTR) {  \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   151
                        __HANDLE_INTERRUPTS__;          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   152
                        continue;                       \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   153
                    }                                   \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   154
                    break;                              \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   155
                }                                       \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   156
	    }						\
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   157
            __offs += (ret);                            \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   158
        }                                               \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   159
        if (__offs > 0)                                 \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   160
            (ret) = __offs;                             \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   161
   }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   162
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   163
#define __WRITEBYTE__(ret, f, buf, isBuffered)          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   164
    if (isBuffered) {                                   \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   165
        for (;;) {                                      \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   166
            ret = putc(*(buf), f);                      \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   167
            if ((ret) >= 0) {                           \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   168
                (ret) = 1;                              \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   169
            } else if (ferror(f)) {                     \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   170
                if (errno == EINTR) {                   \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   171
                    __HANDLE_INTERRUPTS__;              \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   172
                    clearerr(f);                        \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   173
                    continue;                           \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   174
                }                                       \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   175
            } else                                      \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   176
                (ret) = 0;                              \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   177
            break;                                      \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   178
        }                                               \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   179
    } else {                                            \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   180
        for (;;) {                                      \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   181
            (ret) = write(fileno(f), buf, 1);           \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   182
            if ((ret) >= 0 || errno != EINTR)           \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   183
                break;                                  \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   184
            __HANDLE_INTERRUPTS__;                      \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   185
        }                                               \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   186
   }                                                                          
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   187
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   188
#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
   189
    (ret) = 0;                                                                \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   190
    if (isBuffered) {                                                         \
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   191
        int __offs = 0;                                                       \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   192
        while (__offs < (cnt)) {                                              \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   193
            ret = fwrite((buf)+__offs, 1, (cnt)-__offs, f);                   \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   194
            if ((ret) < 0) {                                                  \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   195
                if (ferror(f)) {                                              \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   196
                    if (errno == EINTR) {                                     \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   197
                        __HANDLE_INTERRUPTS__;                                \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   198
                        clearerr(f);                                          \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   199
                        continue;                                             \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   200
                    }                                                         \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   201
                } else {                                                      \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   202
                    (ret) = 0;                                                \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   203
                }                                                             \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   204
                break;                                                        \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   205
            }                                                                 \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   206
            __offs += (ret);                                                  \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   207
        }                                                                     \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   208
        if (__offs > 0)                                                       \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   209
            (ret) = __offs;                                                   \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   210
    } else {                                                                  \
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   211
        int __offs = 0;                                                       \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   212
        while (__offs < (cnt)) {                                              \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   213
            ret = write(fileno(f), (buf)+__offs, (cnt)-__offs);               \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   214
            if (ret <= 0) {                                                   \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   215
                if (ret < 0 && errno == EINTR) {                              \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   216
                    __HANDLE_INTERRUPTS__;                                    \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   217
                    continue;                                                 \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   218
                }                                                             \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   219
                break;                                                        \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   220
            }                                                                 \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   221
            __offs += (ret);                                                  \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   222
        }                                                                     \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   223
        if (__offs > 0)                                                       \
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   224
            (ret) = __offs;                                                   \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   225
   }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   226
223
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   227
/*
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   228
 * on some systems errno is a macro ... check for it here
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   229
 */
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   230
#ifndef errno
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   231
 extern errno;
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   232
#endif
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   233
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   234
%}
188
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   235
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   236
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   237
!ExternalStream class methodsFor:'documentation'!
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   238
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   239
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   240
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   241
 COPYRIGHT (c) 1988 by Claus Gittinger
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   242
              All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   243
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   244
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   245
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   246
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   247
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   248
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   249
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   250
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   251
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   252
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   253
documentation
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   254
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   255
    ExternalStream defines protocol common to Streams which have a file-descriptor and 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   256
    represent some file or communicationChannel of the underlying OperatingSystem.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   257
    ExternalStream is abstract; concrete classes are FileStream, PipeStream etc.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   258
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   259
    ExternalStreams can be in two modes: text- (the default) and binary-mode.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   260
    In text-mode, the elements read/written are characters; 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   261
    while in binary-mode the basic elements are bytes which read/write as SmallIntegers 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   262
    in the range 0..255.
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   263
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   264
    Also, the stream can be either in buffered or unbuffered mode. In buffered mode,
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   265
    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
   266
    is sent (in both modes).
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   267
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   268
    The underlying OperatingSystem streams may either be closed explicitely (sending a close)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   269
    or just forgotten - in this case, the garbage collector will eventually collect the
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   270
    object AND a close will be performed automatically (but you will NOT know when this 
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   271
    happens - so it is recommended, that you close your files when no longer needed).
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   272
    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
   273
    some crash) the data will not be in the file, if unclosed. 
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   274
    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
   275
    a noop in one of the superclasses).
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   276
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   277
    Most of the methods found here redefine inherited methods for better performance,
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   278
    since I/O from/to files should be fast.
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   279
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   280
    Recovering a snapshot:
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   281
      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
   282
      reOpen in subclasses for more information.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   283
      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
   284
      reestablish the stream upon image restart (make someone dependent on ObjectMemory).
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   285
      FileStreams are reopened and positioned to their offset they had at snapshot time.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   286
      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
   287
      if the contents changed in the meantime.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   288
      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
   289
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   290
    [Instance variables:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   291
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   292
        filePointer     <Integer>       the unix FILE*; somehow mapped to an integer
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   293
                                        (notice: not the fd)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   294
        mode            <Symbol>        #readwrite, #readonly or #writeonly
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   295
        buffered        <Boolean>       true, if buffered (i.e. collects characters - does
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   296
                                        not output immediately)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   297
        binary          <Boolean>       true if in binary mode (reads bytes instead of chars)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   298
        useCRLF         <Boolean>       true, if lines should be terminated with crlf instead
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   299
                                        of lf. (i.e. if file is an MSDOS-type file)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   300
        hitEOF          <Boolean>       true, if EOF was reached
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   301
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   302
        lastErrorNumber <Integer>       the value of errno (only valid right after the error -
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   303
                                        updated with next i/o operation)
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   304
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   305
    [Class variables:]
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   306
        Lobby           <Registry>      keeps track of used ext-streams (to free up FILE*'s)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   307
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   308
        StreamErrorSignal       <Signal> parent of all stream errors (see Stream class)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   309
        InvalidReadSignal       <Signal> raised on read from writeonly stream
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   310
        InvalidWriteSignal      <Signal> raised on write to readonly stream 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   311
        InvalidModeSignal       <Signal> raised on text I/O with binary-stream
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   312
                                         or binary I/O with text-stream
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   313
        OpenErrorSignal         <Signal> raised if open fails
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   314
        StreamNotOpenSignal     <Signal> raised on I/O with non-open stream
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   315
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   316
    Additional notes:
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   317
      This class is implemented using the underlying stdio-c library package, which
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   318
      has both advantages and disadvantages: since it is portable (posix defined), porting
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   319
      ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   320
      has big problems handling unbounded Streams, since the EOF handling in stdio is
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   321
      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
   322
      a complete rewrite for UnboundedStream ...
325
claus
parents: 308
diff changeset
   323
188
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   324
      Also, depending on the system, the stdio library behaves infriendly when signals
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   325
      occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   326
      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
   327
      an error and errno is set to EINTR. 
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   328
      Thats what the ugly code around all getc-calls is for ...
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   329
      Since things get more and more ugly - we will rewrite ExternalStream
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   330
      completely, to NOT use any stdio stuff (and do its buffering itself).
325
claus
parents: 308
diff changeset
   331
claus
parents: 308
diff changeset
   332
      Notice that typical stdio's use a single errno global variable to return an error code,
claus
parents: 308
diff changeset
   333
      this was bad design in the stdio lib (right from the very beginning), since its much
claus
parents: 308
diff changeset
   334
      harder to deal with this in the presence of lightweight processes, where errno gets
claus
parents: 308
diff changeset
   335
      overwritten by an I/O operation done in another thread. (stdio should have been written
claus
parents: 308
diff changeset
   336
      to return errno as a negative number ...).
claus
parents: 308
diff changeset
   337
      To deal with this, the scheduler treats errno like a per-thread private variable,
claus
parents: 308
diff changeset
   338
      and saves/restores the errno setting when switching to another thread.
claus
parents: 308
diff changeset
   339
      (Notice that some thread packages do this also, but ST/X's thread implementation
claus
parents: 308
diff changeset
   340
      does not depend on those, but instead uses a portable private package).
claus
parents: 308
diff changeset
   341
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   342
      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
   343
      fseek whenever we are about to read after write and vice versa.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   344
      Two macros (__READING__ and __WRITING__) have been defined to be used before every
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   345
      fread/fgetc and fwrite/putc respectively.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   346
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   347
    [author:]
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   348
        Claus Gittinger
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   349
        Stefan Vogel (many, many fixes ...)
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   350
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   351
    [see also:]
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   352
        FileStream Socket PipeStream
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   353
        Filename OperatingSystem
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   354
"
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   355
! !
847106305963 *** empty log message ***
claus
parents: 12
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:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   358
a27a279701f8 Initial revision
claus
parents:
diff changeset
   359
initialize
593
19d568779cf7 moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   360
    OpenErrorSignal isNil ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   361
        OpenErrorSignal := StreamErrorSignal newSignalMayProceed:true.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   362
        OpenErrorSignal nameClass:self message:#openErrorSignal.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   363
        OpenErrorSignal notifierString:'open error'.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   364
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   365
        InvalidReadSignal := ReadErrorSignal newSignalMayProceed:false.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   366
        InvalidReadSignal nameClass:self message:#invalidReadSignal.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   367
        InvalidReadSignal notifierString:'read error'.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   368
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   369
        InvalidWriteSignal := WriteErrorSignal newSignalMayProceed:false.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   370
        InvalidWriteSignal nameClass:self message:#invalidWriteSignal.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   371
        InvalidWriteSignal notifierString:'write error'.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   372
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   373
        InvalidModeSignal :=  StreamErrorSignal newSignalMayProceed:false.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   374
        InvalidModeSignal nameClass:self message:#invalidModeSignal.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   375
        InvalidModeSignal notifierString:'binary/text mode mismatch'.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   376
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   377
        InvalidOperationSignal :=  StreamErrorSignal newSignalMayProceed:false.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   378
        InvalidOperationSignal nameClass:self message:#invalidOperationSignal.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   379
        InvalidOperationSignal notifierString:'unsupported file operation'.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   380
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   381
        StreamNotOpenSignal := StreamErrorSignal newSignalMayProceed:false.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   382
        StreamNotOpenSignal nameClass:self message:#streamNotOpenSignal.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   383
        StreamNotOpenSignal notifierString:'stream is not open'.
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   384
    ].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   385
31
75f2b9f78be2 *** empty log message ***
claus
parents: 25
diff changeset
   386
    Lobby isNil ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   387
        Lobby := Registry new.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   388
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   389
        "want to get informed when returning from snapshot"
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   390
        ObjectMemory addDependent:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   391
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
   392
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   393
a27a279701f8 Initial revision
claus
parents:
diff changeset
   394
reOpenFiles
a27a279701f8 Initial revision
claus
parents:
diff changeset
   395
    "reopen all files (if possible) after a snapShot load"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   396
301
35e40a6fc72b *** empty log message ***
claus
parents: 269
diff changeset
   397
    Lobby do:[:aFileStream |
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   398
        aFileStream reOpen
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   399
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
   400
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   401
1469
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   402
update:something with:aParameter from:changedObject
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   403
    "have to reopen files when returning from snapshot"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   404
a27a279701f8 Initial revision
claus
parents:
diff changeset
   405
    something == #returnFromSnapshot ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   406
        self reOpenFiles
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   407
    ]
1469
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   408
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   409
    "Created: 15.6.1996 / 15:19:59 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   410
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   411
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   412
!ExternalStream class methodsFor:'instance creation'!
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   413
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   414
forFileDescriptor:aFileDescriptor mode:mode
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   415
    |newStream|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   416
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   417
    newStream := self basicNew.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   418
    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
   419
    ^ 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
   420
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   421
    "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
   422
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   423
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   424
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   425
     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
   426
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   427
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   428
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   429
    "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
   430
    "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
   431
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   432
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   433
forReadWriteToFileDescriptor:aFileDescriptor
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   434
    ^ 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
   435
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   436
    "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
   437
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   438
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   439
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   440
     s := ExternalStream forReadWriteToFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   441
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   442
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   443
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   444
    "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
   445
    "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
   446
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   447
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   448
forReadingFromFileDescriptor:aFileDescriptor
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   449
    ^ 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
   450
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   451
    "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
   452
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   453
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   454
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   455
     s := ExternalStream forReadingFromFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   456
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   457
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   458
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   459
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   460
     |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
   461
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   462
     'create OS pipe ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   463
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   464
     pipe := OperatingSystem makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   465
     readFd := pipe at:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   466
     writeFd := pipe at:2.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   467
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   468
     'connect Smalltalk streams ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   469
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   470
     rs := ExternalStream forReadingFromFileDescriptor:readFd.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   471
     ws := ExternalStream forWritingToFileDescriptor:writeFd.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   472
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   473
     'read ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   474
     [
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   475
         1 to:10 do:[:i |
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   476
             Transcript showCR:rs nextLine
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   477
         ].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   478
         rs close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   479
     ] forkAt:7.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   480
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   481
     'write ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   482
     [
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   483
         1 to:10 do:[:i |
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   484
             ws nextPutAll:'hello world '; nextPutAll:i printString; cr
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   485
         ].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   486
         ws close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   487
     ] fork.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   488
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   489
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   490
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   491
    "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
   492
    "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
   493
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   494
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   495
forWritingToFileDescriptor:aFileDescriptor
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   496
    ^ 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
   497
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   498
    "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
   499
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   500
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   501
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   502
     s := ExternalStream forWritingToFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   503
     s binary.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   504
     s nextPut:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   505
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   506
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   507
    "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
   508
    "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
   509
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   510
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   511
makePipe
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   512
    "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
   513
     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
   514
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   515
     |pipe rs ws|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   516
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   517
     pipe := OperatingSystem makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   518
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   519
     pipe notNil ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   520
         rs := self forReadingFromFileDescriptor:(pipe at:1).
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   521
         ws := self forWritingToFileDescriptor:(pipe at:2).
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   522
         ^ 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
   523
     ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   524
     ^ nil
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   525
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   526
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   527
     |pipe rs ws|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   528
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   529
     pipe := ExternalStream makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   530
     rs := pipe at:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   531
     ws := pipe at:2.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   532
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   533
     'read ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   534
     [
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   535
         1 to:10 do:[:i |
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   536
             Transcript showCR:rs nextLine
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   537
         ].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   538
         rs close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   539
     ] forkAt:7.
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
     'write ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   542
     [
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   543
         1 to:10 do:[:i |
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   544
             ws nextPutAll:'hello world '; nextPutAll:i printString; cr
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   545
         ].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   546
         ws close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   547
     ] fork.
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
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:28:36 / 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
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   553
new
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   554
    |newStream|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   555
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   556
    newStream := self basicNew.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   557
    newStream text; buffered:true; useCRLF:false; clearEOF.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   558
    ^ newStream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   559
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   560
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   561
!ExternalStream class methodsFor:'Signal constants'!
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   562
1522
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   563
inaccessibleSignal
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   564
    "ST-80 compatibility: return openErrorSignal"
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   565
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   566
    ^ self openErrorSignal
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   567
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   568
    "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
   569
!
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   570
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   571
invalidModeSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   572
    "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
   573
     or binary-I/O with a text stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   574
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   575
    ^ InvalidModeSignal
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   576
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   577
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   578
invalidOperationSignal
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   579
    "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
   580
     I/O operation is attempted"
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   581
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   582
    ^ InvalidOperationSignal
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   583
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   584
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   585
invalidReadSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   586
    "return the signal raised when reading from writeonly streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   587
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   588
    ^ InvalidReadSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   589
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   590
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   591
invalidWriteSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   592
    "return the signal raised when writing to readonly streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   593
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   594
    ^ InvalidWriteSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   595
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   596
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   597
openErrorSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   598
    "return the signal raised when a file open failed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   599
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   600
    ^ OpenErrorSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   601
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   602
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   603
streamNotOpenSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   604
    "return the signal raised on I/O with closed streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   605
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   606
    ^ StreamNotOpenSignal
2
claus
parents: 1
diff changeset
   607
! !
claus
parents: 1
diff changeset
   608
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   609
!ExternalStream class methodsFor:'error handling'!
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   610
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   611
lastErrorNumber
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   612
    "return the errno of the last error"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   613
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   614
    ^ LastErrorNumber
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   615
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   616
    "
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   617
     ExternalStream lastErrorNumber
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   618
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   619
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   620
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   621
lastErrorString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   622
    "return a message string describing the last error"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   623
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   624
    ^ OperatingSystem errorTextForNumber:LastErrorNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   625
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   626
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   627
     ExternalStream lastErrorString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   628
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   629
! !
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   630
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   631
!ExternalStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   632
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   633
binary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   634
    "switch to binary mode - default is text"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   635
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   636
    binary := true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   637
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   638
a27a279701f8 Initial revision
claus
parents:
diff changeset
   639
buffered:aBoolean
10
claus
parents: 5
diff changeset
   640
    "turn buffering on or off - default is on"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   641
10
claus
parents: 5
diff changeset
   642
    buffered := aBoolean
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   643
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   644
a27a279701f8 Initial revision
claus
parents:
diff changeset
   645
contents
2
claus
parents: 1
diff changeset
   646
    "return the contents of the file from the current position up-to
claus
parents: 1
diff changeset
   647
     the end. If the stream is in binary mode, a ByteArray containing
claus
parents: 1
diff changeset
   648
     the byte values is returned.
claus
parents: 1
diff changeset
   649
     In text-mode, a collection of strings, each representing one line,
claus
parents: 1
diff changeset
   650
     is returned."
claus
parents: 1
diff changeset
   651
claus
parents: 1
diff changeset
   652
    |text l chunks sizes chunk byteCount cnt bytes offset|
claus
parents: 1
diff changeset
   653
claus
parents: 1
diff changeset
   654
    binary ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   655
        "adding to a ByteArray produces quadratic time-space
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   656
         behavior - therefore we allocate chunks, and concatenate them
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   657
         at the end."
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   658
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   659
        chunks := OrderedCollection new.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   660
        sizes := OrderedCollection new.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   661
        byteCount := 0.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   662
        [self atEnd] whileFalse:[
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   663
            chunk := ByteArray uninitializedNew:4096.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   664
            cnt := self nextBytes:(chunk size) into:chunk.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   665
            cnt notNil ifTrue:[
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   666
                chunks add:chunk.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   667
                sizes add:cnt.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   668
                byteCount := byteCount + cnt
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   669
            ]
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   670
        ].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   671
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   672
        "now, create one big ByteArray"
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   673
        bytes := ByteArray uninitializedNew:byteCount.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   674
        offset := 1.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   675
        1 to:chunks size do:[:index |
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   676
            chunk := chunks at:index.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   677
            cnt := sizes at:index. 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   678
            bytes replaceFrom:offset to:(offset + cnt - 1) with:chunk.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   679
            offset := offset + cnt
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   680
        ].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   681
        ^ bytes
2
claus
parents: 1
diff changeset
   682
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   683
244
9faa2da0650a Text <-> StringCollection
claus
parents: 223
diff changeset
   684
    text := StringCollection new.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   685
    [self atEnd] whileFalse:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   686
        l := self nextLine.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   687
        l isNil ifTrue:[
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   688
            ^ text
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   689
        ].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   690
        text add:l
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   691
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   692
    ^ text
a27a279701f8 Initial revision
claus
parents:
diff changeset
   693
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   694
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   695
contentsOfEntireFile
1522
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   696
    "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
   697
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   698
    ^ self contents asString.
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   699
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   700
    "Modified: 3.7.1996 / 13:22:16 / stefan"
2
claus
parents: 1
diff changeset
   701
!
claus
parents: 1
diff changeset
   702
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   703
contentsSpecies
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   704
    "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
   705
     (such as upTo)"
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   706
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   707
    binary ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   708
        ^ ByteArray
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   709
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   710
    ^ String
2
claus
parents: 1
diff changeset
   711
!
claus
parents: 1
diff changeset
   712
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   713
fileDescriptor
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   714
    "return the fileDescriptor of the receiver -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   715
     notice: this one returns the underlying OSs fileDescriptor -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   716
     this may not be available on all platforms (i.e. non unix systems)."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   717
a27a279701f8 Initial revision
claus
parents:
diff changeset
   718
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   719
a27a279701f8 Initial revision
claus
parents:
diff changeset
   720
    FILE *f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   721
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   722
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   723
    if ((fp = __INST(filePointer)) != nil) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   724
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   725
        RETURN ( __MKSMALLINT(fileno(f)) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   726
    }
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
   727
%}.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   728
    ^ self errorNotOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   729
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   730
826
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   731
fileDescriptor:anInteger withMode:openMode
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   732
    "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
   733
     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
   734
     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
   735
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   736
%{  /* NOCONTEXT */
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   737
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   738
    FILE *f;
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   739
    OBJ fp;
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   740
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   741
    if (__isSmallInteger(anInteger) &&
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   742
        __isString(openMode) &&
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   743
        (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
   744
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   745
        __INST(filePointer) = fp = __MKOBJ((int)f); __STORE(self, fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   746
        RETURN (self);
826
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   747
    }
1068
92fdcccf12a3 alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
   748
%}.
826
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   749
    ^ self primitiveFailed
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   750
!
b271ea453f6a New method to set the filedescriptor of a stream.
Stefan Vogel <sv@exept.de>
parents: 820
diff changeset
   751
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   752
filePointer
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   753
    "return the filePointer of the receiver -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   754
     notice: for portability stdio is used; this means you will get
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   755
     a FILE * - not a fileDescriptor. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   756
     (what you really get is a corresponding integer).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   757
     You cannot do much with the returned value 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   758
     - except passing it to a primitive, for example."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   759
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   760
    ^ filePointer
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   761
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   762
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   763
readonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   764
    "set access mode to readonly"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   765
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   766
    mode := #readonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   767
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   768
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   769
readwrite
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   770
    "set access mode to readwrite"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   771
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   772
    mode := #readwrite
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   773
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   774
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   775
text
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   776
    "switch to text mode - default is text"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   777
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   778
    binary := false
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   779
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   780
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   781
useCRLF:aBoolean
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   782
    "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
   783
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   784
    useCRLF := aBoolean
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   785
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   786
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   787
writeonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   788
    "set access mode to writeonly"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   789
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   790
    mode := #writeonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   791
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   792
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   793
!ExternalStream methodsFor:'error handling'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   794
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   795
argumentMustBeCharacter
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   796
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   797
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   798
    "report an error, that the argument must be a character"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   799
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   800
    ^ self error:'argument must be a character'
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   801
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   802
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   803
argumentMustBeInteger
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   804
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   805
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   806
    "report an error, that the argument must be an integer"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   807
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   808
    ^ self error:'argument must be an integer'
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   809
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   810
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   811
argumentMustBeString
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   812
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   813
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   814
    "report an error, that the argument must be a string"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   815
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   816
    ^ self error:'argument must be a string'
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   817
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   818
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   819
errorBinary
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   820
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   821
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   822
    "report an error, that the stream is in binary mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   823
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   824
    ^ InvalidModeSignal
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   825
        raiseRequestWith:self
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   826
             errorString:(self class name , ' is in binary mode')
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   827
                      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   828
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   829
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   830
errorNotBinary
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   831
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   832
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   833
    "report an error, that the stream is not in binary mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   834
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   835
    ^ InvalidModeSignal
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   836
        raiseRequestWith:self
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   837
             errorString:(self class name , ' is not in binary mode')
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   838
                      in:thisContext sender
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   839
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   840
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   841
errorNotBuffered
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   842
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   843
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   844
    "report an error, that the stream is not in buffered mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   845
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   846
    ^ StreamErrorSignal
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   847
        raiseRequestWith:self
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   848
             errorString:(self class name , ' is unbuffered - operation not allowed')
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   849
                      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   850
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   851
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   852
errorNotOpen
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   853
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   854
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   855
    "report an error, that the stream has not been opened"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   856
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   857
    ^ StreamNotOpenSignal
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   858
        raiseRequestWith:self
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   859
             errorString:(self class name , ' not open')
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   860
                      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   861
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   862
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   863
errorOpen
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   864
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   865
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   866
    "report an error, that the stream is already opened"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   867
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   868
    ^ OpenErrorSignal
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   869
        raiseRequestWith:self
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   870
        errorString:(self class name , ' is already open')
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   871
                 in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   872
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   873
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   874
errorReadOnly
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   875
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   876
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   877
    "report an error, that the stream is a readOnly stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   878
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   879
    ^ InvalidWriteSignal
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   880
        raiseRequestWith:self
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   881
             errorString:(self class name , ' is readonly')
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   882
                      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   883
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   884
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   885
errorUnsupportedOperation
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   886
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   887
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   888
    "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
   889
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   890
    ^ InvalidOperationSignal
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   891
        raiseRequestWith:self
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   892
        errorString:'unsupported operation'
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   893
                 in:thisContext sender
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   894
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   895
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   896
errorWriteOnly
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   897
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   898
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   899
    "report an error, that the stream is a writeOnly stream"
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
    ^ InvalidReadSignal
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   902
        raiseRequestWith:self
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   903
             errorString:(self class name , ' is writeonly')
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   904
                      in:thisContext sender
2
claus
parents: 1
diff changeset
   905
!
claus
parents: 1
diff changeset
   906
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   907
ioError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   908
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   909
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   910
    "report an error, that some I/O error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   911
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   912
    ^ StreamErrorSignal
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   913
        raiseRequestWith:self
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   914
             errorString:('I/O error: ' , self lastErrorString)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   915
                      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   916
!
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
lastErrorNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   919
    "return the last error"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   920
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   921
    ^ lastErrorNumber
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   924
lastErrorString
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   925
    "return a message string describing the last error"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   926
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   927
    (lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   928
        ^ 'I/O error'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   929
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   930
    ^ OperatingSystem errorTextForNumber:lastErrorNumber
2
claus
parents: 1
diff changeset
   931
!
claus
parents: 1
diff changeset
   932
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   933
openError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   934
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   935
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   936
    "report an error, that the open failed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   937
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   938
    ^ OpenErrorSignal
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   939
        raiseRequestWith:self
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   940
             errorString:('error on open: ' , self lastErrorString)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   941
                      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   942
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   943
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   944
readError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   945
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   946
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   947
    "report an error, that some read error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   948
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   949
    ^ ReadErrorSignal
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   950
        raiseRequestWith:self
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   951
             errorString:('read error: ' , self lastErrorString)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   952
                      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   953
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   954
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   955
writeError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   956
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
   957
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   958
    "report an error, that some write error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   959
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   960
    ^ WriteErrorSignal
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   961
        raiseRequestWith:self
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   962
             errorString:('write error: ' , self lastErrorString)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   963
                      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   964
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   965
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   966
!ExternalStream methodsFor:'instance release'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   967
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   968
closeFile
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   969
    "low level close - may be redefined in subclasses"
2
claus
parents: 1
diff changeset
   970
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
   971
%{
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   972
    OBJ fp;
2
claus
parents: 1
diff changeset
   973
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   974
    if ((fp = __INST(filePointer)) != nil) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   975
        __INST(filePointer) = nil;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   976
        __BEGIN_INTERRUPTABLE__
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   977
        fclose(__FILEVal(fp));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   978
        __END_INTERRUPTABLE__
10
claus
parents: 5
diff changeset
   979
    }
claus
parents: 5
diff changeset
   980
%}
claus
parents: 5
diff changeset
   981
!
claus
parents: 5
diff changeset
   982
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   983
disposed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   984
    "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
   985
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   986
    self closeFile
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   987
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   988
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   989
setFilePointer:anInteger
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   990
    filePointer := anInteger
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   991
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   992
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   993
shallowCopyForFinalization
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   994
    "return a copy for finalization-registration;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   995
     since all we need at finalization time is the fileDescriptor,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   996
     a cheaper copy is possible."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   997
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   998
    ^ self class basicNew setFilePointer:filePointer
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   999
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1000
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1001
shutDown
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1002
    "close the stream - added for protocol compatibility with PipeStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1003
     see comment there"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1004
1642
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1005
    filePointer isNil ifTrue:[^ self].
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1006
    Lobby unregister:self.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1007
    self closeFile
1642
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1008
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1009
    "Modified: 30.8.1996 / 00:39:21 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1010
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1011
2
claus
parents: 1
diff changeset
  1012
!ExternalStream methodsFor:'line reading/writing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1013
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1014
nextLine
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1015
    "read the next line (characters up to newline).
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1016
     Return a string containing those characters excluding the newline.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1017
     If the previous-to-last character is a cr, this is also removed,
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1018
     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
  1019
     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
  1020
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1021
    |line|
971
eb70f5674303 max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
  1022
eb70f5674303 max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
  1023
%{  /* STACK:17000 */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1024
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1025
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1026
    int len, ret;
971
eb70f5674303 max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
  1027
    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
  1028
    char *rslt, *nextPtr, *limit;
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1029
    int fd, ch;
1068
92fdcccf12a3 alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1030
    int _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1031
    OBJ fp;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1032
    int lineTooLong = 0;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1033
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1034
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1035
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1036
        && (__INST(mode) != @symbol(writeonly))
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1037
        && (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1038
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1039
        f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1040
        buffer[0] = '\0';
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1041
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1042
        _buffered = (__INST(buffered) == true);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1043
        if (_buffered) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1044
            __READING__(f);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1045
        } 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1046
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1047
        rslt = nextPtr = buffer;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1048
        limit = buffer + sizeof(buffer) - 2;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1049
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1050
        for (;;) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1051
            __READBYTE__(ret, f, nextPtr, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1052
            if (ret <= 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1053
                if (nextPtr == buffer)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1054
                    rslt = NULL;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1055
                if (ret == 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1056
                    __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1057
                    break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1058
                } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1059
                    __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1060
                    goto err;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1061
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1062
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1063
            if (*nextPtr == '\n') {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1064
                *nextPtr = '\0';
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1065
                break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1066
            }
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1067
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1068
            nextPtr++;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1069
            if (nextPtr >= limit) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1070
                *nextPtr = '\0';
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1071
	        lineTooLong = 1;
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1072
                fprintf(stderr, "EXTSTREAM: line truncated in nextLine\n");
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1073
                break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1074
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1075
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1076
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1077
        if (rslt != NULL) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1078
            len = nextPtr-buffer;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1079
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1080
            if (__INST(position) != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1081
                __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + len);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1082
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1083
            /* remove EOL character */
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1084
            if (len != 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1085
                if (buffer[len-1] == '\n') {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1086
                    buffer[--len] = '\0';
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1087
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1088
                if ((len != 0) && (buffer[len-1] == '\r')) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1089
                    buffer[--len] = '\0';
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1090
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1091
            }
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1092
	    line = __MKSTRING_L(buffer, len);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1093
	    if (! lineTooLong) {
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1094
                RETURN ( line );
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1095
	    }
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1096
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1097
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1098
err: ;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1099
%}.
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1100
    line notNil ifTrue:[
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1101
	"/ 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
  1102
	"/ The exception could be handled by reading more and returning the
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1103
	"/ concatenation in your exception handler
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1104
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1105
        ^ ReadErrorSignal
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1106
            raiseRequestWith:(Array with:self with:line)
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1107
                 errorString:('line too long read error')
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1108
    ].
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1109
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1110
    hitEOF ifTrue:[^ self pastEnd].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1111
    lastErrorNumber notNil ifTrue:[^ self readError].
2
claus
parents: 1
diff changeset
  1112
    filePointer isNil ifTrue:[^ self errorNotOpen].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1113
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1114
    ^ self errorBinary
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1115
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1116
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1117
nextPutLine:aString
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1118
    "write the characters in aString and append a newline or CRLF if useCRLF is set"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1119
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1120
%{
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1121
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1122
    int len, cnt, len1, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1123
    OBJ pos, fp;
537
dc4dad8a5ddd many ExtStream rewrites - has to be reevaluated in all platforms
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1124
    char *cp;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1125
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1126
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1127
    if (((fp = __INST(filePointer)) != nil) 
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1128
        && (__INST(mode) != @symbol(readonly))
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1129
        && (__INST(binary) != true)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1130
        && __isString(aString)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1131
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1132
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1133
        len = __stringSize(aString);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1134
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1135
        if (_buffered = (__INST(buffered) == true)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1136
            __WRITING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1137
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1138
        __WRITEBYTES__(cnt, f, __stringVal(aString), len, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1139
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1140
        if (cnt == len) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1141
            len1 = len;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1142
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1143
            if (__INST(useCRLF) == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1144
                cp = "\r\n"; len = 2;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1145
            } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1146
                cp = "\n"; len = 1;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1147
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1148
            __WRITEBYTES__(cnt, f, cp, len, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1149
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1150
            if (cnt > 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1151
                pos = __INST(position);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1152
                if (pos != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1153
                    __INST(position) = __MKSMALLINT(__intVal(pos)+len1+cnt);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1154
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1155
                RETURN ( self );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1156
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1157
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1158
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1159
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1160
%}.
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1161
    super nextPutLine:aString.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1162
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1163
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1164
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1165
    "read from aStream up to and including a line starting with aStringOrNil
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1166
     and append it to self. 
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1167
     Can be used to copy/create large files or copy from a pipe/socket.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1168
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1169
     If aStringOrNil is nil or not matched, copy preceeds to the end.
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1170
     (this allows for example to read a Socket and transfer the data quickly
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1171
      into a file - without creating zillions of temporary strings)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1172
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1173
    |srcFilePointer readError|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1174
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1175
    (mode == #readonly) ifTrue:[^ self errorReadOnly].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1176
    filePointer isNil ifTrue:[^ self errorNotOpen].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1177
    srcFilePointer := aStream filePointer.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1178
    srcFilePointer isNil ifTrue:[^ aStream errorNotOpen].
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1179
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1180
%{  /* STACK:2000 */
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1181
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1182
    FILE *dst, *src;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1183
    char *matchString;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1184
    int matchLen = 0;
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1185
    char buffer[1024];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1186
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1187
    __INST(lastErrorNumber) = nil;
249
claus
parents: 244
diff changeset
  1188
    if (__isSmallInteger(srcFilePointer)) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1189
        if ((aStringOrNil == nil) || __isString(aStringOrNil)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1190
            if (aStringOrNil != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1191
                matchString = (char *) __stringVal(aStringOrNil);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1192
                matchLen = __stringSize(aStringOrNil);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1193
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1194
            dst = __FILEVal(__INST(filePointer));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1195
            src = __FILEVal(srcFilePointer);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1196
            __BEGIN_INTERRUPTABLE__
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1197
            errno = 0;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1198
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1199
            __WRITING__(dst)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1200
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1201
            for (;;) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1202
                if (fgets(buffer, sizeof(buffer)-1, src) == NULL) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1203
                    if (ferror(src)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1204
                        readError = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1205
                        __END_INTERRUPTABLE__
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1206
                        goto err;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1207
                    }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1208
                    break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1209
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1210
                if (fputs(buffer, dst) == EOF) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1211
                    if (ferror(dst)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1212
                        __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1213
                        __END_INTERRUPTABLE__
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1214
                        goto err;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1215
                    }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1216
                    break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1217
                }
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1218
#ifndef OLD
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1219
                if (__INST(buffered) == false) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1220
                    fflush(dst);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1221
                }
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1222
#endif
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1223
                if (matchLen) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1224
                    if (strncmp(matchString, buffer, matchLen) == 0) 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1225
                        break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1226
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1227
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1228
            __END_INTERRUPTABLE__
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1229
            __INST(position) = nil;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1230
            RETURN (self);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1231
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1232
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1233
err: ;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1234
%}.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1235
    readError ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1236
        aStream setLastErrorNumber:readError.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1237
        ^ aStream readError
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1238
    ].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1239
    lastErrorNumber notNil ifTrue:[^ self writeError].
10
claus
parents: 5
diff changeset
  1240
    buffered ifFalse:[^ self errorNotBuffered].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1241
    "
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1242
     argument error
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1243
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1244
    ^ self primitiveFailed
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1245
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1246
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1247
peekForLineStartingWith:aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1248
    "read ahead for next line starting with aString;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1249
     return the line-string if found, or nil if EOF is encountered.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1250
     If matched, not advance position behond that line
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1251
     i.e. nextLine will read the matched line.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1252
     If not matched, reposition to original position for firther reading."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1253
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1254
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1255
    filePointer isNil ifTrue:[^ self errorNotOpen].
2
claus
parents: 1
diff changeset
  1256
    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
  1257
    buffered ifFalse:[^ self errorNotBuffered].
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1258
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1259
%{  /* STACK: 2000 */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1260
    FILE *f;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1261
    int l;
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1262
    char buffer[1024];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1263
    char *cp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1264
    char *matchString;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1265
    int  firstpos = -1, lastpos;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1266
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1267
    __INST(lastErrorNumber) = nil;
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
  1268
    if (__isString(aString)) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1269
        matchString = (char *) __stringVal(aString);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1270
        l = __stringSize(aString);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1271
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1272
        f = __FILEVal(__INST(filePointer));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1273
        __READING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1274
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1275
        for (;;) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1276
            lastpos = ftell(f);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1277
            if (firstpos == -1) firstpos = lastpos;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1278
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1279
            __BEGIN_INTERRUPTABLE__
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1280
            do {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1281
                cp = fgets(buffer, sizeof(buffer)-1, f);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1282
            } while ((cp == NULL) && ferror(f) && (errno == EINTR) && (clearerr(f), 1));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1283
            buffer[sizeof(buffer)-1] = '\0';
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1284
            __END_INTERRUPTABLE__
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1285
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1286
            if (cp == NULL) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1287
                if (ferror(f)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1288
                    __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1289
                    goto err;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1290
                } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1291
                    fseek(f, firstpos, SEEK_SET);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1292
                    RETURN (nil);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1293
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1294
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1295
            if (strncmp(cp, matchString, l) == 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1296
                fseek(f, lastpos, SEEK_SET);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1297
                break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1298
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1299
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1300
        /* remove EOL character */
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1301
        cp = buffer;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1302
        while (*cp && (*cp != '\n')) cp++;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1303
        *cp = '\0';
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1304
        RETURN ( __MKSTRING(buffer) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1305
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1306
err: ;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1307
%}.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1308
    lastErrorNumber notNil ifTrue:[^ self readError].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1309
    ^ self argumentMustBeString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1310
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1311
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1312
peekForLineStartingWithAny:aCollectionOfStrings
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1313
    "read ahead for next line starting with any of aCollectionOfStrings;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1314
     return the index in aCollection if found, nil otherwise..
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1315
     If no match, do not change position; otherwise advance right before the
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1316
     matched line so that nextLine will return this line."
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1317
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1318
    |line startPos linePos index|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1319
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1320
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1321
    filePointer isNil ifTrue:[^ self errorNotOpen].
2
claus
parents: 1
diff changeset
  1322
    binary ifTrue:[^ self errorBinary].
claus
parents: 1
diff changeset
  1323
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1324
    startPos := self position.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1325
    [self atEnd] whileFalse:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1326
        linePos := self position.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1327
        line := self nextLine.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1328
        line notNil ifTrue:[
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1329
            index := 1.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1330
            aCollectionOfStrings do:[:prefix |
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1331
                (line startsWith:prefix) ifTrue:[
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1332
                    self position:linePos.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1333
                    ^ index
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1334
                ].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1335
                index := index + 1
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1336
            ]
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1337
        ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1338
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1339
    self position:startPos.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1340
    ^ nil
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1341
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1342
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1343
!ExternalStream methodsFor:'misc functions'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1344
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1345
async:aBoolean
779
0e41a665038a commentary
Claus Gittinger <cg@exept.de>
parents: 730
diff changeset
  1346
    "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
  1347
     the receiver will trigger an ioInterrupt.
779
0e41a665038a commentary
Claus Gittinger <cg@exept.de>
parents: 730
diff changeset
  1348
     If cleared (which is the default) no special notification is made.
0e41a665038a commentary
Claus Gittinger <cg@exept.de>
parents: 730
diff changeset
  1349
     Notice: not every OS supports this - check with OS>>supportsIOInterrupts before"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1350
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1351
    |fd|
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1352
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1353
    filePointer isNil ifTrue:[^ self errorNotOpen].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1354
    fd := self fileDescriptor.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1355
    aBoolean ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1356
        ^ OperatingSystem enableIOInterruptsOn:fd
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1357
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1358
    ^ OperatingSystem disableIOInterruptsOn:fd
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1359
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1360
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1361
backStep
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1362
    "step back one element -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1363
     redefined, since position is redefined here"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1364
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1365
    self position:(self position - 1)
362
claus
parents: 360
diff changeset
  1366
!
claus
parents: 360
diff changeset
  1367
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1368
blocking:aBoolean
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1369
    "set/clear the blocking attribute - if set (which is the default)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1370
     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
  1371
     If cleared, a read operation will immediately return with a value of
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1372
     nil."
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1373
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1374
    filePointer isNil ifTrue:[^ self errorNotOpen].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1375
    ^ OperatingSystem setBlocking:aBoolean on:(self fileDescriptor)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1376
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1377
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1378
close
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1379
    "close the stream - tell operating system"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1380
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1381
    filePointer isNil ifTrue:[^ self].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1382
    Lobby unregister:self.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1383
    self closeFile.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1384
    filePointer := nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1385
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1386
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1387
create
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1388
    "create the stream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1389
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1390
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1391
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1392
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1393
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1394
ioctl:ioctlNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1395
    "to provide a simple ioctl facility - an ioctl is performed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1396
     on the underlying file; no arguments are passed."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1397
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1398
%{
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1399
#ifndef MSDOS_LIKE
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1400
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1401
    int ret, ioNum, ioArg;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1402
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1403
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1404
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1405
    if ((fp = __INST(filePointer)) != nil) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1406
        if (__isSmallInteger(ioctlNumber)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1407
            ioNum = __intVal(ioctlNumber);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1408
            f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1409
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1410
            __BEGIN_INTERRUPTABLE__
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1411
            do {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1412
                errno = 0;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1413
                ret = ioctl(fileno(f), ioNum);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1414
            } while ((ret < 0) && (errno == EINTR));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1415
            __END_INTERRUPTABLE__
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1416
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1417
            if (ret >= 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1418
                RETURN ( __MKSMALLINT(ret) );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1419
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1420
            __INST(position) = nil;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1421
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1422
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1423
    }
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1424
#endif
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1425
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1426
    lastErrorNumber notNil ifTrue:[^ self ioError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1427
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1428
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1429
     ioctl-number is not an integer
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1430
     or the system does not support ioctl (MSDOS)
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1431
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1432
    ^ self primitiveFailed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1433
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1434
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1435
ioctl:ioctlNumber with:arg
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1436
    "to provide a simple ioctl facility - an ioctl is performed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1437
     on the underlying file; the argument is passed as argument.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1438
     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
  1439
     kind of ByteArray (ByteArray, String or Structure) a pointer to
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1440
     the data is passed. This allows performing most ioctls - however,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1441
     it might be tricky to setup the buffer."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1442
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1443
%{
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1444
#ifndef MSDOS_LIKE
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1445
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1446
    int ret, ioNum;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1447
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1448
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1449
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1450
    if ((fp = __INST(filePointer)) != nil) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1451
        if (__isSmallInteger(ioctlNumber) 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1452
         && (__isSmallInteger(arg) || __isBytes(arg))) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1453
            f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1454
            ioNum = __intVal(ioctlNumber);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1455
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1456
            __BEGIN_INTERRUPTABLE__
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1457
            do {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1458
                errno = 0;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1459
                if (__isSmallInteger(arg)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1460
                    ret = ioctl(fileno(f), ioNum, __intVal(arg));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1461
                } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1462
                    ret = ioctl(fileno(f), ioNum, __ByteArrayInstPtr(arg)->ba_element);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1463
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1464
            } while ((ret < 0) && (errno == EINTR));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1465
            __END_INTERRUPTABLE__
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1466
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1467
            if (ret >= 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1468
                RETURN ( __MKSMALLINT(ret) );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1469
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1470
            __INST(position) = nil;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1471
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1472
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1473
    }
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1474
#endif
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1475
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1476
    lastErrorNumber notNil ifTrue:[^ self ioError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1477
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1478
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1479
     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
  1480
     or the system does not support ioctl (MSDOS)
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1481
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1482
    ^ self primitiveFailed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1483
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1484
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1485
open
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1486
    "open the stream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1487
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1488
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1489
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1490
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1491
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1492
position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1493
    "return the position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1494
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1495
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1496
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1497
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1498
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1499
position:anInteger
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1500
    "set the position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1501
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1502
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1503
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1504
!
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
reset
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1507
    "set the read position to the beginning of the collection"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1508
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1509
    self position:"0" 1
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1510
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1511
1044
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1512
setToEnd
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1513
    "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
  1514
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1515
    ^ self subclassResponsibility
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1516
!
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1517
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1518
truncateTo:newSize
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1519
    "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
  1520
     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
  1521
1068
92fdcccf12a3 alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1522
%{
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1523
#ifdef HAS_FTRUNCATE
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1524
    FILE *f;
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1525
    OBJ fp;
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1526
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1527
    if (((fp = __INST(filePointer)) != nil)
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1528
     && (__INST(mode) != @symbol(readonly))) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1529
        if (__isSmallInteger(newSize)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1530
            f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1531
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1532
            if (__INST(buffered) == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1533
                __READING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1534
                fflush(f);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1535
                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
  1536
	    }
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1537
            ftruncate(fileno(f), __intVal(newSize));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1538
            RETURN (self);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1539
        }
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1540
    }
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1541
#endif
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1542
%}.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1543
    filePointer isNil ifTrue:[^ self errorNotOpen].
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1544
    (mode == #readonly) ifTrue:[^ self errorReadOnly].
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1545
    ^ self errorUnsupportedOperation
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1546
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1547
    "
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1548
     |s|
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1549
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1550
     s := 'test' asFilename writeStream.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1551
     s next:1000 put:$a.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1552
     s truncateTo:100.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1553
     s close.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1554
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1555
     ('test' asFilename fileSize) printNL
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1556
    "
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1557
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1558
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1559
!ExternalStream methodsFor:'non homogenous reading'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1560
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1561
nextByte
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1562
    "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
  1563
     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
  1564
     bytes binary value as an integer in 0..255."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1565
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1566
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1567
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1568
    unsigned char byte;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1569
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1570
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1571
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1572
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1573
    if (((fp = __INST(filePointer)) != nil)
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1574
     && (__INST(mode) != @symbol(writeonly))) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1575
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1576
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1577
        _buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1578
        if (_buffered) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1579
            __READING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1580
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1581
        __READBYTE__(ret, f, &byte, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1582
        if (ret > 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1583
            if (__INST(position) != nil)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1584
                __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1585
            RETURN (__MKSMALLINT(byte));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1586
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1587
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1588
        if (ret == 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1589
            __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1590
        } else /* ret < 0 */ {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1591
            __INST(position) = nil;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1592
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1593
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1594
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1595
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1596
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1597
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1598
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1599
    ^ self errorWriteOnly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1600
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1601
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1602
nextBytes:count into:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1603
    "read the next count bytes into an object and return the number of
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1604
     bytes read. On EOF, 0 is returned.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1605
     If the receiver is some socket/pipe-like stream, an exception
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1606
     is raised if the connection is broken.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1607
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1608
     The object must have non-pointer indexed instvars (i.e. it must be 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1609
     a ByteArray, String, Float- or DoubleArray).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1610
     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
  1611
     fastest possible physical I/O (since no new objects are allocated).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1613
     Use with care - non object oriented i/o.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1614
     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
  1615
     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
  1616
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1617
    ^ self nextBytes:count into:anObject startingAt:1
10
claus
parents: 5
diff changeset
  1618
!
claus
parents: 5
diff changeset
  1619
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1620
nextBytes:count into:anObject startingAt:start
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1621
    "read the next count bytes into an object and return the number of
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1622
     bytes read or 0 on EOF. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1623
     If the receiver is some socket/pipe-like stream, an exception
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1624
     is raised if the connection is broken.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1625
     Notice, that in contrast to other methods
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1626
     here, this does NOT return nil on EOF, but the actual count.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1627
     Thus allowing read of partial blocks.
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
     The object must have non-pointer indexed instvars 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1630
     (i.e. it must be a ByteArray, String, Float- or DoubleArray).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1631
     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
  1632
     fastest possible physical I/O (since no new objects are allocated).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1633
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1634
     Use with care - non object oriented I/O.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1635
     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
  1636
     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
  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
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1640
    int cnt, offs, ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1641
    int objSize, nInstVars, nInstBytes;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1642
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1643
    OBJ pos, fp, oClass;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1644
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1645
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1646
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1647
        && (__INST(mode) != @symbol(writeonly))
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1648
        && __bothSmallInteger(count, start)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1649
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1650
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1651
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1652
        oClass = __Class(anObject);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1653
        switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1654
            case BYTEARRAY:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1655
            case WORDARRAY:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1656
            case LONGARRAY:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1657
            case SWORDARRAY:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1658
            case SLONGARRAY:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1659
            case FLOATARRAY:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1660
            case DOUBLEARRAY:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1661
                break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1662
            default:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1663
                goto bad;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1664
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1665
        cnt = __intVal(count);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1666
        offs = __intVal(start) - 1;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1667
        nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1668
        nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1669
        objSize = __Size(anObject) - nInstBytes;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1670
        if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1671
	    char *cp;
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1672
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1673
            /* 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1674
             * mhmh - since we are interruptable, anObject may move.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1675
             * therefore, fetch the cp-pointer within the loop
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1676
             */
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1677
            _buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1678
            if (_buffered) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1679
                __READING__(f);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1680
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1681
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1682
            /*
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1683
             * on interrupt, anObject may be moved to another location.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1684
             * So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__,
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1685
             * to get a new address.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1686
             */
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1687
	    cp = (char *)__InstPtr(anObject)+nInstBytes+offs;
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1688
            __READBYTES__(ret, f, cp, cnt, _buffered);
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1689
            if (ret > 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1690
                pos = __INST(position);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1691
                if (pos != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1692
                    __INST(position) = __MKSMALLINT(__intVal(pos) + ret);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1693
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1694
                RETURN (__MKSMALLINT(ret));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1695
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1696
            if (ret == 0) { 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1697
                __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1698
            } else /* ret < 0 */ {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1699
                __INST(position) = nil;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1700
                __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1701
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1702
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1703
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1704
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1705
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1706
    (hitEOF and:[self pastEnd isNil]) ifTrue:[^ 0].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1707
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1708
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1709
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1710
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1711
     count not integer or arg not bit-like (String, ByteArray etc)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1712
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1713
    ^ self primitiveFailed
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1714
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1715
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1716
nextBytesInto:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1717
    "read bytes into an object, regardless of binary/text mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1718
     The number of bytes to read is defined by the objects size.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1719
     Return the number of bytes read. On EOF, 0 is returned.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1720
     If the receiver is some socket/pipe-like stream, an exception
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1721
     is raised if the connection is broken.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1722
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1723
     The object to read into must have non-pointer indexed instvars 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1724
     (i.e. it must be a ByteArray, String, Float- or DoubleArray).     
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1725
     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
  1726
     fastest possible physical I/O (since no new objects are allocated).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1727
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1728
     Use with care - non object oriented i/o.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1729
     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
  1730
     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
  1731
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1732
    ^ self nextBytes:(anObject size) into:anObject startingAt:1
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1733
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1734
    " to read 100 bytes from a stream:
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1735
    
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1736
     |b aStream|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1737
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1738
     aStream := 'smalltalk.rc' asFilename readStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1739
     b := ByteArray new:100.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1740
     aStream nextBytesInto:b.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1741
     aStream close.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1742
     b inspect
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1743
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1744
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1745
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1746
     |s aStream|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1747
     aStream := 'smalltalk.rc' asFilename readStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1748
     s := String new:100.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1749
     aStream nextBytesInto:s.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1750
     aStream close.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1751
     s inspect
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1752
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1753
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1754
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1755
nextLong
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1756
    "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
  1757
     The returned value may be a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1758
     (msb-first for compatibility with other smalltalks)"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1759
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1760
    ^ self nextUnsignedLongMSB:true
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1761
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1762
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1763
nextLongMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1764
    "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
  1765
     which may be a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1766
     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
  1767
     otherwise least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1768
     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
  1769
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1770
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1771
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1772
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1773
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1774
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1775
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1776
        && (__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
  1777
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1778
        FILE *f;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1779
        int ret;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1780
        int value;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1781
        char buffer[4];
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1782
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1783
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1784
        __READBYTES__(ret, f, buffer, 4, __INST(buffered) == true);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1785
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1786
        if (ret == 4) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1787
            if (__INST(position) != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1788
                __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 4);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1789
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1790
            if (msbFlag == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1791
                value = (buffer[0] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1792
                value = (value << 8) | (buffer[1] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1793
                value = (value << 8) | (buffer[2] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1794
                value = (value << 8) | (buffer[3] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1795
            } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1796
                value = (buffer[3] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1797
                value = (value << 8) | (buffer[2] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1798
                value = (value << 8) | (buffer[1] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1799
                value = (value << 8) | (buffer[0] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1800
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1801
            if ((value >= _MIN_INT) && (value <= _MAX_INT)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1802
                RETURN ( __MKSMALLINT(value));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1803
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1804
            RETURN ( __MKLARGEINT(value) );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1805
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1806
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1807
        if (ret < 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1808
            __INST(position) = nil;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1809
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1810
        } else /* ret == 0 */ {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1811
            __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1812
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1813
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1814
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1815
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1816
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1817
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1818
    ^ self readError.
1079
d47cd86b487b Make methods signal-proof.
Stefan Vogel <sv@exept.de>
parents: 1068
diff changeset
  1819
362
claus
parents: 360
diff changeset
  1820
!
claus
parents: 360
diff changeset
  1821
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1822
nextShortMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1823
    "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
  1824
     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
  1825
     otherwise least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1826
     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
  1827
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1828
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1829
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1830
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1831
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1832
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1833
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1834
        && (__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
  1835
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1836
        FILE *f;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1837
        int ret;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1838
        short value;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1839
        char buffer[2];
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1840
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1841
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1842
        __READBYTES__(ret, f, buffer, 2, __INST(buffered) == true);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1843
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1844
        if (ret == 2) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1845
            if (__INST(position) != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1846
                __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 2);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1847
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1848
            if (msbFlag == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1849
                value = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1850
            } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1851
                value = ((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1852
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1853
            RETURN (__MKSMALLINT(value));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1854
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1855
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1856
        if (ret < 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1857
            __INST(position) = nil;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1858
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1859
        } else /* ret == 0 */ {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1860
            __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1861
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1862
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1863
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1864
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1865
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1866
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1867
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1868
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1869
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1870
nextUnsignedLongMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1871
    "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
  1872
     a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1873
     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
  1874
     least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1875
     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
  1876
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1877
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1878
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1879
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1880
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1881
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1882
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1883
        && (__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
  1884
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1885
        FILE *f;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1886
        int ret;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1887
        unsigned int value;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1888
        char buffer[4];
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1889
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1890
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1891
        __READBYTES__(ret, f, buffer, 4, __INST(buffered) == true);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1892
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1893
        if (ret == 4) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1894
            if (__INST(position) != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1895
                __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 4);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1896
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1897
            if (msbFlag == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1898
                value = (buffer[0] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1899
                value = (value << 8) | (buffer[1] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1900
                value = (value << 8) | (buffer[2] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1901
                value = (value << 8) | (buffer[3] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1902
            } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1903
                value = (buffer[3] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1904
                value = (value << 8) | (buffer[2] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1905
                value = (value << 8) | (buffer[1] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1906
                value = (value << 8) | (buffer[0] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1907
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1908
            if (value <= _MAX_INT) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1909
                RETURN ( __MKSMALLINT(value));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1910
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1911
            RETURN ( __MKULARGEINT(value) );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1912
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1913
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1914
        if (ret < 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1915
            __INST(position) = nil;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1916
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1917
        } else /* ret == 0 */ {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1918
            __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1919
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1920
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1921
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1922
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1923
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1924
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1925
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1926
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1927
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1928
nextUnsignedShortMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1929
    "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
  1930
     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
  1931
     otherwise least-significant byte comes first.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1932
     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
  1933
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1934
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1935
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1936
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1937
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1938
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1939
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1940
        && (__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
  1941
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1942
        FILE *f;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1943
        int ret;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1944
        unsigned int value;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1945
        char buffer[2];
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1946
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1947
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1948
        __READBYTES__(ret, f, buffer, 2, __INST(buffered) == true);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1949
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1950
        if (ret == 2) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1951
            if (__INST(position) != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1952
                __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 2);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1953
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1954
            if (msbFlag == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1955
                value = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1956
            } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1957
                value = ((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1958
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1959
            RETURN (__MKSMALLINT(value));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1960
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1961
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1962
        if (ret < 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1963
            __INST(position) = nil;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1964
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1965
        } else /* ret == 0 */ {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1966
            __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1967
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1968
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1969
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1970
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1971
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1972
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1973
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1974
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1975
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1976
nextWord
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1977
    "in text-mode:
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1978
         read the alphaNumeric next word (i.e. up to non letter-or-digit).
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1979
         return a string containing those characters.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1980
     in binary-mode:
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1981
         read two bytes (msb-first) and return the value as a 16-bit 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1982
         unsigned Integer (for compatibility with other smalltalks)"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1983
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1984
    binary ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1985
        ^ self nextUnsignedShortMSB:true
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1986
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1987
    ^ self nextAlphaNumericWord
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1988
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1989
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1990
!ExternalStream methodsFor:'non homogenous writing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1991
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1992
nextPutByte:aByteValue
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1993
    "write a byte.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1994
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1995
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1996
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1997
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1998
    char c;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1999
    OBJ pos, fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2000
    int cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2001
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2002
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2003
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2004
        && (__INST(mode) != @symbol(readonly))
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2005
        && __isSmallInteger(aByteValue)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2006
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2007
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2008
        c = __intVal(aByteValue);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2009
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2010
        if (_buffered = (__INST(buffered) == true)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2011
            __WRITING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2012
        } 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2013
        __WRITEBYTE__(cnt, f, &c, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2014
        if (cnt == 1) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2015
            pos = __INST(position);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2016
            if (pos != nil)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2017
                __INST(position) = __MKSMALLINT(__intVal(pos) + 1);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2018
            RETURN (self);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2019
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2020
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2021
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2022
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2023
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2024
    (mode == #readonly) ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2025
    ^ self writeError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2026
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2027
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2028
nextPutBytes:count from:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2029
    "write count bytes from an object.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2030
     Return the number of bytes written or nil on error.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2031
     The object must have non-pointer indexed instvars 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2032
     (i.e. be a ByteArray, String, Float- or DoubleArray).     
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2033
     Use with care - non object oriented i/o.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2034
     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
  2035
     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
  2036
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2037
    ^ self nextPutBytes:count from:anObject startingAt:1
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2038
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2039
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2040
nextPutBytes:count from:anObject startingAt:start
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2041
    "write count bytes from an object starting at index start.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2042
     return the number of bytes written - which could be 0.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2043
     The object must have non-pointer indexed instvars 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2044
     (i.e. be a ByteArray, String, Float- or DoubleArray).     
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2045
     Use with care - non object oriented i/o.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2046
     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
  2047
     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
  2048
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2049
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2050
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2051
    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
  2052
    int objSize, nInstVars, nInstBytes, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2053
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2054
    OBJ oClass, pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2055
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2056
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2057
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2058
        && (__INST(mode) != @symbol(readonly))
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2059
        && __bothSmallInteger(count, start)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2060
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2061
        oClass = __Class(anObject);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2062
        switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2063
            case BYTEARRAY:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2064
            case WORDARRAY:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2065
            case LONGARRAY:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2066
            case SWORDARRAY:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2067
            case SLONGARRAY:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2068
            case FLOATARRAY:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2069
            case DOUBLEARRAY:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2070
                break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2071
            default:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2072
                goto bad;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2073
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2074
        len = __intVal(count);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2075
        offs = __intVal(start) - 1;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2076
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2077
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2078
        nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2079
        nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2080
        objSize = __Size(anObject) - nInstBytes;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2081
        if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2082
            offs += nInstBytes;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2083
            if (_buffered = (__INST(buffered) == true)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2084
                __WRITING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2085
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2086
            __WRITEBYTES__(cnt, f, (char *)__InstPtr(anObject)+offs, len, _buffered); 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2087
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2088
            if (cnt >= 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2089
                pos = __INST(position);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2090
                if (pos != nil)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2091
                    __INST(position) = __MKSMALLINT(__intVal(pos) + cnt);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2092
                RETURN ( __MKSMALLINT(cnt) );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2093
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2094
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2095
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2096
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2097
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2098
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2099
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2100
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2101
    (mode == #readonly) ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2102
    ^ self primitiveFailed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2103
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2104
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2105
nextPutBytesFrom:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2106
    "write bytes from an object; the number of bytes is defined by
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2107
     the objects size.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2108
     Return the number of bytes written or nil on error.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2109
     The object must have non-pointer indexed instvars 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2110
     (i.e. be a ByteArray, String, Float- or DoubleArray).     
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2111
     Use with care - non object oriented i/o.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2112
     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
  2113
     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
  2114
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2115
    ^ self nextPutBytes:(anObject size) from:anObject startingAt:1
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2116
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2117
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2118
nextPutLong:aNumber MSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2119
    "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
  2120
     true, data is written most-significant byte first; otherwise least
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2121
     first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2122
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2123
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2124
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2125
    int num;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2126
    char bytes[4];
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2127
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2128
    int cnt, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2129
    OBJ fp, pos;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2130
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2131
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2132
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2133
        && (__INST(mode) != @symbol(readonly))
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2134
        && __isSmallInteger(aNumber)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2135
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2136
        num = __intVal(aNumber);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2137
        if (msbFlag == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2138
            bytes[0] = (num >> 24) & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2139
            bytes[1] = (num >> 16) & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2140
            bytes[2] = (num >> 8) & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2141
            bytes[3] = num & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2142
        } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2143
            bytes[3] = (num >> 24) & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2144
            bytes[2] = (num >> 16) & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2145
            bytes[1] = (num >> 8) & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2146
            bytes[0] = num & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2147
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2148
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2149
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2150
        if (_buffered = (__INST(buffered) == true)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2151
            __WRITING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2152
        } 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2153
        __WRITEBYTES__(cnt, f, bytes, 4, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2154
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2155
        if (cnt == 4) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2156
            if ((pos = __INST(position)) != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2157
                __INST(position) = __MKSMALLINT(__intVal(pos) + 4);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2158
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2159
            RETURN ( self );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2160
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2161
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2162
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2163
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2164
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2165
    (mode == #readonly) ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2166
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2167
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2168
    aNumber isInteger ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2169
        msbFlag ifTrue:[
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2170
            "high word first"
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2171
            (self nextPutShort:(aNumber // 16r10000) MSB:true) isNil ifTrue:[^ nil].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2172
            ^ self nextPutShort:(aNumber \\ 16r10000) MSB:true
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2173
        ].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2174
        "low word first"
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2175
        (self nextPutShort:(aNumber \\ 16r10000) MSB:false) isNil ifTrue:[^ nil].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2176
        ^ self nextPutShort:(aNumber // 16r10000) MSB:false.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2177
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2178
    self argumentMustBeInteger
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2179
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2180
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2181
nextPutShort:aNumber MSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2182
    "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
  2183
     true, data is written most-significant byte first; otherwise least
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2184
     first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2185
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2186
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2187
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2188
    int num;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2189
    char bytes[2];
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2190
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2191
    int cnt, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2192
    OBJ fp, pos;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2193
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2194
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2195
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2196
        && (__INST(mode) != @symbol(readonly))
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2197
        && __isSmallInteger(aNumber)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2198
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2199
        num = __intVal(aNumber);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2200
        if (msbFlag == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2201
            bytes[0] = (num >> 8) & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2202
            bytes[1] = num & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2203
        } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2204
            bytes[1] = (num >> 8) & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2205
            bytes[0] = num & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2206
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2207
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2208
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2209
        if (_buffered = (__INST(buffered) == true)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2210
            __WRITING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2211
        } 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2212
        __WRITEBYTES__(cnt, f, bytes, 2, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2213
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2214
        if (cnt == 2) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2215
            if ((pos = __INST(position)) != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2216
                __INST(position) = __MKSMALLINT(__intVal(pos) + 2);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2217
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2218
            RETURN ( self );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2219
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2220
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2221
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2222
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2223
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2224
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2225
    (mode == #readonly) ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2226
    self argumentMustBeInteger
10
claus
parents: 5
diff changeset
  2227
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2228
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2229
!ExternalStream methodsFor:'private'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2230
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2231
clearEOF
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2232
    hitEOF := false
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2233
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2234
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2235
connectTo:aFileDescriptor withMode:openmode
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2236
    "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
  2237
     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
  2238
     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
  2239
     a Stream object. 
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2240
     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
  2241
     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
  2242
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2243
    |retVal|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2244
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2245
    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
  2246
%{
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2247
    FILE *f;
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2248
    OBJ fp;
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2249
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2250
    if (__isSmallInteger(aFileDescriptor) 
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2251
     && (__qClass(openmode)== @global(String))) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2252
        f = (FILE *) fdopen(__intVal(aFileDescriptor), (char *)__stringVal(openmode));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2253
        if (f == NULL) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2254
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2255
            __INST(position) = nil;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2256
        } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2257
            __INST(filePointer) = fp = __MKOBJ((int)f); __STORE(self, fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2258
            __INST(position) = __MKSMALLINT(1);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2259
            retVal = self;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2260
        }
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2261
    }
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2262
%}.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2263
    retVal notNil ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2264
        buffered := true.       "default is buffered"
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2265
        Lobby register:self
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2266
    ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2267
    lastErrorNumber notNil ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2268
        "
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2269
         the open failed for some reason ...
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2270
        "
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2271
        ^ self openError
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2272
    ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2273
    ^ retVal
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2274
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2275
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2276
reOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2277
    "sent after snapin to reopen streams.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2278
     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
  2279
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2280
    self class name errorPrint. ': cannot reOpen stream - stream closed' errorPrintNL.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2281
    filePointer := nil.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2282
    Lobby unregister:self.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2283
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2284
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2285
setLastError:aNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2286
    lastErrorNumber := aNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2287
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2288
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2289
!ExternalStream methodsFor:'queries'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2290
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2291
isBinary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2292
    "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
  2293
     The default when created is false."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2294
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2295
    ^ binary
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2298
isExternalStream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2299
    "return true, if the receiver is some kind of externalStream;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2300
     true is returned here - the method redefined from Object."
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
    ^ true
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2303
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2304
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2305
isReadable 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2306
    "return true, if this stream can be read from"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2307
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2308
    ^ (mode ~~ #writeonly)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2309
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2310
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2311
isWritable 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2312
    "return true, if this stream can be written to"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2313
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2314
    ^ (mode ~~ #readonly)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2315
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2316
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2317
!ExternalStream methodsFor:'reading'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2318
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2319
next
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2320
    "return the next element; advance read position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2321
     In binary mode, an integer is returned, otherwise a character.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2322
     If there are no more elements, nil is returned."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2323
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2324
%{
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2325
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2326
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2327
    OBJ pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2328
    unsigned char ch;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2329
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2330
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2331
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2332
        && (__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
  2333
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2334
        f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2335
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2336
        _buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2337
        if (_buffered) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2338
            __READING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2339
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2340
        __READBYTE__(ret, f, &ch, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2341
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2342
        if (ret > 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2343
            pos = __INST(position);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2344
            if (__isSmallInteger(pos)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2345
                __INST(position) = __MKSMALLINT(__intVal(pos) + 1);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2346
            } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2347
                __INST(position) = nil;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2348
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2349
            if (__INST(binary) == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2350
                RETURN ( __MKSMALLINT(ch) );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2351
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2352
            RETURN ( __MKCHARACTER(ch) );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2353
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2354
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2355
        __INST(position) = nil;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2356
        if (ret < 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2357
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2358
        } else /* ret == 0 */ {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2359
            __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2360
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2361
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2362
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2363
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2364
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2365
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2366
    self errorWriteOnly
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2369
next:count
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2370
    "return the next count elements of the stream as a collection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2371
     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
  2372
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2373
    |coll|
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
    binary ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2376
        coll := ByteArray uninitializedNew:count
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2377
    ] ifFalse:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2378
        coll := String new:count
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2379
    ].
872
af04035b443d binary class storage support
Claus Gittinger <cg@exept.de>
parents: 849
diff changeset
  2380
    self nextBytes:count into:coll startingAt:1.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2381
    ^ coll
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2382
!
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
peek
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2385
    "return the element to be read next without advancing read position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2386
     In binary mode, an integer is returned, otherwise a character.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2387
     If there are no more elements, nil is returned.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2388
     Not allowed in unbuffered mode."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2389
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2390
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2391
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2392
    unsigned char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2393
    int ret, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2394
    OBJ fp;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2395
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2396
    __INST(lastErrorNumber) = nil;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2397
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2398
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2399
        && (__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
  2400
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2401
        f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2402
	_buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2403
	if (_buffered) {
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2404
            __READING__(f)
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2405
	}
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2406
        __READBYTE__(ret, f, &c, _buffered);
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2407
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2408
        if (ret > 0) {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2409
	    __UNGETC__(c, f, _buffered);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2410
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2411
            if (__INST(binary) == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2412
                RETURN ( __MKSMALLINT(c) );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2413
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2414
            RETURN ( __MKCHARACTER(c) );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2415
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2416
        if (ret < 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2417
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2418
        } else /* ret == 0 */ {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2419
            __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2420
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2421
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2422
%}.
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2423
    hitEOF ifTrue:[^ self pastEnd]. 
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2424
    lastErrorNumber notNil ifTrue:[^ self readError].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2425
    filePointer isNil ifTrue:[^ self errorNotOpen].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2426
    ^ self errorWriteOnly
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2427
!
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2428
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2429
upToEnd
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2430
    "return a collection of the elements up-to the end.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2431
     Return nil if the stream-end is reached before."
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2432
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2433
    |answerStream ch|
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2434
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2435
    answerStream := WriteStream on:(self contentsSpecies new).
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2436
    [self atEnd] whileFalse:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2437
        ch := self next.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2438
        ch notNil ifTrue:[
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2439
            answerStream nextPut:ch
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2440
        ]
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2441
    ].
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2442
    ^ answerStream contents
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2443
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2444
    "Created: 25.4.1996 / 14:40:31 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2445
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2446
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2447
!ExternalStream methodsFor:'reimplemented for speed'!
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2448
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2449
nextAlphaNumericWord
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2450
    "read the next word (i.e. up to non letter-or-digit) after first
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2451
     skipping any whiteSpace.
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2452
     Return a string containing those characters.
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2453
     There is a limit of 1023 characters in the word - if longer,
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2454
     it is truncated."
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2455
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2456
%{  /* STACK: 2000 */
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2457
    FILE *f;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2458
    int len;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2459
    char buffer[1024];
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2460
    unsigned char ch;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2461
    int cnt = 0;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2462
    int ret, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2463
    OBJ fp;
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2464
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2465
    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
  2466
     && (__INST(mode) != @symbol(writeonly))
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2467
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2468
        f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2469
	_buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2470
	if (_buffered) {
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2471
            __READING__(f)
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2472
	}
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2473
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2474
        /*
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2475
         * skip whiteSpace first ...
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2476
         */
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2477
        do {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2478
            __READBYTE__(ret, f, &ch, _buffered);
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2479
            if (ret > 0)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2480
                cnt++;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2481
            else
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2482
                break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2483
        } while (
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2484
#ifndef NON_ASCII
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2485
                 (ch < ' ') ||
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2486
#endif
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2487
                 (ch == ' ' ) || (ch == '\t') || (ch == '\r')
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2488
              || (ch == '\n') || (ch == 0x0b));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2489
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2490
        len = 0;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2491
        while (ret > 0 && 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2492
               (((ch >= 'a') && (ch <= 'z')) ||
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2493
                ((ch >= 'A') && (ch <= 'Z')) ||
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2494
                ((ch >= '0') && (ch <= '9')))
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2495
        ) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2496
            buffer[len++] = ch;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2497
            if (len >= (sizeof(buffer)-1)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2498
                /* emergency */
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2499
                break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2500
            }
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2501
            __READBYTE__(ret, f, &ch, _buffered);
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2502
            if (ret > 0)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2503
                cnt++;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2504
            else
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2505
                break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2506
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2507
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2508
        if (ret <= 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2509
            if (ret < 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2510
                __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2511
                goto err;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2512
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2513
            else if (ret == 0)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2514
                __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2515
        } else {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2516
	    __UNGETC__(ch, f, _buffered);
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2517
            cnt--;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2518
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2519
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2520
        if (__INST(position) != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2521
            __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + cnt);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2522
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2523
        if (len != 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2524
            buffer[len] = '\0';
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2525
            RETURN ( __MKSTRING_L(buffer, len) );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2526
        }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2527
    }
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2528
err: ;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2529
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2530
    hitEOF ifTrue:[^ self pastEnd].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2531
    lastErrorNumber notNil ifTrue:[^ self readError].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2532
    filePointer isNil ifTrue:[^ self errorNotOpen].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2533
    ^ self errorWriteOnly
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2534
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2535
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2536
nextChunk
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2537
    "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
  2538
     exclamation mark. Within the chunk, exclamation marks have to be doubled -
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2539
     except within primitive code (this exception was added to make it easier
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2540
     to edit primitive code with external editors). This means, that other
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2541
     Smalltalks cannot always read chunks containing primitive code - but that
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2542
     doesnt really matter, since C-primitives are an ST/X feature anyway.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2543
     Reimplemented here for more speed."
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2544
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  2545
    |retVal outOfMemory buffer|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2546
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2547
    filePointer isNil ifTrue:[^ self errorNotOpen].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2548
    binary ifTrue:[^ self errorBinary].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2549
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2550
443
Claus Gittinger <cg@exept.de>
parents: 441
diff changeset
  2551
%{  /* 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
  2552
    /*
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  2553
     * 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
  2554
     * 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
  2555
     * 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
  2556
     * 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
  2557
     */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2558
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2559
    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
  2560
    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
  2561
    int ret;
1823
51ffb7231437 type casts
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  2562
    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
  2563
    char fastBuffer[7000];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2564
    REGISTER int index;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2565
    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
  2566
    int atBeginOfLine = 1, inPrimitive = 0;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2567
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2568
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2569
    f = __FILEVal(__INST(filePointer));
668
73165201a9da nextChunk: %{ is only recognized if at begin-of-line
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  2570
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2571
    _buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2572
    if (_buffered) {
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2573
        __READING__(f)
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2574
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2575
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2576
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2577
     * skip spaces
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2578
     */
673
2c3a4a536cd1 oops - handling of exclas within primitives was wrong
Claus Gittinger <cg@exept.de>
parents: 671
diff changeset
  2579
    c = '\n';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2580
    while (! done) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2581
        lastC = c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2582
        __READBYTE__(ret, f, &c, _buffered);
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2583
        if (ret <= 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2584
            goto err;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2585
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2586
        nread++;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2587
        atBeginOfLine = 0;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2588
        switch (c) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2589
            case '\n':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2590
            case ' ':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2591
            case '\t':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2592
            case '\r':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2593
            case '\b':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2594
            case '\014':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2595
                break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2596
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2597
            default:
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2598
                atBeginOfLine = (lastC == '\n');
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2599
                done = 1;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2600
                break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2601
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2602
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2603
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2604
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2605
     * read chunk into a buffer
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2606
     */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  2607
    bufferPtr = fastBuffer; fastFlag = 1;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2608
    currSize = sizeof(fastBuffer);
362
claus
parents: 360
diff changeset
  2609
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2610
    index = 0;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2611
    for (;;) {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2612
        __READBYTE__(ret, f, &peekC, _buffered);
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2613
        if ((c == '%') && atBeginOfLine && ret > 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2614
            if (peekC == '{') {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2615
                inPrimitive = 1;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2616
            } else if (peekC == '}') {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2617
                inPrimitive = 0;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2618
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2619
        } else if (c == '!' && !inPrimitive) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2620
            if (ret > 0 && peekC == '!') {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2621
                /*
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2622
                 * convert double-! to a single !
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2623
                 */
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2624
                __READBYTE__(ret, f, &peekC, _buffered);
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2625
                if (ret > 0)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2626
                    nread++;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2627
            } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2628
                /*
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2629
                 * End of chunk, push back lookahead character
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2630
                 * and leave loop.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2631
                 */
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2632
                if (ret > 0) {
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2633
		    __UNGETC__(peekC, f, _buffered);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2634
                } else
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2635
                    ret = 1;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2636
                break; 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2637
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2638
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2639
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2640
        /* 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2641
         * do we have to resize the buffer ? 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2642
         */
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2643
        if ((index+2) >= currSize) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2644
            OBJ newBuffer;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2645
            unsigned char *nbp;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2646
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2647
            newBuffer = __MKEMPTYSTRING(currSize * 2);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2648
            if (newBuffer == nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2649
                /*
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2650
                 * mhmh - chunk seems to be very big ....
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2651
                 */
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2652
                outOfMemory = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2653
                goto err;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2654
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2655
            nbp = __stringVal(newBuffer);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2656
            if (!fastFlag) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2657
                /*
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2658
                 * old buffer may have moved - refetch pointer
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2659
                 */
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2660
                bufferPtr = __stringVal(buffer);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2661
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2662
            bcopy(bufferPtr, nbp, index);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2663
            bufferPtr = nbp;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2664
            bufferPtr[index] = '\0';
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2665
            buffer = newBuffer;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2666
            fastFlag = 0;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2667
            currSize = currSize * 2;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2668
        } else if (!fastFlag) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2669
            /*
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2670
             * old buffer may have moved - refetch pointer
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2671
             */
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2672
            bufferPtr = __stringVal(buffer);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2673
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2674
        bufferPtr[index++] = c;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2675
        if (ret <= 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2676
            if (ret == 0)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2677
                break;          /* End of chunk reached */
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2678
            goto err;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2679
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2680
        nread++;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2681
        atBeginOfLine = (c == '\n');
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2682
        c = peekC;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2683
    }
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2684
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2685
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2686
     * 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
  2687
     * 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
  2688
     * 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
  2689
     * fast (C) buffer or from real (ST) buffer.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2690
     */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  2691
    if (fastFlag) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2692
        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
  2693
    } else {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2694
        retVal = __MKSTRING_ST_L(buffer, index);
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2695
    }
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2696
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  2697
err: ;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2698
    if (ret <= 0) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2699
        if (ret == 0)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2700
            __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2701
        else /* ret < 0 */
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2702
            __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
  2703
    }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2704
    if (__INST(position) != nil) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2705
        __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
  2706
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2707
%}.
370
claus
parents: 369
diff changeset
  2708
    retVal isNil ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2709
        "/
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2710
        "/ arrive here with retVal==nil either on error or premature EOF
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2711
        "/ or if running out of malloc-memory
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2712
        "/
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2713
        hitEOF ifTrue:[^ self pastEnd].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2714
        lastErrorNumber notNil ifTrue:[^ self readError].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2715
        outOfMemory == true ifTrue:[
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2716
            "
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2717
             buffer memory allocation failed.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2718
             When we arrive here, there was no memory available for the
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2719
             chunk. (seems to be too big of a chunk ...)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2720
             Bad luck - you should increase the ulimit and/or swap space on your machine.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2721
            "
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2722
            ^ ObjectMemory allocationFailureSignal raise.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2723
        ]
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2724
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2725
    ^ retVal
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2726
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2727
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2728
nextMatchFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2729
    "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
  2730
     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
  2731
     the element after anObject.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2732
     Only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2733
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2734
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2735
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2736
    int ret, peekValue;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2737
    char c;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2738
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2739
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2740
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2741
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2742
        && (__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
  2743
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2744
        if ((__INST(binary) == true) && __isSmallInteger(anObject)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2745
            peekValue = __intVal(anObject) & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2746
        } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2747
            if ((__INST(binary) != true) && __isCharacter(anObject)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2748
                peekValue = __intVal(_characterVal(anObject)) & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2749
            } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2750
                peekValue = -1;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2751
            }   
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2752
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2753
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2754
        if (peekValue >= 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2755
            int _buffered;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2756
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2757
            __INST(position) = nil;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2758
            f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2759
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2760
            if (_buffered = (__INST(buffered) == true)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2761
                __READING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2762
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2763
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2764
            for (;;) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2765
                __READBYTE__(ret, f, &c, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2766
                if (ret <= 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2767
                    if (ret < 0)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2768
                        __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2769
                    else
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2770
                        __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2771
                    break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2772
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2773
                if (c == peekValue) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2774
                    RETURN (anObject);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2775
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2776
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2777
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2778
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2779
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2780
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2781
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2782
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2783
    ^ super nextMatchFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2784
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2785
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2786
peekFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2787
    "return true and move past next element, if next == something.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2788
     Otherwise, stay and return false. False is also returned
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2789
     when EOF is encountered.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2790
     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
  2791
     text mode; only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2792
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2793
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2794
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2795
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2796
    int ret, peekValue, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2797
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2798
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2799
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2800
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2801
        && (__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
  2802
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2803
        if (__INST(binary) == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2804
            if (__isSmallInteger(anObject)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2805
                peekValue = __intVal(anObject) & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2806
            } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2807
                goto bad;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2808
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2809
        } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2810
            if (__isCharacter(anObject)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2811
                peekValue = __intVal(_characterVal(anObject)) & 0xFF;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2812
            } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2813
                goto bad;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2814
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2815
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2816
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2817
        f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2818
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2819
	_buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2820
	if (_buffered) {
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2821
            __READING__(f)
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2822
	}
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2823
        __READBYTE__(ret, f, &c, _buffered);
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2824
        if (ret > 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2825
            if (c == peekValue) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2826
                OBJ pos;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2827
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2828
                if ((pos = __INST(position)) != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2829
                    __INST(position) = __MKSMALLINT(__intVal(pos) + 1);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2830
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2831
                RETURN (true);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2832
            }
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2833
	    __UNGETC__(c, f, _buffered);
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2834
            RETURN (false);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2835
        } 
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2836
	if (ret < 0) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2837
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2838
        } else /* ret == 0 */
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2839
            __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2840
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2841
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2842
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2843
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2844
    hitEOF ifTrue:[self pastEnd. ^ false].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2845
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2846
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2847
    ^ super peekFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2848
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2849
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2850
skipLine
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2851
    "read the next line (characters up to newline) skip only;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2852
     return nil if EOF reached, self otherwise. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2853
     Not allowed in binary mode."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2854
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2855
%{  /* STACK:2000 */
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
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2858
    OBJ fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2859
    int ret, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2860
    char c;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2861
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2862
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2863
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2864
        && (__INST(mode) != @symbol(writeonly))
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2865
        && (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2866
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2867
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2868
        if (_buffered = (__INST(buffered) == true)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2869
            __READING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2870
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2871
        for (;;) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2872
            __READBYTE__(ret, f, &c, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2873
            if (ret > 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2874
                if (c == '\n')
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2875
                    RETURN(self) 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2876
            } else
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2877
                break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2878
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2879
        if (ret < 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2880
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2881
        } else /* ret == 0 */ {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2882
            __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2883
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2884
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2885
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2886
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2887
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2888
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2889
    binary ifTrue:[^ self errorBinary].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2890
    ^ self errorWriteOnly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2891
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2892
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2893
skipSeparators
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2894
    "skip all whitespace; next will return next non-white-space character
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2895
     or nil if endOfFile reached. Not allowed in binary mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2896
     - reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2897
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2898
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2899
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2900
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2901
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2902
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2903
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2904
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2905
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2906
        && (__INST(mode) != @symbol(writeonly))
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2907
        && (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2908
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2909
        f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2910
	_buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2911
	if (_buffered) {
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2912
            __READING__(f)
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2913
	}
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2914
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2915
        while (1) {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2916
            __READBYTE__(ret, f, &c, _buffered);
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2917
            if (ret <= 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2918
                if (ret < 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2919
                    __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2920
                } else /* ret == 0 */ {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2921
                    __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2922
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2923
                break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2924
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2925
            switch (c) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2926
                case ' ':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2927
                case '\t':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2928
                case '\n':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2929
                case '\r':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2930
                case '\b':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2931
                case '\014':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2932
                    break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2933
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2934
                default:
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2935
	            __UNGETC__(c, f, _buffered);
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2936
                    RETURN ( __MKCHARACTER(c & 0xFF) );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2937
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2938
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2939
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2940
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2941
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2942
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2943
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2944
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2945
    ^ self errorBinary.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2946
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2947
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2948
skipSeparatorsExceptCR
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2949
    "skip all whitespace but no newlines;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2950
     next will return next non-white-space character
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2951
     or nil if endOfFile reached. Not allowed in binary mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2952
     - reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2953
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2954
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2955
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2956
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2957
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2958
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2959
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2960
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2961
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2962
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2963
        && (__INST(mode) != @symbol(writeonly))
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2964
        && (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2965
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2966
        f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2967
	_buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2968
	if (_buffered) {
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2969
            __READING__(f)
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2970
	}
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2971
        while (1) {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2972
            __READBYTE__(ret, f, &c, _buffered);
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2973
            if (ret <= 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2974
                if (ret < 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2975
                    __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2976
                } else /* ret == 0 */ {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2977
                    __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2978
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2979
                break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2980
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2981
            switch (c) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2982
                case ' ':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2983
                case '\t':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2984
                case '\b':
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2985
                    break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2986
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2987
                default:
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2988
	            __UNGETC__(c, f, _buffered);
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2989
                    RETURN ( __MKCHARACTER(c & 0xFF) );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2990
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2991
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2992
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2993
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2994
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2995
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2996
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2997
    (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
  2998
    ^ self errorBinary.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2999
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3000
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3001
skipThrough:aCharacter
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3002
    "skip all characters up-to and including aCharacter. Return the receiver if
671
53de87163ad5 spelling
Claus Gittinger <cg@exept.de>
parents: 668
diff changeset
  3003
     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
  3004
     The next read operation will return the character after aCharacter.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3005
     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
  3006
     Only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3007
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3008
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3009
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3010
    REGISTER int cSearch;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3011
    unsigned char c;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3012
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3013
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3014
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3015
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3016
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3017
        && (__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
  3018
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3019
        if (__INST(binary) == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3020
            /* searched for object must be a smallInteger */
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3021
            if (! __isSmallInteger(aCharacter)) goto badArgument;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3022
            cSearch = __intVal(aCharacter);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3023
        } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3024
            /* searched for object must be a character */
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3025
            if (! __isCharacter(aCharacter)) goto badArgument;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3026
            cSearch = __intVal(_characterVal(aCharacter));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3027
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3028
        /* Q: should we just say: "not found" ? */
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3029
        if ((cSearch < 0) || (cSearch > 255)) goto badArgument;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3030
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3031
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3032
        if (_buffered = (__INST(buffered) == true)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3033
            __READING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3034
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3035
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3036
        while (1) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3037
            __READBYTE__(ret, f, &c, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3038
            if (ret <= 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3039
                if (ret < 0) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3040
                    __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3041
                } else /* ret == 0 */ {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3042
                    __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3043
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3044
                break;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3045
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3046
            if (c == cSearch) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3047
                RETURN (self);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3048
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3049
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3050
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3051
badArgument: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3052
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3053
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3054
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3055
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3056
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3057
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3058
     argument must be integer/character in binary mode, 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3059
     character in text mode
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3060
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3061
    ^ self error:'invalid argument'.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3062
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3063
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3064
     |s|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3065
     s := 'Makefile' asFilename readStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3066
     s skipThrough:$=.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3067
     s next:10
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3068
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3069
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3070
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3071
skipToAll:aString
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3072
    "skip for the sequence given by the argument, aCollection;
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3073
     return nil if not found, self otherwise. 
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3074
     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
  3075
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3076
    |oldPos|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3077
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3078
    oldPos := self position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3079
    (self skipThroughAll:aString) isNil ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3080
        "
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3081
         restore position
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3082
        "
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3083
        self position:oldPos.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3084
        ^ nil
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3085
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3086
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3087
     position before match-string
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3088
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3089
    self position:(self position - aString size).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3090
    ^ self
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3091
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3092
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3093
     |s|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3094
     s := 'Makefile' asFilename readStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3095
     s skipToAll:'are'.
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3096
     s next:10 
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3097
    "
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3098
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3099
    "Modified: 26.6.1996 / 09:22:05 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3100
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3101
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3102
!ExternalStream methodsFor:'testing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3103
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3104
atEnd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3105
    "return true, if position is at end"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3106
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3107
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3108
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3109
    OBJ fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3110
    char c;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3111
    int ret;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3112
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3113
    if (__INST(hitEOF) == true) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3114
        RETURN (true);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3115
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3116
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3117
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3118
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3119
    if ((fp = __INST(filePointer)) != nil) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3120
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3121
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3122
        if (__INST(buffered) == false) {
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3123
	    if (__INST(readAhead) != nil) {
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3124
                RETURN (false);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3125
	    }
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3126
	    /*
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3127
	     * read ahead ...
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3128
	     */
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3129
	    __READBYTE__(ret, f, &c, 0);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3130
            if (ret > 0) {
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3131
	        __UNGETC__(c, f, 0);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3132
	    }
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3133
        } else {
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3134
            /*
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3135
             * This does not work:
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3136
             *  RETURN ( feof(f) ? true : false );
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3137
             *     libc tests, if EOF has already bean read,
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3138
             *     smallatalk asks, if next read will return EOF
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3139
             */
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3140
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3141
            __READING__(f)
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3142
            __READBYTE__(ret, f, &c, 1);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3143
            if (ret > 0) {
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3144
	        __UNGETC__(c, f, 1);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3145
            }
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3146
	}
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3147
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3148
        if (ret > 0) {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3149
	    RETURN (false);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3150
	}
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3151
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3152
	if (ret == 0) { 
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3153
            __INST(hitEOF) = true;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3154
            RETURN (true);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3155
        }
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3156
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3157
	/* ret < 0 */
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3158
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3159
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3160
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3161
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3162
    ^ self errorNotOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3163
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3164
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3165
canReadWithoutBlocking
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3166
    "return true, if any data is available for reading (i.e.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3167
     a read operation will not block the smalltalk process), false otherwise."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3168
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3169
    |fd|
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
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3172
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3173
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3174
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3175
    ^ OperatingSystem readCheck:fd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3176
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3177
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3178
     |pipe|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3179
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3180
     pipe := PipeStream readingFrom:'(sleep 10; echo hello)'.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3181
     pipe canReadWithoutBlocking ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3182
         Transcript showCR:'data available'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3183
     ] ifFalse:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3184
         Transcript showCR:'no data available'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3185
     ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3186
     pipe close
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3187
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3188
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3189
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3190
canWriteWithoutBlocking
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3191
    "return true, if data can be written into the stream 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3192
     (i.e. a write operation will not block the smalltalk process)."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3193
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3194
    |fd|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3195
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3196
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3197
    mode == #readonly ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3198
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3199
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3200
    ^ OperatingSystem writeCheck:fd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3201
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3202
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3203
!ExternalStream methodsFor:'waiting for I/O'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3204
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3205
readWait
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3206
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3207
     becomes ready for reading. If data is already available,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3208
     return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3209
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3210
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3211
    self readWaitWithTimeoutMs:nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3212
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3213
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3214
readWaitWithTimeout:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3215
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3216
     becomes ready for reading or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3217
     If data is already available, return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3218
     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
  3219
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3220
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3221
    ^ self readWaitWithTimeoutMs:timeout * 1000
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3222
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3223
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3224
readWaitWithTimeoutMs:timeout 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3225
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3226
     becomes ready for reading or a timeout (in milliseconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3227
     If data is already available, return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3228
     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
  3229
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3230
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3231
    |fd inputSema hasData wasBlocked|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3232
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3233
    readAhead notNil ifTrue:[^ false].
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3234
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3235
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3236
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3237
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3238
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3239
    (OperatingSystem readCheck:fd) ifTrue:[^ false].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3240
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3241
    wasBlocked := OperatingSystem blockInterrupts.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3242
    hasData := OperatingSystem readCheck:fd.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3243
    hasData ifFalse:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3244
        inputSema := Semaphore new.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3245
        [
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3246
            timeout notNil ifTrue:[
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3247
                Processor signal:inputSema afterMilliseconds:timeout 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3248
            ].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3249
            Processor signal:inputSema onInput:fd.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3250
            Processor activeProcess state:#ioWait.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3251
            inputSema wait.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3252
            Processor disableSemaphore:inputSema.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3253
            hasData := OperatingSystem readCheck:fd
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3254
        ] valueOnUnwindDo:[
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3255
            Processor disableSemaphore:inputSema.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3256
            wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3257
        ]
612
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
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3260
    ^ hasData not
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3261
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3262
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3263
writeWait
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3264
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3265
     becomes ready for writing.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3266
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3267
     The other threads are not affected by the wait."
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
    self writeWaitWithTimeoutMs:nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3270
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3271
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3272
writeWaitWithTimeout:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3273
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3274
     becomes ready for writing or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3275
     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
  3276
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3277
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3278
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3279
    ^ self writeWaitWithTimeoutMs:timeout * 1000
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
writeWaitWithTimeoutMs:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3283
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3284
     becomes ready for writing or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3285
     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
  3286
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3287
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3288
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3289
    |fd outputSema canWrite wasBlocked|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3290
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3291
    filePointer isNil ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3292
        ^ self errorNotOpen
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3293
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3294
    mode == #readonly ifTrue:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3295
        ^ self errorReadOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3296
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3297
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3298
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3299
    (OperatingSystem writeCheck:fd) ifTrue:[^ false].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3300
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3301
    wasBlocked := OperatingSystem blockInterrupts.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3302
    canWrite := OperatingSystem writeCheck:fd.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3303
    canWrite ifFalse:[
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3304
        outputSema := Semaphore new.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3305
        [
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3306
            timeout notNil ifTrue:[
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3307
                Processor signal:outputSema afterMilliseconds:timeout
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3308
            ].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3309
            Processor signal:outputSema onOutput:fd.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3310
            Processor activeProcess state:#ioWait.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3311
            outputSema wait.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3312
            Processor disableSemaphore:outputSema.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3313
            canWrite := OperatingSystem writeCheck:fd
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3314
        ] valueOnUnwindDo:[
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3315
            Processor disableSemaphore:outputSema.
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3316
            wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3317
        ]
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3318
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3319
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3320
    ^ canWrite not
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3321
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3322
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3323
!ExternalStream methodsFor:'writing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3324
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3325
cr
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3326
    "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
  3327
     reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3328
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3329
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3330
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3331
    int len, cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3332
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3333
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3334
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3335
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3336
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3337
        && (__INST(mode) != @symbol(readonly))
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3338
        && (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3339
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3340
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3341
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3342
        if (_buffered = (__INST(buffered) == true)) { 
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3343
            __WRITING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3344
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3345
        if (__INST(useCRLF) == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3346
            cp = "\r\n"; len = 2;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3347
        } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3348
            cp = "\n"; len = 1;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3349
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3350
        __WRITEBYTES__(cnt, f, cp, len, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3351
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3352
        if (cnt == len) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3353
            if (__INST(position) != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3354
                __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + len);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3355
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3356
            RETURN ( self );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3357
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3358
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
612
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
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3362
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3363
    (mode == #readonly) ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3364
    self errorBinary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3365
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3366
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3367
flush
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3368
    "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
  3369
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3370
%{
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3371
    OBJ fp;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3372
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3373
    __INST(lastErrorNumber) = nil;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3374
    if ((fp = __INST(filePointer)) != nil) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3375
        if (__INST(mode) != @symbol(readonly)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3376
            if (__INST(buffered) == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3377
                __BEGIN_INTERRUPTABLE__
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3378
                fflush( __FILEVal(fp) );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3379
                __END_INTERRUPTABLE__
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3380
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3381
        }
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3382
    }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3383
%}
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3384
!
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3385
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3386
nextPut:aCharacter
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3387
    "write the argument, aCharacter - return nil if failed, self if ok.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3388
     Only single-byte characters are currently supported"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3389
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3390
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3391
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3392
    char c;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3393
    int cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3394
    OBJ pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3395
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3396
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3397
    if (((fp = __INST(filePointer)) != nil) 
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3398
        && (__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
  3399
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3400
        if (__INST(binary) != true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3401
            if (__isCharacter(aCharacter)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3402
                c = __intVal(__characterVal(aCharacter)) & 0xFF;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3403
    doWrite:
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3404
                f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3405
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3406
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3407
                if (_buffered = (__INST(buffered) == true)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3408
                    __WRITING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3409
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3410
                __WRITEBYTE__(cnt, f, &c, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3411
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3412
                if (cnt == 1) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3413
                    pos = __INST(position);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3414
                    if (pos != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3415
                        __INST(position) = __MKSMALLINT(__intVal(pos) + 1);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3416
                    }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3417
                    RETURN ( self );
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3418
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3419
                __INST(lastErrorNumber) = __MKSMALLINT(errno);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3420
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3421
        } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3422
            if (__isSmallInteger(aCharacter)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3423
                c = __intVal(aCharacter);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3424
                goto doWrite;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3425
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3426
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3427
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3428
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3429
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3430
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3431
    (mode == #readonly) ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3432
    binary ifFalse:[^ self argumentMustBeCharacter].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3433
    ^ self argumentMustBeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3434
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3435
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3436
nextPutAll:aCollection
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3437
    "write all elements of the argument, aCollection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3438
     Reimplemented for speed when writing strings or byteArrays.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3439
     For others, falls back to general method in superclass."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3440
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3441
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3442
    FILE *f;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3443
    int len, cnt;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3444
    OBJ pos, fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3445
    int _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3446
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3447
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3448
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3449
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3450
        && (__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
  3451
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3452
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3453
        if (_buffered = (__INST(buffered) == true)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3454
            __WRITING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3455
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3456
        if (__isString(aCollection) || __isSymbol(aCollection)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3457
            len = __stringSize(aCollection);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3458
            __WRITEBYTES__(cnt, f, __stringVal(aCollection), len, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3459
        } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3460
            if (__INST(binary) == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3461
                int offs;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3462
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3463
                if (__isByteArray(aCollection)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3464
                    offs = 0;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3465
                    len = _byteArraySize(aCollection);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3466
                } else if (__isBytes(aCollection)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3467
                    offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3468
                    len = _byteArraySize(aCollection) - offs;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3469
                } else
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3470
                    goto out;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3471
                __WRITEBYTES__(cnt, f,  __ByteArrayInstPtr(aCollection)->ba_element+offs, len, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3472
            } else
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3473
                goto out;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3474
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3475
        if (cnt == len) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3476
            pos = __INST(position);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3477
            if (pos != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3478
                __INST(position) = __MKSMALLINT(__intVal(pos) + len);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3479
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3480
            RETURN (self);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3481
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3482
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3483
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  3484
out: ;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3485
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3486
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3487
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3488
    (mode == #readonly) ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3489
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3490
    ^ super nextPutAll:aCollection
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3491
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3492
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3493
nextPutAll:aCollection startingAt:start to:stop
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3494
    "write a range of elements of the argument, aCollection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3495
     Reimplemented for speed when writing strings or byteArrays.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3496
     For others, falls back to general method in superclass."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3497
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3498
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3499
    FILE *f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3500
    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
  3501
    OBJ fp, pos;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3502
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3503
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3504
    if (((fp = __INST(filePointer)) != nil)
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3505
        && (__INST(mode) != @symbol(readonly))
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3506
        && __bothSmallInteger(start, stop)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3507
    ) {
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3508
        f = __FILEVal(fp);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3509
        if (_buffered = (__INST(buffered) == true)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3510
            __WRITING__(f)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3511
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3512
        iStart = __intVal(start);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3513
        iStop = __intVal(stop);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3514
        if ((iStart < 1) || (iStop < iStart)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3515
            RETURN(self);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3516
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3517
        if (__isString(aCollection) || __isSymbol(aCollection)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3518
            len = __stringSize(aCollection);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3519
            if (iStop > len) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3520
                RETURN(self);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3521
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3522
            if (iStop > len)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3523
                iStop = len;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3524
            len = iStop - iStart + 1;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3525
            __WRITEBYTES__(cnt, f, __stringVal(aCollection)+iStart-1, len, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3526
        } else {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3527
            if (__INST(binary) == true) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3528
                int offs;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3529
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3530
                if (__isByteArray(aCollection)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3531
                    offs = 0;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3532
                    len = _byteArraySize(aCollection);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3533
                } else if (__isBytes(aCollection)) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3534
                    offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3535
                    len = _byteArraySize(aCollection) - offs;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3536
                } else
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3537
                    goto out;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3538
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3539
                if (iStop > len) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3540
                    RETURN(self);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3541
                }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3542
                if (iStop > len)
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3543
                    iStop = len;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3544
                len = iStop - iStart + 1;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3545
                offs += iStart - 1;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3546
                __WRITEBYTES__(cnt, f,  __ByteArrayInstPtr(aCollection)->ba_element+offs, len, _buffered);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3547
            } else
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3548
                goto out;
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3549
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3550
        if (cnt == len) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3551
            pos = __INST(position);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3552
            if (pos != nil) {
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3553
                __INST(position) = __MKSMALLINT(__intVal(pos) + len);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3554
            }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3555
            RETURN (self);
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3556
        }
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3557
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3558
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  3559
out: ;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3560
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3561
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3562
    ^ super nextPutAll:aCollection startingAt:start to:stop
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3563
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3564
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3565
!ExternalStream class methodsFor:'documentation'!
730
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  3566
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  3567
version
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3568
    ^ '$Header: /cvs/stx/stx/libbasic/Attic/ExtStream.st,v 1.115 1997-01-10 13:18:25 cg Exp $'
730
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  3569
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3570
ExternalStream initialize!