ExternalStream.st
author Claus Gittinger <cg@exept.de>
Sat, 04 Oct 1997 19:01:30 +0200
changeset 2998 930360fb3f12
parent 2986 c6957cf6128f
child 2999 b0e55440cf12
permissions -rw-r--r--
#size is not really obsolete
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
ReadWriteStream subclass:#ExternalStream
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
    14
	instanceVariableNames:'filePointer mode buffered binary eolMode hitEOF didWrite
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    15
		lastErrorNumber readAhead'
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    16
	classVariableNames:'Lobby LastErrorNumber InvalidReadSignal InvalidWriteSignal
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    17
		InvalidModeSignal OpenErrorSignal StreamNotOpenSignal
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
    18
		InvalidOperationSignal DefaultEOLMode ReadMode ReadWriteMode
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
    19
		WriteMode AppendMode CreateReadWriteMode'
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    20
	poolDictionaries:''
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
    21
	category:'Streams-External'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    24
!ExternalStream primitiveDefinitions!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    25
%{
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
    26
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
    27
#ifdef __openVMS__                                        
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
    28
# undef __new    
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
    29
#endif
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
    30
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    31
#include <stdio.h>
437
claus
parents: 436
diff changeset
    32
#define _STDIO_H_INCLUDED_
claus
parents: 436
diff changeset
    33
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    34
#ifndef NO_FCNTL_H
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    35
# include <fcntl.h>
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    36
# define _FCNTL_H_INCLUDED_
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
    37
#endif
437
claus
parents: 436
diff changeset
    38
10
claus
parents: 5
diff changeset
    39
#include <errno.h>
437
claus
parents: 436
diff changeset
    40
#define _ERRNO_H_INCLUDED_
42
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    41
1141
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    42
#ifdef LINUX
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    43
  /* use inline string macros */
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    44
# define __STRINGDEFS__
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    45
# include <linuxIntern.h>
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    46
#endif
8ea1b43f7034 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    47
42
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    48
#ifdef hpux
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    49
# define fileno(f)      ((f->__fileH << 8) | (f->__fileL))
e33491f6f260 *** empty log message ***
claus
parents: 38
diff changeset
    50
#endif
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
    51
933
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    52
#ifndef SEEK_SET
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    53
# define SEEK_SET 0
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    54
#endif
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    55
#ifndef SEEK_CUR
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    56
# define SEEK_CUR 1
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    57
#endif
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    58
#ifndef SEEK_END
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    59
# define SEEK_END 2
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    60
#endif
2eebae059045 oops - when truncating buffered streams, we must flush & seek first (stdio trouble)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
    61
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    62
#ifdef __VMS__
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    63
# define CLEAR_ERRNO		errno = 0;
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    64
#else
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    65
# define CLEAR_ERRNO		/* nothing */
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    66
#endif
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
    67
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    68
#ifdef xxxWIN32
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    69
# define NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    70
# 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
    71
# define READ(f, cp, n)		_lread((f), (cp), (n))
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    72
# define WRITE(f, cp, n)	_lwrite((f), (cp), (n))
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    73
# define FFLUSH(fp)		/* nothing */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    74
# undef STDIO_NEEDS_FSEEK
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    75
# define FILEPOINTER		HFILE
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    76
# define FILENO(f)		(f)
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    77
#else
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    78
# define STDIO_NEEDS_FSEEK
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    79
# define FILEPOINTER		FILE *
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    80
# define READ(f, cp, n)		read(f, cp, n)
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    81
# define WRITE(f, cp, n)	write(f, cp, n)
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    82
# define FFLUSH(fp)		fflush(fp)
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    83
# define FILENO(f)		fileno(f)
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    84
#endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    85
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    86
2596
36c872e47b00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2593
diff changeset
    87
#if defined(WIN32) && defined(NO_STDIO)
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    88
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    89
# ifdef i386
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    90
#  define _X86_
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    91
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    92
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    93
# undef INT
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    94
# undef Array
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    95
# undef Number
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    96
# undef Method
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    97
# undef Point
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    98
# undef Rectangle
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
    99
# undef Block
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   100
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   101
/* # include <windows.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   102
# include <stdarg.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   103
# include <windef.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   104
# include <winbase.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   105
# include <wingdi.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   106
# include <winuser.h> /* */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   107
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   108
# ifdef __DEF_Array
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   109
#   define Array __DEF_Array
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   110
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   111
# ifdef __DEF_Number
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   112
#   define Number __DEF_Number
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   113
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   114
# ifdef __DEF_Method
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   115
#   define Method __DEF_Method
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   116
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   117
# ifdef __DEF_Point
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   118
#   define Point __DEF_Point
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   119
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   120
# ifdef __DEF_Block
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   121
#   define Block __DEF_Block
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   122
# endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   123
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   124
# define stat _stat
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   125
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   126
#endif /* WIN32 */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   127
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   128
/*
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   129
 * stdio library requires an fseek before reading whenever a file
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   130
 * is open for read/write and the last operation was a write.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   131
 * (also vice-versa).
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   132
 * All code should use the following macro before doing reads:
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   133
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   134
#ifdef STDIO_NEEDS_FSEEK
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   135
# define OPT_FSEEK(f, pos, whence)	fseek(f, pos, whence)
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   136
#else
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   137
# define OPT_FSEEK(f, pos, whence)	/* nothing */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   138
#endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   139
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   140
#define __READING__(f)                          \
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   141
    if ((__INST(didWrite) != false)              \
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   142
     && (__INST(mode) == @symbol(readwrite))) {  \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   143
	__INST(didWrite) = false;                \
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   144
	OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   145
    }
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   146
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   147
#define __WRITING__(f)                          \
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   148
    if ((__INST(didWrite) != true)               \
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
   149
     && (__INST(mode) == @symbol(readwrite))) {  \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   150
	__INST(didWrite) = true;                 \
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   151
	OPT_FSEEK(f, 0L, SEEK_CUR); /* needed in stdio */  \
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   152
    }
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   153
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   154
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   155
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   156
#define __UNGETC__(c, f, isBuffered)                    \
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
   157
    __INST(readAhead) = __MKSMALLINT((c));
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   158
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   159
#define __UNGETC__(c, f, isBuffered)                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   160
    if (isBuffered) {                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   161
	ungetc((c), (f));                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   162
    } else {                                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   163
	__INST(readAhead) = __MKSMALLINT((c));          \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   164
    }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   165
#endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   166
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   167
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   168
#define __READBYTE__(ret, f, buf, isBuffered)           \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   169
    {                                            	\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   170
	OBJ rA = __INST(readAhead);                     \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   171
	if (rA != nil) {                                \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   172
	    *(buf) = __intVal(rA);                      \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   173
	    __INST(readAhead) = nil;                    \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   174
	    (ret) = 1;                                  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   175
	} else {                                        \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   176
	    for (;;) {                                  \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   177
		CLEAR_ERRNO;				\
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   178
		(ret) = READ(f, buf, 1);        	\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   179
		if ((ret) >= 0 || errno != EINTR)       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   180
		    break;                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   181
		__HANDLE_INTERRUPTS__;                  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   182
	    }                                           \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   183
	}                                               \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   184
    }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   185
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   186
#define __READBYTE__(ret, f, buf, isBuffered)           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   187
    if (isBuffered) {                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   188
	for (;;) {                                      \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   189
	    CLEAR_ERRNO;				\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   190
	    (ret) = getc(f);                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   191
	    if ((ret) >= 0) {                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   192
		*(buf) = (ret);                         \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   193
		(ret) = 1;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   194
	    } else if (ferror(f)) {                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   195
		if (errno == EINTR) {                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   196
		    __HANDLE_INTERRUPTS__;              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   197
		    clearerr(f);                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   198
		    continue;                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   199
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   200
	    } else                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   201
		(ret) = 0;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   202
	    break;                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   203
	}                                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   204
    } else {                                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   205
	OBJ rA = __INST(readAhead);                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   206
	if (rA != nil) {                                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   207
	    *(buf) = __intVal(rA);                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   208
	    __INST(readAhead) = nil;                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   209
	    (ret) = 1;                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   210
	} else {                                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   211
	    for (;;) {                                  \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   212
	        CLEAR_ERRNO;				\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   213
		(ret) = read(fileno(f), buf, 1);        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   214
		if ((ret) >= 0 || errno != EINTR)       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   215
		    break;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   216
		__HANDLE_INTERRUPTS__;                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   217
	    }                                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   218
	}                                               \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   219
   }                                                                          
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   220
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   221
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   222
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   223
 * read_bytes into a c-buffer
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   224
 * (which may NOT move)
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   225
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   226
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   227
#define __READBYTES__(ret, f, buf, cnt, isBuffered)     \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   228
    {                                            	\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   229
	int __offs = 0;                                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   230
							\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   231
	while (__offs < (cnt)) {                        \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   232
	    OBJ rA = __INST(readAhead);                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   233
	    if (rA != nil) {                            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   234
		(buf)[__offs] = __intVal(rA);           \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   235
		__INST(readAhead) = nil;                \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   236
		(ret) = 1;                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   237
	    } else {                                    \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   238
	        CLEAR_ERRNO;				\
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   239
		(ret) = READ(f, (buf)+__offs, (cnt)-__offs); \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   240
		if ((ret) <= 0) {                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   241
		    if ((ret) < 0 && errno == EINTR) {  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   242
			__HANDLE_INTERRUPTS__;          \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   243
			continue;                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   244
		    }                                   \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   245
		    break;                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   246
		}                                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   247
	    }                                           \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   248
	    __offs += (ret);                            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   249
	}                                               \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   250
	if (__offs > 0)                                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   251
	    (ret) = __offs;                             \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   252
   }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   253
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   254
#define __READBYTES__(ret, f, buf, cnt, isBuffered)     \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   255
    (ret) = 0;                                          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   256
    if (isBuffered) {                                   \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   257
	int __offs = 0;                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   258
	while (__offs < (cnt)) {                        \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   259
	    CLEAR_ERRNO;				\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   260
	    (ret) = getc(f);                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   261
	    if ((ret) < 0) {                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   262
		if (ferror(f)) {                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   263
		    if (errno == EINTR) {               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   264
			__HANDLE_INTERRUPTS__;          \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   265
			clearerr(f);                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   266
			continue;                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   267
		    }                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   268
		} else {                                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   269
		    (ret) = 0;                          \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   270
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   271
		break;                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   272
	    }                                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   273
	    (buf)[__offs++] = (ret);                    \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   274
	}                                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   275
	if (__offs > 0)                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   276
	    (ret) = __offs;                             \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   277
    } else {                                            \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   278
	int __offs = 0;                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   279
	int fd = fileno(f);                             \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   280
							\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   281
	while (__offs < (cnt)) {                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   282
	    OBJ rA = __INST(readAhead);                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   283
	    if (rA != nil) {                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   284
		(buf)[__offs] = __intVal(rA);           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   285
		__INST(readAhead) = nil;                \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   286
		(ret) = 1;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   287
	    } else {                                    \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   288
	        CLEAR_ERRNO;				\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   289
		(ret) = read(fd, (buf)+__offs, (cnt)-__offs);                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   290
		if ((ret) <= 0) {                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   291
		    if ((ret) < 0 && errno == EINTR) {  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   292
			__HANDLE_INTERRUPTS__;          \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   293
			continue;                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   294
		    }                                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   295
		    break;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   296
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   297
	    }                                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   298
	    __offs += (ret);                            \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   299
	}                                               \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   300
	if (__offs > 0)                                 \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   301
	    (ret) = __offs;                             \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   302
   }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   303
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   304
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   305
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   306
 * read_bytes into an object
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   307
 * (which may be moved by GC)
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   308
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   309
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   310
#define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)     \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   311
  {							\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   312
    int __ooffs = obj_offs;				\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   313
    int __offs = 0;					\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   314
    char *buf = (char *)(obj);				\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   315
							\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   316
    (ret) = 0;                                          \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   317
    {                                            	\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   318
	while (__offs < (cnt)) {                        \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   319
	    OBJ rA = __INST(readAhead);                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   320
	    if (rA != nil) {                            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   321
		(buf)[__ooffs+__offs] = __intVal(rA);   \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   322
		__INST(readAhead) = nil;                \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   323
		(ret) = 1;                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   324
	    } else {                                    \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   325
	        CLEAR_ERRNO;				\
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   326
		(ret) = READ(f, (buf)+__ooffs+__offs, (cnt)-__offs); \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   327
		if ((ret) <= 0) {                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   328
		    if ((ret) < 0 && errno == EINTR) {  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   329
			__HANDLE_INTERRUPTS__;          \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   330
			/* refetch */                   \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   331
			buf = (char *)(obj);            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   332
			continue;                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   333
		    }                                   \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   334
		    break;                              \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   335
		}                                       \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   336
	    }                                           \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   337
	    __offs += (ret);                            \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   338
	}                                               \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   339
	if (__offs > 0)                                 \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   340
	    (ret) = __offs;                             \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   341
    }							\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   342
  }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   343
#else
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   344
#define __READBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)     \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   345
  {							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   346
    int __ooffs = obj_offs;				\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   347
    int __offs = 0;					\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   348
    char *buf = (char *)(obj);				\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   349
							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   350
    (ret) = 0;                                          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   351
    if (isBuffered) {                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   352
	while (__offs < (cnt)) {                        \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   353
	    CLEAR_ERRNO;				\
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   354
	    (ret) = getc(f);                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   355
	    if ((ret) < 0) {                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   356
		if (ferror(f)) {                        \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   357
		    if (errno == EINTR) {               \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   358
			__HANDLE_INTERRUPTS__;          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   359
			clearerr(f);                    \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   360
			/* refetch */                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   361
			buf = (char *)(obj);            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   362
			continue;                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   363
		    }                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   364
		} else {                                \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   365
		    (ret) = 0;                          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   366
		}                                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   367
		break;                                  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   368
	    }                                           \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   369
	    (buf)[__ooffs+__offs] = (ret);              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   370
	    __offs++;					\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   371
	}                                               \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   372
	if (__offs > 0)                                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   373
	    (ret) = __offs;                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   374
    } else {                                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   375
	int fd = fileno(f);                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   376
							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   377
	while (__offs < (cnt)) {                        \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   378
	    OBJ rA = __INST(readAhead);                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   379
	    if (rA != nil) {                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   380
		(buf)[__ooffs+__offs] = __intVal(rA);   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   381
		__INST(readAhead) = nil;                \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   382
		(ret) = 1;                              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   383
	    } else {                                    \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   384
	        CLEAR_ERRNO;				\
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   385
		(ret) = read(fd, (buf)+__ooffs+__offs, (cnt)-__offs); \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   386
		if ((ret) <= 0) {                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   387
		    if ((ret) < 0 && errno == EINTR) {  \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   388
			__HANDLE_INTERRUPTS__;          \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   389
			/* refetch */                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   390
			buf = (char *)(obj);            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   391
			continue;                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   392
		    }                                   \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   393
		    break;                              \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   394
		}                                       \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   395
	    }                                           \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   396
	    __offs += (ret);                            \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   397
	}                                               \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   398
	if (__offs > 0)                                 \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   399
	    (ret) = __offs;                             \
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   400
    }							\
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   401
  }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   402
#endif
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   403
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   404
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   405
#define __WRITEBYTE__(ret, f, buf, isBuffered)          \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   406
	for (;;) {                                      \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   407
	    CLEAR_ERRNO;				\
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   408
	    (ret) = WRITE(f, buf, 1);           	\
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   409
	    if ((ret) >= 0 || errno != EINTR)           \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   410
		break;                                  \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   411
	    __HANDLE_INTERRUPTS__;                      \
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   412
	}
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   413
#else
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   414
#define __WRITEBYTE__(ret, f, buf, isBuffered)          \
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   415
    if (isBuffered) {                                   \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   416
	for (;;) {                                      \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   417
	    CLEAR_ERRNO;				\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   418
	    ret = putc(*(buf), f);                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   419
	    if ((ret) >= 0) {                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   420
		(ret) = 1;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   421
	    } else if (ferror(f)) {                     \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   422
		if (errno == EINTR) {                   \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   423
		    __HANDLE_INTERRUPTS__;              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   424
		    clearerr(f);                        \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   425
		    continue;                           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   426
		}                                       \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   427
	    } else                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   428
		(ret) = 0;                              \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   429
	    break;                                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   430
	}                                               \
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
   431
    } else {                                            \
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   432
	for (;;) {                                      \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   433
	    CLEAR_ERRNO;				\
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   434
	    (ret) = write(fileno(f), buf, 1);           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   435
	    if ((ret) >= 0 || errno != EINTR)           \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   436
		break;                                  \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   437
	    __HANDLE_INTERRUPTS__;                      \
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   438
	}                                               \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   439
   }                                                                          
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   440
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   441
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   442
/*
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   443
 * write_bytes from a c-buffer
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   444
 * (which may NOT move)
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   445
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   446
#ifdef NO_STDIO
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   447
#define __WRITEBYTES__(ret, f, buf, cnt, isBuffered)    \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   448
    (ret) = 0;                                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   449
    {                                                   \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   450
	int __offs = 0;                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   451
	while (__offs < (cnt)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   452
	    CLEAR_ERRNO;				\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   453
	    ret = WRITE(f, (buf)+__offs, (cnt)-__offs); \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   454
	    if (ret <= 0) {                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   455
		if (ret < 0 && errno == EINTR) {        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   456
		    __HANDLE_INTERRUPTS__;              \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   457
		    continue;                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   458
		}                                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   459
		break;                                  \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   460
	    }                                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   461
	    __offs += (ret);                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   462
	}                                               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   463
	if (__offs > 0)                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   464
	    (ret) = __offs;                             \
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   465
   }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   466
#else
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   467
#define __WRITEBYTES__(ret, f, buf, cnt, isBuffered)    \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   468
    (ret) = 0;                                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   469
    if (isBuffered) {                                   \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   470
	int __offs = 0;                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   471
	while (__offs < (cnt)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   472
	    CLEAR_ERRNO;				\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   473
	    ret = fwrite((buf)+__offs, 1, (cnt)-__offs, f);\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   474
	    if ((ret) < 0) {                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   475
		if (ferror(f)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   476
		    if (errno == EINTR) {               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   477
			__HANDLE_INTERRUPTS__;          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   478
			clearerr(f);                    \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   479
			continue;                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   480
		    }                                   \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   481
		} else {                                \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   482
		    (ret) = 0;                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   483
		}                                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   484
		break;                                  \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   485
	    }                                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   486
	    __offs += (ret);                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   487
	}                                               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   488
	if (__offs > 0)                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   489
	    (ret) = __offs;                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   490
    } else {                                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   491
	int __offs = 0;                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   492
	while (__offs < (cnt)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   493
	    CLEAR_ERRNO;				\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   494
	    ret = write(fileno(f), (buf)+__offs, (cnt)-__offs);\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   495
	    if (ret <= 0) {                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   496
		if (ret < 0 && errno == EINTR) {        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   497
		    __HANDLE_INTERRUPTS__;              \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   498
		    continue;                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   499
		}                                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   500
		break;                                  \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   501
	    }                                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   502
	    __offs += (ret);                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   503
	}                                               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   504
	if (__offs > 0)                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   505
	    (ret) = __offs;                             \
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   506
   }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   507
#endif
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   508
223
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   509
/*
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   510
 * write_bytes from an object
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   511
 * (which may be moved around by GC)
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   512
 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   513
#ifdef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   514
#define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)            \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   515
  {							\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   516
    int __ooffs = obj_offs;				\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   517
    int __offs = 0;					\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   518
    char *buf = (char *)(obj);				\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   519
							\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   520
    (ret) = 0;                                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   521
    {                                                   \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   522
	while (__offs < (cnt)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   523
	    CLEAR_ERRNO;				\
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   524
	    ret = WRITE(f, (buf)+__ooffs+__offs, (cnt)-__offs);       	      \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   525
	    if (ret <= 0) {                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   526
		if (ret < 0 && errno == EINTR) {        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   527
		    __HANDLE_INTERRUPTS__;              \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   528
		    /* refetch */                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   529
		    buf = (char *)(obj);                \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   530
		    continue;                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   531
		}                                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   532
		break;                                  \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   533
	    }                                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   534
	    __offs += (ret);                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   535
	}                                               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   536
	if (__offs > 0)                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   537
	    (ret) = __offs;                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   538
    }							\
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   539
  }
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   540
#else
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   541
#define __WRITEBYTES_OBJ__(ret, f, obj, obj_offs, cnt, isBuffered)            \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   542
  {							\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   543
    int __ooffs = obj_offs;				\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   544
    int __offs = 0;					\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   545
    char *buf = (char *)(obj);				\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   546
							\
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   547
    (ret) = 0;                                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   548
    if (isBuffered) {                                   \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   549
	while (__offs < (cnt)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   550
	    CLEAR_ERRNO;				\
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   551
	    ret = fwrite((buf)+__ooffs+__offs, 1, (cnt)-__offs, f);           \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   552
	    if ((ret) < 0) {                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   553
		if (ferror(f)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   554
		    if (errno == EINTR) {               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   555
			__HANDLE_INTERRUPTS__;          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   556
			/* refetch */                   \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   557
			buf = (char *)(obj);            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   558
			clearerr(f);                    \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   559
			continue;                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   560
		    }                                   \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   561
		} else {                                \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   562
		    (ret) = 0;                          \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   563
		}                                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   564
		break;                                  \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   565
	    }                                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   566
	    __offs += (ret);                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   567
	}                                               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   568
	if (__offs > 0)                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   569
	    (ret) = __offs;                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   570
    } else {                                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   571
	while (__offs < (cnt)) {                        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   572
	    CLEAR_ERRNO;				\
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   573
	    ret = write(fileno(f), (buf)+__ooffs+__offs, (cnt)-__offs);       \
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   574
	    if (ret <= 0) {                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   575
		if (ret < 0 && errno == EINTR) {        \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   576
		    __HANDLE_INTERRUPTS__;              \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   577
		    /* refetch */                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   578
		    buf = (char *)(obj);                \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   579
		    continue;                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   580
		}                                       \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   581
		break;                                  \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   582
	    }                                           \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   583
	    __offs += (ret);                            \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   584
	}                                               \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   585
	if (__offs > 0)                                 \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   586
	    (ret) = __offs;                             \
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
   587
    }							\
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   588
  }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   589
#endif
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   590
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   591
/*
223
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   592
 * on some systems errno is a macro ... check for it here
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   593
 */
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   594
#ifndef errno
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   595
 extern errno;
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   596
#endif
3075043790b8 immediateInterr & errno cleanup
claus
parents: 216
diff changeset
   597
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   598
%}
188
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   599
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   600
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   601
!ExternalStream class methodsFor:'documentation'!
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   602
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   603
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   604
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   605
 COPYRIGHT (c) 1988 by Claus Gittinger
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   606
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   607
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   608
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   609
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   610
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   611
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   612
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   613
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   614
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   615
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   616
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   617
documentation
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   618
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   619
    ExternalStream defines protocol common to Streams which have a file-descriptor and 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   620
    represent some file or communicationChannel of the underlying OperatingSystem.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   621
    ExternalStream is abstract; concrete classes are FileStream, PipeStream etc.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   622
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   623
    ExternalStreams can be in two modes: text- (the default) and binary-mode.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   624
    In text-mode, the elements read/written are characters; 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   625
    while in binary-mode the basic elements are bytes which read/write as SmallIntegers 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   626
    in the range 0..255.
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   627
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   628
    Also, the stream can be either in buffered or unbuffered mode. In buffered mode,
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   629
    data is not written until either a cr is written (in text mode) or a synchronizeOutput
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   630
    is sent (in both modes).
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   631
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   632
    The underlying OperatingSystem streams may either be closed explicitely (sending a close)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   633
    or just forgotten - in this case, the garbage collector will eventually collect the
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   634
    object AND a close will be performed automatically (but you will NOT know when this 
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   635
    happens - so it is recommended, that you close your files when no longer needed).
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   636
    Closing is also suggested, since if smalltalk is finished (be it by purpose, or due to
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   637
    some crash) the data will not be in the file, if unclosed. 
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   638
    All streams understand the close message, so it never hurts to use it (it is defined as 
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   639
    a noop in one of the superclasses).
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   640
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   641
    Most of the methods found here redefine inherited methods for better performance,
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   642
    since I/O from/to files should be fast.
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   643
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   644
    Recovering a snapshot:
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   645
      not all streams can be restored to the state they had before - see the implementation of
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   646
      reOpen in subclasses for more information.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   647
      For streams sitting on some communication channel (i.e. Pipes and Sockets) you should
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   648
      reestablish the stream upon image restart (make someone dependent on ObjectMemory).
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   649
      FileStreams are reopened and positioned to their offset they had at snapshot time.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   650
      This may fail, if the file was removed or renamed - or lead to confusion
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   651
      if the contents changed in the meantime.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   652
      Therefore, it is a good idea to reopen files and check for these things at restart time.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   653
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   654
    [Instance variables:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   655
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   656
	filePointer     <Integer>       the unix FILE*; somehow mapped to an integer
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   657
					(notice: not the fd)
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
   658
				        on Windows: the fileHandle
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   659
	mode            <Symbol>        #readwrite, #readonly or #writeonly
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   660
	buffered        <Boolean>       true, if buffered (i.e. collects characters - does
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   661
					not output immediately)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   662
	binary          <Boolean>       true if in binary mode (reads bytes instead of chars)
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   663
	eolMode         <Symbol>        one of nil, #cr or #crlf.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   664
					determines how lines should be terminated.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   665
				        nil -> newLine (as in Unix);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   666
					#crlf -> with cr-lf (as in MSDOS)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   667
					#cr -> with cr (as in VMS)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   668
	hitEOF          <Boolean>       true, if EOF was reached
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   669
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   670
	lastErrorNumber <Integer>       the value of errno (only valid right after the error -
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   671
					updated with next i/o operation)
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   672
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   673
    [Class variables:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   674
	Lobby           <Registry>      keeps track of used ext-streams (to free up FILE*'s)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   675
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   676
	StreamErrorSignal       <Signal> parent of all stream errors (see Stream class)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   677
	InvalidReadSignal       <Signal> raised on read from writeonly stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   678
	InvalidWriteSignal      <Signal> raised on write to readonly stream 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   679
	InvalidModeSignal       <Signal> raised on text I/O with binary-stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   680
					 or binary I/O with text-stream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   681
	OpenErrorSignal         <Signal> raised if open fails
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   682
	StreamNotOpenSignal     <Signal> raised on I/O with non-open stream
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   683
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   684
    Additional notes:
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   685
      This class is implemented using the underlying stdio-c library package, which
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   686
      has both advantages and disadvantages: since it is portable (posix defined), porting
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   687
      ST/X to non-Unix machines is simplified. The disadvantage is that the stdio library
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   688
      has big problems handling unbounded Streams, since the EOF handling in stdio is
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   689
      not prepared for data to arrive after EOF has been reached - time will show, if we need
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   690
      a complete rewrite for UnboundedStream ...
325
claus
parents: 308
diff changeset
   691
188
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   692
      Also, depending on the system, the stdio library behaves infriendly when signals
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   693
      occur while reading (for example, timer interrupts) - on real unixes (i.e. BSD) the signal
454ed0ee733e EINTR problems
claus
parents: 159
diff changeset
   694
      is handled transparently - on SYS5.3 (i.e. non unixes :-) the read operation returns
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   695
      an error and errno is set to EINTR. 
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   696
      Thats what the ugly code around all getc-calls is for ...
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   697
      Since things get more and more ugly - we will rewrite ExternalStream
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   698
      completely, to NOT use any stdio stuff (and do its buffering itself).
325
claus
parents: 308
diff changeset
   699
claus
parents: 308
diff changeset
   700
      Notice that typical stdio's use a single errno global variable to return an error code,
claus
parents: 308
diff changeset
   701
      this was bad design in the stdio lib (right from the very beginning), since its much
claus
parents: 308
diff changeset
   702
      harder to deal with this in the presence of lightweight processes, where errno gets
claus
parents: 308
diff changeset
   703
      overwritten by an I/O operation done in another thread. (stdio should have been written
claus
parents: 308
diff changeset
   704
      to return errno as a negative number ...).
claus
parents: 308
diff changeset
   705
      To deal with this, the scheduler treats errno like a per-thread private variable,
claus
parents: 308
diff changeset
   706
      and saves/restores the errno setting when switching to another thread.
claus
parents: 308
diff changeset
   707
      (Notice that some thread packages do this also, but ST/X's thread implementation
claus
parents: 308
diff changeset
   708
      does not depend on those, but instead uses a portable private package).
claus
parents: 308
diff changeset
   709
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   710
      Finally, if an stdio-stream is open for both reading and writing, we have to call
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   711
      fseek whenever we are about to read after write and vice versa.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   712
      Two macros (__READING__ and __WRITING__) have been defined to be used before every
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   713
      fread/fgetc and fwrite/putc respectively.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   714
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   715
    [author:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   716
	Claus Gittinger
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   717
	Stefan Vogel (many, many fixes ...)
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   718
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
   719
    [see also:]
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   720
	FileStream Socket PipeStream
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   721
	Filename OperatingSystem
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   722
"
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   723
! !
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
   724
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   725
!ExternalStream class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   726
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   727
initDefaultEOLMode
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   728
    OperatingSystem isUNIXlike ifTrue:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   729
	"/ unix EOL conventions
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   730
	DefaultEOLMode := #nl
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   731
    ] ifFalse:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   732
	OperatingSystem isVMSlike ifTrue:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   733
	    "/ vms EOL conventions
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   734
	    DefaultEOLMode := #cr
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   735
	] ifFalse:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   736
	    "/ msdos EOL conventions
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   737
	    DefaultEOLMode := #crlf
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   738
	]
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   739
    ]
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   740
!
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   741
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   742
initModeStrings
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   743
    "initialize modeStrings which are passed down to the underlying
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   744
     fopen/fdopen functions."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   745
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   746
    ReadMode := 'r'.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   747
    ReadWriteMode := 'r+'.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   748
    WriteMode := 'w'.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   749
    AppendMode := 'a+'.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   750
    CreateReadWriteMode := 'w+'.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   751
!
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   752
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   753
initialize
593
19d568779cf7 moved StreamErrorSignal into Stream;
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   754
    OpenErrorSignal isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   755
	OpenErrorSignal := StreamErrorSignal newSignalMayProceed:true.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   756
	OpenErrorSignal nameClass:self message:#openErrorSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   757
	OpenErrorSignal notifierString:'open error'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   758
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   759
	InvalidReadSignal := ReadErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   760
	InvalidReadSignal nameClass:self message:#invalidReadSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   761
	InvalidReadSignal notifierString:'read error'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   762
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   763
	InvalidWriteSignal := WriteErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   764
	InvalidWriteSignal nameClass:self message:#invalidWriteSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   765
	InvalidWriteSignal notifierString:'write error'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   766
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   767
	InvalidModeSignal :=  StreamErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   768
	InvalidModeSignal nameClass:self message:#invalidModeSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   769
	InvalidModeSignal notifierString:'binary/text mode mismatch'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   770
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   771
	InvalidOperationSignal :=  StreamErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   772
	InvalidOperationSignal nameClass:self message:#invalidOperationSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   773
	InvalidOperationSignal notifierString:'unsupported file operation'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   774
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   775
	StreamNotOpenSignal := StreamErrorSignal newSignalMayProceed:false.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   776
	StreamNotOpenSignal nameClass:self message:#streamNotOpenSignal.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   777
	StreamNotOpenSignal notifierString:'stream is not open'.
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   778
    ].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   779
31
75f2b9f78be2 *** empty log message ***
claus
parents: 25
diff changeset
   780
    Lobby isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   781
	Lobby := Registry new.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   782
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   783
	"want to get informed when returning from snapshot"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   784
	ObjectMemory addDependent:self
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   785
    ].
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   786
    self initDefaultEOLMode.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   787
    self initModeStrings.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   788
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   789
a27a279701f8 Initial revision
claus
parents:
diff changeset
   790
reOpenFiles
a27a279701f8 Initial revision
claus
parents:
diff changeset
   791
    "reopen all files (if possible) after a snapShot load"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   792
301
35e40a6fc72b *** empty log message ***
claus
parents: 269
diff changeset
   793
    Lobby do:[:aFileStream |
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   794
	aFileStream reOpen
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   795
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   796
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   797
1469
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   798
update:something with:aParameter from:changedObject
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   799
    "have to reopen files when returning from snapshot"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   800
a27a279701f8 Initial revision
claus
parents:
diff changeset
   801
    something == #returnFromSnapshot ifTrue:[
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   802
	self reOpenFiles.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   803
        self initDefaultEOLMode
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   804
    ]
1469
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   805
570ef7f8667b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1464
diff changeset
   806
    "Created: 15.6.1996 / 15:19:59 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   807
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   808
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   809
!ExternalStream class methodsFor:'instance creation'!
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   810
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   811
forFileDescriptor:aFileDescriptor mode:modeString
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   812
    "given a fileDescriptor, create an ExternalStream object
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   813
     to operate on this fd. 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   814
     The mode-argument is passed to the fdopen call.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   815
     This may be used to wrap fd's as returned by user 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   816
     primitive code, or to wrap pipe-fds into externalStreams."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   817
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   818
    |newStream|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   819
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   820
    newStream := self basicNew.
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   821
    newStream text; buffered:true; eolMode:DefaultEOLMode; clearEOF.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   822
    ^ newStream 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   823
	connectTo:aFileDescriptor 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   824
	withMode:modeString
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   825
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   826
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   827
     the example below will probably fail (15 is a random FD):
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   828
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   829
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   830
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   831
     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
   832
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   833
    "
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
    "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
   836
    "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
   837
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   838
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   839
forReadWriteToFileDescriptor:aFileDescriptor
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   840
    "given a fileDescriptor, create an ExternalStream object
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   841
     to read/write from/to this fd. This may be used to wrap fd's
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   842
     as returned by user primitive code, or to wrap pipe-
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   843
     filedescriptors into externalStreams."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   844
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   845
    ^ self forFileDescriptor:aFileDescriptor mode:ReadWriteMode
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   846
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   847
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   848
     the example below will probably fail (15 is a random FD):
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   849
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   850
     |s|
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
     s := ExternalStream forReadWriteToFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   853
     s next.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   854
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   855
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   856
    "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
   857
    "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
   858
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   859
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   860
forReadingFromFileDescriptor:aFileDescriptor
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   861
    "given a fileDescriptor, create an ExternalStream object
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   862
     to read from this fd. This may be used to wrap fd's
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   863
     as returned by user primitive code, or to wrap pipe-
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   864
     filedescriptors into externalStreams."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   865
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   866
    ^ self forFileDescriptor:aFileDescriptor mode:ReadMode
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   867
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   868
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   869
     the example below will probably fail (15 is a random FD):
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   870
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   871
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   872
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   873
     s := ExternalStream forReadingFromFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   874
     s next.
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
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   877
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   878
     |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
   879
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   880
     'create OS pipe ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   881
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   882
     pipe := OperatingSystem makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   883
     readFd := pipe at:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   884
     writeFd := pipe at:2.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   885
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   886
     'connect Smalltalk streams ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   887
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   888
     rs := ExternalStream forReadingFromFileDescriptor:readFd.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   889
     ws := ExternalStream forWritingToFileDescriptor:writeFd.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   890
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   891
     'read ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   892
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   893
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   894
	     Transcript showCR:rs nextLine
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   895
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   896
	 rs close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   897
     ] forkAt:7.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   898
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   899
     'write ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   900
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   901
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   902
	     ws nextPutAll:'hello world '; nextPutAll:i printString; cr
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   903
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   904
	 ws close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   905
     ] fork.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   906
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   907
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   908
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   909
    "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
   910
    "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
   911
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   912
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   913
forWritingToFileDescriptor:aFileDescriptor
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   914
    "given a fileDescriptor, create an ExternalStream object
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   915
     to write to this fd. This may be used to wrap fd's
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   916
     as returned by user primitive code, or to wrap pipe-
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   917
     filedescriptors into externalStreams."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   918
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   919
    ^ self forFileDescriptor:aFileDescriptor mode:WriteMode
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   921
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   922
     the example below will probably fail (15 is a random FD):
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   923
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   924
     |s|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   925
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   926
     s := ExternalStream forWritingToFileDescriptor:15.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   927
     s binary.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   928
     s nextPut:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   929
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   930
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   931
    "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
   932
    "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
   933
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   934
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   935
makePipe
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   936
    "return an array with two streams - the first one for reading, 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   937
     the second for writing. 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   938
     This is the higher level equivalent of OperatingSystem>>makePipe
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   939
     (which returns an array of file-descriptors)."
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   940
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   941
     |pipe rs ws|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   942
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   943
     pipe := OperatingSystem makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   944
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   945
     pipe notNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   946
	 rs := self forReadingFromFileDescriptor:(pipe at:1).
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   947
	 ws := self forWritingToFileDescriptor:(pipe at:2).
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   948
	 ^ 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
   949
     ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   950
     ^ nil
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   951
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   952
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   953
     |pipe rs ws|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   954
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   955
     pipe := ExternalStream makePipe.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   956
     rs := pipe at:1.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   957
     ws := pipe at:2.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   958
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   959
     'read ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   960
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   961
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   962
	     Transcript showCR:rs nextLine
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   963
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   964
	 rs close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   965
     ] forkAt:7.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   966
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   967
     'write ...'.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   968
     [
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   969
	 1 to:10 do:[:i |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   970
	     ws nextPutAll:'hello world '; nextPutAll:i printString; cr
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   971
	 ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   972
	 ws close.
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   973
     ] fork.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   974
    "
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   975
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   976
    "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
   977
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
   978
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   979
new
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   980
    |newStream|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   981
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   982
    newStream := self basicNew.
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   983
    newStream text; buffered:true; eolMode:DefaultEOLMode; clearEOF.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   984
    ^ newStream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   985
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   986
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
   987
!ExternalStream class methodsFor:'Signal constants'!
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
   988
1522
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   989
inaccessibleSignal
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   990
    "ST-80 compatibility: return openErrorSignal"
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   991
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   992
    ^ self openErrorSignal
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   993
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   994
    "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
   995
!
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
   996
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   997
invalidModeSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   998
    "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
   999
     or binary-I/O with a text stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1000
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1001
    ^ InvalidModeSignal
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1002
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1003
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1004
invalidOperationSignal
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1005
    "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
  1006
     I/O operation is attempted"
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1007
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1008
    ^ InvalidOperationSignal
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1009
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1010
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1011
invalidReadSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1012
    "return the signal raised when reading from writeonly streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1013
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1014
    ^ InvalidReadSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1015
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1016
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1017
invalidWriteSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1018
    "return the signal raised when writing to readonly streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1019
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1020
    ^ InvalidWriteSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1021
!
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1022
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1023
openErrorSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1024
    "return the signal raised when a file open failed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1025
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1026
    ^ OpenErrorSignal
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1027
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1028
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1029
streamNotOpenSignal
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1030
    "return the signal raised on I/O with closed streams"
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1031
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1032
    ^ StreamNotOpenSignal
2
claus
parents: 1
diff changeset
  1033
! !
claus
parents: 1
diff changeset
  1034
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1035
!ExternalStream class methodsFor:'error handling'!
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1036
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1037
lastErrorNumber
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1038
    "return the errno of the last error"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1039
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1040
    ^ LastErrorNumber
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1041
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1042
    "
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1043
     ExternalStream lastErrorNumber
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1044
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1045
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1046
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1047
lastErrorString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1048
    "return a message string describing the last error"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1049
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1050
    ^ OperatingSystem errorTextForNumber:LastErrorNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1051
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1052
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1053
     ExternalStream lastErrorString
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1054
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1055
! !
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1056
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1057
!ExternalStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1058
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1059
binary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1060
    "switch to binary mode - default is text"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1061
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1062
    binary := true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1063
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1064
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1065
buffered:aBoolean
10
claus
parents: 5
diff changeset
  1066
    "turn buffering on or off - default is on"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1067
10
claus
parents: 5
diff changeset
  1068
    buffered := aBoolean
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1069
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1070
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1071
contents
2
claus
parents: 1
diff changeset
  1072
    "return the contents of the file from the current position up-to
claus
parents: 1
diff changeset
  1073
     the end. If the stream is in binary mode, a ByteArray containing
claus
parents: 1
diff changeset
  1074
     the byte values is returned.
claus
parents: 1
diff changeset
  1075
     In text-mode, a collection of strings, each representing one line,
claus
parents: 1
diff changeset
  1076
     is returned."
claus
parents: 1
diff changeset
  1077
claus
parents: 1
diff changeset
  1078
    |text l chunks sizes chunk byteCount cnt bytes offset|
claus
parents: 1
diff changeset
  1079
claus
parents: 1
diff changeset
  1080
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1081
	"adding to a ByteArray produces quadratic time-space
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1082
	 behavior - therefore we allocate chunks, and concatenate them
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1083
	 at the end."
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1084
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1085
	chunks := OrderedCollection new.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1086
	sizes := OrderedCollection new.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1087
	byteCount := 0.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1088
	[self atEnd] whileFalse:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1089
	    chunk := ByteArray uninitializedNew:4096.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1090
	    cnt := self nextBytes:(chunk size) into:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1091
	    cnt notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1092
		chunks add:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1093
		sizes add:cnt.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1094
		byteCount := byteCount + cnt
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1095
	    ]
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1096
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1097
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1098
	"now, create one big ByteArray"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1099
	bytes := ByteArray uninitializedNew:byteCount.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1100
	offset := 1.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1101
	1 to:chunks size do:[:index |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1102
	    chunk := chunks at:index.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1103
	    cnt := sizes at:index. 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1104
	    bytes replaceFrom:offset to:(offset + cnt - 1) with:chunk.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1105
	    offset := offset + cnt
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1106
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1107
	^ bytes
2
claus
parents: 1
diff changeset
  1108
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1109
244
9faa2da0650a Text <-> StringCollection
claus
parents: 223
diff changeset
  1110
    text := StringCollection new.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1111
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1112
	l := self nextLine.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1113
	l isNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1114
	    ^ text
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1115
	].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1116
	text add:l
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1117
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1118
    ^ text
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1119
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1120
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1121
contentsOfEntireFile
1522
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1122
    "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
  1123
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1124
    ^ self contents asString.
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1125
1d0b4bc2e563 ST-80 compatibility: #contentsOfEntireFile must return a String.
Stefan Vogel <sv@exept.de>
parents: 1515
diff changeset
  1126
    "Modified: 3.7.1996 / 13:22:16 / stefan"
2
claus
parents: 1
diff changeset
  1127
!
claus
parents: 1
diff changeset
  1128
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1129
contentsSpecies
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1130
    "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
  1131
     (such as upTo)"
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1132
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1133
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1134
	^ ByteArray
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1135
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1136
    ^ String
2
claus
parents: 1
diff changeset
  1137
!
claus
parents: 1
diff changeset
  1138
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1139
eolMode:aSymbolOrNil
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1140
    "specify how end-of-line (EOL) is to be marked.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1141
     The argument may be one of:
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1142
	#crlf         -> add a CR-NL, as in MSDOS
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1143
	#cr           -> add a CR, as in VMS
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1144
	#nl           -> add a NL, as in Unix
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1145
	anyOther      -> like #nl
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1146
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1147
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1148
    eolMode := aSymbolOrNil
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1149
!
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1150
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1151
fileDescriptor
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1152
    "return the fileDescriptor of the receiver -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1153
     notice: this one returns the underlying OSs fileDescriptor -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1154
     this may not be available on all platforms (i.e. non unix systems)."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1155
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1156
%{  /* NOCONTEXT */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1157
#ifdef WIN32
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1158
    RETURN (nil);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1159
#else
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1160
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1161
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1162
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1163
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1164
	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
  1165
	RETURN ( __MKINT(fileno(f)) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1166
    }
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1167
#endif
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1168
%}.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1169
    ^ self errorNotOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1170
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1171
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1172
filePointer
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1173
    "return the filePointer of the receiver -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1174
     notice: for portability stdio is used; this means you will get
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1175
     a FILE * - not a fileDescriptor. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1176
     (what you really get is a corresponding integer).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1177
     You cannot do much with the returned value 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1178
     - except passing it to a primitive, for example."
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
    ^ filePointer
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1181
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1182
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1183
readonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1184
    "set access mode to readonly"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1185
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1186
    mode := #readonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1187
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1188
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1189
readwrite
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1190
    "set access mode to readwrite"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1191
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1192
    mode := #readwrite
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1193
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1194
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1195
text
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1196
    "switch to text mode - default is text"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1197
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1198
    binary := false
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1199
!
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
useCRLF:aBoolean
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1202
    "turn on or off CRLF sending (instead of LF only) - default is off.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1203
     This method is provided for backward compatibility - see #eolMode:
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1204
     which offers another choice."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1205
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1206
    aBoolean ifTrue:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1207
	eolMode := #crlf
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1208
    ] ifFalse:[
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1209
	eolMode := #nl
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1210
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1211
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1212
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1213
writeonly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1214
    "set access mode to writeonly"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1215
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1216
    mode := #writeonly
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1219
!ExternalStream methodsFor:'error handling'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1220
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1221
argumentMustBeCharacter
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1222
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1223
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1224
    "report an error, that the argument must be a character"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1225
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1226
    ^ self error:'argument must be a character'
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1227
!
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
argumentMustBeInteger
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1230
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1231
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1232
    "report an error, that the argument must be an integer"
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
    ^ self error:'argument must be an integer'
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1235
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1236
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1237
argumentMustBeString
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1238
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1239
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1240
    "report an error, that the argument must be a string"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1241
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1242
    ^ self error:'argument must be a string'
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1245
errorBinary
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1246
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1247
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1248
    "report an error, that the stream is in binary mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1249
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1250
    ^ self invalidModeSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1251
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1252
	     errorString:(self class name , ' is in binary mode')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1253
		      in:thisContext sender
612
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1256
errorNotBinary
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1257
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1258
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1259
    "report an error, that the stream is not in binary mode"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1260
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1261
    ^ self invalidModeSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1262
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1263
	     errorString:(self class name , ' is not in binary mode')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1264
		      in:thisContext sender
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1265
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1266
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1267
errorNotBuffered
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1268
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1269
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1270
    "report an error, that the stream is not in buffered mode"
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
    ^ StreamErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1273
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1274
	     errorString:(self class name , ' is unbuffered - operation not allowed')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1275
		      in:thisContext sender
612
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1278
errorNotOpen
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1279
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1280
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1281
    "report an error, that the stream has not been opened"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1282
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1283
    ^ self streamNotOpenSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1284
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1285
	     errorString:(self class name , ' not open')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1286
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1287
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1288
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1289
errorOpen
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1290
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1291
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1292
    "report an error, that the stream is already opened"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1293
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1294
    ^ self openErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1295
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1296
	errorString:(self class name , ' is already open')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1297
		 in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1298
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1299
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1300
errorReadOnly
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1301
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1302
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1303
    "report an error, that the stream is a readOnly stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1304
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1305
    ^ self invalidWriteSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1306
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1307
	     errorString:(self class name , ' is readonly')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1308
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1309
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1310
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1311
errorUnsupportedOperation
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1312
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1313
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1314
    "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
  1315
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1316
    ^ self invalidOperationSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1317
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1318
	errorString:'unsupported operation'
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1319
		 in:thisContext sender
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1320
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  1321
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1322
errorWriteOnly
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1323
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1324
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1325
    "report an error, that the stream is a writeOnly stream"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1326
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1327
    ^ self invalidReadSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1328
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1329
	     errorString:(self class name , ' is writeonly')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1330
		      in:thisContext sender
2
claus
parents: 1
diff changeset
  1331
!
claus
parents: 1
diff changeset
  1332
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1333
ioError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1334
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1335
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1336
    "report an error, that some I/O error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1337
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1338
    ^ StreamErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1339
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1340
	     errorString:('I/O error: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1341
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1342
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1343
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1344
lastErrorNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1345
    "return the last error"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1346
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1347
    ^ lastErrorNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1348
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1349
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1350
lastErrorString
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1351
    "return a message string describing the last error"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1352
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1353
    (lastErrorNumber isNil or:[lastErrorNumber == 0]) ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1354
	^ 'I/O error'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1355
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1356
    ^ OperatingSystem errorTextForNumber:lastErrorNumber
2
claus
parents: 1
diff changeset
  1357
!
claus
parents: 1
diff changeset
  1358
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1359
openError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1360
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1361
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1362
    "report an error, that the open failed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1363
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1364
    ^ OpenErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1365
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1366
	     errorString:('error on open: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1367
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1368
!
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
readError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1371
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1372
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1373
    "report an error, that some read error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1374
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1375
    ^ ReadErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1376
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1377
	     errorString:('read error: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1378
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1379
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1380
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1381
writeError
1119
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1382
    "{ Pragma: +optSpace }"
956d62a5656c compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1079
diff changeset
  1383
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1384
    "report an error, that some write error occured"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1385
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1386
    ^ WriteErrorSignal
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1387
	raiseRequestWith:self
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1388
	     errorString:('write error: ' , self lastErrorString)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1389
		      in:thisContext sender
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1390
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1391
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1392
!ExternalStream methodsFor:'instance release'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1393
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1394
closeFile
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1395
    "low level close - may be redefined in subclasses"
2
claus
parents: 1
diff changeset
  1396
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1397
%{
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1398
    OBJ fp;
2
claus
parents: 1
diff changeset
  1399
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1400
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1401
	__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
  1402
#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
  1403
	CloseHandle(__HANDLEVal(fp));
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1404
#else
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1405
	__BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1406
	fclose(__FILEVal(fp));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1407
	__END_INTERRUPTABLE__
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1408
#endif
10
claus
parents: 5
diff changeset
  1409
    }
claus
parents: 5
diff changeset
  1410
%}
claus
parents: 5
diff changeset
  1411
!
claus
parents: 5
diff changeset
  1412
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1413
disposed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1414
    "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
  1415
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1416
    self closeFile
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1417
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1418
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1419
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
  1420
    "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
  1421
     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
  1422
     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
  1423
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1424
%{  /* NOCONTEXT */
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1425
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1426
#ifndef WIN32
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1427
    FILEPOINTER f;
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1428
    OBJ fp;
2765
a56668774ad7 more alpha64 fixes
Claus Gittinger <cg@exept.de>
parents: 2764
diff changeset
  1429
    FILE *fdopen();
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1430
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1431
    if (__isSmallInteger(anInteger) &&
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1432
	__isString(openMode) &&
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1433
	(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
  1434
    ) {
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1435
	__PROTECT__(self);
2765
a56668774ad7 more alpha64 fixes
Claus Gittinger <cg@exept.de>
parents: 2764
diff changeset
  1436
	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
  1437
	__UNPROTECT__(self);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1438
	__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
  1439
	RETURN (self);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1440
    }
2613
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1441
#endif /* not WIN32 */
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1442
%}.
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1443
    ^ self primitiveFailed
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1444
!
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1445
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1446
setFileHandle:aHandle mode:openMode
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1447
    "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
  1448
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1449
%{  /* NOCONTEXT */
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1450
#ifdef xxWIN32
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1451
    FILEPOINTER f;
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1452
    
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1453
    if (__isExternalAddress(aHandle)) {
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1454
	HFILE hFile = (HFILE)(__externalAddressVal(aHandle));
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1455
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1456
printf("stream handle set to %x\n", hFile);
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1457
	/*
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1458
	 * mhmh - how can we fdopen a file to a given HANDLE ?
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1459
	 */
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1460
    }
d0c8595f910d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2596
diff changeset
  1461
#endif /* WIN32 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1462
%}.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1463
    ^ self primitiveFailed
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1464
!
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1465
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1466
setFilePointer:something
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1467
    "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
  1468
     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
  1469
     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
  1470
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1471
    filePointer := something
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1472
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1473
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1474
shallowCopyForFinalization
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1475
    "return a copy for finalization-registration;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1476
     since all we need at finalization time is the fileDescriptor,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1477
     a cheaper copy is possible."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1478
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1479
    ^ self class basicNew setFilePointer:filePointer
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1480
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1481
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1482
shutDown
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1483
    "close the stream - added for protocol compatibility with PipeStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1484
     see comment there"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1485
1642
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1486
    filePointer isNil ifTrue:[^ self].
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1487
    Lobby unregister:self.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1488
    self closeFile
1642
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1489
91c6860f1c9d when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 1522
diff changeset
  1490
    "Modified: 30.8.1996 / 00:39:21 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1491
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1492
2
claus
parents: 1
diff changeset
  1493
!ExternalStream methodsFor:'line reading/writing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1494
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1495
nextLine
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1496
    "read the next line (characters up to newline).
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1497
     Return a string containing those characters excluding the newline.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1498
     If the previous-to-last character is a cr, this is also removed,
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1499
     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
  1500
     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
  1501
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1502
    |line|
971
eb70f5674303 max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
  1503
eb70f5674303 max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
  1504
%{  /* STACK:17000 */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1505
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1506
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1507
    int len, ret;
971
eb70f5674303 max lineLength (in nextLine) increased to 16k
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
  1508
    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
  1509
    char *rslt, *nextPtr, *limit;
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1510
    int fd, ch;
1068
92fdcccf12a3 alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  1511
    int _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1512
    OBJ fp;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1513
    int lineTooLong = 0;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1514
    int cutOff = 0;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1515
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1516
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1517
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1518
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1519
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1520
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1521
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1522
	buffer[0] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1523
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1524
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1525
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1526
	    __READING__(f);
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
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1529
	rslt = nextPtr = buffer;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1530
	limit = buffer + sizeof(buffer) - 2;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1531
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1532
	for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1533
	    __READBYTE__(ret, f, nextPtr, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1534
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1535
		if (nextPtr == buffer)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1536
		    rslt = NULL;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1537
		if (ret == 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1538
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1539
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1540
		} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1541
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1542
		    goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1543
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1544
	    }
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1545
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1546
	    if (*nextPtr == '\n') {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1547
		cutOff = 1;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1548
		*nextPtr = '\0';
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1549
		break;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1550
	    }
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1551
	    if (*nextPtr == '\r') {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1552
		char peekChar;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1553
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1554
		/*
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1555
		 * peek ahead for a newLine ...
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1556
		 */
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1557
	        __READBYTE__(ret, f, &peekChar, _buffered);
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
  1558
	        if (ret <= 0) {
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
  1559
		    cutOff = 1;
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
  1560
		    *nextPtr = '\0';
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
  1561
		    if (ret == 0) {
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
  1562
		        __INST(hitEOF) = true;
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
  1563
		        break;
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
  1564
		    }
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
  1565
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
  1566
		    goto err;
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
  1567
		}
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
  1568
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1569
		if (peekChar == '\n') {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1570
		    cutOff = 2;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1571
		    *nextPtr = '\0';
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1572
		    break;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1573
		}
2961
a188727d0619 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2920
diff changeset
  1574
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1575
	        __UNGETC__(peekChar, f, _buffered);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1576
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1577
		cutOff = 1;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1578
		*nextPtr = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1579
		break;
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
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1582
	    nextPtr++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1583
	    if (nextPtr >= limit) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1584
		*nextPtr = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1585
		lineTooLong = 1;
2293
aec11c3274cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2264
diff changeset
  1586
		if (@global(InfoPrinting) == true) {
aec11c3274cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2264
diff changeset
  1587
		    fprintf(stderr, "ExtStream [warning]: line truncated in nextLine\n");
aec11c3274cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2264
diff changeset
  1588
		}
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1589
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1590
	    }
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
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1593
	if (rslt != NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1594
	    len = nextPtr-buffer;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1595
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1596
	    if (__INST(position) != nil) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1597
		int __p;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1598
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1599
		__p = __intVal(__INST(position)) + len + cutOff;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1600
		__INST(position) = __MKSMALLINT(__p);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1601
	    }
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1602
	    /* remove any EOL character */
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1603
	    if (len != 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1604
		if (buffer[len-1] == '\n') {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1605
		    buffer[--len] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1606
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1607
		if ((len != 0) && (buffer[len-1] == '\r')) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1608
		    buffer[--len] = '\0';
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
	    }
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1611
	    line = __MKSTRING_L(buffer, len);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1612
	    if (! lineTooLong) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1613
		RETURN ( line );
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1614
	    }
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1615
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1616
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  1617
err: ;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1618
%}.
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1619
    line notNil ifTrue:[
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1620
	"/ 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
  1621
	"/ 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
  1622
	"/ concatenation in your exception handler (the receiver and the partial
aec11c3274cc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2264
diff changeset
  1623
	"/ line are passed as parameter)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1624
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1625
	^ ReadErrorSignal
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1626
	    raiseRequestWith:(Array with:self with:line)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1627
		 errorString:('line too long read error')
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1628
    ].
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1629
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  1630
    hitEOF ifTrue:[^ self pastEnd].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1631
    lastErrorNumber notNil ifTrue:[^ self readError].
2
claus
parents: 1
diff changeset
  1632
    filePointer isNil ifTrue:[^ self errorNotOpen].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1633
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  1634
    ^ self errorBinary
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1635
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1636
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1637
nextPutLine:aString
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1638
    "write the characters in aString and append an end-of-Line marker
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1639
     (LF, CR or CRLF - depending in the setting of eolMode)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1640
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  1641
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1642
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1643
    int len, cnt, len1, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1644
    OBJ pos, fp;
537
dc4dad8a5ddd many ExtStream rewrites - has to be reevaluated in all platforms
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1645
    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
  1646
    int o_offs;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1647
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1648
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1649
    if (((fp = __INST(filePointer)) != nil) 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1650
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1651
	&& (__INST(binary) != true)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1652
	&& __isString(aString)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1653
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1654
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1655
	len = __stringSize(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1656
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1657
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1658
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1659
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1660
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1661
	__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
  1662
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  1663
	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
  1664
	__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
  1665
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1666
	if (cnt == len) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1667
	    OBJ mode = __INST(eolMode);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1668
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1669
	    len1 = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1670
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1671
	    if (mode == @symbol(cr)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1672
		cp = "\r"; len = 1;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1673
	    } else if (mode == @symbol(crlf)) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1674
		cp = "\r\n"; len = 2;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1675
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1676
		cp = "\n"; len = 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1677
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1678
	    __WRITEBYTES__(cnt, f, cp, len, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1679
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1680
	    if (cnt > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1681
		pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1682
		if (pos != nil) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1683
		    int __p;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1684
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1685
		    __p = __intVal(pos) + len1 + cnt;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1686
		    __INST(position) = __MKSMALLINT(__p);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1687
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1688
		RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1689
	    }
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
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1692
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1693
%}.
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1694
    super nextPutLine:aString.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1695
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1696
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1697
nextPutLinesFrom:aStream upToLineStartingWith:aStringOrNil
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1698
    "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
  1699
     and append all lines to self. 
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1700
     Can be used to copy/create large files or copy from a pipe/socket.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1701
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1702
     If aStringOrNil is nil or not matched, copy preceeds to the end.
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1703
     (this allows for example to read a Socket and transfer the data quickly
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1704
      into a file - without creating zillions of temporary strings)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1705
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1706
    |srcFilePointer readError line|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1707
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1708
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1709
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1710
    srcFilePointer := aStream filePointer.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1711
    srcFilePointer isNil ifTrue:[aStream errorNotOpen. ^ self].
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1712
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1713
%{  /* STACK:2000 */
22
847106305963 *** empty log message ***
claus
parents: 12
diff changeset
  1714
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1715
#ifndef NO_STDIO
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1716
    FILEPOINTER dst;
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1717
    FILEPOINTER src;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1718
    char *matchString;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1719
    int matchLen = 0;
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1720
    char buffer[1024];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1721
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1722
    __INST(lastErrorNumber) = nil;
249
claus
parents: 244
diff changeset
  1723
    if (__isSmallInteger(srcFilePointer)) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1724
	if ((aStringOrNil == nil) || __isString(aStringOrNil)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1725
	    if (aStringOrNil != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1726
		matchString = (char *) __stringVal(aStringOrNil);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1727
		matchLen = __stringSize(aStringOrNil);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1728
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1729
	    dst = __FILEVal(__INST(filePointer));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1730
	    src = __FILEVal(srcFilePointer);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1731
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1732
	    errno = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1733
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1734
	    __WRITING__(dst)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1735
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1736
	    for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1737
		if (fgets(buffer, sizeof(buffer)-1, src) == NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1738
		    if (ferror(src)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1739
			readError = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1740
			__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1741
			goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1742
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1743
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1744
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1745
		if (fputs(buffer, dst) == EOF) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1746
		    if (ferror(dst)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1747
			__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1748
			__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1749
			goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1750
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1751
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1752
		}
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1753
#ifndef OLD
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1754
		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
  1755
		    FFLUSH(dst);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1756
		}
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1757
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1758
		if (matchLen) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1759
		    if (strncmp(matchString, buffer, matchLen) == 0) 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1760
			break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1761
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1762
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1763
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1764
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1765
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1766
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1767
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1768
err: ;
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1769
#endif /* ! NO_STDIO */
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1770
%}.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1771
    readError ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1772
	aStream setLastErrorNumber:readError.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1773
	aStream readError.
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1774
	^ self
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1775
    ].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1776
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  1777
    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
  1778
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1779
    "
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1780
     argument error or unimplemented; try it linewise
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1781
    "
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1782
    [aStream atEnd] whileFalse:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1783
	line := aStream nextLine.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1784
	line isNil ifTrue:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1785
	    ^ self.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1786
	].
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1787
	self nextPutLine:line.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1788
	(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
  1789
	    ^ self
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1790
	]
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1791
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1792
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1793
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1794
peekForLineStartingWith:aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1795
    "read ahead for next line starting with aString;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1796
     return the line-string if found, or nil if EOF is encountered.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1797
     If matched, not advance position behond that line
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1798
     i.e. nextLine will read the matched line.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1799
     If not matched, reposition to original position for firther reading."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1800
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1801
    |firstPos lastPos line|
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1802
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1803
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1804
    filePointer isNil ifTrue:[^ self errorNotOpen].
2
claus
parents: 1
diff changeset
  1805
    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
  1806
    buffered ifFalse:[^ self errorNotBuffered].
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1807
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1808
%{  /* STACK: 2000 */
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1809
#ifndef NO_STDIO
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1810
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1811
    FILEPOINTER f;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1812
    int l;
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1813
    char buffer[1024];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1814
    char *cp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1815
    char *matchString;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1816
    int gotFirst = 0;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1817
#ifdef __VMS__
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1818
    fpos_t firstpos, lastpos;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1819
#   define FTELL(__f__, __pos__)	fgetpos(__f__, &(__pos__))
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1820
#   define FSEEK(__f__, __pos__)	fsetpos(__f__, &(__pos__))
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1821
#else
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1822
    long firstpos, lastpos;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1823
#   define FTELL(__f__, __pos__)	__pos__ = ftell(__f__)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1824
#   define FSEEK(__f__, __pos__)	fseek(__f__, __pos__, SEEK_SET)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1825
#endif
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1826
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  1827
    __INST(lastErrorNumber) = nil;
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 44
diff changeset
  1828
    if (__isString(aString)) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1829
	matchString = (char *) __stringVal(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1830
	l = __stringSize(aString);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1831
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1832
	f = __FILEVal(__INST(filePointer));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1833
	__READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1834
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1835
	for (;;) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1836
	    FTELL(f, lastpos);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1837
	    if (!gotFirst) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1838
		firstpos = lastpos;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1839
		gotFirst = 1;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1840
	    }
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1841
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1842
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1843
	    do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1844
		cp = fgets(buffer, sizeof(buffer)-1, f);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1845
	    } while ((cp == NULL) && ferror(f) && (errno == EINTR) && (clearerr(f), 1));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1846
	    buffer[sizeof(buffer)-1] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1847
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1848
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1849
	    if (cp == NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1850
		if (ferror(f)) {
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
		    goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1853
		} else {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1854
		    FSEEK(f, firstpos);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1855
		    RETURN (nil);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1856
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1857
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1858
	    if (strncmp(cp, matchString, l) == 0) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1859
		FSEEK(f, lastpos);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1860
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1861
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1862
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1863
	/* remove EOL character */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1864
	cp = buffer;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1865
	while (*cp && (*cp != '\n') && (*cp != '\r')) cp++;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1866
	*cp = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1867
	RETURN ( __MKSTRING(buffer) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1868
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1869
err: ;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1870
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1871
# undef FTELL
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1872
# undef FSEEK
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1873
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1874
#endif
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1875
%}.
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1876
    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
  1877
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1878
    "/ 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
  1879
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1880
    firstPos := self position.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1881
    [self atEnd] whileFalse:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1882
	lastPos := self position.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1883
	line := self nextLine.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1884
	line isNil ifTrue:[
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1885
	    self position:firstPos.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1886
	    ^ nil
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1887
	].
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1888
	(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
  1889
	    self position:lastPos.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1890
	    ^ line
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1891
	]
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1892
    ].
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1893
    self position:firstPos.
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  1894
    ^ nil
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1895
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1896
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1897
peekForLineStartingWithAny:aCollectionOfStrings
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1898
    "read ahead for next line starting with any of aCollectionOfStrings;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1899
     return the index in aCollection if found, nil otherwise..
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1900
     If no match, do not change position; otherwise advance right before the
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1901
     matched line so that nextLine will return this line."
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1902
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1903
    |line startPos linePos index|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1904
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1905
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1906
    filePointer isNil ifTrue:[^ self errorNotOpen].
2
claus
parents: 1
diff changeset
  1907
    binary ifTrue:[^ self errorBinary].
claus
parents: 1
diff changeset
  1908
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1909
    startPos := self position.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1910
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1911
	linePos := self position.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1912
	line := self nextLine.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1913
	line notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1914
	    index := 1.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1915
	    aCollectionOfStrings do:[:prefix |
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1916
		(line startsWith:prefix) ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1917
		    self position:linePos.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1918
		    ^ index
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1919
		].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1920
		index := index + 1
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1921
	    ]
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1922
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1923
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1924
    self position:startPos.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1925
    ^ nil
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1926
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1927
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1928
!ExternalStream methodsFor:'misc functions'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1929
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1930
async:aBoolean
779
0e41a665038a commentary
Claus Gittinger <cg@exept.de>
parents: 730
diff changeset
  1931
    "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
  1932
     the receiver will trigger an ioInterrupt.
779
0e41a665038a commentary
Claus Gittinger <cg@exept.de>
parents: 730
diff changeset
  1933
     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
  1934
     Notice: 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1935
	not every OS supports this 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1936
	- check with OS>>supportsIOInterrupts before using"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1937
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1938
    |fd|
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1939
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1940
    filePointer isNil ifTrue:[^ self errorNotOpen].
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1941
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1942
    OperatingSystem supportsIOInterrupts ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1943
	^ self errorUnsupportedOperation
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1944
    ].
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1945
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1946
    fd := self fileDescriptor.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1947
    aBoolean ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  1948
	^ OperatingSystem enableIOInterruptsOn:fd
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1949
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1950
    ^ OperatingSystem disableIOInterruptsOn:fd
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1951
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1952
    "Modified: 11.1.1997 / 17:50:21 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1953
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1954
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1955
backStep
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1956
    "step back one element -
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1957
     redefined, since position is redefined here"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1958
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1959
    self position:(self position - 1)
362
claus
parents: 360
diff changeset
  1960
!
claus
parents: 360
diff changeset
  1961
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1962
blocking:aBoolean
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1963
    "set/clear the blocking attribute - if set (which is the default)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1964
     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
  1965
     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
  1966
     nil.
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1967
     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
  1968
     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
  1969
     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
  1970
     methods, in order to avoid other (pasEnd) exceptions."
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1971
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  1972
    filePointer isNil ifTrue:[^ self errorNotOpen].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1973
    ^ 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
  1974
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  1975
    "Modified: 11.1.1997 / 17:48:01 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1976
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1977
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1978
close
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1979
    "close the stream - tell operating system"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1980
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1981
    filePointer isNil ifTrue:[^ self].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1982
    Lobby unregister:self.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1983
    self closeFile.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1984
    filePointer := nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1985
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1986
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1987
create
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1988
    "create the stream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1989
     - this must be redefined in subclass"
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
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1992
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1993
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1994
ioctl:ioctlNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1995
    "to provide a simple ioctl facility - an ioctl is performed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1996
     on the underlying file; no arguments are passed."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1997
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1998
    ^ self ioctl:ioctlNumber with:nil
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1999
!
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2000
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2001
ioctl:ioctlNumber with:arg
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2002
    "to provide a simple ioctl facility - an ioctl is performed
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2003
     on the underlying file; the argument is passed as argument.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2004
     This is not used by ST/X, but provided for special situations 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2005
     - for example, to control proprietrary I/O devices.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2006
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2007
     Since the type of the argument depends on the ioctl being
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2008
     performed, different arg types are allowed here.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2009
     If the argument is nil, an ioctl without argument is performed.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2010
     If the argument is an integral number, its directly passed; 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2011
     if its a kind of ByteArray (ByteArray, String or Structure),
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2012
     or external data (ExternalBytes or ExternalAddress),
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2013
     a pointer to the data is passed. 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2014
     This allows performing most ioctls 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2015
     - however, it might be tricky to setup the buffer.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2016
     Be careful in what you pass - ST/X cannot validate its correctness."
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2017
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2018
%{
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
  2019
#if !defined(MSDOS_LIKE)
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
  2020
# if !defined(__openVMS__)
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2021
    FILEPOINTER f;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2022
    int ret, ioNum;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2023
    OBJ fp;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2024
    INT ioArg;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2025
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2026
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2027
    if ((fp = __INST(filePointer)) != nil) {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2028
	if (__isSmallInteger(ioctlNumber) 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2029
	 && (__isSmallInteger(arg) 
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2030
	     || (arg == nil)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2031
	     || __isBytes(arg)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2032
	     || __isExternalBytes(arg)
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2033
	     || __isExternalAddress(arg))) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2034
	    f = __FILEVal(fp);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2035
	    ioNum = __intVal(ioctlNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2036
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2037
	    __BEGIN_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2038
	    do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2039
		errno = 0;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2040
		if (arg == nil) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2041
		    ioArg = 0;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2042
		} else if (__isSmallInteger(arg)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2043
		    ioArg = __intVal(arg);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2044
		} else if (__isExternalBytes(arg)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2045
		    ioArg = (INT)(__externalBytesAddress(arg));
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2046
		} else if (__isExternalAddress(arg)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2047
		    ioArg = (INT)(__externalAddressVal(arg));
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2048
		} else {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2049
		    ioArg = (INT)(__ByteArrayInstPtr(arg)->ba_element);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2050
		}
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2051
		ret = ioctl(fileno(f), ioNum, ioArg);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2052
	    } while ((ret < 0) && (errno == EINTR));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2053
	    __END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2054
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2055
	    if (ret >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2056
		RETURN ( __MKSMALLINT(ret) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2057
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2058
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2059
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2060
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2061
    }
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2875
diff changeset
  2062
# endif
791
b1c153b1c719 WIN32 has no ioctl
Claus Gittinger <cg@exept.de>
parents: 779
diff changeset
  2063
#endif
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2064
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2065
    lastErrorNumber notNil ifTrue:[^ self ioError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2066
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2067
    "
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2068
     argument is not an integer
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2069
    "
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2070
    (ioctlNumber isMemberOf:SmallInteger) ifFalse:[^ self primitiveFailed].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2071
    "
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2072
     the system does not support ioctl (MSDOS or VMS)
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2073
    "
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2074
    ^ self errorUnsupportedOperation
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2075
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2076
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2077
open
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2078
    "open the stream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2079
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2080
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2081
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2082
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2083
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2084
position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2085
    "return the position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2086
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2087
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2088
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2089
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2090
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2091
position:anInteger
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2092
    "set the position
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2093
     - this must be redefined in subclass"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2094
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2095
    ^ self subclassResponsibility
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2096
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2097
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2098
reset
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2099
    "set the read position to the beginning of the collection"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2100
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2101
    self position:"0" 1
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2102
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2103
1044
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2104
setToEnd
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2105
    "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
  2106
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2107
    ^ self subclassResponsibility
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2108
!
c2fb3818e097 ExtSTream>>next: did not work correct if interrupted.
Stefan Vogel <sv@exept.de>
parents: 971
diff changeset
  2109
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2110
truncateTo:newSize
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2111
    "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
  2112
     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
  2113
1068
92fdcccf12a3 alles MIST - zurueck zu 1.89 und NOCONTEXT entfernt
Claus Gittinger <cg@exept.de>
parents: 1067
diff changeset
  2114
%{
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2115
#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
  2116
    FILEPOINTER f;
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2117
    OBJ fp;
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2118
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2119
    if (((fp = __INST(filePointer)) != nil)
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2120
     && (__INST(mode) != @symbol(readonly))) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2121
	if (__isSmallInteger(newSize)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2122
	    f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2123
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2124
	    if (__INST(buffered) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2125
		__READING__(f)
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2126
		FFLUSH(f);
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2127
		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
  2128
	    }
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2129
	    ftruncate(fileno(f), __intVal(newSize));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2130
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2131
	}
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2132
    }
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2133
#endif
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2134
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2135
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2136
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2137
    self errorUnsupportedOperation
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2138
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2139
    "
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2140
     |s|
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2141
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2142
     s := 'test' asFilename writeStream.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2143
     s next:1000 put:$a.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2144
     s truncateTo:100.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2145
     s close.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2146
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2147
     ('test' asFilename fileSize) printNL
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 872
diff changeset
  2148
    "
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2149
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2150
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2151
!ExternalStream methodsFor:'non homogenous reading'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2152
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2153
nextByte
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2154
    "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
  2155
     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
  2156
     bytes binary value as an integer in 0..255."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2157
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2158
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2159
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2160
    unsigned char byte;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2161
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2162
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2163
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2164
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2165
    if (((fp = __INST(filePointer)) != nil)
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2166
     && (__INST(mode) != @symbol(writeonly))) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2167
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2168
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2169
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2170
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2171
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2172
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2173
	__READBYTE__(ret, f, &byte, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2174
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2175
	    if (__INST(position) != nil)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2176
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2177
	    RETURN (__MKSMALLINT(byte));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2178
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2179
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2180
	if (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
	} else /* ret < 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2183
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2184
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2185
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2186
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2187
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2188
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2189
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2190
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2191
    ^ self errorWriteOnly
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2192
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2193
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2194
nextBytes:count into:anObject startingAt:start
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2195
    "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
  2196
     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
  2197
     If the receiver is some socket/pipe-like stream, an exception
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2198
     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
  2199
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2200
     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
  2201
     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
  2202
     Thus allowing read of partial blocks.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2203
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2204
     The object must have non-pointer indexed instvars 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2205
     (i.e. it must be a ByteArray, String, Float- or DoubleArray).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2206
     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
  2207
     fastest possible physical I/O (since no new objects are allocated).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2208
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2209
     Use with care - non object oriented I/O.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2210
     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
  2211
     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
  2212
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2213
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2214
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2215
    int cnt, offs, ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2216
    int objSize, nInstVars, nInstBytes;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2217
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2218
    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
  2219
    int o_offs;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2220
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2221
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2222
    if (((fp = __INST(filePointer)) != nil)
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2223
        && (__INST(mode) != @symbol(writeonly))
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2224
        && __bothSmallInteger(count, start)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2225
    ) {
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2226
        f = __FILEVal(fp);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2227
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2228
        oClass = __Class(anObject);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2229
        switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2230
            case BYTEARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2231
            case WORDARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2232
            case LONGARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2233
            case SWORDARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2234
            case SLONGARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2235
            case FLOATARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2236
            case DOUBLEARRAY:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2237
                break;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2238
            default:
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2239
                goto bad;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2240
        }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2241
        cnt = __intVal(count);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2242
        offs = __intVal(start) - 1;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2243
        nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2244
        nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2245
        objSize = __Size(anObject) - nInstBytes;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2246
        if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2247
            _buffered = (__INST(buffered) == true);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2248
            if (_buffered) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2249
                __READING__(f);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2250
            }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2251
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2252
            /*
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2253
             * on interrupt, anObject may be moved to another location.
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2254
             * 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
  2255
             * to get a new address.
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2256
             */
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2257
            o_offs = nInstBytes+offs;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2258
            __READBYTES_OBJ__(ret, f, anObject, o_offs, cnt, _buffered);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2259
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2260
            if (ret > 0) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2261
                pos = __INST(position);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2262
                if (pos != nil) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2263
                    __INST(position) = __MKSMALLINT(__intVal(pos) + ret);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2264
                }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2265
                RETURN (__MKSMALLINT(ret));
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2266
            }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2267
            if (ret == 0) { 
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2268
                __INST(hitEOF) = true;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2269
            } else /* ret < 0 */ {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2270
                __INST(position) = nil;
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2271
                __INST(lastErrorNumber) = __MKSMALLINT(errno);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2272
            }
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  2273
        }
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2274
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2275
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2276
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2277
    (hitEOF and:[self pastEnd isNil]) ifTrue:[^ 0].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2278
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2279
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2280
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2281
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2282
     count not integer or arg not bit-like (String, ByteArray etc)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2283
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2284
    ^ self primitiveFailed
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2285
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2286
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2287
nextLong
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2288
    "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
  2289
     The returned value may be a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2290
     (msb-first for compatibility with other smalltalks)"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2291
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2292
    ^ self nextUnsignedLongMSB:true
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2293
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2294
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2295
nextLongMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2296
    "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
  2297
     which may be a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2298
     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
  2299
     otherwise least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2300
     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
  2301
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2302
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2303
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2304
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2305
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2306
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2307
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2308
	&& (__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
  2309
    ) {
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2310
	FILEPOINTER f;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2311
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2312
	int value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2313
	char buffer[4];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2314
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2315
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2316
	__READBYTES__(ret, f, buffer, 4, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2317
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2318
	if (ret == 4) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2319
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2320
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 4);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2321
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2322
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2323
		value = (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2324
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2325
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2326
		value = (value << 8) | (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2327
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2328
		value = (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2329
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2330
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2331
		value = (value << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2332
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2333
	    if ((value >= _MIN_INT) && (value <= _MAX_INT)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2334
		RETURN ( __MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2335
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2336
	    RETURN ( __MKLARGEINT(value) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2337
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2338
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2339
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2340
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2341
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2342
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2343
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2344
	}
612
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
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2347
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2348
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2349
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2350
    ^ self readError.
1079
d47cd86b487b Make methods signal-proof.
Stefan Vogel <sv@exept.de>
parents: 1068
diff changeset
  2351
362
claus
parents: 360
diff changeset
  2352
!
claus
parents: 360
diff changeset
  2353
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2354
nextShortMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2355
    "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
  2356
     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
  2357
     otherwise least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2358
     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
  2359
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2360
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2361
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2362
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2363
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2364
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2365
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2366
	&& (__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
  2367
    ) {
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2368
	FILEPOINTER f;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2369
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2370
	short value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2371
	char buffer[2];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2372
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2373
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2374
	__READBYTES__(ret, f, buffer, 2, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2375
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2376
	if (ret == 2) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2377
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2378
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 2);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2379
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2380
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2381
		value = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2382
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2383
		value = ((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2384
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2385
	    RETURN (__MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2386
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2387
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2388
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2389
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2390
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2391
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2392
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2393
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2394
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2395
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2396
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2397
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2398
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2399
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2400
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2401
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2402
nextUnsignedLongMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2403
    "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
  2404
     a LargeInteger.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2405
     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
  2406
     least-significant byte comes first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2407
     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
  2408
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2409
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2410
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2411
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2412
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2413
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2414
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2415
	&& (__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
  2416
    ) {
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2417
	FILEPOINTER f;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2418
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2419
	unsigned int value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2420
	char buffer[4];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2421
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2422
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2423
	__READBYTES__(ret, f, buffer, 4, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2424
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2425
	if (ret == 4) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2426
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2427
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 4);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2428
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2429
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2430
		value = (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2431
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2432
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2433
		value = (value << 8) | (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2434
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2435
		value = (buffer[3] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2436
		value = (value << 8) | (buffer[2] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2437
		value = (value << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2438
		value = (value << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2439
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2440
	    if (value <= _MAX_INT) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2441
		RETURN ( __MKSMALLINT(value));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2442
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2443
	    RETURN ( __MKULARGEINT(value) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2444
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2445
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2446
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2447
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2448
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2449
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2450
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2451
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2452
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2453
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2454
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2455
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2456
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2457
    ^ self readError.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2458
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2459
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2460
nextUnsignedShortMSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2461
    "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
  2462
     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
  2463
     otherwise least-significant byte comes first.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2464
     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
  2465
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2466
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2467
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2468
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2469
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2470
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2471
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2472
	&& (__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
  2473
    ) {
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2474
	FILEPOINTER f;
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2475
	int ret;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2476
	unsigned int value;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2477
	char buffer[2];
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2478
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2479
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2480
	__READBYTES__(ret, f, buffer, 2, __INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2481
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2482
	if (ret == 2) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2483
	    if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2484
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 2);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2485
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2486
	    if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2487
		value = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2488
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2489
		value = ((buffer[1] & 0xFF) << 8) | (buffer[0] & 0xFF);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2490
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2491
	    RETURN (__MKSMALLINT(value));
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
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2494
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2495
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2496
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2497
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2498
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2499
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2500
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2501
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2502
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2503
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2504
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2505
    ^ self readError.
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2508
nextWord
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2509
    "in text-mode:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2510
	 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
  2511
	 return a string containing those characters.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2512
     in binary-mode:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2513
	 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
  2514
	 unsigned Integer (for compatibility with other smalltalks)"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2515
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2516
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2517
	^ self nextUnsignedShortMSB:true
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2518
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2519
    ^ self nextAlphaNumericWord
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2520
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2521
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2522
!ExternalStream methodsFor:'non homogenous writing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2523
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2524
nextPutByte:aByteValue
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2525
    "write a byte.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2526
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2527
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2528
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2529
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2530
    char c;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2531
    OBJ pos, fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2532
    int cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2533
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2534
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2535
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2536
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2537
	&& __isSmallInteger(aByteValue)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2538
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2539
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2540
	c = __intVal(aByteValue);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2541
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2542
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2543
	    __WRITING__(f)
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
	__WRITEBYTE__(cnt, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2546
	if (cnt == 1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2547
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2548
	    if (pos != nil)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2549
		__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2550
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2551
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2552
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2553
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2554
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2555
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2556
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2557
    self writeError.
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2560
nextPutBytes:count from:anObject startingAt:start
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2561
    "write count bytes from an object starting at index start.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2562
     return the number of bytes written - which could be 0.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2563
     The object must have non-pointer indexed instvars 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2564
     (i.e. be a ByteArray, String, Float- or DoubleArray).     
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2565
     Use with care - non object oriented i/o.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2566
     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
  2567
     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
  2568
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2569
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2570
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2571
    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
  2572
    int objSize, nInstVars, nInstBytes, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2573
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2574
    OBJ oClass, pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2575
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2576
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2577
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2578
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2579
	&& __bothSmallInteger(count, start)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2580
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2581
	oClass = __Class(anObject);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2582
	switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2583
	    case BYTEARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2584
	    case WORDARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2585
	    case LONGARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2586
	    case SWORDARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2587
	    case SLONGARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2588
	    case FLOATARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2589
	    case DOUBLEARRAY:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2590
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2591
	    default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2592
		goto bad;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2593
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2594
	len = __intVal(count);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2595
	offs = __intVal(start) - 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2596
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2597
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2598
	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2599
	nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2600
	objSize = __Size(anObject) - nInstBytes;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2601
	if ( (offs >= 0) && (len >= 0) && (objSize >= (len + offs)) ) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2602
	    offs += nInstBytes;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2603
	    if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2604
		__WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2605
	    }
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  2606
	    __WRITEBYTES_OBJ__(cnt, f, anObject, offs, len, _buffered); 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2607
	    if (cnt >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2608
		pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2609
		if (pos != nil)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2610
		    __INST(position) = __MKSMALLINT(__intVal(pos) + cnt);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2611
		RETURN ( __MKSMALLINT(cnt) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2612
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2613
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2614
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2615
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2616
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2617
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2618
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2619
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2620
    (mode == #readonly) ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2621
    ^ self primitiveFailed
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2622
!
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
nextPutLong:aNumber MSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2625
    "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
  2626
     true, data is written most-significant byte first; otherwise least
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2627
     first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2628
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2629
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2630
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2631
    int num;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2632
    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
  2633
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2634
    int cnt, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2635
    OBJ fp, pos;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2636
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2637
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2638
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2639
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2640
	&& __isSmallInteger(aNumber)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2641
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2642
	num = __intVal(aNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2643
	if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2644
	    bytes[0] = (num >> 24) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2645
	    bytes[1] = (num >> 16) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2646
	    bytes[2] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2647
	    bytes[3] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2648
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2649
	    bytes[3] = (num >> 24) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2650
	    bytes[2] = (num >> 16) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2651
	    bytes[1] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2652
	    bytes[0] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2653
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2654
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2655
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2656
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2657
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2658
	} 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2659
	__WRITEBYTES__(cnt, f, bytes, 4, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2660
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2661
	if (cnt == 4) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2662
	    if ((pos = __INST(position)) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2663
		__INST(position) = __MKSMALLINT(__intVal(pos) + 4);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2664
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2665
	    RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2666
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2667
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2668
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2669
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2670
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2671
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2672
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2673
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2674
    aNumber isInteger ifTrue:[
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2675
	^ super nextPutLong:aNumber MSB:msbFlag
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2676
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2677
    self argumentMustBeInteger
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2678
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2679
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2680
nextPutShort:aNumber MSB:msbFlag
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2681
    "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
  2682
     true, data is written most-significant byte first; otherwise least
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2683
     first.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2684
     Works in both binary and text modes."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2685
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2686
%{
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2687
    int num;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2688
    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
  2689
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2690
    int cnt, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2691
    OBJ fp, pos;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2692
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2693
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2694
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2695
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2696
	&& __isSmallInteger(aNumber)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2697
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2698
	num = __intVal(aNumber);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2699
	if (msbFlag == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2700
	    bytes[0] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2701
	    bytes[1] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2702
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2703
	    bytes[1] = (num >> 8) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2704
	    bytes[0] = num & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2705
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2706
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2707
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2708
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2709
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2710
	} 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2711
	__WRITEBYTES__(cnt, f, bytes, 2, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2712
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2713
	if (cnt == 2) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2714
	    if ((pos = __INST(position)) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2715
		__INST(position) = __MKSMALLINT(__intVal(pos) + 2);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2716
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2717
	    RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2718
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2719
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2720
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2721
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2722
    lastErrorNumber notNil ifTrue:[^ self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2723
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2724
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2725
    self argumentMustBeInteger
10
claus
parents: 5
diff changeset
  2726
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2727
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2728
!ExternalStream methodsFor:'private'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2729
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2730
clearEOF
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2731
    hitEOF := false
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
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2734
connectTo:aFileDescriptor withMode:openmode
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2735
    "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
  2736
     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
  2737
     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
  2738
     a Stream object. 
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2739
     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
  2740
     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
  2741
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2742
    |retVal|
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2743
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2744
    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
  2745
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2746
    FILEPOINTER f;
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2747
    OBJ fp;
2765
a56668774ad7 more alpha64 fixes
Claus Gittinger <cg@exept.de>
parents: 2764
diff changeset
  2748
    FILE *fdopen();
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2749
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2750
    if (__isSmallInteger(aFileDescriptor) 
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2751
     && (__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
  2752
	f = (FILEPOINTER) fdopen(__intVal(aFileDescriptor), (char *)__stringVal(openmode));
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2753
	if (f == NULL) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2754
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2755
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2756
	} else {
2765
a56668774ad7 more alpha64 fixes
Claus Gittinger <cg@exept.de>
parents: 2764
diff changeset
  2757
	    __INST(filePointer) = fp = __MKOBJ(f); __STORE(self, fp);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2758
	    __INST(position) = __MKSMALLINT(1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2759
	    retVal = self;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2760
	}
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2761
    }
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2762
%}.
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2763
    retVal notNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2764
	buffered := true.       "default is buffered"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2765
	Lobby register:self
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2766
    ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2767
    lastErrorNumber notNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2768
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2769
	 the open failed for some reason ...
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2770
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2771
	^ self openError
1048
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2772
    ].
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2773
    ^ retVal
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2774
!
c535c5a73cba added facilities to connect to given Fd's and #makePipe
Claus Gittinger <cg@exept.de>
parents: 1044
diff changeset
  2775
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2776
open:aPath withMode:mode
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2777
    "low level open; opens the file/device and sets the filePointer instance
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2778
     variable. Careful: this does not care for any other state."
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2779
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2780
    |ok|
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2781
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2782
    ok := false.
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2783
%{
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2784
    FILE *f; 
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2785
    OBJ fp;
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2786
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2787
    if (__isString(aPath)) { 
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2788
        __BEGIN_INTERRUPTABLE__
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2789
        do {
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2790
            f = fopen((char *) __stringVal(aPath), (char *) __stringVal(mode));
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2791
        } while ((f == NULL) && (errno == EINTR));
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2792
        __END_INTERRUPTABLE__
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2793
        if (f == NULL) {
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2794
            __INST(lastErrorNumber) = __MKSMALLINT(errno);
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2795
        } else {
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2796
            __INST(filePointer) = fp = __MKOBJ((INT)f); __STORE(self, fp);
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2797
            ok = true;
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2798
        }
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2799
    }
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2800
%}.
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2801
    ok ifFalse:[
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2802
        "
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2803
         the open failed for some reason ...
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2804
        "
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2805
        ^ self openError
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2806
    ]. 
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2807
    Lobby register:self. 
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2808
!
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2961
diff changeset
  2809
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2810
reOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2811
    "sent after snapin to reopen streams.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2812
     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
  2813
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  2814
    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
  2815
    filePointer := nil.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2816
    Lobby unregister:self.
2134
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  2817
246a3bdab8b4 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2120
diff changeset
  2818
    "Modified: 10.1.1997 / 17:50:44 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2819
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2820
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2821
setLastError:aNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2822
    lastErrorNumber := aNumber
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2823
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2824
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2825
!ExternalStream methodsFor:'queries'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2826
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2827
isBinary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2828
    "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
  2829
     The default when created is false."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2830
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2831
    ^ binary
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2832
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2833
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2834
isExternalStream
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2835
    "return true, if the receiver is some kind of externalStream;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2836
     true is returned here - the method redefined from Object."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2837
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2838
    ^ true
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2839
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2840
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2841
isReadable 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2842
    "return true, if this stream can be read from"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2843
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2844
    ^ (mode ~~ #writeonly)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2845
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2846
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2847
isWritable 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2848
    "return true, if this stream can be written to"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2849
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2850
    ^ (mode ~~ #readonly)
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2851
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2852
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2853
!ExternalStream methodsFor:'reading'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2854
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2855
next
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2856
    "return the next element; advance read position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2857
     In binary mode, an integer is returned, otherwise a character.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2858
     If there are no more elements, nil is returned."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2859
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2860
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2861
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2862
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2863
    OBJ pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2864
    unsigned char ch;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2865
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2866
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2867
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2868
	&& (__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
  2869
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2870
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2871
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2872
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2873
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2874
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2875
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2876
	__READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2877
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2878
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2879
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2880
	    if (__isSmallInteger(pos)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2881
		__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2882
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2883
		__INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2884
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2885
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2886
		RETURN ( __MKSMALLINT(ch) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2887
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2888
	    RETURN ( __MKCHARACTER(ch) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2889
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2890
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2891
	__INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2892
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2893
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2894
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2895
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2896
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2897
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2898
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  2899
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2900
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2901
    filePointer isNil ifTrue:[^ self errorNotOpen].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  2902
    ^ self errorWriteOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2903
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2904
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2905
next:count
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2906
    "return the next count elements of the stream as a collection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2907
     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
  2908
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2909
    |coll nRead|
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2910
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2911
    binary ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2912
	coll := ByteArray uninitializedNew:count
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2913
    ] ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2914
	coll := String new:count
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2915
    ].
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2916
    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
  2917
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2918
    "/ for readStream protocol compatibility, 
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2919
    "/ we must raise an exception here.
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2920
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2921
    nRead < count ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2922
	^ self pastEnd
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2923
    ].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2924
    ^ coll
2151
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2925
5f1fd65f8c3b next: must raise pastEnd, if EOF is hit;
Claus Gittinger <cg@exept.de>
parents: 2134
diff changeset
  2926
    "Modified: 11.1.1997 / 17:44:17 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2927
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2928
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2929
peek
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2930
    "return the element to be read next without advancing read position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2931
     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
  2932
     If there are no more elements, nil is returned."
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2933
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  2934
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  2935
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2936
    unsigned char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2937
    int ret, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2938
    OBJ fp;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2939
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2940
    __INST(lastErrorNumber) = nil;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  2941
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  2942
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2943
	&& (__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
  2944
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2945
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2946
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2947
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2948
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2949
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2950
	__READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2951
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2952
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2953
	    __UNGETC__(c, f, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2954
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2955
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2956
		RETURN ( __MKSMALLINT(c) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2957
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2958
	    RETURN ( __MKCHARACTER(c) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2959
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2960
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2961
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2962
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2963
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2964
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2965
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2966
%}.
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  2967
    hitEOF ifTrue:[^ self pastEnd]. 
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  2968
    lastErrorNumber notNil ifTrue:[^ self readError].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2969
    filePointer isNil ifTrue:[^ self errorNotOpen].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2970
    ^ self errorWriteOnly
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2971
!
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2972
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2973
upToEnd
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2974
    "return a collection of the elements up-to the end.
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2975
     Return nil if the stream-end is reached before."
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2976
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2977
    |answerStream ch|
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2978
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2979
    answerStream := WriteStream on:(self contentsSpecies new).
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2980
    [self atEnd] whileFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2981
	ch := self next.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2982
	ch notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2983
	    answerStream nextPut:ch
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  2984
	]
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2985
    ].
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2986
    ^ answerStream contents
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2987
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2988
    "Created: 25.4.1996 / 14:40:31 / cg"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2989
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2990
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2991
!ExternalStream methodsFor:'reimplemented for speed'!
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2992
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2993
nextAlphaNumericWord
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2994
    "read the next word (i.e. up to non letter-or-digit) after first
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2995
     skipping any whiteSpace.
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2996
     Return a string containing those characters.
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2997
     There is a limit of 1023 characters in the word - if longer,
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  2998
     it is truncated."
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  2999
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3000
%{  /* STACK: 2000 */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3001
    FILEPOINTER f;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3002
    int len;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3003
    char buffer[1024];
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3004
    unsigned char ch;
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3005
    int cnt = 0;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3006
    int ret, _buffered;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3007
    OBJ fp;
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3008
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3009
    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
  3010
     && (__INST(mode) != @symbol(writeonly))
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3011
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3012
	f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3013
	_buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3014
	if (_buffered) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3015
	    __READING__(f)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3016
	}
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3017
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3018
	/*
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3019
	 * skip whiteSpace first ...
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3020
	 */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3021
	do {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3022
	    __READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3023
	    if (ret > 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3024
		cnt++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3025
	    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3026
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3027
	} while (
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3028
#ifndef NON_ASCII
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3029
		 (ch < ' ') ||
379
5b5a130ccd09 revision added
claus
parents: 372
diff changeset
  3030
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3031
		 (ch == ' ' ) || (ch == '\t') || (ch == '\r')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3032
	      || (ch == '\n') || (ch == 0x0b));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3033
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3034
	len = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3035
	while (ret > 0 && 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3036
	       (((ch >= 'a') && (ch <= 'z')) ||
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3037
		((ch >= 'A') && (ch <= 'Z')) ||
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3038
		((ch >= '0') && (ch <= '9')))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3039
	) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3040
	    buffer[len++] = ch;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3041
	    if (len >= (sizeof(buffer)-1)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3042
		/* emergency */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3043
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3044
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3045
	    __READBYTE__(ret, f, &ch, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3046
	    if (ret > 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3047
		cnt++;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3048
	    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3049
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3050
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3051
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3052
	if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3053
	    if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3054
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3055
		goto err;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3056
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3057
	    else if (ret == 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3058
		__INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3059
	} else {
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3060
	    __UNGETC__(ch, f, _buffered);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3061
	    cnt--;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3062
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3063
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3064
	if (__INST(position) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3065
	    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + cnt);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3066
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3067
	if (len != 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3068
	    buffer[len] = '\0';
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3069
	    RETURN ( __MKSTRING_L(buffer, len) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3070
	}
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3071
    }
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3072
err: ;
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3073
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3074
    hitEOF ifTrue:[^ self pastEnd].
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3075
    lastErrorNumber notNil ifTrue:[^ self readError].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3076
    filePointer isNil ifTrue:[^ self errorNotOpen].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3077
    ^ self errorWriteOnly
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3078
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3079
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3080
nextChunk
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3081
    "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
  3082
     exclamation mark. Within the chunk, exclamation marks have to be doubled -
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3083
     except within primitive code (this exception was added to make it easier
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3084
     to edit primitive code with external editors). This means, that other
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3085
     Smalltalks cannot always read chunks containing primitive code - but that
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3086
     doesnt really matter, since C-primitives are an ST/X feature anyway.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3087
     Reimplemented here for more speed."
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3088
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3089
    |retVal outOfMemory buffer|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3090
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3091
    filePointer isNil ifTrue:[^ self errorNotOpen].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3092
    binary ifTrue:[^ self errorBinary].
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3093
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3094
2854
3c8bf66e4e7d give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents: 2766
diff changeset
  3095
%{  /* 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
  3096
    /*
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3097
     * the main trick (and a bit of complication) here
2874
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3098
     * is to read the first 8k into a stack-buffer.
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3099
     * 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
  3100
     * 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
  3101
     */
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3102
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3103
    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
  3104
    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
  3105
    int ret;
1823
51ffb7231437 type casts
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  3106
    unsigned char *bufferPtr = (unsigned char *)0;
2874
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3107
    unsigned char fastBuffer[8000];
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3108
    REGISTER int index;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3109
    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
  3110
    int atBeginOfLine = 1, inPrimitive = 0;
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3111
    int haveCR = 0, haveNL = 0;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3112
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3113
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3114
    f = __FILEVal(__INST(filePointer));
668
73165201a9da nextChunk: %{ is only recognized if at begin-of-line
Claus Gittinger <cg@exept.de>
parents: 665
diff changeset
  3115
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3116
    _buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3117
    if (_buffered) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3118
        __READING__(f)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3119
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3120
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3121
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3122
     * skip spaces
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3123
     */
673
2c3a4a536cd1 oops - handling of exclas within primitives was wrong
Claus Gittinger <cg@exept.de>
parents: 671
diff changeset
  3124
    c = '\n';
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3125
    while (! done) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3126
        lastC = c;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3127
        __READBYTE__(ret, f, &c, _buffered);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3128
        if (ret <= 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3129
            goto err;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3130
        }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3131
        nread++;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3132
        atBeginOfLine = 0;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3133
        switch (c) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3134
            case '\n':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3135
            case ' ':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3136
            case '\t':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3137
            case '\r':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3138
            case '\b':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3139
            case '\014':
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3140
                break;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3141
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3142
            default:
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3143
                atBeginOfLine = (lastC == '\n');
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3144
                done = 1;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3145
                break;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3146
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3147
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3148
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3149
    /*
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3150
     * read chunk into a buffer
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3151
     */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3152
    bufferPtr = fastBuffer; fastFlag = 1;
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3153
    currSize = sizeof(fastBuffer);
362
claus
parents: 360
diff changeset
  3154
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3155
    index = 0;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3156
    for (;;) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3157
        __READBYTE__(ret, f, &peekC, _buffered);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3158
        if ((c == '%') && atBeginOfLine && ret > 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3159
            if (peekC == '{') {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3160
                inPrimitive = 1;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3161
            } else if (peekC == '}') {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3162
                inPrimitive = 0;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3163
            }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3164
        } else if (c == '!' && !inPrimitive) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3165
            if (ret > 0 && peekC == '!') {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3166
                /*
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3167
                 * convert double-! to a single !
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3168
                 */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3169
                __READBYTE__(ret, f, &peekC, _buffered);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3170
                if (ret > 0)
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3171
                    nread++;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3172
            } else {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3173
                /*
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3174
                 * End of chunk, push back lookahead character
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3175
                 * and leave loop.
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3176
                 */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3177
                if (ret > 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3178
                    __UNGETC__(peekC, f, _buffered);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3179
                } else
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3180
                    ret = 1;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3181
                break; 
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3182
            }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3183
        }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3184
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3185
        /* 
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3186
         * do we have to resize the buffer ? 
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3187
         */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3188
        if ((index+2) >= currSize) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3189
            OBJ newBuffer;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3190
            unsigned char *nbp;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3191
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3192
            newBuffer = __MKEMPTYSTRING(currSize * 2);
2874
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3193
            if (!fastFlag) {
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3194
                /*
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3195
                 * refetch - buffer could be moved by GC
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3196
                 */
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3197
                bufferPtr = __stringVal(buffer);
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3198
            }
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3199
            if (newBuffer == nil) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3200
                /*
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3201
                 * mhmh - chunk seems to be very big ....
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3202
                 */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3203
                outOfMemory = true;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3204
                goto err;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3205
            }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3206
            nbp = __stringVal(newBuffer);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3207
            bcopy(bufferPtr, nbp, index);
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3208
            bufferPtr = nbp;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3209
            bufferPtr[index] = '\0';
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3210
            buffer = newBuffer;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3211
            fastFlag = 0;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3212
            currSize = currSize * 2;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3213
        }
2854
3c8bf66e4e7d give nextChunk a bit more stack
Claus Gittinger <cg@exept.de>
parents: 2766
diff changeset
  3214
2874
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3215
        if (!fastFlag) {
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3216
            /*
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3217
             * old buffer may have moved (interrupt while reading)
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3218
             * - refetch pointer
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3219
             */
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3220
            bufferPtr = __stringVal(buffer);
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3221
        }
020627074c9e oops - nextChunk could access invalid memory due
Claus Gittinger <cg@exept.de>
parents: 2861
diff changeset
  3222
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3223
        /*
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3224
         * filter out cr-nl; make it nl
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3225
         */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3226
        if (c == '\n') {
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3227
            haveNL = 1;
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3228
            if (index > 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3229
                if (bufferPtr[index-1] == '\r') {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3230
                    index--;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3231
                }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3232
            }
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3233
        } else {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3234
            if (c == '\r') {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3235
                haveCR = 1;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3236
            }
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3237
        }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3238
        bufferPtr[index++] = c;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3239
        if (ret <= 0) {
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3240
            if (ret == 0)
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3241
                break;          /* End of chunk reached */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3242
            goto err;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3243
        }
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3244
        nread++;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3245
        atBeginOfLine = (c == '\n');
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3246
        c = peekC;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3247
    }
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3248
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3249
    /*
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3250
     * care for CR-limited files.
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3251
     * Replace CR's by NL's
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3252
     */
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3253
    if (!haveNL && haveCR) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3254
        int i;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3255
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3256
        for (i=index-1; i>=0; i--) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3257
            if (bufferPtr[i] == '\r') {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3258
                bufferPtr[i] = '\n';
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3259
            }
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3260
        }
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3261
    }
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3262
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3263
    /*
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3264
     * 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
  3265
     * 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
  3266
     * 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
  3267
     * fast (C) buffer or from real (ST) buffer.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3268
     */
665
429936f8e6e7 fixed nextChunk; it was not reentrant due to freeing of the static
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
  3269
    if (fastFlag) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3270
        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
  3271
    } else {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3272
        retVal = __MKSTRING_ST_L(buffer, index);
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3273
    }
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3274
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  3275
err: ;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3276
    if (ret <= 0) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3277
        if (ret == 0)
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3278
            __INST(hitEOF) = true;
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3279
        else /* ret < 0 */
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3280
            __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
  3281
    }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3282
    if (__INST(position) != nil) {
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3283
        __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
  3284
    }
159
514c749165c3 *** empty log message ***
claus
parents: 108
diff changeset
  3285
%}.
370
claus
parents: 369
diff changeset
  3286
    retVal isNil ifTrue:[
2591
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3287
        "/
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3288
        "/ 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
  3289
        "/ or if running out of malloc-memory
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3290
        "/
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3291
        hitEOF ifTrue:[^ self pastEnd].
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3292
        lastErrorNumber notNil ifTrue:[^ self readError].
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3293
        outOfMemory == true ifTrue:[
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3294
            "
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3295
             buffer memory allocation failed.
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3296
             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
  3297
             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
  3298
             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
  3299
            "
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3300
            ^ ObjectMemory allocationFailureSignal raise.
9faeea99f45b remove cr's when reading chunks.
Claus Gittinger <cg@exept.de>
parents: 2577
diff changeset
  3301
        ]
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  3302
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3303
    ^ retVal
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3304
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3305
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3306
nextMatchFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3307
    "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
  3308
     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
  3309
     the element after anObject.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3310
     Only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3311
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3312
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3313
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3314
    int ret, peekValue;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3315
    char c;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3316
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3317
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3318
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3319
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3320
	&& (__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
  3321
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3322
	if ((__INST(binary) == true) && __isSmallInteger(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3323
	    peekValue = __intVal(anObject) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3324
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3325
	    if ((__INST(binary) != true) && __isCharacter(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3326
		peekValue = __intVal(_characterVal(anObject)) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3327
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3328
		peekValue = -1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3329
	    }   
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3330
	}
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
	if (peekValue >= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3333
	    int _buffered;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3334
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3335
	    __INST(position) = nil;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3336
	    f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3337
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3338
	    if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3339
		__READING__(f)
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
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3342
	    for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3343
		__READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3344
		if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3345
		    if (ret < 0)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3346
			__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3347
		    else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3348
			__INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3349
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3350
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3351
		if (c == peekValue) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3352
		    RETURN (anObject);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3353
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3354
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3355
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3356
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3357
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3358
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3359
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3360
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3361
    ^ super nextMatchFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3362
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3363
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3364
peekFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3365
    "return true and move past next element, if next == something.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3366
     Otherwise, stay and return false. False is also returned
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3367
     when EOF is encountered.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3368
     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
  3369
     text mode; only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3370
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3371
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3372
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3373
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3374
    int ret, peekValue, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3375
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3376
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3377
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3378
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3379
	&& (__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
  3380
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3381
	if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3382
	    if (__isSmallInteger(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3383
		peekValue = __intVal(anObject) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3384
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3385
		goto bad;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3386
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3387
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3388
	    if (__isCharacter(anObject)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3389
		peekValue = __intVal(_characterVal(anObject)) & 0xFF;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3390
	    } else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3391
		goto bad;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3392
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3393
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3394
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3395
	f = __FILEVal(fp);
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3396
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3397
	_buffered = (__INST(buffered) == true);
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3398
	if (_buffered) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3399
	    __READING__(f)
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3400
	}
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3401
	__READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3402
	if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3403
	    if (c == peekValue) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3404
		OBJ pos;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3405
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3406
		if ((pos = __INST(position)) != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3407
		    __INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3408
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3409
		RETURN (true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3410
	    }
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3411
	    __UNGETC__(c, f, _buffered);
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3412
	    RETURN (false);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3413
	} 
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3414
	if (ret < 0) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3415
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3416
	} else /* ret == 0 */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3417
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3418
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3419
bad: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3420
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3421
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3422
    hitEOF ifTrue:[self pastEnd. ^ false].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3423
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3424
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3425
    ^ super peekFor:anObject
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3426
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3427
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3428
skipLine
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3429
    "read the next line (characters up to newline) skip only;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3430
     return nil if EOF reached, self otherwise. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3431
     Not allowed in binary mode."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3432
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3433
%{  /* STACK:2000 */
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3434
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3435
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3436
    OBJ fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3437
    int ret, _buffered;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3438
    char c;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3439
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3440
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3441
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3442
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3443
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3444
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3445
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3446
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3447
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3448
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3449
	for (;;) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3450
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3451
	    if (ret > 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3452
		if (c == '\n')
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3453
		    RETURN(self) 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3454
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3455
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3456
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3457
	if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3458
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3459
	} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3460
	    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3461
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3462
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3463
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3464
    hitEOF ifTrue:[^ self pastEnd].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3465
    lastErrorNumber notNil ifTrue:[self readError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3466
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3467
    binary ifTrue:[self errorBinary. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3468
    self errorWriteOnly
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
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3471
skipSeparators
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3472
    "skip all whitespace; next will return next non-white-space character
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3473
     or nil if endOfFile reached. Not allowed in binary mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3474
     - reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3475
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3476
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3477
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3478
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3479
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3480
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3481
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3482
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3483
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3484
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3485
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3486
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3487
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3488
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3489
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3490
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3491
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3492
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3493
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3494
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3495
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3496
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3497
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3498
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3499
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3500
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3501
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3502
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3503
	    switch (c) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3504
		case ' ':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3505
		case '\t':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3506
		case '\n':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3507
		case '\r':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3508
		case '\b':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3509
		case '\f':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3510
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3511
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3512
		default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3513
		    __UNGETC__(c, f, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3514
		    RETURN ( __MKCHARACTER(c & 0xFF) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3515
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3516
	}
612
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
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3519
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3520
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3521
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3522
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3523
    ^ self errorBinary.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3524
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3525
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3526
skipSeparatorsExceptCR
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3527
    "skip all whitespace but no newlines;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3528
     next will return next non-white-space character
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3529
     or nil if endOfFile reached. Not allowed in binary mode.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3530
     - reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3531
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3532
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3533
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3534
    char c;
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3535
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3536
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3537
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3538
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3539
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3540
	&& (__INST(mode) != @symbol(writeonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3541
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3542
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3543
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3544
	_buffered = (__INST(buffered) == true);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3545
	if (_buffered) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3546
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3547
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3548
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3549
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3550
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3551
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3552
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3553
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3554
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3555
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3556
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3557
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3558
	    switch (c) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3559
		case ' ':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3560
		case '\t':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3561
		case '\b':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3562
		case '\f':
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3563
		    break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3564
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3565
		default:
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3566
		    __UNGETC__(c, f, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3567
		    RETURN ( __MKCHARACTER(c & 0xFF) );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3568
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3569
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3570
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3571
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3572
    hitEOF ifTrue:[^ self pastEnd].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3573
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3574
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3575
    (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
  3576
    ^ self errorBinary.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3577
!
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
skipThrough:aCharacter
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3580
    "skip all characters up-to and including aCharacter. Return the receiver if
671
53de87163ad5 spelling
Claus Gittinger <cg@exept.de>
parents: 668
diff changeset
  3581
     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
  3582
     The next read operation will return the character after aCharacter.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3583
     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
  3584
     Only single byte characters are currently supported."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3585
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3586
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3587
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3588
    REGISTER int cSearch;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3589
    unsigned char c;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3590
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3591
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3592
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3593
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3594
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3595
	&& (__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
  3596
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3597
	if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3598
	    /* searched for object must be a smallInteger */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3599
	    if (! __isSmallInteger(aCharacter)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3600
	    cSearch = __intVal(aCharacter);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3601
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3602
	    /* searched for object must be a character */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3603
	    if (! __isCharacter(aCharacter)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3604
	    cSearch = __intVal(_characterVal(aCharacter));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3605
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3606
	/* Q: should we just say: "not found" ? */
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3607
	if ((cSearch < 0) || (cSearch > 255)) goto badArgument;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3608
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3609
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3610
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3611
	    __READING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3612
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3613
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3614
	while (1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3615
	    __READBYTE__(ret, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3616
	    if (ret <= 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3617
		if (ret < 0) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3618
		    __INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3619
		} else /* ret == 0 */ {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3620
		    __INST(hitEOF) = true;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3621
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3622
		break;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3623
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3624
	    if (c == cSearch) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3625
		RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3626
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3627
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3628
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3629
badArgument: ;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3630
%}.
1281
b4b3abffdf32 Support optional signal generation on end of stream.
Stefan Vogel <sv@exept.de>
parents: 1141
diff changeset
  3631
    hitEOF ifTrue:[^ self pastEnd].
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3632
    lastErrorNumber notNil ifTrue:[self readError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3633
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3634
    (mode == #writeonly) ifTrue:[self errorWriteOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3635
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3636
     argument must be integer/character in binary mode, 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3637
     character in text mode
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3638
    "
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3639
    self error:'invalid argument'.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3640
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
     |s|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3643
     s := 'Makefile' asFilename readStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3644
     s skipThrough:$=.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3645
     s next:10
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3646
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3647
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3648
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3649
skipToAll:aString
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3650
    "skip for the sequence given by the argument, aCollection;
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3651
     return nil if not found, self otherwise. 
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3652
     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
  3653
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3654
    |oldPos|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3655
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3656
    oldPos := self position.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3657
    (self skipThroughAll:aString) isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3658
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3659
	 restore position
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3660
	"
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3661
	self position:oldPos.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3662
	^ nil
612
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
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3665
     position before match-string
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3666
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3667
    self position:(self position - aString size).
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3668
    ^ self
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3669
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3670
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3671
     |s|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3672
     s := 'Makefile' asFilename readStream.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3673
     s skipToAll:'are'.
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3674
     s next:10 
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3675
    "
1490
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3676
713852290c8b use skipThroughAll from superclass.
Claus Gittinger <cg@exept.de>
parents: 1478
diff changeset
  3677
    "Modified: 26.6.1996 / 09:22:05 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3678
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3679
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3680
!ExternalStream methodsFor:'testing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3681
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3682
atEnd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3683
    "return true, if position is at end"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3684
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3685
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3686
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3687
    OBJ fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3688
    char c;
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3689
    int ret, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3690
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3691
    if (__INST(hitEOF) == true) {
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3692
        RETURN (true);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3693
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3694
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3695
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3696
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3697
    if ((fp = __INST(filePointer)) != nil) {
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3698
        f = __FILEVal(fp);
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3699
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3700
        if (_buffered = (__INST(buffered) == true)) {
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3701
            __READING__(f);
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3702
        } else {
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3703
            if (__INST(readAhead) != nil) {
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3704
                RETURN (false);
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3705
            }
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3706
        }
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3707
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3708
        /*
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3709
         * read ahead ...
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3710
         */
2875
54c89acc73ce #atEnd must read interruptable
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
  3711
        do {
54c89acc73ce #atEnd must read interruptable
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
  3712
            __BEGIN_INTERRUPTABLE__
54c89acc73ce #atEnd must read interruptable
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
  3713
            __READBYTE__(ret, f, &c, _buffered);
54c89acc73ce #atEnd must read interruptable
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
  3714
            __END_INTERRUPTABLE__
54c89acc73ce #atEnd must read interruptable
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
  3715
        } while ((ret < 0) && (errno == EINTR));
54c89acc73ce #atEnd must read interruptable
Claus Gittinger <cg@exept.de>
parents: 2874
diff changeset
  3716
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3717
        if (ret > 0) {
2861
c098e5766682 Fix #atEnd: for signed chars.
Stefan Vogel <sv@exept.de>
parents: 2854
diff changeset
  3718
            __UNGETC__(c&0xff, f, _buffered);
2679
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3719
            RETURN (false);
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3720
        }
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3721
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3722
        if (ret == 0) { 
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3723
            __INST(hitEOF) = true;
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3724
            RETURN (true);
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3725
        }
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3726
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3727
        /* ret < 0 */
b0fd8c262e2a oops - atEnd must read interruptable.
Claus Gittinger <cg@exept.de>
parents: 2613
diff changeset
  3728
        __INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3729
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3730
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3731
    lastErrorNumber notNil ifTrue:[^ self readError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3732
    ^ self errorNotOpen
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3733
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3734
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3735
canReadWithoutBlocking
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3736
    "return true, if any data is available for reading (i.e.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3737
     a read operation will not block the smalltalk process), false otherwise."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3738
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3739
    |fd|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3740
2986
c6957cf6128f Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents: 2963
diff changeset
  3741
    readAhead notNil ifTrue:[^ true].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3742
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3743
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3744
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3745
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3746
    ^ OperatingSystem readCheck:fd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3747
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3748
    "
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3749
     |pipe|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3750
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3751
     pipe := PipeStream readingFrom:'(sleep 10; echo hello)'.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3752
     pipe canReadWithoutBlocking ifTrue:[
2986
c6957cf6128f Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents: 2963
diff changeset
  3753
         Transcript showCR:'data available'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3754
     ] ifFalse:[
2986
c6957cf6128f Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents: 2963
diff changeset
  3755
         Transcript showCR:'no data available'
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3756
     ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3757
     pipe close
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3758
    "
2986
c6957cf6128f Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents: 2963
diff changeset
  3759
c6957cf6128f Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents: 2963
diff changeset
  3760
    "Modified: 25.9.1997 / 13:08:45 / stefan"
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3761
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3762
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3763
canWriteWithoutBlocking
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3764
    "return true, if data can be written into the stream 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3765
     (i.e. a write operation will not block the smalltalk process)."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3766
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3767
    |fd|
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
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3770
    mode == #readonly ifTrue:[^ self errorReadOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3771
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3772
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3773
    ^ OperatingSystem writeCheck:fd
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3774
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3775
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3776
!ExternalStream methodsFor:'waiting for I/O'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3777
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3778
readWait
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3779
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3780
     becomes ready for reading. If data is already available,
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3781
     return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3782
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3783
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3784
    self readWaitWithTimeoutMs:nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3785
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3786
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3787
readWaitWithTimeout:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3788
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3789
     becomes ready for reading or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3790
     If data is already available, return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3791
     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
  3792
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3793
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3794
    ^ self readWaitWithTimeoutMs:timeout * 1000
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3795
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3796
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3797
readWaitWithTimeoutMs:timeout 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3798
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3799
     becomes ready for reading or a timeout (in milliseconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3800
     If data is already available, return immediate. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3801
     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
  3802
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3803
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3804
    |fd inputSema hasData wasBlocked|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3805
2120
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3806
    readAhead notNil ifTrue:[^ false].
71c1870df7ba implemented 1-character readAhead for unbuffered streams;
Claus Gittinger <cg@exept.de>
parents: 2045
diff changeset
  3807
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3808
    filePointer isNil ifTrue:[^ self errorNotOpen].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3809
    mode == #writeonly ifTrue:[^ self errorWriteOnly].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3810
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3811
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3812
    (OperatingSystem readCheck:fd) ifTrue:[^ false].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3813
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3814
    wasBlocked := OperatingSystem blockInterrupts.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3815
    hasData := OperatingSystem readCheck:fd.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3816
    hasData ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3817
	inputSema := Semaphore new name:'readWait'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3818
	[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3819
	    timeout notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3820
		Processor signal:inputSema afterMilliseconds:timeout 
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3821
	    ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3822
	    Processor signal:inputSema onInput:fd.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3823
	    Processor activeProcess state:#ioWait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3824
	    inputSema wait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3825
	    Processor disableSemaphore:inputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3826
	    hasData := OperatingSystem readCheck:fd
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3827
	] valueOnUnwindDo:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3828
	    Processor disableSemaphore:inputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3829
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3830
	]
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3831
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3832
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3833
    ^ hasData not
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3834
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3835
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3836
writeWait
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3837
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3838
     becomes ready for writing.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3839
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3840
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3841
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3842
    self writeWaitWithTimeoutMs:nil
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3843
!
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
writeWaitWithTimeout:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3846
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3847
     becomes ready for writing or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3848
     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
  3849
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3850
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3851
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3852
    ^ self writeWaitWithTimeoutMs:timeout * 1000
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3853
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3854
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3855
writeWaitWithTimeoutMs:timeout
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3856
    "suspend the current process, until the receiver
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3857
     becomes ready for writing or a timeout (in seconds) expired. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3858
     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
  3859
     Return immediate if the receiver is already ready. 
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3860
     The other threads are not affected by the wait."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3861
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3862
    |fd outputSema canWrite wasBlocked|
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3863
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3864
    filePointer isNil ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3865
	^ self errorNotOpen
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3866
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3867
    mode == #readonly ifTrue:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3868
	^ self errorReadOnly
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3869
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3870
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3871
    fd := self fileDescriptor.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3872
    (OperatingSystem writeCheck:fd) ifTrue:[^ false].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3873
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3874
    wasBlocked := OperatingSystem blockInterrupts.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3875
    canWrite := OperatingSystem writeCheck:fd.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3876
    canWrite ifFalse:[
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3877
	outputSema := Semaphore new name:'writeWait'.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3878
	[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3879
	    timeout notNil ifTrue:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3880
		Processor signal:outputSema afterMilliseconds:timeout
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3881
	    ].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3882
	    Processor signal:outputSema onOutput:fd.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3883
	    Processor activeProcess state:#ioWait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3884
	    outputSema wait.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3885
	    Processor disableSemaphore:outputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3886
	    canWrite := OperatingSystem writeCheck:fd
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3887
	] valueOnUnwindDo:[
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3888
	    Processor disableSemaphore:outputSema.
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3889
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3890
	]
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3891
    ].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3892
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3893
    ^ canWrite not
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3894
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3895
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3896
!ExternalStream methodsFor:'writing'!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3897
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3898
cr
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3899
    "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
  3900
     reimplemented for speed"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3901
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3902
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3903
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3904
    int len, cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3905
    OBJ fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3906
    char *cp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3907
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3908
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3909
    if (((fp = __INST(filePointer)) != nil)
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3910
	&& (__INST(mode) != @symbol(readonly))
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3911
	&& (__INST(binary) != true)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3912
    ) {
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3913
	f = __FILEVal(fp);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3914
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3915
	if (_buffered = (__INST(buffered) == true)) { 
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3916
	    __WRITING__(f)
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3917
	}
2920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3918
	{
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3919
	    OBJ mode = __INST(eolMode);
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3920
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3921
	    if (mode == @symbol(cr)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3922
	        cp = "\r"; len = 1;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3923
	    } else if (mode == @symbol(crlf)) {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3924
	        cp = "\r\n"; len = 2;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3925
	    } else {
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3926
	        cp = "\n"; len = 1;
9c10b66e1ba8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3927
	    }
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3928
	}
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3929
	__WRITEBYTES__(cnt, f, cp, len, _buffered);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3930
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3931
	if (cnt == len) {
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3932
	    if (__INST(position) != nil) {
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3933
		__INST(position) = __MKSMALLINT(__intVal(__INST(position)) + len);
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3934
	    }
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3935
	    RETURN ( self );
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3936
	}
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  3937
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3938
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3939
%}.
2326
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3940
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3941
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3942
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
01fa309e48d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2325
diff changeset
  3943
    self errorBinary
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3944
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3945
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3946
flush
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3947
    "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
  3948
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3949
%{
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3950
    OBJ fp;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3951
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3952
    __INST(lastErrorNumber) = nil;
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3953
    if ((fp = __INST(filePointer)) != nil) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3954
	if (__INST(mode) != @symbol(readonly)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3955
	    if (__INST(buffered) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3956
		__BEGIN_INTERRUPTABLE__
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3957
		FFLUSH( __FILEVal(fp) );
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3958
		__END_INTERRUPTABLE__
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3959
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3960
	}
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3961
    }
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3962
%}
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3963
!
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3964
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3965
nextPut:aCharacter
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3966
    "write the argument, aCharacter - return nil if failed, self if ok.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3967
     Only single-byte characters are currently supported"
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3968
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  3969
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  3970
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3971
    char c;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  3972
    int cnt, _buffered;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3973
    OBJ pos, fp;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3974
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3975
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  3976
    if (((fp = __INST(filePointer)) != nil) 
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3977
	&& (__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
  3978
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3979
	if (__INST(binary) != true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3980
	    if (__isCharacter(aCharacter)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3981
		c = __intVal(__characterVal(aCharacter)) & 0xFF;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  3982
    doWrite:
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3983
		f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3984
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3985
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3986
		if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3987
		    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3988
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3989
		__WRITEBYTE__(cnt, f, &c, _buffered);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3990
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3991
		if (cnt == 1) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3992
		    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3993
		    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3994
			__INST(position) = __MKSMALLINT(__intVal(pos) + 1);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3995
		    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3996
		    RETURN ( self );
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3997
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3998
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  3999
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4000
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4001
	    if (__isSmallInteger(aCharacter)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4002
		c = __intVal(aCharacter);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4003
		goto doWrite;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4004
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4005
	}
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4006
    }
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4007
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4008
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4009
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4010
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4011
    binary ifFalse:[self argumentMustBeCharacter. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4012
    self argumentMustBeInteger.
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4013
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4014
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4015
nextPutAll:aCollection
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4016
    "write all elements of the argument, aCollection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4017
     Reimplemented for speed when writing strings or byteArrays.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4018
     For others, falls back to general method in superclass."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4019
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  4020
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  4021
    FILEPOINTER f;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4022
    int len, cnt;
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4023
    OBJ pos, fp;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4024
    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
  4025
    int o_offs;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4026
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4027
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4028
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4029
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4030
	&& (__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
  4031
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4032
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4033
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4034
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4035
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4036
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4037
	if (__isString(aCollection) || __isSymbol(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4038
	    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
  4039
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4040
	    __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
  4041
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4042
	    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
  4043
	    __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
  4044
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4045
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4046
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4047
		int offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4048
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4049
		if (__isByteArray(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4050
		    offs = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4051
		    len = _byteArraySize(aCollection);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4052
		} else if (__isBytes(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4053
		    offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4054
		    len = _byteArraySize(aCollection) - offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4055
		} else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4056
		    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
  4057
#ifdef BUGGY
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4058
		__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
  4059
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4060
		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
  4061
		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
  4062
		__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
  4063
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4064
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4065
		goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4066
	}
2513
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4067
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4068
	if (cnt == len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4069
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4070
	    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4071
		__INST(position) = __MKSMALLINT(__intVal(pos) + len);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4072
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4073
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4074
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4075
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4076
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  4077
out: ;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4078
%}.
2331
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4079
    lastErrorNumber notNil ifTrue:[self writeError. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4080
    filePointer isNil ifTrue:[self errorNotOpen. ^ self].
d6ddf452adc9 return codes in error cases
Claus Gittinger <cg@exept.de>
parents: 2326
diff changeset
  4081
    (mode == #readonly) ifTrue:[self errorReadOnly. ^ self].
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4082
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4083
    ^ super nextPutAll:aCollection
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4084
!
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4085
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4086
nextPutAll:aCollection startingAt:start to:stop
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4087
    "write a range of elements of the argument, aCollection.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4088
     Reimplemented for speed when writing strings or byteArrays.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4089
     For others, falls back to general method in superclass."
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4090
1067
1e7959af0821 removed all NOCONTEXT (last version did no good - PROTECT-stack overflow ...)
Claus Gittinger <cg@exept.de>
parents: 1066
diff changeset
  4091
%{
2593
d678527ef34e changes for NT; prepare to use HANDLES instead of FILES (NT)
Claus Gittinger <cg@exept.de>
parents: 2591
diff changeset
  4092
    FILEPOINTER f;
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4093
    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
  4094
    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
  4095
    int o_offs;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4096
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4097
    __INST(lastErrorNumber) = nil;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1119
diff changeset
  4098
    if (((fp = __INST(filePointer)) != nil)
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4099
	&& (__INST(mode) != @symbol(readonly))
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4100
	&& __bothSmallInteger(start, stop)
1463
ace6b72b6f4a Use common macros to make interruptable system calls signal proof.
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  4101
    ) {
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4102
	f = __FILEVal(fp);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4103
	if (_buffered = (__INST(buffered) == true)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4104
	    __WRITING__(f)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4105
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4106
	iStart = __intVal(start);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4107
	iStop = __intVal(stop);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4108
	if ((iStart < 1) || (iStop < iStart)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4109
	    RETURN(self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4110
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4111
	if (__isString(aCollection) || __isSymbol(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4112
	    len = __stringSize(aCollection);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4113
	    if (iStop > len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4114
		RETURN(self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4115
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4116
	    if (iStop > len)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4117
		iStop = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4118
	    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
  4119
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4120
	    __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
  4121
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4122
	    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
  4123
	    __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
  4124
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4125
	} else {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4126
	    if (__INST(binary) == true) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4127
		int offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4128
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4129
		if (__isByteArray(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4130
		    offs = 0;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4131
		    len = _byteArraySize(aCollection);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4132
		} else if (__isBytes(aCollection)) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4133
		    offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(aCollection))->c_ninstvars));
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4134
		    len = _byteArraySize(aCollection) - offs;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4135
		} else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4136
		    goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4137
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4138
		if (iStop > len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4139
		    RETURN(self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4140
		}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4141
		if (iStop > len)
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4142
		    iStop = len;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4143
		len = iStop - iStart + 1;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4144
		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
  4145
#ifdef BUGGY
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4146
		__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
  4147
#else
a589586a3828 big bug: READBYTES & WRITEBYTES did not care for moving objects when interrupted.
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
  4148
		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
  4149
		__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
  4150
#endif
2264
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4151
	    } else
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4152
		goto out;
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4153
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4154
	if (cnt == len) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4155
	    pos = __INST(position);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4156
	    if (pos != nil) {
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4157
		__INST(position) = __MKSMALLINT(__intVal(pos) + len);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4158
	    }
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4159
	    RETURN (self);
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4160
	}
ac5dfc03aa26 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
  4161
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4162
    }
1478
aae07192b7d1 labels in empty statements need a semi
Claus Gittinger <cg@exept.de>
parents: 1469
diff changeset
  4163
out: ;
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4164
%}.
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4165
    lastErrorNumber notNil ifTrue:[^ self writeError].
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4166
    ^ super nextPutAll:aCollection startingAt:start to:stop
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4167
! !
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4168
2045
1ad17ca6520f fall back to super>>nextPutLine: if argument is not a string.
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  4169
!ExternalStream class methodsFor:'documentation'!
730
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  4170
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  4171
version
2986
c6957cf6128f Handle readAhead in #canReadWithoutBlocking
Stefan Vogel <sv@exept.de>
parents: 2963
diff changeset
  4172
    ^ '$Header: /cvs/stx/stx/libbasic/ExternalStream.st,v 1.145 1997-09-25 12:58:16 stefan Exp $'
730
62643519bf68 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
  4173
! !
612
e640bef6170e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  4174
ExternalStream initialize!