4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.7 2008/02/06 11:30:37 james
14 * *** empty log message ***
16 * Revision 1.6 2008/02/05 01:11:46 james
17 * *** empty log message ***
19 * Revision 1.5 2008/02/04 20:23:55 james
20 * *** empty log message ***
22 * Revision 1.4 2008/02/04 05:45:55 james
25 * Revision 1.3 2008/02/04 02:05:06 james
26 * *** empty log message ***
28 * Revision 1.2 2008/02/04 01:32:39 james
29 * *** empty log message ***
31 * Revision 1.1 2008/02/03 23:36:41 james
32 * *** empty log message ***
41 :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100:
43 vt100|vt100-am|dec vt100 (w/advanced video):\
45 :co#80:it#8:li#24:vt#3:\
46 :DO=\E[%dB:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:\
48 :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\
49 :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
50 :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\
51 :eA=\E(B\E)0:ho=\E[H:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\
52 :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\
53 :me=\E[m\017:mr=\E[7m:nd=\E[C:rc=\E8:\
54 :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:sc=\E7:se=\E[m:\
55 :sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:up=\E[A:\
56 :us=\E[4m:tc=vt100+fnkeys:
58 vt100+fnkeys|dec vt100 numeric keypad:\
59 :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\
62 vt100+pfkeys|dec vt100 numeric keypad:\
63 :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad:
65 vt100+keypad|dec vt100 numeric keypad no fkeys:\
66 :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:
71 so the parser needs to be able to at least do
128 if ((c >= 'a') && (c <= 'z'))
130 if ((c >= 'A') && (c <= 'Z'))
150 vt102_cursor_normalize (VT102 * v, int do_wrapscroll, int use_margins)
152 int wrap = do_wrapscroll ? 1 : 0;
153 int scroll = do_wrapscroll ? 1 : 0;
154 CRT_Pos *top, *bottom;
158 top = &v->top_margin;
159 bottom = &v->bottom_margin;
163 top = &v->screen_start;
164 bottom = &v->screen_end;
167 if (v->pos.x < top->x) /*don't wrap backwards */
170 if (v->pos.x > bottom->x)
179 v->pos.x = bottom->x;
183 if (v->pos.y < top->y)
186 if (v->pos.y > bottom->y)
189 crt_scroll_up (&v->crt, *top, *bottom, 1);
190 v->pos.y = bottom->y;
196 vt102_cursor_motion (VT102 * v, int x, int y, int wrapscroll)
202 vt102_cursor_normalize (v, wrapscroll, 1);
209 vt102_cursor_normalize (v, wrapscroll, 1);
216 vt102_cursor_normalize (v, wrapscroll, 1);
223 vt102_cursor_normalize (v, wrapscroll, 1);
228 vt102_delete_from_line (VT102 * v, CRT_Pos p)
230 int n = v->bottom_margin.x - p.x;
238 memmove (&v->crt.screen[CRT_ADDR_POS (&p)],
239 &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n);
242 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
243 /*But not attr due to vt102 bug*/
247 vt102_change_mode (VT102 * v, int private, char *ns, int set)
263 if (m >= VT102_NMODES)
267 v->private_modes[m] = set;
271 fprintf (stderr, "mode set=%d private=%d num=%d\n", set, private, m);
275 vt102_parse_mode_string (VT102 * v, char *buf, int len)
278 char last = buf[len - 1];
282 memset (num, 0, sizeof (num));
283 o = sizeof (num) - 1;
301 vt102_change_mode (v, private, &num[o], last == 'h');
302 memset (num, 0, sizeof (num));
303 o = sizeof (num) - 1;
318 vt102_change_mode (v, private, &num[o], last == 'h');
323 vt102_parse_esc (VT102 * v, int c)
325 fprintf (stderr, "ESC 0%o(%c)\n", c, c);
329 vt102_parse_csi (VT102 * v, char *buf, int len)
358 vt102_cursor_motion (v, 0, -narg, 0);
361 vt102_cursor_motion (v, 0, narg, 0);
364 vt102_cursor_motion (v, narg, 0, 0);
367 vt102_cursor_motion (v, -narg, 0, 0);
372 ptr = index (arg, ';');
374 v->pos.x = atoi (ptr + 1) - 1;
378 vt102_cursor_normalize (v, 0, 0);
381 fprintf (stderr, "OCTOPUS %d\n", narg);
385 crt_erase (&v->crt, v->pos, v->screen_end, 1);
388 crt_erase (&v->crt, v->screen_start, v->screen_end, 1);
394 CRT_Pos ls = { 0, v->pos.y };
395 CRT_Pos le = { VT102_COLS - 1, v->pos.y };
397 narg = 0; /*Different default */
402 fprintf (stderr, "FISH %d %d -> %d %d\n",
403 v->pos.x, v->pos.y, le.x, le.y);
404 crt_erase (&v->crt, v->pos, le, 1);
407 fprintf (stderr, "SOUP %d %d -> %d %d\n",
408 ls.x, ls.y, v->pos.x, v->pos.y);
409 crt_erase (&v->crt, ls, v->pos, 1);
412 fprintf (stderr, "TREE %d %d -> %d %d\n",
413 ls.x, ls.y, le.x, le.y);
414 crt_erase (&v->crt, ls, le, 1);
422 vt102_delete_from_line (v, v->pos);
425 if ((v->pos.y >= v->top_margin.y)
426 && (v->pos.y <= v->bottom_margin.y))
429 crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1);
434 if ((v->pos.y >= v->top_margin.y)
435 && (v->pos.y <= v->bottom_margin.y))
438 crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 0);
443 fprintf (stderr, "C: CSI %s buf[0]=%c\n", buf, buf[0]);
448 fprintf (stderr, "D: CSI %s buf[0]=%c\n", buf, buf[0]);
449 vt102_parse_mode_string (v, &buf[1], len - 1);
453 //horror of horrors parsing the ;
456 v->top_margin = v->screen_start;
457 v->bottom_margin = v->screen_end;
459 if ((len > 2) && (ptr = index (arg, ';')))
462 v->top_margin.y = narg - 1;
463 v->bottom_margin.y = atoi (ptr) - 1;
466 if (v->top_margin.y < v->screen_start.y)
467 v->top_margin.y = v->screen_start.y;
468 if (v->top_margin.y > v->screen_end.y)
469 v->top_margin.y = v->screen_end.y;
470 if (v->bottom_margin.y < v->screen_start.y)
471 v->bottom_margin.y = v->screen_start.y;
472 if (v->bottom_margin.y > v->screen_end.y)
473 v->bottom_margin.y = v->screen_end.y;
475 fprintf (stderr, "D: %d %d\n", v->top_margin.y, v->bottom_margin.y);
477 v->pos = v->top_margin;
481 fprintf (stderr, "A: CSI %s buf[0]=%c\n", buf, buf[0]);
485 fprintf (stderr, "B: CSI %s buf[0]=%c\n", buf, buf[0]);
493 vt102_status_line (VT102 * v, char *str)
496 CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
500 ca->attr = CRT_ATTR_REVERSE;
511 vt102_parse_char (VT102 * v, int c)
513 VT102_parser *p = &v->parser;
516 fprintf (stderr, "%c pc %d %d %d %d %d\n", (c > 31) ? 32 : c, c,
517 p->in_csi, p->in_escape, v->pos.x, v->pos.y);
521 p->csi_buf[p->csi_ptr++] = c;
522 if (csi_ender (c) || (p->csi_ptr == VT102_CSI_LEN))
524 vt102_parse_csi (v, p->csi_buf, p->csi_ptr);
528 else if (p->in_escape)
533 p->csi_buf[p->csi_ptr++] = c;
540 vt102_parse_esc (v, c);
558 vt102_cursor_motion (v, -1, 0, 1);
563 vt102_cursor_normalize (v, 1, 1);
568 vt102_cursor_motion (v, 0, 1, 1);
571 v->pos.x = v->top_margin.x;
596 /*regular character */ default:
597 v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = c;
598 v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
599 vt102_cursor_motion (v, 1, 0, 1);
605 vt102_status_line (v, "VT102 foo bar baz I'm the urban spaceman baby");
609 vt102_parser_reset (VT102_parser * p)
617 vt102_reset (VT102 * v)
619 VT102_parser *p = &v->parser;
621 vt102_parser_reset (p);
625 v->screen_start.x = 0;
626 v->screen_start.y = 0;
627 v->screen_end.x = VT102_COLS - 1;
628 v->screen_end.y = VT102_ROWS - 1;
630 v->top_margin = v->screen_start;
631 v->bottom_margin = v->screen_end;
633 v->pos = v->screen_start;