-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.c
156 lines (128 loc) · 2.22 KB
/
io.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* Routines for character input and output to the BBS */
#include "defs.h"
#include "ext.h"
#ifndef BBS
int ansi = 0;
#endif
/* A standard printf -- no color code recognition. */
/* works best if output is not fflushed */
my_printf (const char *fmt, ...)
{
char string [1024];
va_list ap;
va_start (ap, fmt);
(void) vsprintf (string, fmt, ap);
va_end (ap);
return my_puts (string);
}
my_puts (s)
char *s;
{
int count;
count = 0;
while (*s) {
count = count + (my_putchar (*s) != EOF);
s++;
}
return (count);
}
/* A simple printf that recognizes color codes */
colorize (const char *fmt, ...)
{
char string [1024];
va_list ap;
va_start (ap, fmt);
(void) vsprintf (string, fmt, ap);
va_end (ap);
return my_cputs (string);
}
/* check for color codes and \r\n translation. Return the number of characters
(not including color codes) printed. */
my_cputs (s)
char *s;
{
int count;
count = 0;
while (*s) {
if (*s == '@') {
s++;
if (ansi)
switch (*s) {
case '@':
count = count + (my_putchar ('@') != EOF);
break;
case 'r':
case 'R':
output ("\033[31m");
break;
case 'g':
case 'G':
output ("\033[32m");
break;
case 'y':
case 'Y':
output ("\033[33m");
break;
case 'b':
case 'B':
output ("\033[34m");
break;
case 'm':
case 'M':
case 'p':
case 'P':
output ("\033[35m");
break;
case 'c':
case 'C':
output ("\033[36m");
break;
case 'w':
case 'W':
output ("\033[37m");
break;
case 'd':
case 'D':
output ("\033[1m\033[33m");
break;
}
else if (*s == '@')
count = count + (my_putchar (*s) != EOF);
} else
count = count + (my_putchar (*s) != EOF);
s++;
}
return count;
}
output (s)
char *s;
{
while (*s) {
my_putchar (*s);
s++;
}
return 0;
}
my_putchar (c)
int c;
{
#ifdef _SSL
char newline = '\r';
if (c == '\n')
SSL_write (1, &newline, sizeof (newline));
SSL_write (1, &c, sizeof (c));
return (c);
#else
if (c == '\n')
putchar ('\r');
return (putchar (c));
#endif
}
my_putc (c, stream)
int c;
FILE *stream;
{
int i;
i = putc (c, stream);
return (i);
}