4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.36 2008/02/24 12:22:42 james
14 * *** empty log message ***
16 * Revision 1.35 2008/02/24 00:42:53 james
17 * *** empty log message ***
19 * Revision 1.34 2008/02/23 11:48:37 james
20 * *** empty log message ***
22 * Revision 1.33 2008/02/22 23:39:27 james
23 * *** empty log message ***
25 * Revision 1.32 2008/02/22 19:12:05 james
26 * *** empty log message ***
28 * Revision 1.31 2008/02/22 17:07:00 james
29 * *** empty log message ***
31 * Revision 1.30 2008/02/22 14:51:54 james
32 * *** empty log message ***
34 * Revision 1.29 2008/02/15 03:32:07 james
35 * *** empty log message ***
37 * Revision 1.28 2008/02/14 10:34:30 james
38 * *** empty log message ***
40 * Revision 1.27 2008/02/14 02:46:45 james
41 * *** empty log message ***
43 * Revision 1.26 2008/02/14 01:55:57 james
44 * *** empty log message ***
46 * Revision 1.25 2008/02/13 16:57:29 james
47 * *** empty log message ***
49 * Revision 1.24 2008/02/13 09:12:21 james
50 * *** empty log message ***
52 * Revision 1.23 2008/02/07 13:26:35 james
53 * *** empty log message ***
55 * Revision 1.22 2008/02/07 13:22:51 james
56 * *** empty log message ***
58 * Revision 1.21 2008/02/07 12:21:16 james
59 * *** empty log message ***
61 * Revision 1.20 2008/02/07 12:16:04 james
62 * *** empty log message ***
64 * Revision 1.19 2008/02/07 11:27:02 james
65 * *** empty log message ***
67 * Revision 1.18 2008/02/07 01:59:25 james
68 * *** empty log message ***
70 * Revision 1.17 2008/02/07 01:58:28 james
71 * *** empty log message ***
73 * Revision 1.16 2008/02/07 01:57:46 james
74 * *** empty log message ***
76 * Revision 1.15 2008/02/07 00:43:27 james
77 * *** empty log message ***
79 * Revision 1.14 2008/02/07 00:40:23 james
80 * *** empty log message ***
82 * Revision 1.13 2008/02/07 00:39:59 james
83 * *** empty log message ***
85 * Revision 1.12 2008/02/07 00:39:13 james
86 * *** empty log message ***
88 * Revision 1.11 2008/02/06 20:26:58 james
89 * *** empty log message ***
91 * Revision 1.10 2008/02/06 17:53:28 james
92 * *** empty log message ***
94 * Revision 1.9 2008/02/06 15:53:22 james
95 * *** empty log message ***
97 * Revision 1.8 2008/02/06 11:49:47 james
98 * *** empty log message ***
100 * Revision 1.7 2008/02/06 11:30:37 james
101 * *** empty log message ***
103 * Revision 1.6 2008/02/05 01:11:46 james
104 * *** empty log message ***
106 * Revision 1.5 2008/02/04 20:23:55 james
107 * *** empty log message ***
109 * Revision 1.4 2008/02/04 05:45:55 james
112 * Revision 1.3 2008/02/04 02:05:06 james
113 * *** empty log message ***
115 * Revision 1.2 2008/02/04 01:32:39 james
116 * *** empty log message ***
118 * Revision 1.1 2008/02/03 23:36:41 james
119 * *** empty log message ***
130 :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100:
132 vt100|vt100-am|dec vt100 (w/advanced video):\
134 :co#80:it#8:li#24:vt#3:\
135 :DO=\E[%dB:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:\
137 :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\
138 :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
139 :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\
140 :eA=\E(B\E)0:ho=\E[H:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\
141 :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\
142 :me=\E[m\017:mr=\E[7m:nd=\E[C:rc=\E8:\
143 :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:sc=\E7:se=\E[m:\
144 :sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:up=\E[A:\
145 :us=\E[4m:tc=vt100+fnkeys:
147 vt100+fnkeys|dec vt100 numeric keypad:\
148 :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\
151 vt100+pfkeys|dec vt100 numeric keypad:\
152 :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad:
154 vt100+keypad|dec vt100 numeric keypad no fkeys:\
155 :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:
160 so the parser needs to be able to at least do
222 ansi|ansi/pc-term compatible with color:\
223 :u6=\E[%i%d;%dR:u7=\E[6n:u9=\E[c:tc=ecma+color:\
224 :tc=klone+sgr:tc=ansi-m:
225 ansi-m|ansi-mono|ANSI X3.64-1979 terminal with ANSI.SYS compatible attributes:\
227 :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\
228 :LE=\E[%dD:RI=\E[%dC:SF=\E[%dS:SR=\E[%dT:UP=\E[%dA:\
229 :cb=\E[1K:ch=\E[%i%dG:ct=\E[2g:cv=\E[%i%dd:ec=\E[%dX:ei=:\
230 :im=:kB=\E[Z:kI=\E[L:kb=^H:kd=\E[B:kl=\E[D:kr=\E[C:ku=\E[A:\
231 :nw=\r\E[S:pf=\E[4i:po=\E[5i:s0=\E(B:s1=\E)B:s2=\E*B:\
232 :s3=\E+B:ta=\E[I:tc=pcansi-m:
233 pcansi-m|pcansi-mono|ibm-pc terminal programs claiming to be ansi (mono mode):\
236 :al=\E[L:bl=^G:bt=\E[Z:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
237 :cm=\E[%i%d;%dH:cr=^M:ct=\E[2g:dc=\E[P:dl=\E[M:do=\E[B:\
238 :ho=\E[H:kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:\
239 :le=\E[D:nd=\E[C:sf=^J:st=\EH:ta=^I:up=\E[A:\
241 klone+sgr-dumb|attribute control for ansi.sys displays (no ESC [ 11 m):\
242 :as=\E[12m:mb=\E[5m:md=\E[1m:me=\E[0;10m:mk=\E[8m:\
243 :mr=\E[7m:se=\E[m:so=\E[7m:ue=\E[m:us=\E[4m:tc=klone+acs:
244 klone+acs|alternate character set for ansi.sys displays:\
245 :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:\
246 :ae=\E[10m:as=\E[11m:
247 ecma+color|color control for ECMA-48-compatible terminals:\
249 :AB=\E[4%dm:AF=\E[3%dm:op=\E[39;49m:
252 Ignoreing ones in the VT102 spec
282 //static char terminal_reply[]={033,0133,077,066,0143};
283 static char terminal_reply[]={'v','t','1','0','2'};
298 if ((c >= 'a') && (c <= 'z'))
300 if ((c >= 'A') && (c <= 'Z'))
334 in_margins (VT102 * v, CRT_Pos p)
336 if (v->pos.x < v->top_margin.x)
338 if (v->pos.y < v->top_margin.y)
341 if (v->pos.x > v->bottom_margin.x)
343 if (v->pos.y > v->bottom_margin.y)
350 vt102_log_line (Context * c, int line)
352 CRT_Pos e = { VT102_COLS - 1, line };
353 CRT_Pos p = { 0, line };
354 char logbuf[VT102_COLS + 1];
360 for (; e.x > 0; --e.x)
362 if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
366 for (; p.x <= e.x; ++p.x)
368 int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr;
377 c->l->log (c->l, logbuf);
380 /*Called for every upward scroll with same args*/
382 vt102_history (Context * c, CRT_Pos t, CRT_Pos b)
384 /*Only log if it scrolls off the top*/
389 history_add (c->h, &(c->v->crt.screen[CRT_ADDR_POS (&t)]));
393 vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br)
408 vt102_cursor_normalize (VT102 * v)
410 CRT_Pos *top, *bottom;
412 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
414 vt102_clip_cursor (v, v->top_margin, v->bottom_margin);
418 vt102_clip_cursor (v, v->screen_start, v->screen_end);
424 vt102_cursor_carriage_return (VT102 * v)
426 /*FISH*/ v->pos.x = v->top_margin.x;
431 vt102_cursor_advance_line (Context * c)
434 int couldscroll = in_margins (v, v->pos);
436 /*have wraped off end of last line in scrolling region */
437 /* (|| not necessary, but shuts compiler up */
438 if (((v->pos.y == v->bottom_margin.y) || (v->pos.y == v->screen_end.y)) &&
441 vt102_log_line (c, v->pos.y);
443 vt102_history (c, v->top_margin, v->bottom_margin);
445 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, v->color);
449 if (v->pos.y != v->screen_end.y)
456 vt102_cursor_retreat_line (Context * c)
459 int couldscroll = in_margins (v, v->pos);
461 /*have wraped off end of last line in scrolling region */
462 /* (|| not necessary, but shuts compiler up */
463 if (((v->pos.y == v->top_margin.y) || (v->pos.y == v->screen_start.y)) &&
466 vt102_log_line (c, v->pos.y);
468 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1, v->color);
472 if (v->pos.y != v->screen_start.y)
479 vt102_do_pending_wrap (Context * c)
482 int couldscroll = in_margins (v, v->pos);
483 int autowrap = v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP];
485 if (!v->pending_wrap)
489 fprintf (stderr, "ca: (%d,%d) autowrap %d couldscroll %d\n", v->pos.x,
490 v->pos.y, autowrap, couldscroll);
493 /*End of line but no autowrap, nothing to do*/
497 /*End of screen and not allowed to scroll, nothing to do*/
498 if ((v->pos.y == v->screen_end.y) && (!couldscroll))
503 v->pos.x = v->top_margin.x;
510 vt102_cursor_advance_line (c);
514 vt102_cursor_advance (Context * c)
518 if (v->pos.x < v->bottom_margin.x)
526 if (!c->v->xn_glitch)
527 vt102_do_pending_wrap (c);
533 vt102_cursor_retreat (VT102 * v)
535 if (v->pos.x != v->top_margin.x)
542 vt102_reset_tabs (VT102 * v)
546 memset (v->tabs, 0, sizeof (v->tabs));
548 for (i = 0; i < VT102_COLS; i += 8)
554 vt102_cursor_advance_tab (VT102 * v)
556 if (v->pos.x == v->bottom_margin.x)
558 while (v->pos.x < v->bottom_margin.x)
561 if (v->tabs[v->pos.x])
568 vt102_cursor_retreat_tab (VT102 * v)
570 if (v->pos.x == v->top_margin.x)
572 while (v->pos.x > v->top_margin.x)
575 if (v->tabs[v->pos.x])
581 vt102_cursor_home (VT102 * v)
583 v->pos = v->top_margin;
584 vt102_cursor_normalize (v);
589 vt102_cursor_absolute (VT102 * v, int x, int y)
591 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
593 v->pos.x = x + v->top_margin.x;
594 v->pos.y = y + v->top_margin.x;
601 vt102_cursor_normalize (v);
605 vt102_cursor_relative (VT102 * v, int x, int y)
609 vt102_cursor_normalize (v);
616 vt102_delete_from_line (VT102 * v, CRT_Pos p)
618 int n = v->bottom_margin.x - p.x;
626 memmove (&v->crt.screen[CRT_ADDR_POS (&p)],
627 &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n);
630 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
631 /*But not attr due to vt102 bug*/
635 vt102_insert_into_line (VT102 * v, CRT_Pos p)
637 int n = v->bottom_margin.x - p.x;
645 memmove (&v->crt.screen[CRT_ADDR_POS (&p) + 1],
646 &v->crt.screen[CRT_ADDR_POS (&p)], sizeof (CRT_CA) * n);
649 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
650 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].attr = CRT_ATTR_NORMAL;
651 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].color = CRT_COLOR_NORMAL;
657 vt102_change_mode (VT102 * v, int private, char *ns, int set)
673 if (m >= VT102_NMODES)
678 v->private_modes[m] = set;
681 case VT102_PRIVATE_MODE_CURSOR_MODE:
682 if (v->application_keypad_mode)
683 v->private_modes[m] = 0;
685 fprintf (stderr, "APPLICATION CURSOR MODE %d wanted %d\n",
686 v->private_modes[m], set);
689 case VT102_PRIVATE_MODE_ORIGIN_MODE:
690 vt102_cursor_home (v);
699 fprintf (stderr, "mode set=%d private=%d num=%d\n", set, private, m);
704 vt102_parse_mode_string (VT102 * v, char *buf, int len)
707 char last = buf[len - 1];
711 memset (num, 0, sizeof (num));
712 o = sizeof (num) - 1;
730 vt102_change_mode (v, private, &num[o], last == 'h');
731 memset (num, 0, sizeof (num));
732 o = sizeof (num) - 1;
747 vt102_change_mode (v, private, &num[o], last == 'h');
753 vt102_change_attr (VT102 * v, char *na)
770 v->attr = CRT_ATTR_NORMAL;
771 v->color = CRT_COLOR_NORMAL;
774 v->attr |= CRT_ATTR_BOLD;
778 v->attr &= ~CRT_ATTR_BOLD;
781 v->attr |= CRT_ATTR_UNDERLINE;
784 v->attr &= ~CRT_ATTR_UNDERLINE;
787 v->attr |= CRT_ATTR_BLINK;
790 v->attr &= ~CRT_ATTR_BLINK;
793 v->attr |= CRT_ATTR_REVERSE;
796 v->attr &= ~CRT_ATTR_REVERSE;
806 v->color &= ~CRT_COLOR_FG_MASK;
807 v->color |= ((a - 30) << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
817 v->color &= ~CRT_COLOR_FG_MASK;
820 90) | CRT_COLOR_INTENSITY) << CRT_COLOR_FG_SHIFT) &
825 v->color &= ~CRT_COLOR_FG_MASK;
827 (CRT_FGCOLOR_NORMAL << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
837 v->color &= ~CRT_COLOR_BG_MASK;
838 v->color |= ((a - 40) << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
848 v->color &= ~CRT_COLOR_BG_MASK;
851 100) | CRT_COLOR_INTENSITY) << CRT_COLOR_BG_SHIFT) &
856 v->color &= ~CRT_COLOR_BG_MASK;
858 (CRT_BGCOLOR_NORMAL << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
864 fprintf (stderr, "unhandled SGR %d\n", a);
872 vt102_parse_attr_string (VT102 * v, char *buf, int len)
875 char last = buf[len - 1];
879 memset (num, 0, sizeof (num));
880 o = sizeof (num) - 1;
891 vt102_change_attr (v, &num[o]);
892 memset (num, 0, sizeof (num));
893 o = sizeof (num) - 1;
907 vt102_change_attr (v, &num[o]);
911 vt102_save_state (VT102 * v)
913 v->saved.pos = v->pos;
914 v->saved.attr = v->attr;
915 v->saved.color = v->color;
916 v->saved.origin_mode = v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE];
920 vt102_restore_state (VT102 * v)
922 v->pos = v->saved.pos;
923 v->attr = v->saved.attr;
924 v->color = v->saved.color;
925 v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE] = v->saved.origin_mode;
926 vt102_cursor_normalize (v);
931 vt102_regular_char (Context * c, VT102 * v, int ch)
934 vt102_do_pending_wrap (c);
936 if (v->modes[VT102_MODE_INSERT])
937 vt102_insert_into_line (v, v->pos);
939 v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = ch;
940 v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
941 v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color;
942 vt102_cursor_advance (c);
944 v->last_reg_char = ch;
948 vt102_scs (Context * c, int g, int s)
950 /*Ignoring charsets*/
954 vt102_parse_esc (Context * c, int ch)
960 vt102_cursor_relative (v, 0, -1);
963 vt102_cursor_relative (v, 0, 1);
966 vt102_cursor_relative (v, 1, 0);
969 vt102_cursor_relative (v, -1, 0);
972 if (v->pos.y == v->bottom_margin.y)
974 vt102_log_line (c, v->pos.y);
975 vt102_history (c, v->top_margin, v->bottom_margin);
976 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,
981 vt102_cursor_relative (v, 0, 1);
988 vt102_cursor_retreat_line (c);
991 crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color);
995 CRT_Pos le = { VT102_COLS - 1, v->pos.y };
996 crt_erase (&v->crt, v->pos, le, 1, v->color);
1000 if (v->pos.y == v->top_margin.y)
1002 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,
1007 vt102_cursor_relative (v, 0, -1);
1012 v->parser.dca_ptr=0;
1016 c->t->xmit (c->t, terminal_reply,sizeof(terminal_reply));
1020 /*Set ansi mode - ignored*/
1024 vt102_save_state (v);
1027 vt102_restore_state (v);
1030 v->application_keypad_mode = 1;
1033 v->application_keypad_mode = 0;
1036 v->parser.ignore_until_bell++;
1039 log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__,
1040 __LINE__, ch, safe_ch (ch));
1046 vt102_parse_csi (Context * c, char *buf, int len)
1050 char *arg = buf + 1;
1057 last = buf[len - 1];
1078 vt102_insert_into_line (v, v->pos);
1081 vt102_cursor_relative (v, 0, -narg);
1085 vt102_cursor_relative (v, 0, narg);
1089 vt102_cursor_relative (v, narg, 0);
1092 vt102_cursor_relative (v, -narg, 0);
1095 vt102_cursor_relative (v, 0, narg);
1096 vt102_cursor_carriage_return (v);
1099 vt102_cursor_relative (v, 0, -narg);
1100 vt102_cursor_carriage_return (v);
1103 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1112 ptr = index (arg, ';');
1114 x = atoi (ptr + 1) - 1;
1118 vt102_cursor_absolute (v, x, y);
1123 vt102_cursor_advance_tab (c->v);
1127 narg = 0; /*Different default */
1131 crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color);
1134 crt_erase (&v->crt, v->screen_start, v->pos, 1, v->color);
1137 crt_erase (&v->crt, v->screen_start, v->screen_end, 1,
1144 CRT_Pos ls = { 0, v->pos.y };
1145 CRT_Pos le = { VT102_COLS - 1, v->pos.y };
1147 narg = 0; /*Different default */
1152 crt_erase (&v->crt, v->pos, le, 1, v->color);
1155 crt_erase (&v->crt, ls, v->pos, 1, v->color);
1158 crt_erase (&v->crt, ls, le, 1, v->color);
1165 if ((v->pos.y >= v->top_margin.y)
1166 && (v->pos.y <= v->bottom_margin.y))
1169 crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1,
1175 if ((v->pos.y >= v->top_margin.y)
1176 && (v->pos.y <= v->bottom_margin.y))
1180 vt102_history (c, v->pos, v->bottom_margin);
1181 crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1,
1188 vt102_delete_from_line (v, v->pos);
1191 //FIXME: cursor position report - does anything use that?
1196 vt102_history (c, v->top_margin, v->bottom_margin);
1197 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,
1203 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,
1208 CRT_Pos end = v->pos;
1213 if (end.x > v->bottom_margin.x)
1214 end.x = v->bottom_margin.x;
1216 crt_erase (&v->crt, v->pos, end, 1, v->color);
1221 vt102_cursor_retreat_tab (c->v);
1224 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1228 vt102_regular_char (c, v, v->last_reg_char);
1234 vt102_cursor_absolute (v, v->pos.x, narg - 1);
1238 narg = 0; /*Different default */
1243 v->tabs[v->pos.x] = 0;
1245 case 2: //FIXME: - LA120 says current line only WTF?
1247 memset (v->tabs, 0, sizeof (v->tabs));
1252 case 'i': //4,5 Turn printer on and off WTF?
1257 vt102_parse_mode_string (v, &buf[1], len - 1);
1262 vt102_parse_attr_string (v, &buf[1], len - 1);
1264 case 'n': // 6 request cursor position
1268 v->top_margin = v->screen_start;
1269 v->bottom_margin = v->screen_end;
1271 if ((len > 2) && (ptr = index (arg, ';')))
1274 v->top_margin.y = narg - 1;
1275 v->bottom_margin.y = atoi (ptr) - 1;
1278 if (v->top_margin.y < v->screen_start.y)
1279 v->top_margin.y = v->screen_start.y;
1280 if (v->top_margin.y > v->screen_end.y)
1281 v->top_margin.y = v->screen_end.y;
1282 if (v->bottom_margin.y < v->screen_start.y)
1283 v->bottom_margin.y = v->screen_start.y;
1284 if (v->bottom_margin.y > v->screen_end.y)
1285 v->bottom_margin.y = v->screen_end.y;
1287 vt102_cursor_home (v);
1290 v->saved.pos = v->pos;
1293 v->pos = v->saved.pos;
1294 vt102_cursor_normalize (v);
1295 v->pending_wrap = 0;
1299 log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__, __LINE__,
1306 log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__, __LINE__,
1316 vt102_status_line (VT102 * v, char *str)
1319 CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
1323 ca->attr = CRT_ATTR_REVERSE;
1324 ca->color = CRT_COLOR_NORMAL;
1335 vt102_parser_reset (VT102_parser * p)
1339 p->ignore_until_bell = 0;
1344 vt102_reset_state (VT102 * v)
1346 vt102_parser_reset (&v->parser);
1348 v->attr = CRT_ATTR_NORMAL;
1349 v->color = CRT_COLOR_NORMAL;
1351 v->application_keypad_mode = 0;
1353 v->top_margin = v->screen_start;
1354 v->bottom_margin = v->screen_end;
1356 memset (v->modes, 0, VT102_NMODES);
1357 memset (v->private_modes, 0, VT102_NMODES);
1359 v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP] = 1;
1360 v->private_modes[VT102_PRIVATE_MODE_AUTO_REPEAT] = 1;
1361 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] = 1;
1362 v->modes[VT102_MODE_LOCAL_ECHO_OFF] = 1;
1364 vt102_reset_tabs (v);
1369 vt102_parse_char (Context * c, int ch)
1372 VT102_parser *p = &v->parser;
1375 log_f (c->l, "char %3d %c pc %d %d %d %2d %2d %d", ch, safe_ch (ch),
1376 p->ignore_until_bell, p->in_escape, p->in_csi, v->pos.x, v->pos.y,
1380 /* Turn anything non-ascii into '?' */
1382 if ((ch != SYM_CHAR_RESET) && (ch != 0xb9) && (ch > 127))
1389 if (ch == SYM_CHAR_RESET)
1391 vt102_reset_state (v);
1392 } else if (p->in_dca) {
1393 p->dca_buf[p->dca_ptr++]=ch;
1394 if (p->dca_ptr==2) {
1395 vt102_cursor_absolute (v, p->dca_buf[0] - 040, p->dca_buf[1]-040);
1398 }else if (p->ignore_until_bell) {
1400 p->ignore_until_bell = 0;
1404 p->csi_buf[p->csi_ptr++] = ch;
1405 if (csi_ender (ch) || (p->csi_ptr == VT102_CSI_LEN))
1407 if (csi_starter (p->csi_buf[0]))
1409 vt102_parse_csi (c, p->csi_buf, p->csi_ptr);
1411 else if (scs_starter (p->csi_buf[0]))
1413 vt102_scs (c, p->csi_buf[0], p->csi_buf[1]);
1418 "<%s:%d no dispatcher for sequence starting \\033 \\%03o (ESC %c)>",
1419 __FILE__, __LINE__, p->csi_buf[0],
1420 safe_ch (p->csi_buf[0]));
1425 else if (p->in_escape)
1427 if (csi_starter (ch) || scs_starter (ch))
1430 p->csi_buf[p->csi_ptr++] = ch;
1437 vt102_parse_esc (c, ch);
1440 else if (ch == 0x9b) /*One byte CSI */
1443 p->csi_buf[p->csi_ptr++] = '[';
1459 c->t->xmit (c->t, "vt102", 5);
1466 vt102_cursor_retreat (c->v);
1469 vt102_cursor_advance_tab (c->v);
1474 vt102_cursor_advance_line (c);
1475 if (!v->modes[VT102_MODE_NEWLINE_MODE])
1478 vt102_cursor_carriage_return (v);
1482 /*Ignoring charsets */
1486 /*Ignoring charsets */
1509 /*regular character */ default:
1510 vt102_regular_char (c, v, ch);
1514 v->crt.pos = v->pos;
1515 v->crt.hide_cursor =
1516 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0 : 1;
1518 if (v->current_line.y != v->pos.y)
1520 vt102_log_line (c, v->current_line.y);
1521 v->current_line = v->pos;
1525 cmd_show_status (c->d, c);
1529 vt102_send (Context * c, uint8_t key)
1537 fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' ');
1539 if ((key > 31) && (key < 127))
1541 c->t->xmit (c->t, &key, 1);
1560 c->t->xmit (c->t, &key, 1);
1563 c->t->xmit (c->t, &key, 1);
1564 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1567 c->t->xmit (c->t, &ch, 1);
1583 c->t->xmit (c->t, &key, 1);
1591 c->t->xmit (c->t, &key, 1);
1602 if (c->v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE])
1604 uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) };
1605 c->t->xmit (c->t, &buf, sizeof (buf));
1609 uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) };
1610 c->t->xmit (c->t, &buf, sizeof (buf));
1628 if (c->v->application_keypad_mode)
1630 uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) };
1631 c->t->xmit (c->t, &buf, sizeof (buf));
1635 static char kpoff[KEY_NUM] = {
1654 c->t->xmit (c->t, &kpoff[key], 1);
1658 if (c->v->application_keypad_mode)
1660 uint8_t buf[] = { 033, 'O', 'M' };
1661 c->t->xmit (c->t, &buf, sizeof (buf));
1666 c->t->xmit (c->t, &ch, 1);
1667 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1670 c->t->xmit (c->t, &ch, 1);
1679 uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) };
1680 c->t->xmit (c->t, &buf, sizeof (buf));
1688 uint8_t buf[] = { 033, '[', '0' + (key - KEY_180), '~' };
1689 c->t->xmit (c->t, &buf, sizeof (buf));
1697 vt102_reset (VT102 * v)
1699 VT102_parser *p = &v->parser;
1703 v->current_line = v->pos;
1704 v->pending_wrap = 0;
1706 v->screen_start.x = 0;
1707 v->screen_start.y = 0;
1708 v->screen_end.x = VT102_COLS - 1;
1709 v->screen_end.y = VT102_ROWS - 1;
1711 vt102_cursor_home (v);
1712 vt102_status_line (v, "");
1714 vt102_reset_tabs (v);
1715 v->current_line = v->pos;
1717 vt102_parser_reset (p);
1718 vt102_reset_state (v);
1720 vt102_save_state (v);
1722 v->last_reg_char = ' ';
1730 v = (VT102 *) malloc (sizeof (VT102));
1741 vt102_set_ansi (VT102 * v, int ansi)
1743 v->xn_glitch = ansi ? 0 : 1;
1747 vt102_free (VT102 * v)