ObjFW  Diff

Differences From Artifact [56aed5bccb]:

To Artifact [a9dd0b73a2]:


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


100
101
102
103
104
105
106
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
88
89
90
91
92
93
94
95
96
97


98
99
100
101
102
103
104
105
106







-
-
-
+
+
+




-
-
-
+
+
+




-
+



















-
-
+
+







void
_reference_to_OFWin32ConsoleStdIOStream(void)
{
	[OFWin32ConsoleStdIOStream class];
}
#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
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, ...)
{
	void *pool = objc_autoreleasePoolPush();
	OFDate *date;
	OFString *dateString, *me, *msg;
	va_list arguments;

	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

	va_start(arguments, format);
	msg = [[[OFString alloc] initWithFormat: format
				      arguments: arguments] autorelease];
	va_end(arguments);

	[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)
149
150
151
152
153
154
155
156
157

158
159

160
161
162

163
164
165
166
167
168
169
149
150
151
152
153
154
155


156
157

158
159
160

161
162
163
164
165
166
167
168







-
-
+

-
+


-
+







	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();
181
182
183
184
185
186
187
188
189
190
191
192
193






194
195
196
197
198
199
200
180
181
182
183
184
185
186






187
188
189
190
191
192
193
194
195
196
197
198
199







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







	}

	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
379
380
381
382
383
384
385
386

387
388
389
390
391
392
393
378
379
380
381
382
383
384

385
386
387
388
389
390
391
392







-
+








- (void)release
{
}

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

- (bool)hasTerminal
{
#ifdef HAVE_ISATTY
	return isatty(_fd);
#else
489
490
491
492
493
494
495
496

497
498
499
500
501
502
503
504
505
506
507
508
509
510

511
512
513
514
515
516
517
488
489
490
491
492
493
494

495
496
497
498
499
500
501
502
503
504
505
506
507
508

509
510
511
512
513
514
515
516







-
+













-
+







	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];