4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.34 2008/02/23 11:48:37 james
14 * *** empty log message ***
16 * Revision 1.33 2008/02/22 23:39:27 james
17 * *** empty log message ***
19 * Revision 1.32 2008/02/22 19:12:05 james
20 * *** empty log message ***
22 * Revision 1.31 2008/02/22 17:07:00 james
23 * *** empty log message ***
25 * Revision 1.30 2008/02/22 14:51:54 james
26 * *** empty log message ***
28 * Revision 1.29 2008/02/15 03:32:07 james
29 * *** empty log message ***
31 * Revision 1.28 2008/02/14 10:34:30 james
32 * *** empty log message ***
34 * Revision 1.27 2008/02/14 02:46:45 james
35 * *** empty log message ***
37 * Revision 1.26 2008/02/14 01:55:57 james
38 * *** empty log message ***
40 * Revision 1.25 2008/02/13 16:57:29 james
41 * *** empty log message ***
43 * Revision 1.24 2008/02/13 09:12:21 james
44 * *** empty log message ***
46 * Revision 1.23 2008/02/07 13:26:35 james
47 * *** empty log message ***
49 * Revision 1.22 2008/02/07 13:22:51 james
50 * *** empty log message ***
52 * Revision 1.21 2008/02/07 12:21:16 james
53 * *** empty log message ***
55 * Revision 1.20 2008/02/07 12:16:04 james
56 * *** empty log message ***
58 * Revision 1.19 2008/02/07 11:27:02 james
59 * *** empty log message ***
61 * Revision 1.18 2008/02/07 01:59:25 james
62 * *** empty log message ***
64 * Revision 1.17 2008/02/07 01:58:28 james
65 * *** empty log message ***
67 * Revision 1.16 2008/02/07 01:57:46 james
68 * *** empty log message ***
70 * Revision 1.15 2008/02/07 00:43:27 james
71 * *** empty log message ***
73 * Revision 1.14 2008/02/07 00:40:23 james
74 * *** empty log message ***
76 * Revision 1.13 2008/02/07 00:39:59 james
77 * *** empty log message ***
79 * Revision 1.12 2008/02/07 00:39:13 james
80 * *** empty log message ***
82 * Revision 1.11 2008/02/06 20:26:58 james
83 * *** empty log message ***
85 * Revision 1.10 2008/02/06 17:53:28 james
86 * *** empty log message ***
88 * Revision 1.9 2008/02/06 15:53:22 james
89 * *** empty log message ***
91 * Revision 1.8 2008/02/06 11:49:47 james
92 * *** empty log message ***
94 * Revision 1.7 2008/02/06 11:30:37 james
95 * *** empty log message ***
97 * Revision 1.6 2008/02/05 01:11:46 james
98 * *** empty log message ***
100 * Revision 1.5 2008/02/04 20:23:55 james
101 * *** empty log message ***
103 * Revision 1.4 2008/02/04 05:45:55 james
106 * Revision 1.3 2008/02/04 02:05:06 james
107 * *** empty log message ***
109 * Revision 1.2 2008/02/04 01:32:39 james
110 * *** empty log message ***
112 * Revision 1.1 2008/02/03 23:36:41 james
113 * *** empty log message ***
124 :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100:
126 vt100|vt100-am|dec vt100 (w/advanced video):\
128 :co#80:it#8:li#24:vt#3:\
129 :DO=\E[%dB:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:\
131 :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\
132 :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
133 :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\
134 :eA=\E(B\E)0:ho=\E[H:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\
135 :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\
136 :me=\E[m\017:mr=\E[7m:nd=\E[C:rc=\E8:\
137 :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:sc=\E7:se=\E[m:\
138 :sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:up=\E[A:\
139 :us=\E[4m:tc=vt100+fnkeys:
141 vt100+fnkeys|dec vt100 numeric keypad:\
142 :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\
145 vt100+pfkeys|dec vt100 numeric keypad:\
146 :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad:
148 vt100+keypad|dec vt100 numeric keypad no fkeys:\
149 :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:
154 so the parser needs to be able to at least do
216 ansi|ansi/pc-term compatible with color:\
217 :u6=\E[%i%d;%dR:u7=\E[6n:u9=\E[c:tc=ecma+color:\
218 :tc=klone+sgr:tc=ansi-m:
219 ansi-m|ansi-mono|ANSI X3.64-1979 terminal with ANSI.SYS compatible attributes:\
221 :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\
222 :LE=\E[%dD:RI=\E[%dC:SF=\E[%dS:SR=\E[%dT:UP=\E[%dA:\
223 :cb=\E[1K:ch=\E[%i%dG:ct=\E[2g:cv=\E[%i%dd:ec=\E[%dX:ei=:\
224 :im=:kB=\E[Z:kI=\E[L:kb=^H:kd=\E[B:kl=\E[D:kr=\E[C:ku=\E[A:\
225 :nw=\r\E[S:pf=\E[4i:po=\E[5i:s0=\E(B:s1=\E)B:s2=\E*B:\
226 :s3=\E+B:ta=\E[I:tc=pcansi-m:
227 pcansi-m|pcansi-mono|ibm-pc terminal programs claiming to be ansi (mono mode):\
230 :al=\E[L:bl=^G:bt=\E[Z:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
231 :cm=\E[%i%d;%dH:cr=^M:ct=\E[2g:dc=\E[P:dl=\E[M:do=\E[B:\
232 :ho=\E[H:kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:\
233 :le=\E[D:nd=\E[C:sf=^J:st=\EH:ta=^I:up=\E[A:\
235 klone+sgr-dumb|attribute control for ansi.sys displays (no ESC [ 11 m):\
236 :as=\E[12m:mb=\E[5m:md=\E[1m:me=\E[0;10m:mk=\E[8m:\
237 :mr=\E[7m:se=\E[m:so=\E[7m:ue=\E[m:us=\E[4m:tc=klone+acs:
238 klone+acs|alternate character set for ansi.sys displays:\
239 :ac=+\020,\021-\030.^Y0\333`\004a\261f\370g\361h\260j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376:\
240 :ae=\E[10m:as=\E[11m:
241 ecma+color|color control for ECMA-48-compatible terminals:\
243 :AB=\E[4%dm:AF=\E[3%dm:op=\E[39;49m:
246 Ignoreing ones in the VT102 spec
290 if ((c >= 'a') && (c <= 'z'))
292 if ((c >= 'A') && (c <= 'Z'))
323 in_margins (VT102 * v, CRT_Pos p)
325 if (v->pos.x < v->top_margin.x)
327 if (v->pos.y < v->top_margin.y)
330 if (v->pos.x > v->bottom_margin.x)
332 if (v->pos.y > v->bottom_margin.y)
339 vt102_log_line (Context * c, int line)
341 CRT_Pos e = { VT102_COLS - 1, line };
342 CRT_Pos p = { 0, line };
343 char logbuf[VT102_COLS + 1];
349 for (; e.x > 0; --e.x)
351 if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
355 for (; p.x <= e.x; ++p.x)
357 int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr;
366 c->l->log (c->l, logbuf);
369 /*Called for every upward scroll with same args*/
371 vt102_history (Context * c, CRT_Pos t, CRT_Pos b)
373 /*Only log if it scrolls off the top*/
378 history_add (c->h, &(c->v->crt.screen[CRT_ADDR_POS (&t)]));
382 vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br)
397 vt102_cursor_normalize (VT102 * v)
399 CRT_Pos *top, *bottom;
401 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
403 vt102_clip_cursor (v, v->top_margin, v->bottom_margin);
407 vt102_clip_cursor (v, v->screen_start, v->screen_end);
413 vt102_cursor_carriage_return (VT102 * v)
415 /*FISH*/ v->pos.x = v->top_margin.x;
420 vt102_cursor_advance_line (Context * c)
423 int couldscroll = in_margins (v, v->pos);
425 /*have wraped off end of last line in scrolling region */
426 /* (|| not necessary, but shuts compiler up */
427 if (((v->pos.y == v->bottom_margin.y) || (v->pos.y == v->screen_end.y)) &&
430 vt102_log_line (c, v->pos.y);
432 vt102_history (c, v->top_margin, v->bottom_margin);
434 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, v->color);
438 if (v->pos.y != v->screen_end.y)
445 vt102_do_pending_wrap (Context * c)
448 int couldscroll = in_margins (v, v->pos);
449 int autowrap = v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP];
451 if (!v->pending_wrap)
455 fprintf (stderr, "ca: (%d,%d) autowrap %d couldscroll %d\n", v->pos.x,
456 v->pos.y, autowrap, couldscroll);
459 /*End of line but no autowrap, nothing to do*/
463 /*End of screen and not allowed to scroll, nothing to do*/
464 if ((v->pos.y == v->screen_end.y) && (!couldscroll))
469 v->pos.x = v->top_margin.x;
476 vt102_cursor_advance_line (c);
480 vt102_cursor_advance (Context * c)
484 if (v->pos.x < v->bottom_margin.x)
492 if (!c->v->xn_glitch)
493 vt102_do_pending_wrap (c);
499 vt102_cursor_retard (VT102 * v)
501 if (v->pos.x != v->top_margin.x)
508 vt102_reset_tabs (VT102 * v)
512 memset (v->tabs, 0, sizeof (v->tabs));
514 for (i = 0; i < VT102_COLS; i += 8)
520 vt102_cursor_advance_tab (VT102 * v)
522 if (v->pos.x == v->bottom_margin.x)
524 while (v->pos.x < v->bottom_margin.x)
527 if (v->tabs[v->pos.x])
534 vt102_cursor_retard_tab (VT102 * v)
536 if (v->pos.x == v->top_margin.x)
538 while (v->pos.x > v->top_margin.x)
541 if (v->tabs[v->pos.x])
547 vt102_cursor_home (VT102 * v)
549 v->pos = v->top_margin;
550 vt102_cursor_normalize (v);
555 vt102_cursor_absolute (VT102 * v, int x, int y)
557 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
559 v->pos.x = x + v->top_margin.x;
560 v->pos.y = y + v->top_margin.x;
567 vt102_cursor_normalize (v);
571 vt102_cursor_relative (VT102 * v, int x, int y)
575 vt102_cursor_normalize (v);
582 vt102_delete_from_line (VT102 * v, CRT_Pos p)
584 int n = v->bottom_margin.x - p.x;
592 memmove (&v->crt.screen[CRT_ADDR_POS (&p)],
593 &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n);
596 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
597 /*But not attr due to vt102 bug*/
601 vt102_insert_into_line (VT102 * v, CRT_Pos p)
603 int n = v->bottom_margin.x - p.x;
611 memmove (&v->crt.screen[CRT_ADDR_POS (&p) + 1],
612 &v->crt.screen[CRT_ADDR_POS (&p)], sizeof (CRT_CA) * n);
615 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
616 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].attr = CRT_ATTR_NORMAL;
617 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].color = CRT_COLOR_NORMAL;
623 vt102_change_mode (VT102 * v, int private, char *ns, int set)
639 if (m >= VT102_NMODES)
644 v->private_modes[m] = set;
647 case VT102_PRIVATE_MODE_CURSOR_MODE:
648 if (v->application_keypad_mode)
649 v->private_modes[m] = 0;
651 fprintf (stderr, "APPLICATION CURSOR MODE %d wanted %d\n",
652 v->private_modes[m], set);
655 case VT102_PRIVATE_MODE_ORIGIN_MODE:
656 vt102_cursor_home (v);
665 fprintf (stderr, "mode set=%d private=%d num=%d\n", set, private, m);
670 vt102_parse_mode_string (VT102 * v, char *buf, int len)
673 char last = buf[len - 1];
677 memset (num, 0, sizeof (num));
678 o = sizeof (num) - 1;
696 vt102_change_mode (v, private, &num[o], last == 'h');
697 memset (num, 0, sizeof (num));
698 o = sizeof (num) - 1;
713 vt102_change_mode (v, private, &num[o], last == 'h');
719 vt102_change_attr (VT102 * v, char *na)
736 v->attr = CRT_ATTR_NORMAL;
737 v->color = CRT_COLOR_NORMAL;
740 v->attr |= CRT_ATTR_BOLD;
744 v->attr &= ~CRT_ATTR_BOLD;
747 v->attr |= CRT_ATTR_UNDERLINE;
750 v->attr &= ~CRT_ATTR_UNDERLINE;
753 v->attr |= CRT_ATTR_BLINK;
756 v->attr &= ~CRT_ATTR_BLINK;
759 v->attr |= CRT_ATTR_REVERSE;
762 v->attr &= ~CRT_ATTR_REVERSE;
772 v->color &= ~CRT_COLOR_FG_MASK;
773 v->color |= ((a - 30) << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
783 v->color &= ~CRT_COLOR_FG_MASK;
786 90) | CRT_COLOR_INTENSITY) << CRT_COLOR_FG_SHIFT) &
791 v->color &= ~CRT_COLOR_FG_MASK;
793 (CRT_FGCOLOR_NORMAL << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
803 v->color &= ~CRT_COLOR_BG_MASK;
804 v->color |= ((a - 40) << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
814 v->color &= ~CRT_COLOR_BG_MASK;
817 100) | CRT_COLOR_INTENSITY) << CRT_COLOR_BG_SHIFT) &
822 v->color &= ~CRT_COLOR_BG_MASK;
824 (CRT_BGCOLOR_NORMAL << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
830 fprintf (stderr, "unhandled SGR %d\n", a);
838 vt102_parse_attr_string (VT102 * v, char *buf, int len)
841 char last = buf[len - 1];
845 memset (num, 0, sizeof (num));
846 o = sizeof (num) - 1;
857 vt102_change_attr (v, &num[o]);
858 memset (num, 0, sizeof (num));
859 o = sizeof (num) - 1;
873 vt102_change_attr (v, &num[o]);
877 vt102_save_state (VT102 * v)
879 v->saved.pos = v->pos;
880 v->saved.attr = v->attr;
881 v->saved.color = v->color;
882 v->saved.origin_mode = v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE];
886 vt102_restore_state (VT102 * v)
888 v->pos = v->saved.pos;
889 v->attr = v->saved.attr;
890 v->color = v->saved.color;
891 v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE] = v->saved.origin_mode;
892 vt102_cursor_normalize (v);
897 vt102_regular_char (Context * c, VT102 * v, char ch)
900 vt102_do_pending_wrap (c);
902 if (v->modes[VT102_MODE_INSERT])
903 vt102_insert_into_line (v, v->pos);
905 v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = ch;
906 v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
907 v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color;
908 vt102_cursor_advance (c);
910 v->last_reg_char = ch;
914 vt102_scs (Context * c, int g, int s)
916 /*Ignoring charsets*/
920 vt102_parse_esc (Context * c, int ch)
926 if (v->pos.y == v->bottom_margin.y)
928 vt102_log_line (c, v->pos.y);
929 vt102_history (c, v->top_margin, v->bottom_margin);
930 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,
935 vt102_cursor_relative (v, 0, 1);
942 if (v->pos.y == v->top_margin.y)
944 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,
949 vt102_cursor_relative (v, 0, -1);
953 vt102_save_state (v);
956 vt102_restore_state (v);
959 v->application_keypad_mode = 1;
962 v->application_keypad_mode = 0;
965 v->parser.ignore_until_bell++;
968 log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__,
969 __LINE__, ch, safe_ch (ch));
975 vt102_parse_csi (Context * c, char *buf, int len)
1007 vt102_insert_into_line (v, v->pos);
1010 vt102_cursor_relative (v, 0, -narg);
1014 vt102_cursor_relative (v, 0, narg);
1018 vt102_cursor_relative (v, narg, 0);
1021 vt102_cursor_relative (v, -narg, 0);
1024 vt102_cursor_relative (v, 0, narg);
1025 vt102_cursor_carriage_return (v);
1028 vt102_cursor_relative (v, 0, -narg);
1029 vt102_cursor_carriage_return (v);
1032 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1041 ptr = index (arg, ';');
1043 x = atoi (ptr + 1) - 1;
1047 vt102_cursor_absolute (v, x, y);
1052 vt102_cursor_advance_tab (c->v);
1056 narg = 0; /*Different default */
1060 crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color);
1063 crt_erase (&v->crt, v->screen_start, v->pos, 1, v->color);
1066 crt_erase (&v->crt, v->screen_start, v->screen_end, 1,
1073 CRT_Pos ls = { 0, v->pos.y };
1074 CRT_Pos le = { VT102_COLS - 1, v->pos.y };
1076 narg = 0; /*Different default */
1081 crt_erase (&v->crt, v->pos, le, 1, v->color);
1084 crt_erase (&v->crt, ls, v->pos, 1, v->color);
1087 crt_erase (&v->crt, ls, le, 1, v->color);
1094 if ((v->pos.y >= v->top_margin.y)
1095 && (v->pos.y <= v->bottom_margin.y))
1098 crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1,
1104 if ((v->pos.y >= v->top_margin.y)
1105 && (v->pos.y <= v->bottom_margin.y))
1109 vt102_history (c, v->pos, v->bottom_margin);
1110 crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1,
1117 vt102_delete_from_line (v, v->pos);
1120 //FIXME: cursor position report - does anything use that?
1125 vt102_history (c, v->top_margin, v->bottom_margin);
1126 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,
1132 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,
1137 CRT_Pos end = v->pos;
1142 if (end.x > v->bottom_margin.x)
1143 end.x = v->bottom_margin.x;
1145 crt_erase (&v->crt, v->pos, end, 1, v->color);
1150 vt102_cursor_retard_tab (c->v);
1153 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1157 vt102_regular_char (c, v, v->last_reg_char);
1163 vt102_cursor_absolute (v, v->pos.x, narg - 1);
1167 narg = 0; /*Different default */
1172 v->tabs[v->pos.x] = 0;
1174 case 2: //FIXME: - LA120 says current line only WTF?
1176 memset (v->tabs, 0, sizeof (v->tabs));
1181 case 'i': //4,5 Turn printer on and off WTF?
1186 vt102_parse_mode_string (v, &buf[1], len - 1);
1191 vt102_parse_attr_string (v, &buf[1], len - 1);
1193 case 'n': // 6 request cursor position
1197 v->top_margin = v->screen_start;
1198 v->bottom_margin = v->screen_end;
1200 if ((len > 2) && (ptr = index (arg, ';')))
1203 v->top_margin.y = narg - 1;
1204 v->bottom_margin.y = atoi (ptr) - 1;
1207 if (v->top_margin.y < v->screen_start.y)
1208 v->top_margin.y = v->screen_start.y;
1209 if (v->top_margin.y > v->screen_end.y)
1210 v->top_margin.y = v->screen_end.y;
1211 if (v->bottom_margin.y < v->screen_start.y)
1212 v->bottom_margin.y = v->screen_start.y;
1213 if (v->bottom_margin.y > v->screen_end.y)
1214 v->bottom_margin.y = v->screen_end.y;
1216 vt102_cursor_home (v);
1219 v->saved.pos = v->pos;
1222 v->pos = v->saved.pos;
1223 vt102_cursor_normalize (v);
1224 v->pending_wrap = 0;
1228 log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__, __LINE__,
1235 log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__, __LINE__,
1245 vt102_status_line (VT102 * v, char *str)
1248 CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
1252 ca->attr = CRT_ATTR_REVERSE;
1253 ca->color = CRT_COLOR_NORMAL;
1264 vt102_parser_reset (VT102_parser * p)
1268 p->ignore_until_bell = 0;
1273 vt102_reset_state (VT102 * v)
1275 vt102_parser_reset (&v->parser);
1277 v->attr = CRT_ATTR_NORMAL;
1278 v->color = CRT_COLOR_NORMAL;
1280 v->application_keypad_mode = 0;
1282 v->top_margin = v->screen_start;
1283 v->bottom_margin = v->screen_end;
1285 memset (v->modes, 0, VT102_NMODES);
1286 memset (v->private_modes, 0, VT102_NMODES);
1288 v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP] = 1;
1289 v->private_modes[VT102_PRIVATE_MODE_AUTO_REPEAT] = 1;
1290 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] = 1;
1291 v->modes[VT102_MODE_LOCAL_ECHO_OFF] = 1;
1293 vt102_reset_tabs (v);
1298 vt102_parse_char (Context * c, int ch)
1301 VT102_parser *p = &v->parser;
1304 log_f (c->l, "char %3d %c pc %d %d %d %2d %2d %d", ch, safe_ch (ch),
1305 p->ignore_until_bell, p->in_escape, p->in_csi, v->pos.x, v->pos.y,
1309 /* Turn anything non-ascii into '?' */
1310 if ((ch != SYM_CHAR_RESET) && (ch != 0xb9) && (ch > 127))
1316 if (ch == SYM_CHAR_RESET)
1318 vt102_reset_state (v);
1320 if (p->ignore_until_bell)
1323 p->ignore_until_bell = 0;
1327 p->csi_buf[p->csi_ptr++] = ch;
1328 if (csi_ender (ch) || (p->csi_ptr == VT102_CSI_LEN))
1330 if (csi_starter (p->csi_buf[0]))
1332 vt102_parse_csi (c, p->csi_buf, p->csi_ptr);
1334 else if (scs_starter (p->csi_buf[0]))
1336 vt102_scs (c, p->csi_buf[0], p->csi_buf[1]);
1341 "<%s:%d no dispatcher for sequence starting \\033 \\%03o (ESC %c)>",
1342 __FILE__, __LINE__, p->csi_buf[0],
1343 safe_ch (p->csi_buf[0]));
1348 else if (p->in_escape)
1350 if (csi_starter (ch) || scs_starter (ch))
1353 p->csi_buf[p->csi_ptr++] = ch;
1360 vt102_parse_esc (c, ch);
1363 else if (ch == 0x9b) /*One byte CSI */
1366 p->csi_buf[p->csi_ptr++] = '[';
1382 c->t->xmit (c->t, "vt102", 5);
1388 vt102_cursor_retard (c->v);
1391 vt102_cursor_advance_tab (c->v);
1396 vt102_cursor_advance_line (c);
1397 if (!v->modes[VT102_MODE_NEWLINE_MODE])
1400 vt102_cursor_carriage_return (v);
1404 /*Ignoring charsets */
1408 /*Ignoring charsets */
1431 /*regular character */ default:
1432 vt102_regular_char (c, v, ch);
1436 v->crt.pos = v->pos;
1437 v->crt.hide_cursor =
1438 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0 : 1;
1440 if (v->current_line.y != v->pos.y)
1442 vt102_log_line (c, v->current_line.y);
1443 v->current_line = v->pos;
1447 cmd_show_status (c->d, c);
1451 vt102_send (Context * c, uint8_t key)
1459 fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' ');
1461 if ((key > 31) && (key < 127))
1463 c->t->xmit (c->t, &key, 1);
1482 c->t->xmit (c->t, &key, 1);
1485 c->t->xmit (c->t, &key, 1);
1486 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1489 c->t->xmit (c->t, &ch, 1);
1505 c->t->xmit (c->t, &key, 1);
1513 c->t->xmit (c->t, &key, 1);
1524 if (c->v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE])
1526 uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) };
1527 c->t->xmit (c->t, &buf, sizeof (buf));
1531 uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) };
1532 c->t->xmit (c->t, &buf, sizeof (buf));
1550 if (c->v->application_keypad_mode)
1552 uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) };
1553 c->t->xmit (c->t, &buf, sizeof (buf));
1557 static char kpoff[KEY_NUM] = {
1576 c->t->xmit (c->t, &kpoff[key], 1);
1580 if (c->v->application_keypad_mode)
1582 uint8_t buf[] = { 033, 'O', 'M' };
1583 c->t->xmit (c->t, &buf, sizeof (buf));
1588 c->t->xmit (c->t, &ch, 1);
1589 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1592 c->t->xmit (c->t, &ch, 1);
1601 uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) };
1602 c->t->xmit (c->t, &buf, sizeof (buf));
1610 uint8_t buf[] = { 033, '[', '0' + (key - KEY_180), '~' };
1611 c->t->xmit (c->t, &buf, sizeof (buf));
1619 vt102_reset (VT102 * v)
1621 VT102_parser *p = &v->parser;
1625 v->current_line = v->pos;
1626 v->pending_wrap = 0;
1628 v->screen_start.x = 0;
1629 v->screen_start.y = 0;
1630 v->screen_end.x = VT102_COLS - 1;
1631 v->screen_end.y = VT102_ROWS - 1;
1633 vt102_cursor_home (v);
1634 vt102_status_line (v, "");
1636 vt102_reset_tabs (v);
1637 v->current_line = v->pos;
1639 vt102_parser_reset (p);
1640 vt102_reset_state (v);
1642 vt102_save_state (v);
1644 v->last_reg_char = ' ';
1652 v = (VT102 *) malloc (sizeof (VT102));
1663 vt102_set_ansi (VT102 * v, int ansi)
1665 v->xn_glitch = ansi ? 0 : 1;
1669 vt102_free (VT102 * v)