4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.33 2008/02/22 23:39:27 james
14 * *** empty log message ***
16 * Revision 1.32 2008/02/22 19:12:05 james
17 * *** empty log message ***
19 * Revision 1.31 2008/02/22 17:07:00 james
20 * *** empty log message ***
22 * Revision 1.30 2008/02/22 14:51:54 james
23 * *** empty log message ***
25 * Revision 1.29 2008/02/15 03:32:07 james
26 * *** empty log message ***
28 * Revision 1.28 2008/02/14 10:34:30 james
29 * *** empty log message ***
31 * Revision 1.27 2008/02/14 02:46:45 james
32 * *** empty log message ***
34 * Revision 1.26 2008/02/14 01:55:57 james
35 * *** empty log message ***
37 * Revision 1.25 2008/02/13 16:57:29 james
38 * *** empty log message ***
40 * Revision 1.24 2008/02/13 09:12:21 james
41 * *** empty log message ***
43 * Revision 1.23 2008/02/07 13:26:35 james
44 * *** empty log message ***
46 * Revision 1.22 2008/02/07 13:22:51 james
47 * *** empty log message ***
49 * Revision 1.21 2008/02/07 12:21:16 james
50 * *** empty log message ***
52 * Revision 1.20 2008/02/07 12:16:04 james
53 * *** empty log message ***
55 * Revision 1.19 2008/02/07 11:27:02 james
56 * *** empty log message ***
58 * Revision 1.18 2008/02/07 01:59:25 james
59 * *** empty log message ***
61 * Revision 1.17 2008/02/07 01:58:28 james
62 * *** empty log message ***
64 * Revision 1.16 2008/02/07 01:57:46 james
65 * *** empty log message ***
67 * Revision 1.15 2008/02/07 00:43:27 james
68 * *** empty log message ***
70 * Revision 1.14 2008/02/07 00:40:23 james
71 * *** empty log message ***
73 * Revision 1.13 2008/02/07 00:39:59 james
74 * *** empty log message ***
76 * Revision 1.12 2008/02/07 00:39:13 james
77 * *** empty log message ***
79 * Revision 1.11 2008/02/06 20:26:58 james
80 * *** empty log message ***
82 * Revision 1.10 2008/02/06 17:53:28 james
83 * *** empty log message ***
85 * Revision 1.9 2008/02/06 15:53:22 james
86 * *** empty log message ***
88 * Revision 1.8 2008/02/06 11:49:47 james
89 * *** empty log message ***
91 * Revision 1.7 2008/02/06 11:30:37 james
92 * *** empty log message ***
94 * Revision 1.6 2008/02/05 01:11:46 james
95 * *** empty log message ***
97 * Revision 1.5 2008/02/04 20:23:55 james
98 * *** empty log message ***
100 * Revision 1.4 2008/02/04 05:45:55 james
103 * Revision 1.3 2008/02/04 02:05:06 james
104 * *** empty log message ***
106 * Revision 1.2 2008/02/04 01:32:39 james
107 * *** empty log message ***
109 * Revision 1.1 2008/02/03 23:36:41 james
110 * *** empty log message ***
121 :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100:
123 vt100|vt100-am|dec vt100 (w/advanced video):\
125 :co#80:it#8:li#24:vt#3:\
126 :DO=\E[%dB:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:\
128 :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\
129 :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
130 :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\
131 :eA=\E(B\E)0:ho=\E[H:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\
132 :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\
133 :me=\E[m\017:mr=\E[7m:nd=\E[C:rc=\E8:\
134 :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:sc=\E7:se=\E[m:\
135 :sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:up=\E[A:\
136 :us=\E[4m:tc=vt100+fnkeys:
138 vt100+fnkeys|dec vt100 numeric keypad:\
139 :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\
142 vt100+pfkeys|dec vt100 numeric keypad:\
143 :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad:
145 vt100+keypad|dec vt100 numeric keypad no fkeys:\
146 :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:
151 so the parser needs to be able to at least do
213 ansi|ansi/pc-term compatible with color:\
214 :u6=\E[%i%d;%dR:u7=\E[6n:u9=\E[c:tc=ecma+color:\
215 :tc=klone+sgr:tc=ansi-m:
216 ansi-m|ansi-mono|ANSI X3.64-1979 terminal with ANSI.SYS compatible attributes:\
218 :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\
219 :LE=\E[%dD:RI=\E[%dC:SF=\E[%dS:SR=\E[%dT:UP=\E[%dA:\
220 :cb=\E[1K:ch=\E[%i%dG:ct=\E[2g:cv=\E[%i%dd:ec=\E[%dX:ei=:\
221 :im=:kB=\E[Z:kI=\E[L:kb=^H:kd=\E[B:kl=\E[D:kr=\E[C:ku=\E[A:\
222 :nw=\r\E[S:pf=\E[4i:po=\E[5i:s0=\E(B:s1=\E)B:s2=\E*B:\
223 :s3=\E+B:ta=\E[I:tc=pcansi-m:
224 pcansi-m|pcansi-mono|ibm-pc terminal programs claiming to be ansi (mono mode):\
227 :al=\E[L:bl=^G:bt=\E[Z:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
228 :cm=\E[%i%d;%dH:cr=^M:ct=\E[2g:dc=\E[P:dl=\E[M:do=\E[B:\
229 :ho=\E[H:kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:\
230 :le=\E[D:nd=\E[C:sf=^J:st=\EH:ta=^I:up=\E[A:\
232 klone+sgr-dumb|attribute control for ansi.sys displays (no ESC [ 11 m):\
233 :as=\E[12m:mb=\E[5m:md=\E[1m:me=\E[0;10m:mk=\E[8m:\
234 :mr=\E[7m:se=\E[m:so=\E[7m:ue=\E[m:us=\E[4m:tc=klone+acs:
235 klone+acs|alternate character set for ansi.sys displays:\
236 :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:\
237 :ae=\E[10m:as=\E[11m:
238 ecma+color|color control for ECMA-48-compatible terminals:\
240 :AB=\E[4%dm:AF=\E[3%dm:op=\E[39;49m:
243 Ignoreing ones in the VT102 spec
276 if (c<32) return ' ';
277 if (c>126) return ' ';
284 if ((c >= 'a') && (c <= 'z'))
286 if ((c >= 'A') && (c <= 'Z'))
317 in_margins (VT102 * v, CRT_Pos p)
319 if (v->pos.x < v->top_margin.x)
321 if (v->pos.y < v->top_margin.y)
324 if (v->pos.x > v->bottom_margin.x)
326 if (v->pos.y > v->bottom_margin.y)
333 vt102_log_line (Context * c, int line)
335 CRT_Pos e = { VT102_COLS - 1, line };
336 CRT_Pos p = { 0, line };
337 char logbuf[VT102_COLS + 1];
343 for (; e.x > 0; --e.x)
345 if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
349 for (; p.x <= e.x; ++p.x)
351 int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr;
360 c->l->log (c->l, logbuf);
363 /*Called for every upward scroll with same args*/
365 vt102_history (Context * c, CRT_Pos t, CRT_Pos b)
367 /*Only log if it scrolls off the top*/
372 history_add (c->h, &(c->v->crt.screen[CRT_ADDR_POS (&t)]));
376 vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br)
391 vt102_cursor_normalize (VT102 * v)
393 CRT_Pos *top, *bottom;
395 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
397 vt102_clip_cursor (v, v->top_margin, v->bottom_margin);
401 vt102_clip_cursor (v, v->screen_start, v->screen_end);
407 vt102_cursor_carriage_return (VT102 * v)
409 /*FISH*/ v->pos.x = v->top_margin.x;
414 vt102_cursor_advance_line (Context * c)
417 int couldscroll = in_margins (v, v->pos);
419 /*have wraped off end of last line in scrolling region */
420 /* (|| not necessary, but shuts compiler up */
421 if (((v->pos.y == v->bottom_margin.y) || (v->pos.y == v->screen_end.y)) &&
424 vt102_log_line (c, v->pos.y);
426 vt102_history (c, v->top_margin, v->bottom_margin);
428 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, v->color);
432 if (v->pos.y!=v->screen_end.y) v->pos.y++;
438 vt102_do_pending_wrap (Context * c)
441 int couldscroll = in_margins (v, v->pos);
442 int autowrap = v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP];
444 if (!v->pending_wrap)
448 fprintf (stderr, "ca: (%d,%d) autowrap %d couldscroll %d\n", v->pos.x,
449 v->pos.y, autowrap, couldscroll);
452 /*End of line but no autowrap, nothing to do*/
456 /*End of screen and not allowed to scroll, nothing to do*/
457 if ((v->pos.y == v->screen_end.y) && (!couldscroll))
462 v->pos.x = v->top_margin.x;
469 vt102_cursor_advance_line (c);
473 vt102_cursor_advance (Context * c)
477 if (v->pos.x < v->bottom_margin.x)
485 if (!c->v->xn_glitch)
486 vt102_do_pending_wrap(c);
492 vt102_cursor_retard (VT102 * v)
494 if (v->pos.x != v->top_margin.x)
501 vt102_reset_tabs (VT102 * v)
505 memset (v->tabs, 0, sizeof (v->tabs));
507 for (i = 0; i < VT102_COLS; i += 8)
513 vt102_cursor_advance_tab (VT102 * v)
515 if (v->pos.x == v->bottom_margin.x)
517 while (v->pos.x < v->bottom_margin.x)
520 if (v->tabs[v->pos.x])
527 vt102_cursor_retard_tab (VT102 * v)
529 if (v->pos.x == v->top_margin.x)
531 while (v->pos.x > v->top_margin.x)
534 if (v->tabs[v->pos.x])
540 vt102_cursor_home (VT102 * v)
542 v->pos = v->top_margin;
543 vt102_cursor_normalize (v);
548 vt102_cursor_absolute (VT102 * v, int x, int y)
550 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
552 v->pos.x = x + v->top_margin.x;
553 v->pos.y = y + v->top_margin.x;
560 vt102_cursor_normalize (v);
564 vt102_cursor_relative (VT102 * v, int x, int y)
568 vt102_cursor_normalize (v);
575 vt102_delete_from_line (VT102 * v, CRT_Pos p)
577 int n = v->bottom_margin.x - p.x;
585 memmove (&v->crt.screen[CRT_ADDR_POS (&p)],
586 &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n);
589 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
590 /*But not attr due to vt102 bug*/
594 vt102_insert_into_line (VT102 * v, CRT_Pos p)
596 int n = v->bottom_margin.x - p.x;
604 memmove (&v->crt.screen[CRT_ADDR_POS (&p) + 1],
605 &v->crt.screen[CRT_ADDR_POS (&p)], sizeof (CRT_CA) * n);
608 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
609 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].attr = CRT_ATTR_NORMAL;
610 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].color = CRT_COLOR_NORMAL;
616 vt102_change_mode (VT102 * v, int private, char *ns, int set)
632 if (m >= VT102_NMODES)
637 v->private_modes[m] = set;
640 case VT102_PRIVATE_MODE_CURSOR_MODE:
641 if (v->application_keypad_mode)
642 v->private_modes[m] = 0;
644 fprintf (stderr, "APPLICATION CURSOR MODE %d wanted %d\n",
645 v->private_modes[m], set);
648 case VT102_PRIVATE_MODE_ORIGIN_MODE:
649 vt102_cursor_home (v);
658 fprintf (stderr, "mode set=%d private=%d num=%d\n", set, private, m);
663 vt102_parse_mode_string (VT102 * v, char *buf, int len)
666 char last = buf[len - 1];
670 memset (num, 0, sizeof (num));
671 o = sizeof (num) - 1;
689 vt102_change_mode (v, private, &num[o], last == 'h');
690 memset (num, 0, sizeof (num));
691 o = sizeof (num) - 1;
706 vt102_change_mode (v, private, &num[o], last == 'h');
712 vt102_change_attr (VT102 * v, char *na)
729 v->attr = CRT_ATTR_NORMAL;
730 v->color = CRT_COLOR_NORMAL;
733 v->attr |= CRT_ATTR_BOLD;
737 v->attr &= ~CRT_ATTR_BOLD;
740 v->attr |= CRT_ATTR_UNDERLINE;
743 v->attr &= ~CRT_ATTR_UNDERLINE;
746 v->attr |= CRT_ATTR_BLINK;
749 v->attr &= ~CRT_ATTR_BLINK;
752 v->attr |= CRT_ATTR_REVERSE;
755 v->attr &= ~CRT_ATTR_REVERSE;
765 v->color &= ~CRT_COLOR_FG_MASK;
766 v->color |= ((a - 30) << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
776 v->color &= ~CRT_COLOR_FG_MASK;
779 90) | CRT_COLOR_INTENSITY) << CRT_COLOR_FG_SHIFT) &
784 v->color &= ~CRT_COLOR_FG_MASK;
786 (CRT_FGCOLOR_NORMAL << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
796 v->color &= ~CRT_COLOR_BG_MASK;
797 v->color |= ((a - 40) << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
807 v->color &= ~CRT_COLOR_BG_MASK;
810 100) | CRT_COLOR_INTENSITY) << CRT_COLOR_BG_SHIFT) &
815 v->color &= ~CRT_COLOR_BG_MASK;
817 (CRT_BGCOLOR_NORMAL << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
823 fprintf (stderr, "unhandled SGR %d\n", a);
831 vt102_parse_attr_string (VT102 * v, char *buf, int len)
834 char last = buf[len - 1];
838 memset (num, 0, sizeof (num));
839 o = sizeof (num) - 1;
850 vt102_change_attr (v, &num[o]);
851 memset (num, 0, sizeof (num));
852 o = sizeof (num) - 1;
866 vt102_change_attr (v, &num[o]);
870 vt102_save_state (VT102 * v)
872 v->saved.pos = v->pos;
873 v->saved.attr = v->attr;
874 v->saved.color = v->color;
875 v->saved.origin_mode = v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE];
879 vt102_restore_state (VT102 * v)
881 v->pos = v->saved.pos;
882 v->attr = v->saved.attr;
883 v->color = v->saved.color;
884 v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE] = v->saved.origin_mode;
885 vt102_cursor_normalize (v);
890 vt102_regular_char (Context * c, VT102 * v, char ch)
893 vt102_do_pending_wrap (c);
895 if (v->modes[VT102_MODE_INSERT])
896 vt102_insert_into_line (v, v->pos);
898 v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = ch;
899 v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
900 v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color;
901 vt102_cursor_advance (c);
903 v->last_reg_char = ch;
907 vt102_scs (Context * c, int g, int s)
909 /*Ignoring charsets*/
913 vt102_parse_esc (Context * c, int ch)
919 if (v->pos.y == v->bottom_margin.y)
921 vt102_log_line (c, v->pos.y);
922 vt102_history (c, v->top_margin, v->bottom_margin);
923 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
927 vt102_cursor_relative (v, 0, 1);
934 if (v->pos.y == v->top_margin.y)
936 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
940 vt102_cursor_relative (v, 0, -1);
944 vt102_save_state (v);
947 vt102_restore_state (v);
950 v->application_keypad_mode = 1;
953 v->application_keypad_mode = 0;
956 log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__,__LINE__,ch,safe_ch(ch));
962 vt102_parse_csi (Context * c, char *buf, int len)
994 vt102_insert_into_line (v, v->pos);
997 vt102_cursor_relative (v, 0, -narg);
1001 vt102_cursor_relative (v, 0, narg);
1005 vt102_cursor_relative (v, narg, 0);
1008 vt102_cursor_relative (v, -narg, 0);
1011 vt102_cursor_relative (v, 0, narg);
1012 vt102_cursor_carriage_return (v);
1015 vt102_cursor_relative (v, 0, -narg);
1016 vt102_cursor_carriage_return (v);
1019 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1028 ptr = index (arg, ';');
1030 x = atoi (ptr + 1) - 1;
1034 vt102_cursor_absolute (v, x, y);
1039 vt102_cursor_advance_tab (c->v);
1043 narg = 0; /*Different default */
1047 crt_erase (&v->crt, v->pos, v->screen_end, 1,v->color);
1050 crt_erase (&v->crt, v->screen_start, v->pos, 1,v->color);
1053 crt_erase (&v->crt, v->screen_start, v->screen_end, 1,v->color);
1059 CRT_Pos ls = { 0, v->pos.y };
1060 CRT_Pos le = { VT102_COLS - 1, v->pos.y };
1062 narg = 0; /*Different default */
1067 crt_erase (&v->crt, v->pos, le, 1,v->color);
1070 crt_erase (&v->crt, ls, v->pos, 1,v->color);
1073 crt_erase (&v->crt, ls, le, 1,v->color);
1080 if ((v->pos.y >= v->top_margin.y)
1081 && (v->pos.y <= v->bottom_margin.y))
1084 crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1,v->color);
1089 if ((v->pos.y >= v->top_margin.y)
1090 && (v->pos.y <= v->bottom_margin.y))
1094 vt102_history (c, v->pos, v->bottom_margin);
1095 crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1,v->color);
1101 vt102_delete_from_line (v, v->pos);
1104 //FIXME: cursor position report - does anything use that?
1109 vt102_history (c, v->top_margin, v->bottom_margin);
1110 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
1115 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
1119 CRT_Pos end = v->pos;
1123 if (end.x > v->bottom_margin.x)
1124 end.x = v->bottom_margin.x;
1126 crt_erase (&v->crt, v->pos, end, 1,v->color);
1131 vt102_cursor_retard_tab (c->v);
1134 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1138 vt102_regular_char (c, v, v->last_reg_char);
1144 vt102_cursor_absolute (v, v->pos.x, narg - 1);
1148 narg = 0; /*Different default */
1153 v->tabs[v->pos.x] = 0;
1155 case 2: //FIXME: - LA120 says current line only WTF?
1157 memset (v->tabs, 0, sizeof (v->tabs));
1162 case 'i': //4,5 Turn printer on and off WTF?
1167 vt102_parse_mode_string (v, &buf[1], len - 1);
1172 vt102_parse_attr_string (v, &buf[1], len - 1);
1174 case 'n': // 6 request cursor position
1178 v->top_margin = v->screen_start;
1179 v->bottom_margin = v->screen_end;
1181 if ((len > 2) && (ptr = index (arg, ';')))
1184 v->top_margin.y = narg - 1;
1185 v->bottom_margin.y = atoi (ptr) - 1;
1188 if (v->top_margin.y < v->screen_start.y)
1189 v->top_margin.y = v->screen_start.y;
1190 if (v->top_margin.y > v->screen_end.y)
1191 v->top_margin.y = v->screen_end.y;
1192 if (v->bottom_margin.y < v->screen_start.y)
1193 v->bottom_margin.y = v->screen_start.y;
1194 if (v->bottom_margin.y > v->screen_end.y)
1195 v->bottom_margin.y = v->screen_end.y;
1197 vt102_cursor_home (v);
1200 v->saved.pos = v->pos;
1203 v->pos = v->saved.pos;
1204 vt102_cursor_normalize (v);
1205 v->pending_wrap = 0;
1209 log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__,__LINE__,buf);
1215 log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__,__LINE__,buf);
1224 vt102_status_line (VT102 * v, char *str)
1227 CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
1231 ca->attr = CRT_ATTR_REVERSE;
1232 ca->color = CRT_COLOR_NORMAL;
1243 vt102_parser_reset (VT102_parser * p)
1251 vt102_reset_state(VT102 *v)
1253 vt102_parser_reset(&v->parser);
1255 v->attr = CRT_ATTR_NORMAL;
1256 v->color = CRT_COLOR_NORMAL;
1258 v->application_keypad_mode = 0;
1260 v->top_margin = v->screen_start;
1261 v->bottom_margin = v->screen_end;
1263 memset (v->modes, 0, VT102_NMODES);
1264 memset (v->private_modes, 0, VT102_NMODES);
1266 v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP] = 1;
1267 v->private_modes[VT102_PRIVATE_MODE_AUTO_REPEAT] = 1;
1268 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] = 1;
1269 v->modes[VT102_MODE_LOCAL_ECHO_OFF] = 1;
1271 vt102_reset_tabs (v);
1276 vt102_parse_char (Context * c, int ch)
1279 VT102_parser *p = &v->parser;
1282 log_f (c->l, "char %3d %c pc %d %d %d %2d %2d %d",ch,safe_ch(ch),
1283 p->in_utf8,p->in_escape, p->in_csi, v->pos.x, v->pos.y,v->pending_wrap);
1286 if (ch==SYM_CHAR_RESET) {
1287 vt102_reset_state(v);
1288 } else if (p->in_csi)
1290 p->csi_buf[p->csi_ptr++] = ch;
1291 if (csi_ender (ch) || (p->csi_ptr == VT102_CSI_LEN))
1293 if (csi_starter (p->csi_buf[0]))
1295 vt102_parse_csi (c, p->csi_buf, p->csi_ptr);
1297 else if (scs_starter (p->csi_buf[0]))
1299 vt102_scs (c, p->csi_buf[0], p->csi_buf[1]);
1303 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]));
1308 else if (p->in_escape)
1310 if (csi_starter (ch) || scs_starter (ch))
1313 p->csi_buf[p->csi_ptr++] = ch;
1320 vt102_parse_esc (c, ch);
1323 else if (ch==0x9b) /*One byte CSI*/
1326 p->csi_buf[p->csi_ptr++] = '[';
1342 c->t->xmit (c->t, "vt102", 5);
1348 vt102_cursor_retard (c->v);
1351 vt102_cursor_advance_tab (c->v);
1356 vt102_cursor_advance_line (c);
1357 if (!v->modes[VT102_MODE_NEWLINE_MODE])
1360 vt102_cursor_carriage_return (v);
1364 /*Ignoring charsets */
1368 /*Ignoring charsets */
1391 /*regular character */ default:
1392 vt102_regular_char (c, v, ch);
1396 v->crt.pos = v->pos;
1397 v->crt.hide_cursor =
1398 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0 : 1;
1400 if (v->current_line.y != v->pos.y)
1402 vt102_log_line (c, v->current_line.y);
1403 v->current_line = v->pos;
1407 cmd_show_status (c->d, c);
1411 vt102_send (Context * c, uint8_t key)
1419 fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' ');
1421 if ((key > 31) && (key < 127))
1423 c->t->xmit (c->t, &key, 1);
1442 c->t->xmit (c->t, &key, 1);
1445 c->t->xmit (c->t, &key, 1);
1446 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1449 c->t->xmit (c->t, &ch, 1);
1465 c->t->xmit (c->t, &key, 1);
1473 c->t->xmit (c->t, &key, 1);
1484 if (c->v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE])
1486 uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) };
1487 c->t->xmit (c->t, &buf, sizeof (buf));
1491 uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) };
1492 c->t->xmit (c->t, &buf, sizeof (buf));
1510 if (c->v->application_keypad_mode)
1512 uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) };
1513 c->t->xmit (c->t, &buf, sizeof (buf));
1517 static char kpoff[KEY_NUM] = {
1536 c->t->xmit (c->t, &kpoff[key], 1);
1540 if (c->v->application_keypad_mode)
1542 uint8_t buf[] = { 033, 'O', 'M' };
1543 c->t->xmit (c->t, &buf, sizeof (buf));
1548 c->t->xmit (c->t, &ch, 1);
1549 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1552 c->t->xmit (c->t, &ch, 1);
1561 uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) };
1562 c->t->xmit (c->t, &buf, sizeof (buf));
1570 uint8_t buf[] = { 033, '[', '0' + (key - KEY_180), '~' };
1571 c->t->xmit (c->t, &buf, sizeof (buf));
1579 vt102_reset (VT102 * v)
1581 VT102_parser *p = &v->parser;
1583 vt102_parser_reset (p);
1584 vt102_reset_state(v);
1587 v->current_line = v->pos;
1588 v->pending_wrap = 0;
1590 v->screen_start.x = 0;
1591 v->screen_start.y = 0;
1592 v->screen_end.x = VT102_COLS - 1;
1593 v->screen_end.y = VT102_ROWS - 1;
1595 vt102_cursor_home (v);
1596 vt102_status_line (v, "");
1598 vt102_reset_tabs (v);
1599 v->current_line = v->pos;
1601 vt102_save_state (v);
1603 v->last_reg_char = ' ';
1610 v = (VT102 *) malloc (sizeof (VT102));
1620 void vt102_set_ansi(VT102 *v,int ansi)
1622 v->xn_glitch=ansi ? 0:1;
1626 vt102_free (VT102 * v)