#include #include #include #include #include #include "string.h" #include "private.h" #include #include "termpty.h" #include /* {{{ stub */ int _log_domain = -1; static Config *_config = NULL; const char * theme_path_get(void) { return NULL; } void main_config_sync(const Config *config) { } void termio_content_change(Evas_Object *obj EINA_UNUSED, Evas_Coord x EINA_UNUSED, Evas_Coord y EINA_UNUSED, int n EINA_UNUSED) { } Config * termio_config_get(const Evas_Object *obj EINA_UNUSED) { return _config; } void termio_scroll(Evas_Object *obj EINA_UNUSED, int direction EINA_UNUSED, int start_y EINA_UNUSED, int end_y EINA_UNUSED) { } /* used to set argument to evas_object_textgrid_palette_set() */ Evas_Object * termio_textgrid_get(Evas_Object *obj EINA_UNUSED) { return NULL; } /* }}} */ static void _init_termpty(Termpty *ty) { ty->w = 80; ty->h = 25; ty->backsize = 50; termpty_reset_state(ty); ty->screen = calloc(1, sizeof(Termcell) * ty->w * ty->h); ty->screen2 = calloc(1, sizeof(Termcell) * ty->w * ty->h); assert(ty->screen); assert(ty->screen2); ty->circular_offset = 0; ty->fd = STDIN_FILENO; } int main(int argc, char **argv) { Termpty ty = {}; char buf[4097]; Eina_Unicode codepoint[4097]; int len, i, j, k, reads; eina_init(); _log_domain = eina_log_domain_register("tyfuzz", NULL); _config = config_new(); _init_termpty(&ty); do { char *rbuf = buf; len = sizeof(buf) - 1; for (i = 0; i < (int)sizeof(ty.oldbuf) && ty.oldbuf[i] & 0x80; i++) { *rbuf = ty.oldbuf[i]; rbuf++; len--; } len = read(ty.fd, rbuf, len); if (len < 0 && errno != EAGAIN) { ERR("error while reading from tty slave fd"); break; } if (len <= 0) break; for (i = 0; i < (int)sizeof(ty.oldbuf); i++) ty.oldbuf[i] = 0; len += rbuf - buf; buf[len] = 0; // convert UTF8 to codepoint integers j = 0; for (i = 0; i < len;) { int g = 0, prev_i = i; if (buf[i]) { #if (EINA_VERSION_MAJOR > 1) || (EINA_VERSION_MINOR >= 8) g = eina_unicode_utf8_next_get(buf, &i); if ((0xdc80 <= g) && (g <= 0xdcff) && (len - prev_i) <= (int)sizeof(ty.oldbuf)) #else i = evas_string_char_next_get(buf, i, &g); if (i < 0 && (len - prev_i) <= (int)sizeof(ty.oldbuf)) #endif { for (k = 0; (k < (int)sizeof(ty.oldbuf)) && (k < (len - prev_i)); k++) { ty.oldbuf[k] = buf[prev_i+k]; } DBG("failure at %d/%d/%d", prev_i, i, len); break; } } else { g = 0; i++; } codepoint[j] = g; j++; } codepoint[j] = 0; termpty_handle_buf(&ty, codepoint, j); } while (1); eina_shutdown(); free(_config); return 0; }