45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# include <proto/dos.h>
# undef BOOL
# define INVALID_FD 0
# define getpid() ((int)SysBase->ThisTask)
# define read(fd, buf, len) Read(fd, buf, len)
# define write(fd, buf, len) Write(fd, buf, len)
# define close(fd) Close(fd)
extern struct ExecBase *SysBase;
#endif
#ifndef INVALID_FD
# define INVALID_FD -1
#endif
/* References for static linking */
#ifdef OF_WINDOWS
void
_reference_to_OFStdIOStream_Win32Console(void)
{
[OFStdIOStream_Win32Console class];
}
#endif
OFStdIOStream *of_stdin = nil;
OFStdIOStream *of_stdout = nil;
OFStdIOStream *of_stderr = nil;
void
of_log(OFConstantString *format, ...)
{
void *pool = objc_autoreleasePoolPush();
OFDate *date;
OFString *dateString, *me, *msg;
|
<
>
>
>
>
>
>
>
>
>
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# include <proto/dos.h>
# undef BOOL
# define INVALID_FD 0
# define getpid() ((int)SysBase->ThisTask)
# define read(fd, buf, len) Read(fd, buf, len)
# define write(fd, buf, len) Write(fd, buf, len)
extern struct ExecBase *SysBase;
#endif
#ifndef INVALID_FD
# define INVALID_FD -1
#endif
/* References for static linking */
#ifdef OF_WINDOWS
void
_reference_to_OFStdIOStream_Win32Console(void)
{
[OFStdIOStream_Win32Console class];
}
#endif
OFStdIOStream *of_stdin = nil;
OFStdIOStream *of_stdout = nil;
OFStdIOStream *of_stderr = nil;
#if defined(OF_MORPHOS) && !defined(OF_IXEMUL)
OF_DESTRUCTOR()
{
[of_stdin dealloc];
[of_stdout dealloc];
[of_stderr dealloc];
}
#endif
void
of_log(OFConstantString *format, ...)
{
void *pool = objc_autoreleasePoolPush();
OFDate *date;
OFString *dateString, *me, *msg;
|
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
+ (void)load
{
# if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
of_stdin = [[OFStdIOStream alloc] of_initWithFileDescriptor: 0];
of_stdout = [[OFStdIOStream alloc] of_initWithFileDescriptor: 1];
of_stderr = [[OFStdIOStream alloc] of_initWithFileDescriptor: 2];
# else
of_stdin = [[OFStdIOStream alloc] of_initWithFileDescriptor: Input()];
of_stdout = [[OFStdIOStream alloc] of_initWithFileDescriptor: Output()];
of_stderr = [[OFStdIOStream alloc] of_initWithFileDescriptor: Output()];
# endif
}
#endif
- init
{
OF_INVALID_INIT_METHOD
}
- (instancetype)of_initWithFileDescriptor: (int)fd
{
self = [super init];
_fd = fd;
return self;
}
- (bool)lowlevelIsAtEndOfStream
{
if (_fd == INVALID_FD)
return true;
return _atEndOfStream;
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
+ (void)load
{
# if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
of_stdin = [[OFStdIOStream alloc] of_initWithFileDescriptor: 0];
of_stdout = [[OFStdIOStream alloc] of_initWithFileDescriptor: 1];
of_stderr = [[OFStdIOStream alloc] of_initWithFileDescriptor: 2];
# else
BPTR input = Input(), output = Output();
BPTR error = ((struct Process *)SysBase->ThisTask)->pr_CES;
bool inputClosable = false, outputClosable = false,
errorClosable = false;
if (input == INVALID_FD) {
input = Open("*", MODE_OLDFILE);
inputClosable = true;
}
if (output == INVALID_FD) {
output = Open("*", MODE_OLDFILE);
outputClosable = true;
}
if (error == INVALID_FD) {
error = Open("*", MODE_OLDFILE);
errorClosable = true;
}
of_stdin = [[OFStdIOStream alloc]
of_initWithFileDescriptor: input
closable: inputClosable];
of_stdout = [[OFStdIOStream alloc]
of_initWithFileDescriptor: output
closable: outputClosable];
of_stderr = [[OFStdIOStream alloc]
of_initWithFileDescriptor: error
closable: errorClosable];
# endif
}
#endif
- init
{
OF_INVALID_INIT_METHOD
}
#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
- (instancetype)of_initWithFileDescriptor: (int)fd
{
self = [super init];
_fd = fd;
return self;
}
#else
- (instancetype)of_initWithFileDescriptor: (long)fd
closable: (bool)closable
{
self = [super init];
_fd = fd;
_closable = closable;
return self;
}
#endif
- (void)dealloc
{
[self close];
[super dealloc];
}
- (bool)lowlevelIsAtEndOfStream
{
if (_fd == INVALID_FD)
return true;
return _atEndOfStream;
|
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
{
return _fd;
}
#endif
- (void)close
{
if (_fd != INVALID_FD)
close(_fd);
_fd = INVALID_FD;
[super close];
}
- autorelease
|
>
>
>
>
>
|
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
{
return _fd;
}
#endif
- (void)close
{
#if !defined(OF_MORPHOS) || defined(OF_IXEMUL)
if (_fd != INVALID_FD)
close(_fd);
#else
if (_closable && _fd != INVALID_FD)
Close(_fd);
#endif
_fd = INVALID_FD;
[super close];
}
- autorelease
|
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
}
- (unsigned int)retainCount
{
return OF_RETAIN_COUNT_MAX;
}
- (void)dealloc
{
OF_DEALLOC_UNSUPPORTED
}
- (int)columns
{
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ)
struct winsize ws;
if (ioctl(_fd, TIOCGWINSZ, &ws) != 0)
return -1;
|
<
<
<
<
<
|
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
}
- (unsigned int)retainCount
{
return OF_RETAIN_COUNT_MAX;
}
- (int)columns
{
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ)
struct winsize ws;
if (ioctl(_fd, TIOCGWINSZ, &ws) != 0)
return -1;
|