4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.31 2008/02/22 17:07:00 james
14 * *** empty log message ***
16 * Revision 1.30 2008/02/22 14:51:54 james
17 * *** empty log message ***
19 * Revision 1.29 2008/02/15 03:32:07 james
20 * *** empty log message ***
22 * Revision 1.28 2008/02/14 10:34:30 james
23 * *** empty log message ***
25 * Revision 1.27 2008/02/14 02:46:45 james
26 * *** empty log message ***
28 * Revision 1.26 2008/02/14 01:55:57 james
29 * *** empty log message ***
31 * Revision 1.25 2008/02/13 16:57:29 james
32 * *** empty log message ***
34 * Revision 1.24 2008/02/13 09:12:21 james
35 * *** empty log message ***
37 * Revision 1.23 2008/02/07 13:26:35 james
38 * *** empty log message ***
40 * Revision 1.22 2008/02/07 13:22:51 james
41 * *** empty log message ***
43 * Revision 1.21 2008/02/07 12:21:16 james
44 * *** empty log message ***
46 * Revision 1.20 2008/02/07 12:16:04 james
47 * *** empty log message ***
49 * Revision 1.19 2008/02/07 11:27:02 james
50 * *** empty log message ***
52 * Revision 1.18 2008/02/07 01:59:25 james
53 * *** empty log message ***
55 * Revision 1.17 2008/02/07 01:58:28 james
56 * *** empty log message ***
58 * Revision 1.16 2008/02/07 01:57:46 james
59 * *** empty log message ***
61 * Revision 1.15 2008/02/07 00:43:27 james
62 * *** empty log message ***
64 * Revision 1.14 2008/02/07 00:40:23 james
65 * *** empty log message ***
67 * Revision 1.13 2008/02/07 00:39:59 james
68 * *** empty log message ***
70 * Revision 1.12 2008/02/07 00:39:13 james
71 * *** empty log message ***
73 * Revision 1.11 2008/02/06 20:26:58 james
74 * *** empty log message ***
76 * Revision 1.10 2008/02/06 17:53:28 james
77 * *** empty log message ***
79 * Revision 1.9 2008/02/06 15:53:22 james
80 * *** empty log message ***
82 * Revision 1.8 2008/02/06 11:49:47 james
83 * *** empty log message ***
85 * Revision 1.7 2008/02/06 11:30:37 james
86 * *** empty log message ***
88 * Revision 1.6 2008/02/05 01:11:46 james
89 * *** empty log message ***
91 * Revision 1.5 2008/02/04 20:23:55 james
92 * *** empty log message ***
94 * Revision 1.4 2008/02/04 05:45:55 james
97 * Revision 1.3 2008/02/04 02:05:06 james
98 * *** empty log message ***
100 * Revision 1.2 2008/02/04 01:32:39 james
101 * *** empty log message ***
103 * Revision 1.1 2008/02/03 23:36:41 james
104 * *** empty log message ***
115 :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100:
117 vt100|vt100-am|dec vt100 (w/advanced video):\
119 :co#80:it#8:li#24:vt#3:\
120 :DO=\E[%dB:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:\
122 :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\
123 :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
124 :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\
125 :eA=\E(B\E)0:ho=\E[H:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\
126 :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\
127 :me=\E[m\017:mr=\E[7m:nd=\E[C:rc=\E8:\
128 :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:sc=\E7:se=\E[m:\
129 :sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:up=\E[A:\
130 :us=\E[4m:tc=vt100+fnkeys:
132 vt100+fnkeys|dec vt100 numeric keypad:\
133 :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\
136 vt100+pfkeys|dec vt100 numeric keypad:\
137 :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad:
139 vt100+keypad|dec vt100 numeric keypad no fkeys:\
140 :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:
145 so the parser needs to be able to at least do
207 ansi|ansi/pc-term compatible with color:\
208 :u6=\E[%i%d;%dR:u7=\E[6n:u9=\E[c:tc=ecma+color:\
209 :tc=klone+sgr:tc=ansi-m:
210 ansi-m|ansi-mono|ANSI X3.64-1979 terminal with ANSI.SYS compatible attributes:\
212 :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\
213 :LE=\E[%dD:RI=\E[%dC:SF=\E[%dS:SR=\E[%dT:UP=\E[%dA:\
214 :cb=\E[1K:ch=\E[%i%dG:ct=\E[2g:cv=\E[%i%dd:ec=\E[%dX:ei=:\
215 :im=:kB=\E[Z:kI=\E[L:kb=^H:kd=\E[B:kl=\E[D:kr=\E[C:ku=\E[A:\
216 :nw=\r\E[S:pf=\E[4i:po=\E[5i:s0=\E(B:s1=\E)B:s2=\E*B:\
217 :s3=\E+B:ta=\E[I:tc=pcansi-m:
218 pcansi-m|pcansi-mono|ibm-pc terminal programs claiming to be ansi (mono mode):\
221 :al=\E[L:bl=^G:bt=\E[Z:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
222 :cm=\E[%i%d;%dH:cr=^M:ct=\E[2g:dc=\E[P:dl=\E[M:do=\E[B:\
223 :ho=\E[H:kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:\
224 :le=\E[D:nd=\E[C:sf=^J:st=\EH:ta=^I:up=\E[A:\
226 klone+sgr-dumb|attribute control for ansi.sys displays (no ESC [ 11 m):\
227 :as=\E[12m:mb=\E[5m:md=\E[1m:me=\E[0;10m:mk=\E[8m:\
228 :mr=\E[7m:se=\E[m:so=\E[7m:ue=\E[m:us=\E[4m:tc=klone+acs:
229 klone+acs|alternate character set for ansi.sys displays:\
230 :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:\
231 :ae=\E[10m:as=\E[11m:
232 ecma+color|color control for ECMA-48-compatible terminals:\
234 :AB=\E[4%dm:AF=\E[3%dm:op=\E[39;49m:
237 Ignoreing ones in the VT102 spec
270 if (c<32) return ' ';
271 if (c>126) return ' ';
278 if ((c >= 'a') && (c <= 'z'))
280 if ((c >= 'A') && (c <= 'Z'))
311 in_margins (VT102 * v, CRT_Pos p)
313 if (v->pos.x < v->top_margin.x)
315 if (v->pos.y < v->top_margin.y)
318 if (v->pos.x > v->bottom_margin.x)
320 if (v->pos.y > v->bottom_margin.y)
327 vt102_log_line (Context * c, int line)
329 CRT_Pos e = { VT102_COLS - 1, line };
330 CRT_Pos p = { 0, line };
331 char logbuf[VT102_COLS + 1];
337 for (; e.x > 0; --e.x)
339 if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
343 for (; p.x <= e.x; ++p.x)
345 int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr;
354 c->l->log (c->l, logbuf);
357 /*Called for every upward scroll with same args*/
359 vt102_history (Context * c, CRT_Pos t, CRT_Pos b)
361 /*Only log if it scrolls off the top*/
366 history_add (c->h, &(c->v->crt.screen[CRT_ADDR_POS (&t)]));
370 vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br)
385 vt102_cursor_normalize (VT102 * v)
387 CRT_Pos *top, *bottom;
389 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
391 vt102_clip_cursor (v, v->top_margin, v->bottom_margin);
395 vt102_clip_cursor (v, v->screen_start, v->screen_end);
401 vt102_cursor_carriage_return (VT102 * v)
403 /*FISH*/ v->pos.x = v->top_margin.x;
408 vt102_cursor_advance_line (Context * c)
411 int couldscroll = in_margins (v, v->pos);
413 /*have wraped off end of last line in scrolling region */
414 /* (|| not necessary, but shuts compiler up */
415 if (((v->pos.y == v->bottom_margin.y) || (v->pos.y == v->screen_end.y)) &&
418 vt102_log_line (c, v->pos.y);
420 vt102_history (c, v->top_margin, v->bottom_margin);
422 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, v->color);
426 if (v->pos.y!=v->screen_end.y) v->pos.y++;
432 vt102_do_pending_wrap (Context * c)
435 int couldscroll = in_margins (v, v->pos);
436 int autowrap = v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP];
438 if (!v->pending_wrap)
442 fprintf (stderr, "ca: (%d,%d) autowrap %d couldscroll %d\n", v->pos.x,
443 v->pos.y, autowrap, couldscroll);
446 /*End of line but no autowrap, nothing to do*/
450 /*End of screen and not allowed to scroll, nothing to do*/
451 if ((v->pos.y == v->screen_end.y) && (!couldscroll))
456 v->pos.x = v->top_margin.x;
463 vt102_cursor_advance_line (c);
467 vt102_cursor_advance (Context * c)
471 if (v->pos.x < v->bottom_margin.x)
479 if (!c->v->xn_glitch)
480 vt102_do_pending_wrap(c);
486 vt102_cursor_retard (VT102 * v)
488 if (v->pos.x != v->top_margin.x)
495 vt102_reset_tabs (VT102 * v)
499 memset (v->tabs, 0, sizeof (v->tabs));
501 for (i = 0; i < VT102_COLS; i += 8)
507 vt102_cursor_advance_tab (VT102 * v)
509 if (v->pos.x == v->bottom_margin.x)
511 while (v->pos.x < v->bottom_margin.x)
514 if (v->tabs[v->pos.x])
521 vt102_cursor_retard_tab (VT102 * v)
523 if (v->pos.x == v->top_margin.x)
525 while (v->pos.x > v->top_margin.x)
528 if (v->tabs[v->pos.x])
534 vt102_cursor_home (VT102 * v)
536 v->pos = v->top_margin;
537 vt102_cursor_normalize (v);
542 vt102_cursor_absolute (VT102 * v, int x, int y)
544 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
546 v->pos.x = x + v->top_margin.x;
547 v->pos.y = y + v->top_margin.x;
554 vt102_cursor_normalize (v);
558 vt102_cursor_relative (VT102 * v, int x, int y)
562 vt102_cursor_normalize (v);
569 vt102_delete_from_line (VT102 * v, CRT_Pos p)
571 int n = v->bottom_margin.x - p.x;
579 memmove (&v->crt.screen[CRT_ADDR_POS (&p)],
580 &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n);
583 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
584 /*But not attr due to vt102 bug*/
588 vt102_insert_into_line (VT102 * v, CRT_Pos p)
590 int n = v->bottom_margin.x - p.x;
598 memmove (&v->crt.screen[CRT_ADDR_POS (&p) + 1],
599 &v->crt.screen[CRT_ADDR_POS (&p)], sizeof (CRT_CA) * n);
602 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
603 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].attr = CRT_ATTR_NORMAL;
604 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].color = CRT_COLOR_NORMAL;
610 vt102_change_mode (VT102 * v, int private, char *ns, int set)
626 if (m >= VT102_NMODES)
631 v->private_modes[m] = set;
634 case VT102_PRIVATE_MODE_CURSOR_MODE:
635 if (v->application_keypad_mode)
636 v->private_modes[m] = 0;
638 fprintf (stderr, "APPLICATION CURSOR MODE %d wanted %d\n",
639 v->private_modes[m], set);
642 case VT102_PRIVATE_MODE_ORIGIN_MODE:
643 vt102_cursor_home (v);
652 fprintf (stderr, "mode set=%d private=%d num=%d\n", set, private, m);
657 vt102_parse_mode_string (VT102 * v, char *buf, int len)
660 char last = buf[len - 1];
664 memset (num, 0, sizeof (num));
665 o = sizeof (num) - 1;
683 vt102_change_mode (v, private, &num[o], last == 'h');
684 memset (num, 0, sizeof (num));
685 o = sizeof (num) - 1;
700 vt102_change_mode (v, private, &num[o], last == 'h');
706 vt102_change_attr (VT102 * v, char *na)
723 v->attr = CRT_ATTR_NORMAL;
724 v->color = CRT_COLOR_NORMAL;
727 v->attr |= CRT_ATTR_BOLD;
731 v->attr &= ~CRT_ATTR_BOLD;
734 v->attr |= CRT_ATTR_UNDERLINE;
737 v->attr &= ~CRT_ATTR_UNDERLINE;
740 v->attr |= CRT_ATTR_BLINK;
743 v->attr &= ~CRT_ATTR_BLINK;
746 v->attr |= CRT_ATTR_REVERSE;
749 v->attr &= ~CRT_ATTR_REVERSE;
759 v->color &= ~CRT_COLOR_FG_MASK;
760 v->color |= ((a - 30) << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
770 v->color &= ~CRT_COLOR_FG_MASK;
773 90) | CRT_COLOR_INTENSITY) << CRT_COLOR_FG_SHIFT) &
778 v->color &= ~CRT_COLOR_FG_MASK;
780 (CRT_FGCOLOR_NORMAL << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
790 v->color &= ~CRT_COLOR_BG_MASK;
791 v->color |= ((a - 40) << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
801 v->color &= ~CRT_COLOR_BG_MASK;
804 100) | CRT_COLOR_INTENSITY) << CRT_COLOR_BG_SHIFT) &
809 v->color &= ~CRT_COLOR_BG_MASK;
811 (CRT_BGCOLOR_NORMAL << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
817 fprintf (stderr, "unhandled SGR %d\n", a);
825 vt102_parse_attr_string (VT102 * v, char *buf, int len)
828 char last = buf[len - 1];
832 memset (num, 0, sizeof (num));
833 o = sizeof (num) - 1;
844 vt102_change_attr (v, &num[o]);
845 memset (num, 0, sizeof (num));
846 o = sizeof (num) - 1;
860 vt102_change_attr (v, &num[o]);
864 vt102_save_state (VT102 * v)
866 v->saved.pos = v->pos;
867 v->saved.attr = v->attr;
868 v->saved.color = v->color;
869 v->saved.origin_mode = v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE];
873 vt102_restore_state (VT102 * v)
875 v->pos = v->saved.pos;
876 v->attr = v->saved.attr;
877 v->color = v->saved.color;
878 v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE] = v->saved.origin_mode;
879 vt102_cursor_normalize (v);
884 vt102_regular_char (Context * c, VT102 * v, char ch)
887 vt102_do_pending_wrap (c);
889 if (v->modes[VT102_MODE_INSERT])
890 vt102_insert_into_line (v, v->pos);
892 v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = ch;
893 v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
894 v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color;
895 vt102_cursor_advance (c);
897 v->last_reg_char = ch;
901 vt102_scs (Context * c, int g, int s)
903 /*Ignoring charsets*/
907 vt102_parse_esc (Context * c, int ch)
913 if (v->pos.y == v->bottom_margin.y)
915 vt102_log_line (c, v->pos.y);
916 vt102_history (c, v->top_margin, v->bottom_margin);
917 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
921 vt102_cursor_relative (v, 0, 1);
928 if (v->pos.y == v->top_margin.y)
930 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
934 vt102_cursor_relative (v, 0, -1);
938 vt102_save_state (v);
941 vt102_restore_state (v);
944 v->application_keypad_mode = 1;
947 v->application_keypad_mode = 0;
950 log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__,__LINE__,ch,safe_ch(ch));
956 vt102_parse_csi (Context * c, char *buf, int len)
988 vt102_insert_into_line (v, v->pos);
991 vt102_cursor_relative (v, 0, -narg);
995 vt102_cursor_relative (v, 0, narg);
999 vt102_cursor_relative (v, narg, 0);
1002 vt102_cursor_relative (v, -narg, 0);
1005 vt102_cursor_relative (v, 0, narg);
1006 vt102_cursor_carriage_return (v);
1009 vt102_cursor_relative (v, 0, -narg);
1010 vt102_cursor_carriage_return (v);
1013 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1022 ptr = index (arg, ';');
1024 x = atoi (ptr + 1) - 1;
1028 vt102_cursor_absolute (v, x, y);
1033 vt102_cursor_advance_tab (c->v);
1037 narg = 0; /*Different default */
1041 crt_erase (&v->crt, v->pos, v->screen_end, 1,v->color);
1044 crt_erase (&v->crt, v->screen_start, v->pos, 1,v->color);
1047 crt_erase (&v->crt, v->screen_start, v->screen_end, 1,v->color);
1053 CRT_Pos ls = { 0, v->pos.y };
1054 CRT_Pos le = { VT102_COLS - 1, v->pos.y };
1056 narg = 0; /*Different default */
1061 crt_erase (&v->crt, v->pos, le, 1,v->color);
1064 crt_erase (&v->crt, ls, v->pos, 1,v->color);
1067 crt_erase (&v->crt, ls, le, 1,v->color);
1074 if ((v->pos.y >= v->top_margin.y)
1075 && (v->pos.y <= v->bottom_margin.y))
1078 crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1,v->color);
1083 if ((v->pos.y >= v->top_margin.y)
1084 && (v->pos.y <= v->bottom_margin.y))
1088 vt102_history (c, v->pos, v->bottom_margin);
1089 crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1,v->color);
1095 vt102_delete_from_line (v, v->pos);
1098 //FIXME: cursor position report - does anything use that?
1103 vt102_history (c, v->top_margin, v->bottom_margin);
1104 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
1109 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
1113 CRT_Pos end = v->pos;
1117 if (end.x > v->bottom_margin.x)
1118 end.x = v->bottom_margin.x;
1120 crt_erase (&v->crt, v->pos, end, 1,v->color);
1125 vt102_cursor_retard_tab (c->v);
1128 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1132 vt102_regular_char (c, v, v->last_reg_char);
1138 vt102_cursor_absolute (v, v->pos.x, narg - 1);
1142 narg = 0; /*Different default */
1147 v->tabs[v->pos.x] = 0;
1149 case 2: //FIXME: - LA120 says current line only WTF?
1151 memset (v->tabs, 0, sizeof (v->tabs));
1156 case 'i': //4,5 Turn printer on and off WTF?
1161 vt102_parse_mode_string (v, &buf[1], len - 1);
1166 vt102_parse_attr_string (v, &buf[1], len - 1);
1168 case 'n': // 6 request cursor position
1172 v->top_margin = v->screen_start;
1173 v->bottom_margin = v->screen_end;
1175 if ((len > 2) && (ptr = index (arg, ';')))
1178 v->top_margin.y = narg - 1;
1179 v->bottom_margin.y = atoi (ptr) - 1;
1182 if (v->top_margin.y < v->screen_start.y)
1183 v->top_margin.y = v->screen_start.y;
1184 if (v->top_margin.y > v->screen_end.y)
1185 v->top_margin.y = v->screen_end.y;
1186 if (v->bottom_margin.y < v->screen_start.y)
1187 v->bottom_margin.y = v->screen_start.y;
1188 if (v->bottom_margin.y > v->screen_end.y)
1189 v->bottom_margin.y = v->screen_end.y;
1191 vt102_cursor_home (v);
1194 v->saved.pos = v->pos;
1197 v->pos = v->saved.pos;
1198 vt102_cursor_normalize (v);
1199 v->pending_wrap = 0;
1203 log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__,__LINE__,buf);
1209 log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__,__LINE__,buf);
1218 vt102_status_line (VT102 * v, char *str)
1221 CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
1225 ca->attr = CRT_ATTR_REVERSE;
1226 ca->color = CRT_COLOR_NORMAL;
1237 vt102_parse_char (Context * c, int ch)
1240 VT102_parser *p = &v->parser;
1243 log_f (c->l, "char %3d %c pc %d %d %d %2d %2d %d",ch,safe_ch(ch),
1244 p->in_utf8,p->in_escape, p->in_csi, v->pos.x, v->pos.y,v->pending_wrap);
1247 if ((ch>=0xc0) && (ch<0xe0)) /*Start of two byte unicode sequence*/
1250 } else if ((ch>=0xe0) && (ch<0xf0)) /*Start of three byte unicode sequence*/
1253 } else if ((ch>=0xf0) && (ch<0xf7)) /*Start of four byte unicode sequence*/
1263 /*Not first or last byte in sequence*/
1264 }else if (p->in_csi)
1266 p->csi_buf[p->csi_ptr++] = ch;
1267 if (csi_ender (ch) || (p->csi_ptr == VT102_CSI_LEN))
1269 if (csi_starter (p->csi_buf[0]))
1271 vt102_parse_csi (c, p->csi_buf, p->csi_ptr);
1273 else if (scs_starter (p->csi_buf[0]))
1275 vt102_scs (c, p->csi_buf[0], p->csi_buf[1]);
1279 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]));
1284 else if (p->in_escape)
1286 if (csi_starter (ch) || scs_starter (ch))
1289 p->csi_buf[p->csi_ptr++] = ch;
1296 vt102_parse_esc (c, ch);
1299 else if (ch==0x9b) /*One byte CSI*/
1302 p->csi_buf[p->csi_ptr++] = '[';
1318 c->t->xmit (c->t, "vt102", 5);
1324 vt102_cursor_retard (c->v);
1327 vt102_cursor_advance_tab (c->v);
1332 vt102_cursor_advance_line (c);
1333 if (!v->modes[VT102_MODE_NEWLINE_MODE])
1336 vt102_cursor_carriage_return (v);
1340 /*Ignoring charsets */
1344 /*Ignoring charsets */
1367 /*regular character */ default:
1368 vt102_regular_char (c, v, ch);
1372 v->crt.pos = v->pos;
1373 v->crt.hide_cursor =
1374 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0 : 1;
1376 if (v->current_line.y != v->pos.y)
1378 vt102_log_line (c, v->current_line.y);
1379 v->current_line = v->pos;
1383 cmd_show_status (c->d, c);
1386 vt102_parse (Context * c, char *buf, int len)
1389 vt102_parse_char (c, *(buf++));
1394 vt102_parser_reset (VT102_parser * p)
1403 vt102_send (Context * c, uint8_t key)
1411 fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' ');
1413 if ((key > 31) && (key < 127))
1415 c->t->xmit (c->t, &key, 1);
1434 c->t->xmit (c->t, &key, 1);
1437 c->t->xmit (c->t, &key, 1);
1438 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1441 c->t->xmit (c->t, &ch, 1);
1457 c->t->xmit (c->t, &key, 1);
1465 c->t->xmit (c->t, &key, 1);
1476 if (c->v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE])
1478 uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) };
1479 c->t->xmit (c->t, &buf, sizeof (buf));
1483 uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) };
1484 c->t->xmit (c->t, &buf, sizeof (buf));
1502 if (c->v->application_keypad_mode)
1504 uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) };
1505 c->t->xmit (c->t, &buf, sizeof (buf));
1509 static char kpoff[KEY_NUM] = {
1528 c->t->xmit (c->t, &kpoff[key], 1);
1532 if (c->v->application_keypad_mode)
1534 uint8_t buf[] = { 033, 'O', 'M' };
1535 c->t->xmit (c->t, &buf, sizeof (buf));
1540 c->t->xmit (c->t, &ch, 1);
1541 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1544 c->t->xmit (c->t, &ch, 1);
1553 uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) };
1554 c->t->xmit (c->t, &buf, sizeof (buf));
1562 uint8_t buf[] = { 033, '[', '0' + (key - KEY_180), '~' };
1563 c->t->xmit (c->t, &buf, sizeof (buf));
1571 vt102_reset (VT102 * v)
1573 VT102_parser *p = &v->parser;
1575 vt102_parser_reset (p);
1578 v->attr = CRT_ATTR_NORMAL;
1579 v->color = CRT_COLOR_NORMAL;
1581 v->application_keypad_mode = 0;
1583 v->current_line = v->pos;
1584 v->pending_wrap = 0;
1586 v->screen_start.x = 0;
1587 v->screen_start.y = 0;
1588 v->screen_end.x = VT102_COLS - 1;
1589 v->screen_end.y = VT102_ROWS - 1;
1591 v->top_margin = v->screen_start;
1592 v->bottom_margin = v->screen_end;
1594 memset (v->modes, 0, VT102_NMODES);
1595 memset (v->private_modes, 0, VT102_NMODES);
1597 v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP] = 1;
1598 v->private_modes[VT102_PRIVATE_MODE_AUTO_REPEAT] = 1;
1599 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] = 1;
1600 v->modes[VT102_MODE_LOCAL_ECHO_OFF] = 1;
1602 vt102_cursor_home (v);
1603 vt102_reset_tabs (v);
1604 v->current_line = v->pos;
1606 vt102_save_state (v);
1608 vt102_status_line (v, "");
1610 v->last_reg_char = ' ';
1616 vt102_dispatch (Context * c)
1621 red = c->t->recv (c->t, buf, sizeof (buf));
1629 vt102_parse (c, buf, red);
1636 vt102_dispatch_one (Context * c)
1641 red = c->t->recv (c->t, &buf, sizeof (buf));
1648 vt102_parse_char (c, buf);
1658 v = (VT102 *) malloc (sizeof (VT102));
1667 void vt102_set_ansi(VT102 *v,int ansi)
1669 v->xn_glitch=ansi ? 0:1;
1673 vt102_free (VT102 * v)