ObjFW  Diff

Differences From Artifact [470dd5a9cf]:

To Artifact [2787693b17]:


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
88

89
90

91
92
93
94
95
96
97
98
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


133
134
135
136
137
138
139
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

88
89

90
91
92
93
94
95
96



97
98
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
133
134
135
136
137
138
139







-
-
-
+
+
+


-
-
-
+
+
+



-
+

-
+



-
+

-
+



-
+

-
+






-
-
-
+
+
+




-
+




-
+




-
+
















-
-
+
+







_reference_to_OFWin32ConsoleStdIOStream(void)
{
	[OFWin32ConsoleStdIOStream class];
}
#endif

#ifdef OF_AMIGAOS
# undef of_stdin
# undef of_stdout
# undef of_stderr
# undef OFStdIn
# undef OFStdOut
# undef OFStdErr
#endif

OFStdIOStream *of_stdin = nil;
OFStdIOStream *of_stdout = nil;
OFStdIOStream *of_stderr = nil;
OFStdIOStream *OFStdIn = nil;
OFStdIOStream *OFStdOut = nil;
OFStdIOStream *OFStdErr = nil;

#ifdef OF_AMIGAOS
OFStdIOStream **
of_stdin_ref(void)
OFStdInRef(void)
{
	return &of_stdin;
	return &OFStdIn;
}

OFStdIOStream **
of_stdout_ref(void)
OFStdOutRef(void)
{
	return &of_stdout;
	return &OFStdOut;
}

OFStdIOStream **
of_stderr_ref(void)
OFStdErrRef(void)
{
	return &of_stderr;
	return &OFStdErr;
}
#endif

#ifdef OF_AMIGAOS
OF_DESTRUCTOR()
{
	[of_stdin dealloc];
	[of_stdout dealloc];
	[of_stderr dealloc];
	[OFStdIn dealloc];
	[OFStdOut dealloc];
	[OFStdErr dealloc];
}
#endif

void
of_log(OFConstantString *format, ...)
OFLog(OFConstantString *format, ...)
{
	va_list arguments;

	va_start(arguments, format);
	of_logv(format, arguments);
	OFLogV(format, arguments);
	va_end(arguments);
}

void
of_logv(OFConstantString *format, va_list arguments)
OFLogV(OFConstantString *format, va_list arguments)
{
	void *pool = objc_autoreleasePoolPush();
	OFDate *date;
	OFString *dateString, *me, *msg;

	date = [OFDate date];
	dateString = [date localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"];
#ifdef OF_HAVE_FILES
	me = [OFApplication programName].lastPathComponent;
#else
	me = [OFApplication programName];
#endif

	msg = [[[OFString alloc] initWithFormat: format
				      arguments: arguments] autorelease];

	[of_stderr writeFormat: @"[%@.%03d %@(%d)] %@\n", dateString,
				date.microsecond / 1000, me, getpid(), msg];
	[OFStdErr writeFormat: @"[%@.%03d %@(%d)] %@\n", dateString,
			       date.microsecond / 1000, me, getpid(), msg];

	objc_autoreleasePoolPop(pool);
}

#ifdef HAVE_ISATTY
static int
colorToANSI(OFColor *color)
182
183
184
185
186
187
188
189
190

191
192

193
194
195

196
197
198
199
200
201
202
182
183
184
185
186
187
188


189
190

191
192
193

194
195
196
197
198
199
200
201







-
-
+

-
+


-
+







	if (self != [OFStdIOStream class])
		return;

# ifndef OF_AMIGAOS
	int fd;

	if ((fd = fileno(stdin)) >= 0)
		of_stdin = [[OFStdIOStream alloc]
		    of_initWithFileDescriptor: fd];
		OFStdIn = [[OFStdIOStream alloc] of_initWithFileDescriptor: fd];
	if ((fd = fileno(stdout)) >= 0)
		of_stdout = [[OFStdIOStream alloc]
		OFStdOut = [[OFStdIOStream alloc]
		    of_initWithFileDescriptor: fd];
	if ((fd = fileno(stderr)) >= 0)
		of_stderr = [[OFStdIOStream alloc]
		OFStdErr = [[OFStdIOStream alloc]
		    of_initWithFileDescriptor: fd];
# else
	BPTR input, output, error;
	bool inputClosable = false, outputClosable = false,
	    errorClosable = false;

	input = Input();
214
215
216
217
218
219
220
221
222
223
224
225
226






227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246

247
248
249
250
251
252
253
254
213
214
215
216
217
218
219






220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244

245

246
247
248
249
250
251
252







-
-
-
-
-
-
+
+
+
+
+
+



















-
+
-







	}

	if (error == 0) {
		error = Open("*", MODE_OLDFILE);
		errorClosable = true;
	}

	of_stdin = [[OFStdIOStream alloc] of_initWithHandle: input
						   closable: inputClosable];
	of_stdout = [[OFStdIOStream alloc] of_initWithHandle: output
						    closable: outputClosable];
	of_stderr = [[OFStdIOStream alloc] of_initWithHandle: error
						    closable: errorClosable];
	OFStdIn = [[OFStdIOStream alloc] of_initWithHandle: input
						  closable: inputClosable];
	OFStdOut = [[OFStdIOStream alloc] of_initWithHandle: output
						   closable: outputClosable];
	OFStdErr = [[OFStdIOStream alloc] of_initWithHandle: error
						   closable: errorClosable];
# endif
}
#endif

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

#ifndef OF_AMIGAOS
- (instancetype)of_initWithFileDescriptor: (int)fd
{
	self = [super init];

	_fd = fd;

	return self;
}
#else
- (instancetype)of_initWithHandle: (BPTR)handle
- (instancetype)of_initWithHandle: (BPTR)handle closable: (bool)closable
			 closable: (bool)closable
{
	self = [super init];

	_handle = handle;
	_closable = closable;

	return self;
275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290
273
274
275
276
277
278
279

280

281
282
283
284
285
286
287







-
+
-







	if (_handle == 0)
#endif
		@throw [OFNotOpenException exceptionWithObject: self];

	return _atEndOfStream;
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer
- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length
			  length: (size_t)length
{
	ssize_t ret;

#ifndef OF_AMIGAOS
	if (_fd == -1)
		@throw [OFNotOpenException exceptionWithObject: self];

317
318
319
320
321
322
323
324

325
326
327
328
329
330
331
332
314
315
316
317
318
319
320

321

322
323
324
325
326
327
328







-
+
-








	if (ret == 0)
		_atEndOfStream = true;

	return ret;
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer
- (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length
		       length: (size_t)length
{
#ifndef OF_AMIGAOS
	if (_fd == -1)
		@throw [OFNotOpenException exceptionWithObject: self];

# ifndef OF_WINDOWS
	ssize_t bytesWritten;
415
416
417
418
419
420
421
422

423
424
425
426
427
428
429
411
412
413
414
415
416
417

418
419
420
421
422
423
424
425







-
+








- (void)release
{
}

- (unsigned int)retainCount
{
	return OF_RETAIN_COUNT_MAX;
	return OFMaxRetainCount;
}

- (bool)hasTerminal
{
#ifdef HAVE_ISATTY
	return isatty(_fd);
#else
525
526
527
528
529
530
531
532

533
534
535
536
537
538
539
540
541
542
543
544
545
546

547
548
549
550
551
552
553
521
522
523
524
525
526
527

528
529
530
531
532
533
534
535
536
537
538
539
540
541

542
543
544
545
546
547
548
549







-
+













-
+







	if (!isatty(_fd))
		return;

	[self writeFormat: @"\033[%uG", column + 1];
#endif
}

- (void)setCursorPosition: (of_point_t)position
- (void)setCursorPosition: (OFPoint)position
{
	if (position.x < 0 || position.y < 0)
		@throw [OFInvalidArgumentException exception];

#ifdef HAVE_ISATTY
	if (!isatty(_fd))
		return;

	[self writeFormat: @"\033[%u;%uH",
			   (unsigned)position.y + 1, (unsigned)position.x + 1];
#endif
}

- (void)setRelativeCursorPosition: (of_point_t)position
- (void)setRelativeCursorPosition: (OFPoint)position
{
#ifdef HAVE_ISATTY
	if (!isatty(_fd))
		return;

	if (position.x > 0)
		[self writeFormat: @"\033[%uC", (unsigned)position.x];