4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.8 2008/02/06 11:49:47 james
14 * *** empty log message ***
16 * Revision 1.7 2008/02/06 11:30:37 james
17 * *** empty log message ***
19 * Revision 1.6 2008/02/05 01:11:46 james
20 * *** empty log message ***
22 * Revision 1.5 2008/02/04 20:23:55 james
23 * *** empty log message ***
25 * Revision 1.4 2008/02/04 05:45:55 james
28 * Revision 1.3 2008/02/04 02:05:06 james
29 * *** empty log message ***
31 * Revision 1.2 2008/02/04 01:32:39 james
32 * *** empty log message ***
34 * Revision 1.1 2008/02/03 23:36:41 james
35 * *** empty log message ***
44 :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100:
46 vt100|vt100-am|dec vt100 (w/advanced video):\
48 :co#80:it#8:li#24:vt#3:\
49 :DO=\E[%dB:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:\
51 :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\
52 :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
53 :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\
54 :eA=\E(B\E)0:ho=\E[H:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\
55 :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\
56 :me=\E[m\017:mr=\E[7m:nd=\E[C:rc=\E8:\
57 :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:sc=\E7:se=\E[m:\
58 :sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:up=\E[A:\
59 :us=\E[4m:tc=vt100+fnkeys:
61 vt100+fnkeys|dec vt100 numeric keypad:\
62 :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\
65 vt100+pfkeys|dec vt100 numeric keypad:\
66 :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad:
68 vt100+keypad|dec vt100 numeric keypad no fkeys:\
69 :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:
74 so the parser needs to be able to at least do
131 if ((c >= 'a') && (c <= 'z'))
133 if ((c >= 'A') && (c <= 'Z'))
153 vt102_cursor_normalize (VT102 * v, int do_wrapscroll, int use_margins)
155 int wrap = do_wrapscroll ? 1 : 0;
156 int scroll = do_wrapscroll ? 1 : 0;
157 CRT_Pos *top, *bottom;
161 top = &v->top_margin;
162 bottom = &v->bottom_margin;
166 top = &v->screen_start;
167 bottom = &v->screen_end;
170 if (v->pos.x < top->x) /*don't wrap backwards */
173 if (v->pos.x > bottom->x)
182 v->pos.x = bottom->x;
186 if (v->pos.y < top->y)
189 if (v->pos.y > bottom->y)
192 crt_scroll_up (&v->crt, *top, *bottom, 1);
193 v->pos.y = bottom->y;
199 vt102_cursor_motion (VT102 * v, int x, int y, int wrapscroll)
205 vt102_cursor_normalize (v, wrapscroll, 1);
212 vt102_cursor_normalize (v, wrapscroll, 1);
219 vt102_cursor_normalize (v, wrapscroll, 1);
226 vt102_cursor_normalize (v, wrapscroll, 1);
231 vt102_delete_from_line (VT102 * v, CRT_Pos p)
233 int n = v->bottom_margin.x - p.x;
241 memmove (&v->crt.screen[CRT_ADDR_POS (&p)],
242 &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n);
245 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
246 /*But not attr due to vt102 bug*/
250 vt102_insert_into_line (VT102 * v, CRT_Pos p)
252 int n = v->bottom_margin.x - p.x;
260 memmove (&v->crt.screen[CRT_ADDR_POS (&p) + 1],
261 &v->crt.screen[CRT_ADDR_POS (&p) ], sizeof (CRT_CA) * n);
264 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
265 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].attr = CRT_ATTR_NORMAL;
269 vt102_change_mode (VT102 * v, int private, char *ns, int set)
285 if (m >= VT102_NMODES)
289 v->private_modes[m] = set;
293 fprintf (stderr, "mode set=%d private=%d num=%d\n", set, private, m);
297 vt102_parse_mode_string (VT102 * v, char *buf, int len)
300 char last = buf[len - 1];
304 memset (num, 0, sizeof (num));
305 o = sizeof (num) - 1;
323 vt102_change_mode (v, private, &num[o], last == 'h');
324 memset (num, 0, sizeof (num));
325 o = sizeof (num) - 1;
340 vt102_change_mode (v, private, &num[o], last == 'h');
345 vt102_parse_esc (VT102 * v, int c)
347 fprintf (stderr, "ESC 0%o(%c)\n", c, c);
351 vt102_parse_csi (VT102 * v, char *buf, int len)
380 vt102_cursor_motion (v, 0, -narg, 0);
383 vt102_cursor_motion (v, 0, narg, 0);
386 vt102_cursor_motion (v, narg, 0, 0);
389 vt102_cursor_motion (v, -narg, 0, 0);
394 ptr = index (arg, ';');
396 v->pos.x = atoi (ptr + 1) - 1;
400 vt102_cursor_normalize (v, 0, 0);
403 fprintf (stderr, "OCTOPUS %d\n", narg);
407 crt_erase (&v->crt, v->pos, v->screen_end, 1);
410 crt_erase (&v->crt, v->screen_start, v->screen_end, 1);
416 CRT_Pos ls = { 0, v->pos.y };
417 CRT_Pos le = { VT102_COLS - 1, v->pos.y };
419 narg = 0; /*Different default */
424 fprintf (stderr, "FISH %d %d -> %d %d\n",
425 v->pos.x, v->pos.y, le.x, le.y);
426 crt_erase (&v->crt, v->pos, le, 1);
429 fprintf (stderr, "SOUP %d %d -> %d %d\n",
430 ls.x, ls.y, v->pos.x, v->pos.y);
431 crt_erase (&v->crt, ls, v->pos, 1);
434 fprintf (stderr, "TREE %d %d -> %d %d\n",
435 ls.x, ls.y, le.x, le.y);
436 crt_erase (&v->crt, ls, le, 1);
444 vt102_delete_from_line (v, v->pos);
447 if ((v->pos.y >= v->top_margin.y)
448 && (v->pos.y <= v->bottom_margin.y))
451 crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1);
456 if ((v->pos.y >= v->top_margin.y)
457 && (v->pos.y <= v->bottom_margin.y))
460 crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 0);
465 fprintf (stderr, "C: CSI %s buf[0]=%c\n", buf, buf[0]);
470 fprintf (stderr, "D: CSI %s buf[0]=%c\n", buf, buf[0]);
471 vt102_parse_mode_string (v, &buf[1], len - 1);
475 //horror of horrors parsing the ;
478 v->top_margin = v->screen_start;
479 v->bottom_margin = v->screen_end;
481 if ((len > 2) && (ptr = index (arg, ';')))
484 v->top_margin.y = narg - 1;
485 v->bottom_margin.y = atoi (ptr) - 1;
488 if (v->top_margin.y < v->screen_start.y)
489 v->top_margin.y = v->screen_start.y;
490 if (v->top_margin.y > v->screen_end.y)
491 v->top_margin.y = v->screen_end.y;
492 if (v->bottom_margin.y < v->screen_start.y)
493 v->bottom_margin.y = v->screen_start.y;
494 if (v->bottom_margin.y > v->screen_end.y)
495 v->bottom_margin.y = v->screen_end.y;
497 fprintf (stderr, "D: %d %d\n", v->top_margin.y, v->bottom_margin.y);
499 v->pos = v->top_margin;
503 fprintf (stderr, "A: CSI %s buf[0]=%c\n", buf, buf[0]);
507 fprintf (stderr, "B: CSI %s buf[0]=%c\n", buf, buf[0]);
515 vt102_status_line (VT102 * v, char *str)
518 CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
522 ca->attr = CRT_ATTR_REVERSE;
533 vt102_parse_char (VT102 * v, int c)
535 VT102_parser *p = &v->parser;
538 fprintf (stderr, "%c pc %d %d %d %d %d\n", (c > 31) ? 32 : c, c,
539 p->in_csi, p->in_escape, v->pos.x, v->pos.y);
543 p->csi_buf[p->csi_ptr++] = c;
544 if (csi_ender (c) || (p->csi_ptr == VT102_CSI_LEN))
546 vt102_parse_csi (v, p->csi_buf, p->csi_ptr);
550 else if (p->in_escape)
555 p->csi_buf[p->csi_ptr++] = c;
562 vt102_parse_esc (v, c);
580 vt102_cursor_motion (v, -1, 0, 1);
585 vt102_cursor_normalize (v, 1, 1);
590 vt102_cursor_motion (v, 0, 1, 1);
591 if (v->modes[VT102_MODE_NEWLINE_MODE])
592 v->pos.x = v->top_margin.x;
595 v->pos.x = v->top_margin.x;
620 /*regular character */ default:
622 if (v->modes[VT102_MODE_INSERT])
623 vt102_insert_into_line(v,v->pos);
625 v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = c;
626 v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
627 vt102_cursor_motion (v, 1, 0, 1);
633 vt102_status_line (v, "VT102 foo bar baz I'm the urban spaceman baby");
637 vt102_parser_reset (VT102_parser * p)
645 vt102_reset (VT102 * v)
647 VT102_parser *p = &v->parser;
649 vt102_parser_reset (p);
653 v->screen_start.x = 0;
654 v->screen_start.y = 0;
655 v->screen_end.x = VT102_COLS - 1;
656 v->screen_end.y = VT102_ROWS - 1;
658 v->top_margin = v->screen_start;
659 v->bottom_margin = v->screen_end;
661 v->pos = v->screen_start;
663 memset(v->modes,0,VT102_NMODES);
664 memset(v->private_modes,0,VT102_NMODES);
666 v->modes[VT102_PRIVATE_MODE_AUTO_WRAP]=1;
667 v->modes[VT102_PRIVATE_MODE_AUTO_REPEAT]=1;