ExternalStream.st
author Stefan Vogel <sv@exept.de>
Tue, 19 Aug 1997 11:16:52 +0200
changeset 2861 c098e5766682
parent 2854 3c8bf66e4e7d
child 2874 020627074c9e
permissions -rw-r--r--
Fix #atEnd: for signed chars.
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
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
    13
'From Smalltalk/X, Version:3.1.9 on 19-aug-1997 at 10:14:54'                    !
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
ReadWriteStream subclass:#ExternalStream
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    16
	instanceVariableNames:'filePointer mode buffered binary useCRLF hitEOF didWrite
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    17
		lastErrorNumber readAhead'
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    18
	classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    19
		InvalidModeSignal OpenErrorSignal StreamNotOpenSignal
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    20
		InvalidOperationSignal'
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    21
	poolDictionaries:''
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    22
	category:'Streams-External'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    25
!ExternalStream primitiveDefinitions!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    26
%{
a27a279701f8 Initial revision
claus
parents:
diff changeset
    27
#include <stdio.h>
437
claus
parents: 436
diff changeset
    28
#define _STDIO_H_INCLUDED_
claus
parents: 436
diff changeset
    29
10
claus
parents: 5
diff changeset
    30
#include <fcntl.h>
437
claus
parents: 436
diff changeset
    31
#define _FCNTL_H_INCLUDED_
claus
parents: 436
diff changeset
    32
10
claus
parents: 5
diff changeset
    33
#include <errno.h>
437
claus
parents: 436
diff changeset
    34
#define _ERRNO_H_INCLUDED_
42
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    35
1141
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    36
#ifdef LINUX
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    37
  /* use inline string macros */
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    38
# define __STRINGDEFS__
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    39
# include <linuxIntern.h>
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    40
#endif
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    41
42
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    42
#ifdef hpux
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    43
# define fileno(f)      ((f->__fileH << 8) | (f->__fileL))
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    44
#endif
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    45
933
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    46
#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
    47
# 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
    48
#endif
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    49
#ifndef SEEK_CUR
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    50
# define SEEK_CUR 1
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    51
#endif
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    52
#ifndef SEEK_END
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_END 2
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
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    56
#ifdef xxxWIN32
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    57
# define NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    58
# define __HANDLEVal(o) 	(HFILE)(__MKCP(o))
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    59
# 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
    60
# 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
    61
# 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
    62
# 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
    63
# define FILEPOINTER		HFILE
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    64
# 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
    65
#else
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    66
# 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
    67
# define FILEPOINTER		FILE *
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    68
# 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
    69
# 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
    70
# 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
    71
# 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
    72
#endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    73
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    74
2596
36c872e47b00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2593
diff changeset
    75
#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
    76
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    77
# ifdef i386
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    78
#  define _X86_
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    79
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    80
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    81
# undef INT
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    82
# undef Array
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    83
# undef Number
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    84
# undef Method
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    85
# undef Point
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    86
# undef Rectangle
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    87
# undef Block
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
/* # include <windows.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    90
# include <stdarg.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    91
# include <windef.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    92
# include <winbase.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    93
# include <wingdi.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    94
# include <winuser.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    95
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    96
# ifdef __DEF_Array
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    97
#   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
    98
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    99
# ifdef __DEF_Number
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   100
#   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
   101
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   102
# ifdef __DEF_Method
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   103
#   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
   104
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   105
# ifdef __DEF_Point
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   106
#   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
   107
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   108
# ifdef __DEF_Block
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   109
#   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
   110
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   111
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   112
# define stat _stat
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   113
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   114
#endif /* WIN32 */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   115
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   116
/*
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   117
 * stdio library requires an fseek before reading whenever a file
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   118
 * is open for read/write and the last operation was a write.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   119
 * (also vice-versa).
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   120
 * All code should use the following macro before doing reads:
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   121
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   122
#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
   123
# 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
   124
#else
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   125
# 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
   126
#endif
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
#define __READING__(f)                          \
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   129
    if ((__INST(didWrite) != false)              \
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   130
     && (__INST(mode) == @symbol(readwrite))) {  \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   131
	__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
   132
	OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   133
    }
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   134
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   135
#define __WRITING__(f)                          \
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   136
    if ((__INST(didWrite) != true)               \
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   137
     && (__INST(mode) == @symbol(readwrite))) {  \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   138
	__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
   139
	OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   140
    }
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   141
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   142
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   143
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   144
#define __UNGETC__(c, f, isBuffered)                    \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   145
	__INST(readAhead) = __MKSMALLINT((c));
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   146
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   147
#define __UNGETC__(c, f, isBuffered)                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   148
    if (isBuffered) {                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   149
	ungetc((c), (f));                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   150
    } else {                                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   151
	__INST(readAhead) = __MKSMALLINT((c));          \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   152
    }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   153
#endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   154
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 __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
   157
    {                                            	\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   158
	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
   159
	if (rA != nil) {                                \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   160
	    *(buf) = __intVal(rA);                      \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   161
	    __INST(readAhead) = nil;                    \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   162
	    (ret) = 1;                                  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   163
	} else {                                        \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   164
	    for (;;) {                                  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   165
		(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
   166
		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
   167
		    break;                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   168
		__HANDLE_INTERRUPTS__;                  \
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
	}                                               \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   171
    }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   172
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   173
#define __READBYTE__(ret, f, buf, isBuffered)           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   174
    if (isBuffered) {                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   175
	for (;;) {                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   176
	    (ret) = getc(f);                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   177
	    if ((ret) >= 0) {                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   178
		*(buf) = (ret);                         \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   179
		(ret) = 1;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   180
	    } else if (ferror(f)) {                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   181
		if (errno == EINTR) {                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   182
		    __HANDLE_INTERRUPTS__;              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   183
		    clearerr(f);                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   184
		    continue;                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   185
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   186
	    } else                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   187
		(ret) = 0;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   188
	    break;                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   189
	}                                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   190
    } else {                                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   191
	OBJ rA = __INST(readAhead);                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   192
	if (rA != nil) {                                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   193
	    *(buf) = __intVal(rA);                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   194
	    __INST(readAhead) = nil;                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   195
	    (ret) = 1;                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   196
	} else {                                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   197
	    for (;;) {                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   198
		(ret) = read(fileno(f), buf, 1);        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   199
		if ((ret) >= 0 || errno != EINTR)       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   200
		    break;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   201
		__HANDLE_INTERRUPTS__;                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   202
	    }                                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   203
	}                                               \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   204
   }                                                                          
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   205
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   206
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   207
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   208
 * 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
   209
 * (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
   210
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   211
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   212
#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
   213
    {                                            	\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   214
	int __offs = 0;                                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   215
							\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   216
	while (__offs < (cnt)) {                        \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   217
	    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
   218
	    if (rA != nil) {                            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   219
		(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
   220
		__INST(readAhead) = nil;                \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   221
		(ret) = 1;                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   222
	    } else {                                    \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   223
		(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
   224
		if ((ret) <= 0) {                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   225
		    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
   226
			__HANDLE_INTERRUPTS__;          \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   227
			continue;                       \
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
		    break;                              \
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
	    }                                           \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   232
	    __offs += (ret);                            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   233
	}                                               \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   234
	if (__offs > 0)                                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   235
	    (ret) = __offs;                             \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   236
   }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   237
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   238
#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
   239
    (ret) = 0;                                          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   240
    if (isBuffered) {                                   \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   241
	int __offs = 0;                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   242
	while (__offs < (cnt)) {                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   243
	    (ret) = getc(f);                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   244
	    if ((ret) < 0) {                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   245
		if (ferror(f)) {                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   246
		    if (errno == EINTR) {               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   247
			__HANDLE_INTERRUPTS__;          \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   248
			clearerr(f);                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   249
			continue;                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   250
		    }                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   251
		} else {                                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   252
		    (ret) = 0;                          \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   253
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   254
		break;                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   255
	    }                                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   256
	    (buf)[__offs++] = (ret);                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   257
	}                                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   258
	if (__offs > 0)                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   259
	    (ret) = __offs;                             \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   260
    } else {                                            \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   261
	int __offs = 0;                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   262
	int fd = fileno(f);                             \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   263
							\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   264
	while (__offs < (cnt)) {                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   265
	    OBJ rA = __INST(readAhead);                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   266
	    if (rA != nil) {                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   267
		(buf)[__offs] = __intVal(rA);           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   268
		__INST(readAhead) = nil;                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   269
		(ret) = 1;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   270
	    } else {                                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   271
		(ret) = read(fd, (buf)+__offs, (cnt)-__offs);                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   272
		if ((ret) <= 0) {                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   273
		    if ((ret) < 0 && errno == EINTR) {  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   274
			__HANDLE_INTERRUPTS__;          \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   275
			continue;                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   276
		    }                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   277
		    break;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   278
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   279
	    }                                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   280
	    __offs += (ret);                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   281
	}                                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   282
	if (__offs > 0)                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   283
	    (ret) = __offs;                             \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   284
   }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   285
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   286
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   287
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   288
 * 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
   289
 * (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
   290
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   291
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   292
#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
   293
  {							\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   294
    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
   295
    int __offs = 0;					\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   296
    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
   297
							\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   298
    (ret) = 0;                                          \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   299
    {                                            	\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   300
	while (__offs < (cnt)) {                        \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   301
	    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
   302
	    if (rA != nil) {                            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   303
		(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
   304
		__INST(readAhead) = nil;                \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   305
		(ret) = 1;                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   306
	    } else {                                    \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   307
		(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
   308
		if ((ret) <= 0) {                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   309
		    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
   310
			__HANDLE_INTERRUPTS__;          \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   311
			/* refetch */                   \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   312
			buf = (char *)(obj);            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   313
			continue;                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   314
		    }                                   \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   315
		    break;                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   316
		}                                       \
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
	    __offs += (ret);                            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   319
	}                                               \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   320
	if (__offs > 0)                                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   321
	    (ret) = __offs;                             \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   322
    }							\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   323
  }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   324
#else
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   325
#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
   326
  {							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   327
    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
   328
    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
   329
    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
   330
							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   331
    (ret) = 0;                                          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   332
    if (isBuffered) {                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   333
	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
   334
	    (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
   335
	    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
   336
		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
   337
		    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
   338
			__HANDLE_INTERRUPTS__;          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   339
			clearerr(f);                    \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   340
			/* refetch */                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   341
			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
   342
			continue;                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   343
		    }                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   344
		} else {                                \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   345
		    (ret) = 0;                          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   346
		}                                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   347
		break;                                  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   348
	    }                                           \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   349
	    (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
   350
	    __offs++;					\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   351
	}                                               \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   352
	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
   353
	    (ret) = __offs;                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   354
    } else {                                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   355
	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
   356
							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   357
	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
   358
	    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
   359
	    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
   360
		(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
   361
		__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
   362
		(ret) = 1;                              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   363
	    } else {                                    \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   364
		(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
   365
		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
   366
		    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
   367
			__HANDLE_INTERRUPTS__;          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   368
			/* refetch */                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   369
			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
   370
			continue;                       \
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
		    break;                              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   373
		}                                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   374
	    }                                           \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   375
	    __offs += (ret);                            \
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
	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
   378
	    (ret) = __offs;                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   379
    }							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   380
  }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   381
#endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   382
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   383
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   384
#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
   385
	for (;;) {                                      \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   386
	    (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
   387
	    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
   388
		break;                                  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   389
	    __HANDLE_INTERRUPTS__;                      \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   390
	}
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   391
#else
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   392
#define __WRITEBYTE__(ret, f, buf, isBuffered)          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   393
    if (isBuffered) {                                   \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   394
	for (;;) {                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   395
	    ret = putc(*(buf), f);                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   396
	    if ((ret) >= 0) {                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   397
		(ret) = 1;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   398
	    } else if (ferror(f)) {                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   399
		if (errno == EINTR) {                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   400
		    __HANDLE_INTERRUPTS__;              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   401
		    clearerr(f);                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   402
		    continue;                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   403
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   404
	    } else                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   405
		(ret) = 0;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   406
	    break;                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   407
	}                                               \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   408
    } else {                                            \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   409
	for (;;) {                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   410
	    (ret) = write(fileno(f), buf, 1);           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   411
	    if ((ret) >= 0 || errno != EINTR)           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   412
		break;                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   413
	    __HANDLE_INTERRUPTS__;                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   414
	}                                               \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   415
   }                                                                          
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   416
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   417
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   418
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   419
 * 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
   420
 * (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
   421
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   422
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   423
#define __WRITEBYTES__(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
   424
    (ret) = 0;                                                                \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   425
    {                                                                  	      \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   426
	int __offs = 0;                                                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   427
	while (__offs < (cnt)) {                                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   428
	    ret = WRITE(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
   429
	    if (ret <= 0) {                                                   \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   430
		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
   431
		    __HANDLE_INTERRUPTS__;                                    \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   432
		    continue;                                                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   433
		}                                                             \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   434
		break;                                                        \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   435
	    }                                                                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   436
	    __offs += (ret);                                                  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   437
	}                                                                     \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   438
	if (__offs > 0)                                                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   439
	    (ret) = __offs;                                                   \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   440
   }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   441
#else
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   442
#define __WRITEBYTES__(ret, f, buf, cnt, isBuffered)                          \
1464
6d533b5e5de3 Fix reads and writes with cnt==0.
Stefan Vogel <sv@exept.de>
parents: 1463
diff changeset
   443
    (ret) = 0;                                                                \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   444
    if (isBuffered) {                                                         \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   445
	int __offs = 0;                                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   446
	while (__offs < (cnt)) {                                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   447
	    ret = fwrite((buf)+__offs, 1, (cnt)-__offs, f);                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   448
	    if ((ret) < 0) {                                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   449
		if (ferror(f)) {                                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   450
		    if (errno == EINTR) {                                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   451
			__HANDLE_INTERRUPTS__;                                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   452
			clearerr(f);                                          \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   453
			continue;                                             \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   454
		    }                                                         \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   455
		} else {                                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   456
		    (ret) = 0;                                                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   457
		}                                                             \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   458
		break;                                                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   459
	    }                                                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   460
	    __offs += (ret);                                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   461
	}                                                                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   462
	if (__offs > 0)                                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   463
	    (ret) = __offs;                                                   \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   464
    } else {                                                                  \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   465
	int __offs = 0;                                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   466
	while (__offs < (cnt)) {                                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   467
	    ret = write(fileno(f), (buf)+__offs, (cnt)-__offs);               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   468
	    if (ret <= 0) {                                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   469
		if (ret < 0 && errno == EINTR) {                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   470
		    __HANDLE_INTERRUPTS__;                                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   471
		    continue;                                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   472
		}                                                             \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   473
		break;                                                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   474
	    }                                                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   475
	    __offs += (ret);                                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   476
	}                                                                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   477
	if (__offs > 0)                                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   478
	    (ret) = __offs;                                                   \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   479
   }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   480
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   481
223
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   482
/*
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   483
 * 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
   484
 * (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
   485
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   486
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   487
#define __WRITEBYTES_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
   488
  {									      \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   489
    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
   490
    int __offs = 0;							      \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   491
    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
   492
									      \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   493
    (ret) = 0;                                                                \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   494
    {                                                                         \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   495
	while (__offs < (cnt)) {                                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   496
	    ret = WRITE(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
   497
	    if (ret <= 0) {                                                   \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   498
		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
   499
		    __HANDLE_INTERRUPTS__;                                    \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   500
		    /* refetch */                                             \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   501
		    buf = (char *)(obj);                                      \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   502
		    continue;                                                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   503
		}                                                             \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   504
		break;                                                        \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   505
	    }                                                                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   506
	    __offs += (ret);                                                  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   507
	}                                                                     \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   508
	if (__offs > 0)                                                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   509
	    (ret) = __offs;                                                   \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   510
    }									      \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   511
  }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   512
#else
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   513
#define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   514
  {									      \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   515
    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
   516
    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
   517
    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
   518
									      \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   519
    (ret) = 0;                                                                \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   520
    if (isBuffered) {                                                         \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   521
	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
   522
	    ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f);           \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   523
	    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
   524
		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
   525
		    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
   526
			__HANDLE_INTERRUPTS__;                                \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   527
			/* refetch */                                         \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   528
			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
   529
			clearerr(f);                                          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   530
			continue;                                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   531
		    }                                                         \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   532
		} else {                                                      \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   533
		    (ret) = 0;                                                \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   534
		}                                                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   535
		break;                                                        \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   536
	    }                                                                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   537
	    __offs += (ret);                                                  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   538
	}                                                                     \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   539
	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
   540
	    (ret) = __offs;                                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   541
    } else {                                                                  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   542
	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
   543
	    ret = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs);       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   544
	    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
   545
		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
   546
		    __HANDLE_INTERRUPTS__;                                    \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   547
		    /* refetch */                                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   548
		    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
   549
		    continue;                                                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   550
		}                                                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   551
		break;                                                        \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   552
	    }                                                                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   553
	    __offs += (ret);                                                  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   554
	}                                                                     \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   555
	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
   556
	    (ret) = __offs;                                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   557
    }									      \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   558
  }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   559
#endif
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   560
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   561
/*
223
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   562
 * on some systems errno is a macro ... check for it here
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   563
 */
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   564
#ifndef errno
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   565
 extern errno;
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   566
#endif
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   567
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   568
%}
188
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   569
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   570
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   571
!ExternalStream class methodsFor:'documentation'!
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   572
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   573
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   574
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   575
 COPYRIGHT (c) 1988 by Claus Gittinger
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   576
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   577
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   578
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   579
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   580
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   581
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   582
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   583
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   584
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   585
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   586
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   587
documentation
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   588
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   589
    ExternalStream defines protocol common to Streams which have a file-descriptor and 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   590
    represent some file or communicationChannel of the underlying OperatingSystem.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   591
    ExternalStream is abstract; concrete classes are FileStream, PipeStream etc.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   592
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   593
    ExternalStreams can be in two modes: text- (the default) and binary-mode.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   594
    In text-mode, the elements read/written are characters; 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   595
    while in binary-mode the basic elements are bytes which read/write as SmallIntegers 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   596
    in the range 0..255.
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   597
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   598
    Also, the stream can be either in buffered or unbuffered mode. In buffered mode,
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   599
    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
   600
    is sent (in both modes).
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   601
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   602
    The underlying OperatingSystem streams may either be closed explicitely (sending a close)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   603
    or just forgotten - in this case, the garbage collector will eventually collect the
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   604
    object AND a close will be performed automatically (but you will NOT know when this 
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   605
    happens - so it is recommended, that you close your files when no longer needed).
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   606
    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
   607
    some crash) the data will not be in the file, if unclosed. 
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   608
    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
   609
    a noop in one of the superclasses).
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   610
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   611
    Most of the methods found here redefine inherited methods for better performance,
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   612
    since I/O from/to files should be fast.
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   613
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   614
    Recovering a snapshot:
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   615
      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
   616
      reOpen in subclasses for more information.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   617
      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
   618
      reestablish the stream upon image restart (make someone dependent on ObjectMemory).
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   619
      FileStreams are reopened and positioned to their offset they had at snapshot time.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   620
      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
   621
      if the contents changed in the meantime.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   622
      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
   623
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   624
    [Instance variables:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   625
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   626
	filePointer     <Integer>       the unix FILE*; somehow mapped to an integer
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   627
					(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
   628
				        on Windows: the fileHandle
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   629
	mode            <Symbol>        #readwrite, #readonly or #writeonly
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   630
	buffered        <Boolean>       true, if buffered (i.e. collects characters - does
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   631
					not output immediately)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   632
	binary          <Boolean>       true if in binary mode (reads bytes instead of chars)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   633
	useCRLF         <Boolean>       true, if lines should be terminated with crlf instead
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   634
					of lf. (i.e. if file is an MSDOS-type file)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   635
	hitEOF          <Boolean>       true, if EOF was reached
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   636
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   637
	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
   638
					updated with next i/o operation)
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   639
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   640
    [Class variables:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   641
	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
   642
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   643
	StreamErrorSignal       <Signal> parent of all stream errors (see Stream class)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   644
	InvalidReadSignal       <Signal> raised on read from writeonly stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   645
	InvalidWriteSignal      <Signal> raised on write to readonly stream 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   646
	InvalidModeSignal       <Signal> raised on text I/O with binary-stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   647
					 or binary I/O with text-stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   648
	OpenErrorSignal         <Signal> raised if open fails
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   649
	StreamNotOpenSignal     <Signal> raised on I/O with non-open stream
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   650
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   651
    Additional notes:
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   652
      This class is implemented using the underlying stdio-c library package, which
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   653
      has both advantages and disadvantages: since it is portable (posix defined), porting
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   654
      ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   655
      has big problems handling unbounded Streams, since the EOF handling in stdio is
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   656
      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
   657
      a complete rewrite for UnboundedStream ...
325
claus
parents: 308
diff changeset
   658
188
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   659
      Also, depending on the system, the stdio library behaves infriendly when signals
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   660
      occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   661
      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
   662
      an error and errno is set to EINTR. 
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   663
      Thats what the ugly code around all getc-calls is for ...
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   664
      Since things get more and more ugly - we will rewrite ExternalStream
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   665
      completely, to NOT use any stdio stuff (and do its buffering itself).
325
claus
parents: 308
diff changeset
   666
claus
parents: 308
diff changeset
   667
      Notice that typical stdio's use a single errno global variable to return an error code,
claus
parents: 308
diff changeset
   668
      this was bad design in the stdio lib (right from the very beginning), since its much
claus
parents: 308
diff changeset
   669
      harder to deal with this in the presence of lightweight processes, where errno gets
claus
parents: 308
diff changeset
   670
      overwritten by an I/O operation done in another thread. (stdio should have been written
claus
parents: 308
diff changeset
   671
      to return errno as a negative number ...).
claus
parents: 308
diff changeset
   672
      To deal with this, the scheduler treats errno like a per-thread private variable,
claus
parents: 308
diff changeset
   673
      and saves/restores the errno setting when switching to another thread.
claus
parents: 308
diff changeset
   674
      (Notice that some thread packages do this also, but ST/X's thread implementation
claus
parents: 308
diff changeset
   675
      does not depend on those, but instead uses a portable private package).
claus
parents: 308
diff changeset
   676
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   677
      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
   678
      fseek whenever we are about to read after write and vice versa.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   679
      Two macros (__READING__ and __WRITING__) have been defined to be used before every
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   680
      fread/fgetc and fwrite/putc respectively.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   681
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   682
    [author:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   683
	Claus Gittinger
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   684
	Stefan Vogel (many, many fixes ...)
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   685
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   686
    [see also:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   687
	FileStream Socket PipeStream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   688
	Filename OperatingSystem
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   689
"
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   690
! !
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   691
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   692
!ExternalStream class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   693
a27a279701f8 Initial revision
claus
parents:
diff changeset
   694
initialize
593
19d568779cf7 moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   695
    OpenErrorSignal isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   696
	OpenErrorSignal := StreamErrorSignal newSignalMayProceed:true.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   697
	OpenErrorSignal nameClass:self message:#openErrorSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   698
	OpenErrorSignal notifierString:'open error'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   699
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   700
	InvalidReadSignal := ReadErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   701
	InvalidReadSignal nameClass:self message:#invalidReadSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   702
	InvalidReadSignal notifierString:'read error'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   703
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   704
	InvalidWriteSignal := WriteErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   705
	InvalidWriteSignal nameClass:self message:#invalidWriteSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   706
	InvalidWriteSignal notifierString:'write error'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   707
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   708
	InvalidModeSignal :=  StreamErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   709
	InvalidModeSignal nameClass:self message:#invalidModeSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   710
	InvalidModeSignal notifierString:'binary/text mode mismatch'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   711
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   712
	InvalidOperationSignal :=  StreamErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   713
	InvalidOperationSignal nameClass:self message:#invalidOperationSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   714
	InvalidOperationSignal notifierString:'unsupported file operation'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   715
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   716
	StreamNotOpenSignal := StreamErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   717
	StreamNotOpenSignal nameClass:self message:#streamNotOpenSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   718
	StreamNotOpenSignal notifierString:'stream is not open'.
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   719
    ].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   720
31
75f2b9f78be2 *** empty log message ***
claus
parents: 25
diff changeset
   721
    Lobby isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   722
	Lobby := Registry new.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   723
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   724
	"want to get informed when returning from snapshot"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   725
	ObjectMemory addDependent:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   726
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
   727
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   728
a27a279701f8 Initial revision
claus
parents:
diff changeset
   729
reOpenFiles
a27a279701f8 Initial revision
claus
parents:
diff changeset
   730
    "reopen all files (if possible) after a snapShot load"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   731
301
35e40a6fc72b *** empty log message ***
claus
parents: 269
diff changeset
   732
    Lobby do:[:aFileStream |
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   733
	aFileStream reOpen
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   734
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
   735
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   736
1469
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   737
update:something with:aParameter from:changedObject
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   738
    "have to reopen files when returning from snapshot"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   739
a27a279701f8 Initial revision
claus
parents:
diff changeset
   740
    something == #returnFromSnapshot ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   741
	self reOpenFiles
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   742
    ]
1469
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   743
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   744
    "Created: 15.6.1996 / 15:19:59 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   745
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   746
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   747
!ExternalStream class methodsFor:'instance creation'!
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   748
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   749
forFileDescriptor:aFileDescriptor mode:mode
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   750
    |newStream|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   751
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   752
    newStream := self basicNew.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   753
    newStream text; buffered:true; useCRLF:false; clearEOF.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   754
    ^ newStream connectTo:aFileDescriptor withMode:mode
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   755
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   756
    "this will probably fail (15 is a random FD):
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   757
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   758
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   759
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   760
     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
   761
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   762
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   763
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   764
    "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
   765
    "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
   766
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   767
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   768
forReadWriteToFileDescriptor:aFileDescriptor
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   769
    ^ self forFileDescriptor:aFileDescriptor mode:'r+'
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   770
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   771
    "this will probably fail (15 is a random FD):
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   772
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   773
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   774
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   775
     s := ExternalStream forReadWriteToFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   776
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   777
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   778
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   779
    "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
   780
    "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
   781
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   782
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   783
forReadingFromFileDescriptor:aFileDescriptor
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   784
    ^ self forFileDescriptor:aFileDescriptor mode:'r'
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   785
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   786
    "this will probably fail (15 is a random FD):
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   787
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   788
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   789
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   790
     s := ExternalStream forReadingFromFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   791
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   792
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   793
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   794
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   795
     |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
   796
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   797
     'create OS pipe ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   798
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   799
     pipe := OperatingSystem makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   800
     readFd := pipe at:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   801
     writeFd := pipe at:2.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   802
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   803
     'connect Smalltalk streams ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   804
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   805
     rs := ExternalStream forReadingFromFileDescriptor:readFd.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   806
     ws := ExternalStream forWritingToFileDescriptor:writeFd.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   807
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   808
     'read ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   809
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   810
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   811
	     Transcript showCR:rs nextLine
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   812
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   813
	 rs close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   814
     ] forkAt:7.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   815
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   816
     'write ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   817
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   818
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   819
	     ws nextPutAll:'hello world '; nextPutAll:i printString; cr
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   820
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   821
	 ws close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   822
     ] fork.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   823
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   824
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   825
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   826
    "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
   827
    "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
   828
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   829
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   830
forWritingToFileDescriptor:aFileDescriptor
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   831
    ^ self forFileDescriptor:aFileDescriptor mode:'w'
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   832
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   833
    "this will probably fail (15 is a random FD):
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   834
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   835
     |s|
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 := ExternalStream forWritingToFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   838
     s binary.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   839
     s nextPut:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   840
    "
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
    "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
   843
    "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
   844
!
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
makePipe
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   847
    "return an array with two streams - the first one for reading, the second
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   848
     for writing. This is the higher level equivalent of OperatingSystem>>makePipe."
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   849
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   850
     |pipe rs ws|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   851
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   852
     pipe := OperatingSystem makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   853
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   854
     pipe notNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   855
	 rs := self forReadingFromFileDescriptor:(pipe at:1).
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   856
	 ws := self forWritingToFileDescriptor:(pipe at:2).
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   857
	 ^ 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
   858
     ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   859
     ^ nil
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   860
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   861
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   862
     |pipe rs ws|
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
     pipe := ExternalStream makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   865
     rs := pipe at:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   866
     ws := pipe at:2.
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
     'read ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   869
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   870
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   871
	     Transcript showCR:rs nextLine
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   872
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   873
	 rs close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   874
     ] forkAt:7.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   875
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   876
     'write ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   877
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   878
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   879
	     ws nextPutAll:'hello world '; nextPutAll:i printString; cr
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   880
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   881
	 ws close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   882
     ] fork.
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
    "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
   886
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   887
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   888
new
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   889
    |newStream|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   890
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   891
    newStream := self basicNew.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   892
    newStream text; buffered:true; useCRLF:false; clearEOF.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   893
    ^ newStream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   894
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   895
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   896
!ExternalStream class methodsFor:'Signal constants'!
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   897
1522
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   898
inaccessibleSignal
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   899
    "ST-80 compatibility: return openErrorSignal"
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   900
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   901
    ^ self openErrorSignal
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   902
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   903
    "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
   904
!
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   905
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   906
invalidModeSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   907
    "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
   908
     or binary-I/O with a text stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   909
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   910
    ^ InvalidModeSignal
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   911
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   912
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   913
invalidOperationSignal
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   914
    "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
   915
     I/O operation is attempted"
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   916
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   917
    ^ InvalidOperationSignal
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   918
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
   919
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   920
invalidReadSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   921
    "return the signal raised when reading from writeonly streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   922
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   923
    ^ InvalidReadSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   924
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   925
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   926
invalidWriteSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   927
    "return the signal raised when writing to readonly streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   928
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   929
    ^ InvalidWriteSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   930
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   931
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   932
openErrorSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   933
    "return the signal raised when a file open failed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   934
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   935
    ^ OpenErrorSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   936
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   937
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   938
streamNotOpenSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   939
    "return the signal raised on I/O with closed streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   940
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   941
    ^ StreamNotOpenSignal
2
claus
parents: 1
diff changeset
   942
! !
claus
parents: 1
diff changeset
   943
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   944
!ExternalStream class methodsFor:'error handling'!
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   945
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   946
lastErrorNumber
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   947
    "return the errno of the last error"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   948
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   949
    ^ LastErrorNumber
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   950
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   951
    "
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   952
     ExternalStream lastErrorNumber
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   953
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   954
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   955
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   956
lastErrorString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   957
    "return a message string describing the last error"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   958
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   959
    ^ OperatingSystem errorTextForNumber:LastErrorNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   960
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   961
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   962
     ExternalStream lastErrorString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   963
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   964
! !
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   965
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   966
!ExternalStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   967
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   968
binary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   969
    "switch to binary mode - default is text"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   970
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   971
    binary := true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   972
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   973
a27a279701f8 Initial revision
claus
parents:
diff changeset
   974
buffered:aBoolean
10
claus
parents: 5
diff changeset
   975
    "turn buffering on or off - default is on"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   976
10
claus
parents: 5
diff changeset
   977
    buffered := aBoolean
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   978
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   979
a27a279701f8 Initial revision
claus
parents:
diff changeset
   980
contents
2
claus
parents: 1
diff changeset
   981
    "return the contents of the file from the current position up-to
claus
parents: 1
diff changeset
   982
     the end. If the stream is in binary mode, a ByteArray containing
claus
parents: 1
diff changeset
   983
     the byte values is returned.
claus
parents: 1
diff changeset
   984
     In text-mode, a collection of strings, each representing one line,
claus
parents: 1
diff changeset
   985
     is returned."
claus
parents: 1
diff changeset
   986
claus
parents: 1
diff changeset
   987
    |text l chunks sizes chunk byteCount cnt bytes offset|
claus
parents: 1
diff changeset
   988
claus
parents: 1
diff changeset
   989
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   990
	"adding to a ByteArray produces quadratic time-space
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   991
	 behavior - therefore we allocate chunks, and concatenate them
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   992
	 at the end."
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   993
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   994
	chunks := OrderedCollection new.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   995
	sizes := OrderedCollection new.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   996
	byteCount := 0.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   997
	[self atEnd] whileFalse:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   998
	    chunk := ByteArray uninitializedNew:4096.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   999
	    cnt := self nextBytes:(chunk size) into:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1000
	    cnt notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1001
		chunks add:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1002
		sizes add:cnt.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1003
		byteCount := byteCount + cnt
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1004
	    ]
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1005
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1006
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1007
	"now, create one big ByteArray"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1008
	bytes := ByteArray uninitializedNew:byteCount.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1009
	offset := 1.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1010
	1 to:chunks size do:[:index |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1011
	    chunk := chunks at:index.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1012
	    cnt := sizes at:index. 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1013
	    bytes replaceFrom:offset to:(offset + cnt - 1) with:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1014
	    offset := offset + cnt
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1015
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1016
	^ bytes
2
claus
parents: 1
diff changeset
  1017
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1018
244
9faa2da0650a Text <-> StringCollection
claus
parents: 223
diff changeset
  1019
    text := StringCollection new.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1020
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1021
	l := self nextLine.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1022
	l isNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1023
	    ^ text
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1024
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1025
	text add:l
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1026
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1027
    ^ text
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1028
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1029
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1030
contentsOfEntireFile
1522
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1031
    "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
  1032
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1033
    ^ self contents asString.
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1034
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1035
    "Modified: 3.7.1996 / 13:22:16 / stefan"
2
claus
parents: 1
diff changeset
  1036
!
claus
parents: 1
diff changeset
  1037
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1038
contentsSpecies
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1039
    "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
  1040
     (such as upTo)"
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1041
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1042
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1043
	^ ByteArray
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1044
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1045
    ^ String
2
claus
parents: 1
diff changeset
  1046
!
claus
parents: 1
diff changeset
  1047
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1048
fileDescriptor
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1049
    "return the fileDescriptor of the receiver -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1050
     notice: this one returns the underlying OSs fileDescriptor -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1051
     this may not be available on all platforms (i.e. non unix systems)."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1052
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1053
%{  /* NOCONTEXT */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1054
#ifdef WIN32
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1055
    RETURN (nil);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1056
#else
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1057
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1058
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1059
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1060
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1061
	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
  1062
	RETURN ( __MKINT(fileno(f)) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1063
    }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1064
#endif
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1065
%}.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1066
    ^ self errorNotOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1067
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1068
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1069
filePointer
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1070
    "return the filePointer of the receiver -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1071
     notice: for portability stdio is used; this means you will get
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1072
     a FILE * - not a fileDescriptor. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1073
     (what you really get is a corresponding integer).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1074
     You cannot do much with the returned value 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1075
     - except passing it to a primitive, for example."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1076
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1077
    ^ filePointer
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1078
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1079
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1080
readonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1081
    "set access mode to readonly"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1082
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1083
    mode := #readonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1084
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1085
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1086
readwrite
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1087
    "set access mode to readwrite"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1088
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1089
    mode := #readwrite
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1090
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1091
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1092
text
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1093
    "switch to text mode - default is text"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1094
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1095
    binary := false
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1096
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1097
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1098
useCRLF:aBoolean
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1099
    "turn on or off CRLF sending (instead of LF only) - default is off"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1100
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1101
    useCRLF := aBoolean
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1102
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1103
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1104
writeonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1105
    "set access mode to writeonly"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1106
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1107
    mode := #writeonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1108
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1109
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1110
!ExternalStream methodsFor:'error handling'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1111
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1112
argumentMustBeCharacter
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1113
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1114
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1115
    "report an error, that the argument must be a character"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1116
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1117
    ^ self error:'argument must be a character'
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1118
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1119
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1120
argumentMustBeInteger
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1121
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1122
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1123
    "report an error, that the argument must be an integer"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1124
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1125
    ^ self error:'argument must be an integer'
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1126
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1127
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1128
argumentMustBeString
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1129
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1130
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1131
    "report an error, that the argument must be a string"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1132
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1133
    ^ self error:'argument must be a string'
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1134
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1135
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1136
errorBinary
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1137
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1138
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1139
    "report an error, that the stream is in binary mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1140
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1141
    ^ InvalidModeSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1142
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1143
	     errorString:(self class name , ' is in binary mode')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1144
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1145
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1146
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1147
errorNotBinary
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1148
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1149
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1150
    "report an error, that the stream is not in binary mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1151
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1152
    ^ InvalidModeSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1153
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1154
	     errorString:(self class name , ' is not in binary mode')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1155
		      in:thisContext sender
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1156
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1157
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1158
errorNotBuffered
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1159
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1160
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1161
    "report an error, that the stream is not in buffered mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1162
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1163
    ^ StreamErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1164
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1165
	     errorString:(self class name , ' is unbuffered - operation not allowed')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1166
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1167
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1168
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1169
errorNotOpen
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1170
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1171
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1172
    "report an error, that the stream has not been opened"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1173
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1174
    ^ StreamNotOpenSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1175
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1176
	     errorString:(self class name , ' not open')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1177
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1178
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1179
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1180
errorOpen
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1181
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1182
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1183
    "report an error, that the stream is already opened"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1184
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1185
    ^ OpenErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1186
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1187
	errorString:(self class name , ' is already open')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1188
		 in:thisContext sender
612
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
errorReadOnly
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1192
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1193
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1194
    "report an error, that the stream is a readOnly stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1195
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1196
    ^ InvalidWriteSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1197
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1198
	     errorString:(self class name , ' is readonly')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1199
		      in:thisContext sender
612
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
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1202
errorUnsupportedOperation
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1203
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1204
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1205
    "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
  1206
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1207
    ^ InvalidOperationSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1208
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1209
	errorString:'unsupported operation'
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1210
		 in:thisContext sender
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1211
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1212
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1213
errorWriteOnly
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1214
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1215
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1216
    "report an error, that the stream is a writeOnly stream"
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
    ^ InvalidReadSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1219
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1220
	     errorString:(self class name , ' is writeonly')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1221
		      in:thisContext sender
2
claus
parents: 1
diff changeset
  1222
!
claus
parents: 1
diff changeset
  1223
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1224
ioError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1225
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1226
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1227
    "report an error, that some I/O error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1228
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1229
    ^ StreamErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1230
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1231
	     errorString:('I/O error: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1232
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1233
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1234
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1235
lastErrorNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1236
    "return the last error"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1237
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1238
    ^ lastErrorNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1239
!
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
lastErrorString
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1242
    "return a message string describing the last error"
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
    (lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1245
	^ 'I/O error'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1246
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1247
    ^ OperatingSystem errorTextForNumber:lastErrorNumber
2
claus
parents: 1
diff changeset
  1248
!
claus
parents: 1
diff changeset
  1249
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1250
openError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1251
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1252
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1253
    "report an error, that the open failed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1254
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1255
    ^ OpenErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1256
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1257
	     errorString:('error on open: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1258
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1259
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1260
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1261
readError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1262
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1263
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1264
    "report an error, that some read error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1265
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1266
    ^ ReadErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1267
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1268
	     errorString:('read error: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1269
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1270
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1271
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1272
writeError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1273
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1274
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1275
    "report an error, that some write error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1276
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1277
    ^ WriteErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1278
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1279
	     errorString:('write error: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1280
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1281
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1282
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1283
!ExternalStream methodsFor:'instance release'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1284
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1285
closeFile
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1286
    "low level close - may be redefined in subclasses"
2
claus
parents: 1
diff changeset
  1287
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1288
%{
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1289
    OBJ fp;
2
claus
parents: 1
diff changeset
  1290
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1291
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1292
	__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
  1293
#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
  1294
	CloseHandle(__HANDLEVal(fp));
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1295
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1296
	__BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1297
	fclose(__FILEVal(fp));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1298
	__END_INTERRUPTABLE__
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1299
#endif
10
claus
parents: 5
diff changeset
  1300
    }
claus
parents: 5
diff changeset
  1301
%}
claus
parents: 5
diff changeset
  1302
!
claus
parents: 5
diff changeset
  1303
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1304
disposed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1305
    "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
  1306
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1307
    self closeFile
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1308
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1309
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1310
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
  1311
    "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
  1312
     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
  1313
     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
  1314
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1315
%{  /* NOCONTEXT */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1316
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1317
#ifndef WIN32
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1318
    FILEPOINTER f;
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1319
    OBJ fp;
2765
a56668774ad7 more alpha64 fixes
Claus Gittinger <cg@exept.de>
parents: 2764
diff changeset
  1320
    FILE *fdopen();
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1321
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1322
    if (__isSmallInteger(anInteger) &&
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1323
	__isString(openMode) &&
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1324
	(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
  1325
    ) {
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1326
	__PROTECT__(self);
2765
a56668774ad7 more alpha64 fixes
Claus Gittinger <cg@exept.de>
parents: 2764
diff changeset
  1327
	fp = __MKOBJ(f); 
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1328
	__UNPROTECT__(self);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1329
	__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
  1330
	RETURN (self);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1331
    }
2613
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1332
#endif /* not WIN32 */
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1333
%}.
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1334
    ^ self primitiveFailed
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1335
!
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1336
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1337
setFileHandle:aHandle mode:openMode
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1338
    "special Windows entry: setup for a given handle (in contrast to an fd)"
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1339
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1340
%{  /* NOCONTEXT */
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1341
#ifdef xxWIN32
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1342
    FILEPOINTER f;
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1343
    
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1344
    if (__isExternalAddress(aHandle)) {
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1345
	HFILE hFile = (HFILE)(__externalAddressVal(aHandle));
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1346
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1347
printf("stream handle set to %x\n", hFile);
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1348
	/*
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1349
	 * mhmh - how can we fdopen a file to a given HANDLE ?
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1350
	 */
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1351
    }
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1352
#endif /* WIN32 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1353
%}.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1354
    ^ self primitiveFailed
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1355
!
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1356
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1357
setFilePointer:something
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1358
    "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
  1359
     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
  1360
     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
  1361
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1362
    filePointer := something
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1363
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1364
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1365
shallowCopyForFinalization
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1366
    "return a copy for finalization-registration;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1367
     since all we need at finalization time is the fileDescriptor,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1368
     a cheaper copy is possible."
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
    ^ self class basicNew setFilePointer:filePointer
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1371
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1372
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1373
shutDown
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1374
    "close the stream - added for protocol compatibility with PipeStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1375
     see comment there"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1376
1642
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1377
    filePointer isNil ifTrue:[^ self].
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1378
    Lobby unregister:self.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1379
    self closeFile
1642
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1380
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1381
    "Modified: 30.8.1996 / 00:39:21 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1382
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1383
2
claus
parents: 1
diff changeset
  1384
!ExternalStream methodsFor:'line reading/writing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1385
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1386
nextLine
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1387
    "read the next line (characters up to newline).
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1388
     Return a string containing those characters excluding the newline.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1389
     If the previous-to-last character is a cr, this is also removed,
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1390
     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
  1391
     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
  1392
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1393
    |line|
971
eb70f5674303 max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
  1394
eb70f5674303 max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
  1395
%{  /* STACK:17000 */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1396
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1397
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1398
    int len, ret;
971
eb70f5674303 max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
  1399
    char buffer[16*1024];
521
70533ec40482 use new MKSTRING_L if length is known (avoids a useless strlen)
Claus Gittinger <cg@exept.de>
parents: 481
diff changeset
  1400
    char *rslt, *nextPtr, *limit;
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1401
    int fd, ch;
1068
92fdcccf12a3 alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1402
    int _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1403
    OBJ fp;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1404
    int lineTooLong = 0;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1405
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1406
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1407
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1408
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1409
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1410
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1411
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1412
	buffer[0] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1413
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1414
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1415
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1416
	    __READING__(f);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1417
	} 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1418
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1419
	rslt = nextPtr = buffer;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1420
	limit = buffer + sizeof(buffer) - 2;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1421
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1422
	for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1423
	    __READBYTE__(ret, f, nextPtr, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1424
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1425
		if (nextPtr == buffer)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1426
		    rslt = NULL;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1427
		if (ret == 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1428
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1429
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1430
		} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1431
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1432
		    goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1433
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1434
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1435
	    if (*nextPtr == '\n') {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1436
		*nextPtr = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1437
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1438
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1439
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1440
	    nextPtr++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1441
	    if (nextPtr >= limit) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1442
		*nextPtr = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1443
		lineTooLong = 1;
2293
aec11c3274cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2264
diff changeset
  1444
		if (@global(InfoPrinting) == true) {
aec11c3274cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2264
diff changeset
  1445
		    fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n");
aec11c3274cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2264
diff changeset
  1446
		}
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1447
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1448
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1449
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1450
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1451
	if (rslt != NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1452
	    len = nextPtr-buffer;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1453
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1454
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1455
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + len);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1456
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1457
	    /* remove EOL character */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1458
	    if (len != 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1459
		if (buffer[len-1] == '\n') {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1460
		    buffer[--len] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1461
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1462
		if ((len != 0) && (buffer[len-1] == '\r')) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1463
		    buffer[--len] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1464
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1465
	    }
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1466
	    line = __MKSTRING_L(buffer, len);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1467
	    if (! lineTooLong) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1468
		RETURN ( line );
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1469
	    }
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1470
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1471
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1472
err: ;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1473
%}.
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1474
    line notNil ifTrue:[
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1475
	"/ the line as read is longer than 16k characters (boy - what a line)
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1476
	"/ The exception could be handled by reading more and returning the
2293
aec11c3274cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2264
diff changeset
  1477
	"/ concatenation in your exception handler (the receiver and the partial
aec11c3274cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2264
diff changeset
  1478
	"/ line are passed as parameter)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1479
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1480
	^ ReadErrorSignal
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1481
	    raiseRequestWith:(Array with:self with:line)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1482
		 errorString:('line too long read error')
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1483
    ].
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1484
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1485
    hitEOF ifTrue:[^ self pastEnd].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1486
    lastErrorNumber notNil ifTrue:[^ self readError].
2
claus
parents: 1
diff changeset
  1487
    filePointer isNil ifTrue:[^ self errorNotOpen].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1488
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1489
    ^ self errorBinary
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1490
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1491
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1492
nextPutLine:aString
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1493
    "write the characters in aString and append a newline or CRLF if useCRLF is set"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1494
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1495
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1496
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1497
    int len, cnt, len1, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1498
    OBJ pos, fp;
537
dc4dad8a5ddd many ExtStream rewrites - has to be reevaluated in all platforms
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1499
    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
  1500
    int o_offs;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1501
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1502
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1503
    if (((fp = __INST(filePointer)) != nil) 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1504
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1505
	&& (__INST(binary) != true)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1506
	&& __isString(aString)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1507
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1508
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1509
	len = __stringSize(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1510
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1511
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1512
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1513
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1514
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1515
	__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
  1516
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1517
	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
  1518
	__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
  1519
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1520
	if (cnt == len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1521
	    len1 = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1522
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1523
	    if (__INST(useCRLF) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1524
		cp = "\r\n"; len = 2;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1525
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1526
		cp = "\n"; len = 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1527
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1528
	    __WRITEBYTES__(cnt, f, cp, len, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1529
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1530
	    if (cnt > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1531
		pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1532
		if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1533
		    __INST(position) = __MKSMALLINT(__intVal(pos)+len1+cnt);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1534
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1535
		RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1536
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1537
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1538
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1539
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1540
%}.
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1541
    super nextPutLine:aString.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1542
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1543
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1544
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1545
    "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
  1546
     and append all lines to self. 
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1547
     Can be used to copy/create large files or copy from a pipe/socket.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1548
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1549
     If aStringOrNil is nil or not matched, copy preceeds to the end.
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1550
     (this allows for example to read a Socket and transfer the data quickly
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1551
      into a file - without creating zillions of temporary strings)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1552
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1553
    |srcFilePointer readError line|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1554
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1555
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1556
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1557
    srcFilePointer := aStream filePointer.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1558
    srcFilePointer isNil ifTrue:[aStream errorNotOpen. ^ self].
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1559
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1560
%{  /* STACK:2000 */
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1561
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1562
#ifndef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1563
    FILEPOINTER dst;
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1564
    FILEPOINTER src;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1565
    char *matchString;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1566
    int matchLen = 0;
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1567
    char buffer[1024];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1568
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1569
    __INST(lastErrorNumber) = nil;
249
claus
parents: 244
diff changeset
  1570
    if (__isSmallInteger(srcFilePointer)) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1571
	if ((aStringOrNil == nil) || __isString(aStringOrNil)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1572
	    if (aStringOrNil != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1573
		matchString = (char *) __stringVal(aStringOrNil);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1574
		matchLen = __stringSize(aStringOrNil);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1575
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1576
	    dst = __FILEVal(__INST(filePointer));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1577
	    src = __FILEVal(srcFilePointer);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1578
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1579
	    errno = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1580
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1581
	    __WRITING__(dst)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1582
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1583
	    for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1584
		if (fgets(buffer, sizeof(buffer)-1, src) == NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1585
		    if (ferror(src)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1586
			readError = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1587
			__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1588
			goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1589
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1590
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1591
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1592
		if (fputs(buffer, dst) == EOF) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1593
		    if (ferror(dst)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1594
			__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1595
			__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1596
			goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1597
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1598
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1599
		}
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1600
#ifndef OLD
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1601
		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
  1602
		    FFLUSH(dst);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1603
		}
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1604
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1605
		if (matchLen) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1606
		    if (strncmp(matchString, buffer, matchLen) == 0) 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1607
			break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1608
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1609
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1610
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1611
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1612
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1613
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1614
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1615
err: ;
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1616
#endif /* ! NO_STDIO */
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1617
%}.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1618
    readError ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1619
	aStream setLastErrorNumber:readError.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1620
	aStream readError.
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1621
	^ self
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1622
    ].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1623
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1624
    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
  1625
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1626
    "
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1627
     argument error or unimplemented; try it linewise
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1628
    "
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1629
    [aStream atEnd] whileFalse:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1630
	line := aStream nextLine.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1631
	line isNil ifTrue:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1632
	    ^ self.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1633
	].
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1634
	self nextPutLine:line.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1635
	(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
  1636
	    ^ self
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1637
	]
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1638
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1639
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1640
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1641
peekForLineStartingWith:aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1642
    "read ahead for next line starting with aString;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1643
     return the line-string if found, or nil if EOF is encountered.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1644
     If matched, not advance position behond that line
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1645
     i.e. nextLine will read the matched line.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1646
     If not matched, reposition to original position for firther reading."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1647
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1648
    |firstPos lastPos line|
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1649
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1650
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1651
    filePointer isNil ifTrue:[^ self errorNotOpen].
2
claus
parents: 1
diff changeset
  1652
    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
  1653
    buffered ifFalse:[^ self errorNotBuffered].
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1654
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1655
%{  /* STACK: 2000 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1656
    FILEPOINTER f;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1657
    int l;
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1658
    char buffer[1024];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1659
    char *cp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1660
    char *matchString;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1661
    int  firstpos = -1, lastpos;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1662
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1663
#ifndef NO_STDIO
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1664
    __INST(lastErrorNumber) = nil;
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
  1665
    if (__isString(aString)) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1666
	matchString = (char *) __stringVal(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1667
	l = __stringSize(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1668
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1669
	f = __FILEVal(__INST(filePointer));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1670
	__READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1671
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1672
	for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1673
	    lastpos = ftell(f);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1674
	    if (firstpos == -1) firstpos = lastpos;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1675
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1676
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1677
	    do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1678
		cp = fgets(buffer, sizeof(buffer)-1, f);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1679
	    } while ((cp == NULL) && ferror(f) && (errno == EINTR) && (clearerr(f), 1));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1680
	    buffer[sizeof(buffer)-1] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1681
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1682
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1683
	    if (cp == NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1684
		if (ferror(f)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1685
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1686
		    goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1687
		} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1688
		    fseek(f, firstpos, SEEK_SET);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1689
		    RETURN (nil);
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
	    if (strncmp(cp, matchString, l) == 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1693
		fseek(f, lastpos, SEEK_SET);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1694
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1695
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1696
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1697
	/* remove EOL character */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1698
	cp = buffer;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1699
	while (*cp && (*cp != '\n')) cp++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1700
	*cp = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1701
	RETURN ( __MKSTRING(buffer) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1702
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1703
err: ;
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1704
#endif
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1705
%}.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1706
    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
  1707
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1708
    "/ 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
  1709
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1710
    firstPos := self position.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1711
    [self atEnd] whileFalse:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1712
	lastPos := self position.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1713
	line := self nextLine.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1714
	line isNil ifTrue:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1715
	    self position:firstPos.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1716
	    ^ nil
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1717
	].
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1718
	(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
  1719
	    self position:lastPos.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1720
	    ^ line
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1721
	]
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1722
    ].
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1723
    self position:firstPos.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1724
    ^ nil
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1725
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1726
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1727
peekForLineStartingWithAny:aCollectionOfStrings
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1728
    "read ahead for next line starting with any of aCollectionOfStrings;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1729
     return the index in aCollection if found, nil otherwise..
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1730
     If no match, do not change position; otherwise advance right before the
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1731
     matched line so that nextLine will return this line."
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1732
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1733
    |line startPos linePos index|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1734
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1735
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1736
    filePointer isNil ifTrue:[^ self errorNotOpen].
2
claus
parents: 1
diff changeset
  1737
    binary ifTrue:[^ self errorBinary].
claus
parents: 1
diff changeset
  1738
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1739
    startPos := self position.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1740
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1741
	linePos := self position.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1742
	line := self nextLine.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1743
	line notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1744
	    index := 1.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1745
	    aCollectionOfStrings do:[:prefix |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1746
		(line startsWith:prefix) ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1747
		    self position:linePos.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1748
		    ^ index
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1749
		].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1750
		index := index + 1
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
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1753
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1754
    self position:startPos.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1755
    ^ nil
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1756
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1757
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1758
!ExternalStream methodsFor:'misc functions'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1759
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1760
async:aBoolean
779
0e41a665038a commentary
Claus Gittinger <cg@exept.de>
parents: 730
diff changeset
  1761
    "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
  1762
     the receiver will trigger an ioInterrupt.
779
0e41a665038a commentary
Claus Gittinger <cg@exept.de>
parents: 730
diff changeset
  1763
     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
  1764
     Notice: 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1765
	not every OS supports this 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1766
	- check with OS>>supportsIOInterrupts before using"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1767
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1768
    |fd|
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1769
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1770
    filePointer isNil ifTrue:[^ self errorNotOpen].
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1771
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1772
    OperatingSystem supportsIOInterrupts ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1773
	^ self errorUnsupportedOperation
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1774
    ].
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1775
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1776
    fd := self fileDescriptor.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1777
    aBoolean ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1778
	^ OperatingSystem enableIOInterruptsOn:fd
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1779
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1780
    ^ OperatingSystem disableIOInterruptsOn:fd
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1781
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1782
    "Modified: 11.1.1997 / 17:50:21 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1783
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1784
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1785
backStep
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1786
    "step back one element -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1787
     redefined, since position is redefined here"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1788
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1789
    self position:(self position - 1)
362
claus
parents: 360
diff changeset
  1790
!
claus
parents: 360
diff changeset
  1791
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1792
blocking:aBoolean
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1793
    "set/clear the blocking attribute - if set (which is the default)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1794
     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
  1795
     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
  1796
     nil.
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1797
     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
  1798
     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
  1799
     in advance. However, the data must then be read using #nextBytes:
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1800
     methods, in order to avoid other (pasEnd) exceptions."
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1801
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1802
    filePointer isNil ifTrue:[^ self errorNotOpen].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1803
    ^ 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
  1804
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1805
    "Modified: 11.1.1997 / 17:48:01 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1806
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1807
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1808
close
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1809
    "close the stream - tell operating system"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1810
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1811
    filePointer isNil ifTrue:[^ self].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1812
    Lobby unregister:self.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1813
    self closeFile.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1814
    filePointer := nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1815
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1816
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1817
create
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1818
    "create the stream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1819
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1820
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1821
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1822
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1823
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1824
ioctl:ioctlNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1825
    "to provide a simple ioctl facility - an ioctl is performed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1826
     on the underlying file; no arguments are passed."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1827
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1828
%{
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1829
#ifndef MSDOS_LIKE
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1830
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1831
    int ret, ioNum, ioArg;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1832
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1833
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1834
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1835
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1836
	if (__isSmallInteger(ioctlNumber)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1837
	    ioNum = __intVal(ioctlNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1838
	    f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1839
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1840
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1841
	    do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1842
		errno = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1843
		ret = ioctl(fileno(f), ioNum);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1844
	    } while ((ret < 0) && (errno == EINTR));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1845
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1846
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1847
	    if (ret >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1848
		RETURN ( __MKSMALLINT(ret) );
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
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1851
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1852
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1853
    }
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1854
#endif
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1855
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1856
    lastErrorNumber notNil ifTrue:[^ self ioError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1857
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1858
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1859
     ioctl-number is not an integer
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1860
     or the system does not support ioctl (MSDOS)
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1861
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1862
    ^ self primitiveFailed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1863
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1864
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1865
ioctl:ioctlNumber with:arg
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1866
    "to provide a simple ioctl facility - an ioctl is performed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1867
     on the underlying file; the argument is passed as argument.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1868
     If the argument is a number, its directly passed; if its a
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1869
     kind of ByteArray (ByteArray, String or Structure) a pointer to
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1870
     the data is passed. This allows performing most ioctls - however,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1871
     it might be tricky to setup the buffer."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1872
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1873
%{
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1874
#ifndef MSDOS_LIKE
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1875
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1876
    int ret, ioNum;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1877
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1878
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1879
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1880
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1881
	if (__isSmallInteger(ioctlNumber) 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1882
	 && (__isSmallInteger(arg) || __isBytes(arg))) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1883
	    f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1884
	    ioNum = __intVal(ioctlNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1885
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1886
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1887
	    do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1888
		errno = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1889
		if (__isSmallInteger(arg)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1890
		    ret = ioctl(fileno(f), ioNum, __intVal(arg));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1891
		} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1892
		    ret = ioctl(fileno(f), ioNum, __ByteArrayInstPtr(arg)->ba_element);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1893
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1894
	    } while ((ret < 0) && (errno == EINTR));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1895
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1896
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1897
	    if (ret >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1898
		RETURN ( __MKSMALLINT(ret) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1899
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1900
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1901
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1902
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1903
    }
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1904
#endif
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1905
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1906
    lastErrorNumber notNil ifTrue:[^ self ioError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1907
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1908
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1909
     ioctl-number is not an integer or argument is not byteArray-like
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  1910
     or the system does not support ioctl (MSDOS)
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1911
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1912
    ^ self primitiveFailed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1913
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1914
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1915
open
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1916
    "open the stream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1917
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1918
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1919
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1920
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1921
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1922
position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1923
    "return the position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1924
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1925
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1926
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1927
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1928
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1929
position:anInteger
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1930
    "set the position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1931
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1932
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1933
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1934
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1935
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1936
reset
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1937
    "set the read position to the beginning of the collection"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1938
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1939
    self position:"0" 1
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1940
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1941
1044
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1942
setToEnd
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1943
    "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
  1944
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1945
    ^ self subclassResponsibility
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1946
!
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  1947
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1948
truncateTo:newSize
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1949
    "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
  1950
     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
  1951
1068
92fdcccf12a3 alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1952
%{
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1953
#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
  1954
    FILEPOINTER f;
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1955
    OBJ fp;
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1956
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1957
    if (((fp = __INST(filePointer)) != nil)
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1958
     && (__INST(mode) != @symbol(readonly))) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1959
	if (__isSmallInteger(newSize)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1960
	    f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1961
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1962
	    if (__INST(buffered) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1963
		__READING__(f)
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1964
		FFLUSH(f);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1965
		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
  1966
	    }
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1967
	    ftruncate(fileno(f), __intVal(newSize));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1968
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1969
	}
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1970
    }
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1971
#endif
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1972
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1973
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1974
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1975
    self errorUnsupportedOperation
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1976
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1977
    "
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1978
     |s|
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1979
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1980
     s := 'test' asFilename writeStream.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1981
     s next:1000 put:$a.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1982
     s truncateTo:100.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1983
     s close.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1984
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1985
     ('test' asFilename fileSize) printNL
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1986
    "
612
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
!ExternalStream methodsFor:'non homogenous reading'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1990
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1991
nextByte
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1992
    "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
  1993
     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
  1994
     bytes binary value as an integer in 0..255."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1995
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1996
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1997
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1998
    unsigned char byte;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1999
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2000
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2001
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2002
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2003
    if (((fp = __INST(filePointer)) != nil)
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2004
     && (__INST(mode) != @symbol(writeonly))) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2005
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2006
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2007
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2008
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2009
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2010
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2011
	__READBYTE__(ret, f, &byte, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2012
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2013
	    if (__INST(position) != nil)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2014
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2015
	    RETURN (__MKSMALLINT(byte));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2016
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2017
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2018
	if (ret == 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2019
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2020
	} else /* ret < 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2021
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2022
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2023
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2024
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2025
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2026
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2027
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2028
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2029
    ^ self errorWriteOnly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2030
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2031
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2032
nextBytes:count into:anObject startingAt:start
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2033
    "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
  2034
     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
  2035
     If the receiver is some socket/pipe-like stream, an exception
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2036
     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
  2037
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2038
     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
  2039
     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
  2040
     Thus allowing read of partial blocks.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2041
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2042
     The object must have non-pointer indexed instvars 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2043
     (i.e. it must be a ByteArray, String, Float- or DoubleArray).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2044
     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
  2045
     fastest possible physical I/O (since no new objects are allocated).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2046
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2047
     Use with care - non object oriented I/O.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2048
     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
  2049
     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
  2050
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2051
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2052
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2053
    int cnt, offs, ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2054
    int objSize, nInstVars, nInstBytes;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2055
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2056
    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
  2057
    int o_offs;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2058
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2059
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2060
    if (((fp = __INST(filePointer)) != nil)
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2061
        && (__INST(mode) != @symbol(writeonly))
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2062
        && __bothSmallInteger(count, start)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2063
    ) {
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2064
        f = __FILEVal(fp);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2065
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2066
        oClass = __Class(anObject);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2067
        switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2068
            case BYTEARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2069
            case WORDARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2070
            case LONGARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2071
            case SWORDARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2072
            case SLONGARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2073
            case FLOATARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2074
            case DOUBLEARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2075
                break;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2076
            default:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2077
                goto bad;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2078
        }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2079
        cnt = __intVal(count);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2080
        offs = __intVal(start) - 1;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2081
        nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2082
        nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2083
        objSize = __Size(anObject) - nInstBytes;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2084
        if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2085
            _buffered = (__INST(buffered) == true);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2086
            if (_buffered) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2087
                __READING__(f);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2088
            }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2089
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2090
            /*
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2091
             * on interrupt, anObject may be moved to another location.
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2092
             * 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
  2093
             * to get a new address.
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2094
             */
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2095
            o_offs = nInstBytes+offs;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2096
            __READBYTES_OBJ__(ret, f, anObject, o_offs, cnt, _buffered);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2097
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2098
            if (ret > 0) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2099
                pos = __INST(position);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2100
                if (pos != nil) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2101
                    __INST(position) = __MKSMALLINT(__intVal(pos) + ret);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2102
                }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2103
                RETURN (__MKSMALLINT(ret));
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2104
            }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2105
            if (ret == 0) { 
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2106
                __INST(hitEOF) = true;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2107
            } else /* ret < 0 */ {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2108
                __INST(position) = nil;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2109
                __INST(lastErrorNumber) = __MKSMALLINT(errno);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2110
            }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2111
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2112
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2113
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2114
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2115
    (hitEOF and:[self pastEnd isNil]) ifTrue:[^ 0].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2116
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2117
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2118
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2119
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2120
     count not integer or arg not bit-like (String, ByteArray etc)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2121
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2122
    ^ self primitiveFailed
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2123
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2124
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2125
nextLong
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2126
    "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
  2127
     The returned value may be a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2128
     (msb-first for compatibility with other smalltalks)"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2129
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2130
    ^ self nextUnsignedLongMSB:true
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2131
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2132
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2133
nextLongMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2134
    "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
  2135
     which may be a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2136
     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
  2137
     otherwise least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2138
     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
  2139
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2140
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2141
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2142
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2143
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2144
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2145
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2146
	&& (__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
  2147
    ) {
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2148
	FILEPOINTER f;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2149
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2150
	int value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2151
	char buffer[4];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2152
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2153
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2154
	__READBYTES__(ret, f, buffer, 4, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2155
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2156
	if (ret == 4) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2157
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2158
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 4);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2159
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2160
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2161
		value = (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2162
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2163
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2164
		value = (value << 8) | (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2165
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2166
		value = (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2167
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2168
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2169
		value = (value << 8) | (buffer[0] & 0xFF);
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
	    if ((value >= _MIN_INT) && (value <= _MAX_INT)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2172
		RETURN ( __MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2173
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2174
	    RETURN ( __MKLARGEINT(value) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2175
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2176
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2177
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2178
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2179
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2180
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2181
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2182
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2183
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2184
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2185
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2186
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2187
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2188
    ^ self readError.
1079
d47cd86b487b Make methods signal-proof.
Stefan Vogel <sv@exept.de>
parents: 1068
diff changeset
  2189
362
claus
parents: 360
diff changeset
  2190
!
claus
parents: 360
diff changeset
  2191
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2192
nextShortMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2193
    "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
  2194
     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
  2195
     otherwise least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2196
     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
  2197
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2198
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2199
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2200
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2201
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2202
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2203
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2204
	&& (__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
  2205
    ) {
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2206
	FILEPOINTER f;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2207
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2208
	short value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2209
	char buffer[2];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2210
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2211
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2212
	__READBYTES__(ret, f, buffer, 2, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2213
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2214
	if (ret == 2) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2215
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2216
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 2);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2217
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2218
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2219
		value = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2220
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2221
		value = ((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2222
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2223
	    RETURN (__MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2224
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2225
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2226
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2227
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2228
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2229
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2230
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2231
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2232
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2233
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2234
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2235
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2236
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2237
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2238
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2239
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2240
nextUnsignedLongMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2241
    "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
  2242
     a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2243
     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
  2244
     least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2245
     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
  2246
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2247
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2248
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2249
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2250
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2251
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2252
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2253
	&& (__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
  2254
    ) {
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2255
	FILEPOINTER f;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2256
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2257
	unsigned int value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2258
	char buffer[4];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2259
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2260
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2261
	__READBYTES__(ret, f, buffer, 4, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2262
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2263
	if (ret == 4) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2264
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2265
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 4);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2266
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2267
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2268
		value = (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2269
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2270
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2271
		value = (value << 8) | (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2272
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2273
		value = (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2274
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2275
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2276
		value = (value << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2277
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2278
	    if (value <= _MAX_INT) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2279
		RETURN ( __MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2280
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2281
	    RETURN ( __MKULARGEINT(value) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2282
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2283
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2284
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2285
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2286
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2287
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2288
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2289
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2290
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2291
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2292
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2293
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2294
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2295
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2296
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2297
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2298
nextUnsignedShortMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2299
    "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
  2300
     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
  2301
     otherwise least-significant byte comes first.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2302
     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
  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
	unsigned int value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2315
	char buffer[2];
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, 2, __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 == 2) {
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)) + 2);
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) << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2326
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2327
		value = ((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2328
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2329
	    RETURN (__MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2330
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2331
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2332
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2333
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2334
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2335
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2336
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2337
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2338
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2339
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2340
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2341
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2342
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2343
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2344
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2345
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2346
nextWord
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2347
    "in text-mode:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2348
	 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
  2349
	 return a string containing those characters.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2350
     in binary-mode:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2351
	 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
  2352
	 unsigned Integer (for compatibility with other smalltalks)"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2353
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2354
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2355
	^ self nextUnsignedShortMSB:true
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2356
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2357
    ^ self nextAlphaNumericWord
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2358
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2359
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2360
!ExternalStream methodsFor:'non homogenous writing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2361
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2362
nextPutByte:aByteValue
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2363
    "write a byte.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2364
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2365
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2366
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2367
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2368
    char c;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2369
    OBJ pos, fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2370
    int cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2371
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2372
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2373
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2374
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2375
	&& __isSmallInteger(aByteValue)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2376
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2377
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2378
	c = __intVal(aByteValue);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2379
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2380
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2381
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2382
	} 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2383
	__WRITEBYTE__(cnt, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2384
	if (cnt == 1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2385
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2386
	    if (pos != nil)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2387
		__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2388
	    RETURN (self);
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
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2391
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2392
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2393
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2394
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2395
    self writeError.
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2398
nextPutBytes:count from:anObject startingAt:start
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2399
    "write count bytes from an object starting at index start.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2400
     return the number of bytes written - which could be 0.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2401
     The object must have non-pointer indexed instvars 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2402
     (i.e. be a ByteArray, String, Float- or DoubleArray).     
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2403
     Use with care - non object oriented i/o.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2404
     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
  2405
     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
  2406
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2407
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2408
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2409
    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
  2410
    int objSize, nInstVars, nInstBytes, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2411
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2412
    OBJ oClass, pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2413
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2414
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2415
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2416
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2417
	&& __bothSmallInteger(count, start)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2418
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2419
	oClass = __Class(anObject);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2420
	switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2421
	    case BYTEARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2422
	    case WORDARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2423
	    case LONGARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2424
	    case SWORDARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2425
	    case SLONGARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2426
	    case FLOATARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2427
	    case DOUBLEARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2428
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2429
	    default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2430
		goto bad;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2431
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2432
	len = __intVal(count);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2433
	offs = __intVal(start) - 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2434
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2435
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2436
	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2437
	nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2438
	objSize = __Size(anObject) - nInstBytes;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2439
	if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2440
	    offs += nInstBytes;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2441
	    if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2442
		__WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2443
	    }
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  2444
	    __WRITEBYTES_OBJ__(cnt, f, anObject, offs, len, _buffered); 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2445
	    if (cnt >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2446
		pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2447
		if (pos != nil)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2448
		    __INST(position) = __MKSMALLINT(__intVal(pos) + cnt);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2449
		RETURN ( __MKSMALLINT(cnt) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2450
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2451
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2452
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2453
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2454
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2455
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2456
    lastErrorNumber notNil ifTrue:[^ self writeError].
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 == #readonly) ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2459
    ^ self primitiveFailed
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
nextPutLong:aNumber MSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2463
    "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
  2464
     true, data is written most-significant byte first; otherwise least
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2465
     first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2466
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2467
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2468
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2469
    int num;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2470
    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
  2471
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2472
    int cnt, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2473
    OBJ fp, pos;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2474
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2475
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2476
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2477
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2478
	&& __isSmallInteger(aNumber)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2479
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2480
	num = __intVal(aNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2481
	if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2482
	    bytes[0] = (num >> 24) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2483
	    bytes[1] = (num >> 16) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2484
	    bytes[2] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2485
	    bytes[3] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2486
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2487
	    bytes[3] = (num >> 24) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2488
	    bytes[2] = (num >> 16) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2489
	    bytes[1] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2490
	    bytes[0] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2491
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2492
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2493
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2494
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2495
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2496
	} 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2497
	__WRITEBYTES__(cnt, f, bytes, 4, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2498
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2499
	if (cnt == 4) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2500
	    if ((pos = __INST(position)) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2501
		__INST(position) = __MKSMALLINT(__intVal(pos) + 4);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2502
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2503
	    RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2504
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2505
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2506
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2507
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2508
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2509
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2510
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2511
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2512
    aNumber isInteger ifTrue:[
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2513
	^ super nextPutLong:aNumber MSB:msbFlag
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2514
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2515
    self argumentMustBeInteger
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2516
!
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
nextPutShort:aNumber MSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2519
    "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
  2520
     true, data is written most-significant byte first; otherwise least
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2521
     first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2522
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2523
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2524
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2525
    int num;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2526
    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
  2527
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2528
    int cnt, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2529
    OBJ fp, pos;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2530
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2531
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2532
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2533
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2534
	&& __isSmallInteger(aNumber)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2535
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2536
	num = __intVal(aNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2537
	if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2538
	    bytes[0] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2539
	    bytes[1] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2540
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2541
	    bytes[1] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2542
	    bytes[0] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2543
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2544
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2545
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2546
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2547
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2548
	} 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2549
	__WRITEBYTES__(cnt, f, bytes, 2, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2550
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2551
	if (cnt == 2) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2552
	    if ((pos = __INST(position)) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2553
		__INST(position) = __MKSMALLINT(__intVal(pos) + 2);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2554
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2555
	    RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2556
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2557
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2558
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2559
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2560
    lastErrorNumber notNil ifTrue:[^ self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2561
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2562
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2563
    self argumentMustBeInteger
10
claus
parents: 5
diff changeset
  2564
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2565
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2566
!ExternalStream methodsFor:'private'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2567
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2568
clearEOF
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2569
    hitEOF := false
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2570
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2571
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2572
connectTo:aFileDescriptor withMode:openmode
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2573
    "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
  2574
     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
  2575
     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
  2576
     a Stream object. 
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2577
     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
  2578
     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
  2579
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2580
    |retVal|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2581
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2582
    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
  2583
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2584
    FILEPOINTER f;
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2585
    OBJ fp;
2765
a56668774ad7 more alpha64 fixes
Claus Gittinger <cg@exept.de>
parents: 2764
diff changeset
  2586
    FILE *fdopen();
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2587
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2588
    if (__isSmallInteger(aFileDescriptor) 
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2589
     && (__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
  2590
	f = (FILEPOINTER) fdopen(__intVal(aFileDescriptor), (char *)__stringVal(openmode));
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2591
	if (f == NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2592
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2593
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2594
	} else {
2765
a56668774ad7 more alpha64 fixes
Claus Gittinger <cg@exept.de>
parents: 2764
diff changeset
  2595
	    __INST(filePointer) = fp = __MKOBJ(f); __STORE(self, fp);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2596
	    __INST(position) = __MKSMALLINT(1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2597
	    retVal = self;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2598
	}
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2599
    }
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2600
%}.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2601
    retVal notNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2602
	buffered := true.       "default is buffered"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2603
	Lobby register:self
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2604
    ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2605
    lastErrorNumber notNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2606
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2607
	 the open failed for some reason ...
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2608
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2609
	^ self openError
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2610
    ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2611
    ^ retVal
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2612
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2613
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2614
reOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2615
    "sent after snapin to reopen streams.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2616
     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
  2617
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  2618
    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
  2619
    filePointer := nil.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2620
    Lobby unregister:self.
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  2621
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  2622
    "Modified: 10.1.1997 / 17:50:44 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2623
!
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
setLastError:aNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2626
    lastErrorNumber := aNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2627
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2628
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2629
!ExternalStream methodsFor:'queries'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2630
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2631
isBinary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2632
    "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
  2633
     The default when created is false."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2634
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2635
    ^ binary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2636
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2637
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2638
isExternalStream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2639
    "return true, if the receiver is some kind of externalStream;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2640
     true is returned here - the method redefined from Object."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2641
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2642
    ^ true
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2643
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2644
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2645
isReadable 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2646
    "return true, if this stream can be read from"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2647
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2648
    ^ (mode ~~ #writeonly)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2649
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2650
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2651
isWritable 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2652
    "return true, if this stream can be written to"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2653
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2654
    ^ (mode ~~ #readonly)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2655
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2656
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2657
!ExternalStream methodsFor:'reading'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2658
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2659
next
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2660
    "return the next element; advance read position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2661
     In binary mode, an integer is returned, otherwise a character.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2662
     If there are no more elements, nil is returned."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2663
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2664
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2665
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2666
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2667
    OBJ pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2668
    unsigned char ch;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2669
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2670
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2671
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2672
	&& (__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
  2673
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2674
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2675
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2676
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2677
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2678
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2679
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2680
	__READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2681
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2682
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2683
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2684
	    if (__isSmallInteger(pos)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2685
		__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2686
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2687
		__INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2688
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2689
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2690
		RETURN ( __MKSMALLINT(ch) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2691
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2692
	    RETURN ( __MKCHARACTER(ch) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2693
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2694
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2695
	__INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2696
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2697
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2698
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2699
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2700
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2701
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2702
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2703
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2704
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2705
    filePointer isNil ifTrue:[^ self errorNotOpen].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2706
    ^ self errorWriteOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2707
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2708
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2709
next:count
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2710
    "return the next count elements of the stream as a collection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2711
     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
  2712
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2713
    |coll nRead|
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2714
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2715
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2716
	coll := ByteArray uninitializedNew:count
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2717
    ] ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2718
	coll := String new:count
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2719
    ].
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2720
    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
  2721
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2722
    "/ for readStream protocol compatibility, 
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2723
    "/ we must raise an exception here.
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2724
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2725
    nRead < count ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2726
	^ self pastEnd
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2727
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2728
    ^ coll
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2729
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2730
    "Modified: 11.1.1997 / 17:44:17 / cg"
612
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2733
peek
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2734
    "return the element to be read next without advancing read position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2735
     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
  2736
     If there are no more elements, nil is returned."
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2737
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2738
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2739
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2740
    unsigned char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2741
    int ret, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2742
    OBJ fp;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2743
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2744
    __INST(lastErrorNumber) = nil;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2745
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2746
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2747
	&& (__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
  2748
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2749
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2750
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2751
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2752
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2753
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2754
	__READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2755
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2756
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2757
	    __UNGETC__(c, f, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2758
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2759
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2760
		RETURN ( __MKSMALLINT(c) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2761
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2762
	    RETURN ( __MKCHARACTER(c) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2763
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2764
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2765
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2766
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2767
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2768
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2769
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2770
%}.
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2771
    hitEOF ifTrue:[^ self pastEnd]. 
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2772
    lastErrorNumber notNil ifTrue:[^ self readError].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2773
    filePointer isNil ifTrue:[^ self errorNotOpen].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2774
    ^ self errorWriteOnly
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2775
!
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2776
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2777
upToEnd
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2778
    "return a collection of the elements up-to the end.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2779
     Return nil if the stream-end is reached before."
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2780
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2781
    |answerStream ch|
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2782
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2783
    answerStream := WriteStream on:(self contentsSpecies new).
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2784
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2785
	ch := self next.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2786
	ch notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2787
	    answerStream nextPut:ch
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2788
	]
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2789
    ].
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2790
    ^ answerStream contents
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2791
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2792
    "Created: 25.4.1996 / 14:40:31 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2793
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2794
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2795
!ExternalStream methodsFor:'reimplemented for speed'!
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2796
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2797
nextAlphaNumericWord
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2798
    "read the next word (i.e. up to non letter-or-digit) after first
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2799
     skipping any whiteSpace.
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2800
     Return a string containing those characters.
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2801
     There is a limit of 1023 characters in the word - if longer,
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2802
     it is truncated."
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2803
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2804
%{  /* STACK: 2000 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2805
    FILEPOINTER f;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2806
    int len;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2807
    char buffer[1024];
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2808
    unsigned char ch;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2809
    int cnt = 0;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2810
    int ret, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2811
    OBJ fp;
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2812
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2813
    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
  2814
     && (__INST(mode) != @symbol(writeonly))
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2815
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2816
	f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2817
	_buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2818
	if (_buffered) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2819
	    __READING__(f)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2820
	}
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2821
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2822
	/*
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2823
	 * skip whiteSpace first ...
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2824
	 */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2825
	do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2826
	    __READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2827
	    if (ret > 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2828
		cnt++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2829
	    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2830
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2831
	} while (
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2832
#ifndef NON_ASCII
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2833
		 (ch < ' ') ||
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2834
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2835
		 (ch == ' ' ) || (ch == '\t') || (ch == '\r')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2836
	      || (ch == '\n') || (ch == 0x0b));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2837
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2838
	len = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2839
	while (ret > 0 && 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2840
	       (((ch >= 'a') && (ch <= 'z')) ||
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2841
		((ch >= 'A') && (ch <= 'Z')) ||
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2842
		((ch >= '0') && (ch <= '9')))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2843
	) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2844
	    buffer[len++] = ch;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2845
	    if (len >= (sizeof(buffer)-1)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2846
		/* emergency */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2847
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2848
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2849
	    __READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2850
	    if (ret > 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2851
		cnt++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2852
	    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2853
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2854
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2855
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2856
	if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2857
	    if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2858
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2859
		goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2860
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2861
	    else if (ret == 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2862
		__INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2863
	} else {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2864
	    __UNGETC__(ch, f, _buffered);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2865
	    cnt--;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2866
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2867
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2868
	if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2869
	    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + cnt);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2870
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2871
	if (len != 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2872
	    buffer[len] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2873
	    RETURN ( __MKSTRING_L(buffer, len) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2874
	}
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2875
    }
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2876
err: ;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2877
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2878
    hitEOF ifTrue:[^ self pastEnd].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2879
    lastErrorNumber notNil ifTrue:[^ self readError].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2880
    filePointer isNil ifTrue:[^ self errorNotOpen].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2881
    ^ self errorWriteOnly
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2882
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2883
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2884
nextChunk
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2885
    "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
  2886
     exclamation mark. Within the chunk, exclamation marks have to be doubled -
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2887
     except within primitive code (this exception was added to make it easier
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2888
     to edit primitive code with external editors). This means, that other
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2889
     Smalltalks cannot always read chunks containing primitive code - but that
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2890
     doesnt really matter, since C-primitives are an ST/X feature anyway.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2891
     Reimplemented here for more speed."
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2892
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  2893
    |retVal outOfMemory buffer|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2894
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2895
    filePointer isNil ifTrue:[^ self errorNotOpen].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2896
    binary ifTrue:[^ self errorBinary].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2897
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2898
2854
3c8bf66e4e7d give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents: 2766
diff changeset
  2899
%{  /* 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
  2900
    /*
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  2901
     * the main trick (and a bit of complication) here
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2902
     * is to read the first 7k into a stack-buffer.
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  2903
     * 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
  2904
     * 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
  2905
     */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2906
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2907
    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
  2908
    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
  2909
    int ret;
1823
51ffb7231437 type casts
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  2910
    unsigned char *bufferPtr = (unsigned char *)0;
2764
2a69c1c354a2 unsigned vs. signed to avoid warnings
Claus Gittinger <cg@exept.de>
parents: 2679
diff changeset
  2911
    unsigned char fastBuffer[7000];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2912
    REGISTER int index;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2913
    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
  2914
    int atBeginOfLine = 1, inPrimitive = 0;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2915
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2916
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2917
    f = __FILEVal(__INST(filePointer));
668
73165201a9da nextChunk: %{ is only recognized if at begin-of-line
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  2918
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2919
    _buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2920
    if (_buffered) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2921
        __READING__(f)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2922
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2923
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2924
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2925
     * skip spaces
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2926
     */
673
2c3a4a536cd1 oops - handling of exclas within primitives was wrong
Claus Gittinger <cg@exept.de>
parents: 671
diff changeset
  2927
    c = '\n';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2928
    while (! done) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2929
        lastC = c;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2930
        __READBYTE__(ret, f, &c, _buffered);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2931
        if (ret <= 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2932
            goto err;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2933
        }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2934
        nread++;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2935
        atBeginOfLine = 0;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2936
        switch (c) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2937
            case '\n':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2938
            case ' ':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2939
            case '\t':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2940
            case '\r':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2941
            case '\b':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2942
            case '\014':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2943
                break;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2944
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2945
            default:
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2946
                atBeginOfLine = (lastC == '\n');
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2947
                done = 1;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2948
                break;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2949
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2950
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2951
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2952
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2953
     * read chunk into a buffer
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2954
     */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  2955
    bufferPtr = fastBuffer; fastFlag = 1;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2956
    currSize = sizeof(fastBuffer);
362
claus
parents: 360
diff changeset
  2957
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2958
    index = 0;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2959
    for (;;) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2960
        __READBYTE__(ret, f, &peekC, _buffered);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2961
        if ((c == '%') && atBeginOfLine && ret > 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2962
            if (peekC == '{') {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2963
                inPrimitive = 1;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2964
            } else if (peekC == '}') {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2965
                inPrimitive = 0;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2966
            }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2967
        } else if (c == '!' && !inPrimitive) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2968
            if (ret > 0 && peekC == '!') {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2969
                /*
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2970
                 * convert double-! to a single !
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2971
                 */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2972
                __READBYTE__(ret, f, &peekC, _buffered);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2973
                if (ret > 0)
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2974
                    nread++;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2975
            } else {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2976
                /*
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2977
                 * End of chunk, push back lookahead character
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2978
                 * and leave loop.
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2979
                 */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2980
                if (ret > 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2981
                    __UNGETC__(peekC, f, _buffered);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2982
                } else
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2983
                    ret = 1;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2984
                break; 
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2985
            }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2986
        }
2854
3c8bf66e4e7d give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents: 2766
diff changeset
  2987
        if (!fastFlag) {
3c8bf66e4e7d give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents: 2766
diff changeset
  2988
            /*
3c8bf66e4e7d give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents: 2766
diff changeset
  2989
             * old buffer may have moved - refetch pointer
3c8bf66e4e7d give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents: 2766
diff changeset
  2990
             */
3c8bf66e4e7d give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents: 2766
diff changeset
  2991
            bufferPtr = __stringVal(buffer);
3c8bf66e4e7d give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents: 2766
diff changeset
  2992
        }
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2993
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2994
        /* 
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2995
         * do we have to resize the buffer ? 
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2996
         */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2997
        if ((index+2) >= currSize) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2998
            OBJ newBuffer;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  2999
            unsigned char *nbp;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3000
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3001
            newBuffer = __MKEMPTYSTRING(currSize * 2);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3002
            if (newBuffer == nil) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3003
                /*
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3004
                 * mhmh - chunk seems to be very big ....
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3005
                 */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3006
                outOfMemory = true;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3007
                goto err;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3008
            }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3009
            nbp = __stringVal(newBuffer);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3010
            bcopy(bufferPtr, nbp, index);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3011
            bufferPtr = nbp;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3012
            bufferPtr[index] = '\0';
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3013
            buffer = newBuffer;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3014
            fastFlag = 0;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3015
            currSize = currSize * 2;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3016
        }
2854
3c8bf66e4e7d give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents: 2766
diff changeset
  3017
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3018
        /*
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3019
         * filter out cr-nl; make it nl
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3020
         */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3021
        if (c == '\n') {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3022
            if (index > 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3023
                if (bufferPtr[index-1] == '\r') {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3024
                    index--;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3025
                }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3026
            }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3027
        }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3028
        bufferPtr[index++] = c;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3029
        if (ret <= 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3030
            if (ret == 0)
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3031
                break;          /* End of chunk reached */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3032
            goto err;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3033
        }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3034
        nread++;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3035
        atBeginOfLine = (c == '\n');
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3036
        c = peekC;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3037
    }
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3038
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3039
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3040
     * 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
  3041
     * 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
  3042
     * 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
  3043
     * fast (C) buffer or from real (ST) buffer.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3044
     */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3045
    if (fastFlag) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3046
        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
  3047
    } else {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3048
        retVal = __MKSTRING_ST_L(buffer, index);
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3049
    }
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3050
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  3051
err: ;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3052
    if (ret <= 0) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3053
        if (ret == 0)
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3054
            __INST(hitEOF) = true;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3055
        else /* ret < 0 */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3056
            __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
  3057
    }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3058
    if (__INST(position) != nil) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3059
        __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
  3060
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3061
%}.
370
claus
parents: 369
diff changeset
  3062
    retVal isNil ifTrue:[
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3063
        "/
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3064
        "/ 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
  3065
        "/ or if running out of malloc-memory
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3066
        "/
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3067
        hitEOF ifTrue:[^ self pastEnd].
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3068
        lastErrorNumber notNil ifTrue:[^ self readError].
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3069
        outOfMemory == true ifTrue:[
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3070
            "
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3071
             buffer memory allocation failed.
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3072
             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
  3073
             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
  3074
             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
  3075
            "
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3076
            ^ ObjectMemory allocationFailureSignal raise.
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3077
        ]
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3078
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3079
    ^ retVal
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3080
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3081
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3082
nextMatchFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3083
    "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
  3084
     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
  3085
     the element after anObject.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3086
     Only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3087
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3088
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3089
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3090
    int ret, peekValue;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3091
    char c;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3092
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3093
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3094
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3095
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3096
	&& (__INST(mode) != @symbol(writeonly))
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3097
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3098
	if ((__INST(binary) == true) && __isSmallInteger(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3099
	    peekValue = __intVal(anObject) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3100
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3101
	    if ((__INST(binary) != true) && __isCharacter(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3102
		peekValue = __intVal(_characterVal(anObject)) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3103
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3104
		peekValue = -1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3105
	    }   
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3106
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3107
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3108
	if (peekValue >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3109
	    int _buffered;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3110
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3111
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3112
	    f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3113
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3114
	    if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3115
		__READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3116
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3117
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3118
	    for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3119
		__READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3120
		if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3121
		    if (ret < 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3122
			__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3123
		    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3124
			__INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3125
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3126
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3127
		if (c == peekValue) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3128
		    RETURN (anObject);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3129
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3130
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3131
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3132
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3133
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3134
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3135
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3136
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3137
    ^ super nextMatchFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3138
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3139
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3140
peekFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3141
    "return true and move past next element, if next == something.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3142
     Otherwise, stay and return false. False is also returned
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3143
     when EOF is encountered.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3144
     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
  3145
     text mode; only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3146
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3147
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3148
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3149
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3150
    int ret, peekValue, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3151
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3152
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3153
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3154
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3155
	&& (__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
  3156
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3157
	if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3158
	    if (__isSmallInteger(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3159
		peekValue = __intVal(anObject) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3160
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3161
		goto bad;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3162
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3163
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3164
	    if (__isCharacter(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3165
		peekValue = __intVal(_characterVal(anObject)) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3166
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3167
		goto bad;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3168
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3169
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3170
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3171
	f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3172
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3173
	_buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3174
	if (_buffered) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3175
	    __READING__(f)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3176
	}
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3177
	__READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3178
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3179
	    if (c == peekValue) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3180
		OBJ pos;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3181
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3182
		if ((pos = __INST(position)) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3183
		    __INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3184
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3185
		RETURN (true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3186
	    }
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3187
	    __UNGETC__(c, f, _buffered);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3188
	    RETURN (false);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3189
	} 
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3190
	if (ret < 0) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3191
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3192
	} else /* ret == 0 */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3193
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3194
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3195
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3196
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3197
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3198
    hitEOF ifTrue:[self pastEnd. ^ false].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3199
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3200
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3201
    ^ super peekFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3202
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3203
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3204
skipLine
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3205
    "read the next line (characters up to newline) skip only;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3206
     return nil if EOF reached, self otherwise. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3207
     Not allowed in binary mode."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3208
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3209
%{  /* STACK:2000 */
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3210
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3211
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3212
    OBJ fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3213
    int ret, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3214
    char c;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3215
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3216
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3217
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3218
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3219
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3220
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3221
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3222
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3223
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3224
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3225
	for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3226
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3227
	    if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3228
		if (c == '\n')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3229
		    RETURN(self) 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3230
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3231
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3232
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3233
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3234
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3235
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3236
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3237
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3238
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3239
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3240
    hitEOF ifTrue:[^ self pastEnd].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3241
    lastErrorNumber notNil ifTrue:[self readError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3242
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3243
    binary ifTrue:[self errorBinary. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3244
    self errorWriteOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3245
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3246
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3247
skipSeparators
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3248
    "skip all whitespace; next will return next non-white-space character
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3249
     or nil if endOfFile reached. Not allowed in binary mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3250
     - reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3251
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3252
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3253
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3254
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3255
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3256
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3257
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3258
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3259
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3260
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3261
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3262
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3263
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3264
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3265
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3266
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3267
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3268
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3269
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3270
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3271
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3272
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3273
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3274
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3275
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3276
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3277
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3278
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3279
	    switch (c) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3280
		case ' ':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3281
		case '\t':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3282
		case '\n':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3283
		case '\r':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3284
		case '\b':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3285
		case '\f':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3286
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3287
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3288
		default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3289
		    __UNGETC__(c, f, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3290
		    RETURN ( __MKCHARACTER(c & 0xFF) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3291
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3292
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3293
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3294
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3295
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3296
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3297
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3298
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3299
    ^ self errorBinary.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3300
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3301
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3302
skipSeparatorsExceptCR
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3303
    "skip all whitespace but no newlines;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3304
     next will return next non-white-space character
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3305
     or nil if endOfFile reached. Not allowed in binary mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3306
     - reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3307
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3308
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3309
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3310
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3311
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3312
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3313
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3314
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3315
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3316
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3317
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3318
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3319
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3320
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3321
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3322
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3323
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3324
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3325
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3326
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3327
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3328
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3329
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3330
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3331
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3332
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3333
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3334
	    switch (c) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3335
		case ' ':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3336
		case '\t':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3337
		case '\b':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3338
		case '\f':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3339
		    break;
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
		default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3342
		    __UNGETC__(c, f, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3343
		    RETURN ( __MKCHARACTER(c & 0xFF) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3344
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3345
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3346
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3347
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3348
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3349
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3350
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3351
    (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
  3352
    ^ self errorBinary.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3353
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3354
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3355
skipThrough:aCharacter
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3356
    "skip all characters up-to and including aCharacter. Return the receiver if
671
53de87163ad5 spelling
Claus Gittinger <cg@exept.de>
parents: 668
diff changeset
  3357
     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
  3358
     The next read operation will return the character after aCharacter.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3359
     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
  3360
     Only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3361
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3362
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3363
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3364
    REGISTER int cSearch;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3365
    unsigned char c;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3366
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3367
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3368
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3369
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3370
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3371
	&& (__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
  3372
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3373
	if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3374
	    /* searched for object must be a smallInteger */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3375
	    if (! __isSmallInteger(aCharacter)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3376
	    cSearch = __intVal(aCharacter);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3377
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3378
	    /* searched for object must be a character */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3379
	    if (! __isCharacter(aCharacter)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3380
	    cSearch = __intVal(_characterVal(aCharacter));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3381
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3382
	/* Q: should we just say: "not found" ? */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3383
	if ((cSearch < 0) || (cSearch > 255)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3384
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3385
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3386
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3387
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3388
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3389
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3390
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3391
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3392
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3393
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3394
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3395
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3396
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3397
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3398
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3399
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3400
	    if (c == cSearch) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3401
		RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3402
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3403
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3404
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3405
badArgument: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3406
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3407
    hitEOF ifTrue:[^ self pastEnd].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3408
    lastErrorNumber notNil ifTrue:[self readError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3409
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3410
    (mode == #writeonly) ifTrue:[self errorWriteOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3411
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3412
     argument must be integer/character in binary mode, 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3413
     character in text mode
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3414
    "
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3415
    self error:'invalid argument'.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3416
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3417
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3418
     |s|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3419
     s := 'Makefile' asFilename readStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3420
     s skipThrough:$=.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3421
     s next:10
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3422
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3423
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3424
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3425
skipToAll:aString
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3426
    "skip for the sequence given by the argument, aCollection;
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3427
     return nil if not found, self otherwise. 
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3428
     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
  3429
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3430
    |oldPos|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3431
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3432
    oldPos := self position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3433
    (self skipThroughAll:aString) isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3434
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3435
	 restore position
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3436
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3437
	self position:oldPos.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3438
	^ nil
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3439
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3440
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3441
     position before match-string
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3442
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3443
    self position:(self position - aString size).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3444
    ^ self
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3445
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3446
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3447
     |s|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3448
     s := 'Makefile' asFilename readStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3449
     s skipToAll:'are'.
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3450
     s next:10 
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3451
    "
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3452
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3453
    "Modified: 26.6.1996 / 09:22:05 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3454
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3455
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3456
!ExternalStream methodsFor:'testing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3457
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3458
atEnd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3459
    "return true, if position is at end"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3460
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3461
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3462
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3463
    OBJ fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3464
    char c;
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3465
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3466
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3467
    if (__INST(hitEOF) == true) {
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3468
        RETURN (true);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3469
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3470
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3471
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3472
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3473
    if ((fp = __INST(filePointer)) != nil) {
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3474
        f = __FILEVal(fp);
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3475
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3476
        if (_buffered = (__INST(buffered) == true)) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3477
            __READING__(f);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3478
        } else {
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3479
            if (__INST(readAhead) != nil) {
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3480
                RETURN (false);
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3481
            }
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3482
        }
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3483
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3484
        /*
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3485
         * read ahead ...
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3486
         */
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3487
        __READBYTE__(ret, f, &c, _buffered);
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3488
        if (ret > 0) {
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3489
            __UNGETC__(c&0xff, f, _buffered);
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3490
            RETURN (false);
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3491
        }
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3492
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3493
        if (ret == 0) { 
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3494
            __INST(hitEOF) = true;
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3495
            RETURN (true);
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3496
        }
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3497
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3498
        /* ret < 0 */
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3499
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3500
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3501
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3502
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3503
    ^ self errorNotOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3504
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3505
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3506
canReadWithoutBlocking
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3507
    "return true, if any data is available for reading (i.e.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3508
     a read operation will not block the smalltalk process), false otherwise."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3509
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3510
    |fd|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3511
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3512
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3513
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3514
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3515
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3516
    ^ OperatingSystem readCheck:fd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3517
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3518
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3519
     |pipe|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3520
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3521
     pipe := PipeStream readingFrom:'(sleep 10; echo hello)'.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3522
     pipe canReadWithoutBlocking ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3523
	 Transcript showCR:'data available'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3524
     ] ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3525
	 Transcript showCR:'no data available'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3526
     ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3527
     pipe close
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3528
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3529
!
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
canWriteWithoutBlocking
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3532
    "return true, if data can be written into the stream 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3533
     (i.e. a write operation will not block the smalltalk process)."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3534
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3535
    |fd|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3536
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3537
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3538
    mode == #readonly ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3539
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3540
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3541
    ^ OperatingSystem writeCheck:fd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3542
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3543
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3544
!ExternalStream methodsFor:'waiting for I/O'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3545
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3546
readWait
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3547
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3548
     becomes ready for reading. If data is already available,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3549
     return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3550
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3551
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3552
    self readWaitWithTimeoutMs:nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3553
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3554
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3555
readWaitWithTimeout:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3556
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3557
     becomes ready for reading or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3558
     If data is already available, return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3559
     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
  3560
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3561
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3562
    ^ self readWaitWithTimeoutMs:timeout * 1000
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3563
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3564
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3565
readWaitWithTimeoutMs:timeout 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3566
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3567
     becomes ready for reading or a timeout (in milliseconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3568
     If data is already available, return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3569
     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
  3570
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3571
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3572
    |fd inputSema hasData wasBlocked|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3573
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3574
    readAhead notNil ifTrue:[^ false].
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3575
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3576
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3577
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3578
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3579
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3580
    (OperatingSystem readCheck:fd) ifTrue:[^ false].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3581
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3582
    wasBlocked := OperatingSystem blockInterrupts.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3583
    hasData := OperatingSystem readCheck:fd.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3584
    hasData ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3585
	inputSema := Semaphore new name:'readWait'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3586
	[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3587
	    timeout notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3588
		Processor signal:inputSema afterMilliseconds:timeout 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3589
	    ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3590
	    Processor signal:inputSema onInput:fd.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3591
	    Processor activeProcess state:#ioWait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3592
	    inputSema wait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3593
	    Processor disableSemaphore:inputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3594
	    hasData := OperatingSystem readCheck:fd
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3595
	] valueOnUnwindDo:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3596
	    Processor disableSemaphore:inputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3597
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3598
	]
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3599
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3600
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3601
    ^ hasData not
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3602
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3603
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3604
writeWait
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3605
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3606
     becomes ready for writing.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3607
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3608
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3609
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3610
    self writeWaitWithTimeoutMs:nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3611
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3613
writeWaitWithTimeout:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3614
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3615
     becomes ready for writing or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3616
     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
  3617
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3618
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3619
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3620
    ^ self writeWaitWithTimeoutMs:timeout * 1000
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3621
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3622
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3623
writeWaitWithTimeoutMs:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3624
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3625
     becomes ready for writing or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3626
     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
  3627
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3628
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3629
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3630
    |fd outputSema canWrite wasBlocked|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3631
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3632
    filePointer isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3633
	^ self errorNotOpen
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
    mode == #readonly ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3636
	^ self errorReadOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3637
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3638
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3639
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3640
    (OperatingSystem writeCheck:fd) ifTrue:[^ false].
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
    wasBlocked := OperatingSystem blockInterrupts.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3643
    canWrite := OperatingSystem writeCheck:fd.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3644
    canWrite ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3645
	outputSema := Semaphore new name:'writeWait'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3646
	[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3647
	    timeout notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3648
		Processor signal:outputSema afterMilliseconds:timeout
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3649
	    ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3650
	    Processor signal:outputSema onOutput:fd.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3651
	    Processor activeProcess state:#ioWait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3652
	    outputSema wait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3653
	    Processor disableSemaphore:outputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3654
	    canWrite := OperatingSystem writeCheck:fd
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3655
	] valueOnUnwindDo:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3656
	    Processor disableSemaphore:outputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3657
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3658
	]
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
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3661
    ^ canWrite not
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3662
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3663
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3664
!ExternalStream methodsFor:'writing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3665
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3666
cr
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3667
    "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
  3668
     reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3669
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3670
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3671
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3672
    int len, cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3673
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3674
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3675
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3676
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3677
    if (((fp = __INST(filePointer)) != nil)
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3678
	&& (__INST(mode) != @symbol(readonly))
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3679
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3680
    ) {
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3681
	f = __FILEVal(fp);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3682
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3683
	if (_buffered = (__INST(buffered) == true)) { 
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3684
	    __WRITING__(f)
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3685
	}
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3686
	if (__INST(useCRLF) == true) {
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3687
	    cp = "\r\n"; len = 2;
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3688
	} else {
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3689
	    cp = "\n"; len = 1;
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3690
	}
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3691
	__WRITEBYTES__(cnt, f, cp, len, _buffered);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3692
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3693
	if (cnt == len) {
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3694
	    if (__INST(position) != nil) {
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3695
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + len);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3696
	    }
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3697
	    RETURN ( self );
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3698
	}
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3699
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3700
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3701
%}.
2326
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3702
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3703
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3704
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3705
    self errorBinary
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3706
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3707
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3708
flush
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3709
    "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
  3710
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3711
%{
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3712
    OBJ fp;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3713
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3714
    __INST(lastErrorNumber) = nil;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3715
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3716
	if (__INST(mode) != @symbol(readonly)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3717
	    if (__INST(buffered) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3718
		__BEGIN_INTERRUPTABLE__
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3719
		FFLUSH( __FILEVal(fp) );
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3720
		__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3721
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3722
	}
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3723
    }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3724
%}
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3725
!
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3726
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3727
nextPut:aCharacter
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3728
    "write the argument, aCharacter - return nil if failed, self if ok.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3729
     Only single-byte characters are currently supported"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3730
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3731
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3732
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3733
    char c;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3734
    int cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3735
    OBJ pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3736
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3737
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3738
    if (((fp = __INST(filePointer)) != nil) 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3739
	&& (__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
  3740
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3741
	if (__INST(binary) != true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3742
	    if (__isCharacter(aCharacter)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3743
		c = __intVal(__characterVal(aCharacter)) & 0xFF;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3744
    doWrite:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3745
		f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3746
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3747
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3748
		if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3749
		    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3750
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3751
		__WRITEBYTE__(cnt, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3752
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3753
		if (cnt == 1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3754
		    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3755
		    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3756
			__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3757
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3758
		    RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3759
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3760
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3761
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3762
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3763
	    if (__isSmallInteger(aCharacter)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3764
		c = __intVal(aCharacter);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3765
		goto doWrite;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3766
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3767
	}
612
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
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3770
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3771
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3772
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3773
    binary ifFalse:[self argumentMustBeCharacter. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3774
    self argumentMustBeInteger.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3775
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3776
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3777
nextPutAll:aCollection
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3778
    "write all elements of the argument, aCollection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3779
     Reimplemented for speed when writing strings or byteArrays.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3780
     For others, falls back to general method in superclass."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3781
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3782
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3783
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3784
    int len, cnt;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3785
    OBJ pos, fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3786
    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
  3787
    int o_offs;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3788
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3789
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3790
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3791
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3792
	&& (__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
  3793
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3794
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3795
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3796
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3797
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  3798
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3799
	if (__isString(aCollection) || __isSymbol(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3800
	    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
  3801
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3802
	    __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
  3803
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  3804
	    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
  3805
	    __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
  3806
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3807
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3808
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3809
		int offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3810
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3811
		if (__isByteArray(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3812
		    offs = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3813
		    len = _byteArraySize(aCollection);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3814
		} else if (__isBytes(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3815
		    offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3816
		    len = _byteArraySize(aCollection) - offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3817
		} else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3818
		    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
  3819
#ifdef BUGGY
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  3820
		__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
  3821
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  3822
		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
  3823
		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
  3824
		__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
  3825
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3826
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3827
		goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3828
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  3829
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3830
	if (cnt == len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3831
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3832
	    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3833
		__INST(position) = __MKSMALLINT(__intVal(pos) + len);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3834
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3835
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3836
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3837
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3838
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  3839
out: ;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3840
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3841
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3842
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3843
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3844
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3845
    ^ super nextPutAll:aCollection
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3848
nextPutAll:aCollection startingAt:start to:stop
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3849
    "write a range of elements of the argument, aCollection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3850
     Reimplemented for speed when writing strings or byteArrays.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3851
     For others, falls back to general method in superclass."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3852
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3853
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3854
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3855
    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
  3856
    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
  3857
    int o_offs;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3858
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3859
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3860
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3861
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3862
	&& __bothSmallInteger(start, stop)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3863
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3864
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3865
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3866
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3867
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3868
	iStart = __intVal(start);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3869
	iStop = __intVal(stop);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3870
	if ((iStart < 1) || (iStop < iStart)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3871
	    RETURN(self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3872
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3873
	if (__isString(aCollection) || __isSymbol(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3874
	    len = __stringSize(aCollection);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3875
	    if (iStop > len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3876
		RETURN(self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3877
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3878
	    if (iStop > len)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3879
		iStop = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3880
	    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
  3881
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3882
	    __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
  3883
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  3884
	    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
  3885
	    __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
  3886
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3887
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3888
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3889
		int offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3890
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3891
		if (__isByteArray(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3892
		    offs = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3893
		    len = _byteArraySize(aCollection);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3894
		} else if (__isBytes(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3895
		    offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3896
		    len = _byteArraySize(aCollection) - offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3897
		} else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3898
		    goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3899
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3900
		if (iStop > len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3901
		    RETURN(self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3902
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3903
		if (iStop > len)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3904
		    iStop = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3905
		len = iStop - iStart + 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3906
		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
  3907
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3908
		__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
  3909
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  3910
		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
  3911
		__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
  3912
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3913
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3914
		goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3915
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3916
	if (cnt == len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3917
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3918
	    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3919
		__INST(position) = __MKSMALLINT(__intVal(pos) + len);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3920
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3921
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3922
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3923
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3924
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  3925
out: ;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3926
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3927
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3928
    ^ super nextPutAll:aCollection startingAt:start to:stop
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3929
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3930
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3931
!ExternalStream class methodsFor:'documentation'!
730
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  3932
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  3933
version
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3934
    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.137 1997-08-19 09:16:52 stefan Exp $'
730
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  3935
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3936
ExternalStream initialize!