-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmode.c
237 lines (221 loc) · 5.01 KB
/
mode.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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
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
/*
Licensed under the MIT license. See LICENSE file in the project root for details.
*/
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <util.h>
typedef struct _cmd_t {
char * name;
char * vt_cmd;
char * desc;
#ifndef __STDC__
int (*fn)();
#else
int (*fn)(char *);
#endif
int prefix;
int cpm86;
} _cmd_t;
#ifndef __STDC__
int status(arg)
char* arg;
#else
int status(char* arg)
#endif
{
setstatus(arg);
}
#ifndef __STDC__
int set_mode(arg)
char* arg;
#else
int set_mode(char* arg)
#endif
{
if(!istrcmp("default",arg,0)) {
scrmode(SCRMODE_DEFAULT);
} else if(!istrcmp("col80",arg,0)) {
scrmode(SCRMODE_COL80);
} else if(!istrcmp("col40",arg,0)) {
scrmode(SCRMODE_COL40);
} else if(!istrcmp("color",arg,0)) {
scrmode(SCRMODE_COLOR);
} else if(!istrcmp("mono",arg,0)) {
scrmode(SCRMODE_MONO);
} else {
return -1;
}
return 0;
}
#ifndef __STDC__
int cls(arg)
char* arg;
#else
int cls(char* arg)
#endif
{
clrscr();
return 0;
}
#ifndef __STDC__
int cursor_on(arg)
char* arg;
#else
int cursor_on(char* arg)
#endif
{
cursor(CURSOR_ON);
return 0;
}
#ifndef __STDC__
int cursor_off(arg)
char* arg;
#else
int cursor_off(char* arg)
#endif
{
cursor(CURSOR_OFF);
return 0;
}
#ifndef __STDC__
int statline_on(arg)
char* arg;
#else
int statline_on(char* arg)
#endif
{
statline(STATLINE_ON);
return 0;
}
#ifndef __STDC__
int statline_off(arg)
char* arg;
#else
int statline_off(char* arg)
#endif
{
statline(STATLINE_OFF);
return 0;
}
#ifndef __STDC__
int fg(arg)
char* arg;
#else
int fg(char* arg)
#endif
{
char fg=255;
if(strlen(arg)>1) {
return -1;
}
if(arg[0]>='1' && arg[0]<='9') {
fg=arg[0]-'0';
} else if(arg[0]>='a' && arg[0]<='f') {
fg=arg[0]-'a'+10;
} else if(arg[0]>='A' && arg[0]<='F') {
fg=arg[0]-'A'+10;
} else {
return -1;
}
fprintf(stdout,"\x1bb%c",fg);
return 0;
}
#ifndef __STDC__
int bg(arg)
char* arg;
#else
int bg(char* arg)
#endif
{
char bg=255;
if(strlen(arg)>1) {
return -1;
}
if(arg[0]>='0' && arg[0]<='9') {
bg=arg[0]-'0';
} else if(arg[0]>='a' && arg[0]<='f') {
bg=arg[0]-'a'+10;
} else if(arg[0]>='A' && arg[0]<='F') {
bg=arg[0]='A'+10;
} else {
return -1;
}
fprintf(stdout,"\x1bc%c",bg);
return 0;
}
_cmd_t cmds[]= {
{"cls", 0, "Clear screen",cls, 0, 0x2000},
{"cursor=on", 0, "Show cursor", cursor_on, 0 , 0x2000},
{"cursor=off", 0, "Hide cursor", cursor_off, 0, 0x2000},
{"statln=on", 0, "Show status line", statline_on, 0, 0x22},
{"statln=off", 0, "Hide status line", statline_off, 0, 0x22},
{"status=", 0, "Set status line message", status, 1, 0x22},
{"scr=", 0, "Set screen mode (default,col80,col40,mono,color)", set_mode, 1, 0x22},
{"fg=", 0, "Set foreground color (1-F)", fg, 1, 0x2000},
{"bg=", 0, "Set background color (1-F)", bg, 1, 0x2000},
{0,0,0,0}
};
#ifndef __STDC__
int main(argc, argv)
int argc;
char **argv;
#else
int main(int argc, char **argv)
#endif
{
int index=0;
int done=0;
int arg=1;
int os=osver();
if(argc<2) {
exit(0);
}
if(!strcmp(argv[1],"-h")||!strcmp(argv[1],"-H")) {
fprintf(stderr, "INF: Usage: mode -h | option option ...\n");
fprintf(stderr, "INF: Console configuration utility\n");
fprintf(stderr, "INF: -h for help\n");
fprintf(stderr, "INF: and options:\n");
index=0;
while(cmds[index].name) {
if(os>cmds[index].cpm86) {
index++;
continue;
}
fprintf(stderr, "INF: %-10s %s\n",cmds[index].name,cmds[index].desc);
index++;
}
exit(0);
}
freopen("con:", "w", stdout);
while(arg<argc) {
done=0;
index=0;
while(cmds[index].name) {
if(!istrcmp(cmds[index].name,argv[arg],cmds[index].prefix)) {
if(os>cmds[index].cpm86) {
index++;
continue;
}
done=1;
if(cmds[index].fn) {
if(cmds[index].fn(argv[arg]+strlen(cmds[index].name))) {
fprintf(stderr, "ERR: Action(%s) failed\n",argv[arg]);
exit(-1);
}
}
if(cmds[index].vt_cmd) {
printf("%s",cmds[index].vt_cmd);
}
break;
}
index++;
}
if(!done) {
fprintf(stderr, "ERR: Action(%s) unknown\n",argv[arg]);
exit(-1);
}
arg++;
}
exit(0);
}