4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.37 2008/02/24 12:22:53 james
14 * *** empty log message ***
16 * Revision 1.36 2008/02/24 12:22:42 james
17 * *** empty log message ***
19 * Revision 1.35 2008/02/24 00:42:53 james
20 * *** empty log message ***
22 * Revision 1.34 2008/02/23 11:48:37 james
23 * *** empty log message ***
25 * Revision 1.33 2008/02/22 23:39:27 james
26 * *** empty log message ***
28 * Revision 1.32 2008/02/22 19:12:05 james
29 * *** empty log message ***
31 * Revision 1.31 2008/02/22 17:07:00 james
32 * *** empty log message ***
34 * Revision 1.30 2008/02/22 14:51:54 james
35 * *** empty log message ***
37 * Revision 1.29 2008/02/15 03:32:07 james
38 * *** empty log message ***
40 * Revision 1.28 2008/02/14 10:34:30 james
41 * *** empty log message ***
43 * Revision 1.27 2008/02/14 02:46:45 james
44 * *** empty log message ***
46 * Revision 1.26 2008/02/14 01:55:57 james
47 * *** empty log message ***
49 * Revision 1.25 2008/02/13 16:57:29 james
50 * *** empty log message ***
52 * Revision 1.24 2008/02/13 09:12:21 james
53 * *** empty log message ***
55 * Revision 1.23 2008/02/07 13:26:35 james
56 * *** empty log message ***
58 * Revision 1.22 2008/02/07 13:22:51 james
59 * *** empty log message ***
61 * Revision 1.21 2008/02/07 12:21:16 james
62 * *** empty log message ***
64 * Revision 1.20 2008/02/07 12:16:04 james
65 * *** empty log message ***
67 * Revision 1.19 2008/02/07 11:27:02 james
68 * *** empty log message ***
70 * Revision 1.18 2008/02/07 01:59:25 james
71 * *** empty log message ***
73 * Revision 1.17 2008/02/07 01:58:28 james
74 * *** empty log message ***
76 * Revision 1.16 2008/02/07 01:57:46 james
77 * *** empty log message ***
79 * Revision 1.15 2008/02/07 00:43:27 james
80 * *** empty log message ***
82 * Revision 1.14 2008/02/07 00:40:23 james
83 * *** empty log message ***
85 * Revision 1.13 2008/02/07 00:39:59 james
86 * *** empty log message ***
88 * Revision 1.12 2008/02/07 00:39:13 james
89 * *** empty log message ***
91 * Revision 1.11 2008/02/06 20:26:58 james
92 * *** empty log message ***
94 * Revision 1.10 2008/02/06 17:53:28 james
95 * *** empty log message ***
97 * Revision 1.9 2008/02/06 15:53:22 james
98 * *** empty log message ***
100 * Revision 1.8 2008/02/06 11:49:47 james
101 * *** empty log message ***
103 * Revision 1.7 2008/02/06 11:30:37 james
104 * *** empty log message ***
106 * Revision 1.6 2008/02/05 01:11:46 james
107 * *** empty log message ***
109 * Revision 1.5 2008/02/04 20:23:55 james
110 * *** empty log message ***
112 * Revision 1.4 2008/02/04 05:45:55 james
115 * Revision 1.3 2008/02/04 02:05:06 james
116 * *** empty log message ***
118 * Revision 1.2 2008/02/04 01:32:39 james
119 * *** empty log message ***
121 * Revision 1.1 2008/02/03 23:36:41 james
122 * *** empty log message ***
133 :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100:
135 vt100|vt100-am|dec vt100 (w/advanced video):\
137 :co#80:it#8:li#24:vt#3:\
138 :DO=\E[%dB:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:\
140 :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\
141 :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
142 :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\
143 :eA=\E(B\E)0:ho=\E[H:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\
144 :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\
145 :me=\E[m\017:mr=\E[7m:nd=\E[C:rc=\E8:\
146 :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:sc=\E7:se=\E[m:\
147 :sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:up=\E[A:\
148 :us=\E[4m:tc=vt100+fnkeys:
150 vt100+fnkeys|dec vt100 numeric keypad:\
151 :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\
154 vt100+pfkeys|dec vt100 numeric keypad:\
155 :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad:
157 vt100+keypad|dec vt100 numeric keypad no fkeys:\
158 :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:
163 so the parser needs to be able to at least do
225 ansi|ansi/pc-term compatible with color:\
226 :u6=\E[%i%d;%dR:u7=\E[6n:u9=\E[c:tc=ecma+color:\
227 :tc=klone+sgr:tc=ansi-m:
228 ansi-m|ansi-mono|ANSI X3.64-1979 terminal with ANSI.SYS compatible attributes:\
230 :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\
231 :LE=\E[%dD:RI=\E[%dC:SF=\E[%dS:SR=\E[%dT:UP=\E[%dA:\
232 :cb=\E[1K:ch=\E[%i%dG:ct=\E[2g:cv=\E[%i%dd:ec=\E[%dX:ei=:\
233 :im=:kB=\E[Z:kI=\E[L:kb=^H:kd=\E[B:kl=\E[D:kr=\E[C:ku=\E[A:\
234 :nw=\r\E[S:pf=\E[4i:po=\E[5i:s0=\E(B:s1=\E)B:s2=\E*B:\
235 :s3=\E+B:ta=\E[I:tc=pcansi-m:
236 pcansi-m|pcansi-mono|ibm-pc terminal programs claiming to be ansi (mono mode):\
239 :al=\E[L:bl=^G:bt=\E[Z:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
240 :cm=\E[%i%d;%dH:cr=^M:ct=\E[2g:dc=\E[P:dl=\E[M:do=\E[B:\
241 :ho=\E[H:kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:\
242 :le=\E[D:nd=\E[C:sf=^J:st=\EH:ta=^I:up=\E[A:\
244 klone+sgr-dumb|attribute control for ansi.sys displays (no ESC [ 11 m):\
245 :as=\E[12m:mb=\E[5m:md=\E[1m:me=\E[0;10m:mk=\E[8m:\
246 :mr=\E[7m:se=\E[m:so=\E[7m:ue=\E[m:us=\E[4m:tc=klone+acs:
247 klone+acs|alternate character set for ansi.sys displays:\
248 :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:\
249 :ae=\E[10m:as=\E[11m:
250 ecma+color|color control for ECMA-48-compatible terminals:\
252 :AB=\E[4%dm:AF=\E[3%dm:op=\E[39;49m:
255 Ignoreing ones in the VT102 spec
285 //static char terminal_reply[]={033,0133,077,066,0143};
286 static char terminal_reply[] = { 'v', 't', '1', '0', '2' };
301 if ((c >= 'a') && (c <= 'z'))
303 if ((c >= 'A') && (c <= 'Z'))
337 in_margins (VT102 * v, CRT_Pos p)
339 if (v->pos.x < v->top_margin.x)
341 if (v->pos.y < v->top_margin.y)
344 if (v->pos.x > v->bottom_margin.x)
346 if (v->pos.y > v->bottom_margin.y)
353 vt102_log_line (Context * c, int line)
355 CRT_Pos e = { VT102_COLS - 1, line };
356 CRT_Pos p = { 0, line };
357 char logbuf[VT102_COLS + 1];
363 for (; e.x > 0; --e.x)
365 if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
369 for (; p.x <= e.x; ++p.x)
371 int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr;
380 c->l->log (c->l, logbuf);
383 /*Called for every upward scroll with same args*/
385 vt102_history (Context * c, CRT_Pos t, CRT_Pos b)
387 /*Only log if it scrolls off the top*/
392 history_add (c->h, &(c->v->crt.screen[CRT_ADDR_POS (&t)]));
396 vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br)
411 vt102_cursor_normalize (VT102 * v)
413 CRT_Pos *top, *bottom;
415 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
417 vt102_clip_cursor (v, v->top_margin, v->bottom_margin);
421 vt102_clip_cursor (v, v->screen_start, v->screen_end);
427 vt102_cursor_carriage_return (VT102 * v)
429 /*FISH*/ v->pos.x = v->top_margin.x;
434 vt102_cursor_advance_line (Context * c)
437 int couldscroll = in_margins (v, v->pos);
439 /*have wraped off end of last line in scrolling region */
440 /* (|| not necessary, but shuts compiler up */
441 if (((v->pos.y == v->bottom_margin.y) || (v->pos.y == v->screen_end.y)) &&
444 vt102_log_line (c, v->pos.y);
446 vt102_history (c, v->top_margin, v->bottom_margin);
448 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, v->color);
452 if (v->pos.y != v->screen_end.y)
459 vt102_cursor_retreat_line (Context * c)
462 int couldscroll = in_margins (v, v->pos);
464 /*have wraped off end of last line in scrolling region */
465 /* (|| not necessary, but shuts compiler up */
466 if (((v->pos.y == v->top_margin.y) || (v->pos.y == v->screen_start.y)) &&
469 vt102_log_line (c, v->pos.y);
471 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1, v->color);
475 if (v->pos.y != v->screen_start.y)
482 vt102_do_pending_wrap (Context * c)
485 int couldscroll = in_margins (v, v->pos);
486 int autowrap = v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP];
488 if (!v->pending_wrap)
492 fprintf (stderr, "ca: (%d,%d) autowrap %d couldscroll %d\n", v->pos.x,
493 v->pos.y, autowrap, couldscroll);
496 /*End of line but no autowrap, nothing to do*/
500 /*End of screen and not allowed to scroll, nothing to do*/
501 if ((v->pos.y == v->screen_end.y) && (!couldscroll))
506 v->pos.x = v->top_margin.x;
513 vt102_cursor_advance_line (c);
517 vt102_cursor_advance (Context * c)
521 if (v->pos.x < v->bottom_margin.x)
529 if (!c->v->xn_glitch)
530 vt102_do_pending_wrap (c);
536 vt102_cursor_retreat (VT102 * v)
538 if (v->pos.x != v->top_margin.x)
545 vt102_reset_tabs (VT102 * v)
549 memset (v->tabs, 0, sizeof (v->tabs));
551 for (i = 0; i < VT102_COLS; i += 8)
557 vt102_cursor_advance_tab (VT102 * v)
559 if (v->pos.x == v->bottom_margin.x)
561 while (v->pos.x < v->bottom_margin.x)
564 if (v->tabs[v->pos.x])
571 vt102_cursor_retreat_tab (VT102 * v)
573 if (v->pos.x == v->top_margin.x)
575 while (v->pos.x > v->top_margin.x)
578 if (v->tabs[v->pos.x])
584 vt102_cursor_home (VT102 * v)
586 v->pos = v->top_margin;
587 vt102_cursor_normalize (v);
592 vt102_cursor_absolute (VT102 * v, int x, int y)
594 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
596 v->pos.x = x + v->top_margin.x;
597 v->pos.y = y + v->top_margin.x;
604 vt102_cursor_normalize (v);
608 vt102_cursor_relative (VT102 * v, int x, int y)
612 vt102_cursor_normalize (v);
619 vt102_delete_from_line (VT102 * v, CRT_Pos p)
621 int n = v->bottom_margin.x - p.x;
629 memmove (&v->crt.screen[CRT_ADDR_POS (&p)],
630 &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n);
633 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
634 /*But not attr due to vt102 bug*/
638 vt102_insert_into_line (VT102 * v, CRT_Pos p)
640 int n = v->bottom_margin.x - p.x;
648 memmove (&v->crt.screen[CRT_ADDR_POS (&p) + 1],
649 &v->crt.screen[CRT_ADDR_POS (&p)], sizeof (CRT_CA) * n);
652 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
653 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].attr = CRT_ATTR_NORMAL;
654 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].color = CRT_COLOR_NORMAL;
660 vt102_change_mode (VT102 * v, int private, char *ns, int set)
676 if (m >= VT102_NMODES)
681 v->private_modes[m] = set;
684 case VT102_PRIVATE_MODE_CURSOR_MODE:
685 if (v->application_keypad_mode)
686 v->private_modes[m] = 0;
688 fprintf (stderr, "APPLICATION CURSOR MODE %d wanted %d\n",
689 v->private_modes[m], set);
692 case VT102_PRIVATE_MODE_ORIGIN_MODE:
693 vt102_cursor_home (v);
702 fprintf (stderr, "mode set=%d private=%d num=%d\n", set, private, m);
707 vt102_parse_mode_string (VT102 * v, char *buf, int len)
710 char last = buf[len - 1];
714 memset (num, 0, sizeof (num));
715 o = sizeof (num) - 1;
733 vt102_change_mode (v, private, &num[o], last == 'h');
734 memset (num, 0, sizeof (num));
735 o = sizeof (num) - 1;
750 vt102_change_mode (v, private, &num[o], last == 'h');
756 vt102_change_attr (VT102 * v, char *na)
773 v->attr = CRT_ATTR_NORMAL;
774 v->color = CRT_COLOR_NORMAL;
777 v->attr |= CRT_ATTR_BOLD;
781 v->attr &= ~CRT_ATTR_BOLD;
784 v->attr |= CRT_ATTR_UNDERLINE;
787 v->attr &= ~CRT_ATTR_UNDERLINE;
790 v->attr |= CRT_ATTR_BLINK;
793 v->attr &= ~CRT_ATTR_BLINK;
796 v->attr |= CRT_ATTR_REVERSE;
799 v->attr &= ~CRT_ATTR_REVERSE;
809 v->color &= ~CRT_COLOR_FG_MASK;
810 v->color |= ((a - 30) << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
820 v->color &= ~CRT_COLOR_FG_MASK;
823 90) | CRT_COLOR_INTENSITY) << CRT_COLOR_FG_SHIFT) &
828 v->color &= ~CRT_COLOR_FG_MASK;
830 (CRT_FGCOLOR_NORMAL << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
840 v->color &= ~CRT_COLOR_BG_MASK;
841 v->color |= ((a - 40) << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
851 v->color &= ~CRT_COLOR_BG_MASK;
854 100) | CRT_COLOR_INTENSITY) << CRT_COLOR_BG_SHIFT) &
859 v->color &= ~CRT_COLOR_BG_MASK;
861 (CRT_BGCOLOR_NORMAL << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
867 fprintf (stderr, "unhandled SGR %d\n", a);
875 vt102_parse_attr_string (VT102 * v, char *buf, int len)
878 char last = buf[len - 1];
882 memset (num, 0, sizeof (num));
883 o = sizeof (num) - 1;
894 vt102_change_attr (v, &num[o]);
895 memset (num, 0, sizeof (num));
896 o = sizeof (num) - 1;
910 vt102_change_attr (v, &num[o]);
914 vt102_save_state (VT102 * v)
916 v->saved.pos = v->pos;
917 v->saved.attr = v->attr;
918 v->saved.color = v->color;
919 v->saved.origin_mode = v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE];
923 vt102_restore_state (VT102 * v)
925 v->pos = v->saved.pos;
926 v->attr = v->saved.attr;
927 v->color = v->saved.color;
928 v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE] = v->saved.origin_mode;
929 vt102_cursor_normalize (v);
934 vt102_regular_char (Context * c, VT102 * v, int ch)
937 vt102_do_pending_wrap (c);
939 if (v->modes[VT102_MODE_INSERT])
940 vt102_insert_into_line (v, v->pos);
942 v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = ch;
943 v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
944 v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color;
945 vt102_cursor_advance (c);
947 v->last_reg_char = ch;
951 vt102_scs (Context * c, int g, int s)
953 /*Ignoring charsets*/
957 vt102_parse_esc (Context * c, int ch)
963 vt102_cursor_relative (v, 0, -1);
966 vt102_cursor_relative (v, 0, 1);
969 vt102_cursor_relative (v, 1, 0);
972 vt102_cursor_relative (v, -1, 0);
975 if (v->pos.y == v->bottom_margin.y)
977 vt102_log_line (c, v->pos.y);
978 vt102_history (c, v->top_margin, v->bottom_margin);
979 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,
984 vt102_cursor_relative (v, 0, 1);
991 vt102_cursor_retreat_line (c);
994 crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color);
998 CRT_Pos le = { VT102_COLS - 1, v->pos.y };
999 crt_erase (&v->crt, v->pos, le, 1, v->color);
1003 if (v->pos.y == v->top_margin.y)
1005 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,
1010 vt102_cursor_relative (v, 0, -1);
1015 v->parser.dca_ptr = 0;
1020 c->t->xmit (c->t, terminal_reply, sizeof (terminal_reply));
1024 /*Set ansi mode - ignored */
1028 vt102_save_state (v);
1031 vt102_restore_state (v);
1034 v->application_keypad_mode = 1;
1037 v->application_keypad_mode = 0;
1040 v->parser.ignore_until_bell++;
1043 log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__,
1044 __LINE__, ch, safe_ch (ch));
1050 vt102_parse_csi (Context * c, char *buf, int len)
1054 char *arg = buf + 1;
1061 last = buf[len - 1];
1082 vt102_insert_into_line (v, v->pos);
1085 vt102_cursor_relative (v, 0, -narg);
1089 vt102_cursor_relative (v, 0, narg);
1093 vt102_cursor_relative (v, narg, 0);
1096 vt102_cursor_relative (v, -narg, 0);
1099 vt102_cursor_relative (v, 0, narg);
1100 vt102_cursor_carriage_return (v);
1103 vt102_cursor_relative (v, 0, -narg);
1104 vt102_cursor_carriage_return (v);
1107 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1116 ptr = index (arg, ';');
1118 x = atoi (ptr + 1) - 1;
1122 vt102_cursor_absolute (v, x, y);
1127 vt102_cursor_advance_tab (c->v);
1131 narg = 0; /*Different default */
1135 crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color);
1138 crt_erase (&v->crt, v->screen_start, v->pos, 1, v->color);
1141 crt_erase (&v->crt, v->screen_start, v->screen_end, 1,
1148 CRT_Pos ls = { 0, v->pos.y };
1149 CRT_Pos le = { VT102_COLS - 1, v->pos.y };
1151 narg = 0; /*Different default */
1156 crt_erase (&v->crt, v->pos, le, 1, v->color);
1159 crt_erase (&v->crt, ls, v->pos, 1, v->color);
1162 crt_erase (&v->crt, ls, le, 1, v->color);
1169 if ((v->pos.y >= v->top_margin.y)
1170 && (v->pos.y <= v->bottom_margin.y))
1173 crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1,
1179 if ((v->pos.y >= v->top_margin.y)
1180 && (v->pos.y <= v->bottom_margin.y))
1184 vt102_history (c, v->pos, v->bottom_margin);
1185 crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1,
1192 vt102_delete_from_line (v, v->pos);
1195 //FIXME: cursor position report - does anything use that?
1200 vt102_history (c, v->top_margin, v->bottom_margin);
1201 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,
1207 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,
1212 CRT_Pos end = v->pos;
1217 if (end.x > v->bottom_margin.x)
1218 end.x = v->bottom_margin.x;
1220 crt_erase (&v->crt, v->pos, end, 1, v->color);
1225 vt102_cursor_retreat_tab (c->v);
1228 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1232 vt102_regular_char (c, v, v->last_reg_char);
1238 vt102_cursor_absolute (v, v->pos.x, narg - 1);
1242 narg = 0; /*Different default */
1247 v->tabs[v->pos.x] = 0;
1249 case 2: //FIXME: - LA120 says current line only WTF?
1251 memset (v->tabs, 0, sizeof (v->tabs));
1256 case 'i': //4,5 Turn printer on and off WTF?
1261 vt102_parse_mode_string (v, &buf[1], len - 1);
1266 vt102_parse_attr_string (v, &buf[1], len - 1);
1268 case 'n': // 6 request cursor position
1272 v->top_margin = v->screen_start;
1273 v->bottom_margin = v->screen_end;
1275 if ((len > 2) && (ptr = index (arg, ';')))
1278 v->top_margin.y = narg - 1;
1279 v->bottom_margin.y = atoi (ptr) - 1;
1282 if (v->top_margin.y < v->screen_start.y)
1283 v->top_margin.y = v->screen_start.y;
1284 if (v->top_margin.y > v->screen_end.y)
1285 v->top_margin.y = v->screen_end.y;
1286 if (v->bottom_margin.y < v->screen_start.y)
1287 v->bottom_margin.y = v->screen_start.y;
1288 if (v->bottom_margin.y > v->screen_end.y)
1289 v->bottom_margin.y = v->screen_end.y;
1291 vt102_cursor_home (v);
1294 v->saved.pos = v->pos;
1297 v->pos = v->saved.pos;
1298 vt102_cursor_normalize (v);
1299 v->pending_wrap = 0;
1303 log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__, __LINE__,
1310 log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__, __LINE__,
1320 vt102_status_line (VT102 * v, char *str)
1323 CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
1327 ca->attr = CRT_ATTR_REVERSE;
1328 ca->color = CRT_COLOR_NORMAL;
1339 vt102_parser_reset (VT102_parser * p)
1343 p->ignore_until_bell = 0;
1348 vt102_reset_state (VT102 * v)
1350 vt102_parser_reset (&v->parser);
1352 v->attr = CRT_ATTR_NORMAL;
1353 v->color = CRT_COLOR_NORMAL;
1355 v->application_keypad_mode = 0;
1357 v->top_margin = v->screen_start;
1358 v->bottom_margin = v->screen_end;
1360 memset (v->modes, 0, VT102_NMODES);
1361 memset (v->private_modes, 0, VT102_NMODES);
1363 v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP] = 1;
1364 v->private_modes[VT102_PRIVATE_MODE_AUTO_REPEAT] = 1;
1365 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] = 1;
1366 v->modes[VT102_MODE_LOCAL_ECHO_OFF] = 1;
1368 vt102_reset_tabs (v);
1373 vt102_parse_char (Context * c, int ch)
1376 VT102_parser *p = &v->parser;
1379 log_f (c->l, "char %3d %c pc %d %d %d %2d %2d %d", ch, safe_ch (ch),
1380 p->ignore_until_bell, p->in_escape, p->in_csi, v->pos.x, v->pos.y,
1384 /* Turn anything non-ascii into '?' */
1386 if ((ch != SYM_CHAR_RESET) && (ch != 0xb9) && (ch > 127))
1393 if (ch == SYM_CHAR_RESET)
1395 vt102_reset_state (v);
1399 p->dca_buf[p->dca_ptr++] = ch;
1400 if (p->dca_ptr == 2)
1402 vt102_cursor_absolute (v, p->dca_buf[0] - 040, p->dca_buf[1] - 040);
1406 else if (p->ignore_until_bell)
1409 p->ignore_until_bell = 0;
1413 p->csi_buf[p->csi_ptr++] = ch;
1414 if (csi_ender (ch) || (p->csi_ptr == VT102_CSI_LEN))
1416 if (csi_starter (p->csi_buf[0]))
1418 vt102_parse_csi (c, p->csi_buf, p->csi_ptr);
1420 else if (scs_starter (p->csi_buf[0]))
1422 vt102_scs (c, p->csi_buf[0], p->csi_buf[1]);
1427 "<%s:%d no dispatcher for sequence starting \\033 \\%03o (ESC %c)>",
1428 __FILE__, __LINE__, p->csi_buf[0],
1429 safe_ch (p->csi_buf[0]));
1434 else if (p->in_escape)
1436 if (csi_starter (ch) || scs_starter (ch))
1439 p->csi_buf[p->csi_ptr++] = ch;
1446 vt102_parse_esc (c, ch);
1449 else if (ch == 0x9b) /*One byte CSI */
1452 p->csi_buf[p->csi_ptr++] = '[';
1469 c->t->xmit (c->t, "vt102", 5);
1476 vt102_cursor_retreat (c->v);
1479 vt102_cursor_advance_tab (c->v);
1484 vt102_cursor_advance_line (c);
1485 if (!v->modes[VT102_MODE_NEWLINE_MODE])
1488 vt102_cursor_carriage_return (v);
1492 /*Ignoring charsets */
1496 /*Ignoring charsets */
1519 /*regular character */ default:
1520 vt102_regular_char (c, v, ch);
1524 v->crt.pos = v->pos;
1525 v->crt.hide_cursor =
1526 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0 : 1;
1528 if (v->current_line.y != v->pos.y)
1530 vt102_log_line (c, v->current_line.y);
1531 v->current_line = v->pos;
1535 cmd_show_status (c->d, c);
1539 vt102_send (Context * c, uint8_t key)
1547 fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' ');
1549 if ((key > 31) && (key < 127))
1551 c->t->xmit (c->t, &key, 1);
1570 c->t->xmit (c->t, &key, 1);
1573 c->t->xmit (c->t, &key, 1);
1574 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1577 c->t->xmit (c->t, &ch, 1);
1593 c->t->xmit (c->t, &key, 1);
1601 c->t->xmit (c->t, &key, 1);
1612 if (c->v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE])
1614 uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) };
1615 c->t->xmit (c->t, &buf, sizeof (buf));
1619 uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) };
1620 c->t->xmit (c->t, &buf, sizeof (buf));
1638 if (c->v->application_keypad_mode)
1640 uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) };
1641 c->t->xmit (c->t, &buf, sizeof (buf));
1645 static char kpoff[KEY_NUM] = {
1664 c->t->xmit (c->t, &kpoff[key], 1);
1668 if (c->v->application_keypad_mode)
1670 uint8_t buf[] = { 033, 'O', 'M' };
1671 c->t->xmit (c->t, &buf, sizeof (buf));
1676 c->t->xmit (c->t, &ch, 1);
1677 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1680 c->t->xmit (c->t, &ch, 1);
1689 uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) };
1690 c->t->xmit (c->t, &buf, sizeof (buf));
1698 uint8_t buf[] = { 033, '[', '0' + (key - KEY_180), '~' };
1699 c->t->xmit (c->t, &buf, sizeof (buf));
1707 vt102_reset (VT102 * v)
1709 VT102_parser *p = &v->parser;
1713 v->current_line = v->pos;
1714 v->pending_wrap = 0;
1716 v->screen_start.x = 0;
1717 v->screen_start.y = 0;
1718 v->screen_end.x = VT102_COLS - 1;
1719 v->screen_end.y = VT102_ROWS - 1;
1721 vt102_cursor_home (v);
1722 vt102_status_line (v, "");
1724 vt102_reset_tabs (v);
1725 v->current_line = v->pos;
1727 vt102_parser_reset (p);
1728 vt102_reset_state (v);
1730 vt102_save_state (v);
1732 v->last_reg_char = ' ';
1740 v = (VT102 *) malloc (sizeof (VT102));
1751 vt102_set_ansi (VT102 * v, int ansi)
1753 v->xn_glitch = ansi ? 0 : 1;
1757 vt102_free (VT102 * v)