#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
+#include <string.h>
+#include <errno.h>
static void
_text_clear(Termpty *ty, Termcell *cells, int count, int val, Eina_Bool inherit_att)
if (ty->cb.cancel_sel.func)
ty->cb.cancel_sel.func(ty->cb.cancel_sel.data);
}
- DBG("... scroll!!!!! [%i->%i]\n", start_y, end_y);
+ DBG("... scroll!!!!! [%i->%i]", start_y, end_y);
cells2 = &(ty->screen[end_y * ty->w]);
for (y = start_y; y < end_y; y++)
{
start_y = ty->state.scroll_y1;
end_y = ty->state.scroll_y2 - 1;
}
- DBG("... scroll rev!!!!! [%i->%i]\n", start_y, end_y);
+ DBG("... scroll rev!!!!! [%i->%i]", start_y, end_y);
cells = &(ty->screen[end_y * ty->w]);
for (y = end_y; y > start_y; y--)
{
static void
_term_write(Termpty *ty, const char *txt, int size)
{
- if (write(ty->fd, txt, size) < 0) perror("write");
+ if (write(ty->fd, txt, size) < 0) ERR("write: %s", strerror(errno));
}
#define _term_txt_write(ty, txt) _term_write(ty, txt, sizeof(txt) - 1)
if (cc == ce) return -2;
*b = 0;
b = buf;
- DBG(" CSI: '%c' args '%s'\n", *cc, buf);
+ DBG(" CSI: '%c' args '%s'", *cc, buf);
switch (*cc)
{
case 'm': // color set
case 38: // xterm 256 fg color ???
// now check if next arg is 5
arg = _csi_arg_get(&b);
- if (arg != 5) ERR("Failed xterm 256 color fg esc 5\n");
+ if (arg != 5) ERR("Failed xterm 256 color fg esc 5");
else
{
// then get next arg - should be color index 0-255
arg = _csi_arg_get(&b);
- if (!b) ERR("Failed xterm 256 color fg esc val\n");
+ if (!b) ERR("Failed xterm 256 color fg esc val");
else
{
ty->state.att.fg256 = 1;
case 48: // xterm 256 bg color ???
// now check if next arg is 5
arg = _csi_arg_get(&b);
- if (arg != 5) ERR("Failed xterm 256 color bg esc 5\n");
+ if (arg != 5) ERR("Failed xterm 256 color bg esc 5");
else
{
// then get next arg - should be color index 0-255
arg = _csi_arg_get(&b);
- if (!b) ERR("Failed xterm 256 color bg esc val\n");
+ if (!b) ERR("Failed xterm 256 color bg esc val");
else
{
ty->state.att.bg256 = 1;
case 98: // xterm 256 fg color ???
// now check if next arg is 5
arg = _csi_arg_get(&b);
- if (arg != 5) ERR("Failed xterm 256 color fg esc 5\n");
+ if (arg != 5) ERR("Failed xterm 256 color fg esc 5");
else
{
// then get next arg - should be color index 0-255
arg = _csi_arg_get(&b);
- if (!b) ERR("Failed xterm 256 color fg esc val\n");
+ if (!b) ERR("Failed xterm 256 color fg esc val");
else
{
ty->state.att.fg256 = 1;
case 108: // xterm 256 bg color ???
// now check if next arg is 5
arg = _csi_arg_get(&b);
- if (arg != 5) ERR("Failed xterm 256 color bg esc 5\n");
+ if (arg != 5) ERR("Failed xterm 256 color bg esc 5");
else
{
// then get next arg - should be color index 0-255
arg = _csi_arg_get(&b);
- if (!b) ERR("Failed xterm 256 color bg esc val\n");
+ if (!b) ERR("Failed xterm 256 color bg esc val");
else
{
ty->state.att.bg256 = 1;
ty->state.att.bgintense = 1;
break;
default: // not handled???
- ERR(" color cmd [%i] not handled\n", arg);
+ ERR(" color cmd [%i] not handled", arg);
break;
}
}
if ((arg >= CLR_END) && (arg <= CLR_ALL))
_clear_screen(ty, arg);
else
- ERR("invalid clr scr %i\n", arg);
+ ERR("invalid clr scr %i", arg);
}
else _clear_screen(ty, CLR_END);
break;
if ((arg >= CLR_END) && (arg <= CLR_ALL))
_clear_line(ty, arg, ty->w);
else
- ERR("invalid clr lin %i\n", arg);
+ ERR("invalid clr lin %i", arg);
}
else _clear_line(ty, CLR_END, ty->w);
break;
break;
case 7:
handled = 1;
- DBG("DDD: set wrap mode to %i\n", mode);
+ DBG("DDD: set wrap mode to %i", mode);
ty->state.wrap = mode;
break;
case 20:
break;
case 12:
handled = 1;
-// DBG("XXX: set blinking cursor to (stop?) %i\n", mode);
+// DBG("XXX: set blinking cursor to (stop?) %i", mode);
break;
case 25:
handled = 1;
break;
case 1000:
handled = 1;
- INF("XXX: set x11 mouse reporting to %i\n", mode);
+ INF("XXX: set x11 mouse reporting to %i", mode);
break;
case 1049:
case 47:
case 1047:
handled = 1;
- DBG("DDD: switch buf\n");
+ DBG("DDD: switch buf");
if (ty->altbuf)
{
// if we are looking at alt buf now,
DBG("Ignored screen mode %i", arg);
break;
default:
- ERR("unhandled screen mode arg %i\n", arg);
+ ERR("unhandled screen mode arg %i", arg);
break;
}
}
else if (arg == 4)
{
handled = 1;
- DBG("DDD: set insert mode to %i\n", mode);
+ DBG("DDD: set insert mode to %i", mode);
ty->state.insert = mode;
}
// else if (arg == 24)
// {
-// ERR("unhandled #24 arg %i\n", arg);
+// ERR("unhandled #24 arg %i", arg);
// // ???
// }
else
- ERR("unhandled screen non-priv mode arg %i, mode %i, ch '%c'\n", arg, mode, *cc);
+ ERR("unhandled screen non-priv mode arg %i, mode %i, ch '%c'", arg, mode, *cc);
}
}
}
- if (!handled) ERR("unhandled '%c' : '%s'\n", *cc, buf);
+ if (!handled) ERR("unhandled '%c' : '%s'", *cc, buf);
}
break;
case 'r':
arg = _csi_arg_get(&b);
if (!b)
{
- INF("no region args reset region\n");
+ INF("no region args reset region");
ty->state.scroll_y1 = 0;
ty->state.scroll_y2 = 0;
}
arg2 = _csi_arg_get(&b);
if (!b)
{
- INF("failed to give 2 region args reset region\n");
+ INF("failed to give 2 region args reset region");
ty->state.scroll_y1 = 0;
ty->state.scroll_y2 = 0;
}
{
if (arg >= arg2)
{
- ERR("scroll region beginning >= end [%i %i]\n", arg, arg2);
+ ERR("scroll region beginning >= end [%i %i]", arg, arg2);
ty->state.scroll_y1 = 0;
ty->state.scroll_y2 = 0;
}
else
{
- INF("2 region args: %i %i\n", arg, arg2);
+ INF("2 region args: %i %i", arg, arg2);
if (arg >= ty->h) arg = ty->h - 1;
if (arg2 > ty->h) arg2 = ty->h;
arg2++;
break;
*/
default:
- ERR("unhandled CSI '%c' (0x%02x), buf='%s'\n", *cc, *cc, buf);
+ ERR("unhandled CSI '%c' (0x%02x), buf='%s'", *cc, *cc, buf);
break;
}
cc++;
break;
default:
// many others
- ERR("unhandled xterm esc '%c' -> '%s'\n", buf[0], buf);
+ ERR("unhandled xterm esc '%c' -> '%s'", buf[0], buf);
break;
}
return cc - c;
_handle_esc(Termpty *ty, const int *c, int *ce)
{
if ((ce - c) < 2) return 0;
- DBG("ESC: '%c'\n", c[1]);
+ DBG("ESC: '%c'", c[1]);
switch (c[1])
{
case '[':
_term_txt_write(ty, "\033[?1;2C");
return 2;
case 'c': // reset terminal to initial state
- DBG("reset to init mode and clear\n");
+ DBG("reset to init mode and clear");
_reset_state(ty);
_clear_screen(ty, CLR_ALL);
if (ty->cb.cancel_sel.func)
int i, size;
Termcell *cells;
- DBG("reset to init mode and clear then fill with E\n");
+ DBG("reset to init mode and clear then fill with E");
_reset_state(ty);
ty->save = ty->state;
ty->swap = ty->state;
return 2;
*/
default:
- ERR("eek - esc unhandled '%c' (0x%02x)\n", c[1], c[1]);
+ ERR("eek - esc unhandled '%c' (0x%02x)", c[1], c[1]);
break;
}
return 1;
return 1;
*/
case 0x07: // BEL '\a' (bell)
- INF("BEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEP\n");
+ INF("BEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEP");
ty->state.had_cr = 0;
return 1;
case 0x08: // BS '\b' (backspace)
- DBG("->BS\n");
+ DBG("->BS");
ty->state.wrapnext = 0;
ty->state.cx--;
if (ty->state.cx < 0) ty->state.cx = 0;
ty->state.had_cr = 0;
return 1;
case 0x09: // HT '\t' (horizontal tab)
- DBG("->HT\n");
+ DBG("->HT");
ty->screen[ty->state.cx + (ty->state.cy * ty->w)].att.tab = 1;
ty->state.wrapnext = 0;
ty->state.cx += 8;
case 0x0a: // LF '\n' (new line)
case 0x0b: // VT '\v' (vertical tab)
case 0x0c: // FF '\f' (form feed)
- DBG("->LF\n");
+ DBG("->LF");
if (ty->state.had_cr)
ty->screen[ty->state.had_cr_x + (ty->state.had_cr_y * ty->w)].att.newline = 1;
ty->state.wrapnext = 0;
ty->state.had_cr = 0;
return 1;
case 0x0d: // CR '\r' (carriage ret)
- DBG("->CR\n");
+ DBG("->CR");
if (ty->state.cx != 0)
{
ty->state.had_cr_x = ty->state.cx;
return 1;
*/
default:
- ERR("unhandled char 0x%02x\n", c[0]);
+ ERR("unhandled char 0x%02x", c[0]);
ty->state.had_cr = 0;
return 1;
}
}
else if (c[0] == 0xf7) // DEL
{
- ERR("unhandled char 0x%02x [DEL]\n", c[0]);
+ ERR("unhandled char 0x%02x [DEL]", c[0]);
ty->state.had_cr = 0;
return 1;
}
cc++;
len++;
}
- DBG("]\n");
+ DBG("]");
_text_append(ty, c, len);
ty->state.had_cr = 0;
return len;
b = realloc(ty->buf, bytes);
if (!b)
{
- ERR("memerr\n");
+ ERR("memerr");
}
- INF("realloc add %i + %i\n", (int)(ty->buflen * sizeof(int)), (int)(len * sizeof(int)));
+ INF("realloc add %i + %i", (int)(ty->buflen * sizeof(int)), (int)(len * sizeof(int)));
bytes = len * sizeof(int);
memcpy(&(b[ty->buflen]), glyphs, bytes);
ty->buf = b;
ty->buf = NULL;
ty->buflen = 0;
bytes = ((char *)ce - (char *)c) + sizeof(int);
- INF("malloc til %i\n", (int)(bytes - sizeof(int)));
+ INF("malloc til %i", (int)(bytes - sizeof(int)));
ty->buf = malloc(bytes);
if (!ty->buf)
{
- ERR("memerr\n");
+ ERR("memerr");
}
bytes = (char *)ce - (char *)c;
memcpy(ty->buf, c, bytes);
{
bytes = ((char *)ce - (char *)c) + sizeof(int);
ty->buf = malloc(bytes);
- INF("malloc %i\n", (int)(bytes - sizeof(int)));
+ INF("malloc %i", (int)(bytes - sizeof(int)));
if (!ty->buf)
{
- ERR("memerr\n");
+ ERR("memerr");
}
bytes = (char *)ce - (char *)c;
memcpy(ty->buf, c, bytes);
sz.ws_row = ty->h;
sz.ws_xpixel = 0;
sz.ws_ypixel = 0;
- if (ioctl(ty->fd, TIOCSWINSZ, &sz) < 0) perror("Size set ioctl failed\n");
+ if (ioctl(ty->fd, TIOCSWINSZ, &sz) < 0)
+ ERR("Size set ioctl failed: %s", strerror(errno));
}
static Eina_Bool
{
i = evas_string_char_next_get(buf, i, &g);
if (i < 0) break;
-// DBG("(%i) %02x '%c'\n", j, g, g);
+// DBG("(%i) %02x '%c'", j, g, g);
}
else
{
- ERR("ZERO GLYPH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
+ ERR("ZERO GLYPH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
g = 0;
i++;
}
j++;
}
glyph[j] = 0;
-// DBG("---------------- handle buf %i\n", j);
+// DBG("---------------- handle buf %i", j);
_handle_buf(ty, glyph, j);
}
if (ty->cb.change.func) ty->cb.change.func(ty->cb.change.data);
void
termpty_write(Termpty *ty, const char *input, int len)
{
- if (write(ty->fd, input, len) < 0) perror("write");
+ if (write(ty->fd, input, len) < 0) ERR("write %s", strerror(errno));
}
void