ExternalStream.st
author Claus Gittinger <cg@exept.de>
Sun, 25 Jan 1998 15:13:53 +0100
changeset 3221 21085ae8e1be
parent 3200 9e2f02b2e256
child 3235 cc254b307159
permissions -rw-r--r--
eliminated some single-underscore macro refs (stringSize, arraySize ...)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
ReadWriteStream subclass:#ExternalStream
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
    14
	instanceVariableNames:'filePointer mode buffered binary eolMode hitEOF didWrite
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    15
		lastErrorNumber readAhead'
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    16
	classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    17
		InvalidModeSignal OpenErrorSignal StreamNotOpenSignal
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
    18
		InvalidOperationSignal DefaultEOLMode ReadMode ReadWriteMode
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
    19
		WriteMode AppendMode CreateReadWriteMode'
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    20
	poolDictionaries:''
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    21
	category:'Streams-External'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    24
!ExternalStream primitiveDefinitions!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    25
%{
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
    26
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
    27
#ifdef __openVMS__                                        
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
    28
# undef __new    
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
    29
#endif
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
    30
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    31
#include <stdio.h>
437
claus
parents: 436
diff changeset
    32
#define _STDIO_H_INCLUDED_
claus
parents: 436
diff changeset
    33
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    34
#ifndef NO_FCNTL_H
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    35
# include <fcntl.h>
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    36
# define _FCNTL_H_INCLUDED_
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    37
#endif
437
claus
parents: 436
diff changeset
    38
10
claus
parents: 5
diff changeset
    39
#include <errno.h>
437
claus
parents: 436
diff changeset
    40
#define _ERRNO_H_INCLUDED_
42
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    41
1141
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    42
#ifdef LINUX
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    43
  /* use inline string macros */
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    44
# define __STRINGDEFS__
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    45
# include <linuxIntern.h>
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    46
#endif
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    47
42
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    48
#ifdef hpux
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    49
# define fileno(f)      ((f->__fileH << 8) | (f->__fileL))
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    50
#endif
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    51
933
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    52
#ifndef SEEK_SET
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    53
# define SEEK_SET 0
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    54
#endif
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    55
#ifndef SEEK_CUR
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    56
# define SEEK_CUR 1
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    57
#endif
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    58
#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
    59
# 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
    60
#endif
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    61
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    62
#ifdef __VMS__
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    63
# define CLEAR_ERRNO		errno = 0;
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    64
#else
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    65
# define CLEAR_ERRNO		/* nothing */
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    66
#endif
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    67
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    68
#ifdef xxxWIN32
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    69
# define NO_STDIO
2999
b0e55440cf12 eliminate MKOBJ & MKCP (use MKEXTERNALADDRESS & externalAddressVal)
Claus Gittinger <cg@exept.de>
parents: 2986
diff changeset
    70
# define __HANDLEVal(o) 	(HFILE)(__externalAddressVal(o))
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    71
# define READ(f, cp, n)		_lread((f), (cp), (n))
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    72
# define WRITE(f, cp, n)	_lwrite((f), (cp), (n))
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    73
# define FFLUSH(fp)		/* nothing */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    74
# undef STDIO_NEEDS_FSEEK
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    75
# define FILEPOINTER		HFILE
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    76
# define FILENO(f)		(f)
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    77
#else
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    78
# define STDIO_NEEDS_FSEEK
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    79
# define FILEPOINTER		FILE *
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    80
# define READ(f, cp, n)		read(f, cp, n)
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    81
# define WRITE(f, cp, n)	write(f, cp, n)
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    82
# define FFLUSH(fp)		fflush(fp)
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    83
# define FILENO(f)		fileno(f)
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    84
#endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    85
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    86
2596
36c872e47b00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2593
diff changeset
    87
#if defined(WIN32) && defined(NO_STDIO)
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    88
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    89
# ifdef i386
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    90
#  define _X86_
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    91
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    92
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    93
# undef INT
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    94
# undef Array
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    95
# undef Number
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    96
# undef Method
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    97
# undef Point
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    98
# undef Rectangle
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    99
# undef Block
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   100
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   101
/* # include <windows.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   102
# include <stdarg.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   103
# include <windef.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   104
# include <winbase.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   105
# include <wingdi.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   106
# include <winuser.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   107
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   108
# ifdef __DEF_Array
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   109
#   define Array __DEF_Array
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   110
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   111
# ifdef __DEF_Number
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   112
#   define Number __DEF_Number
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   113
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   114
# ifdef __DEF_Method
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   115
#   define Method __DEF_Method
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   116
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   117
# ifdef __DEF_Point
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   118
#   define Point __DEF_Point
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   119
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   120
# ifdef __DEF_Block
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   121
#   define Block __DEF_Block
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   122
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   123
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   124
# define stat _stat
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   125
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   126
#endif /* WIN32 */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   127
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   128
/*
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   129
 * stdio library requires an fseek before reading whenever a file
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   130
 * is open for read/write and the last operation was a write.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   131
 * (also vice-versa).
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   132
 * All code should use the following macro before doing reads:
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   133
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   134
#ifdef STDIO_NEEDS_FSEEK
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   135
# define OPT_FSEEK(f, pos, whence)	fseek(f, pos, whence)
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   136
#else
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   137
# define OPT_FSEEK(f, pos, whence)	/* nothing */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   138
#endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   139
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   140
#define __READING__(f)                          \
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   141
    if ((__INST(didWrite) != false)              \
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   142
     && (__INST(mode) == @symbol(readwrite))) {  \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   143
	__INST(didWrite) = false;                \
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   144
	OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   145
    }
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   146
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   147
#define __WRITING__(f)                          \
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   148
    if ((__INST(didWrite) != true)               \
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   149
     && (__INST(mode) == @symbol(readwrite))) {  \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   150
	__INST(didWrite) = true;                 \
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   151
	OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   152
    }
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   153
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   154
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   155
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   156
#define __UNGETC__(c, f, isBuffered)                    \
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   157
    __INST(readAhead) = __MKSMALLINT((c));
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   158
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   159
#define __UNGETC__(c, f, isBuffered)                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   160
    if (isBuffered) {                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   161
	ungetc((c), (f));                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   162
    } else {                                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   163
	__INST(readAhead) = __MKSMALLINT((c));          \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   164
    }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   165
#endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   166
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   167
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   168
#define __READBYTE__(ret, f, buf, isBuffered)           \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   169
    {                                            	\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   170
	OBJ rA = __INST(readAhead);                     \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   171
	if (rA != nil) {                                \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   172
	    *(buf) = __intVal(rA);                      \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   173
	    __INST(readAhead) = nil;                    \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   174
	    (ret) = 1;                                  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   175
	} else {                                        \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   176
	    for (;;) {                                  \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   177
		CLEAR_ERRNO;				\
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   178
		(ret) = READ(f, buf, 1);        	\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   179
		if ((ret) >= 0 || errno != EINTR)       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   180
		    break;                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   181
		__HANDLE_INTERRUPTS__;                  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   182
	    }                                           \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   183
	}                                               \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   184
    }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   185
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   186
#define __READBYTE__(ret, f, buf, isBuffered)           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   187
    if (isBuffered) {                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   188
	for (;;) {                                      \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   189
	    CLEAR_ERRNO;				\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   190
	    (ret) = getc(f);                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   191
	    if ((ret) >= 0) {                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   192
		*(buf) = (ret);                         \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   193
		(ret) = 1;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   194
	    } else if (ferror(f)) {                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   195
		if (errno == EINTR) {                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   196
		    __HANDLE_INTERRUPTS__;              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   197
		    clearerr(f);                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   198
		    continue;                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   199
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   200
	    } else                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   201
		(ret) = 0;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   202
	    break;                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   203
	}                                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   204
    } else {                                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   205
	OBJ rA = __INST(readAhead);                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   206
	if (rA != nil) {                                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   207
	    *(buf) = __intVal(rA);                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   208
	    __INST(readAhead) = nil;                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   209
	    (ret) = 1;                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   210
	} else {                                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   211
	    for (;;) {                                  \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   212
	        CLEAR_ERRNO;				\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   213
		(ret) = read(fileno(f), buf, 1);        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   214
		if ((ret) >= 0 || errno != EINTR)       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   215
		    break;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   216
		__HANDLE_INTERRUPTS__;                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   217
	    }                                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   218
	}                                               \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   219
   }                                                                          
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   220
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   221
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   222
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   223
 * read_bytes into a c-buffer
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   224
 * (which may NOT move)
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   225
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   226
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   227
#define __READBYTES__(ret, f, buf, cnt, isBuffered)     \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   228
    {                                            	\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   229
	int __offs = 0;                                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   230
							\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   231
	while (__offs < (cnt)) {                        \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   232
	    OBJ rA = __INST(readAhead);                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   233
	    if (rA != nil) {                            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   234
		(buf)[__offs] = __intVal(rA);           \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   235
		__INST(readAhead) = nil;                \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   236
		(ret) = 1;                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   237
	    } else {                                    \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   238
	        CLEAR_ERRNO;				\
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   239
		(ret) = READ(f, (buf)+__offs, (cnt)-__offs); \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   240
		if ((ret) <= 0) {                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   241
		    if ((ret) < 0 && errno == EINTR) {  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   242
			__HANDLE_INTERRUPTS__;          \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   243
			continue;                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   244
		    }                                   \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   245
		    break;                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   246
		}                                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   247
	    }                                           \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   248
	    __offs += (ret);                            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   249
	}                                               \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   250
	if (__offs > 0)                                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   251
	    (ret) = __offs;                             \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   252
   }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   253
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   254
#define __READBYTES__(ret, f, buf, cnt, isBuffered)     \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   255
    (ret) = 0;                                          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   256
    if (isBuffered) {                                   \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   257
	int __offs = 0;                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   258
	while (__offs < (cnt)) {                        \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   259
	    CLEAR_ERRNO;				\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   260
	    (ret) = getc(f);                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   261
	    if ((ret) < 0) {                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   262
		if (ferror(f)) {                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   263
		    if (errno == EINTR) {               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   264
			__HANDLE_INTERRUPTS__;          \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   265
			clearerr(f);                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   266
			continue;                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   267
		    }                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   268
		} else {                                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   269
		    (ret) = 0;                          \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   270
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   271
		break;                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   272
	    }                                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   273
	    (buf)[__offs++] = (ret);                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   274
	}                                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   275
	if (__offs > 0)                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   276
	    (ret) = __offs;                             \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   277
    } else {                                            \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   278
	int __offs = 0;                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   279
	int fd = fileno(f);                             \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   280
							\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   281
	while (__offs < (cnt)) {                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   282
	    OBJ rA = __INST(readAhead);                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   283
	    if (rA != nil) {                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   284
		(buf)[__offs] = __intVal(rA);           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   285
		__INST(readAhead) = nil;                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   286
		(ret) = 1;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   287
	    } else {                                    \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   288
	        CLEAR_ERRNO;				\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   289
		(ret) = read(fd, (buf)+__offs, (cnt)-__offs);                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   290
		if ((ret) <= 0) {                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   291
		    if ((ret) < 0 && errno == EINTR) {  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   292
			__HANDLE_INTERRUPTS__;          \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   293
			continue;                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   294
		    }                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   295
		    break;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   296
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   297
	    }                                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   298
	    __offs += (ret);                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   299
	}                                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   300
	if (__offs > 0)                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   301
	    (ret) = __offs;                             \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   302
   }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   303
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   304
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   305
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   306
 * read_bytes into an object
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   307
 * (which may be moved by GC)
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   308
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   309
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   310
#define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)     \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   311
  {							\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   312
    int __ooffs = obj_offs;				\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   313
    int __offs = 0;					\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   314
    char *buf = (char *)(obj);				\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   315
							\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   316
    (ret) = 0;                                          \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   317
    {                                            	\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   318
	while (__offs < (cnt)) {                        \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   319
	    OBJ rA = __INST(readAhead);                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   320
	    if (rA != nil) {                            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   321
		(buf)[__ooffs+__offs] = __intVal(rA);   \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   322
		__INST(readAhead) = nil;                \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   323
		(ret) = 1;                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   324
	    } else {                                    \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   325
	        CLEAR_ERRNO;				\
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   326
		(ret) = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs); \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   327
		if ((ret) <= 0) {                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   328
		    if ((ret) < 0 && errno == EINTR) {  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   329
			__HANDLE_INTERRUPTS__;          \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   330
			/* refetch */                   \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   331
			buf = (char *)(obj);            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   332
			continue;                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   333
		    }                                   \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   334
		    break;                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   335
		}                                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   336
	    }                                           \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   337
	    __offs += (ret);                            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   338
	}                                               \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   339
	if (__offs > 0)                                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   340
	    (ret) = __offs;                             \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   341
    }							\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   342
  }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   343
#else
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   344
#define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)     \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   345
  {							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   346
    int __ooffs = obj_offs;				\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   347
    int __offs = 0;					\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   348
    char *buf = (char *)(obj);				\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   349
							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   350
    (ret) = 0;                                          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   351
    if (isBuffered) {                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   352
	while (__offs < (cnt)) {                        \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   353
	    CLEAR_ERRNO;				\
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   354
	    (ret) = getc(f);                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   355
	    if ((ret) < 0) {                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   356
		if (ferror(f)) {                        \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   357
		    if (errno == EINTR) {               \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   358
			__HANDLE_INTERRUPTS__;          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   359
			clearerr(f);                    \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   360
			/* refetch */                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   361
			buf = (char *)(obj);            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   362
			continue;                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   363
		    }                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   364
		} else {                                \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   365
		    (ret) = 0;                          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   366
		}                                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   367
		break;                                  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   368
	    }                                           \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   369
	    (buf)[__ooffs+__offs] = (ret);              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   370
	    __offs++;					\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   371
	}                                               \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   372
	if (__offs > 0)                                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   373
	    (ret) = __offs;                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   374
    } else {                                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   375
	int fd = fileno(f);                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   376
							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   377
	while (__offs < (cnt)) {                        \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   378
	    OBJ rA = __INST(readAhead);                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   379
	    if (rA != nil) {                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   380
		(buf)[__ooffs+__offs] = __intVal(rA);   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   381
		__INST(readAhead) = nil;                \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   382
		(ret) = 1;                              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   383
	    } else {                                    \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   384
	        CLEAR_ERRNO;				\
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   385
		(ret) = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   386
		if ((ret) <= 0) {                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   387
		    if ((ret) < 0 && errno == EINTR) {  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   388
			__HANDLE_INTERRUPTS__;          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   389
			/* refetch */                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   390
			buf = (char *)(obj);            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   391
			continue;                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   392
		    }                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   393
		    break;                              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   394
		}                                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   395
	    }                                           \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   396
	    __offs += (ret);                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   397
	}                                               \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   398
	if (__offs > 0)                                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   399
	    (ret) = __offs;                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   400
    }							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   401
  }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   402
#endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   403
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   404
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   405
#define __WRITEBYTE__(ret, f, buf, isBuffered)          \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   406
	for (;;) {                                      \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   407
	    CLEAR_ERRNO;				\
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   408
	    (ret) = WRITE(f, buf, 1);           	\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   409
	    if ((ret) >= 0 || errno != EINTR)           \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   410
		break;                                  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   411
	    __HANDLE_INTERRUPTS__;                      \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   412
	}
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   413
#else
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   414
#define __WRITEBYTE__(ret, f, buf, isBuffered)          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   415
    if (isBuffered) {                                   \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   416
	for (;;) {                                      \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   417
	    CLEAR_ERRNO;				\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   418
	    ret = putc(*(buf), f);                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   419
	    if ((ret) >= 0) {                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   420
		(ret) = 1;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   421
	    } else if (ferror(f)) {                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   422
		if (errno == EINTR) {                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   423
		    __HANDLE_INTERRUPTS__;              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   424
		    clearerr(f);                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   425
		    continue;                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   426
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   427
	    } else                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   428
		(ret) = 0;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   429
	    break;                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   430
	}                                               \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   431
    } else {                                            \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   432
	for (;;) {                                      \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   433
	    CLEAR_ERRNO;				\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   434
	    (ret) = write(fileno(f), buf, 1);           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   435
	    if ((ret) >= 0 || errno != EINTR)           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   436
		break;                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   437
	    __HANDLE_INTERRUPTS__;                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   438
	}                                               \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   439
   }                                                                          
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   440
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   441
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   442
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   443
 * write_bytes from a c-buffer
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   444
 * (which may NOT move)
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   445
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   446
#ifdef NO_STDIO
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   447
#define __WRITEBYTES__(ret, f, buf, cnt, isBuffered)    \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   448
    (ret) = 0;                                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   449
    {                                                   \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   450
	int __offs = 0;                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   451
	while (__offs < (cnt)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   452
	    CLEAR_ERRNO;				\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   453
	    ret = WRITE(f, (buf)+__offs, (cnt)-__offs); \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   454
	    if (ret <= 0) {                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   455
		if (ret < 0 && errno == EINTR) {        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   456
		    __HANDLE_INTERRUPTS__;              \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   457
		    continue;                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   458
		}                                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   459
		break;                                  \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   460
	    }                                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   461
	    __offs += (ret);                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   462
	}                                               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   463
	if (__offs > 0)                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   464
	    (ret) = __offs;                             \
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   465
   }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   466
#else
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   467
#define __WRITEBYTES__(ret, f, buf, cnt, isBuffered)    \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   468
    (ret) = 0;                                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   469
    if (isBuffered) {                                   \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   470
	int __offs = 0;                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   471
	while (__offs < (cnt)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   472
	    CLEAR_ERRNO;				\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   473
	    ret = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\
3187
824107b81d57 oops - fwrite returns 0 (with errno set) in case of E-NO-SPACE.
Claus Gittinger <cg@exept.de>
parents: 3174
diff changeset
   474
	    if ((ret) <= 0) {                            \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   475
		if (ferror(f)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   476
		    if (errno == EINTR) {               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   477
			__HANDLE_INTERRUPTS__;          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   478
			clearerr(f);                    \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   479
			continue;                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   480
		    }                                   \
3187
824107b81d57 oops - fwrite returns 0 (with errno set) in case of E-NO-SPACE.
Claus Gittinger <cg@exept.de>
parents: 3174
diff changeset
   481
		    break;                              \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   482
		} else {                                \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   483
		    (ret) = 0;                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   484
		}                                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   485
	    }                                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   486
	    __offs += (ret);                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   487
	}                                               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   488
	if (__offs > 0)                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   489
	    (ret) = __offs;                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   490
    } else {                                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   491
	int __offs = 0;                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   492
	while (__offs < (cnt)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   493
	    CLEAR_ERRNO;				\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   494
	    ret = write(fileno(f), (buf)+__offs, (cnt)-__offs);\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   495
	    if (ret <= 0) {                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   496
		if (ret < 0 && errno == EINTR) {        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   497
		    __HANDLE_INTERRUPTS__;              \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   498
		    continue;                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   499
		}                                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   500
		break;                                  \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   501
	    }                                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   502
	    __offs += (ret);                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   503
	}                                               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   504
	if (__offs > 0)                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   505
	    (ret) = __offs;                             \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   506
   }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   507
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   508
223
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   509
/*
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   510
 * write_bytes from an object
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   511
 * (which may be moved around by GC)
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   512
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   513
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   514
#define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)            \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   515
  {							\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   516
    int __ooffs = obj_offs;				\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   517
    int __offs = 0;					\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   518
    char *buf = (char *)(obj);				\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   519
							\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   520
    (ret) = 0;                                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   521
    {                                                   \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   522
	while (__offs < (cnt)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   523
	    CLEAR_ERRNO;				\
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   524
	    ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs);       	      \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   525
	    if (ret <= 0) {                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   526
		if (ret < 0 && errno == EINTR) {        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   527
		    __HANDLE_INTERRUPTS__;              \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   528
		    /* refetch */                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   529
		    buf = (char *)(obj);                \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   530
		    continue;                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   531
		}                                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   532
		break;                                  \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   533
	    }                                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   534
	    __offs += (ret);                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   535
	}                                               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   536
	if (__offs > 0)                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   537
	    (ret) = __offs;                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   538
    }							\
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   539
  }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   540
#else
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   541
#define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)            \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   542
  {							\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   543
    int __ooffs = obj_offs;				\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   544
    int __offs = 0;					\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   545
    char *buf = (char *)(obj);				\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   546
							\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   547
    (ret) = 0;                                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   548
    if (isBuffered) {                                   \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   549
	while (__offs < (cnt)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   550
	    CLEAR_ERRNO;				\
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   551
	    ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f);           \
3187
824107b81d57 oops - fwrite returns 0 (with errno set) in case of E-NO-SPACE.
Claus Gittinger <cg@exept.de>
parents: 3174
diff changeset
   552
	    if ((ret) <= 0) {                           \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   553
		if (ferror(f)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   554
		    if (errno == EINTR) {               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   555
			__HANDLE_INTERRUPTS__;          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   556
			/* refetch */                   \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   557
			buf = (char *)(obj);            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   558
			clearerr(f);                    \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   559
			continue;                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   560
		    }                                   \
3187
824107b81d57 oops - fwrite returns 0 (with errno set) in case of E-NO-SPACE.
Claus Gittinger <cg@exept.de>
parents: 3174
diff changeset
   561
		    break;                              \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   562
		} else {                                \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   563
		    (ret) = 0;                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   564
		}                                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   565
	    }                                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   566
	    __offs += (ret);                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   567
	}                                               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   568
	if (__offs > 0)                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   569
	    (ret) = __offs;                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   570
    } else {                                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   571
	while (__offs < (cnt)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   572
	    CLEAR_ERRNO;				\
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   573
	    ret = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs);       \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   574
	    if (ret <= 0) {                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   575
		if (ret < 0 && errno == EINTR) {        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   576
		    __HANDLE_INTERRUPTS__;              \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   577
		    /* refetch */                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   578
		    buf = (char *)(obj);                \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   579
		    continue;                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   580
		}                                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   581
		break;                                  \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   582
	    }                                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   583
	    __offs += (ret);                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   584
	}                                               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   585
	if (__offs > 0)                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   586
	    (ret) = __offs;                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   587
    }							\
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   588
  }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   589
#endif
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   590
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   591
/*
223
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   592
 * on some systems errno is a macro ... check for it here
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   593
 */
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   594
#ifndef errno
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   595
 extern errno;
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   596
#endif
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   597
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   598
%}
188
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   599
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   600
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   601
!ExternalStream class methodsFor:'documentation'!
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   602
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   603
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   604
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   605
 COPYRIGHT (c) 1988 by Claus Gittinger
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   606
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   607
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   608
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   609
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   610
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   611
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   612
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   613
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   614
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   615
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   616
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   617
documentation
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   618
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   619
    ExternalStream defines protocol common to Streams which have a file-descriptor and 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   620
    represent some file or communicationChannel of the underlying OperatingSystem.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   621
    ExternalStream is abstract; concrete classes are FileStream, PipeStream etc.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   622
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   623
    ExternalStreams can be in two modes: text- (the default) and binary-mode.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   624
    In text-mode, the elements read/written are characters; 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   625
    while in binary-mode the basic elements are bytes which read/write as SmallIntegers 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   626
    in the range 0..255.
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   627
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   628
    Also, the stream can be either in buffered or unbuffered mode. In buffered mode,
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   629
    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
   630
    is sent (in both modes).
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   631
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   632
    The underlying OperatingSystem streams may either be closed explicitely (sending a close)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   633
    or just forgotten - in this case, the garbage collector will eventually collect the
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   634
    object AND a close will be performed automatically (but you will NOT know when this 
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   635
    happens - so it is recommended, that you close your files when no longer needed).
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   636
    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
   637
    some crash) the data will not be in the file, if unclosed. 
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   638
    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
   639
    a noop in one of the superclasses).
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   640
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   641
    Most of the methods found here redefine inherited methods for better performance,
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   642
    since I/O from/to files should be fast.
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   643
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   644
    Recovering a snapshot:
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   645
      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
   646
      reOpen in subclasses for more information.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   647
      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
   648
      reestablish the stream upon image restart (make someone dependent on ObjectMemory).
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   649
      FileStreams are reopened and positioned to their offset they had at snapshot time.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   650
      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
   651
      if the contents changed in the meantime.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   652
      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
   653
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   654
    [Instance variables:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   655
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   656
	filePointer     <Integer>       the unix FILE*; somehow mapped to an integer
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   657
					(notice: not the fd)
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   658
				        on Windows: the fileHandle
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   659
	mode            <Symbol>        #readwrite, #readonly or #writeonly
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   660
	buffered        <Boolean>       true, if buffered (i.e. collects characters - does
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   661
					not output immediately)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   662
	binary          <Boolean>       true if in binary mode (reads bytes instead of chars)
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   663
	eolMode         <Symbol>        one of nil, #cr or #crlf.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   664
					determines how lines should be terminated.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   665
				        nil -> newLine (as in Unix);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   666
					#crlf -> with cr-lf (as in MSDOS)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   667
					#cr -> with cr (as in VMS)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   668
	hitEOF          <Boolean>       true, if EOF was reached
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   669
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   670
	lastErrorNumber <Integer>       the value of errno (only valid right after the error -
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   671
					updated with next i/o operation)
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   672
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   673
    [Class variables:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   674
	Lobby           <Registry>      keeps track of used ext-streams (to free up FILE*'s)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   675
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   676
	StreamErrorSignal       <Signal> parent of all stream errors (see Stream class)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   677
	InvalidReadSignal       <Signal> raised on read from writeonly stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   678
	InvalidWriteSignal      <Signal> raised on write to readonly stream 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   679
	InvalidModeSignal       <Signal> raised on text I/O with binary-stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   680
					 or binary I/O with text-stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   681
	OpenErrorSignal         <Signal> raised if open fails
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   682
	StreamNotOpenSignal     <Signal> raised on I/O with non-open stream
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   683
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   684
    Additional notes:
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   685
      This class is implemented using the underlying stdio-c library package, which
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   686
      has both advantages and disadvantages: since it is portable (posix defined), porting
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   687
      ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   688
      has big problems handling unbounded Streams, since the EOF handling in stdio is
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   689
      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
   690
      a complete rewrite for UnboundedStream ...
325
claus
parents: 308
diff changeset
   691
188
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   692
      Also, depending on the system, the stdio library behaves infriendly when signals
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   693
      occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   694
      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
   695
      an error and errno is set to EINTR. 
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   696
      Thats what the ugly code around all getc-calls is for ...
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   697
      Since things get more and more ugly - we will rewrite ExternalStream
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   698
      completely, to NOT use any stdio stuff (and do its buffering itself).
325
claus
parents: 308
diff changeset
   699
claus
parents: 308
diff changeset
   700
      Notice that typical stdio's use a single errno global variable to return an error code,
claus
parents: 308
diff changeset
   701
      this was bad design in the stdio lib (right from the very beginning), since its much
claus
parents: 308
diff changeset
   702
      harder to deal with this in the presence of lightweight processes, where errno gets
claus
parents: 308
diff changeset
   703
      overwritten by an I/O operation done in another thread. (stdio should have been written
claus
parents: 308
diff changeset
   704
      to return errno as a negative number ...).
claus
parents: 308
diff changeset
   705
      To deal with this, the scheduler treats errno like a per-thread private variable,
claus
parents: 308
diff changeset
   706
      and saves/restores the errno setting when switching to another thread.
claus
parents: 308
diff changeset
   707
      (Notice that some thread packages do this also, but ST/X's thread implementation
claus
parents: 308
diff changeset
   708
      does not depend on those, but instead uses a portable private package).
claus
parents: 308
diff changeset
   709
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   710
      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
   711
      fseek whenever we are about to read after write and vice versa.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   712
      Two macros (__READING__ and __WRITING__) have been defined to be used before every
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   713
      fread/fgetc and fwrite/putc respectively.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   714
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   715
    [author:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   716
	Claus Gittinger
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   717
	Stefan Vogel (many, many fixes ...)
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   718
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   719
    [see also:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   720
	FileStream Socket PipeStream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   721
	Filename OperatingSystem
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   722
"
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   723
! !
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   724
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   725
!ExternalStream class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   726
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   727
initDefaultEOLMode
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   728
    OperatingSystem isUNIXlike ifTrue:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   729
	"/ unix EOL conventions
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   730
	DefaultEOLMode := #nl
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   731
    ] ifFalse:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   732
	OperatingSystem isVMSlike ifTrue:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   733
	    "/ vms EOL conventions
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   734
	    DefaultEOLMode := #cr
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   735
	] ifFalse:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   736
	    "/ msdos EOL conventions
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   737
	    DefaultEOLMode := #crlf
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   738
	]
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   739
    ]
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   740
!
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   741
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   742
initModeStrings
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   743
    "initialize modeStrings which are passed down to the underlying
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   744
     fopen/fdopen functions."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   745
3132
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   746
    OperatingSystem isMSDOSlike ifTrue:[
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   747
        ReadMode := 'rb'.
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   748
        ReadWriteMode := 'rb+'.
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   749
        WriteMode := 'wb'.
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   750
        AppendMode := 'ab+'.
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   751
        CreateReadWriteMode := 'wb+'.
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   752
    ] ifFalse:[
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   753
        ReadMode := 'r'.
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   754
        ReadWriteMode := 'r+'.
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   755
        WriteMode := 'w'.
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   756
        AppendMode := 'a+'.
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   757
        CreateReadWriteMode := 'w+'.
037027ae20fd msdos MUST use binary mode in I/O
Claus Gittinger <cg@exept.de>
parents: 3044
diff changeset
   758
    ]
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   759
!
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   760
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   761
initialize
593
19d568779cf7 moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   762
    OpenErrorSignal isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   763
	OpenErrorSignal := StreamErrorSignal newSignalMayProceed:true.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   764
	OpenErrorSignal nameClass:self message:#openErrorSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   765
	OpenErrorSignal notifierString:'open error'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   766
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   767
	InvalidReadSignal := ReadErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   768
	InvalidReadSignal nameClass:self message:#invalidReadSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   769
	InvalidReadSignal notifierString:'read error'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   770
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   771
	InvalidWriteSignal := WriteErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   772
	InvalidWriteSignal nameClass:self message:#invalidWriteSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   773
	InvalidWriteSignal notifierString:'write error'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   774
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   775
	InvalidModeSignal :=  StreamErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   776
	InvalidModeSignal nameClass:self message:#invalidModeSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   777
	InvalidModeSignal notifierString:'binary/text mode mismatch'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   778
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   779
	InvalidOperationSignal :=  StreamErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   780
	InvalidOperationSignal nameClass:self message:#invalidOperationSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   781
	InvalidOperationSignal notifierString:'unsupported file operation'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   782
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   783
	StreamNotOpenSignal := StreamErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   784
	StreamNotOpenSignal nameClass:self message:#streamNotOpenSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   785
	StreamNotOpenSignal notifierString:'stream is not open'.
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   786
    ].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   787
31
75f2b9f78be2 *** empty log message ***
claus
parents: 25
diff changeset
   788
    Lobby isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   789
	Lobby := Registry new.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   790
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   791
	"want to get informed when returning from snapshot"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   792
	ObjectMemory addDependent:self
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   793
    ].
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   794
    self initDefaultEOLMode.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   795
    self initModeStrings.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   796
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   797
a27a279701f8 Initial revision
claus
parents:
diff changeset
   798
reOpenFiles
a27a279701f8 Initial revision
claus
parents:
diff changeset
   799
    "reopen all files (if possible) after a snapShot load"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   800
301
35e40a6fc72b *** empty log message ***
claus
parents: 269
diff changeset
   801
    Lobby do:[:aFileStream |
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   802
	aFileStream reOpen
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   803
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   804
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   805
1469
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   806
update:something with:aParameter from:changedObject
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   807
    "have to reopen files when returning from snapshot"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   808
a27a279701f8 Initial revision
claus
parents:
diff changeset
   809
    something == #returnFromSnapshot ifTrue:[
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   810
	self reOpenFiles.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   811
        self initDefaultEOLMode
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   812
    ]
1469
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   813
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   814
    "Created: 15.6.1996 / 15:19:59 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   815
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   816
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   817
!ExternalStream class methodsFor:'instance creation'!
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   818
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   819
forFileDescriptor:aFileDescriptor mode:modeString
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   820
    "given a fileDescriptor, create an ExternalStream object
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   821
     to operate on this fd. 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   822
     The mode-argument is passed to the fdopen call.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   823
     This may be used to wrap fd's as returned by user 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   824
     primitive code, or to wrap pipe-fds into externalStreams."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   825
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   826
    |newStream|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   827
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   828
    newStream := self basicNew.
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   829
    newStream text; buffered:true; eolMode:DefaultEOLMode; clearEOF.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   830
    ^ newStream 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   831
	connectTo:aFileDescriptor 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   832
	withMode:modeString
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   833
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   834
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   835
     the example below will probably fail (15 is a random FD):
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   836
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   837
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   838
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   839
     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
   840
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   841
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   842
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   843
    "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
   844
    "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
   845
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   846
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   847
forReadWriteToFileDescriptor:aFileDescriptor
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   848
    "given a fileDescriptor, create an ExternalStream object
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   849
     to read/write from/to this fd. This may be used to wrap fd's
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   850
     as returned by user primitive code, or to wrap pipe-
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   851
     filedescriptors into externalStreams."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   852
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   853
    ^ self forFileDescriptor:aFileDescriptor mode:ReadWriteMode
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   854
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   855
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   856
     the example below will probably fail (15 is a random FD):
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   857
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   858
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   859
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   860
     s := ExternalStream forReadWriteToFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   861
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   862
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   863
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   864
    "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
   865
    "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
   866
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   867
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   868
forReadingFromFileDescriptor:aFileDescriptor
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   869
    "given a fileDescriptor, create an ExternalStream object
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   870
     to read from this fd. This may be used to wrap fd's
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   871
     as returned by user primitive code, or to wrap pipe-
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   872
     filedescriptors into externalStreams."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   873
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   874
    ^ self forFileDescriptor:aFileDescriptor mode:ReadMode
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   875
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   876
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   877
     the example below will probably fail (15 is a random FD):
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   878
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   879
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   880
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   881
     s := ExternalStream forReadingFromFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   882
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   883
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   884
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   885
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   886
     |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
   887
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   888
     'create OS pipe ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   889
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   890
     pipe := OperatingSystem makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   891
     readFd := pipe at:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   892
     writeFd := pipe at:2.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   893
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   894
     'connect Smalltalk streams ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   895
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   896
     rs := ExternalStream forReadingFromFileDescriptor:readFd.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   897
     ws := ExternalStream forWritingToFileDescriptor:writeFd.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   898
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   899
     'read ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   900
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   901
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   902
	     Transcript showCR:rs nextLine
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   903
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   904
	 rs close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   905
     ] forkAt:7.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   906
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   907
     'write ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   908
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   909
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   910
	     ws nextPutAll:'hello world '; nextPutAll:i printString; cr
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   911
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   912
	 ws close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   913
     ] fork.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   914
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   915
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   916
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   917
    "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
   918
    "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
   919
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   920
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   921
forWritingToFileDescriptor:aFileDescriptor
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   922
    "given a fileDescriptor, create an ExternalStream object
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   923
     to write to this fd. This may be used to wrap fd's
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   924
     as returned by user primitive code, or to wrap pipe-
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   925
     filedescriptors into externalStreams."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   926
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   927
    ^ self forFileDescriptor:aFileDescriptor mode:WriteMode
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   928
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   929
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   930
     the example below will probably fail (15 is a random FD):
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   931
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   932
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   933
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   934
     s := ExternalStream forWritingToFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   935
     s binary.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   936
     s nextPut:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   937
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   938
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   939
    "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
   940
    "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
   941
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   942
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   943
makePipe
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   944
    "return an array with two streams - the first one for reading, 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   945
     the second for writing. 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   946
     This is the higher level equivalent of OperatingSystem>>makePipe
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   947
     (which returns an array of file-descriptors)."
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   948
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   949
     |pipe rs ws|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   950
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   951
     pipe := OperatingSystem makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   952
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   953
     pipe notNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   954
	 rs := self forReadingFromFileDescriptor:(pipe at:1).
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   955
	 ws := self forWritingToFileDescriptor:(pipe at:2).
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   956
	 ^ 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
   957
     ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   958
     ^ nil
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   959
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   960
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   961
     |pipe rs ws|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   962
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   963
     pipe := ExternalStream makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   964
     rs := pipe at:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   965
     ws := pipe at:2.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   966
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   967
     'read ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   968
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   969
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   970
	     Transcript showCR:rs nextLine
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   971
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   972
	 rs close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   973
     ] forkAt:7.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   974
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   975
     'write ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   976
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   977
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   978
	     ws nextPutAll:'hello world '; nextPutAll:i printString; cr
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   979
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   980
	 ws close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   981
     ] fork.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   982
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   983
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   984
    "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
   985
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   986
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   987
new
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   988
    |newStream|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   989
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   990
    newStream := self basicNew.
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   991
    newStream text; buffered:true; eolMode:DefaultEOLMode; clearEOF.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   992
    ^ newStream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   993
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   994
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   995
!ExternalStream class methodsFor:'Signal constants'!
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   996
1522
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   997
inaccessibleSignal
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   998
    "ST-80 compatibility: return openErrorSignal"
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   999
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1000
    ^ self openErrorSignal
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1001
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1002
    "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
  1003
!
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1004
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1005
invalidModeSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1006
    "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
  1007
     or binary-I/O with a text stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1008
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1009
    ^ InvalidModeSignal
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1010
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1011
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1012
invalidOperationSignal
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1013
    "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
  1014
     I/O operation is attempted"
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1015
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1016
    ^ InvalidOperationSignal
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1017
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1018
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1019
invalidReadSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1020
    "return the signal raised when reading from writeonly streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1021
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1022
    ^ InvalidReadSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1023
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1024
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1025
invalidWriteSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1026
    "return the signal raised when writing to readonly streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1027
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1028
    ^ InvalidWriteSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1029
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1030
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1031
openErrorSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1032
    "return the signal raised when a file open failed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1033
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1034
    ^ OpenErrorSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1035
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1036
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1037
streamNotOpenSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1038
    "return the signal raised on I/O with closed streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1039
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1040
    ^ StreamNotOpenSignal
2
claus
parents: 1
diff changeset
  1041
! !
claus
parents: 1
diff changeset
  1042
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1043
!ExternalStream class methodsFor:'error handling'!
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1044
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1045
lastErrorNumber
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1046
    "return the errno of the last error"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1047
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1048
    ^ LastErrorNumber
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1049
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1050
    "
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1051
     ExternalStream lastErrorNumber
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1052
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1053
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1054
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1055
lastErrorString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1056
    "return a message string describing the last error"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1057
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1058
    ^ OperatingSystem errorTextForNumber:LastErrorNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1059
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1060
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1061
     ExternalStream lastErrorString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1062
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1063
! !
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1064
3044
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1065
!ExternalStream methodsFor:'Squeak compatibility'!
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1066
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1067
readOnly
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1068
    "Squeak compatibility: make the stream readOnly"
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1069
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1070
    mode := #readonly
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1071
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1072
    "Modified: 20.10.1997 / 19:23:04 / cg"
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1073
    "Created: 20.10.1997 / 19:23:19 / cg"
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1074
! !
a0bbac91639b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3029
diff changeset
  1075
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1076
!ExternalStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1077
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1078
binary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1079
    "switch to binary mode - default is text"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1080
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1081
    binary := true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1082
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1083
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1084
buffered:aBoolean
10
claus
parents: 5
diff changeset
  1085
    "turn buffering on or off - default is on"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1086
10
claus
parents: 5
diff changeset
  1087
    buffered := aBoolean
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1088
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1089
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1090
contents
2
claus
parents: 1
diff changeset
  1091
    "return the contents of the file from the current position up-to
claus
parents: 1
diff changeset
  1092
     the end. If the stream is in binary mode, a ByteArray containing
claus
parents: 1
diff changeset
  1093
     the byte values is returned.
claus
parents: 1
diff changeset
  1094
     In text-mode, a collection of strings, each representing one line,
claus
parents: 1
diff changeset
  1095
     is returned."
claus
parents: 1
diff changeset
  1096
claus
parents: 1
diff changeset
  1097
    |text l chunks sizes chunk byteCount cnt bytes offset|
claus
parents: 1
diff changeset
  1098
claus
parents: 1
diff changeset
  1099
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1100
	"adding to a ByteArray produces quadratic time-space
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1101
	 behavior - therefore we allocate chunks, and concatenate them
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1102
	 at the end."
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1103
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1104
	chunks := OrderedCollection new.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1105
	sizes := OrderedCollection new.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1106
	byteCount := 0.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1107
	[self atEnd] whileFalse:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1108
	    chunk := ByteArray uninitializedNew:4096.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1109
	    cnt := self nextBytes:(chunk size) into:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1110
	    cnt notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1111
		chunks add:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1112
		sizes add:cnt.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1113
		byteCount := byteCount + cnt
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1114
	    ]
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1115
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1116
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1117
	"now, create one big ByteArray"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1118
	bytes := ByteArray uninitializedNew:byteCount.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1119
	offset := 1.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1120
	1 to:chunks size do:[:index |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1121
	    chunk := chunks at:index.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1122
	    cnt := sizes at:index. 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1123
	    bytes replaceFrom:offset to:(offset + cnt - 1) with:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1124
	    offset := offset + cnt
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1125
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1126
	^ bytes
2
claus
parents: 1
diff changeset
  1127
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1128
244
9faa2da0650a Text <-> StringCollection
claus
parents: 223
diff changeset
  1129
    text := StringCollection new.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1130
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1131
	l := self nextLine.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1132
	l isNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1133
	    ^ text
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1134
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1135
	text add:l
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1136
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1137
    ^ text
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1138
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1139
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1140
contentsOfEntireFile
1522
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1141
    "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
  1142
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1143
    ^ self contents asString.
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1144
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1145
    "Modified: 3.7.1996 / 13:22:16 / stefan"
2
claus
parents: 1
diff changeset
  1146
!
claus
parents: 1
diff changeset
  1147
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1148
contentsSpecies
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1149
    "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
  1150
     (such as upTo)"
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1151
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1152
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1153
	^ ByteArray
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1154
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1155
    ^ String
2
claus
parents: 1
diff changeset
  1156
!
claus
parents: 1
diff changeset
  1157
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1158
eolMode:aSymbolOrNil
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1159
    "specify how end-of-line (EOL) is to be marked.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1160
     The argument may be one of:
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1161
	#crlf         -> add a CR-NL, as in MSDOS
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1162
	#cr           -> add a CR, as in VMS
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1163
	#nl           -> add a NL, as in Unix
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1164
	anyOther      -> like #nl
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1165
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1166
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1167
    eolMode := aSymbolOrNil
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1168
!
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1169
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1170
fileDescriptor
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1171
    "return the fileDescriptor of the receiver -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1172
     notice: this one returns the underlying OSs fileDescriptor -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1173
     this may not be available on all platforms (i.e. non unix systems)."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1174
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1175
%{  /* NOCONTEXT */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1176
#ifdef WIN32
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1177
    RETURN (nil);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1178
#else
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1179
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1180
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1181
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1182
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1183
	f = __FILEVal(fp);
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1184
	RETURN ( __MKINT(fileno(f)) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1185
    }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1186
#endif
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1187
%}.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1188
    ^ self errorNotOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1189
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1190
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1191
filePointer
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1192
    "return the filePointer of the receiver -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1193
     notice: for portability stdio is used; this means you will get
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1194
     a FILE * - not a fileDescriptor. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1195
     (what you really get is a corresponding integer).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1196
     You cannot do much with the returned value 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1197
     - except passing it to a primitive, for example."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1198
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1199
    ^ filePointer
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1200
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1201
3016
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  1202
lineEndTransparent
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  1203
    eolMode := #cr
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  1204
!
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  1205
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1206
readonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1207
    "set access mode to readonly"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1208
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1209
    mode := #readonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1210
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1211
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1212
readwrite
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1213
    "set access mode to readwrite"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1214
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1215
    mode := #readwrite
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1216
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1217
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1218
text
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1219
    "switch to text mode - default is text"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1220
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1221
    binary := false
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1222
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1223
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1224
useCRLF:aBoolean
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1225
    "turn on or off CRLF sending (instead of LF only) - default is off.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1226
     This method is provided for backward compatibility - see #eolMode:
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1227
     which offers another choice."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1228
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1229
    aBoolean ifTrue:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1230
	eolMode := #crlf
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1231
    ] ifFalse:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1232
	eolMode := #nl
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1233
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1234
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1235
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1236
writeonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1237
    "set access mode to writeonly"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1238
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1239
    mode := #writeonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1240
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1241
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1242
!ExternalStream methodsFor:'error handling'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1243
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1244
argumentMustBeCharacter
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1245
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1246
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1247
    "report an error, that the argument must be a character"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1248
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1249
    ^ self error:'argument must be a character'
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1250
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1251
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1252
argumentMustBeInteger
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1253
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1254
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1255
    "report an error, that the argument must be an integer"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1256
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1257
    ^ self error:'argument must be an integer'
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1258
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1259
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1260
argumentMustBeString
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1261
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1262
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1263
    "report an error, that the argument must be a string"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1264
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1265
    ^ self error:'argument must be a string'
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1266
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1267
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1268
errorBinary
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1269
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1270
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1271
    "report an error, that the stream is in binary mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1272
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1273
    ^ self invalidModeSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1274
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1275
	     errorString:(self class name , ' is in binary mode')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1276
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1277
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1278
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1279
errorNotBinary
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1280
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1281
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1282
    "report an error, that the stream is not in binary mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1283
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1284
    ^ self invalidModeSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1285
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1286
	     errorString:(self class name , ' is not in binary mode')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1287
		      in:thisContext sender
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1288
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1289
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1290
errorNotBuffered
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1291
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1292
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1293
    "report an error, that the stream is not in buffered mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1294
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1295
    ^ StreamErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1296
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1297
	     errorString:(self class name , ' is unbuffered - operation not allowed')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1298
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1299
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1300
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1301
errorNotOpen
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1302
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1303
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1304
    "report an error, that the stream has not been opened"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1305
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1306
    ^ self streamNotOpenSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1307
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1308
	     errorString:(self class name , ' not open')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1309
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1310
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1311
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1312
errorOpen
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1313
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1314
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1315
    "report an error, that the stream is already opened"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1316
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1317
    ^ self openErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1318
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1319
	errorString:(self class name , ' is already open')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1320
		 in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1321
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1322
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1323
errorReadOnly
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1324
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1325
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1326
    "report an error, that the stream is a readOnly stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1327
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1328
    ^ self invalidWriteSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1329
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1330
	     errorString:(self class name , ' is readonly')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1331
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1332
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1333
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1334
errorUnsupportedOperation
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1335
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1336
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1337
    "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
  1338
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1339
    ^ self invalidOperationSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1340
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1341
	errorString:'unsupported operation'
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1342
		 in:thisContext sender
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1343
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1344
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1345
errorWriteOnly
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1346
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1347
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1348
    "report an error, that the stream is a writeOnly stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1349
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1350
    ^ self invalidReadSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1351
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1352
	     errorString:(self class name , ' is writeonly')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1353
		      in:thisContext sender
2
claus
parents: 1
diff changeset
  1354
!
claus
parents: 1
diff changeset
  1355
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1356
ioError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1357
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1358
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1359
    "report an error, that some I/O error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1360
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1361
    ^ StreamErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1362
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1363
	     errorString:('I/O error: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1364
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1365
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1366
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1367
lastErrorNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1368
    "return the last error"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1369
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1370
    ^ lastErrorNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1371
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1372
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1373
lastErrorString
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1374
    "return a message string describing the last error"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1375
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1376
    (lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1377
	^ 'I/O error'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1378
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1379
    ^ OperatingSystem errorTextForNumber:lastErrorNumber
2
claus
parents: 1
diff changeset
  1380
!
claus
parents: 1
diff changeset
  1381
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1382
openError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1383
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1384
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1385
    "report an error, that the open failed"
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
    ^ OpenErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1388
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1389
	     errorString:('error on open: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1390
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1391
!
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
readError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1394
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1395
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1396
    "report an error, that some read error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1397
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1398
    ^ ReadErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1399
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1400
	     errorString:('read error: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1401
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1402
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1403
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1404
writeError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1405
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1406
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1407
    "report an error, that some write error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1408
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1409
    ^ WriteErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1410
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1411
	     errorString:('write error: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1412
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1413
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1414
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1415
!ExternalStream methodsFor:'instance release'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1416
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1417
closeFile
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1418
    "low level close - may be redefined in subclasses"
2
claus
parents: 1
diff changeset
  1419
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1420
%{
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1421
    OBJ fp;
2
claus
parents: 1
diff changeset
  1422
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1423
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1424
	__INST(filePointer) = nil;
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1425
#if defined(WIN32) && defined(NO_STDIO)
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1426
	CloseHandle(__HANDLEVal(fp));
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1427
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1428
	__BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1429
	fclose(__FILEVal(fp));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1430
	__END_INTERRUPTABLE__
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1431
#endif
10
claus
parents: 5
diff changeset
  1432
    }
claus
parents: 5
diff changeset
  1433
%}
claus
parents: 5
diff changeset
  1434
!
claus
parents: 5
diff changeset
  1435
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1436
disposed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1437
    "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
  1438
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1439
    self closeFile
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1440
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1441
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1442
setFileDescriptor:anInteger mode:openMode
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1443
    "set the filePointer based upon a given fileDescriptor -
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1444
     notice: this one is based on the underlying OSs fileDescriptor -
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1445
     this may not be available on all platforms (i.e. non unix systems)."
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1446
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1447
%{  /* NOCONTEXT */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1448
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1449
    FILEPOINTER f;
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1450
    OBJ fp;
2765
a56668774ad7 more alpha64 fixes
Claus Gittinger <cg@exept.de>
parents: 2764
diff changeset
  1451
    FILE *fdopen();
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1452
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1453
    if (__isSmallInteger(anInteger) &&
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1454
	__isString(openMode) &&
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1455
	(f = fdopen(__intVal(anInteger), __stringVal(openMode))) != 0
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1456
    ) {
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1457
	__PROTECT__(self);
2999
b0e55440cf12 eliminate MKOBJ & MKCP (use MKEXTERNALADDRESS & externalAddressVal)
Claus Gittinger <cg@exept.de>
parents: 2986
diff changeset
  1458
	fp = __MKEXTERNALADDRESS(f); 
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1459
	__UNPROTECT__(self);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1460
	__INST(filePointer) = fp; __STORE(self, fp);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1461
	RETURN (self);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1462
    }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1463
%}.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1464
    ^ self primitiveFailed
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1465
!
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1466
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1467
setFilePointer:something
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1468
    "set the filePointer to the given one;
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1469
     low level private & friend interface; may also be used to connect to some
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1470
     externally provided file handle."
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1471
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1472
    filePointer := something
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1473
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1474
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1475
shallowCopyForFinalization
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1476
    "return a copy for finalization-registration;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1477
     since all we need at finalization time is the fileDescriptor,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1478
     a cheaper copy is possible."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1479
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1480
    ^ self class basicNew setFilePointer:filePointer
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1481
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1482
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1483
shutDown
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1484
    "close the stream - added for protocol compatibility with PipeStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1485
     see comment there"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1486
1642
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1487
    filePointer isNil ifTrue:[^ self].
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1488
    Lobby unregister:self.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1489
    self closeFile
1642
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1490
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1491
    "Modified: 30.8.1996 / 00:39:21 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1492
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1493
2
claus
parents: 1
diff changeset
  1494
!ExternalStream methodsFor:'line reading/writing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1495
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1496
nextLine
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1497
    "read the next line (characters up to newline).
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1498
     Return a string containing those characters excluding the newline.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1499
     If the previous-to-last character is a cr, this is also removed,
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1500
     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
  1501
     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
  1502
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1503
    |line|
971
eb70f5674303 max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
  1504
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1505
%{  /* STACK:34000 */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1506
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1507
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1508
    int len, ret;
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1509
    char buffer[32*1024];
521
70533ec40482 use new MKSTRING_L if length is known (avoids a useless strlen)
Claus Gittinger <cg@exept.de>
parents: 481
diff changeset
  1510
    char *rslt, *nextPtr, *limit;
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1511
    int fd, ch;
1068
92fdcccf12a3 alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1512
    int _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1513
    OBJ fp;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1514
    int lineTooLong = 0;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1515
    int cutOff = 0;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1516
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1517
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1518
    if (((fp = __INST(filePointer)) != nil)
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1519
        && (__INST(mode) != @symbol(writeonly))
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1520
        && (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1521
    ) {
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1522
        f = __FILEVal(fp);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1523
        buffer[0] = '\0';
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1524
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1525
        _buffered = (__INST(buffered) == true);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1526
        if (_buffered) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1527
            __READING__(f);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1528
        } 
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1529
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1530
        rslt = nextPtr = buffer;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1531
        limit = buffer + sizeof(buffer) - 2;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1532
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1533
        for (;;) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1534
            __READBYTE__(ret, f, nextPtr, _buffered);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1535
            if (ret <= 0) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1536
                if (nextPtr == buffer)
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1537
                    rslt = NULL;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1538
                if (ret == 0) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1539
                    __INST(hitEOF) = true;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1540
                    break;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1541
                } else {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1542
                    __INST(lastErrorNumber) = __MKSMALLINT(errno);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1543
                    goto err;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1544
                }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1545
            }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1546
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1547
            if (*nextPtr == '\n') {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1548
                cutOff = 1;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1549
                *nextPtr = '\0';
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1550
                break;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1551
            }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1552
            if (*nextPtr == '\r') {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1553
                char peekChar;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1554
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1555
                /*
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1556
                 * peek ahead for a newLine ...
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1557
                 */
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1558
                __READBYTE__(ret, f, &peekChar, _buffered);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1559
                if (ret <= 0) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1560
                    cutOff = 1;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1561
                    *nextPtr = '\0';
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1562
                    if (ret == 0) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1563
                        __INST(hitEOF) = true;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1564
                        break;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1565
                    }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1566
                    __INST(lastErrorNumber) = __MKSMALLINT(errno);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1567
                    goto err;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1568
                }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1569
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1570
                if (peekChar == '\n') {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1571
                    cutOff = 2;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1572
                    *nextPtr = '\0';
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1573
                    break;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1574
                }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1575
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1576
                __UNGETC__(peekChar, f, _buffered);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1577
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1578
                cutOff = 1;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1579
                *nextPtr = '\0';
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1580
                break;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1581
            }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1582
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1583
            nextPtr++;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1584
            if (nextPtr >= limit) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1585
                *nextPtr = '\0';
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1586
                lineTooLong = 1;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1587
                if (@global(InfoPrinting) == true) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1588
                    fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n");
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1589
                }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1590
                break;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1591
            }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1592
        }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1593
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1594
        if (rslt != NULL) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1595
            len = nextPtr-buffer;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1596
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1597
            if (__INST(position) != nil) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1598
                int __p;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1599
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1600
                __p = __intVal(__INST(position)) + len + cutOff;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1601
                __INST(position) = __MKSMALLINT(__p);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1602
            }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1603
            /* remove any EOL character */
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1604
            if (len != 0) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1605
                if (buffer[len-1] == '\n') {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1606
                    buffer[--len] = '\0';
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1607
                }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1608
                if ((len != 0) && (buffer[len-1] == '\r')) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1609
                    buffer[--len] = '\0';
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1610
                }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1611
            }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1612
            line = __MKSTRING_L(buffer, len);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1613
            if (! lineTooLong) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1614
                RETURN ( line );
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1615
            }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1616
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1617
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1618
err: ;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1619
%}.
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1620
    line notNil ifTrue:[
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1621
        "/ the line as read is longer than 32k characters (boy - what a line)
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1622
        "/ The exception could be handled by reading more and returning the
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1623
        "/ concatenation in your exception handler (the receiver and the partial
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1624
        "/ line are passed as parameter)
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1625
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1626
        ^ ReadErrorSignal
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1627
            raiseRequestWith:(Array with:self with:line)
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  1628
                 errorString:('line too long read error')
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1629
    ].
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1630
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1631
    hitEOF ifTrue:[^ self pastEnd].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1632
    lastErrorNumber notNil ifTrue:[^ self readError].
2
claus
parents: 1
diff changeset
  1633
    filePointer isNil ifTrue:[^ self errorNotOpen].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1634
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1635
    ^ self errorBinary
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1636
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1637
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1638
nextPutLine:aString
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1639
    "write the characters in aString and append an end-of-Line marker
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1640
     (LF, CR or CRLF - depending in the setting of eolMode)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1641
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1642
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1643
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1644
    int len, cnt, len1, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1645
    OBJ pos, fp;
537
dc4dad8a5ddd many ExtStream rewrites - has to be reevaluated in all platforms
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1646
    char *cp;
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1647
    int o_offs;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1648
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1649
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1650
    if (((fp = __INST(filePointer)) != nil) 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1651
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1652
	&& (__INST(binary) != true)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1653
	&& __isString(aString)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1654
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1655
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1656
	len = __stringSize(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1657
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1658
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1659
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1660
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1661
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1662
	__WRITEBYTES__(cnt, f, __stringVal(aString), len, _buffered);
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1663
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1664
	o_offs = (char *)__stringVal(aString)-(char *)aString;
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1665
	__WRITEBYTES_OBJ__(cnt, f, aString, o_offs, len, _buffered);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1666
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1667
	if (cnt == len) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1668
	    OBJ mode = __INST(eolMode);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1669
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1670
	    len1 = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1671
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1672
	    if (mode == @symbol(cr)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1673
		cp = "\r"; len = 1;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1674
	    } else if (mode == @symbol(crlf)) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1675
		cp = "\r\n"; len = 2;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1676
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1677
		cp = "\n"; len = 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1678
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1679
	    __WRITEBYTES__(cnt, f, cp, len, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1680
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1681
	    if (cnt > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1682
		pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1683
		if (pos != nil) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1684
		    int __p;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1685
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1686
		    __p = __intVal(pos) + len1 + cnt;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1687
		    __INST(position) = __MKSMALLINT(__p);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1688
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1689
		RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1690
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1691
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1692
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1693
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1694
%}.
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1695
    super nextPutLine:aString.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1696
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1697
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1698
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1699
    "read from aStream up to and including a line starting with aStringOrNil
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1700
     and append all lines to self. 
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1701
     Can be used to copy/create large files or copy from a pipe/socket.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1702
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1703
     If aStringOrNil is nil or not matched, copy preceeds to the end.
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1704
     (this allows for example to read a Socket and transfer the data quickly
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1705
      into a file - without creating zillions of temporary strings)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1706
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1707
    |srcFilePointer readError line|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1708
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1709
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1710
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1711
    srcFilePointer := aStream filePointer.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1712
    srcFilePointer isNil ifTrue:[aStream errorNotOpen. ^ self].
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1713
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1714
%{  /* STACK:2000 */
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1715
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1716
#ifndef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1717
    FILEPOINTER dst;
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1718
    FILEPOINTER src;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1719
    char *matchString;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1720
    int matchLen = 0;
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1721
    char buffer[1024];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1722
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1723
    __INST(lastErrorNumber) = nil;
249
claus
parents: 244
diff changeset
  1724
    if (__isSmallInteger(srcFilePointer)) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1725
	if ((aStringOrNil == nil) || __isString(aStringOrNil)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1726
	    if (aStringOrNil != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1727
		matchString = (char *) __stringVal(aStringOrNil);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1728
		matchLen = __stringSize(aStringOrNil);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1729
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1730
	    dst = __FILEVal(__INST(filePointer));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1731
	    src = __FILEVal(srcFilePointer);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1732
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1733
	    errno = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1734
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1735
	    __WRITING__(dst)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1736
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1737
	    for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1738
		if (fgets(buffer, sizeof(buffer)-1, src) == NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1739
		    if (ferror(src)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1740
			readError = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1741
			__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1742
			goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1743
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1744
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1745
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1746
		if (fputs(buffer, dst) == EOF) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1747
		    if (ferror(dst)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1748
			__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1749
			__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1750
			goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1751
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1752
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1753
		}
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1754
#ifndef OLD
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1755
		if (__INST(buffered) == false) {
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1756
		    FFLUSH(dst);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1757
		}
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1758
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1759
		if (matchLen) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1760
		    if (strncmp(matchString, buffer, matchLen) == 0) 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1761
			break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1762
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1763
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1764
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1765
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1766
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1767
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1768
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1769
err: ;
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1770
#endif /* ! NO_STDIO */
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1771
%}.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1772
    readError ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1773
	aStream setLastErrorNumber:readError.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1774
	aStream readError.
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1775
	^ self
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1776
    ].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1777
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1778
    buffered ifFalse:[self errorNotBuffered. ^ self].
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1779
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1780
    "
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1781
     argument error or unimplemented; try it linewise
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1782
    "
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1783
    [aStream atEnd] whileFalse:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1784
	line := aStream nextLine.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1785
	line isNil ifTrue:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1786
	    ^ self.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1787
	].
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1788
	self nextPutLine:line.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1789
	(aStringOrNil notNil and:[line startsWith:aStringOrNil]) ifTrue:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1790
	    ^ self
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1791
	]
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1792
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1793
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1794
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1795
peekForLineStartingWith:aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1796
    "read ahead for next line starting with aString;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1797
     return the line-string if found, or nil if EOF is encountered.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1798
     If matched, not advance position behond that line
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1799
     i.e. nextLine will read the matched line.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1800
     If not matched, reposition to original position for firther reading."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1801
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1802
    |firstPos lastPos line|
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1803
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1804
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1805
    filePointer isNil ifTrue:[^ self errorNotOpen].
2
claus
parents: 1
diff changeset
  1806
    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
  1807
    buffered ifFalse:[^ self errorNotBuffered].
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1808
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1809
%{  /* STACK: 2000 */
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1810
#ifndef NO_STDIO
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1811
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1812
    FILEPOINTER f;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1813
    int l;
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1814
    char buffer[1024];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1815
    char *cp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1816
    char *matchString;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1817
    int gotFirst = 0;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1818
#ifdef __VMS__
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1819
    fpos_t firstpos, lastpos;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1820
#   define FTELL(__f__, __pos__)	fgetpos(__f__, &(__pos__))
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1821
#   define FSEEK(__f__, __pos__)	fsetpos(__f__, &(__pos__))
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1822
#else
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1823
    long firstpos, lastpos;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1824
#   define FTELL(__f__, __pos__)	__pos__ = ftell(__f__)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1825
#   define FSEEK(__f__, __pos__)	fseek(__f__, __pos__, SEEK_SET)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1826
#endif
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1827
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1828
    __INST(lastErrorNumber) = nil;
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
  1829
    if (__isString(aString)) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1830
	matchString = (char *) __stringVal(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1831
	l = __stringSize(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1832
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1833
	f = __FILEVal(__INST(filePointer));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1834
	__READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1835
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1836
	for (;;) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1837
	    FTELL(f, lastpos);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1838
	    if (!gotFirst) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1839
		firstpos = lastpos;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1840
		gotFirst = 1;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1841
	    }
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1842
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1843
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1844
	    do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1845
		cp = fgets(buffer, sizeof(buffer)-1, f);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1846
	    } while ((cp == NULL) && ferror(f) && (errno == EINTR) && (clearerr(f), 1));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1847
	    buffer[sizeof(buffer)-1] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1848
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1849
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1850
	    if (cp == NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1851
		if (ferror(f)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1852
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1853
		    goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1854
		} else {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1855
		    FSEEK(f, firstpos);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1856
		    RETURN (nil);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1857
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1858
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1859
	    if (strncmp(cp, matchString, l) == 0) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1860
		FSEEK(f, lastpos);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1861
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1862
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1863
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1864
	/* remove EOL character */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1865
	cp = buffer;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1866
	while (*cp && (*cp != '\n') && (*cp != '\r')) cp++;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1867
	*cp = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1868
	RETURN ( __MKSTRING(buffer) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1869
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1870
err: ;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1871
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1872
# undef FTELL
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1873
# undef FSEEK
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1874
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1875
#endif
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1876
%}.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1877
    lastErrorNumber notNil ifTrue:[^ self readError].
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1878
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1879
    "/ try using generic code ...
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1880
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1881
    firstPos := self position.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1882
    [self atEnd] whileFalse:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1883
	lastPos := self position.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1884
	line := self nextLine.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1885
	line isNil ifTrue:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1886
	    self position:firstPos.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1887
	    ^ nil
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1888
	].
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1889
	(line startsWith:aString) ifTrue:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1890
	    self position:lastPos.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1891
	    ^ line
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1892
	]
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1893
    ].
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1894
    self position:firstPos.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1895
    ^ nil
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1896
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1897
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1898
peekForLineStartingWithAny:aCollectionOfStrings
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1899
    "read ahead for next line starting with any of aCollectionOfStrings;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1900
     return the index in aCollection if found, nil otherwise..
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1901
     If no match, do not change position; otherwise advance right before the
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1902
     matched line so that nextLine will return this line."
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1903
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1904
    |line startPos linePos index|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1905
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1906
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1907
    filePointer isNil ifTrue:[^ self errorNotOpen].
2
claus
parents: 1
diff changeset
  1908
    binary ifTrue:[^ self errorBinary].
claus
parents: 1
diff changeset
  1909
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1910
    startPos := self position.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1911
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1912
	linePos := self position.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1913
	line := self nextLine.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1914
	line notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1915
	    index := 1.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1916
	    aCollectionOfStrings do:[:prefix |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1917
		(line startsWith:prefix) ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1918
		    self position:linePos.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1919
		    ^ index
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1920
		].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1921
		index := index + 1
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1922
	    ]
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1923
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1924
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1925
    self position:startPos.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1926
    ^ nil
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1927
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1928
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1929
!ExternalStream methodsFor:'misc functions'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1930
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1931
async:aBoolean
779
0e41a665038a commentary
Claus Gittinger <cg@exept.de>
parents: 730
diff changeset
  1932
    "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
  1933
     the receiver will trigger an ioInterrupt.
779
0e41a665038a commentary
Claus Gittinger <cg@exept.de>
parents: 730
diff changeset
  1934
     If cleared (which is the default) no special notification is made.
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1935
     Notice: 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1936
	not every OS supports this 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1937
	- check with OS>>supportsIOInterrupts before using"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1938
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1939
    |fd|
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1940
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1941
    filePointer isNil ifTrue:[^ self errorNotOpen].
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1942
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1943
    OperatingSystem supportsIOInterrupts ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1944
	^ self errorUnsupportedOperation
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1945
    ].
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1946
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1947
    fd := self fileDescriptor.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1948
    aBoolean ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1949
	^ OperatingSystem enableIOInterruptsOn:fd
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1950
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1951
    ^ OperatingSystem disableIOInterruptsOn:fd
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1952
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1953
    "Modified: 11.1.1997 / 17:50:21 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1954
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1955
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1956
backStep
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1957
    "step back one element -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1958
     redefined, since position is redefined here"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1959
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1960
    self position:(self position - 1)
362
claus
parents: 360
diff changeset
  1961
!
claus
parents: 360
diff changeset
  1962
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1963
blocking:aBoolean
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1964
    "set/clear the blocking attribute - if set (which is the default)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1965
     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
  1966
     If cleared, a read operation will immediately return with a value of
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1967
     nil.
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1968
     Turning off blocking is useful when reading from PipeStreams
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1969
     or Sockets, and the amount of data to be read is not known
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1970
     in advance. However, the data must then be read using #nextBytes:
3174
668414a73de9 Typo in comment
Stefan Vogel <sv@exept.de>
parents: 3132
diff changeset
  1971
     methods, in order to avoid other (pastEnd) exceptions."
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1972
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1973
    filePointer isNil ifTrue:[^ self errorNotOpen].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1974
    ^ OperatingSystem setBlocking:aBoolean on:(self fileDescriptor)
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1975
3174
668414a73de9 Typo in comment
Stefan Vogel <sv@exept.de>
parents: 3132
diff changeset
  1976
    "Modified: / 11.1.1997 / 17:48:01 / cg"
668414a73de9 Typo in comment
Stefan Vogel <sv@exept.de>
parents: 3132
diff changeset
  1977
    "Modified: / 15.1.1998 / 11:49:48 / stefan"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1978
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1979
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1980
close
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1981
    "close the stream - tell operating system"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1982
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1983
    filePointer isNil ifTrue:[^ self].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1984
    Lobby unregister:self.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1985
    self closeFile.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1986
    filePointer := nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1987
!
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
create
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1990
    "create the stream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1991
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1992
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1993
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1994
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1995
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1996
ioctl:ioctlNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1997
    "to provide a simple ioctl facility - an ioctl is performed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1998
     on the underlying file; no arguments are passed."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1999
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2000
    ^ self ioctl:ioctlNumber with:nil
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2001
!
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2002
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2003
ioctl:ioctlNumber with:arg
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2004
    "to provide a simple ioctl facility - an ioctl is performed
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2005
     on the underlying file; the argument is passed as argument.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2006
     This is not used by ST/X, but provided for special situations 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2007
     - for example, to control proprietrary I/O devices.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2008
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2009
     Since the type of the argument depends on the ioctl being
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2010
     performed, different arg types are allowed here.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2011
     If the argument is nil, an ioctl without argument is performed.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2012
     If the argument is an integral number, its directly passed; 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2013
     if its a kind of ByteArray (ByteArray, String or Structure),
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2014
     or external data (ExternalBytes or ExternalAddress),
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2015
     a pointer to the data is passed. 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2016
     This allows performing most ioctls 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2017
     - however, it might be tricky to setup the buffer.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2018
     Be careful in what you pass - ST/X cannot validate its correctness."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2019
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2020
%{
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
  2021
#if !defined(MSDOS_LIKE)
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
  2022
# if !defined(__openVMS__)
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2023
    FILEPOINTER f;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2024
    int ret, ioNum;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2025
    OBJ fp;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2026
    INT ioArg;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2027
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2028
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2029
    if ((fp = __INST(filePointer)) != nil) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2030
	if (__isSmallInteger(ioctlNumber) 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2031
	 && (__isSmallInteger(arg) 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2032
	     || (arg == nil)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2033
	     || __isBytes(arg)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2034
	     || __isExternalBytes(arg)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2035
	     || __isExternalAddress(arg))) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2036
	    f = __FILEVal(fp);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2037
	    ioNum = __intVal(ioctlNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2038
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2039
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2040
	    do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2041
		errno = 0;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2042
		if (arg == nil) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2043
		    ioArg = 0;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2044
		} else if (__isSmallInteger(arg)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2045
		    ioArg = __intVal(arg);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2046
		} else if (__isExternalBytes(arg)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2047
		    ioArg = (INT)(__externalBytesAddress(arg));
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2048
		} else if (__isExternalAddress(arg)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2049
		    ioArg = (INT)(__externalAddressVal(arg));
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2050
		} else {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2051
		    ioArg = (INT)(__ByteArrayInstPtr(arg)->ba_element);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2052
		}
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2053
		ret = ioctl(fileno(f), ioNum, ioArg);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2054
	    } while ((ret < 0) && (errno == EINTR));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2055
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2056
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2057
	    if (ret >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2058
		RETURN ( __MKSMALLINT(ret) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2059
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2060
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2061
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2062
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2063
    }
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
  2064
# endif
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  2065
#endif
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2066
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2067
    lastErrorNumber notNil ifTrue:[^ self ioError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2068
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2069
    "
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2070
     argument is not an integer
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2071
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2072
    (ioctlNumber isMemberOf:SmallInteger) ifFalse:[^ self primitiveFailed].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2073
    "
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2074
     the system does not support ioctl (MSDOS or VMS)
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2075
    "
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2076
    ^ self errorUnsupportedOperation
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2077
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2078
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2079
open
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2080
    "open the stream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2081
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2082
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2083
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2084
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2085
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2086
position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2087
    "return the position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2088
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2089
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2090
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2091
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2092
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2093
position:anInteger
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2094
    "set the position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2095
     - this must be redefined in subclass"
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
    ^ self subclassResponsibility
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2100
reset
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2101
    "set the read position to the beginning of the collection"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2102
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2103
    self position:"0" 1
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
1044
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2106
setToEnd
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2107
    "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
  2108
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2109
    ^ self subclassResponsibility
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2110
!
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2111
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2112
truncateTo:newSize
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2113
    "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
  2114
     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
  2115
1068
92fdcccf12a3 alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  2116
%{
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2117
#ifdef HAS_FTRUNCATE
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2118
    FILEPOINTER f;
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2119
    OBJ fp;
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2120
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2121
    if (((fp = __INST(filePointer)) != nil)
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2122
     && (__INST(mode) != @symbol(readonly))) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2123
	if (__isSmallInteger(newSize)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2124
	    f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2125
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2126
	    if (__INST(buffered) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2127
		__READING__(f)
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2128
		FFLUSH(f);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2129
		OPT_FSEEK(f, 0L, SEEK_END); /* needed in stdio */
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2130
	    }
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2131
	    ftruncate(fileno(f), __intVal(newSize));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2132
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2133
	}
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2134
    }
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2135
#endif
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2136
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2137
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2138
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2139
    self errorUnsupportedOperation
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2140
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2141
    "
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2142
     |s|
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2143
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2144
     s := 'test' asFilename writeStream.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2145
     s next:1000 put:$a.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2146
     s truncateTo:100.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2147
     s close.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2148
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2149
     ('test' asFilename fileSize) printNL
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2150
    "
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2151
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2152
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2153
!ExternalStream methodsFor:'non homogenous reading'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2154
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2155
nextByte
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2156
    "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
  2157
     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
  2158
     bytes binary value as an integer in 0..255."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2159
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2160
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2161
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2162
    unsigned char byte;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2163
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2164
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2165
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2166
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2167
    if (((fp = __INST(filePointer)) != nil)
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2168
     && (__INST(mode) != @symbol(writeonly))) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2169
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2170
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2171
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2172
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2173
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2174
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2175
	__READBYTE__(ret, f, &byte, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2176
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2177
	    if (__INST(position) != nil)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2178
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2179
	    RETURN (__MKSMALLINT(byte));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2180
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2181
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2182
	if (ret == 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2183
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2184
	} else /* ret < 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2185
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2186
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2187
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2188
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2189
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2190
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2191
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2192
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2193
    ^ self errorWriteOnly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2194
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2195
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2196
nextBytes:count into:anObject startingAt:start
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2197
    "read the next count bytes into an object and return the number of
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2198
     bytes read or the number of bytes read, if EOF is encountered before.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2199
     If the receiver is some socket/pipe-like stream, an exception
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2200
     is raised if the connection is broken.
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2201
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2202
     Notice, that in contrast to other methods,
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2203
     this does NOT return nil on EOF, but the actual count.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2204
     Thus allowing read of partial blocks.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2205
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2206
     The object must have non-pointer indexed instvars 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2207
     (i.e. it must be a ByteArray, String, Float- or DoubleArray).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2208
     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
  2209
     fastest possible physical I/O (since no new objects are allocated).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2210
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2211
     Use with care - non object oriented I/O.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2212
     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
  2213
     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
  2214
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2215
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2216
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2217
    int cnt, offs, ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2218
    int objSize, nInstVars, nInstBytes;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2219
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2220
    OBJ pos, fp, oClass;
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  2221
    int o_offs;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2222
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2223
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2224
    if (((fp = __INST(filePointer)) != nil)
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2225
        && (__INST(mode) != @symbol(writeonly))
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2226
        && __bothSmallInteger(count, start)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2227
    ) {
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2228
        f = __FILEVal(fp);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2229
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2230
        oClass = __Class(anObject);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2231
        switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2232
            case BYTEARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2233
            case WORDARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2234
            case LONGARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2235
            case SWORDARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2236
            case SLONGARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2237
            case FLOATARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2238
            case DOUBLEARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2239
                break;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2240
            default:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2241
                goto bad;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2242
        }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2243
        cnt = __intVal(count);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2244
        offs = __intVal(start) - 1;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2245
        nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2246
        nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2247
        objSize = __Size(anObject) - nInstBytes;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2248
        if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2249
            _buffered = (__INST(buffered) == true);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2250
            if (_buffered) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2251
                __READING__(f);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2252
            }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2253
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2254
            /*
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2255
             * on interrupt, anObject may be moved to another location.
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2256
             * So we pass (char *)__InstPtr(anObject) + nInstBytes + offs to the macro __READ_BYTES__,
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2257
             * to get a new address.
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2258
             */
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2259
            o_offs = nInstBytes+offs;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2260
            __READBYTES_OBJ__(ret, f, anObject, o_offs, cnt, _buffered);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2261
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2262
            if (ret > 0) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2263
                pos = __INST(position);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2264
                if (pos != nil) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2265
                    __INST(position) = __MKSMALLINT(__intVal(pos) + ret);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2266
                }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2267
                RETURN (__MKSMALLINT(ret));
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2268
            }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2269
            if (ret == 0) { 
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2270
                __INST(hitEOF) = true;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2271
            } else /* ret < 0 */ {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2272
                __INST(position) = nil;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2273
                __INST(lastErrorNumber) = __MKSMALLINT(errno);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2274
            }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2275
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2276
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2277
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2278
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2279
    (hitEOF and:[self pastEnd isNil]) ifTrue:[^ 0].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2280
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2281
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2282
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
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
     count not integer or arg not bit-like (String, ByteArray etc)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2285
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2286
    ^ self primitiveFailed
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2287
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2288
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2289
nextLong
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2290
    "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
  2291
     The returned value may be a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2292
     (msb-first for compatibility with other smalltalks)"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2293
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2294
    ^ self nextUnsignedLongMSB:true
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2295
!
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
nextLongMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2298
    "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
  2299
     which may be a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2300
     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
  2301
     otherwise least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2302
     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
  2303
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2304
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2305
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2306
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2307
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2308
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2309
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2310
	&& (__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
  2311
    ) {
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2312
	FILEPOINTER f;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2313
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2314
	int value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2315
	char buffer[4];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2316
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2317
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2318
	__READBYTES__(ret, f, buffer, 4, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2319
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2320
	if (ret == 4) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2321
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2322
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 4);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2323
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2324
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2325
		value = (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2326
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2327
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2328
		value = (value << 8) | (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2329
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2330
		value = (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2331
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2332
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2333
		value = (value << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2334
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2335
	    if ((value >= _MIN_INT) && (value <= _MAX_INT)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2336
		RETURN ( __MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2337
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2338
	    RETURN ( __MKLARGEINT(value) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2339
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2340
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2341
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2342
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2343
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2344
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2345
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2346
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2347
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2348
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2349
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2350
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2351
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2352
    ^ self readError.
1079
d47cd86b487b Make methods signal-proof.
Stefan Vogel <sv@exept.de>
parents: 1068
diff changeset
  2353
362
claus
parents: 360
diff changeset
  2354
!
claus
parents: 360
diff changeset
  2355
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2356
nextShortMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2357
    "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
  2358
     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
  2359
     otherwise least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2360
     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
  2361
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2362
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2363
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2364
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2365
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2366
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2367
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2368
	&& (__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
  2369
    ) {
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2370
	FILEPOINTER f;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2371
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2372
	short value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2373
	char buffer[2];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2374
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2375
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2376
	__READBYTES__(ret, f, buffer, 2, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2377
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2378
	if (ret == 2) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2379
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2380
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 2);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2381
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2382
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2383
		value = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2384
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2385
		value = ((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2386
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2387
	    RETURN (__MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2388
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2389
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2390
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2391
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2392
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2393
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2394
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2395
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2396
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2397
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2398
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2399
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2400
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2401
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2402
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2403
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2404
nextUnsignedLongMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2405
    "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
  2406
     a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2407
     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
  2408
     least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2409
     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
  2410
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2411
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2412
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2413
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2414
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2415
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2416
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2417
	&& (__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
  2418
    ) {
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2419
	FILEPOINTER f;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2420
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2421
	unsigned int value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2422
	char buffer[4];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2423
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2424
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2425
	__READBYTES__(ret, f, buffer, 4, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2426
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2427
	if (ret == 4) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2428
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2429
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 4);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2430
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2431
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2432
		value = (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2433
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2434
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2435
		value = (value << 8) | (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2436
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2437
		value = (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2438
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2439
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2440
		value = (value << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2441
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2442
	    if (value <= _MAX_INT) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2443
		RETURN ( __MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2444
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2445
	    RETURN ( __MKULARGEINT(value) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2446
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2447
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2448
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2449
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2450
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2451
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2452
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2453
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2454
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2455
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2456
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2457
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2458
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2459
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2460
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2461
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2462
nextUnsignedShortMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2463
    "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
  2464
     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
  2465
     otherwise least-significant byte comes first.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2466
     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
  2467
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2468
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2469
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2470
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2471
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2472
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2473
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2474
	&& (__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
  2475
    ) {
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2476
	FILEPOINTER f;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2477
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2478
	unsigned int value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2479
	char buffer[2];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2480
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2481
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2482
	__READBYTES__(ret, f, buffer, 2, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2483
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2484
	if (ret == 2) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2485
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2486
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 2);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2487
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2488
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2489
		value = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2490
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2491
		value = ((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2492
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2493
	    RETURN (__MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2494
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2495
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2496
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2497
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2498
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2499
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2500
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2501
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2502
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2503
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2504
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2505
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2506
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2507
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2508
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2509
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2510
nextWord
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2511
    "in text-mode:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2512
	 read the alphaNumeric next word (i.e. up to non letter-or-digit).
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2513
	 return a string containing those characters.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2514
     in binary-mode:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2515
	 read two bytes (msb-first) and return the value as a 16-bit 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2516
	 unsigned Integer (for compatibility with other smalltalks)"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2517
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2518
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2519
	^ self nextUnsignedShortMSB:true
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2520
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2521
    ^ self nextAlphaNumericWord
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2522
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2523
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2524
!ExternalStream methodsFor:'non homogenous writing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2525
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2526
nextPutByte:aByteValue
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2527
    "write a byte.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2528
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2529
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2530
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2531
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2532
    char c;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2533
    OBJ pos, fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2534
    int cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2535
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2536
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2537
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2538
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2539
	&& __isSmallInteger(aByteValue)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2540
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2541
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2542
	c = __intVal(aByteValue);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2543
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2544
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2545
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2546
	} 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2547
	__WRITEBYTE__(cnt, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2548
	if (cnt == 1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2549
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2550
	    if (pos != nil)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2551
		__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2552
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2553
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2554
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2555
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2556
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2557
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2558
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2559
    self writeError.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2560
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2561
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2562
nextPutBytes:count from:anObject startingAt:start
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2563
    "write count bytes from an object starting at index start.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2564
     return the number of bytes written - which could be 0.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2565
     The object must have non-pointer indexed instvars 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2566
     (i.e. be a ByteArray, String, Float- or DoubleArray).     
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2567
     Use with care - non object oriented i/o.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2568
     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
  2569
     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
  2570
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2571
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2572
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2573
    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
  2574
    int objSize, nInstVars, nInstBytes, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2575
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2576
    OBJ oClass, pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2577
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2578
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2579
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2580
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2581
	&& __bothSmallInteger(count, start)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2582
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2583
	oClass = __Class(anObject);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2584
	switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2585
	    case BYTEARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2586
	    case WORDARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2587
	    case LONGARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2588
	    case SWORDARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2589
	    case SLONGARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2590
	    case FLOATARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2591
	    case DOUBLEARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2592
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2593
	    default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2594
		goto bad;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2595
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2596
	len = __intVal(count);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2597
	offs = __intVal(start) - 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2598
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2599
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2600
	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2601
	nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2602
	objSize = __Size(anObject) - nInstBytes;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2603
	if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2604
	    offs += nInstBytes;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2605
	    if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2606
		__WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2607
	    }
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  2608
	    __WRITEBYTES_OBJ__(cnt, f, anObject, offs, len, _buffered); 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2609
	    if (cnt >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2610
		pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2611
		if (pos != nil)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2612
		    __INST(position) = __MKSMALLINT(__intVal(pos) + cnt);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2613
		RETURN ( __MKSMALLINT(cnt) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2614
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2615
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2616
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2617
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2618
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2619
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2620
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2621
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2622
    (mode == #readonly) ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2623
    ^ self primitiveFailed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2624
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2625
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2626
nextPutLong:aNumber MSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2627
    "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
  2628
     true, data is written most-significant byte first; otherwise least
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2629
     first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2630
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2631
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2632
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2633
    int num;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2634
    char bytes[4];
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2635
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2636
    int cnt, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2637
    OBJ fp, pos;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2638
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2639
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2640
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2641
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2642
	&& __isSmallInteger(aNumber)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2643
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2644
	num = __intVal(aNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2645
	if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2646
	    bytes[0] = (num >> 24) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2647
	    bytes[1] = (num >> 16) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2648
	    bytes[2] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2649
	    bytes[3] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2650
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2651
	    bytes[3] = (num >> 24) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2652
	    bytes[2] = (num >> 16) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2653
	    bytes[1] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2654
	    bytes[0] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2655
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2656
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2657
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2658
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2659
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2660
	} 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2661
	__WRITEBYTES__(cnt, f, bytes, 4, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2662
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2663
	if (cnt == 4) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2664
	    if ((pos = __INST(position)) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2665
		__INST(position) = __MKSMALLINT(__intVal(pos) + 4);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2666
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2667
	    RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2668
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2669
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2670
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2671
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2672
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2673
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2674
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2675
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2676
    aNumber isInteger ifTrue:[
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2677
	^ super nextPutLong:aNumber MSB:msbFlag
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2678
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2679
    self argumentMustBeInteger
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2680
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2681
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2682
nextPutShort:aNumber MSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2683
    "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
  2684
     true, data is written most-significant byte first; otherwise least
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2685
     first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2686
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2687
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2688
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2689
    int num;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2690
    char bytes[2];
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2691
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2692
    int cnt, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2693
    OBJ fp, pos;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2694
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2695
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2696
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2697
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2698
	&& __isSmallInteger(aNumber)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2699
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2700
	num = __intVal(aNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2701
	if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2702
	    bytes[0] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2703
	    bytes[1] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2704
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2705
	    bytes[1] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2706
	    bytes[0] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2707
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2708
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2709
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2710
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2711
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2712
	} 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2713
	__WRITEBYTES__(cnt, f, bytes, 2, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2714
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2715
	if (cnt == 2) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2716
	    if ((pos = __INST(position)) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2717
		__INST(position) = __MKSMALLINT(__intVal(pos) + 2);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2718
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2719
	    RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2720
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2721
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2722
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2723
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2724
    lastErrorNumber notNil ifTrue:[^ self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2725
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2726
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2727
    self argumentMustBeInteger
10
claus
parents: 5
diff changeset
  2728
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2729
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2730
!ExternalStream methodsFor:'private'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2731
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2732
clearEOF
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2733
    hitEOF := false
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2734
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2735
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2736
connectTo:aFileDescriptor withMode:openmode
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2737
    "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
  2738
     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
  2739
     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
  2740
     a Stream object. 
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2741
     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
  2742
     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
  2743
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2744
    |retVal|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2745
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2746
    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
  2747
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2748
    FILEPOINTER f;
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2749
    OBJ fp;
2765
a56668774ad7 more alpha64 fixes
Claus Gittinger <cg@exept.de>
parents: 2764
diff changeset
  2750
    FILE *fdopen();
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2751
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2752
    if (__isSmallInteger(aFileDescriptor) 
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2753
     && (__qClass(openmode)== @global(String))) {
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2754
	f = (FILEPOINTER) fdopen(__intVal(aFileDescriptor), (char *)__stringVal(openmode));
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2755
	if (f == NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2756
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2757
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2758
	} else {
2999
b0e55440cf12 eliminate MKOBJ & MKCP (use MKEXTERNALADDRESS & externalAddressVal)
Claus Gittinger <cg@exept.de>
parents: 2986
diff changeset
  2759
	    __INST(filePointer) = fp = __MKEXTERNALADDRESS(f); __STORE(self, fp);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2760
	    __INST(position) = __MKSMALLINT(1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2761
	    retVal = self;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2762
	}
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2763
    }
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2764
%}.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2765
    retVal notNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2766
	buffered := true.       "default is buffered"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2767
	Lobby register:self
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2768
    ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2769
    lastErrorNumber notNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2770
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2771
	 the open failed for some reason ...
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2772
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2773
	^ self openError
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2774
    ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2775
    ^ retVal
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2776
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2777
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2778
open:aPath withMode:mode
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2779
    "low level open; opens the file/device and sets the filePointer instance
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2780
     variable. Careful: this does not care for any other state."
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2781
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2782
    |ok|
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2783
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2784
    ok := false.
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2785
%{
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2786
    FILE *f; 
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2787
    OBJ fp;
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2788
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2789
    if (__isString(aPath)) { 
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2790
        __BEGIN_INTERRUPTABLE__
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2791
        do {
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2792
            f = fopen((char *) __stringVal(aPath), (char *) __stringVal(mode));
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2793
        } while ((f == NULL) && (errno == EINTR));
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2794
        __END_INTERRUPTABLE__
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2795
        if (f == NULL) {
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2796
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2797
        } else {
2999
b0e55440cf12 eliminate MKOBJ & MKCP (use MKEXTERNALADDRESS & externalAddressVal)
Claus Gittinger <cg@exept.de>
parents: 2986
diff changeset
  2798
            __INST(filePointer) = fp = __MKEXTERNALADDRESS((INT)f); __STORE(self, fp);
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2799
            ok = true;
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2800
        }
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2801
    }
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2802
%}.
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2803
    ok ifFalse:[
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2804
        "
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2805
         the open failed for some reason ...
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2806
        "
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2807
        ^ self openError
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2808
    ]. 
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2809
    Lobby register:self. 
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2810
!
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2811
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2812
reOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2813
    "sent after snapin to reopen streams.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2814
     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
  2815
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  2816
    self class name errorPrint. ' [warning]: automatic reOpen not supported - stream closed' errorPrintCR.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2817
    filePointer := nil.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2818
    Lobby unregister:self.
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  2819
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  2820
    "Modified: 10.1.1997 / 17:50:44 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2821
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2822
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2823
setLastError:aNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2824
    lastErrorNumber := aNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2825
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2826
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2827
!ExternalStream methodsFor:'queries'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2828
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2829
isBinary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2830
    "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
  2831
     The default when created is false."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2832
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2833
    ^ binary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2834
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2835
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2836
isExternalStream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2837
    "return true, if the receiver is some kind of externalStream;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2838
     true is returned here - the method redefined from Object."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2839
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2840
    ^ true
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2841
!
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
isReadable 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2844
    "return true, if this stream can be read from"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2845
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2846
    ^ (mode ~~ #writeonly)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2847
!
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
isWritable 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2850
    "return true, if this stream can be written to"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2851
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2852
    ^ (mode ~~ #readonly)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2853
! !
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
!ExternalStream methodsFor:'reading'!
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
next
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2858
    "return the next element; advance read position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2859
     In binary mode, an integer is returned, otherwise a character.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2860
     If there are no more elements, nil is returned."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2861
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2862
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2863
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2864
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2865
    OBJ pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2866
    unsigned char ch;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2867
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2868
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2869
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2870
	&& (__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
  2871
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2872
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2873
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2874
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2875
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2876
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2877
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2878
	__READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2879
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2880
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2881
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2882
	    if (__isSmallInteger(pos)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2883
		__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2884
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2885
		__INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2886
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2887
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2888
		RETURN ( __MKSMALLINT(ch) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2889
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2890
	    RETURN ( __MKCHARACTER(ch) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2891
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2892
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2893
	__INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2894
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2895
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2896
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2897
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2898
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2899
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2900
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2901
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2902
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2903
    filePointer isNil ifTrue:[^ self errorNotOpen].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2904
    ^ self errorWriteOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2905
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2906
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2907
next:count
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2908
    "return the next count elements of the stream as a collection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2909
     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
  2910
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2911
    |coll nRead|
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2912
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2913
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2914
	coll := ByteArray uninitializedNew:count
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2915
    ] ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2916
	coll := String new:count
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2917
    ].
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2918
    nRead := self nextBytes:count into:coll startingAt:1.
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2919
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2920
    "/ for readStream protocol compatibility, 
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2921
    "/ we must raise an exception here.
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2922
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2923
    nRead < count ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2924
	^ self pastEnd
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2925
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2926
    ^ coll
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2927
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2928
    "Modified: 11.1.1997 / 17:44:17 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2929
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2930
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2931
peek
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2932
    "return the element to be read next without advancing read position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2933
     In binary mode, an integer is returned, otherwise a character.
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2934
     If there are no more elements, nil is returned."
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2935
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2936
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2937
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2938
    unsigned char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2939
    int ret, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2940
    OBJ fp;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2941
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2942
    if (__INST(readAhead) != nil) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2943
        RETURN (__INST(readAhead));
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2944
    }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2945
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2946
    __INST(lastErrorNumber) = nil;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2947
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2948
    if (((fp = __INST(filePointer)) != nil)
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2949
        && (__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
  2950
    ) {
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2951
        f = __FILEVal(fp);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2952
        _buffered = (__INST(buffered) == true);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2953
        if (_buffered) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2954
            __READING__(f)
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2955
        }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2956
        __READBYTE__(ret, f, &c, _buffered);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2957
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2958
        if (ret > 0) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2959
            __UNGETC__(c, f, _buffered);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2960
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2961
            if (__INST(binary) == true) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2962
                RETURN ( __MKSMALLINT(c) );
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2963
            }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2964
            RETURN ( __MKCHARACTER(c) );
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2965
        }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2966
        if (ret < 0) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2967
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2968
        } else /* ret == 0 */ {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2969
            __INST(hitEOF) = true;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  2970
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2971
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2972
%}.
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2973
    hitEOF ifTrue:[^ self pastEnd]. 
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2974
    lastErrorNumber notNil ifTrue:[^ self readError].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2975
    filePointer isNil ifTrue:[^ self errorNotOpen].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2976
    ^ self errorWriteOnly
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2977
!
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2978
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2979
upToEnd
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2980
    "return a collection of the elements up-to the end.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2981
     Return nil if the stream-end is reached before."
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2982
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2983
    |answerStream ch|
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2984
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2985
    answerStream := WriteStream on:(self contentsSpecies new).
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2986
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2987
	ch := self next.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2988
	ch notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2989
	    answerStream nextPut:ch
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2990
	]
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2991
    ].
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2992
    ^ answerStream contents
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2993
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2994
    "Created: 25.4.1996 / 14:40:31 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2995
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2996
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2997
!ExternalStream methodsFor:'reimplemented for speed'!
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2998
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2999
nextAlphaNumericWord
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3000
    "read the next word (i.e. up to non letter-or-digit) after first
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3001
     skipping any whiteSpace.
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3002
     Return a string containing those characters.
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3003
     There is a limit of 1023 characters in the word - if longer,
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3004
     it is truncated."
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3005
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3006
%{  /* STACK: 2000 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3007
    FILEPOINTER f;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3008
    int len;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3009
    char buffer[1024];
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3010
    unsigned char ch;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3011
    int cnt = 0;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3012
    int ret, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3013
    OBJ fp;
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3014
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3015
    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
  3016
     && (__INST(mode) != @symbol(writeonly))
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3017
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3018
	f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3019
	_buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3020
	if (_buffered) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3021
	    __READING__(f)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3022
	}
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3023
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3024
	/*
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3025
	 * skip whiteSpace first ...
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3026
	 */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3027
	do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3028
	    __READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3029
	    if (ret > 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3030
		cnt++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3031
	    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3032
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3033
	} while (
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3034
#ifndef NON_ASCII
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3035
		 (ch < ' ') ||
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3036
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3037
		 (ch == ' ' ) || (ch == '\t') || (ch == '\r')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3038
	      || (ch == '\n') || (ch == 0x0b));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3039
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3040
	len = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3041
	while (ret > 0 && 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3042
	       (((ch >= 'a') && (ch <= 'z')) ||
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3043
		((ch >= 'A') && (ch <= 'Z')) ||
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3044
		((ch >= '0') && (ch <= '9')))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3045
	) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3046
	    buffer[len++] = ch;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3047
	    if (len >= (sizeof(buffer)-1)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3048
		/* emergency */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3049
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3050
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3051
	    __READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3052
	    if (ret > 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3053
		cnt++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3054
	    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3055
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3056
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3057
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3058
	if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3059
	    if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3060
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3061
		goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3062
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3063
	    else if (ret == 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3064
		__INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3065
	} else {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3066
	    __UNGETC__(ch, f, _buffered);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3067
	    cnt--;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3068
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3069
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3070
	if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3071
	    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + cnt);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3072
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3073
	if (len != 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3074
	    buffer[len] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3075
	    RETURN ( __MKSTRING_L(buffer, len) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3076
	}
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3077
    }
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3078
err: ;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3079
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3080
    hitEOF ifTrue:[^ self pastEnd].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3081
    lastErrorNumber notNil ifTrue:[^ self readError].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3082
    filePointer isNil ifTrue:[^ self errorNotOpen].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3083
    ^ self errorWriteOnly
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3084
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3085
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3086
nextChunk
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3087
    "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
  3088
     exclamation mark. Within the chunk, exclamation marks have to be doubled -
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3089
     except within primitive code (this exception was added to make it easier
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3090
     to edit primitive code with external editors). This means, that other
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3091
     Smalltalks cannot always read chunks containing primitive code - but that
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3092
     doesnt really matter, since C-primitives are an ST/X feature anyway.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3093
     Reimplemented here for more speed."
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3094
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3095
    |retVal outOfMemory buffer|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3096
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3097
    filePointer isNil ifTrue:[^ self errorNotOpen].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3098
    binary ifTrue:[^ self errorBinary].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3099
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3100
2854
3c8bf66e4e7d give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents: 2766
diff changeset
  3101
%{  /* STACK: 12000 */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3102
    /*
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3103
     * the main trick (and a bit of complication) here
2874
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3104
     * is to read the first 8k into a stack-buffer.
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3105
     * 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
  3106
     * 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
  3107
     */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3108
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3109
    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
  3110
    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
  3111
    int ret;
1823
51ffb7231437 type casts
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  3112
    unsigned char *bufferPtr = (unsigned char *)0;
2874
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3113
    unsigned char fastBuffer[8000];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3114
    REGISTER int index;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3115
    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
  3116
    int atBeginOfLine = 1, inPrimitive = 0;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3117
    int haveCR = 0, haveNL = 0;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3118
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3119
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3120
    f = __FILEVal(__INST(filePointer));
668
73165201a9da nextChunk: %{ is only recognized if at begin-of-line
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  3121
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3122
    _buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3123
    if (_buffered) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3124
        __READING__(f)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3125
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3126
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3127
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3128
     * skip spaces
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3129
     */
673
2c3a4a536cd1 oops - handling of exclas within primitives was wrong
Claus Gittinger <cg@exept.de>
parents: 671
diff changeset
  3130
    c = '\n';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3131
    while (! done) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3132
        lastC = c;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3133
        __READBYTE__(ret, f, &c, _buffered);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3134
        if (ret <= 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3135
            goto err;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3136
        }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3137
        nread++;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3138
        atBeginOfLine = 0;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3139
        switch (c) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3140
            case '\n':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3141
            case ' ':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3142
            case '\t':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3143
            case '\r':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3144
            case '\b':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3145
            case '\014':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3146
                break;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3147
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3148
            default:
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3149
                atBeginOfLine = (lastC == '\n');
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3150
                done = 1;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3151
                break;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3152
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3153
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3154
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3155
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3156
     * read chunk into a buffer
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3157
     */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3158
    bufferPtr = fastBuffer; fastFlag = 1;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3159
    currSize = sizeof(fastBuffer);
362
claus
parents: 360
diff changeset
  3160
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3161
    index = 0;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3162
    for (;;) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3163
        __READBYTE__(ret, f, &peekC, _buffered);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3164
        if ((c == '%') && atBeginOfLine && ret > 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3165
            if (peekC == '{') {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3166
                inPrimitive = 1;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3167
            } else if (peekC == '}') {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3168
                inPrimitive = 0;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3169
            }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3170
        } else if (c == '!' && !inPrimitive) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3171
            if (ret > 0 && peekC == '!') {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3172
                /*
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3173
                 * convert double-! to a single !
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3174
                 */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3175
                __READBYTE__(ret, f, &peekC, _buffered);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3176
                if (ret > 0)
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3177
                    nread++;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3178
            } else {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3179
                /*
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3180
                 * End of chunk, push back lookahead character
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3181
                 * and leave loop.
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3182
                 */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3183
                if (ret > 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3184
                    __UNGETC__(peekC, f, _buffered);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3185
                } else
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3186
                    ret = 1;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3187
                break; 
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3188
            }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3189
        }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3190
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3191
        /* 
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3192
         * do we have to resize the buffer ? 
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3193
         */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3194
        if ((index+2) >= currSize) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3195
            OBJ newBuffer;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3196
            unsigned char *nbp;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3197
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3198
            newBuffer = __MKEMPTYSTRING(currSize * 2);
2874
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3199
            if (!fastFlag) {
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3200
                /*
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3201
                 * refetch - buffer could be moved by GC
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3202
                 */
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3203
                bufferPtr = __stringVal(buffer);
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3204
            }
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3205
            if (newBuffer == nil) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3206
                /*
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3207
                 * mhmh - chunk seems to be very big ....
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3208
                 */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3209
                outOfMemory = true;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3210
                goto err;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3211
            }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3212
            nbp = __stringVal(newBuffer);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3213
            bcopy(bufferPtr, nbp, index);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3214
            bufferPtr = nbp;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3215
            bufferPtr[index] = '\0';
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3216
            buffer = newBuffer;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3217
            fastFlag = 0;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3218
            currSize = currSize * 2;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3219
        }
2854
3c8bf66e4e7d give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents: 2766
diff changeset
  3220
2874
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3221
        if (!fastFlag) {
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3222
            /*
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3223
             * old buffer may have moved (interrupt while reading)
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3224
             * - refetch pointer
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3225
             */
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3226
            bufferPtr = __stringVal(buffer);
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3227
        }
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3228
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3229
        /*
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3230
         * filter out cr-nl; make it nl
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3231
         */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3232
        if (c == '\n') {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3233
            haveNL = 1;
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3234
            if (index > 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3235
                if (bufferPtr[index-1] == '\r') {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3236
                    index--;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3237
                }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3238
            }
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3239
        } else {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3240
            if (c == '\r') {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3241
                haveCR = 1;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3242
            }
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3243
        }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3244
        bufferPtr[index++] = c;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3245
        if (ret <= 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3246
            if (ret == 0)
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3247
                break;          /* End of chunk reached */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3248
            goto err;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3249
        }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3250
        nread++;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3251
        atBeginOfLine = (c == '\n');
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3252
        c = peekC;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3253
    }
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3254
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3255
    /*
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3256
     * care for CR-limited files.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3257
     * Replace CR's by NL's
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3258
     */
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3259
    if (!haveNL && haveCR) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3260
        int i;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3261
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3262
        for (i=index-1; i>=0; i--) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3263
            if (bufferPtr[i] == '\r') {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3264
                bufferPtr[i] = '\n';
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3265
            }
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3266
        }
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3267
    }
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3268
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3269
    /*
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3270
     * 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
  3271
     * 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
  3272
     * 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
  3273
     * fast (C) buffer or from real (ST) buffer.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3274
     */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3275
    if (fastFlag) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3276
        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
  3277
    } else {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3278
        retVal = __MKSTRING_ST_L(buffer, index);
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3279
    }
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3280
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  3281
err: ;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3282
    if (ret <= 0) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3283
        if (ret == 0)
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3284
            __INST(hitEOF) = true;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3285
        else /* ret < 0 */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3286
            __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
  3287
    }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3288
    if (__INST(position) != nil) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3289
        __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
  3290
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3291
%}.
370
claus
parents: 369
diff changeset
  3292
    retVal isNil ifTrue:[
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3293
        "/
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3294
        "/ arrive here with retVal==nil either on error or premature EOF
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3295
        "/ or if running out of malloc-memory
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3296
        "/
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3297
        hitEOF ifTrue:[^ self pastEnd].
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3298
        lastErrorNumber notNil ifTrue:[^ self readError].
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3299
        outOfMemory == true ifTrue:[
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3300
            "
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3301
             buffer memory allocation failed.
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3302
             When we arrive here, there was no memory available for the
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3303
             chunk. (seems to be too big of a chunk ...)
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3304
             Bad luck - you should increase the ulimit and/or swap space on your machine.
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3305
            "
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3306
            ^ ObjectMemory allocationFailureSignal raise.
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3307
        ]
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3308
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3309
    ^ retVal
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3310
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3311
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3312
nextMatchFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3313
    "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
  3314
     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
  3315
     the element after anObject.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3316
     Only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3317
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3318
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3319
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3320
    int ret, peekValue;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3321
    char c;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3322
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3323
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3324
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3325
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3326
	&& (__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
  3327
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3328
	if ((__INST(binary) == true) && __isSmallInteger(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3329
	    peekValue = __intVal(anObject) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3330
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3331
	    if ((__INST(binary) != true) && __isCharacter(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3332
		peekValue = __intVal(_characterVal(anObject)) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3333
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3334
		peekValue = -1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3335
	    }   
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3336
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3337
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3338
	if (peekValue >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3339
	    int _buffered;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3340
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3341
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3342
	    f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3343
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3344
	    if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3345
		__READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3346
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3347
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3348
	    for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3349
		__READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3350
		if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3351
		    if (ret < 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3352
			__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3353
		    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3354
			__INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3355
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3356
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3357
		if (c == peekValue) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3358
		    RETURN (anObject);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3359
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3360
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3361
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3362
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3363
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3364
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3365
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3366
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3367
    ^ super nextMatchFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3368
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3369
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3370
peekFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3371
    "return true and move past next element, if next == something.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3372
     Otherwise, stay and return false. False is also returned
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3373
     when EOF is encountered.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3374
     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
  3375
     text mode; only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3376
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3377
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3378
    FILEPOINTER f;
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3379
    unsigned char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3380
    int ret, peekValue, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3381
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3382
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3383
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3384
    if (((fp = __INST(filePointer)) != nil)
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3385
        && (__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
  3386
    ) {
3029
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3387
        if (__INST(binary) == true) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3388
            if (__isSmallInteger(anObject)) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3389
                peekValue = __intVal(anObject) & 0xFF;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3390
            } else {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3391
                goto bad;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3392
            }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3393
        } else {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3394
            if (__isCharacter(anObject)) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3395
                peekValue = __intVal(_characterVal(anObject)) & 0xFF;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3396
            } else {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3397
                goto bad;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3398
            }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3399
        }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3400
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3401
        f = __FILEVal(fp);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3402
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3403
        _buffered = (__INST(buffered) == true);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3404
        if (_buffered) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3405
            __READING__(f)
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3406
        }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3407
        __READBYTE__(ret, f, &c, _buffered);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3408
        if (ret > 0) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3409
            if (c == peekValue) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3410
                OBJ pos;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3411
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3412
                if ((pos = __INST(position)) != nil) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3413
                    __INST(position) = __MKSMALLINT(__intVal(pos) + 1);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3414
                }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3415
                RETURN (true);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3416
            }
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3417
            __UNGETC__(c, f, _buffered);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3418
            RETURN (false);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3419
        } 
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3420
        if (ret < 0) {
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3421
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3422
        } else /* ret == 0 */
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3423
            __INST(hitEOF) = true;
aa14768e0e6a larger lineBuffer in #nextLine
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3424
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3425
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3426
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3427
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3428
    hitEOF ifTrue:[self pastEnd. ^ false].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3429
    lastErrorNumber notNil ifTrue:[^ self readError].
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
    ^ super peekFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3432
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3433
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3434
skipLine
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3435
    "read the next line (characters up to newline) skip only;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3436
     return nil if EOF reached, self otherwise. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3437
     Not allowed in binary mode."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3438
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3439
%{  /* STACK:2000 */
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3440
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3441
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3442
    OBJ fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3443
    int ret, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3444
    char c;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3445
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3446
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3447
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3448
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3449
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3450
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3451
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3452
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3453
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3454
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3455
	for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3456
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3457
	    if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3458
		if (c == '\n')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3459
		    RETURN(self) 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3460
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3461
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3462
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3463
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3464
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3465
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3466
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3467
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3468
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3469
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3470
    hitEOF ifTrue:[^ self pastEnd].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3471
    lastErrorNumber notNil ifTrue:[self readError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3472
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3473
    binary ifTrue:[self errorBinary. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3474
    self errorWriteOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3475
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3476
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3477
skipSeparators
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3478
    "skip all whitespace; next will return next non-white-space character
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3479
     or nil if endOfFile reached. Not allowed in binary mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3480
     - reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3481
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3482
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3483
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3484
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3485
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3486
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3487
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3488
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3489
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3490
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3491
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3492
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3493
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3494
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3495
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3496
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3497
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3498
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3499
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3500
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3501
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3502
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3503
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3504
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3505
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3506
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3507
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3508
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3509
	    switch (c) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3510
		case ' ':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3511
		case '\t':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3512
		case '\n':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3513
		case '\r':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3514
		case '\b':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3515
		case '\f':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3516
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3517
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3518
		default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3519
		    __UNGETC__(c, f, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3520
		    RETURN ( __MKCHARACTER(c & 0xFF) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3521
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3522
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3523
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3524
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3525
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3526
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3527
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3528
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3529
    ^ self errorBinary.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3530
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3531
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3532
skipSeparatorsExceptCR
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3533
    "skip all whitespace but no newlines;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3534
     next will return next non-white-space character
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3535
     or nil if endOfFile reached. Not allowed in binary mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3536
     - reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3537
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3538
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3539
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3540
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3541
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3542
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3543
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3544
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3545
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3546
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3547
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3548
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3549
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3550
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3551
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3552
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3553
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3554
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3555
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3556
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3557
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3558
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3559
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3560
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3561
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3562
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3563
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3564
	    switch (c) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3565
		case ' ':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3566
		case '\t':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3567
		case '\b':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3568
		case '\f':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3569
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3570
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3571
		default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3572
		    __UNGETC__(c, f, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3573
		    RETURN ( __MKCHARACTER(c & 0xFF) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3574
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3575
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3576
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3577
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3578
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3579
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3580
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3581
    (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
  3582
    ^ self errorBinary.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3583
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3584
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3585
skipThrough:aCharacter
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3586
    "skip all characters up-to and including aCharacter. Return the receiver if
671
53de87163ad5 spelling
Claus Gittinger <cg@exept.de>
parents: 668
diff changeset
  3587
     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
  3588
     The next read operation will return the character after aCharacter.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3589
     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
  3590
     Only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3591
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3592
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3593
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3594
    REGISTER int cSearch;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3595
    unsigned char c;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3596
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3597
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3598
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3599
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3600
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3601
	&& (__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
  3602
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3603
	if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3604
	    /* searched for object must be a smallInteger */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3605
	    if (! __isSmallInteger(aCharacter)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3606
	    cSearch = __intVal(aCharacter);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3607
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3608
	    /* searched for object must be a character */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3609
	    if (! __isCharacter(aCharacter)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3610
	    cSearch = __intVal(_characterVal(aCharacter));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3611
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3612
	/* Q: should we just say: "not found" ? */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3613
	if ((cSearch < 0) || (cSearch > 255)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3614
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3615
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3616
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3617
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3618
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3619
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3620
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3621
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3622
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3623
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3624
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3625
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3626
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3627
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3628
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3629
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3630
	    if (c == cSearch) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3631
		RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3632
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3633
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3634
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3635
badArgument: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3636
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3637
    hitEOF ifTrue:[^ self pastEnd].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3638
    lastErrorNumber notNil ifTrue:[self readError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3639
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3640
    (mode == #writeonly) ifTrue:[self errorWriteOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3641
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3642
     argument must be integer/character in binary mode, 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3643
     character in text mode
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3644
    "
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3645
    self error:'invalid argument'.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3646
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3647
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3648
     |s|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3649
     s := 'Makefile' asFilename readStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3650
     s skipThrough:$=.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3651
     s next:10
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3652
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3653
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3654
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3655
skipToAll:aString
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3656
    "skip for the sequence given by the argument, aCollection;
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3657
     return nil if not found, self otherwise. 
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3658
     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
  3659
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3660
    |oldPos|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3661
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3662
    oldPos := self position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3663
    (self skipThroughAll:aString) isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3664
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3665
	 restore position
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3666
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3667
	self position:oldPos.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3668
	^ nil
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3669
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3670
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3671
     position before match-string
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3672
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3673
    self position:(self position - aString size).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3674
    ^ self
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3675
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3676
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3677
     |s|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3678
     s := 'Makefile' asFilename readStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3679
     s skipToAll:'are'.
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3680
     s next:10 
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3681
    "
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3682
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3683
    "Modified: 26.6.1996 / 09:22:05 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3684
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3685
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3686
!ExternalStream methodsFor:'testing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3687
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3688
atEnd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3689
    "return true, if position is at end"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3690
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3691
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3692
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3693
    OBJ fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3694
    char c;
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3695
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3696
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3697
    if (__INST(hitEOF) == true) {
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3698
        RETURN (true);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3699
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3700
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3701
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3702
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3703
    if ((fp = __INST(filePointer)) != nil) {
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3704
        f = __FILEVal(fp);
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3705
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3706
        if (_buffered = (__INST(buffered) == true)) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3707
            __READING__(f);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3708
        } else {
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3709
            if (__INST(readAhead) != nil) {
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3710
                RETURN (false);
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3711
            }
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3712
        }
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3713
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3714
        /*
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3715
         * read ahead ...
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3716
         */
2875
54c89acc73ce #atEnd must read interruptable
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
  3717
        do {
54c89acc73ce #atEnd must read interruptable
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
  3718
            __BEGIN_INTERRUPTABLE__
54c89acc73ce #atEnd must read interruptable
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
  3719
            __READBYTE__(ret, f, &c, _buffered);
54c89acc73ce #atEnd must read interruptable
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
  3720
            __END_INTERRUPTABLE__
54c89acc73ce #atEnd must read interruptable
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
  3721
        } while ((ret < 0) && (errno == EINTR));
54c89acc73ce #atEnd must read interruptable
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
  3722
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3723
        if (ret > 0) {
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3724
            __UNGETC__(c&0xff, f, _buffered);
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3725
            RETURN (false);
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3726
        }
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3727
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3728
        if (ret == 0) { 
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3729
            __INST(hitEOF) = true;
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3730
            RETURN (true);
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3731
        }
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3732
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3733
        /* ret < 0 */
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3734
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3735
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3736
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3737
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3738
    ^ self errorNotOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3739
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3740
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3741
canReadWithoutBlocking
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3742
    "return true, if any data is available for reading (i.e.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3743
     a read operation will not block the smalltalk process), false otherwise."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3744
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3745
    |fd|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3746
2986
c6957cf6128f Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents: 2963
diff changeset
  3747
    readAhead notNil ifTrue:[^ true].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3748
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3749
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3750
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3751
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3752
    ^ OperatingSystem readCheck:fd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3753
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3754
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3755
     |pipe|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3756
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3757
     pipe := PipeStream readingFrom:'(sleep 10; echo hello)'.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3758
     pipe canReadWithoutBlocking ifTrue:[
2986
c6957cf6128f Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents: 2963
diff changeset
  3759
         Transcript showCR:'data available'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3760
     ] ifFalse:[
2986
c6957cf6128f Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents: 2963
diff changeset
  3761
         Transcript showCR:'no data available'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3762
     ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3763
     pipe close
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3764
    "
2986
c6957cf6128f Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents: 2963
diff changeset
  3765
c6957cf6128f Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents: 2963
diff changeset
  3766
    "Modified: 25.9.1997 / 13:08:45 / stefan"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3767
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3768
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3769
canWriteWithoutBlocking
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3770
    "return true, if data can be written into the stream 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3771
     (i.e. a write operation will not block the smalltalk process)."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3772
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3773
    |fd|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3774
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3775
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3776
    mode == #readonly ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3777
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3778
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3779
    ^ OperatingSystem writeCheck:fd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3780
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3781
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3782
!ExternalStream methodsFor:'waiting for I/O'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3783
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3784
readWait
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3785
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3786
     becomes ready for reading. If data is already available,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3787
     return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3788
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3789
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3790
    self readWaitWithTimeoutMs:nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3791
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3792
3016
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  3793
readWaitTimeoutMs:timeout
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  3794
    "ST-80 compatibility"
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  3795
    ^ self readWaitWithTimeoutMs:timeout 
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  3796
!
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  3797
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3798
readWaitWithTimeout:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3799
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3800
     becomes ready for reading or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3801
     If data is already available, return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3802
     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
  3803
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3804
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3805
    ^ self readWaitWithTimeoutMs:timeout * 1000
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3806
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3807
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3808
readWaitWithTimeoutMs:timeout 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3809
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3810
     becomes ready for reading or a timeout (in milliseconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3811
     If data is already available, return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3812
     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
  3813
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3814
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3815
    |fd inputSema hasData wasBlocked|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3816
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3817
    readAhead notNil ifTrue:[^ false].
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3818
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3819
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3820
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3821
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3822
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3823
    (OperatingSystem readCheck:fd) ifTrue:[^ false].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3824
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3825
    wasBlocked := OperatingSystem blockInterrupts.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3826
    hasData := OperatingSystem readCheck:fd.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3827
    hasData ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3828
	inputSema := Semaphore new name:'readWait'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3829
	[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3830
	    timeout notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3831
		Processor signal:inputSema afterMilliseconds:timeout 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3832
	    ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3833
	    Processor signal:inputSema onInput:fd.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3834
	    Processor activeProcess state:#ioWait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3835
	    inputSema wait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3836
	    Processor disableSemaphore:inputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3837
	    hasData := OperatingSystem readCheck:fd
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3838
	] valueOnUnwindDo:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3839
	    Processor disableSemaphore:inputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3840
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3841
	]
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3842
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3843
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3844
    ^ hasData not
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3845
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3846
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3847
writeWait
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3848
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3849
     becomes ready for writing.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3850
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3851
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3852
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3853
    self writeWaitWithTimeoutMs:nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3854
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3855
3016
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  3856
writeWaitTimeoutMs:timeout
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  3857
    "ST-80 compatibility"
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  3858
    ^ self writeWaitWithTimeoutMs:timeout 
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  3859
!
42466b291fae more ST80 compatibility
ca
parents: 2999
diff changeset
  3860
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3861
writeWaitWithTimeout:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3862
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3863
     becomes ready for writing or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3864
     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
  3865
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3866
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3867
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3868
    ^ self writeWaitWithTimeoutMs:timeout * 1000
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3869
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3870
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3871
writeWaitWithTimeoutMs:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3872
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3873
     becomes ready for writing or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3874
     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
  3875
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3876
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3877
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3878
    |fd outputSema canWrite wasBlocked|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3879
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3880
    filePointer isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3881
	^ self errorNotOpen
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3882
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3883
    mode == #readonly ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3884
	^ self errorReadOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3885
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3886
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3887
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3888
    (OperatingSystem writeCheck:fd) ifTrue:[^ false].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3889
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3890
    wasBlocked := OperatingSystem blockInterrupts.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3891
    canWrite := OperatingSystem writeCheck:fd.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3892
    canWrite ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3893
	outputSema := Semaphore new name:'writeWait'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3894
	[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3895
	    timeout notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3896
		Processor signal:outputSema afterMilliseconds:timeout
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3897
	    ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3898
	    Processor signal:outputSema onOutput:fd.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3899
	    Processor activeProcess state:#ioWait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3900
	    outputSema wait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3901
	    Processor disableSemaphore:outputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3902
	    canWrite := OperatingSystem writeCheck:fd
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3903
	] valueOnUnwindDo:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3904
	    Processor disableSemaphore:outputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3905
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3906
	]
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3907
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3908
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3909
    ^ canWrite not
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3910
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3911
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3912
!ExternalStream methodsFor:'writing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3913
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3914
cr
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3915
    "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
  3916
     reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3917
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3918
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3919
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3920
    int len, cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3921
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3922
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3923
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3924
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3925
    if (((fp = __INST(filePointer)) != nil)
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3926
	&& (__INST(mode) != @symbol(readonly))
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3927
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3928
    ) {
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3929
	f = __FILEVal(fp);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3930
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3931
	if (_buffered = (__INST(buffered) == true)) { 
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3932
	    __WRITING__(f)
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3933
	}
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3934
	{
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3935
	    OBJ mode = __INST(eolMode);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3936
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3937
	    if (mode == @symbol(cr)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3938
	        cp = "\r"; len = 1;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3939
	    } else if (mode == @symbol(crlf)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3940
	        cp = "\r\n"; len = 2;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3941
	    } else {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3942
	        cp = "\n"; len = 1;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3943
	    }
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3944
	}
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3945
	__WRITEBYTES__(cnt, f, cp, len, _buffered);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3946
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3947
	if (cnt == len) {
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3948
	    if (__INST(position) != nil) {
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3949
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + len);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3950
	    }
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3951
	    RETURN ( self );
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3952
	}
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3953
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3954
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3955
%}.
2326
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3956
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3957
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3958
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3959
    self errorBinary
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3960
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3961
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3962
flush
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3963
    "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
  3964
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3965
%{
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3966
    OBJ fp;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3967
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3968
    __INST(lastErrorNumber) = nil;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3969
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3970
	if (__INST(mode) != @symbol(readonly)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3971
	    if (__INST(buffered) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3972
		__BEGIN_INTERRUPTABLE__
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3973
		FFLUSH( __FILEVal(fp) );
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3974
		__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3975
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3976
	}
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3977
    }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3978
%}
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3979
!
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3980
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3981
nextPut:aCharacter
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3982
    "write the argument, aCharacter - return nil if failed, self if ok.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3983
     Only single-byte characters are currently supported"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3984
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3985
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3986
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3987
    char c;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3988
    int cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3989
    OBJ pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3990
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3991
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3992
    if (((fp = __INST(filePointer)) != nil) 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3993
	&& (__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
  3994
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3995
	if (__INST(binary) != true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3996
	    if (__isCharacter(aCharacter)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3997
		c = __intVal(__characterVal(aCharacter)) & 0xFF;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3998
    doWrite:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3999
		f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4000
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4001
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4002
		if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4003
		    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4004
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4005
		__WRITEBYTE__(cnt, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4006
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4007
		if (cnt == 1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4008
		    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4009
		    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4010
			__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4011
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4012
		    RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4013
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4014
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4015
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4016
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4017
	    if (__isSmallInteger(aCharacter)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4018
		c = __intVal(aCharacter);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4019
		goto doWrite;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4020
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4021
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4022
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4023
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4024
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4025
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4026
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4027
    binary ifFalse:[self argumentMustBeCharacter. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4028
    self argumentMustBeInteger.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4029
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4030
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4031
nextPutAll:aCollection
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4032
    "write all elements of the argument, aCollection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4033
     Reimplemented for speed when writing strings or byteArrays.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4034
     For others, falls back to general method in superclass."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4035
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  4036
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  4037
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4038
    int len, cnt;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4039
    OBJ pos, fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4040
    int _buffered;
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4041
    int o_offs;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4042
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4043
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4044
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4045
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4046
	&& (__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
  4047
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4048
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4049
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4050
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4051
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4052
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4053
	if (__isString(aCollection) || __isSymbol(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4054
	    len = __stringSize(aCollection);
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4055
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4056
	    __WRITEBYTES__(cnt, f, __stringVal(aCollection), len, _buffered);
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4057
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4058
	    o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4059
	    __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4060
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4061
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4062
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4063
		int offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4064
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4065
		if (__isByteArray(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4066
		    offs = 0;
3221
21085ae8e1be eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents: 3200
diff changeset
  4067
		    len = __byteArraySize(aCollection);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4068
		} else if (__isBytes(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4069
		    offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
3221
21085ae8e1be eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents: 3200
diff changeset
  4070
		    len = __byteArraySize(aCollection) - offs;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4071
		} else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4072
		    goto out;
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4073
#ifdef BUGGY
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4074
		__WRITEBYTES__(cnt, f, __ByteArrayInstPtr(aCollection)->ba_element+offs, len, _buffered);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4075
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4076
		o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element) - (char *)__InstPtr(aCollection);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4077
		o_offs += offs;
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4078
		__WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs, len, _buffered);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4079
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4080
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4081
		goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4082
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4083
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4084
	if (cnt == len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4085
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4086
	    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4087
		__INST(position) = __MKSMALLINT(__intVal(pos) + len);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4088
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4089
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4090
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4091
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4092
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  4093
out: ;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4094
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4095
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4096
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4097
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4098
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4099
    ^ super nextPutAll:aCollection
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4100
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4101
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4102
nextPutAll:aCollection startingAt:start to:stop
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4103
    "write a range of elements of the argument, aCollection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4104
     Reimplemented for speed when writing strings or byteArrays.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4105
     For others, falls back to general method in superclass."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4106
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  4107
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  4108
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4109
    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
  4110
    OBJ fp, pos;
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4111
    int o_offs;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4112
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4113
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4114
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4115
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4116
	&& __bothSmallInteger(start, stop)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4117
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4118
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4119
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4120
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4121
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4122
	iStart = __intVal(start);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4123
	iStop = __intVal(stop);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4124
	if ((iStart < 1) || (iStop < iStart)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4125
	    RETURN(self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4126
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4127
	if (__isString(aCollection) || __isSymbol(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4128
	    len = __stringSize(aCollection);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4129
	    if (iStop > len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4130
		RETURN(self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4131
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4132
	    if (iStop > len)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4133
		iStop = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4134
	    len = iStop - iStart + 1;
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4135
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4136
	    __WRITEBYTES__(cnt, f, __stringVal(aCollection)+iStart-1, len, _buffered);
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4137
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4138
	    o_offs = (char *)__stringVal(aCollection)-(char *)__InstPtr(aCollection);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4139
	    __WRITEBYTES_OBJ__(cnt, f, aCollection, o_offs+iStart-1, len, _buffered);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4140
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4141
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4142
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4143
		int offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4144
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4145
		if (__isByteArray(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4146
		    offs = 0;
3221
21085ae8e1be eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents: 3200
diff changeset
  4147
		    len = __byteArraySize(aCollection);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4148
		} else if (__isBytes(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4149
		    offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
3221
21085ae8e1be eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents: 3200
diff changeset
  4150
		    len = __byteArraySize(aCollection) - offs;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4151
		} else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4152
		    goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4153
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4154
		if (iStop > len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4155
		    RETURN(self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4156
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4157
		if (iStop > len)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4158
		    iStop = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4159
		len = iStop - iStart + 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4160
		offs += iStart - 1;
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4161
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4162
		__WRITEBYTES__(cnt, f,  __ByteArrayInstPtr(aCollection)->ba_element+offs, len, _buffered);
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4163
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4164
		o_offs = (char *)(__ByteArrayInstPtr(aCollection)->ba_element)-(char *)__InstPtr(aCollection);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4165
		__WRITEBYTES_OBJ__(cnt, f,  aCollection, o_offs+offs, len, _buffered);
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4166
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4167
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4168
		goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4169
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4170
	if (cnt == len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4171
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4172
	    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4173
		__INST(position) = __MKSMALLINT(__intVal(pos) + len);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4174
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4175
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4176
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4177
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4178
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  4179
out: ;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4180
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4181
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4182
    ^ super nextPutAll:aCollection startingAt:start to:stop
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4183
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4184
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  4185
!ExternalStream class methodsFor:'documentation'!
730
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  4186
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  4187
version
3221
21085ae8e1be eliminated some single-underscore macro refs (stringSize, arraySize ...)
Claus Gittinger <cg@exept.de>
parents: 3200
diff changeset
  4188
    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.154 1998-01-25 14:12:35 cg Exp $'
730
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  4189
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4190
ExternalStream initialize!