forked from torvalds/uemacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vmsvt.c
489 lines (412 loc) · 11.5 KB
/
vmsvt.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
/* VMSVT.C
*
* Advanced VMS terminal driver
*
* Knows about any terminal defined in SMGTERMS.TXT and TERMTABLE.TXT
* located in SYS$SYSTEM.
*
* Author: Curtis Smith
* modified by Petri Kutvonen
*/
#include <stdio.h> /* Standard I/O package */
#include "estruct.h" /* Emacs' structures */
#include "edef.h" /* Emacs' definitions */
#if VMSVT
#include <descrip.h> /* Descriptor definitions */
/* These would normally come from iodef.h and ttdef.h */
#define IO$_SENSEMODE 0x27 /* Sense mode of terminal */
#define TT$_UNKNOWN 0x00 /* Unknown terminal */
#define TT$_VT100 96
/** Forward references **/
int vmsopen(), ttclose(), vmskopen(), vmskclose(), ttgetc(), ttputc();
int ttflush(), vmsmove(), vmseeol(), vmseeop(), vmsbeep(), vmsrev();
int vmscres();
extern int eolexist, revexist;
extern char sres[];
#if COLOR
int vmsfcol(), vmsbcol();
#endif
/** SMG stuff **/
static char *begin_reverse, *end_reverse, *erase_to_end_line;
static char *erase_whole_display;
static int termtype;
#define SMG$K_BEGIN_REVERSE 0x1bf
#define SMG$K_END_REVERSE 0x1d6
#define SMG$K_SET_CURSOR_ABS 0x23a
#define SMG$K_ERASE_WHOLE_DISPLAY 0x1da
#define SMG$K_ERASE_TO_END_LINE 0x1d9
#if SCROLLCODE
#define SMG$K_SCROLL_FORWARD 561 /* from sys$library:smgtrmptr.h */
#define SMG$K_SCROLL_REVERSE 562
#define SMG$K_SET_SCROLL_REGION 572
static char *scroll_forward, *scroll_reverse;
#endif
/* Dispatch table. All hard fields just point into the terminal I/O code. */
struct terminal term = {
#if PKCODE
MAXROW,
#else
24 - 1, /* Max number of rows allowable */
#endif
/* Filled in */ -1,
/* Current number of rows used */
MAXCOL, /* Max number of columns */
/* Filled in */ 0,
/* Current number of columns */
64, /* Min margin for extended lines */
8, /* Size of scroll region */
100, /* # times thru update to pause */
vmsopen, /* Open terminal at the start */
ttclose, /* Close terminal at end */
vmskopen, /* Open keyboard */
vmskclose, /* Close keyboard */
ttgetc, /* Get character from keyboard */
ttputc, /* Put character to display */
ttflush, /* Flush output buffers */
vmsmove, /* Move cursor, origin 0 */
vmseeol, /* Erase to end of line */
vmseeop, /* Erase to end of page */
vmsbeep, /* Beep */
vmsrev, /* Set reverse video state */
vmscres /* Change screen resolution */
#if COLOR
, vmsfcol, /* Set forground color */
vmsbcol /* Set background color */
#endif
#if SCROLLCODE
, NULL
#endif
};
/***
* ttputs - Send a string to ttputc
*
* Nothing returned
***/
ttputs(string)
char *string; /* String to write */
{
if (string)
while (*string != '\0')
ttputc(*string++);
}
/***
* vmsmove - Move the cursor (0 origin)
*
* Nothing returned
***/
vmsmove(row, col)
int row; /* Row position */
int col; /* Column position */
{
char buffer[32];
int ret_length;
static int request_code = SMG$K_SET_CURSOR_ABS;
static int max_buffer_length = sizeof(buffer);
static int arg_list[3] = { 2 };
char *cp;
int i;
/* Set the arguments into the arg_list array
* SMG assumes the row/column positions are 1 based (boo!)
*/
arg_list[1] = row + 1;
arg_list[2] = col + 1;
if ((smg$get_term_data( /* Get terminal data */
&termtype, /* Terminal table address */
&request_code, /* Request code */
&max_buffer_length, /* Maximum buffer length */
&ret_length, /* Return length */
buffer, /* Capability data buffer */
arg_list)
/* Argument list array */
/* We'll know soon enough if this doesn't work */
&1) == 0) {
ttputs("OOPS");
return;
}
/* Send out resulting sequence */
i = ret_length;
cp = buffer;
while (i-- > 0)
ttputc(*cp++);
}
#if SCROLLCODE
vmsscroll_reg(from, to, howmany)
{
int i;
if (to == from)
return;
if (to < from) {
vmsscrollregion(to, from + howmany - 1);
vmsmove(from + howmany - 1, 0);
for (i = from - to; i > 0; i--)
ttputs(scroll_forward);
} else { /* from < to */
vmsscrollregion(from, to + howmany - 1);
vmsmove(from, 0);
for (i = to - from; i > 0; i--)
ttputs(scroll_reverse);
}
vmsscrollregion(-1, -1);
}
vmsscrollregion(top, bot)
int top; /* Top position */
int bot; /* Bottom position */
{
char buffer[32];
int ret_length;
static int request_code = SMG$K_SET_SCROLL_REGION;
static int max_buffer_length = sizeof(buffer);
static int arg_list[3] = { 2 };
char *cp;
int i;
/* Set the arguments into the arg_list array
* SMG assumes the row/column positions are 1 based (boo!)
*/
arg_list[1] = top + 1;
arg_list[2] = bot + 1;
if ((smg$get_term_data( /* Get terminal data */
&termtype, /* Terminal table address */
&request_code, /* Request code */
&max_buffer_length, /* Maximum buffer length */
&ret_length, /* Return length */
buffer, /* Capability data buffer */
arg_list)
/* Argument list array */
/* We'll know soon enough if this doesn't work */
&1) == 0) {
ttputs("OOPS");
return;
}
ttputc(0);
/* Send out resulting sequence */
i = ret_length;
cp = buffer;
while (i-- > 0)
ttputc(*cp++);
}
#endif
/***
* vmsrev - Set the reverse video status
*
* Nothing returned
***/
vmsrev(status)
int status; /* TRUE if setting reverse */
{
if (status)
ttputs(begin_reverse);
else
ttputs(end_reverse);
}
/***
* vmscres - Change screen resolution (which it doesn't)
*
* Nothing returned
***/
vmscres()
{
/* But it could. For vt100/vt200s, one could switch from
80 and 132 columns modes */
}
#if COLOR
/***
* vmsfcol - Set the forground color (not implimented)
*
* Nothing returned
***/
vmsfcol()
{
}
/***
* vmsbcol - Set the background color (not implimented)
*
* Nothing returned
***/
vmsbcol()
{
}
#endif
/***
* vmseeol - Erase to end of line
*
* Nothing returned
***/
vmseeol()
{
ttputs(erase_to_end_line);
}
/***
* vmseeop - Erase to end of page (clear screen)
*
* Nothing returned
***/
vmseeop()
{
ttputs(erase_whole_display);
}
/***
* vmsbeep - Ring the bell
*
* Nothing returned
***/
vmsbeep()
{
ttputc('\007');
}
/***
* vmsgetstr - Get an SMG string capability by name
*
* Returns: Escape sequence
* NULL No escape sequence available
***/
char *vmsgetstr(request_code)
int request_code; /* Request code */
{
char *result;
static char seq_storage[1024];
static char *buffer = seq_storage;
static int arg_list[2] = { 1, 1 };
int max_buffer_length, ret_length;
/* Precompute buffer length */
max_buffer_length = (seq_storage + sizeof(seq_storage)) - buffer;
/* Get terminal commands sequence from master table */
if ((smg$get_term_data( /* Get terminal data */
&termtype, /* Terminal table address */
&request_code, /* Request code */
&max_buffer_length, /* Maximum buffer length */
&ret_length, /* Return length */
buffer, /* Capability data buffer */
arg_list)
/* Argument list array */
/* If this doesn't work, try again with no arguments */
&1) == 0 && (smg$get_term_data( /* Get terminal data */
&termtype, /* Terminal table address */
&request_code, /* Request code */
&max_buffer_length, /* Maximum buffer length */
&ret_length, /* Return length */
buffer)
/* Capability data buffer */
/* Return NULL pointer if capability is not available */
&1) == 0)
return NULL;
/* Check for empty result */
if (ret_length == 0)
return NULL;
/* Save current position so we can return it to caller */
result = buffer;
/* NIL terminate the sequence for return */
buffer[ret_length] = 0;
/* Advance buffer */
buffer += ret_length + 1;
/* Return capability to user */
return result;
}
/** I/O information block definitions **/
struct iosb { /* I/O status block */
short i_cond; /* Condition value */
short i_xfer; /* Transfer count */
long i_info; /* Device information */
};
struct termchar { /* Terminal characteristics */
char t_class; /* Terminal class */
char t_type; /* Terminal type */
short t_width; /* Terminal width in characters */
long t_mandl; /* Terminal's mode and length */
long t_extend; /* Extended terminal characteristics */
};
static struct termchar tc; /* Terminal characteristics */
/***
* vmsgtty - Get terminal type from system control block
*
* Nothing returned
***/
vmsgtty()
{
short fd;
int status;
struct iosb iostatus;
$DESCRIPTOR(devnam, "SYS$INPUT");
/* Assign input to a channel */
status = sys$assign(&devnam, &fd, 0, 0);
if ((status & 1) == 0)
exit(status);
/* Get terminal characteristics */
status = sys$qiow( /* Queue and wait */
0, /* Wait on event flag zero */
fd, /* Channel to input terminal */
IO$_SENSEMODE, /* Get current characteristic */
&iostatus, /* Status after operation */
0, 0, /* No AST service */
&tc, /* Terminal characteristics buf */
sizeof(tc), /* Size of the buffer */
0, 0, 0, 0); /* P3-P6 unused */
/* De-assign the input device */
if ((sys$dassgn(fd) & 1) == 0)
exit(status);
/* Jump out if bad status */
if ((status & 1) == 0)
exit(status);
if ((iostatus.i_cond & 1) == 0)
exit(iostatus.i_cond);
}
/***
* vmsopen - Get terminal type and open terminal
*
* Nothing returned
***/
vmsopen()
{
/* Get terminal type */
vmsgtty();
if (tc.t_type == TT$_UNKNOWN) {
printf("Terminal type is unknown!\n");
printf
("Try set your terminal type with SET TERMINAL/INQUIRE\n");
printf("Or get help on SET TERMINAL/DEVICE_TYPE\n");
exit(3);
}
/* Access the system terminal definition table for the */
/* information of the terminal type returned by IO$_SENSEMODE */
if ((smg$init_term_table_by_type(&tc.t_type, &termtype) & 1) == 0)
return -1;
/* Set sizes */
term.t_nrow = ((unsigned int) tc.t_mandl >> 24) - 1;
term.t_ncol = tc.t_width;
/* Get some capabilities */
begin_reverse = vmsgetstr(SMG$K_BEGIN_REVERSE);
end_reverse = vmsgetstr(SMG$K_END_REVERSE);
revexist = begin_reverse != NULL && end_reverse != NULL;
erase_to_end_line = vmsgetstr(SMG$K_ERASE_TO_END_LINE);
eolexist = erase_to_end_line != NULL;
erase_whole_display = vmsgetstr(SMG$K_ERASE_WHOLE_DISPLAY);
#if SCROLLCODE
scroll_forward = vmsgetstr(SMG$K_SCROLL_FORWARD);
scroll_reverse = vmsgetstr(SMG$K_SCROLL_REVERSE);
if (tc.t_type < TT$_VT100 || scroll_reverse == NULL ||
scroll_forward == NULL)
term.t_scroll = NULL;
else
term.t_scroll = vmsscroll_reg;
#endif
/* Set resolution */
strcpy(sres, "NORMAL");
/* Open terminal I/O drivers */
ttopen();
}
/***
* vmskopen - Open keyboard (not used)
*
* Nothing returned
***/
vmskopen()
{
}
/***
* vmskclose - Close keyboard (not used)
*
* Nothing returned
***/
vmskclose()
{
}
#endif