4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.35 2008/02/24 00:42:53 james
14 * *** empty log message ***
16 * Revision 1.34 2008/02/23 11:48:37 james
17 * *** empty log message ***
19 * Revision 1.33 2008/02/22 23:39:27 james
20 * *** empty log message ***
22 * Revision 1.32 2008/02/22 19:12:05 james
23 * *** empty log message ***
25 * Revision 1.31 2008/02/22 17:07:00 james
26 * *** empty log message ***
28 * Revision 1.30 2008/02/22 14:51:54 james
29 * *** empty log message ***
31 * Revision 1.29 2008/02/15 03:32:07 james
32 * *** empty log message ***
34 * Revision 1.28 2008/02/14 10:34:30 james
35 * *** empty log message ***
37 * Revision 1.27 2008/02/14 02:46:45 james
38 * *** empty log message ***
40 * Revision 1.26 2008/02/14 01:55:57 james
41 * *** empty log message ***
43 * Revision 1.25 2008/02/13 16:57:29 james
44 * *** empty log message ***
46 * Revision 1.24 2008/02/13 09:12:21 james
47 * *** empty log message ***
49 * Revision 1.23 2008/02/07 13:26:35 james
50 * *** empty log message ***
52 * Revision 1.22 2008/02/07 13:22:51 james
53 * *** empty log message ***
55 * Revision 1.21 2008/02/07 12:21:16 james
56 * *** empty log message ***
58 * Revision 1.20 2008/02/07 12:16:04 james
59 * *** empty log message ***
61 * Revision 1.19 2008/02/07 11:27:02 james
62 * *** empty log message ***
64 * Revision 1.18 2008/02/07 01:59:25 james
65 * *** empty log message ***
67 * Revision 1.17 2008/02/07 01:58:28 james
68 * *** empty log message ***
70 * Revision 1.16 2008/02/07 01:57:46 james
71 * *** empty log message ***
73 * Revision 1.15 2008/02/07 00:43:27 james
74 * *** empty log message ***
76 * Revision 1.14 2008/02/07 00:40:23 james
77 * *** empty log message ***
79 * Revision 1.13 2008/02/07 00:39:59 james
80 * *** empty log message ***
82 * Revision 1.12 2008/02/07 00:39:13 james
83 * *** empty log message ***
85 * Revision 1.11 2008/02/06 20:26:58 james
86 * *** empty log message ***
88 * Revision 1.10 2008/02/06 17:53:28 james
89 * *** empty log message ***
91 * Revision 1.9 2008/02/06 15:53:22 james
92 * *** empty log message ***
94 * Revision 1.8 2008/02/06 11:49:47 james
95 * *** empty log message ***
97 * Revision 1.7 2008/02/06 11:30:37 james
98 * *** empty log message ***
100 * Revision 1.6 2008/02/05 01:11:46 james
101 * *** empty log message ***
103 * Revision 1.5 2008/02/04 20:23:55 james
104 * *** empty log message ***
106 * Revision 1.4 2008/02/04 05:45:55 james
109 * Revision 1.3 2008/02/04 02:05:06 james
110 * *** empty log message ***
112 * Revision 1.2 2008/02/04 01:32:39 james
113 * *** empty log message ***
115 * Revision 1.1 2008/02/03 23:36:41 james
116 * *** empty log message ***
127 :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100:
129 vt100|vt100-am|dec vt100 (w/advanced video):\
131 :co#80:it#8:li#24:vt#3:\
132 :DO=\E[%dB:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:\
134 :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\
135 :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
136 :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\
137 :eA=\E(B\E)0:ho=\E[H:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\
138 :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\
139 :me=\E[m\017:mr=\E[7m:nd=\E[C:rc=\E8:\
140 :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:sc=\E7:se=\E[m:\
141 :sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:up=\E[A:\
142 :us=\E[4m:tc=vt100+fnkeys:
144 vt100+fnkeys|dec vt100 numeric keypad:\
145 :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\
148 vt100+pfkeys|dec vt100 numeric keypad:\
149 :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad:
151 vt100+keypad|dec vt100 numeric keypad no fkeys:\
152 :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:
157 so the parser needs to be able to at least do
219 ansi|ansi/pc-term compatible with color:\
220 :u6=\E[%i%d;%dR:u7=\E[6n:u9=\E[c:tc=ecma+color:\
221 :tc=klone+sgr:tc=ansi-m:
222 ansi-m|ansi-mono|ANSI X3.64-1979 terminal with ANSI.SYS compatible attributes:\
224 :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\
225 :LE=\E[%dD:RI=\E[%dC:SF=\E[%dS:SR=\E[%dT:UP=\E[%dA:\
226 :cb=\E[1K:ch=\E[%i%dG:ct=\E[2g:cv=\E[%i%dd:ec=\E[%dX:ei=:\
227 :im=:kB=\E[Z:kI=\E[L:kb=^H:kd=\E[B:kl=\E[D:kr=\E[C:ku=\E[A:\
228 :nw=\r\E[S:pf=\E[4i:po=\E[5i:s0=\E(B:s1=\E)B:s2=\E*B:\
229 :s3=\E+B:ta=\E[I:tc=pcansi-m:
230 pcansi-m|pcansi-mono|ibm-pc terminal programs claiming to be ansi (mono mode):\
233 :al=\E[L:bl=^G:bt=\E[Z:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
234 :cm=\E[%i%d;%dH:cr=^M:ct=\E[2g:dc=\E[P:dl=\E[M:do=\E[B:\
235 :ho=\E[H:kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:\
236 :le=\E[D:nd=\E[C:sf=^J:st=\EH:ta=^I:up=\E[A:\
238 klone+sgr-dumb|attribute control for ansi.sys displays (no ESC [ 11 m):\
239 :as=\E[12m:mb=\E[5m:md=\E[1m:me=\E[0;10m:mk=\E[8m:\
240 :mr=\E[7m:se=\E[m:so=\E[7m:ue=\E[m:us=\E[4m:tc=klone+acs:
241 klone+acs|alternate character set for ansi.sys displays:\
242 :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:\
243 :ae=\E[10m:as=\E[11m:
244 ecma+color|color control for ECMA-48-compatible terminals:\
246 :AB=\E[4%dm:AF=\E[3%dm:op=\E[39;49m:
249 Ignoreing ones in the VT102 spec
293 if ((c >= 'a') && (c <= 'z'))
295 if ((c >= 'A') && (c <= 'Z'))
326 in_margins (VT102 * v, CRT_Pos p)
328 if (v->pos.x < v->top_margin.x)
330 if (v->pos.y < v->top_margin.y)
333 if (v->pos.x > v->bottom_margin.x)
335 if (v->pos.y > v->bottom_margin.y)
342 vt102_log_line (Context * c, int line)
344 CRT_Pos e = { VT102_COLS - 1, line };
345 CRT_Pos p = { 0, line };
346 char logbuf[VT102_COLS + 1];
352 for (; e.x > 0; --e.x)
354 if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
358 for (; p.x <= e.x; ++p.x)
360 int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr;
369 c->l->log (c->l, logbuf);
372 /*Called for every upward scroll with same args*/
374 vt102_history (Context * c, CRT_Pos t, CRT_Pos b)
376 /*Only log if it scrolls off the top*/
381 history_add (c->h, &(c->v->crt.screen[CRT_ADDR_POS (&t)]));
385 vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br)
400 vt102_cursor_normalize (VT102 * v)
402 CRT_Pos *top, *bottom;
404 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
406 vt102_clip_cursor (v, v->top_margin, v->bottom_margin);
410 vt102_clip_cursor (v, v->screen_start, v->screen_end);
416 vt102_cursor_carriage_return (VT102 * v)
418 /*FISH*/ v->pos.x = v->top_margin.x;
423 vt102_cursor_advance_line (Context * c)
426 int couldscroll = in_margins (v, v->pos);
428 /*have wraped off end of last line in scrolling region */
429 /* (|| not necessary, but shuts compiler up */
430 if (((v->pos.y == v->bottom_margin.y) || (v->pos.y == v->screen_end.y)) &&
433 vt102_log_line (c, v->pos.y);
435 vt102_history (c, v->top_margin, v->bottom_margin);
437 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, v->color);
441 if (v->pos.y != v->screen_end.y)
448 vt102_do_pending_wrap (Context * c)
451 int couldscroll = in_margins (v, v->pos);
452 int autowrap = v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP];
454 if (!v->pending_wrap)
458 fprintf (stderr, "ca: (%d,%d) autowrap %d couldscroll %d\n", v->pos.x,
459 v->pos.y, autowrap, couldscroll);
462 /*End of line but no autowrap, nothing to do*/
466 /*End of screen and not allowed to scroll, nothing to do*/
467 if ((v->pos.y == v->screen_end.y) && (!couldscroll))
472 v->pos.x = v->top_margin.x;
479 vt102_cursor_advance_line (c);
483 vt102_cursor_advance (Context * c)
487 if (v->pos.x < v->bottom_margin.x)
495 if (!c->v->xn_glitch)
496 vt102_do_pending_wrap (c);
502 vt102_cursor_retard (VT102 * v)
504 if (v->pos.x != v->top_margin.x)
511 vt102_reset_tabs (VT102 * v)
515 memset (v->tabs, 0, sizeof (v->tabs));
517 for (i = 0; i < VT102_COLS; i += 8)
523 vt102_cursor_advance_tab (VT102 * v)
525 if (v->pos.x == v->bottom_margin.x)
527 while (v->pos.x < v->bottom_margin.x)
530 if (v->tabs[v->pos.x])
537 vt102_cursor_retard_tab (VT102 * v)
539 if (v->pos.x == v->top_margin.x)
541 while (v->pos.x > v->top_margin.x)
544 if (v->tabs[v->pos.x])
550 vt102_cursor_home (VT102 * v)
552 v->pos = v->top_margin;
553 vt102_cursor_normalize (v);
558 vt102_cursor_absolute (VT102 * v, int x, int y)
560 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
562 v->pos.x = x + v->top_margin.x;
563 v->pos.y = y + v->top_margin.x;
570 vt102_cursor_normalize (v);
574 vt102_cursor_relative (VT102 * v, int x, int y)
578 vt102_cursor_normalize (v);
585 vt102_delete_from_line (VT102 * v, CRT_Pos p)
587 int n = v->bottom_margin.x - p.x;
595 memmove (&v->crt.screen[CRT_ADDR_POS (&p)],
596 &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n);
599 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
600 /*But not attr due to vt102 bug*/
604 vt102_insert_into_line (VT102 * v, CRT_Pos p)
606 int n = v->bottom_margin.x - p.x;
614 memmove (&v->crt.screen[CRT_ADDR_POS (&p) + 1],
615 &v->crt.screen[CRT_ADDR_POS (&p)], sizeof (CRT_CA) * n);
618 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
619 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].attr = CRT_ATTR_NORMAL;
620 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].color = CRT_COLOR_NORMAL;
626 vt102_change_mode (VT102 * v, int private, char *ns, int set)
642 if (m >= VT102_NMODES)
647 v->private_modes[m] = set;
650 case VT102_PRIVATE_MODE_CURSOR_MODE:
651 if (v->application_keypad_mode)
652 v->private_modes[m] = 0;
654 fprintf (stderr, "APPLICATION CURSOR MODE %d wanted %d\n",
655 v->private_modes[m], set);
658 case VT102_PRIVATE_MODE_ORIGIN_MODE:
659 vt102_cursor_home (v);
668 fprintf (stderr, "mode set=%d private=%d num=%d\n", set, private, m);
673 vt102_parse_mode_string (VT102 * v, char *buf, int len)
676 char last = buf[len - 1];
680 memset (num, 0, sizeof (num));
681 o = sizeof (num) - 1;
699 vt102_change_mode (v, private, &num[o], last == 'h');
700 memset (num, 0, sizeof (num));
701 o = sizeof (num) - 1;
716 vt102_change_mode (v, private, &num[o], last == 'h');
722 vt102_change_attr (VT102 * v, char *na)
739 v->attr = CRT_ATTR_NORMAL;
740 v->color = CRT_COLOR_NORMAL;
743 v->attr |= CRT_ATTR_BOLD;
747 v->attr &= ~CRT_ATTR_BOLD;
750 v->attr |= CRT_ATTR_UNDERLINE;
753 v->attr &= ~CRT_ATTR_UNDERLINE;
756 v->attr |= CRT_ATTR_BLINK;
759 v->attr &= ~CRT_ATTR_BLINK;
762 v->attr |= CRT_ATTR_REVERSE;
765 v->attr &= ~CRT_ATTR_REVERSE;
775 v->color &= ~CRT_COLOR_FG_MASK;
776 v->color |= ((a - 30) << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
786 v->color &= ~CRT_COLOR_FG_MASK;
789 90) | CRT_COLOR_INTENSITY) << CRT_COLOR_FG_SHIFT) &
794 v->color &= ~CRT_COLOR_FG_MASK;
796 (CRT_FGCOLOR_NORMAL << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
806 v->color &= ~CRT_COLOR_BG_MASK;
807 v->color |= ((a - 40) << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
817 v->color &= ~CRT_COLOR_BG_MASK;
820 100) | CRT_COLOR_INTENSITY) << CRT_COLOR_BG_SHIFT) &
825 v->color &= ~CRT_COLOR_BG_MASK;
827 (CRT_BGCOLOR_NORMAL << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
833 fprintf (stderr, "unhandled SGR %d\n", a);
841 vt102_parse_attr_string (VT102 * v, char *buf, int len)
844 char last = buf[len - 1];
848 memset (num, 0, sizeof (num));
849 o = sizeof (num) - 1;
860 vt102_change_attr (v, &num[o]);
861 memset (num, 0, sizeof (num));
862 o = sizeof (num) - 1;
876 vt102_change_attr (v, &num[o]);
880 vt102_save_state (VT102 * v)
882 v->saved.pos = v->pos;
883 v->saved.attr = v->attr;
884 v->saved.color = v->color;
885 v->saved.origin_mode = v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE];
889 vt102_restore_state (VT102 * v)
891 v->pos = v->saved.pos;
892 v->attr = v->saved.attr;
893 v->color = v->saved.color;
894 v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE] = v->saved.origin_mode;
895 vt102_cursor_normalize (v);
900 vt102_regular_char (Context * c, VT102 * v, int ch)
903 vt102_do_pending_wrap (c);
905 if (v->modes[VT102_MODE_INSERT])
906 vt102_insert_into_line (v, v->pos);
908 v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = ch;
909 v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
910 v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color;
911 vt102_cursor_advance (c);
913 v->last_reg_char = ch;
917 vt102_scs (Context * c, int g, int s)
919 /*Ignoring charsets*/
923 vt102_parse_esc (Context * c, int ch)
929 if (v->pos.y == v->bottom_margin.y)
931 vt102_log_line (c, v->pos.y);
932 vt102_history (c, v->top_margin, v->bottom_margin);
933 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,
938 vt102_cursor_relative (v, 0, 1);
945 if (v->pos.y == v->top_margin.y)
947 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,
952 vt102_cursor_relative (v, 0, -1);
956 vt102_save_state (v);
959 vt102_restore_state (v);
962 v->application_keypad_mode = 1;
965 v->application_keypad_mode = 0;
968 v->parser.ignore_until_bell++;
971 log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__,
972 __LINE__, ch, safe_ch (ch));
978 vt102_parse_csi (Context * c, char *buf, int len)
1010 vt102_insert_into_line (v, v->pos);
1013 vt102_cursor_relative (v, 0, -narg);
1017 vt102_cursor_relative (v, 0, narg);
1021 vt102_cursor_relative (v, narg, 0);
1024 vt102_cursor_relative (v, -narg, 0);
1027 vt102_cursor_relative (v, 0, narg);
1028 vt102_cursor_carriage_return (v);
1031 vt102_cursor_relative (v, 0, -narg);
1032 vt102_cursor_carriage_return (v);
1035 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1044 ptr = index (arg, ';');
1046 x = atoi (ptr + 1) - 1;
1050 vt102_cursor_absolute (v, x, y);
1055 vt102_cursor_advance_tab (c->v);
1059 narg = 0; /*Different default */
1063 crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color);
1066 crt_erase (&v->crt, v->screen_start, v->pos, 1, v->color);
1069 crt_erase (&v->crt, v->screen_start, v->screen_end, 1,
1076 CRT_Pos ls = { 0, v->pos.y };
1077 CRT_Pos le = { VT102_COLS - 1, v->pos.y };
1079 narg = 0; /*Different default */
1084 crt_erase (&v->crt, v->pos, le, 1, v->color);
1087 crt_erase (&v->crt, ls, v->pos, 1, v->color);
1090 crt_erase (&v->crt, ls, le, 1, v->color);
1097 if ((v->pos.y >= v->top_margin.y)
1098 && (v->pos.y <= v->bottom_margin.y))
1101 crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1,
1107 if ((v->pos.y >= v->top_margin.y)
1108 && (v->pos.y <= v->bottom_margin.y))
1112 vt102_history (c, v->pos, v->bottom_margin);
1113 crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1,
1120 vt102_delete_from_line (v, v->pos);
1123 //FIXME: cursor position report - does anything use that?
1128 vt102_history (c, v->top_margin, v->bottom_margin);
1129 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,
1135 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,
1140 CRT_Pos end = v->pos;
1145 if (end.x > v->bottom_margin.x)
1146 end.x = v->bottom_margin.x;
1148 crt_erase (&v->crt, v->pos, end, 1, v->color);
1153 vt102_cursor_retard_tab (c->v);
1156 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1160 vt102_regular_char (c, v, v->last_reg_char);
1166 vt102_cursor_absolute (v, v->pos.x, narg - 1);
1170 narg = 0; /*Different default */
1175 v->tabs[v->pos.x] = 0;
1177 case 2: //FIXME: - LA120 says current line only WTF?
1179 memset (v->tabs, 0, sizeof (v->tabs));
1184 case 'i': //4,5 Turn printer on and off WTF?
1189 vt102_parse_mode_string (v, &buf[1], len - 1);
1194 vt102_parse_attr_string (v, &buf[1], len - 1);
1196 case 'n': // 6 request cursor position
1200 v->top_margin = v->screen_start;
1201 v->bottom_margin = v->screen_end;
1203 if ((len > 2) && (ptr = index (arg, ';')))
1206 v->top_margin.y = narg - 1;
1207 v->bottom_margin.y = atoi (ptr) - 1;
1210 if (v->top_margin.y < v->screen_start.y)
1211 v->top_margin.y = v->screen_start.y;
1212 if (v->top_margin.y > v->screen_end.y)
1213 v->top_margin.y = v->screen_end.y;
1214 if (v->bottom_margin.y < v->screen_start.y)
1215 v->bottom_margin.y = v->screen_start.y;
1216 if (v->bottom_margin.y > v->screen_end.y)
1217 v->bottom_margin.y = v->screen_end.y;
1219 vt102_cursor_home (v);
1222 v->saved.pos = v->pos;
1225 v->pos = v->saved.pos;
1226 vt102_cursor_normalize (v);
1227 v->pending_wrap = 0;
1231 log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__, __LINE__,
1238 log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__, __LINE__,
1248 vt102_status_line (VT102 * v, char *str)
1251 CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
1255 ca->attr = CRT_ATTR_REVERSE;
1256 ca->color = CRT_COLOR_NORMAL;
1267 vt102_parser_reset (VT102_parser * p)
1271 p->ignore_until_bell = 0;
1276 vt102_reset_state (VT102 * v)
1278 vt102_parser_reset (&v->parser);
1280 v->attr = CRT_ATTR_NORMAL;
1281 v->color = CRT_COLOR_NORMAL;
1283 v->application_keypad_mode = 0;
1285 v->top_margin = v->screen_start;
1286 v->bottom_margin = v->screen_end;
1288 memset (v->modes, 0, VT102_NMODES);
1289 memset (v->private_modes, 0, VT102_NMODES);
1291 v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP] = 1;
1292 v->private_modes[VT102_PRIVATE_MODE_AUTO_REPEAT] = 1;
1293 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] = 1;
1294 v->modes[VT102_MODE_LOCAL_ECHO_OFF] = 1;
1296 vt102_reset_tabs (v);
1301 vt102_parse_char (Context * c, int ch)
1304 VT102_parser *p = &v->parser;
1307 log_f (c->l, "char %3d %c pc %d %d %d %2d %2d %d", ch, safe_ch (ch),
1308 p->ignore_until_bell, p->in_escape, p->in_csi, v->pos.x, v->pos.y,
1312 /* Turn anything non-ascii into '?' */
1314 if ((ch != SYM_CHAR_RESET) && (ch != 0xb9) && (ch > 127))
1321 if (ch == SYM_CHAR_RESET)
1323 vt102_reset_state (v);
1325 if (p->ignore_until_bell)
1328 p->ignore_until_bell = 0;
1332 p->csi_buf[p->csi_ptr++] = ch;
1333 if (csi_ender (ch) || (p->csi_ptr == VT102_CSI_LEN))
1335 if (csi_starter (p->csi_buf[0]))
1337 vt102_parse_csi (c, p->csi_buf, p->csi_ptr);
1339 else if (scs_starter (p->csi_buf[0]))
1341 vt102_scs (c, p->csi_buf[0], p->csi_buf[1]);
1346 "<%s:%d no dispatcher for sequence starting \\033 \\%03o (ESC %c)>",
1347 __FILE__, __LINE__, p->csi_buf[0],
1348 safe_ch (p->csi_buf[0]));
1353 else if (p->in_escape)
1355 if (csi_starter (ch) || scs_starter (ch))
1358 p->csi_buf[p->csi_ptr++] = ch;
1365 vt102_parse_esc (c, ch);
1368 else if (ch == 0x9b) /*One byte CSI */
1371 p->csi_buf[p->csi_ptr++] = '[';
1387 c->t->xmit (c->t, "vt102", 5);
1393 vt102_cursor_retard (c->v);
1396 vt102_cursor_advance_tab (c->v);
1401 vt102_cursor_advance_line (c);
1402 if (!v->modes[VT102_MODE_NEWLINE_MODE])
1405 vt102_cursor_carriage_return (v);
1409 /*Ignoring charsets */
1413 /*Ignoring charsets */
1436 /*regular character */ default:
1437 vt102_regular_char (c, v, ch);
1441 v->crt.pos = v->pos;
1442 v->crt.hide_cursor =
1443 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0 : 1;
1445 if (v->current_line.y != v->pos.y)
1447 vt102_log_line (c, v->current_line.y);
1448 v->current_line = v->pos;
1452 cmd_show_status (c->d, c);
1456 vt102_send (Context * c, uint8_t key)
1464 fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' ');
1466 if ((key > 31) && (key < 127))
1468 c->t->xmit (c->t, &key, 1);
1487 c->t->xmit (c->t, &key, 1);
1490 c->t->xmit (c->t, &key, 1);
1491 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1494 c->t->xmit (c->t, &ch, 1);
1510 c->t->xmit (c->t, &key, 1);
1518 c->t->xmit (c->t, &key, 1);
1529 if (c->v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE])
1531 uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) };
1532 c->t->xmit (c->t, &buf, sizeof (buf));
1536 uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) };
1537 c->t->xmit (c->t, &buf, sizeof (buf));
1555 if (c->v->application_keypad_mode)
1557 uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) };
1558 c->t->xmit (c->t, &buf, sizeof (buf));
1562 static char kpoff[KEY_NUM] = {
1581 c->t->xmit (c->t, &kpoff[key], 1);
1585 if (c->v->application_keypad_mode)
1587 uint8_t buf[] = { 033, 'O', 'M' };
1588 c->t->xmit (c->t, &buf, sizeof (buf));
1593 c->t->xmit (c->t, &ch, 1);
1594 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1597 c->t->xmit (c->t, &ch, 1);
1606 uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) };
1607 c->t->xmit (c->t, &buf, sizeof (buf));
1615 uint8_t buf[] = { 033, '[', '0' + (key - KEY_180), '~' };
1616 c->t->xmit (c->t, &buf, sizeof (buf));
1624 vt102_reset (VT102 * v)
1626 VT102_parser *p = &v->parser;
1630 v->current_line = v->pos;
1631 v->pending_wrap = 0;
1633 v->screen_start.x = 0;
1634 v->screen_start.y = 0;
1635 v->screen_end.x = VT102_COLS - 1;
1636 v->screen_end.y = VT102_ROWS - 1;
1638 vt102_cursor_home (v);
1639 vt102_status_line (v, "");
1641 vt102_reset_tabs (v);
1642 v->current_line = v->pos;
1644 vt102_parser_reset (p);
1645 vt102_reset_state (v);
1647 vt102_save_state (v);
1649 v->last_reg_char = ' ';
1657 v = (VT102 *) malloc (sizeof (VT102));
1668 vt102_set_ansi (VT102 * v, int ansi)
1670 v->xn_glitch = ansi ? 0 : 1;
1674 vt102_free (VT102 * v)