4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.32 2008/02/22 19:12:05 james
14 * *** empty log message ***
16 * Revision 1.31 2008/02/22 17:07:00 james
17 * *** empty log message ***
19 * Revision 1.30 2008/02/22 14:51:54 james
20 * *** empty log message ***
22 * Revision 1.29 2008/02/15 03:32:07 james
23 * *** empty log message ***
25 * Revision 1.28 2008/02/14 10:34:30 james
26 * *** empty log message ***
28 * Revision 1.27 2008/02/14 02:46:45 james
29 * *** empty log message ***
31 * Revision 1.26 2008/02/14 01:55:57 james
32 * *** empty log message ***
34 * Revision 1.25 2008/02/13 16:57:29 james
35 * *** empty log message ***
37 * Revision 1.24 2008/02/13 09:12:21 james
38 * *** empty log message ***
40 * Revision 1.23 2008/02/07 13:26:35 james
41 * *** empty log message ***
43 * Revision 1.22 2008/02/07 13:22:51 james
44 * *** empty log message ***
46 * Revision 1.21 2008/02/07 12:21:16 james
47 * *** empty log message ***
49 * Revision 1.20 2008/02/07 12:16:04 james
50 * *** empty log message ***
52 * Revision 1.19 2008/02/07 11:27:02 james
53 * *** empty log message ***
55 * Revision 1.18 2008/02/07 01:59:25 james
56 * *** empty log message ***
58 * Revision 1.17 2008/02/07 01:58:28 james
59 * *** empty log message ***
61 * Revision 1.16 2008/02/07 01:57:46 james
62 * *** empty log message ***
64 * Revision 1.15 2008/02/07 00:43:27 james
65 * *** empty log message ***
67 * Revision 1.14 2008/02/07 00:40:23 james
68 * *** empty log message ***
70 * Revision 1.13 2008/02/07 00:39:59 james
71 * *** empty log message ***
73 * Revision 1.12 2008/02/07 00:39:13 james
74 * *** empty log message ***
76 * Revision 1.11 2008/02/06 20:26:58 james
77 * *** empty log message ***
79 * Revision 1.10 2008/02/06 17:53:28 james
80 * *** empty log message ***
82 * Revision 1.9 2008/02/06 15:53:22 james
83 * *** empty log message ***
85 * Revision 1.8 2008/02/06 11:49:47 james
86 * *** empty log message ***
88 * Revision 1.7 2008/02/06 11:30:37 james
89 * *** empty log message ***
91 * Revision 1.6 2008/02/05 01:11:46 james
92 * *** empty log message ***
94 * Revision 1.5 2008/02/04 20:23:55 james
95 * *** empty log message ***
97 * Revision 1.4 2008/02/04 05:45:55 james
100 * Revision 1.3 2008/02/04 02:05:06 james
101 * *** empty log message ***
103 * Revision 1.2 2008/02/04 01:32:39 james
104 * *** empty log message ***
106 * Revision 1.1 2008/02/03 23:36:41 james
107 * *** empty log message ***
118 :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100:
120 vt100|vt100-am|dec vt100 (w/advanced video):\
122 :co#80:it#8:li#24:vt#3:\
123 :DO=\E[%dB:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:\
125 :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\
126 :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
127 :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\
128 :eA=\E(B\E)0:ho=\E[H:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\
129 :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\
130 :me=\E[m\017:mr=\E[7m:nd=\E[C:rc=\E8:\
131 :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:sc=\E7:se=\E[m:\
132 :sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:up=\E[A:\
133 :us=\E[4m:tc=vt100+fnkeys:
135 vt100+fnkeys|dec vt100 numeric keypad:\
136 :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\
139 vt100+pfkeys|dec vt100 numeric keypad:\
140 :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad:
142 vt100+keypad|dec vt100 numeric keypad no fkeys:\
143 :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:
148 so the parser needs to be able to at least do
210 ansi|ansi/pc-term compatible with color:\
211 :u6=\E[%i%d;%dR:u7=\E[6n:u9=\E[c:tc=ecma+color:\
212 :tc=klone+sgr:tc=ansi-m:
213 ansi-m|ansi-mono|ANSI X3.64-1979 terminal with ANSI.SYS compatible attributes:\
215 :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\
216 :LE=\E[%dD:RI=\E[%dC:SF=\E[%dS:SR=\E[%dT:UP=\E[%dA:\
217 :cb=\E[1K:ch=\E[%i%dG:ct=\E[2g:cv=\E[%i%dd:ec=\E[%dX:ei=:\
218 :im=:kB=\E[Z:kI=\E[L:kb=^H:kd=\E[B:kl=\E[D:kr=\E[C:ku=\E[A:\
219 :nw=\r\E[S:pf=\E[4i:po=\E[5i:s0=\E(B:s1=\E)B:s2=\E*B:\
220 :s3=\E+B:ta=\E[I:tc=pcansi-m:
221 pcansi-m|pcansi-mono|ibm-pc terminal programs claiming to be ansi (mono mode):\
224 :al=\E[L:bl=^G:bt=\E[Z:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
225 :cm=\E[%i%d;%dH:cr=^M:ct=\E[2g:dc=\E[P:dl=\E[M:do=\E[B:\
226 :ho=\E[H:kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:\
227 :le=\E[D:nd=\E[C:sf=^J:st=\EH:ta=^I:up=\E[A:\
229 klone+sgr-dumb|attribute control for ansi.sys displays (no ESC [ 11 m):\
230 :as=\E[12m:mb=\E[5m:md=\E[1m:me=\E[0;10m:mk=\E[8m:\
231 :mr=\E[7m:se=\E[m:so=\E[7m:ue=\E[m:us=\E[4m:tc=klone+acs:
232 klone+acs|alternate character set for ansi.sys displays:\
233 :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:\
234 :ae=\E[10m:as=\E[11m:
235 ecma+color|color control for ECMA-48-compatible terminals:\
237 :AB=\E[4%dm:AF=\E[3%dm:op=\E[39;49m:
240 Ignoreing ones in the VT102 spec
273 if (c<32) return ' ';
274 if (c>126) return ' ';
281 if ((c >= 'a') && (c <= 'z'))
283 if ((c >= 'A') && (c <= 'Z'))
314 in_margins (VT102 * v, CRT_Pos p)
316 if (v->pos.x < v->top_margin.x)
318 if (v->pos.y < v->top_margin.y)
321 if (v->pos.x > v->bottom_margin.x)
323 if (v->pos.y > v->bottom_margin.y)
330 vt102_log_line (Context * c, int line)
332 CRT_Pos e = { VT102_COLS - 1, line };
333 CRT_Pos p = { 0, line };
334 char logbuf[VT102_COLS + 1];
340 for (; e.x > 0; --e.x)
342 if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
346 for (; p.x <= e.x; ++p.x)
348 int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr;
357 c->l->log (c->l, logbuf);
360 /*Called for every upward scroll with same args*/
362 vt102_history (Context * c, CRT_Pos t, CRT_Pos b)
364 /*Only log if it scrolls off the top*/
369 history_add (c->h, &(c->v->crt.screen[CRT_ADDR_POS (&t)]));
373 vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br)
388 vt102_cursor_normalize (VT102 * v)
390 CRT_Pos *top, *bottom;
392 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
394 vt102_clip_cursor (v, v->top_margin, v->bottom_margin);
398 vt102_clip_cursor (v, v->screen_start, v->screen_end);
404 vt102_cursor_carriage_return (VT102 * v)
406 /*FISH*/ v->pos.x = v->top_margin.x;
411 vt102_cursor_advance_line (Context * c)
414 int couldscroll = in_margins (v, v->pos);
416 /*have wraped off end of last line in scrolling region */
417 /* (|| not necessary, but shuts compiler up */
418 if (((v->pos.y == v->bottom_margin.y) || (v->pos.y == v->screen_end.y)) &&
421 vt102_log_line (c, v->pos.y);
423 vt102_history (c, v->top_margin, v->bottom_margin);
425 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, v->color);
429 if (v->pos.y!=v->screen_end.y) v->pos.y++;
435 vt102_do_pending_wrap (Context * c)
438 int couldscroll = in_margins (v, v->pos);
439 int autowrap = v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP];
441 if (!v->pending_wrap)
445 fprintf (stderr, "ca: (%d,%d) autowrap %d couldscroll %d\n", v->pos.x,
446 v->pos.y, autowrap, couldscroll);
449 /*End of line but no autowrap, nothing to do*/
453 /*End of screen and not allowed to scroll, nothing to do*/
454 if ((v->pos.y == v->screen_end.y) && (!couldscroll))
459 v->pos.x = v->top_margin.x;
466 vt102_cursor_advance_line (c);
470 vt102_cursor_advance (Context * c)
474 if (v->pos.x < v->bottom_margin.x)
482 if (!c->v->xn_glitch)
483 vt102_do_pending_wrap(c);
489 vt102_cursor_retard (VT102 * v)
491 if (v->pos.x != v->top_margin.x)
498 vt102_reset_tabs (VT102 * v)
502 memset (v->tabs, 0, sizeof (v->tabs));
504 for (i = 0; i < VT102_COLS; i += 8)
510 vt102_cursor_advance_tab (VT102 * v)
512 if (v->pos.x == v->bottom_margin.x)
514 while (v->pos.x < v->bottom_margin.x)
517 if (v->tabs[v->pos.x])
524 vt102_cursor_retard_tab (VT102 * v)
526 if (v->pos.x == v->top_margin.x)
528 while (v->pos.x > v->top_margin.x)
531 if (v->tabs[v->pos.x])
537 vt102_cursor_home (VT102 * v)
539 v->pos = v->top_margin;
540 vt102_cursor_normalize (v);
545 vt102_cursor_absolute (VT102 * v, int x, int y)
547 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
549 v->pos.x = x + v->top_margin.x;
550 v->pos.y = y + v->top_margin.x;
557 vt102_cursor_normalize (v);
561 vt102_cursor_relative (VT102 * v, int x, int y)
565 vt102_cursor_normalize (v);
572 vt102_delete_from_line (VT102 * v, CRT_Pos p)
574 int n = v->bottom_margin.x - p.x;
582 memmove (&v->crt.screen[CRT_ADDR_POS (&p)],
583 &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n);
586 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
587 /*But not attr due to vt102 bug*/
591 vt102_insert_into_line (VT102 * v, CRT_Pos p)
593 int n = v->bottom_margin.x - p.x;
601 memmove (&v->crt.screen[CRT_ADDR_POS (&p) + 1],
602 &v->crt.screen[CRT_ADDR_POS (&p)], sizeof (CRT_CA) * n);
605 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
606 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].attr = CRT_ATTR_NORMAL;
607 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].color = CRT_COLOR_NORMAL;
613 vt102_change_mode (VT102 * v, int private, char *ns, int set)
629 if (m >= VT102_NMODES)
634 v->private_modes[m] = set;
637 case VT102_PRIVATE_MODE_CURSOR_MODE:
638 if (v->application_keypad_mode)
639 v->private_modes[m] = 0;
641 fprintf (stderr, "APPLICATION CURSOR MODE %d wanted %d\n",
642 v->private_modes[m], set);
645 case VT102_PRIVATE_MODE_ORIGIN_MODE:
646 vt102_cursor_home (v);
655 fprintf (stderr, "mode set=%d private=%d num=%d\n", set, private, m);
660 vt102_parse_mode_string (VT102 * v, char *buf, int len)
663 char last = buf[len - 1];
667 memset (num, 0, sizeof (num));
668 o = sizeof (num) - 1;
686 vt102_change_mode (v, private, &num[o], last == 'h');
687 memset (num, 0, sizeof (num));
688 o = sizeof (num) - 1;
703 vt102_change_mode (v, private, &num[o], last == 'h');
709 vt102_change_attr (VT102 * v, char *na)
726 v->attr = CRT_ATTR_NORMAL;
727 v->color = CRT_COLOR_NORMAL;
730 v->attr |= CRT_ATTR_BOLD;
734 v->attr &= ~CRT_ATTR_BOLD;
737 v->attr |= CRT_ATTR_UNDERLINE;
740 v->attr &= ~CRT_ATTR_UNDERLINE;
743 v->attr |= CRT_ATTR_BLINK;
746 v->attr &= ~CRT_ATTR_BLINK;
749 v->attr |= CRT_ATTR_REVERSE;
752 v->attr &= ~CRT_ATTR_REVERSE;
762 v->color &= ~CRT_COLOR_FG_MASK;
763 v->color |= ((a - 30) << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
773 v->color &= ~CRT_COLOR_FG_MASK;
776 90) | CRT_COLOR_INTENSITY) << CRT_COLOR_FG_SHIFT) &
781 v->color &= ~CRT_COLOR_FG_MASK;
783 (CRT_FGCOLOR_NORMAL << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
793 v->color &= ~CRT_COLOR_BG_MASK;
794 v->color |= ((a - 40) << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
804 v->color &= ~CRT_COLOR_BG_MASK;
807 100) | CRT_COLOR_INTENSITY) << CRT_COLOR_BG_SHIFT) &
812 v->color &= ~CRT_COLOR_BG_MASK;
814 (CRT_BGCOLOR_NORMAL << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
820 fprintf (stderr, "unhandled SGR %d\n", a);
828 vt102_parse_attr_string (VT102 * v, char *buf, int len)
831 char last = buf[len - 1];
835 memset (num, 0, sizeof (num));
836 o = sizeof (num) - 1;
847 vt102_change_attr (v, &num[o]);
848 memset (num, 0, sizeof (num));
849 o = sizeof (num) - 1;
863 vt102_change_attr (v, &num[o]);
867 vt102_save_state (VT102 * v)
869 v->saved.pos = v->pos;
870 v->saved.attr = v->attr;
871 v->saved.color = v->color;
872 v->saved.origin_mode = v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE];
876 vt102_restore_state (VT102 * v)
878 v->pos = v->saved.pos;
879 v->attr = v->saved.attr;
880 v->color = v->saved.color;
881 v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE] = v->saved.origin_mode;
882 vt102_cursor_normalize (v);
887 vt102_regular_char (Context * c, VT102 * v, char ch)
890 vt102_do_pending_wrap (c);
892 if (v->modes[VT102_MODE_INSERT])
893 vt102_insert_into_line (v, v->pos);
895 v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = ch;
896 v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
897 v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color;
898 vt102_cursor_advance (c);
900 v->last_reg_char = ch;
904 vt102_scs (Context * c, int g, int s)
906 /*Ignoring charsets*/
910 vt102_parse_esc (Context * c, int ch)
916 if (v->pos.y == v->bottom_margin.y)
918 vt102_log_line (c, v->pos.y);
919 vt102_history (c, v->top_margin, v->bottom_margin);
920 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
924 vt102_cursor_relative (v, 0, 1);
931 if (v->pos.y == v->top_margin.y)
933 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
937 vt102_cursor_relative (v, 0, -1);
941 vt102_save_state (v);
944 vt102_restore_state (v);
947 v->application_keypad_mode = 1;
950 v->application_keypad_mode = 0;
953 log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__,__LINE__,ch,safe_ch(ch));
959 vt102_parse_csi (Context * c, char *buf, int len)
991 vt102_insert_into_line (v, v->pos);
994 vt102_cursor_relative (v, 0, -narg);
998 vt102_cursor_relative (v, 0, narg);
1002 vt102_cursor_relative (v, narg, 0);
1005 vt102_cursor_relative (v, -narg, 0);
1008 vt102_cursor_relative (v, 0, narg);
1009 vt102_cursor_carriage_return (v);
1012 vt102_cursor_relative (v, 0, -narg);
1013 vt102_cursor_carriage_return (v);
1016 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1025 ptr = index (arg, ';');
1027 x = atoi (ptr + 1) - 1;
1031 vt102_cursor_absolute (v, x, y);
1036 vt102_cursor_advance_tab (c->v);
1040 narg = 0; /*Different default */
1044 crt_erase (&v->crt, v->pos, v->screen_end, 1,v->color);
1047 crt_erase (&v->crt, v->screen_start, v->pos, 1,v->color);
1050 crt_erase (&v->crt, v->screen_start, v->screen_end, 1,v->color);
1056 CRT_Pos ls = { 0, v->pos.y };
1057 CRT_Pos le = { VT102_COLS - 1, v->pos.y };
1059 narg = 0; /*Different default */
1064 crt_erase (&v->crt, v->pos, le, 1,v->color);
1067 crt_erase (&v->crt, ls, v->pos, 1,v->color);
1070 crt_erase (&v->crt, ls, le, 1,v->color);
1077 if ((v->pos.y >= v->top_margin.y)
1078 && (v->pos.y <= v->bottom_margin.y))
1081 crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1,v->color);
1086 if ((v->pos.y >= v->top_margin.y)
1087 && (v->pos.y <= v->bottom_margin.y))
1091 vt102_history (c, v->pos, v->bottom_margin);
1092 crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1,v->color);
1098 vt102_delete_from_line (v, v->pos);
1101 //FIXME: cursor position report - does anything use that?
1106 vt102_history (c, v->top_margin, v->bottom_margin);
1107 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
1112 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
1116 CRT_Pos end = v->pos;
1120 if (end.x > v->bottom_margin.x)
1121 end.x = v->bottom_margin.x;
1123 crt_erase (&v->crt, v->pos, end, 1,v->color);
1128 vt102_cursor_retard_tab (c->v);
1131 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1135 vt102_regular_char (c, v, v->last_reg_char);
1141 vt102_cursor_absolute (v, v->pos.x, narg - 1);
1145 narg = 0; /*Different default */
1150 v->tabs[v->pos.x] = 0;
1152 case 2: //FIXME: - LA120 says current line only WTF?
1154 memset (v->tabs, 0, sizeof (v->tabs));
1159 case 'i': //4,5 Turn printer on and off WTF?
1164 vt102_parse_mode_string (v, &buf[1], len - 1);
1169 vt102_parse_attr_string (v, &buf[1], len - 1);
1171 case 'n': // 6 request cursor position
1175 v->top_margin = v->screen_start;
1176 v->bottom_margin = v->screen_end;
1178 if ((len > 2) && (ptr = index (arg, ';')))
1181 v->top_margin.y = narg - 1;
1182 v->bottom_margin.y = atoi (ptr) - 1;
1185 if (v->top_margin.y < v->screen_start.y)
1186 v->top_margin.y = v->screen_start.y;
1187 if (v->top_margin.y > v->screen_end.y)
1188 v->top_margin.y = v->screen_end.y;
1189 if (v->bottom_margin.y < v->screen_start.y)
1190 v->bottom_margin.y = v->screen_start.y;
1191 if (v->bottom_margin.y > v->screen_end.y)
1192 v->bottom_margin.y = v->screen_end.y;
1194 vt102_cursor_home (v);
1197 v->saved.pos = v->pos;
1200 v->pos = v->saved.pos;
1201 vt102_cursor_normalize (v);
1202 v->pending_wrap = 0;
1206 log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__,__LINE__,buf);
1212 log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__,__LINE__,buf);
1221 vt102_status_line (VT102 * v, char *str)
1224 CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
1228 ca->attr = CRT_ATTR_REVERSE;
1229 ca->color = CRT_COLOR_NORMAL;
1240 vt102_parser_reset (VT102_parser * p)
1248 vt102_reset_state(VT102 *v)
1250 vt102_parser_reset(&v->parser);
1252 v->attr = CRT_ATTR_NORMAL;
1253 v->color = CRT_COLOR_NORMAL;
1255 v->application_keypad_mode = 0;
1257 v->top_margin = v->screen_start;
1258 v->bottom_margin = v->screen_end;
1260 memset (v->modes, 0, VT102_NMODES);
1261 memset (v->private_modes, 0, VT102_NMODES);
1263 v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP] = 1;
1264 v->private_modes[VT102_PRIVATE_MODE_AUTO_REPEAT] = 1;
1265 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] = 1;
1266 v->modes[VT102_MODE_LOCAL_ECHO_OFF] = 1;
1268 vt102_reset_tabs (v);
1273 vt102_parse_char (Context * c, int ch)
1276 VT102_parser *p = &v->parser;
1279 log_f (c->l, "char %3d %c pc %d %d %d %2d %2d %d",ch,safe_ch(ch),
1280 p->in_utf8,p->in_escape, p->in_csi, v->pos.x, v->pos.y,v->pending_wrap);
1283 if (ch==SYM_CHAR_RESET) {
1284 vt102_reset_state(v);
1285 } else if (p->in_csi)
1287 p->csi_buf[p->csi_ptr++] = ch;
1288 if (csi_ender (ch) || (p->csi_ptr == VT102_CSI_LEN))
1290 if (csi_starter (p->csi_buf[0]))
1292 vt102_parse_csi (c, p->csi_buf, p->csi_ptr);
1294 else if (scs_starter (p->csi_buf[0]))
1296 vt102_scs (c, p->csi_buf[0], p->csi_buf[1]);
1300 log_f (c->l, "<%s:%d no dispatcher for sequence starting \\033 \\%03o (ESC %c)>", __FILE__,__LINE__,p->csi_buf[0],safe_ch(p->csi_buf[0]));
1305 else if (p->in_escape)
1307 if (csi_starter (ch) || scs_starter (ch))
1310 p->csi_buf[p->csi_ptr++] = ch;
1317 vt102_parse_esc (c, ch);
1320 else if (ch==0x9b) /*One byte CSI*/
1323 p->csi_buf[p->csi_ptr++] = '[';
1339 c->t->xmit (c->t, "vt102", 5);
1345 vt102_cursor_retard (c->v);
1348 vt102_cursor_advance_tab (c->v);
1353 vt102_cursor_advance_line (c);
1354 if (!v->modes[VT102_MODE_NEWLINE_MODE])
1357 vt102_cursor_carriage_return (v);
1361 /*Ignoring charsets */
1365 /*Ignoring charsets */
1388 /*regular character */ default:
1389 vt102_regular_char (c, v, ch);
1393 v->crt.pos = v->pos;
1394 v->crt.hide_cursor =
1395 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0 : 1;
1397 if (v->current_line.y != v->pos.y)
1399 vt102_log_line (c, v->current_line.y);
1400 v->current_line = v->pos;
1404 cmd_show_status (c->d, c);
1408 vt102_send (Context * c, uint8_t key)
1416 fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' ');
1418 if ((key > 31) && (key < 127))
1420 c->t->xmit (c->t, &key, 1);
1439 c->t->xmit (c->t, &key, 1);
1442 c->t->xmit (c->t, &key, 1);
1443 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1446 c->t->xmit (c->t, &ch, 1);
1462 c->t->xmit (c->t, &key, 1);
1470 c->t->xmit (c->t, &key, 1);
1481 if (c->v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE])
1483 uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) };
1484 c->t->xmit (c->t, &buf, sizeof (buf));
1488 uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) };
1489 c->t->xmit (c->t, &buf, sizeof (buf));
1507 if (c->v->application_keypad_mode)
1509 uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) };
1510 c->t->xmit (c->t, &buf, sizeof (buf));
1514 static char kpoff[KEY_NUM] = {
1533 c->t->xmit (c->t, &kpoff[key], 1);
1537 if (c->v->application_keypad_mode)
1539 uint8_t buf[] = { 033, 'O', 'M' };
1540 c->t->xmit (c->t, &buf, sizeof (buf));
1545 c->t->xmit (c->t, &ch, 1);
1546 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1549 c->t->xmit (c->t, &ch, 1);
1558 uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) };
1559 c->t->xmit (c->t, &buf, sizeof (buf));
1567 uint8_t buf[] = { 033, '[', '0' + (key - KEY_180), '~' };
1568 c->t->xmit (c->t, &buf, sizeof (buf));
1576 vt102_reset (VT102 * v)
1578 VT102_parser *p = &v->parser;
1580 vt102_parser_reset (p);
1581 vt102_reset_state(p);
1584 v->current_line = v->pos;
1585 v->pending_wrap = 0;
1587 v->screen_start.x = 0;
1588 v->screen_start.y = 0;
1589 v->screen_end.x = VT102_COLS - 1;
1590 v->screen_end.y = VT102_ROWS - 1;
1592 vt102_cursor_home (v);
1593 vt102_status_line (v, "");
1595 vt102_reset_tabs (v);
1596 v->current_line = v->pos;
1598 vt102_save_state (v);
1600 v->last_reg_char = ' ';
1607 v = (VT102 *) malloc (sizeof (VT102));
1617 void vt102_set_ansi(VT102 *v,int ansi)
1619 v->xn_glitch=ansi ? 0:1;
1623 vt102_free (VT102 * v)