+ fprintf (stderr, "ESC 0%o(%c)\n", c, c);
+}
+
+void
+vt102_parse_csi (VT102 * v, char *buf, int len)
+{
+ char last;
+ char *ptr;
+ char *arg = buf + 1;
+ int narg;
+
+ buf[len] = 0;
+
+ last = buf[len - 1];
+#if 0
+ buf[len - 1] = 0;
+#endif
+
+ if (len>2)
+ {
+ narg = atoi (arg);
+ }
+ else
+ {
+ narg = 1;
+ }
+
+ switch (buf[0])
+ {
+ case '[':
+ switch (last)
+ {
+ case 'A':
+ vt102_cursor_motion (v, 0, -narg, 0);
+ break;
+ case 'B':
+ vt102_cursor_motion (v, 0, narg, 0);
+ break;
+ case 'C':
+ vt102_cursor_motion (v, narg, 0, 0);
+ break;
+ case 'D':
+ vt102_cursor_motion (v, -narg, 0, 0);
+ break;
+ case 'H':
+ v->pos.y = narg - 1;
+
+ ptr = index (arg, ';');
+ if (ptr)
+ v->pos.x = atoi (ptr + 1) - 1;
+ else
+ v->pos.x = 0;
+
+ vt102_cursor_normalize (v, 0, 0);
+ break;
+ case 'J':
+ fprintf(stderr,"OCTOPUS %d\n",narg);
+ switch (narg)
+ {
+ case 1:
+ crt_erase (&v->crt, v->pos, v->screen_end, 1);
+ break;
+ case 2:
+ crt_erase (&v->crt, v->screen_start, v->screen_end, 1);
+ break;
+ }
+ break;
+ case 'K':
+ {
+ CRT_Pos ls = { 0, v->pos.y };
+ CRT_Pos le = { VT102_COLS - 1, v->pos.y };
+ if (len==2)
+ narg = 0; /*Different default */
+
+ switch (narg)
+ {
+ case 0:
+ fprintf(stderr,"FISH %d %d -> %d %d\n",
+ v->pos.x,v->pos.y,
+ le.x,le.y);
+ crt_erase (&v->crt, v->pos, le, 1);
+ break;
+ case 1:
+ fprintf(stderr,"SOUP %d %d -> %d %d\n",
+ ls.x,ls.y,
+ v->pos.x,v->pos.y);
+ crt_erase (&v->crt, ls, v->pos, 1);
+ break;
+ case 2:
+ fprintf(stderr,"TREE %d %d -> %d %d\n",
+ ls.x,ls.y,
+ le.x,le.y);
+ crt_erase (&v->crt, ls, le, 1);
+ break;
+ }
+ }
+ break;
+
+ case 'P':
+ while (narg--)
+ vt102_delete_from_line (v, v->pos);
+ break;
+ case 'L':
+ if ((v->pos.y >= v->top_margin.y)
+ && (v->pos.y <= v->bottom_margin.y))
+ {
+ while (narg--)
+ crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1);
+ }
+ break;
+
+ case 'M':
+ if ((v->pos.y >= v->top_margin.y)
+ && (v->pos.y <= v->bottom_margin.y))
+ {
+ while (narg--)
+ crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 0);
+ }
+ break;
+
+ default:
+ fprintf (stderr, "A: CSI %s buf[0]=%c\n", buf,buf[0]);
+ }
+ break;
+ default:
+ fprintf (stderr, "B: CSI %s buf[0]=%c\n", buf,buf[0]);
+ }
+
+
+