aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-04-20 22:57:28 -0400
committerJesse Luehrs <doy@tozt.net>2014-04-20 22:58:22 -0400
commitd6f244f7d9f52462bafb608f23494707eeb24751 (patch)
tree8b2cab0559f4fce36b20896b24b38b54b6267400 /src
parent29f45358ccc638f7c2ce951e03d91bbd02d6a109 (diff)
downloadrunes-d6f244f7d9f52462bafb608f23494707eeb24751.tar.gz
runes-d6f244f7d9f52462bafb608f23494707eeb24751.zip
clean up the directory structure a bit
Diffstat (limited to 'src')
-rw-r--r--src/config.c248
-rw-r--r--src/config.h6
-rw-r--r--src/display.c563
-rw-r--r--src/display.h39
-rw-r--r--src/parser.c2776
-rw-r--r--src/parser.h6
-rw-r--r--src/parser.l676
-rw-r--r--src/pty-unix.c138
-rw-r--r--src/pty-unix.h17
-rw-r--r--src/runes.c19
-rw-r--r--src/runes.h35
-rw-r--r--src/term.c33
-rw-r--r--src/term.h63
-rw-r--r--src/window-xlib.c532
-rw-r--r--src/window-xlib.h46
15 files changed, 5197 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c
new file mode 100644
index 0000000..0becda1
--- /dev/null
+++ b/src/config.c
@@ -0,0 +1,248 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "runes.h"
+
+static void runes_config_set_defaults(RunesTerm *t);
+static FILE *runes_config_get_config_file();
+static void runes_config_process_config_file(RunesTerm *t, FILE *config_file);
+static void runes_config_set(RunesTerm *t, char *key, char *value);
+static char runes_config_parse_bool(char *val);
+static int runes_config_parse_uint(char *val);
+static char *runes_config_parse_string(char *val);
+static cairo_pattern_t *runes_config_parse_color(char *val);
+
+void runes_config_init(RunesTerm *t, int argc, char *argv[])
+{
+ UNUSED(argc);
+ UNUSED(argv);
+
+ memset((void *)t, 0, sizeof(*t));
+
+ runes_config_set_defaults(t);
+ runes_config_process_config_file(t, runes_config_get_config_file());
+}
+
+static void runes_config_set_defaults(RunesTerm *t)
+{
+ t->font_name = "monospace 10";
+ t->bold_is_bright = 1;
+ t->bold_is_bold = 1;
+ t->audible_bell = 1;
+
+ t->fgdefault = cairo_pattern_create_rgb(0.827, 0.827, 0.827);
+ t->bgdefault = cairo_pattern_create_rgb(0.0, 0.0, 0.0);
+
+ t->colors[0] = cairo_pattern_create_rgb(0.0, 0.0, 0.0);
+ t->colors[1] = cairo_pattern_create_rgb(0.804, 0.0, 0.0);
+ t->colors[2] = cairo_pattern_create_rgb(0.0, 0.804, 0.0);
+ t->colors[3] = cairo_pattern_create_rgb(0.804, 0.804, 0.0);
+ t->colors[4] = cairo_pattern_create_rgb(0.0, 0.0, 0.804);
+ t->colors[5] = cairo_pattern_create_rgb(0.804, 0.0, 0.804);
+ t->colors[6] = cairo_pattern_create_rgb(0.0, 0.804, 0.804);
+ t->colors[7] = cairo_pattern_create_rgb(0.898, 0.898, 0.898);
+
+ t->brightcolors[0] = cairo_pattern_create_rgb(0.302, 0.302, 0.302);
+ t->brightcolors[1] = cairo_pattern_create_rgb(1.0, 0.0, 0.0);
+ t->brightcolors[2] = cairo_pattern_create_rgb(0.0, 1.0, 0.0);
+ t->brightcolors[3] = cairo_pattern_create_rgb(1.0, 1.0, 0.0);
+ t->brightcolors[4] = cairo_pattern_create_rgb(0.0, 0.0, 1.0);
+ t->brightcolors[5] = cairo_pattern_create_rgb(1.0, 0.0, 1.0);
+ t->brightcolors[6] = cairo_pattern_create_rgb(0.0, 1.0, 1.0);
+ t->brightcolors[7] = cairo_pattern_create_rgb(1.0, 1.0, 1.0);
+
+ t->default_rows = 24;
+ t->default_cols = 80;
+}
+
+static FILE *runes_config_get_config_file()
+{
+ char *home, *config_dir, *path;
+ size_t home_len, config_dir_len;
+ FILE *file;
+
+ home = getenv("HOME");
+ home_len = strlen(home);
+
+ config_dir = getenv("XDG_CONFIG_HOME");
+ if (config_dir) {
+ config_dir = strdup(config_dir);
+ }
+ else {
+ config_dir = malloc(home_len + sizeof("/.config") + 1);
+ strcpy(config_dir, home);
+ strcpy(config_dir + home_len, "/.config");
+ }
+ config_dir_len = strlen(config_dir);
+
+ path = malloc(config_dir_len + sizeof("/runes/runes.conf") + 1);
+ strcpy(path, config_dir);
+ strcpy(path + config_dir_len, "/runes/runes.conf");
+ free(config_dir);
+
+ if ((file = fopen(path, "r"))) {
+ free(path);
+ return file;
+ }
+
+ free(path);
+ path = malloc(home_len + sizeof("/.runesrc") + 1);
+ strcpy(path, home);
+ strcpy(path + home_len, "/.runesrc");
+
+ if ((file = fopen(path, "r"))) {
+ free(path);
+ return file;
+ }
+
+ free(path);
+
+ if ((file = fopen("/etc/runesrc", "r"))) {
+ return file;
+ }
+
+ return NULL;
+}
+
+static void runes_config_process_config_file(RunesTerm *t, FILE *config_file)
+{
+ char line[1024];
+
+ if (!config_file) {
+ return;
+ }
+
+ while (fgets(line, 1024, config_file)) {
+ char *kbegin, *kend, *vbegin, *vend;
+ size_t len;
+
+ len = strlen(line);
+ if (line[len - 1] == '\n') {
+ line[len - 1] = '\0';
+ len--;
+ }
+
+ if (!len || line[strspn(line, " \t")] == '#') {
+ continue;
+ }
+
+ kbegin = line + strspn(line, " \t");
+ kend = kbegin + strcspn(kbegin, " \t=");
+ vbegin = kend + strspn(kend, " \t");
+ if (*vbegin != '=') {
+ fprintf(stderr, "couldn't parse line: '%s'\n", line);
+ }
+ vbegin++;
+ vbegin = vbegin + strspn(vbegin, " \t");
+ vend = line + len;
+
+ *kend = '\0';
+ *vend = '\0';
+
+ runes_config_set(t, kbegin, vbegin);
+ }
+}
+
+static void runes_config_set(RunesTerm *t, char *key, char *val)
+{
+ if (!strcmp(key, "font")) {
+ t->font_name = runes_config_parse_string(val);
+ }
+ else if (!strcmp(key, "bold_is_bright")) {
+ t->bold_is_bright = runes_config_parse_bool(val);
+ }
+ else if (!strcmp(key, "bold_is_bold")) {
+ t->bold_is_bold = runes_config_parse_bool(val);
+ }
+ else if (!strcmp(key, "audible_bell")) {
+ t->audible_bell = runes_config_parse_bool(val);
+ }
+ else if (!strcmp(key, "bgcolor")) {
+ cairo_pattern_t *newcolor;
+ newcolor = runes_config_parse_color(val);
+ if (newcolor) {
+ cairo_pattern_destroy(t->bgdefault);
+ t->bgdefault = newcolor;
+ }
+ }
+ else if (!strcmp(key, "fgcolor")) {
+ cairo_pattern_t *newcolor;
+ newcolor = runes_config_parse_color(val);
+ if (newcolor) {
+ cairo_pattern_destroy(t->fgdefault);
+ t->fgdefault = newcolor;
+ }
+ }
+ else if (!strncmp(key, "color", 5)
+ && strlen(key) == 6 && key[5] >= '0' && key[5] <= '7') {
+ cairo_pattern_t *newcolor;
+ newcolor = runes_config_parse_color(val);
+ if (newcolor) {
+ cairo_pattern_destroy(t->colors[key[5] - '0']);
+ t->colors[key[5] - '0'] = newcolor;
+ }
+ }
+ else if (!strncmp(key, "brightcolor", 5)
+ && strlen(key) == 6 && key[5] >= '0' && key[5] <= '7') {
+ cairo_pattern_t *newcolor;
+ newcolor = runes_config_parse_color(val);
+ if (newcolor) {
+ cairo_pattern_destroy(t->brightcolors[key[5] - '0']);
+ t->brightcolors[key[5] - '0'] = newcolor;
+ }
+ }
+ else if (!strcmp(key, "rows")) {
+ t->default_rows = runes_config_parse_uint(val);
+ }
+ else if (!strcmp(key, "cols")) {
+ t->default_cols = runes_config_parse_uint(val);
+ }
+ else if (!strcmp(key, "command")) {
+ t->cmd = runes_config_parse_string(val);
+ }
+ else {
+ fprintf(stderr, "unknown option: '%s'\n", key);
+ }
+}
+
+static char runes_config_parse_bool(char *val)
+{
+ if (!strcmp(val, "true")) {
+ return 1;
+ }
+ else if (!strcmp(val, "false")) {
+ return 0;
+ }
+ else {
+ fprintf(stderr, "unknown boolean value: '%s'\n", val);
+ return 0;
+ }
+}
+
+static int runes_config_parse_uint(char *val)
+{
+ if (strspn(val, "0123456789") != strlen(val)) {
+ fprintf(stderr, "unknown unsigned integer value: '%s'\n", val);
+ }
+
+ return atoi(val);
+}
+
+static char *runes_config_parse_string(char *val)
+{
+ return strdup(val);
+}
+
+static cairo_pattern_t *runes_config_parse_color(char *val)
+{
+ int r, g, b;
+
+ if (strlen(val) != 7 || sscanf(val, "#%2x%2x%2x", &r, &g, &b) != 3) {
+ fprintf(stderr, "unknown color value: '%s'\n", val);
+ return NULL;
+ }
+
+ return cairo_pattern_create_rgb(
+ (double)r / 255.0, (double)g / 255.0, (double)b / 255.0);
+}
diff --git a/src/config.h b/src/config.h
new file mode 100644
index 0000000..980cbab
--- /dev/null
+++ b/src/config.h
@@ -0,0 +1,6 @@
+#ifndef _RUNES_CONFIG_H
+#define _RUNES_CONFIG_H
+
+void runes_config_init(RunesTerm *t, int argc, char *argv[]);
+
+#endif
diff --git a/src/display.c b/src/display.c
new file mode 100644
index 0000000..474d972
--- /dev/null
+++ b/src/display.c
@@ -0,0 +1,563 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "runes.h"
+
+static cairo_pattern_t *runes_display_get_fgcolor(RunesTerm *t);
+static cairo_pattern_t *runes_display_get_bgcolor(RunesTerm *t);
+static void runes_display_recalculate_font_metrics(RunesTerm *t);
+static void runes_display_position_cursor(RunesTerm *t, cairo_t *cr);
+static void runes_display_paint_rectangle(
+ RunesTerm *t, cairo_t *cr, cairo_pattern_t *pattern,
+ int x, int y, int width, int height);
+static void runes_display_scroll_down(RunesTerm *t, int rows);
+
+void runes_display_init(RunesTerm *t)
+{
+ runes_display_recalculate_font_metrics(t);
+
+ t->cursorcolor = cairo_pattern_create_rgba(0.0, 1.0, 0.0, 0.5);
+
+ t->fgcolor = -1;
+ t->bgcolor = -1;
+}
+
+void runes_display_set_window_size(RunesTerm *t)
+{
+ int width, height;
+ cairo_t *old_cr = NULL;
+ cairo_surface_t *surface;
+
+ runes_window_backend_get_size(t, &width, &height);
+
+ if (width == t->xpixel && height == t->ypixel) {
+ return;
+ }
+
+ t->xpixel = width;
+ t->ypixel = height;
+
+ t->rows = t->ypixel / t->fonty;
+ t->cols = t->xpixel / t->fontx;
+
+ old_cr = t->cr;
+
+ /* XXX this should really use cairo_surface_create_similar_image, but when
+ * i did that, drawing calls would occasionally block until an X event
+ * occurred for some reason. should look into this, because i think
+ * create_similar_image does things that are more efficient (using some
+ * xlib shm stuff) */
+ surface = cairo_image_surface_create(
+ CAIRO_FORMAT_RGB24, t->xpixel, t->ypixel);
+ t->cr = cairo_create(surface);
+ cairo_surface_destroy(surface);
+ cairo_set_source(t->cr, runes_display_get_fgcolor(t));
+ if (t->layout) {
+ pango_cairo_update_layout(t->cr, t->layout);
+ }
+ else {
+ PangoAttrList *attrs;
+ PangoFontDescription *font_desc;
+
+ attrs = pango_attr_list_new();
+ font_desc = pango_font_description_from_string(t->font_name);
+
+ t->layout = pango_cairo_create_layout(t->cr);
+ pango_layout_set_attributes(t->layout, attrs);
+ pango_layout_set_font_description(t->layout, font_desc);
+
+ pango_attr_list_unref(attrs);
+ pango_font_description_free(font_desc);
+ }
+
+ cairo_save(t->cr);
+
+ if (old_cr) {
+ cairo_set_source_surface(t->cr, cairo_get_target(old_cr), 0.0, 0.0);
+ }
+ else {
+ cairo_set_source(t->cr, t->bgdefault);
+ }
+
+ cairo_paint(t->cr);
+
+ cairo_restore(t->cr);
+
+ if (old_cr) {
+ cairo_destroy(old_cr);
+ }
+
+ runes_pty_backend_set_window_size(t);
+ runes_display_position_cursor(t, t->cr);
+}
+
+void runes_display_focus_in(RunesTerm *t)
+{
+ t->unfocused = 0;
+}
+
+void runes_display_focus_out(RunesTerm *t)
+{
+ t->unfocused = 1;
+}
+
+void runes_display_move_to(RunesTerm *t, int row, int col)
+{
+ int height = t->scroll_bottom - t->scroll_top;
+
+ t->row = row + t->scroll_top;
+ t->col = col;
+
+ if (row > height) {
+ runes_display_scroll_down(t, row - height);
+ t->row = t->scroll_bottom;
+ }
+ else if (row < 0) {
+ runes_display_scroll_up(t, -row);
+ t->row = t->scroll_top;
+ }
+
+ runes_display_position_cursor(t, t->cr);
+}
+
+void runes_display_show_string_ascii(RunesTerm *t, char *buf, size_t len)
+{
+ if (len) {
+ int remaining = len, space_in_row = t->cols - t->col;
+
+ do {
+ int to_write = remaining > space_in_row ? space_in_row : remaining;
+
+ runes_display_paint_rectangle(
+ t, t->cr, runes_display_get_bgcolor(t),
+ t->col, t->row, to_write, 1);
+
+ pango_layout_set_text(t->layout, buf, to_write);
+ pango_cairo_update_layout(t->cr, t->layout);
+ pango_cairo_show_layout(t->cr, t->layout);
+
+ buf += to_write;
+ remaining -= to_write;
+ space_in_row = t->cols;
+ if (remaining) {
+ runes_display_move_to(t, t->row + 1, 0);
+ }
+ else {
+ t->col += len;
+ runes_display_position_cursor(t, t->cr);
+ }
+ } while (remaining > 0);
+ }
+}
+
+/* XXX this is gross and kind of slow, but i can't find a better way to do it.
+ * i need to be able to convert the string into clusters before laying it out,
+ * since i'm not going to be using the full layout anyway, but the only way i
+ * can see to do that is with pango_get_log_attrs, which only returns character
+ * (not byte) offsets, so i have to reparse the utf8 myself once i get the
+ * results. not ideal. */
+void runes_display_show_string_utf8(RunesTerm *t, char *buf, size_t len)
+{
+ size_t i, pos, char_len;
+ PangoLogAttr *attrs;
+
+ char_len = g_utf8_strlen(buf, len);
+ attrs = malloc(sizeof(PangoLogAttr) * (char_len + 1));
+ pango_get_log_attrs(buf, len, -1, NULL, attrs, char_len + 1);
+
+ pos = 0;
+ for (i = 1; i < char_len + 1; ++i) {
+ if (attrs[i].is_cursor_position) {
+ char *startpos, *c;
+ size_t cluster_len;
+ char width = 1;
+
+ startpos = g_utf8_offset_to_pointer(buf, pos);
+ cluster_len = g_utf8_offset_to_pointer(buf, i) - startpos;
+
+ for (c = startpos;
+ (size_t)(c - startpos) < cluster_len;
+ c = g_utf8_next_char(c)) {
+ if (g_unichar_iswide(g_utf8_get_char(c))) {
+ width = 2;
+ }
+ }
+
+ runes_display_paint_rectangle(
+ t, t->cr, runes_display_get_bgcolor(t),
+ t->col, t->row, width, 1);
+
+ pango_layout_set_text(t->layout, startpos, cluster_len);
+ pango_cairo_update_layout(t->cr, t->layout);
+ pango_cairo_show_layout(t->cr, t->layout);
+
+ if (t->col + width >= t->cols) {
+ runes_display_move_to(t, t->row + 1, 0);
+ }
+ else {
+ runes_display_move_to(t, t->row, t->col + width);
+ }
+ pos = i;
+ }
+ }
+
+ free(attrs);
+}
+
+void runes_display_clear_screen(RunesTerm *t)
+{
+ runes_display_paint_rectangle(
+ t, t->cr, t->bgdefault, 0, 0, t->cols, t->rows);
+}
+
+void runes_display_clear_screen_forward(RunesTerm *t)
+{
+ runes_display_kill_line_forward(t);
+ runes_display_paint_rectangle(
+ t, t->cr, t->bgdefault, 0, t->row, t->cols, t->rows - t->row);
+}
+
+void runes_display_kill_line_forward(RunesTerm *t)
+{
+ runes_display_paint_rectangle(
+ t, t->cr, t->bgdefault, t->col, t->row, t->cols - t->col, 1);
+}
+
+void runes_display_delete_characters(RunesTerm *t, int count)
+{
+ cairo_pattern_t *pattern;
+ cairo_matrix_t matrix;
+
+ cairo_save(t->cr);
+ cairo_push_group(t->cr);
+ pattern = cairo_pattern_create_for_surface(cairo_get_target(t->cr));
+ cairo_matrix_init_translate(&matrix, count * t->fontx, 0.0);
+ cairo_pattern_set_matrix(pattern, &matrix);
+ runes_display_paint_rectangle(
+ t, t->cr, pattern, t->col, t->row, t->cols - t->col - count, 1);
+ cairo_pattern_destroy(pattern);
+ cairo_pop_group_to_source(t->cr);
+ cairo_paint(t->cr);
+ runes_display_paint_rectangle(
+ t, t->cr, t->colors[0], t->cols - count, t->row, count, 1);
+ cairo_restore(t->cr);
+}
+
+void runes_display_reset_text_attributes(RunesTerm *t)
+{
+ runes_display_reset_fg_color(t);
+ runes_display_reset_bg_color(t);
+ runes_display_reset_bold(t);
+ runes_display_reset_italic(t);
+ runes_display_reset_underline(t);
+ runes_display_reset_inverse(t);
+}
+
+void runes_display_set_bold(RunesTerm *t)
+{
+ PangoAttrList *attrs;
+
+ attrs = pango_layout_get_attributes(t->layout);
+ if (t->bold_is_bold) {
+ pango_attr_list_change(
+ attrs, pango_attr_weight_new(PANGO_WEIGHT_BOLD));
+ }
+ t->bold = 1;
+ cairo_set_source(t->cr, runes_display_get_fgcolor(t));
+}
+
+void runes_display_reset_bold(RunesTerm *t)
+{
+ PangoAttrList *attrs;
+
+ attrs = pango_layout_get_attributes(t->layout);
+ if (t->bold_is_bold) {
+ pango_attr_list_change(
+ attrs, pango_attr_weight_new(PANGO_WEIGHT_NORMAL));
+ }
+ t->bold = 0;
+ cairo_set_source(t->cr, runes_display_get_fgcolor(t));
+}
+
+void runes_display_set_italic(RunesTerm *t)
+{
+ PangoAttrList *attrs;
+
+ attrs = pango_layout_get_attributes(t->layout);
+ pango_attr_list_change(attrs, pango_attr_style_new(PANGO_STYLE_ITALIC));
+}
+
+void runes_display_reset_italic(RunesTerm *t)
+{
+ PangoAttrList *attrs;
+
+ attrs = pango_layout_get_attributes(t->layout);
+ pango_attr_list_change(attrs, pango_attr_style_new(PANGO_STYLE_NORMAL));
+}
+
+void runes_display_set_underline(RunesTerm *t)
+{
+ PangoAttrList *attrs;
+
+ attrs = pango_layout_get_attributes(t->layout);
+ pango_attr_list_change(
+ attrs, pango_attr_underline_new(PANGO_UNDERLINE_SINGLE));
+}
+
+void runes_display_reset_underline(RunesTerm *t)
+{
+ PangoAttrList *attrs;
+
+ attrs = pango_layout_get_attributes(t->layout);
+ pango_attr_list_change(
+ attrs, pango_attr_underline_new(PANGO_UNDERLINE_NONE));
+}
+
+void runes_display_set_inverse(RunesTerm *t)
+{
+ t->inverse = 1;
+ cairo_set_source(t->cr, runes_display_get_fgcolor(t));
+}
+
+void runes_display_reset_inverse(RunesTerm *t)
+{
+ t->inverse = 0;
+ cairo_set_source(t->cr, runes_display_get_fgcolor(t));
+}
+
+void runes_display_set_fg_color(RunesTerm *t, int color)
+{
+ t->fgcolor = color;
+ cairo_set_source(t->cr, runes_display_get_fgcolor(t));
+}
+
+void runes_display_reset_fg_color(RunesTerm *t)
+{
+ runes_display_set_fg_color(t, -1);
+}
+
+void runes_display_set_bg_color(RunesTerm *t, int color)
+{
+ t->bgcolor = color;
+ cairo_set_source(t->cr, runes_display_get_fgcolor(t));
+}
+
+void runes_display_reset_bg_color(RunesTerm *t)
+{
+ runes_display_set_bg_color(t, -1);
+}
+
+void runes_display_show_cursor(RunesTerm *t)
+{
+ t->hide_cursor = 0;
+}
+
+void runes_display_hide_cursor(RunesTerm *t)
+{
+ t->hide_cursor = 1;
+}
+
+void runes_display_save_cursor(RunesTerm *t)
+{
+ t->saved_row = t->row;
+ t->saved_col = t->col;
+ /* XXX do other stuff here? */
+}
+
+void runes_display_restore_cursor(RunesTerm *t)
+{
+ t->row = t->saved_row;
+ t->col = t->saved_col;
+}
+
+void runes_display_use_alternate_buffer(RunesTerm *t)
+{
+ if (t->alternate_cr) {
+ return;
+ }
+
+ runes_display_save_cursor(t);
+ t->alternate_cr = t->cr;
+ t->cr = NULL;
+ t->xpixel = -1;
+ t->ypixel = -1;
+ runes_display_set_window_size(t);
+}
+
+void runes_display_use_normal_buffer(RunesTerm *t)
+{
+ if (!t->alternate_cr) {
+ return;
+ }
+
+ runes_display_restore_cursor(t);
+ cairo_destroy(t->cr);
+ t->cr = t->alternate_cr;
+ t->alternate_cr = NULL;
+ t->xpixel = -1;
+ t->ypixel = -1;
+ runes_display_set_window_size(t);
+}
+
+void runes_display_set_scroll_region(
+ RunesTerm *t, int top, int bottom, int left, int right)
+{
+ top = (top < 1 ? 1 : top) - 1;
+ bottom = (bottom > t->rows ? t->rows : bottom) - 1;
+ left = (left < 1 ? 1 : left) - 1;
+ right = (right > t->cols ? t->cols : right) - 1;
+
+ if (left != 0 || right != t->cols - 1) {
+ fprintf(stderr, "vertical scroll regions not yet supported\n");
+ }
+
+ if (top >= bottom || left >= right) {
+ t->scroll_top = 0;
+ t->scroll_bottom = t->rows - 1;
+ return;
+ }
+
+ t->scroll_top = top;
+ t->scroll_bottom = bottom;
+ runes_display_move_to(t, 0, 0);
+}
+
+void runes_display_scroll_up(RunesTerm *t, int rows)
+{
+ cairo_pattern_t *pattern;
+ cairo_matrix_t matrix;
+
+ cairo_save(t->cr);
+ cairo_push_group(t->cr);
+ pattern = cairo_pattern_create_for_surface(cairo_get_target(t->cr));
+ cairo_matrix_init_translate(&matrix, 0.0, -rows * t->fonty);
+ cairo_pattern_set_matrix(pattern, &matrix);
+ runes_display_paint_rectangle(
+ t, t->cr, pattern,
+ 0, t->scroll_top + rows,
+ t->cols, t->scroll_bottom - t->scroll_top + 1 - rows);
+ cairo_pattern_destroy(pattern);
+ cairo_pop_group_to_source(t->cr);
+ cairo_paint(t->cr);
+ runes_display_paint_rectangle(
+ t, t->cr, t->bgdefault, 0, t->scroll_top, t->cols, rows);
+ cairo_restore(t->cr);
+}
+
+void runes_display_cleanup(RunesTerm *t)
+{
+ int i;
+
+ g_object_unref(t->layout);
+ for (i = 0; i < 8; ++i) {
+ cairo_pattern_destroy(t->colors[i]);
+ cairo_pattern_destroy(t->brightcolors[i]);
+ }
+ cairo_pattern_destroy(t->cursorcolor);
+ cairo_destroy(t->cr);
+}
+
+static cairo_pattern_t *runes_display_get_fgcolor(RunesTerm *t)
+{
+ int color = t->inverse ? t->bgcolor : t->fgcolor;
+
+ if (t->inverse && t->bgcolor == t->fgcolor) {
+ return t->bgdefault;
+ }
+ else if (color == -1) {
+ return t->inverse ? t->bgdefault : t->fgdefault;
+ }
+ else if (t->bold_is_bright && t->bold) {
+ return t->brightcolors[color];
+ }
+ else {
+ return t->colors[color];
+ }
+}
+
+static cairo_pattern_t *runes_display_get_bgcolor(RunesTerm *t)
+{
+ int color = t->inverse ? t->fgcolor : t->bgcolor;
+
+ if (t->inverse && t->bgcolor == t->fgcolor) {
+ return t->fgdefault;
+ }
+ else if (color == -1) {
+ return t->inverse ? t->fgdefault : t->bgdefault;
+ }
+ else {
+ return t->colors[color];
+ }
+}
+
+static void runes_display_recalculate_font_metrics(RunesTerm *t)
+{
+ PangoFontDescription *desc;
+ PangoContext *context;
+ PangoFontMetrics *metrics;
+ int ascent, descent;
+
+ desc = pango_font_description_from_string(t->font_name);
+
+ if (t->layout) {
+ context = pango_layout_get_context(t->layout);
+ }
+ else {
+ context = pango_font_map_create_context(
+ pango_cairo_font_map_get_default());
+ }
+
+ metrics = pango_context_get_metrics(context, desc, NULL);
+
+ t->fontx = PANGO_PIXELS(
+ pango_font_metrics_get_approximate_digit_width(metrics));
+ ascent = pango_font_metrics_get_ascent(metrics);
+ descent = pango_font_metrics_get_descent(metrics);
+ t->fonty = PANGO_PIXELS(ascent + descent);
+
+ pango_font_metrics_unref(metrics);
+ pango_font_description_free(desc);
+ if (!t->layout) {
+ g_object_unref(context);
+ }
+}
+
+static void runes_display_position_cursor(RunesTerm *t, cairo_t *cr)
+{
+ cairo_move_to(cr, t->col * t->fontx, t->row * t->fonty);
+}
+
+static void runes_display_paint_rectangle(
+ RunesTerm *t, cairo_t *cr, cairo_pattern_t *pattern,
+ int x, int y, int width, int height)
+{
+ cairo_save(cr);
+ cairo_set_source(cr, pattern);
+ cairo_rectangle(
+ cr, x * t->fontx, y * t->fonty, width * t->fontx, height * t->fonty);
+ cairo_fill(cr);
+ cairo_restore(cr);
+ runes_display_position_cursor(t, t->cr);
+}
+
+static void runes_display_scroll_down(RunesTerm *t, int rows)
+{
+ cairo_pattern_t *pattern;
+ cairo_matrix_t matrix;
+
+ cairo_save(t->cr);
+ cairo_push_group(t->cr);
+ pattern = cairo_pattern_create_for_surface(cairo_get_target(t->cr));
+ cairo_matrix_init_translate(&matrix, 0.0, rows * t->fonty);
+ cairo_pattern_set_matrix(pattern, &matrix);
+ runes_display_paint_rectangle(
+ t, t->cr, pattern,
+ 0, t->scroll_top, t->cols, t->scroll_bottom - t->scroll_top);
+ cairo_pattern_destroy(pattern);
+ cairo_pop_group_to_source(t->cr);
+ cairo_paint(t->cr);
+ runes_display_paint_rectangle(
+ t, t->cr, t->bgdefault, 0, t->scroll_bottom + 1 - rows, t->cols, rows);
+ cairo_restore(t->cr);
+}
diff --git a/src/display.h b/src/display.h
new file mode 100644
index 0000000..cb0b16c
--- /dev/null
+++ b/src/display.h
@@ -0,0 +1,39 @@
+#ifndef _RUNES_DISPLAY_H
+#define _RUNES_DISPLAY_H
+
+void runes_display_init(RunesTerm *t);
+void runes_display_set_window_size(RunesTerm *t);
+void runes_display_focus_in(RunesTerm *t);
+void runes_display_focus_out(RunesTerm *t);
+void runes_display_move_to(RunesTerm *t, int row, int col);
+void runes_display_show_string_ascii(RunesTerm *t, char *buf, size_t len);
+void runes_display_show_string_utf8(RunesTerm *t, char *buf, size_t len);
+void runes_display_clear_screen(RunesTerm *t);
+void runes_display_clear_screen_forward(RunesTerm *t);
+void runes_display_kill_line_forward(RunesTerm *t);
+void runes_display_delete_characters(RunesTerm *t, int count);
+void runes_display_reset_text_attributes(RunesTerm *t);
+void runes_display_set_bold(RunesTerm *t);
+void runes_display_reset_bold(RunesTerm *t);
+void runes_display_set_italic(RunesTerm *t);
+void runes_display_reset_italic(RunesTerm *t);
+void runes_display_set_underline(RunesTerm *t);
+void runes_display_reset_underline(RunesTerm *t);
+void runes_display_set_inverse(RunesTerm *t);
+void runes_display_reset_inverse(RunesTerm *t);
+void runes_display_set_fg_color(RunesTerm *t, int color);
+void runes_display_reset_fg_color(RunesTerm *t);
+void runes_display_set_bg_color(RunesTerm *t, int color);
+void runes_display_reset_bg_color(RunesTerm *t);
+void runes_display_show_cursor(RunesTerm *t);
+void runes_display_hide_cursor(RunesTerm *t);
+void runes_display_save_cursor(RunesTerm *t);
+void runes_display_restore_cursor(RunesTerm *t);
+void runes_display_use_alternate_buffer(RunesTerm *t);
+void runes_display_use_normal_buffer(RunesTerm *t);
+void runes_display_set_scroll_region(
+ RunesTerm *t, int top, int bottom, int left, int right);
+void runes_display_scroll_up(RunesTerm *t, int rows);
+void runes_display_cleanup(RunesTerm *t);
+
+#endif
diff --git a/src/parser.c b/src/parser.c
new file mode 100644
index 0000000..e19e023
--- /dev/null
+++ b/src/parser.c
@@ -0,0 +1,2776 @@
+#line 2 "src/parser.c"
+
+#line 4 "src/parser.c"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+#define YY_FLEX_SUBMINOR_VERSION 39
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+
+/* end standard C headers. */
+
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+#ifdef __cplusplus
+
+/* The "const" storage-class-modifier is valid. */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+/* C99 requires __STDC__ to be defined as 1. */
+#if defined (__STDC__)
+
+#define YY_USE_CONST
+
+#endif /* defined (__STDC__) */
+#endif /* ! __cplusplus */
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+
+/* Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative,
+ * we want to instead treat it as an 8-bit unsigned char, hence the
+ * double cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/* An opaque pointer. */
+#ifndef YY_TYPEDEF_YY_SCANNER_T
+#define YY_TYPEDEF_YY_SCANNER_T
+typedef void* yyscan_t;
+#endif
+
+/* For convenience, these vars (plus the bison vars far below)
+ are macros in the reentrant scanner. */
+#define yyin yyg->yyin_r
+#define yyout yyg->yyout_r
+#define yyextra yyg->yyextra_r
+#define yyleng yyg->yyleng_r
+#define yytext yyg->yytext_r
+#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
+#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
+#define yy_flex_debug yyg->yy_flex_debug_r
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yyg->yy_start = 1 + 2 *
+
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yyg->yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE runes_parser_yyrestart(yyin ,yyscanner )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#define YY_BUF_SIZE 16384
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+ #define YY_LESS_LINENO(n)
+ #define YY_LINENO_REWIND_TO(ptr)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = yyg->yy_hold_char; \
+ YY_RESTORE_YY_MORE_OFFSET \
+ yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ yy_size_t yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via runes_parser_yyrestart()), so that the user can continue scanning by
+ * just pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
+ ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
+ : NULL)
+
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
+
+void runes_parser_yyrestart (FILE *input_file ,yyscan_t yyscanner );
+void runes_parser_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+YY_BUFFER_STATE runes_parser_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
+void runes_parser_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void runes_parser_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
+void runes_parser_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
+void runes_parser_yypop_buffer_state (yyscan_t yyscanner );
+
+static void runes_parser_yyensure_buffer_stack (yyscan_t yyscanner );
+static void runes_parser_yy_load_buffer_state (yyscan_t yyscanner );
+static void runes_parser_yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
+
+#define YY_FLUSH_BUFFER runes_parser_yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
+
+YY_BUFFER_STATE runes_parser_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
+YY_BUFFER_STATE runes_parser_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
+YY_BUFFER_STATE runes_parser_yy_scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner );
+
+void *runes_parser_yyalloc (yy_size_t ,yyscan_t yyscanner );
+void *runes_parser_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
+void runes_parser_yyfree (void * ,yyscan_t yyscanner );
+
+#define yy_new_buffer runes_parser_yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ runes_parser_yyensure_buffer_stack (yyscanner); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ runes_parser_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ runes_parser_yyensure_buffer_stack (yyscanner); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ runes_parser_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* Begin user sect3 */
+
+#define runes_parser_yywrap(yyscanner) 1
+#define YY_SKIP_YYWRAP
+
+typedef unsigned char YY_CHAR;
+
+typedef int yy_state_type;
+
+#define yytext_ptr yytext_r
+
+static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
+static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
+static int yy_get_next_buffer (yyscan_t yyscanner );
+static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ yyg->yytext_ptr = yy_bp; \
+ yyleng = (size_t) (yy_cp - yy_bp); \
+ yyg->yy_hold_char = *yy_cp; \
+ *yy_cp = '\0'; \
+ yyg->yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 49
+#define YY_END_OF_BUFFER 50
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static yyconst flex_int16_t yy_accept[133] =
+ { 0,
+ 0, 0, 50, 47, 1, 2, 3, 4, 5, 6,
+ 7, 40, 32, 48, 34, 35, 36, 45, 46, 12,
+ 13, 8, 9, 10, 38, 39, 11, 0, 0, 0,
+ 32, 0, 0, 0, 33, 35, 36, 41, 42, 37,
+ 37, 42, 42, 14, 15, 16, 17, 18, 19, 20,
+ 21, 22, 23, 24, 25, 26, 0, 0, 0, 43,
+ 44, 44, 44, 44, 0, 0, 0, 0, 0, 0,
+ 0, 36, 37, 37, 37, 27, 28, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 37, 0,
+ 29, 0, 0, 0, 0, 30, 0, 0, 0, 0,
+
+ 31, 0, 0, 0, 0, 0, 37, 37, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 23, 24,
+ 37, 0, 0, 0, 37, 37, 0, 37, 37, 0,
+ 37, 0
+ } ;
+
+static yyconst flex_int32_t yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 2, 3, 4, 5,
+ 6, 7, 8, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 9, 1, 1, 1,
+ 1, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 11, 12, 13,
+ 14, 14, 14, 14, 15, 16, 14, 10, 17, 18,
+ 19, 20, 21, 10, 22, 23, 24, 25, 10, 10,
+ 10, 26, 10, 27, 28, 29, 30, 10, 10, 31,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 32, 10, 33, 10, 10, 10, 10, 10, 10, 10,
+
+ 10, 10, 34, 35, 10, 10, 10, 36, 37, 10,
+ 10, 10, 10, 38, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 1, 39, 39, 39,
+ 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
+ 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
+ 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
+ 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
+ 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
+ 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
+ 39, 40, 40, 40, 40, 40, 40, 40, 40, 40,
+
+ 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
+ 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
+ 40, 40, 40, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41, 41, 42,
+ 42, 42, 42, 42, 42, 42, 42, 43, 43, 43,
+ 43, 43, 43, 43, 43
+ } ;
+
+static yyconst flex_int32_t yy_meta[44] =
+ { 0,
+ 1, 2, 1, 1, 1, 1, 1, 1, 1, 3,
+ 4, 4, 4, 4, 4, 4, 5, 6, 6, 3,
+ 6, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 5, 5, 3, 3, 7, 3,
+ 3, 3, 7
+ } ;
+
+static yyconst flex_int16_t yy_base[147] =
+ { 0,
+ 0, 43, 318, 511, 511, 511, 511, 511, 511, 511,
+ 511, 86, 13, 511, 278, 277, 276, 511, 511, 511,
+ 511, 511, 511, 511, 128, 170, 511, 274, 273, 272,
+ 16, 271, 270, 257, 19, 256, 255, 511, 511, 0,
+ 511, 212, 244, 511, 511, 511, 511, 511, 511, 511,
+ 511, 511, 511, 511, 511, 511, 254, 253, 252, 511,
+ 511, 271, 270, 269, 246, 245, 244, 243, 242, 241,
+ 231, 230, 4, 45, 262, 511, 511, 228, 227, 24,
+ 27, 30, 226, 225, 224, 223, 288, 0, 9, 222,
+ 511, 33, 212, 170, 169, 511, 165, 165, 164, 163,
+
+ 511, 266, 162, 161, 158, 157, 0, 15, 163, 316,
+ 156, 155, 154, 153, 151, 147, 334, 58, 511, 511,
+ 350, 86, 39, 24, 368, 166, 384, 400, 170, 416,
+ 0, 511, 454, 459, 465, 469, 472, 477, 482, 487,
+ 490, 493, 496, 498, 501, 504
+ } ;
+
+static yyconst flex_int16_t yy_def[147] =
+ { 0,
+ 133, 133, 132, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 134, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 132, 132, 132, 135, 132, 132, 132, 132,
+ 134, 132, 132, 132, 136, 132, 132, 132, 132, 25,
+ 132, 132, 42, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 132, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 132, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 137, 42, 42, 132, 132, 132, 132, 138,
+ 139, 140, 132, 132, 132, 132, 42, 132, 141, 132,
+ 132, 138, 132, 132, 132, 132, 139, 132, 132, 132,
+
+ 132, 140, 132, 132, 132, 132, 87, 142, 143, 75,
+ 132, 132, 132, 132, 132, 132, 87, 144, 132, 132,
+ 75, 132, 132, 132, 87, 145, 87, 87, 146, 87,
+ 130, 0, 132, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 132, 132, 132, 132
+ } ;
+
+static yyconst flex_int16_t yy_nxt[555] =
+ { 0,
+ 4, 5, 6, 7, 8, 9, 10, 11, 12, 132,
+ 109, 109, 109, 109, 109, 109, 73, 39, 39, 132,
+ 39, 88, 88, 132, 88, 91, 88, 88, 96, 88,
+ 132, 101, 88, 88, 91, 88, 132, 39, 14, 15,
+ 16, 17, 14, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 32, 33, 34, 32, 33, 34, 32, 33,
+ 34, 89, 102, 93, 94, 95, 98, 99, 100, 103,
+ 104, 105, 93, 94, 95, 88, 88, 97, 88, 53,
+ 54, 14, 15, 16, 17, 14, 18, 18, 18, 18,
+ 18, 18, 18, 18, 18, 19, 19, 19, 19, 19,
+
+ 20, 21, 19, 19, 22, 23, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 24, 19, 25, 26, 27,
+ 19, 19, 19, 19, 92, 28, 29, 30, 38, 38,
+ 38, 38, 38, 38, 38, 38, 38, 39, 40, 40,
+ 40, 40, 40, 40, 41, 42, 42, 39, 43, 44,
+ 45, 46, 47, 48, 49, 50, 51, 39, 52, 39,
+ 39, 39, 53, 54, 55, 56, 96, 57, 58, 59,
+ 60, 60, 60, 60, 60, 60, 60, 60, 60, 118,
+ 62, 63, 64, 88, 88, 124, 88, 88, 88, 102,
+ 88, 123, 97, 122, 92, 61, 116, 119, 120, 115,
+
+ 102, 114, 113, 97, 98, 99, 100, 112, 111, 65,
+ 66, 67, 38, 38, 38, 38, 38, 38, 38, 38,
+ 38, 39, 74, 74, 74, 74, 74, 74, 41, 39,
+ 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
+ 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
+ 92, 57, 58, 59, 75, 75, 75, 75, 75, 75,
+ 39, 35, 19, 106, 61, 90, 39, 101, 35, 86,
+ 76, 77, 75, 75, 75, 75, 75, 75, 89, 35,
+ 85, 19, 84, 83, 61, 82, 81, 80, 76, 77,
+ 79, 78, 39, 72, 35, 71, 53, 54, 107, 107,
+
+ 107, 107, 107, 107, 108, 103, 104, 105, 70, 35,
+ 69, 68, 19, 48, 37, 36, 35, 132, 132, 132,
+ 132, 132, 53, 54, 55, 56, 121, 121, 121, 121,
+ 121, 121, 132, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 39, 39, 125, 125, 125, 125, 125, 125,
+ 126, 132, 132, 132, 132, 132, 132, 132, 132, 39,
+ 121, 121, 121, 121, 121, 121, 132, 132, 132, 132,
+ 132, 132, 132, 132, 132, 132, 39, 39, 125, 125,
+ 125, 125, 125, 125, 126, 132, 132, 132, 132, 132,
+ 132, 132, 132, 39, 128, 128, 128, 128, 128, 128,
+
+ 129, 132, 132, 132, 132, 132, 132, 132, 132, 39,
+ 128, 128, 128, 128, 128, 128, 129, 132, 132, 132,
+ 132, 132, 132, 132, 132, 39, 131, 131, 131, 131,
+ 131, 131, 129, 132, 132, 132, 132, 132, 132, 132,
+ 132, 39, 132, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 132, 39, 13, 13, 13, 13, 13, 13,
+ 13, 31, 31, 31, 31, 61, 61, 61, 61, 61,
+ 61, 35, 35, 35, 35, 87, 132, 87, 92, 92,
+ 92, 92, 92, 97, 97, 97, 97, 97, 102, 102,
+ 102, 102, 102, 110, 132, 110, 117, 132, 117, 109,
+
+ 109, 109, 132, 109, 127, 132, 127, 130, 132, 130,
+ 3, 132, 132, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 132, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 132, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 132, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 132, 132
+ } ;
+
+static yyconst flex_int16_t yy_chk[555] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
+ 88, 88, 88, 88, 88, 88, 40, 40, 40, 0,
+ 40, 73, 73, 0, 73, 80, 89, 89, 81, 89,
+ 0, 82, 108, 108, 92, 108, 0, 40, 1, 1,
+ 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 13, 13, 13, 31, 31, 31, 35, 35,
+ 35, 74, 124, 80, 80, 80, 81, 81, 81, 82,
+ 82, 82, 92, 92, 92, 118, 118, 123, 118, 74,
+ 74, 2, 2, 2, 2, 2, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+ 12, 12, 12, 12, 122, 12, 12, 12, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+ 25, 25, 25, 25, 25, 25, 97, 25, 25, 25,
+ 26, 26, 26, 26, 26, 26, 26, 26, 26, 109,
+ 26, 26, 26, 126, 126, 116, 126, 129, 129, 115,
+ 129, 114, 113, 112, 111, 106, 105, 109, 109, 104,
+
+ 103, 100, 99, 98, 97, 97, 97, 95, 94, 26,
+ 26, 26, 42, 42, 42, 42, 42, 42, 42, 42,
+ 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
+ 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
+ 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
+ 93, 42, 42, 42, 43, 43, 43, 43, 43, 43,
+ 90, 86, 85, 84, 83, 79, 78, 102, 72, 71,
+ 43, 43, 75, 75, 75, 75, 75, 75, 75, 70,
+ 69, 68, 67, 66, 65, 64, 63, 62, 75, 75,
+ 59, 58, 57, 37, 36, 34, 75, 75, 87, 87,
+
+ 87, 87, 87, 87, 87, 102, 102, 102, 33, 32,
+ 30, 29, 28, 87, 17, 16, 15, 3, 0, 0,
+ 0, 0, 87, 87, 87, 87, 110, 110, 110, 110,
+ 110, 110, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 110, 110, 117, 117, 117, 117, 117, 117,
+ 117, 0, 0, 0, 0, 0, 0, 0, 0, 117,
+ 121, 121, 121, 121, 121, 121, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 121, 121, 125, 125,
+ 125, 125, 125, 125, 125, 0, 0, 0, 0, 0,
+ 0, 0, 0, 125, 127, 127, 127, 127, 127, 127,
+
+ 127, 0, 0, 0, 0, 0, 0, 0, 0, 127,
+ 128, 128, 128, 128, 128, 128, 128, 0, 0, 0,
+ 0, 0, 0, 0, 0, 128, 130, 130, 130, 130,
+ 130, 130, 130, 0, 0, 0, 0, 0, 0, 0,
+ 0, 130, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 130, 133, 133, 133, 133, 133, 133,
+ 133, 134, 134, 134, 134, 135, 135, 135, 135, 135,
+ 135, 136, 136, 136, 136, 137, 0, 137, 138, 138,
+ 138, 138, 138, 139, 139, 139, 139, 139, 140, 140,
+ 140, 140, 140, 141, 0, 141, 142, 0, 142, 143,
+
+ 143, 144, 0, 144, 145, 0, 145, 146, 0, 146,
+ 132, 132, 132, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 132, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 132, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 132, 132, 132, 132, 132, 132, 132, 132,
+ 132, 132, 132, 132
+ } ;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+#line 1 "src/parser.l"
+#line 2 "src/parser.l"
+#include <string.h>
+
+#include "runes.h"
+
+#define RUNES_PARSER_CSI_MAX_PARAMS 256
+
+#define YY_EXIT_FAILURE (UNUSED(yyscanner), 2)
+#define YY_NO_INPUT 1
+#line 73 "src/parser.l"
+static void runes_parser_handle_bel(RunesTerm *t);
+static void runes_parser_handle_bs(RunesTerm *t);
+static void runes_parser_handle_tab(RunesTerm *t);
+static void runes_parser_handle_lf(RunesTerm *t);
+static void runes_parser_handle_cr(RunesTerm *t);
+static void runes_parser_handle_deckpam(RunesTerm *t);
+static void runes_parser_handle_deckpnm(RunesTerm *t);
+static void runes_parser_handle_ri(RunesTerm *t);
+static void runes_parser_handle_vb(RunesTerm *t);
+static void runes_parser_handle_decsc(RunesTerm *t);
+static void runes_parser_handle_decrc(RunesTerm *t);
+static void runes_parser_extract_csi_params(
+ char *buf, size_t len, int *params, int *nparams);
+static void runes_parser_extract_sm_params(
+ char *buf, size_t len, char *modes, int *params, int *nparams);
+static void runes_parser_handle_cuu(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_cud(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_cuf(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_cub(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_cup(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_ed(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_el(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_il(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_dch(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_sm(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_rm(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_sgr(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_csr(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_decsed(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_decsel(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_osc0(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_osc1(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_osc2(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_ascii(RunesTerm *t, char *text, size_t len);
+static void runes_parser_handle_text(RunesTerm *t, char *text, size_t len);
+#line 647 "src/parser.c"
+
+#define INITIAL 0
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+#include <unistd.h>
+#endif
+
+#define YY_EXTRA_TYPE RunesTerm *
+
+/* Holds the entire state of the reentrant scanner. */
+struct yyguts_t
+ {
+
+ /* User-defined. Not touched by flex. */
+ YY_EXTRA_TYPE yyextra_r;
+
+ /* The rest are the same as the globals declared in the non-reentrant scanner. */
+ FILE *yyin_r, *yyout_r;
+ size_t yy_buffer_stack_top; /**< index of top of stack. */
+ size_t yy_buffer_stack_max; /**< capacity of stack. */
+ YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
+ char yy_hold_char;
+ yy_size_t yy_n_chars;
+ yy_size_t yyleng_r;
+ char *yy_c_buf_p;
+ int yy_init;
+ int yy_start;
+ int yy_did_buffer_switch_on_eof;
+ int yy_start_stack_ptr;
+ int yy_start_stack_depth;
+ int *yy_start_stack;
+ yy_state_type yy_last_accepting_state;
+ char* yy_last_accepting_cpos;
+
+ int yylineno_r;
+ int yy_flex_debug_r;
+
+ char *yytext_r;
+ int yy_more_flag;
+ int yy_more_len;
+
+ }; /* end struct yyguts_t */
+
+static int yy_init_globals (yyscan_t yyscanner );
+
+int runes_parser_yylex_init (yyscan_t* scanner);
+
+int runes_parser_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int runes_parser_yylex_destroy (yyscan_t yyscanner );
+
+int runes_parser_yyget_debug (yyscan_t yyscanner );
+
+void runes_parser_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+
+YY_EXTRA_TYPE runes_parser_yyget_extra (yyscan_t yyscanner );
+
+void runes_parser_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+
+FILE *runes_parser_yyget_in (yyscan_t yyscanner );
+
+void runes_parser_yyset_in (FILE * in_str ,yyscan_t yyscanner );
+
+FILE *runes_parser_yyget_out (yyscan_t yyscanner );
+
+void runes_parser_yyset_out (FILE * out_str ,yyscan_t yyscanner );
+
+yy_size_t runes_parser_yyget_leng (yyscan_t yyscanner );
+
+char *runes_parser_yyget_text (yyscan_t yyscanner );
+
+int runes_parser_yyget_lineno (yyscan_t yyscanner );
+
+void runes_parser_yyset_lineno (int line_number ,yyscan_t yyscanner );
+
+int runes_parser_yyget_column (yyscan_t yyscanner );
+
+void runes_parser_yyset_column (int column_no ,yyscan_t yyscanner );
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int runes_parser_yywrap (yyscan_t yyscanner );
+#else
+extern int runes_parser_yywrap (yyscan_t yyscanner );
+#endif
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+#endif
+
+#ifndef YY_NO_INPUT
+
+#ifdef __cplusplus
+static int yyinput (yyscan_t yyscanner );
+#else
+static int input (yyscan_t yyscanner );
+#endif
+
+#endif
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ size_t n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(yyin); \
+ } \
+ }\
+\
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
+#endif
+
+/* end tables serialization structures and prototypes */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+
+extern int runes_parser_yylex (yyscan_t yyscanner);
+
+#define YY_DECL int runes_parser_yylex (yyscan_t yyscanner)
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if ( !yyg->yy_init )
+ {
+ yyg->yy_init = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! yyg->yy_start )
+ yyg->yy_start = 1; /* first start state */
+
+ if ( ! yyin )
+ yyin = stdin;
+
+ if ( ! yyout )
+ yyout = stdout;
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ runes_parser_yyensure_buffer_stack (yyscanner);
+ YY_CURRENT_BUFFER_LVALUE =
+ runes_parser_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ }
+
+ runes_parser_yy_load_buffer_state(yyscanner );
+ }
+
+ {
+#line 110 "src/parser.l"
+
+
+#line 898 "src/parser.c"
+
+ while ( 1 ) /* loops until end-of-file is reached */
+ {
+ yy_cp = yyg->yy_c_buf_p;
+
+ /* Support of yytext. */
+ *yy_cp = yyg->yy_hold_char;
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = yyg->yy_start;
+yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
+ if ( yy_accept[yy_current_state] )
+ {
+ yyg->yy_last_accepting_state = yy_current_state;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 133 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while ( yy_current_state != 132 );
+ yy_cp = yyg->yy_last_accepting_cpos;
+ yy_current_state = yyg->yy_last_accepting_state;
+
+yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+
+ YY_DO_BEFORE_ACTION;
+
+do_action: /* This label is used only to access EOF actions. */
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = yyg->yy_hold_char;
+ yy_cp = yyg->yy_last_accepting_cpos;
+ yy_current_state = yyg->yy_last_accepting_state;
+ goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 112 "src/parser.l"
+runes_parser_handle_bel(yyextra); return -1;
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 113 "src/parser.l"
+runes_parser_handle_bs(yyextra); return -1;
+ YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 114 "src/parser.l"
+runes_parser_handle_tab(yyextra); return -1;
+ YY_BREAK
+case 4:
+/* rule 4 can match eol */
+#line 116 "src/parser.l"
+case 5:
+/* rule 5 can match eol */
+#line 117 "src/parser.l"
+case 6:
+/* rule 6 can match eol */
+YY_RULE_SETUP
+#line 117 "src/parser.l"
+runes_parser_handle_lf(yyextra); return -1;
+ YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 118 "src/parser.l"
+runes_parser_handle_cr(yyextra); return -1;
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 120 "src/parser.l"
+runes_parser_handle_deckpam(yyextra); return -1;
+ YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 121 "src/parser.l"
+runes_parser_handle_deckpnm(yyextra); return -1;
+ YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 122 "src/parser.l"
+runes_parser_handle_ri(yyextra); return -1;
+ YY_BREAK
+case 11:
+YY_RULE_SETUP
+#line 123 "src/parser.l"
+runes_parser_handle_vb(yyextra); return -1;
+ YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 124 "src/parser.l"
+runes_parser_handle_decsc(yyextra); return -1;
+ YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 125 "src/parser.l"
+runes_parser_handle_decrc(yyextra); return -1;
+ YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 127 "src/parser.l"
+runes_parser_handle_cuu(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 128 "src/parser.l"
+runes_parser_handle_cud(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 129 "src/parser.l"
+runes_parser_handle_cuf(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 130 "src/parser.l"
+runes_parser_handle_cub(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 131 "src/parser.l"
+runes_parser_handle_cup(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 132 "src/parser.l"
+runes_parser_handle_ed(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 133 "src/parser.l"
+runes_parser_handle_el(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 134 "src/parser.l"
+runes_parser_handle_il(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 22:
+YY_RULE_SETUP
+#line 135 "src/parser.l"
+runes_parser_handle_dch(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 23:
+YY_RULE_SETUP
+#line 136 "src/parser.l"
+runes_parser_handle_sm(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 24:
+YY_RULE_SETUP
+#line 137 "src/parser.l"
+runes_parser_handle_rm(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 25:
+YY_RULE_SETUP
+#line 138 "src/parser.l"
+runes_parser_handle_sgr(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 26:
+YY_RULE_SETUP
+#line 139 "src/parser.l"
+runes_parser_handle_csr(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 27:
+YY_RULE_SETUP
+#line 141 "src/parser.l"
+runes_parser_handle_decsed(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 28:
+YY_RULE_SETUP
+#line 142 "src/parser.l"
+runes_parser_handle_decsel(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 29:
+YY_RULE_SETUP
+#line 144 "src/parser.l"
+runes_parser_handle_osc0(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 30:
+YY_RULE_SETUP
+#line 145 "src/parser.l"
+runes_parser_handle_osc1(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 31:
+YY_RULE_SETUP
+#line 146 "src/parser.l"
+runes_parser_handle_osc2(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 32:
+YY_RULE_SETUP
+#line 148 "src/parser.l"
+runes_parser_handle_ascii(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 33:
+YY_RULE_SETUP
+#line 149 "src/parser.l"
+runes_parser_handle_text(yyextra, yytext, yyleng); return -1;
+ YY_BREAK
+case 34:
+#line 152 "src/parser.l"
+case 35:
+#line 153 "src/parser.l"
+case 36:
+#line 154 "src/parser.l"
+case 37:
+#line 155 "src/parser.l"
+case 38:
+#line 156 "src/parser.l"
+case 39:
+#line 157 "src/parser.l"
+case 40:
+YY_RULE_SETUP
+#line 157 "src/parser.l"
+return yyleng;
+ YY_BREAK
+case YY_STATE_EOF(INITIAL):
+#line 159 "src/parser.l"
+return 0;
+ YY_BREAK
+case 41:
+/* rule 41 can match eol */
+YY_RULE_SETUP
+#line 161 "src/parser.l"
+{
+ fprintf(
+ stderr, "unhandled CSI sequence: \\033%*s\\%hho\n",
+ (int)yyleng - 2, yytext + 1, yytext[yyleng - 1]);
+ return -1;
+}
+ YY_BREAK
+case 42:
+YY_RULE_SETUP
+#line 168 "src/parser.l"
+{
+ fprintf(
+ stderr, "unhandled CSI sequence: \\033%*s\n",
+ (int)yyleng - 1, yytext + 1);
+ return -1;
+}
+ YY_BREAK
+case 43:
+/* rule 43 can match eol */
+YY_RULE_SETUP
+#line 175 "src/parser.l"
+{
+ fprintf(
+ stderr, "unhandled OSC sequence: \\033%*s\\%hho\n",
+ (int)yyleng - 2, yytext + 1, yytext[yyleng - 1]);
+ return -1;
+}
+ YY_BREAK
+case 44:
+YY_RULE_SETUP
+#line 182 "src/parser.l"
+{
+ fprintf(
+ stderr, "unhandled OSC sequence: \\033%*s\n",
+ (int)yyleng - 1, yytext + 1);
+ return -1;
+}
+ YY_BREAK
+case 45:
+/* rule 45 can match eol */
+YY_RULE_SETUP
+#line 189 "src/parser.l"
+{
+ fprintf(stderr, "unhandled escape sequence: \\%hho\n", yytext[1]);
+ return -1;
+}
+ YY_BREAK
+case 46:
+YY_RULE_SETUP
+#line 194 "src/parser.l"
+{
+ fprintf(
+ stderr, "unhandled escape sequence: %*s\n",
+ (int)yyleng - 1, yytext + 1);
+ return -1;
+}
+ YY_BREAK
+case 47:
+/* rule 47 can match eol */
+YY_RULE_SETUP
+#line 201 "src/parser.l"
+{
+ fprintf(stderr, "unhandled control character: \\%hho\n", yytext[0]);
+ return -1;
+}
+ YY_BREAK
+case 48:
+YY_RULE_SETUP
+#line 206 "src/parser.l"
+{
+ fprintf(stderr, "invalid utf8 byte: \\%hho\n", yytext[0]);
+ return -1;
+}
+ YY_BREAK
+case 49:
+YY_RULE_SETUP
+#line 211 "src/parser.l"
+YY_FATAL_ERROR( "flex scanner jammed" );
+ YY_BREAK
+#line 1217 "src/parser.c"
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = yyg->yy_hold_char;
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed yyin at a new source and called
+ * runes_parser_yylex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
+
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++yyg->yy_c_buf_p;
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = yyg->yy_last_accepting_cpos;
+ yy_current_state = yyg->yy_last_accepting_state;
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( yyscanner ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ yyg->yy_did_buffer_switch_on_eof = 0;
+
+ if ( runes_parser_yywrap(yyscanner ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! yyg->yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yyg->yy_c_buf_p =
+ yyg->yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ yy_cp = yyg->yy_c_buf_p;
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ yyg->yy_c_buf_p =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
+
+ yy_current_state = yy_get_previous_state( yyscanner );
+
+ yy_cp = yyg->yy_c_buf_p;
+ yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+ } /* end of user's declarations */
+} /* end of runes_parser_yylex */
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+static int yy_get_next_buffer (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ register char *source = yyg->yytext_ptr;
+ register int number_to_move, i;
+ int ret_val;
+
+ if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
+
+ else
+ {
+ yy_size_t num_to_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
+
+ int yy_c_buf_p_offset =
+ (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ yy_size_t new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ runes_parser_yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = 0;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ yyg->yy_n_chars, num_to_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ if ( yyg->yy_n_chars == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ runes_parser_yyrestart(yyin ,yyscanner);
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) runes_parser_yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ }
+
+ yyg->yy_n_chars += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+ yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+ static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ yy_current_state = yyg->yy_start;
+
+ for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
+ {
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ yyg->yy_last_accepting_state = yy_current_state;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 133 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
+{
+ register int yy_is_jam;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
+ register char *yy_cp = yyg->yy_c_buf_p;
+
+ register YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ yyg->yy_last_accepting_state = yy_current_state;
+ yyg->yy_last_accepting_cpos = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 133 )
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 132);
+
+ (void)yyg;
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (yyscan_t yyscanner)
+#else
+ static int input (yyscan_t yyscanner)
+#endif
+
+{
+ int c;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+
+ if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
+ /* This was really a NUL. */
+ *yyg->yy_c_buf_p = '\0';
+
+ else
+ { /* need more input */
+ yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
+ ++yyg->yy_c_buf_p;
+
+ switch ( yy_get_next_buffer( yyscanner ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ runes_parser_yyrestart(yyin ,yyscanner);
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( runes_parser_yywrap(yyscanner ) )
+ return EOF;
+
+ if ( ! yyg->yy_did_buffer_switch_on_eof )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput(yyscanner);
+#else
+ return input(yyscanner);
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
+ *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
+ yyg->yy_hold_char = *++yyg->yy_c_buf_p;
+
+ return c;
+}
+#endif /* ifndef YY_NO_INPUT */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ * @param yyscanner The scanner object.
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+ void runes_parser_yyrestart (FILE * input_file , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if ( ! YY_CURRENT_BUFFER ){
+ runes_parser_yyensure_buffer_stack (yyscanner);
+ YY_CURRENT_BUFFER_LVALUE =
+ runes_parser_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ }
+
+ runes_parser_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
+ runes_parser_yy_load_buffer_state(yyscanner );
+}
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ * @param yyscanner The scanner object.
+ */
+ void runes_parser_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * runes_parser_yypop_buffer_state();
+ * runes_parser_yypush_buffer_state(new_buffer);
+ */
+ runes_parser_yyensure_buffer_stack (yyscanner);
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ runes_parser_yy_load_buffer_state(yyscanner );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (runes_parser_yywrap()) processing, but the only time this flag
+ * is looked at is after runes_parser_yywrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ yyg->yy_did_buffer_switch_on_eof = 1;
+}
+
+static void runes_parser_yy_load_buffer_state (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+ yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+ yyg->yy_hold_char = *yyg->yy_c_buf_p;
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ * @param yyscanner The scanner object.
+ * @return the allocated buffer state.
+ */
+ YY_BUFFER_STATE runes_parser_yy_create_buffer (FILE * file, int size , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) runes_parser_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in runes_parser_yy_create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) runes_parser_yyalloc(b->yy_buf_size + 2 ,yyscanner );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in runes_parser_yy_create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ runes_parser_yy_init_buffer(b,file ,yyscanner);
+
+ return b;
+}
+
+/** Destroy the buffer.
+ * @param b a buffer created with runes_parser_yy_create_buffer()
+ * @param yyscanner The scanner object.
+ */
+ void runes_parser_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ runes_parser_yyfree((void *) b->yy_ch_buf ,yyscanner );
+
+ runes_parser_yyfree((void *) b ,yyscanner );
+}
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a runes_parser_yyrestart() or at EOF.
+ */
+ static void runes_parser_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
+
+{
+ int oerrno = errno;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ runes_parser_yy_flush_buffer(b ,yyscanner);
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then runes_parser_yy_init_buffer was _probably_
+ * called from runes_parser_yyrestart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+ b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ * @param yyscanner The scanner object.
+ */
+ void runes_parser_yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ runes_parser_yy_load_buffer_state(yyscanner );
+}
+
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ * @param yyscanner The scanner object.
+ */
+void runes_parser_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if (new_buffer == NULL)
+ return;
+
+ runes_parser_yyensure_buffer_stack(yyscanner);
+
+ /* This block is copied from runes_parser_yy_switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *yyg->yy_c_buf_p = yyg->yy_hold_char;
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ yyg->yy_buffer_stack_top++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from runes_parser_yy_switch_to_buffer. */
+ runes_parser_yy_load_buffer_state(yyscanner );
+ yyg->yy_did_buffer_switch_on_eof = 1;
+}
+
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ * @param yyscanner The scanner object.
+ */
+void runes_parser_yypop_buffer_state (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ runes_parser_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if (yyg->yy_buffer_stack_top > 0)
+ --yyg->yy_buffer_stack_top;
+
+ if (YY_CURRENT_BUFFER) {
+ runes_parser_yy_load_buffer_state(yyscanner );
+ yyg->yy_did_buffer_switch_on_eof = 1;
+ }
+}
+
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+static void runes_parser_yyensure_buffer_stack (yyscan_t yyscanner)
+{
+ yy_size_t num_to_alloc;
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (!yyg->yy_buffer_stack) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1;
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)runes_parser_yyalloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ , yyscanner);
+ if ( ! yyg->yy_buffer_stack )
+ YY_FATAL_ERROR( "out of dynamic memory in runes_parser_yyensure_buffer_stack()" );
+
+ memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ yyg->yy_buffer_stack_max = num_to_alloc;
+ yyg->yy_buffer_stack_top = 0;
+ return;
+ }
+
+ if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ int grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)runes_parser_yyrealloc
+ (yyg->yy_buffer_stack,
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ , yyscanner);
+ if ( ! yyg->yy_buffer_stack )
+ YY_FATAL_ERROR( "out of dynamic memory in runes_parser_yyensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
+ yyg->yy_buffer_stack_max = num_to_alloc;
+ }
+}
+
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE runes_parser_yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return 0;
+
+ b = (YY_BUFFER_STATE) runes_parser_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in runes_parser_yy_scan_buffer()" );
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ runes_parser_yy_switch_to_buffer(b ,yyscanner );
+
+ return b;
+}
+
+/** Setup the input buffer state to scan a string. The next call to runes_parser_yylex() will
+ * scan from a @e copy of @a str.
+ * @param yystr a NUL-terminated string to scan
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * runes_parser_yy_scan_bytes() instead.
+ */
+YY_BUFFER_STATE runes_parser_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
+{
+
+ return runes_parser_yy_scan_bytes(yystr,strlen(yystr) ,yyscanner);
+}
+
+/** Setup the input buffer state to scan the given bytes. The next call to runes_parser_yylex() will
+ * scan from a @e copy of @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ * @param yyscanner The scanner object.
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE runes_parser_yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len , yyscan_t yyscanner)
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ yy_size_t i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = _yybytes_len + 2;
+ buf = (char *) runes_parser_yyalloc(n ,yyscanner );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in runes_parser_yy_scan_bytes()" );
+
+ for ( i = 0; i < _yybytes_len; ++i )
+ buf[i] = yybytes[i];
+
+ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = runes_parser_yy_scan_buffer(buf,n ,yyscanner);
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in runes_parser_yy_scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
+{
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ yytext[yyleng] = yyg->yy_hold_char; \
+ yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
+ yyg->yy_hold_char = *yyg->yy_c_buf_p; \
+ *yyg->yy_c_buf_p = '\0'; \
+ yyleng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/** Get the user-defined data for this scanner.
+ * @param yyscanner The scanner object.
+ */
+YY_EXTRA_TYPE runes_parser_yyget_extra (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyextra;
+}
+
+/** Get the current line number.
+ * @param yyscanner The scanner object.
+ */
+int runes_parser_yyget_lineno (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (! YY_CURRENT_BUFFER)
+ return 0;
+
+ return yylineno;
+}
+
+/** Get the current column number.
+ * @param yyscanner The scanner object.
+ */
+int runes_parser_yyget_column (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ if (! YY_CURRENT_BUFFER)
+ return 0;
+
+ return yycolumn;
+}
+
+/** Get the input stream.
+ * @param yyscanner The scanner object.
+ */
+FILE *runes_parser_yyget_in (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyin;
+}
+
+/** Get the output stream.
+ * @param yyscanner The scanner object.
+ */
+FILE *runes_parser_yyget_out (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyout;
+}
+
+/** Get the length of the current token.
+ * @param yyscanner The scanner object.
+ */
+yy_size_t runes_parser_yyget_leng (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yyleng;
+}
+
+/** Get the current token.
+ * @param yyscanner The scanner object.
+ */
+
+char *runes_parser_yyget_text (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yytext;
+}
+
+/** Set the user-defined data. This data is never touched by the scanner.
+ * @param user_defined The data to be associated with this scanner.
+ * @param yyscanner The scanner object.
+ */
+void runes_parser_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyextra = user_defined ;
+}
+
+/** Set the current line number.
+ * @param line_number
+ * @param yyscanner The scanner object.
+ */
+void runes_parser_yyset_lineno (int line_number , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* lineno is only valid if an input buffer exists. */
+ if (! YY_CURRENT_BUFFER )
+ YY_FATAL_ERROR( "runes_parser_yyset_lineno called with no buffer" );
+
+ yylineno = line_number;
+}
+
+/** Set the current column.
+ * @param line_number
+ * @param yyscanner The scanner object.
+ */
+void runes_parser_yyset_column (int column_no , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* column is only valid if an input buffer exists. */
+ if (! YY_CURRENT_BUFFER )
+ YY_FATAL_ERROR( "runes_parser_yyset_column called with no buffer" );
+
+ yycolumn = column_no;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param in_str A readable stream.
+ * @param yyscanner The scanner object.
+ * @see runes_parser_yy_switch_to_buffer
+ */
+void runes_parser_yyset_in (FILE * in_str , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyin = in_str ;
+}
+
+void runes_parser_yyset_out (FILE * out_str , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yyout = out_str ;
+}
+
+int runes_parser_yyget_debug (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ return yy_flex_debug;
+}
+
+void runes_parser_yyset_debug (int bdebug , yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ yy_flex_debug = bdebug ;
+}
+
+/* Accessor methods for yylval and yylloc */
+
+/* User-visible API */
+
+/* runes_parser_yylex_init is special because it creates the scanner itself, so it is
+ * the ONLY reentrant function that doesn't take the scanner as the last argument.
+ * That's why we explicitly handle the declaration, instead of using our macros.
+ */
+
+int runes_parser_yylex_init(yyscan_t* ptr_yy_globals)
+
+{
+ if (ptr_yy_globals == NULL){
+ errno = EINVAL;
+ return 1;
+ }
+
+ *ptr_yy_globals = (yyscan_t) runes_parser_yyalloc ( sizeof( struct yyguts_t ), NULL );
+
+ if (*ptr_yy_globals == NULL){
+ errno = ENOMEM;
+ return 1;
+ }
+
+ /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
+ memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
+
+ return yy_init_globals ( *ptr_yy_globals );
+}
+
+/* runes_parser_yylex_init_extra has the same functionality as runes_parser_yylex_init, but follows the
+ * convention of taking the scanner as the last argument. Note however, that
+ * this is a *pointer* to a scanner, as it will be allocated by this call (and
+ * is the reason, too, why this function also must handle its own declaration).
+ * The user defined value in the first argument will be available to runes_parser_yyalloc in
+ * the yyextra field.
+ */
+
+int runes_parser_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
+
+{
+ struct yyguts_t dummy_yyguts;
+
+ runes_parser_yyset_extra (yy_user_defined, &dummy_yyguts);
+
+ if (ptr_yy_globals == NULL){
+ errno = EINVAL;
+ return 1;
+ }
+
+ *ptr_yy_globals = (yyscan_t) runes_parser_yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
+
+ if (*ptr_yy_globals == NULL){
+ errno = ENOMEM;
+ return 1;
+ }
+
+ /* By setting to 0xAA, we expose bugs in
+ yy_init_globals. Leave at 0x00 for releases. */
+ memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
+
+ runes_parser_yyset_extra (yy_user_defined, *ptr_yy_globals);
+
+ return yy_init_globals ( *ptr_yy_globals );
+}
+
+static int yy_init_globals (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+ /* Initialization is the same as for the non-reentrant scanner.
+ * This function is called from runes_parser_yylex_destroy(), so don't allocate here.
+ */
+
+ yyg->yy_buffer_stack = 0;
+ yyg->yy_buffer_stack_top = 0;
+ yyg->yy_buffer_stack_max = 0;
+ yyg->yy_c_buf_p = (char *) 0;
+ yyg->yy_init = 0;
+ yyg->yy_start = 0;
+
+ yyg->yy_start_stack_ptr = 0;
+ yyg->yy_start_stack_depth = 0;
+ yyg->yy_start_stack = NULL;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ yyin = stdin;
+ yyout = stdout;
+#else
+ yyin = (FILE *) 0;
+ yyout = (FILE *) 0;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * runes_parser_yylex_init()
+ */
+ return 0;
+}
+
+/* runes_parser_yylex_destroy is for both reentrant and non-reentrant scanners. */
+int runes_parser_yylex_destroy (yyscan_t yyscanner)
+{
+ struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ runes_parser_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ runes_parser_yypop_buffer_state(yyscanner);
+ }
+
+ /* Destroy the stack itself. */
+ runes_parser_yyfree(yyg->yy_buffer_stack ,yyscanner);
+ yyg->yy_buffer_stack = NULL;
+
+ /* Destroy the start condition stack. */
+ runes_parser_yyfree(yyg->yy_start_stack ,yyscanner );
+ yyg->yy_start_stack = NULL;
+
+ /* Reset the globals. This is important in a non-reentrant scanner so the next time
+ * runes_parser_yylex() is called, initialization will occur. */
+ yy_init_globals( yyscanner);
+
+ /* Destroy the main struct (reentrant only). */
+ runes_parser_yyfree ( yyscanner , yyscanner );
+ yyscanner = NULL;
+ return 0;
+}
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
+{
+ register int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
+{
+ register int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+#define YYTABLES_NAME "yytables"
+
+#line 211 "src/parser.l"
+
+
+
+void runes_parser_process_string(RunesTerm *t, char *buf, size_t len)
+{
+ YY_BUFFER_STATE state;
+ yyscan_t scanner;
+ int remaining;
+
+ /* XXX this will break if buf ends with a partial escape sequence or utf8
+ * character. we need to detect that and not consume the entire input in
+ * that case */
+ runes_parser_yylex_init_extra(t,&scanner);
+ state = runes_parser_yy_scan_bytes(buf, len, scanner);
+ while ((remaining = runes_parser_yylex(scanner)) == -1);
+ t->remaininglen = remaining;
+ if (t->remaininglen) {
+ memmove(t->readbuf, &buf[len - t->remaininglen], t->remaininglen);
+ }
+ runes_parser_yy_delete_buffer(state, scanner);
+ runes_parser_yylex_destroy(scanner);
+}
+
+static void runes_parser_handle_bel(RunesTerm *t)
+{
+ if (t->audible_bell) {
+ runes_window_backend_request_audible_bell(t);
+ }
+ else {
+ runes_window_backend_request_visual_bell(t);
+ }
+}
+
+static void runes_parser_handle_bs(RunesTerm *t)
+{
+ runes_display_move_to(t, t->row, t->col - 1);
+}
+
+static void runes_parser_handle_tab(RunesTerm *t)
+{
+ runes_display_move_to(t, t->row, t->col - (t->col % 8) + 8);
+}
+
+static void runes_parser_handle_lf(RunesTerm *t)
+{
+ runes_display_move_to(t, t->row + 1, t->col);
+}
+
+static void runes_parser_handle_cr(RunesTerm *t)
+{
+ runes_display_move_to(t, t->row, 0);
+}
+
+static void runes_parser_handle_deckpam(RunesTerm *t)
+{
+ t->application_keypad = 1;
+}
+
+static void runes_parser_handle_deckpnm(RunesTerm *t)
+{
+ t->application_keypad = 0;
+}
+
+static void runes_parser_handle_ri(RunesTerm *t)
+{
+ runes_display_move_to(t, t->row - 1, t->col);
+}
+
+static void runes_parser_handle_vb(RunesTerm *t)
+{
+ runes_window_backend_request_visual_bell(t);
+}
+
+static void runes_parser_handle_decsc(RunesTerm *t)
+{
+ runes_display_save_cursor(t);
+}
+
+static void runes_parser_handle_decrc(RunesTerm *t)
+{
+ runes_display_restore_cursor(t);
+}
+
+static void runes_parser_extract_csi_params(
+ char *buf, size_t len, int *params, int *nparams)
+{
+ runes_parser_extract_sm_params(buf, len, NULL, params, nparams);
+}
+
+static void runes_parser_extract_sm_params(
+ char *buf, size_t len, char *modes, int *params, int *nparams)
+{
+ char *pos = buf;
+
+ /* this assumes that it will only ever be called on a fully matched CSI
+ * sequence: accessing one character beyond the end is safe because CSI
+ * sequences always have one character after the parameters (to determine
+ * the type of sequence), and the parameters can only ever be digits,
+ * separated by semicolons. */
+ buf[len] = '\0';
+ *nparams = 0;
+ while ((size_t)(pos - buf) < len) {
+ if (*nparams >= RUNES_PARSER_CSI_MAX_PARAMS) {
+ fprintf(stderr, "max CSI parameter length exceeded\n");
+ break;
+ }
+
+ if (modes && (size_t)(pos - buf) < len) {
+ if (strstr(pos, "0123456789")) {
+ modes[*nparams] = '\0';
+ }
+ else {
+ modes[*nparams] = *pos++;
+ }
+ }
+
+ params[(*nparams)++] = atoi(pos);
+
+ pos = strchr(pos, ';');
+ if (pos) {
+ pos++;
+ }
+ else {
+ break;
+ }
+ }
+}
+
+static void runes_parser_handle_cuu(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 1 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ runes_display_move_to(t, t->row - params[0], t->col);
+}
+
+static void runes_parser_handle_cud(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 1 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ runes_display_move_to(t, t->row + params[0], t->col);
+}
+
+static void runes_parser_handle_cuf(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 1 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ runes_display_move_to(t, t->row, t->col + params[0]);
+}
+
+static void runes_parser_handle_cub(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 1 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ runes_display_move_to(t, t->row, t->col - params[0]);
+}
+
+static void runes_parser_handle_cup(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 0, 0 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ if (params[0] == 0) {
+ params[0] = 1;
+ }
+ if (params[1] == 0) {
+ params[1] = 1;
+ }
+ runes_display_move_to(t, params[0] - 1, params[1] - 1);
+}
+
+static void runes_parser_handle_ed(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 0 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ switch (params[0]) {
+ case 0:
+ runes_display_clear_screen_forward(t);
+ break;
+ case 1:
+ /* XXX */
+ fprintf(stderr, "unhandled ED parameter 1\n");
+ break;
+ case 2:
+ runes_display_clear_screen(t);
+ break;
+ default:
+ fprintf(stderr, "unknown ED parameter %d\n", params[0]);
+ break;
+ }
+}
+
+static void runes_parser_handle_el(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 0 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ switch (params[0]) {
+ case 0:
+ runes_display_kill_line_forward(t);
+ break;
+ case 1:
+ /* XXX */
+ fprintf(stderr, "unhandled EL parameter 1\n");
+ break;
+ case 2:
+ /* XXX */
+ fprintf(stderr, "unhandled EL parameter 2\n");
+ break;
+ default:
+ fprintf(stderr, "unknown EL parameter %d\n", params[0]);
+ break;
+ }
+}
+
+static void runes_parser_handle_il(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 1 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ runes_display_scroll_up(t, params[0]);
+}
+
+static void runes_parser_handle_dch(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 1 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ runes_display_delete_characters(t, params[0]);
+}
+
+static void runes_parser_handle_sm(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS], nparams, i;
+ char modes[RUNES_PARSER_CSI_MAX_PARAMS] = { 0 };
+
+ runes_parser_extract_sm_params(buf + 2, len - 3, modes, params, &nparams);
+ for (i = 0; i < nparams; ++i) {
+ switch (modes[i]) {
+ case '?':
+ switch (params[i]) {
+ case 1:
+ t->application_cursor = 1;
+ break;
+ case 25:
+ runes_display_show_cursor(t);
+ break;
+ case 1049:
+ runes_display_use_alternate_buffer(t);
+ break;
+ default:
+ fprintf(
+ stderr, "unknown SM parameter: %c%d\n",
+ modes[i], params[i]);
+ break;
+ }
+ break;
+ default:
+ fprintf(
+ stderr, "unknown SM parameter: %c%d\n",
+ modes[i], params[i]);
+ break;
+ }
+ }
+}
+
+static void runes_parser_handle_rm(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS], nparams, i;
+ char modes[RUNES_PARSER_CSI_MAX_PARAMS] = { 0 };
+
+ runes_parser_extract_sm_params(buf + 2, len - 3, modes, params, &nparams);
+ for (i = 0; i < nparams; ++i) {
+ switch (modes[i]) {
+ case '?':
+ switch (params[i]) {
+ case 1:
+ t->application_cursor = 0;
+ break;
+ case 25:
+ runes_display_hide_cursor(t);
+ break;
+ case 1049:
+ runes_display_use_normal_buffer(t);
+ break;
+ default:
+ fprintf(
+ stderr, "unknown RM parameter: %c%d\n",
+ modes[i], params[i]);
+ break;
+ }
+ break;
+ default:
+ fprintf(
+ stderr, "unknown RM parameter: %c%d\n",
+ modes[i], params[i]);
+ break;
+ }
+ }
+}
+
+static void runes_parser_handle_sgr(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 0 }, nparams, i;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ if (nparams < 1) {
+ nparams = 1;
+ }
+ for (i = 0; i < nparams; ++i) {
+ switch (params[i]) {
+ case 0:
+ runes_display_reset_text_attributes(t);
+ break;
+ case 1:
+ runes_display_set_bold(t);
+ break;
+ case 3:
+ runes_display_set_italic(t);
+ break;
+ case 4:
+ runes_display_set_underline(t);
+ break;
+ case 7:
+ runes_display_set_inverse(t);
+ break;
+ case 22:
+ runes_display_reset_bold(t);
+ break;
+ case 23:
+ runes_display_reset_italic(t);
+ break;
+ case 24:
+ runes_display_reset_underline(t);
+ break;
+ case 27:
+ runes_display_reset_inverse(t);
+ break;
+ case 30: case 31: case 32: case 33:
+ case 34: case 35: case 36: case 37:
+ runes_display_set_fg_color(t, params[i] - 30);
+ break;
+ case 39:
+ runes_display_reset_fg_color(t);
+ break;
+ case 40: case 41: case 42: case 43:
+ case 44: case 45: case 46: case 47:
+ runes_display_set_bg_color(t, params[i] - 40);
+ break;
+ case 49:
+ runes_display_reset_bg_color(t);
+ break;
+ default:
+ fprintf(stderr, "unknown SGR parameter: %d\n", params[i]);
+ break;
+ }
+ }
+}
+
+static void runes_parser_handle_csr(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 1, t->rows, 1, t->cols };
+ int nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+
+ runes_display_set_scroll_region(
+ t, params[0], params[1], params[2], params[3]);
+}
+
+static void runes_parser_handle_decsed(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 0 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ switch (params[0]) {
+ case 0:
+ /* XXX not quite correct */
+ runes_display_clear_screen_forward(t);
+ break;
+ case 1:
+ /* XXX */
+ fprintf(stderr, "unhandled DECSED parameter 1\n");
+ break;
+ case 2:
+ /* XXX not quite correct */
+ runes_display_clear_screen(t);
+ break;
+ default:
+ fprintf(stderr, "unknown DECSED parameter %d\n", params[0]);
+ break;
+ }
+}
+
+static void runes_parser_handle_decsel(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 0 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ switch (params[0]) {
+ case 0:
+ /* XXX not quite correct */
+ runes_display_kill_line_forward(t);
+ break;
+ case 1:
+ /* XXX */
+ fprintf(stderr, "unhandled DECSEL parameter 1\n");
+ break;
+ case 2:
+ /* XXX */
+ fprintf(stderr, "unhandled DECSEL parameter 2\n");
+ break;
+ default:
+ fprintf(stderr, "unknown DECSEL parameter %d\n", params[0]);
+ break;
+ }
+}
+
+static void runes_parser_handle_osc0(RunesTerm *t, char *buf, size_t len)
+{
+ runes_window_backend_set_icon_name(t, buf + 4, len - 5);
+ runes_window_backend_set_window_title(t, buf + 4, len - 5);
+}
+
+static void runes_parser_handle_osc1(RunesTerm *t, char *buf, size_t len)
+{
+ runes_window_backend_set_icon_name(t, buf + 4, len - 5);
+}
+
+static void runes_parser_handle_osc2(RunesTerm *t, char *buf, size_t len)
+{
+ runes_window_backend_set_window_title(t, buf + 4, len - 5);
+}
+
+static void runes_parser_handle_ascii(RunesTerm *t, char *text, size_t len)
+{
+ runes_display_show_string_ascii(t, text, len);
+}
+
+static void runes_parser_handle_text(RunesTerm *t, char *text, size_t len)
+{
+ runes_display_show_string_utf8(t, text, len);
+}
+
+/* XXX these are copied from the generated file so that I can add the UNUSED
+ * declarations, otherwise we get compilation errors */
+void *runes_parser_yyalloc(yy_size_t size, yyscan_t yyscanner)
+{
+ UNUSED(yyscanner);
+ return (void *)malloc(size);
+}
+
+void *runes_parser_yyrealloc(void *ptr, yy_size_t size, yyscan_t yyscanner)
+{
+ UNUSED(yyscanner);
+ return (void *)realloc((char *)ptr, size);
+}
+
+void runes_parser_yyfree(void *ptr, yyscan_t yyscanner)
+{
+ UNUSED(yyscanner);
+ free((char *) ptr);
+}
+
diff --git a/src/parser.h b/src/parser.h
new file mode 100644
index 0000000..ea449a8
--- /dev/null
+++ b/src/parser.h
@@ -0,0 +1,6 @@
+#ifndef _RUNES_PARSER_H
+#define _RUNES_PARSER_H
+
+void runes_parser_process_string(RunesTerm *t, char *buf, size_t len);
+
+#endif
diff --git a/src/parser.l b/src/parser.l
new file mode 100644
index 0000000..a4c4ced
--- /dev/null
+++ b/src/parser.l
@@ -0,0 +1,676 @@
+%{
+#include <string.h>
+
+#include "runes.h"
+
+#define RUNES_PARSER_CSI_MAX_PARAMS 256
+
+#define YY_EXIT_FAILURE (UNUSED(yyscanner), 2)
+%}
+
+%option reentrant nodefault batch
+%option noyywrap nounput noinput noyyalloc noyyrealloc noyyfree
+%option prefix="runes_parser_yy"
+%option extra-type="RunesTerm *"
+
+CTRL [\000-\037\177]
+ASCII [\040-\176]
+LEAD2 [\300-\337]
+LEAD3 [\340-\357]
+LEAD4 [\360-\367]
+CONT [\200-\277]
+UNICHAR ({LEAD2}{CONT}|{LEAD3}{CONT}{CONT}|{LEAD4}{CONT}{CONT}{CONT})
+CHAR ({ASCII}|{UNICHAR})
+
+ST \007
+BEL \007
+BS \010
+TAB \011
+LF \012
+VT \013
+FF \014
+CR \015
+ESC \033
+
+DECKPAM {ESC}=
+DECKPNM {ESC}>
+CSI {ESC}\[
+OSC {ESC}\]
+RI {ESC}M
+VB {ESC}g
+DECSC {ESC}7
+DECRC {ESC}8
+
+DECCSI {CSI}\?
+CSIPARAM1 ([0-9]+)?
+CSIPARAM2 ([0-9]+(;[0-9]+)?)?
+CSIPARAM24 ([0-9]+(;[0-9]+){1,3})?
+CSIPARAMS ([0-9]+(;[0-9]+)*)?
+SMPARAMS ([<=?]?[0-9]+(;[<=?]?[0-9]+)*)?
+
+CUU {CSI}{CSIPARAM1}A
+CUD {CSI}{CSIPARAM1}B
+CUF {CSI}{CSIPARAM1}C
+CUB {CSI}{CSIPARAM1}D
+CUP {CSI}{CSIPARAM2}H
+ED {CSI}{CSIPARAM1}J
+EL {CSI}{CSIPARAM1}K
+IL {CSI}{CSIPARAM1}L
+DCH {CSI}{CSIPARAM1}P
+SM {CSI}{SMPARAMS}h
+RM {CSI}{SMPARAMS}l
+SGR {CSI}{CSIPARAMS}m
+CSR {CSI}{CSIPARAM24}r
+
+DECSED {DECCSI}{CSIPARAM1}J
+DECSEL {DECCSI}{CSIPARAM1}K
+
+OSC0 {OSC}0;{CHAR}*{ST}
+OSC1 {OSC}1;{CHAR}*{ST}
+OSC2 {OSC}2;{CHAR}*{ST}
+
+%{
+static void runes_parser_handle_bel(RunesTerm *t);
+static void runes_parser_handle_bs(RunesTerm *t);
+static void runes_parser_handle_tab(RunesTerm *t);
+static void runes_parser_handle_lf(RunesTerm *t);
+static void runes_parser_handle_cr(RunesTerm *t);
+static void runes_parser_handle_deckpam(RunesTerm *t);
+static void runes_parser_handle_deckpnm(RunesTerm *t);
+static void runes_parser_handle_ri(RunesTerm *t);
+static void runes_parser_handle_vb(RunesTerm *t);
+static void runes_parser_handle_decsc(RunesTerm *t);
+static void runes_parser_handle_decrc(RunesTerm *t);
+static void runes_parser_extract_csi_params(
+ char *buf, size_t len, int *params, int *nparams);
+static void runes_parser_extract_sm_params(
+ char *buf, size_t len, char *modes, int *params, int *nparams);
+static void runes_parser_handle_cuu(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_cud(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_cuf(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_cub(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_cup(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_ed(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_el(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_il(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_dch(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_sm(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_rm(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_sgr(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_csr(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_decsed(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_decsel(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_osc0(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_osc1(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_osc2(RunesTerm *t, char *buf, size_t len);
+static void runes_parser_handle_ascii(RunesTerm *t, char *text, size_t len);
+static void runes_parser_handle_text(RunesTerm *t, char *text, size_t len);
+%}
+
+%%
+
+{BEL} runes_parser_handle_bel(yyextra); return -1;
+{BS} runes_parser_handle_bs(yyextra); return -1;
+{TAB} runes_parser_handle_tab(yyextra); return -1;
+{LF} |
+{VT} |
+{FF} runes_parser_handle_lf(yyextra); return -1;
+{CR} runes_parser_handle_cr(yyextra); return -1;
+
+{DECKPAM} runes_parser_handle_deckpam(yyextra); return -1;
+{DECKPNM} runes_parser_handle_deckpnm(yyextra); return -1;
+{RI} runes_parser_handle_ri(yyextra); return -1;
+{VB} runes_parser_handle_vb(yyextra); return -1;
+{DECSC} runes_parser_handle_decsc(yyextra); return -1;
+{DECRC} runes_parser_handle_decrc(yyextra); return -1;
+
+{CUU} runes_parser_handle_cuu(yyextra, yytext, yyleng); return -1;
+{CUD} runes_parser_handle_cud(yyextra, yytext, yyleng); return -1;
+{CUF} runes_parser_handle_cuf(yyextra, yytext, yyleng); return -1;
+{CUB} runes_parser_handle_cub(yyextra, yytext, yyleng); return -1;
+{CUP} runes_parser_handle_cup(yyextra, yytext, yyleng); return -1;
+{ED} runes_parser_handle_ed(yyextra, yytext, yyleng); return -1;
+{EL} runes_parser_handle_el(yyextra, yytext, yyleng); return -1;
+{IL} runes_parser_handle_il(yyextra, yytext, yyleng); return -1;
+{DCH} runes_parser_handle_dch(yyextra, yytext, yyleng); return -1;
+{SM} runes_parser_handle_sm(yyextra, yytext, yyleng); return -1;
+{RM} runes_parser_handle_rm(yyextra, yytext, yyleng); return -1;
+{SGR} runes_parser_handle_sgr(yyextra, yytext, yyleng); return -1;
+{CSR} runes_parser_handle_csr(yyextra, yytext, yyleng); return -1;
+
+{DECSED} runes_parser_handle_decsed(yyextra, yytext, yyleng); return -1;
+{DECSEL} runes_parser_handle_decsel(yyextra, yytext, yyleng); return -1;
+
+{OSC0} runes_parser_handle_osc0(yyextra, yytext, yyleng); return -1;
+{OSC1} runes_parser_handle_osc1(yyextra, yytext, yyleng); return -1;
+{OSC2} runes_parser_handle_osc2(yyextra, yytext, yyleng); return -1;
+
+{ASCII}+ runes_parser_handle_ascii(yyextra, yytext, yyleng); return -1;
+{CHAR}+ runes_parser_handle_text(yyextra, yytext, yyleng); return -1;
+
+{LEAD2} |
+{LEAD3}{CONT}? |
+{LEAD4}{CONT}?{CONT}? |
+{CSI}[<=?]?{CSIPARAMS}[0-9;] |
+{CSI} |
+{OSC} |
+{ESC} return yyleng;
+
+<<EOF>> return 0;
+
+{CSI}[<=?]?{CSIPARAMS}{CTRL} {
+ fprintf(
+ stderr, "unhandled CSI sequence: \\033%*s\\%hho\n",
+ (int)yyleng - 2, yytext + 1, yytext[yyleng - 1]);
+ return -1;
+}
+
+{CSI}[<=?]?{CSIPARAMS}{CHAR} {
+ fprintf(
+ stderr, "unhandled CSI sequence: \\033%*s\n",
+ (int)yyleng - 1, yytext + 1);
+ return -1;
+}
+
+{OSC}{CTRL} {
+ fprintf(
+ stderr, "unhandled OSC sequence: \\033%*s\\%hho\n",
+ (int)yyleng - 2, yytext + 1, yytext[yyleng - 1]);
+ return -1;
+}
+
+{OSC}{CHAR} {
+ fprintf(
+ stderr, "unhandled OSC sequence: \\033%*s\n",
+ (int)yyleng - 1, yytext + 1);
+ return -1;
+}
+
+{ESC}{CTRL} {
+ fprintf(stderr, "unhandled escape sequence: \\%hho\n", yytext[1]);
+ return -1;
+}
+
+{ESC}{CHAR} {
+ fprintf(
+ stderr, "unhandled escape sequence: %*s\n",
+ (int)yyleng - 1, yytext + 1);
+ return -1;
+}
+
+{CTRL} {
+ fprintf(stderr, "unhandled control character: \\%hho\n", yytext[0]);
+ return -1;
+}
+
+(?s:.) {
+ fprintf(stderr, "invalid utf8 byte: \\%hho\n", yytext[0]);
+ return -1;
+}
+
+%%
+
+void runes_parser_process_string(RunesTerm *t, char *buf, size_t len)
+{
+ YY_BUFFER_STATE state;
+ yyscan_t scanner;
+ int remaining;
+
+ /* XXX this will break if buf ends with a partial escape sequence or utf8
+ * character. we need to detect that and not consume the entire input in
+ * that case */
+ yylex_init_extra(t, &scanner);
+ state = runes_parser_yy_scan_bytes(buf, len, scanner);
+ while ((remaining = runes_parser_yylex(scanner)) == -1);
+ t->remaininglen = remaining;
+ if (t->remaininglen) {
+ memmove(t->readbuf, &buf[len - t->remaininglen], t->remaininglen);
+ }
+ runes_parser_yy_delete_buffer(state, scanner);
+ yylex_destroy(scanner);
+}
+
+static void runes_parser_handle_bel(RunesTerm *t)
+{
+ if (t->audible_bell) {
+ runes_window_backend_request_audible_bell(t);
+ }
+ else {
+ runes_window_backend_request_visual_bell(t);
+ }
+}
+
+static void runes_parser_handle_bs(RunesTerm *t)
+{
+ runes_display_move_to(t, t->row, t->col - 1);
+}
+
+static void runes_parser_handle_tab(RunesTerm *t)
+{
+ runes_display_move_to(t, t->row, t->col - (t->col % 8) + 8);
+}
+
+static void runes_parser_handle_lf(RunesTerm *t)
+{
+ runes_display_move_to(t, t->row + 1, t->col);
+}
+
+static void runes_parser_handle_cr(RunesTerm *t)
+{
+ runes_display_move_to(t, t->row, 0);
+}
+
+static void runes_parser_handle_deckpam(RunesTerm *t)
+{
+ t->application_keypad = 1;
+}
+
+static void runes_parser_handle_deckpnm(RunesTerm *t)
+{
+ t->application_keypad = 0;
+}
+
+static void runes_parser_handle_ri(RunesTerm *t)
+{
+ runes_display_move_to(t, t->row - 1, t->col);
+}
+
+static void runes_parser_handle_vb(RunesTerm *t)
+{
+ runes_window_backend_request_visual_bell(t);
+}
+
+static void runes_parser_handle_decsc(RunesTerm *t)
+{
+ runes_display_save_cursor(t);
+}
+
+static void runes_parser_handle_decrc(RunesTerm *t)
+{
+ runes_display_restore_cursor(t);
+}
+
+static void runes_parser_extract_csi_params(
+ char *buf, size_t len, int *params, int *nparams)
+{
+ runes_parser_extract_sm_params(buf, len, NULL, params, nparams);
+}
+
+static void runes_parser_extract_sm_params(
+ char *buf, size_t len, char *modes, int *params, int *nparams)
+{
+ char *pos = buf;
+
+ /* this assumes that it will only ever be called on a fully matched CSI
+ * sequence: accessing one character beyond the end is safe because CSI
+ * sequences always have one character after the parameters (to determine
+ * the type of sequence), and the parameters can only ever be digits,
+ * separated by semicolons. */
+ buf[len] = '\0';
+ *nparams = 0;
+ while ((size_t)(pos - buf) < len) {
+ if (*nparams >= RUNES_PARSER_CSI_MAX_PARAMS) {
+ fprintf(stderr, "max CSI parameter length exceeded\n");
+ break;
+ }
+
+ if (modes && (size_t)(pos - buf) < len) {
+ if (strstr(pos, "0123456789")) {
+ modes[*nparams] = '\0';
+ }
+ else {
+ modes[*nparams] = *pos++;
+ }
+ }
+
+ params[(*nparams)++] = atoi(pos);
+
+ pos = strchr(pos, ';');
+ if (pos) {
+ pos++;
+ }
+ else {
+ break;
+ }
+ }
+}
+
+static void runes_parser_handle_cuu(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 1 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ runes_display_move_to(t, t->row - params[0], t->col);
+}
+
+static void runes_parser_handle_cud(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 1 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ runes_display_move_to(t, t->row + params[0], t->col);
+}
+
+static void runes_parser_handle_cuf(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 1 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ runes_display_move_to(t, t->row, t->col + params[0]);
+}
+
+static void runes_parser_handle_cub(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 1 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ runes_display_move_to(t, t->row, t->col - params[0]);
+}
+
+static void runes_parser_handle_cup(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 0, 0 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ if (params[0] == 0) {
+ params[0] = 1;
+ }
+ if (params[1] == 0) {
+ params[1] = 1;
+ }
+ runes_display_move_to(t, params[0] - 1, params[1] - 1);
+}
+
+static void runes_parser_handle_ed(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 0 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ switch (params[0]) {
+ case 0:
+ runes_display_clear_screen_forward(t);
+ break;
+ case 1:
+ /* XXX */
+ fprintf(stderr, "unhandled ED parameter 1\n");
+ break;
+ case 2:
+ runes_display_clear_screen(t);
+ break;
+ default:
+ fprintf(stderr, "unknown ED parameter %d\n", params[0]);
+ break;
+ }
+}
+
+static void runes_parser_handle_el(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 0 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ switch (params[0]) {
+ case 0:
+ runes_display_kill_line_forward(t);
+ break;
+ case 1:
+ /* XXX */
+ fprintf(stderr, "unhandled EL parameter 1\n");
+ break;
+ case 2:
+ /* XXX */
+ fprintf(stderr, "unhandled EL parameter 2\n");
+ break;
+ default:
+ fprintf(stderr, "unknown EL parameter %d\n", params[0]);
+ break;
+ }
+}
+
+static void runes_parser_handle_il(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 1 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ runes_display_scroll_up(t, params[0]);
+}
+
+static void runes_parser_handle_dch(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 1 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ runes_display_delete_characters(t, params[0]);
+}
+
+static void runes_parser_handle_sm(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS], nparams, i;
+ char modes[RUNES_PARSER_CSI_MAX_PARAMS] = { 0 };
+
+ runes_parser_extract_sm_params(buf + 2, len - 3, modes, params, &nparams);
+ for (i = 0; i < nparams; ++i) {
+ switch (modes[i]) {
+ case '?':
+ switch (params[i]) {
+ case 1:
+ t->application_cursor = 1;
+ break;
+ case 25:
+ runes_display_show_cursor(t);
+ break;
+ case 1049:
+ runes_display_use_alternate_buffer(t);
+ break;
+ default:
+ fprintf(
+ stderr, "unknown SM parameter: %c%d\n",
+ modes[i], params[i]);
+ break;
+ }
+ break;
+ default:
+ fprintf(
+ stderr, "unknown SM parameter: %c%d\n",
+ modes[i], params[i]);
+ break;
+ }
+ }
+}
+
+static void runes_parser_handle_rm(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS], nparams, i;
+ char modes[RUNES_PARSER_CSI_MAX_PARAMS] = { 0 };
+
+ runes_parser_extract_sm_params(buf + 2, len - 3, modes, params, &nparams);
+ for (i = 0; i < nparams; ++i) {
+ switch (modes[i]) {
+ case '?':
+ switch (params[i]) {
+ case 1:
+ t->application_cursor = 0;
+ break;
+ case 25:
+ runes_display_hide_cursor(t);
+ break;
+ case 1049:
+ runes_display_use_normal_buffer(t);
+ break;
+ default:
+ fprintf(
+ stderr, "unknown RM parameter: %c%d\n",
+ modes[i], params[i]);
+ break;
+ }
+ break;
+ default:
+ fprintf(
+ stderr, "unknown RM parameter: %c%d\n",
+ modes[i], params[i]);
+ break;
+ }
+ }
+}
+
+static void runes_parser_handle_sgr(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 0 }, nparams, i;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ if (nparams < 1) {
+ nparams = 1;
+ }
+ for (i = 0; i < nparams; ++i) {
+ switch (params[i]) {
+ case 0:
+ runes_display_reset_text_attributes(t);
+ break;
+ case 1:
+ runes_display_set_bold(t);
+ break;
+ case 3:
+ runes_display_set_italic(t);
+ break;
+ case 4:
+ runes_display_set_underline(t);
+ break;
+ case 7:
+ runes_display_set_inverse(t);
+ break;
+ case 22:
+ runes_display_reset_bold(t);
+ break;
+ case 23:
+ runes_display_reset_italic(t);
+ break;
+ case 24:
+ runes_display_reset_underline(t);
+ break;
+ case 27:
+ runes_display_reset_inverse(t);
+ break;
+ case 30: case 31: case 32: case 33:
+ case 34: case 35: case 36: case 37:
+ runes_display_set_fg_color(t, params[i] - 30);
+ break;
+ case 39:
+ runes_display_reset_fg_color(t);
+ break;
+ case 40: case 41: case 42: case 43:
+ case 44: case 45: case 46: case 47:
+ runes_display_set_bg_color(t, params[i] - 40);
+ break;
+ case 49:
+ runes_display_reset_bg_color(t);
+ break;
+ default:
+ fprintf(stderr, "unknown SGR parameter: %d\n", params[i]);
+ break;
+ }
+ }
+}
+
+static void runes_parser_handle_csr(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 1, t->rows, 1, t->cols };
+ int nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+
+ runes_display_set_scroll_region(
+ t, params[0], params[1], params[2], params[3]);
+}
+
+static void runes_parser_handle_decsed(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 0 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ switch (params[0]) {
+ case 0:
+ /* XXX not quite correct */
+ runes_display_clear_screen_forward(t);
+ break;
+ case 1:
+ /* XXX */
+ fprintf(stderr, "unhandled DECSED parameter 1\n");
+ break;
+ case 2:
+ /* XXX not quite correct */
+ runes_display_clear_screen(t);
+ break;
+ default:
+ fprintf(stderr, "unknown DECSED parameter %d\n", params[0]);
+ break;
+ }
+}
+
+static void runes_parser_handle_decsel(RunesTerm *t, char *buf, size_t len)
+{
+ int params[RUNES_PARSER_CSI_MAX_PARAMS] = { 0 }, nparams;
+
+ runes_parser_extract_csi_params(buf + 2, len - 3, params, &nparams);
+ switch (params[0]) {
+ case 0:
+ /* XXX not quite correct */
+ runes_display_kill_line_forward(t);
+ break;
+ case 1:
+ /* XXX */
+ fprintf(stderr, "unhandled DECSEL parameter 1\n");
+ break;
+ case 2:
+ /* XXX */
+ fprintf(stderr, "unhandled DECSEL parameter 2\n");
+ break;
+ default:
+ fprintf(stderr, "unknown DECSEL parameter %d\n", params[0]);
+ break;
+ }
+}
+
+static void runes_parser_handle_osc0(RunesTerm *t, char *buf, size_t len)
+{
+ runes_window_backend_set_icon_name(t, buf + 4, len - 5);
+ runes_window_backend_set_window_title(t, buf + 4, len - 5);
+}
+
+static void runes_parser_handle_osc1(RunesTerm *t, char *buf, size_t len)
+{
+ runes_window_backend_set_icon_name(t, buf + 4, len - 5);
+}
+
+static void runes_parser_handle_osc2(RunesTerm *t, char *buf, size_t len)
+{
+ runes_window_backend_set_window_title(t, buf + 4, len - 5);
+}
+
+static void runes_parser_handle_ascii(RunesTerm *t, char *text, size_t len)
+{
+ runes_display_show_string_ascii(t, text, len);
+}
+
+static void runes_parser_handle_text(RunesTerm *t, char *text, size_t len)
+{
+ runes_display_show_string_utf8(t, text, len);
+}
+
+/* XXX these are copied from the generated file so that I can add the UNUSED
+ * declarations, otherwise we get compilation errors */
+void *runes_parser_yyalloc(yy_size_t size, yyscan_t yyscanner)
+{
+ UNUSED(yyscanner);
+ return (void *)malloc(size);
+}
+
+void *runes_parser_yyrealloc(void *ptr, yy_size_t size, yyscan_t yyscanner)
+{
+ UNUSED(yyscanner);
+ return (void *)realloc((char *)ptr, size);
+}
+
+void runes_parser_yyfree(void *ptr, yyscan_t yyscanner)
+{
+ UNUSED(yyscanner);
+ free((char *) ptr);
+}
diff --git a/src/pty-unix.c b/src/pty-unix.c
new file mode 100644
index 0000000..643c5ba
--- /dev/null
+++ b/src/pty-unix.c
@@ -0,0 +1,138 @@
+#define _XOPEN_SOURCE 600
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include "runes.h"
+
+static void runes_pty_backend_read(uv_work_t *req);
+static void runes_pty_backend_got_data(uv_work_t *req, int status);
+
+void runes_pty_backend_spawn_subprocess(RunesTerm *t)
+{
+ RunesPtyBackend *pty = &t->pty;
+
+ pty->master = posix_openpt(O_RDWR);
+ grantpt(pty->master);
+ unlockpt(pty->master);
+ pty->slave = open(ptsname(pty->master), O_RDWR);
+
+ pty->child_pid = fork();
+ if (pty->child_pid) {
+ close(pty->slave);
+ pty->slave = -1;
+ }
+ else {
+ char *cmd;
+ int old_stderr_fd;
+ FILE *old_stderr;
+
+ old_stderr_fd = dup(2);
+ fcntl(old_stderr_fd, F_SETFD, FD_CLOEXEC);
+ old_stderr = fdopen(old_stderr_fd, "w");
+
+ setsid();
+ ioctl(pty->slave, TIOCSCTTY, NULL);
+
+ close(pty->master);
+
+ dup2(pty->slave, 0);
+ dup2(pty->slave, 1);
+ dup2(pty->slave, 2);
+
+ close(pty->slave);
+
+ cmd = t->cmd;
+ if (!cmd) {
+ cmd = getenv("SHELL");
+ }
+ if (!cmd) {
+ cmd = "/bin/sh";
+ }
+
+ /* XXX should use a different TERM value eventually, but for right now
+ * screen is compatible enough */
+ setenv("TERM", "screen", 1);
+ unsetenv("LINES");
+ unsetenv("COLUMNS");
+
+ execlp(cmd, cmd, (char *)NULL);
+
+ fprintf(old_stderr, "Couldn't run %s: %s\n", cmd, strerror(errno));
+ exit(1);
+ }
+}
+
+void runes_pty_backend_start_loop(RunesTerm *t)
+{
+ void *data;
+
+ data = malloc(sizeof(RunesLoopData));
+ ((RunesLoopData *)data)->req.data = data;
+ ((RunesLoopData *)data)->t = t;
+
+ uv_queue_work(
+ t->loop, data, runes_pty_backend_read, runes_pty_backend_got_data);
+}
+
+void runes_pty_backend_set_window_size(RunesTerm *t)
+{
+ struct winsize size;
+
+ size.ws_row = t->rows;
+ size.ws_col = t->cols;
+ size.ws_xpixel = t->xpixel;
+ size.ws_ypixel = t->ypixel;
+ ioctl(t->pty.master, TIOCSWINSZ, &size);
+}
+
+void runes_pty_backend_write(RunesTerm *t, char *buf, size_t len)
+{
+ write(t->pty.master, buf, len);
+}
+
+void runes_pty_backend_request_close(RunesTerm *t)
+{
+ RunesPtyBackend *pty = &t->pty;
+
+ kill(pty->child_pid, SIGHUP);
+}
+
+void runes_pty_backend_cleanup(RunesTerm *t)
+{
+ RunesPtyBackend *pty = &t->pty;
+
+ close(pty->master);
+}
+
+static void runes_pty_backend_read(uv_work_t *req)
+{
+ RunesLoopData *data = req->data;
+ RunesTerm *t = data->t;
+
+ runes_window_backend_request_flush(t);
+ t->readlen = read(
+ t->pty.master, t->readbuf + t->remaininglen,
+ RUNES_READ_BUFFER_LENGTH - t->remaininglen);
+}
+
+static void runes_pty_backend_got_data(uv_work_t *req, int status)
+{
+ RunesLoopData *data = req->data;
+ RunesTerm *t = data->t;
+
+ UNUSED(status);
+
+ if (t->readlen > 0) {
+ runes_parser_process_string(
+ t, t->readbuf, t->readlen + t->remaininglen);
+ uv_queue_work(
+ t->loop, req, runes_pty_backend_read, runes_pty_backend_got_data);
+ }
+ else {
+ runes_window_backend_request_close(t);
+ free(req);
+ }
+}
diff --git a/src/pty-unix.h b/src/pty-unix.h
new file mode 100644
index 0000000..0d96aa9
--- /dev/null
+++ b/src/pty-unix.h
@@ -0,0 +1,17 @@
+#ifndef _RUNES_PTY_H
+#define _RUNES_PTY_H
+
+struct runes_pty {
+ int master;
+ int slave;
+ pid_t child_pid;
+};
+
+void runes_pty_backend_spawn_subprocess(RunesTerm *t);
+void runes_pty_backend_start_loop(RunesTerm *t);
+void runes_pty_backend_set_window_size(RunesTerm *t);
+void runes_pty_backend_write(RunesTerm *t, char *buf, size_t len);
+void runes_pty_backend_request_close(RunesTerm *t);
+void runes_pty_backend_cleanup(RunesTerm *t);
+
+#endif
diff --git a/src/runes.c b/src/runes.c
new file mode 100644
index 0000000..b47796f
--- /dev/null
+++ b/src/runes.c
@@ -0,0 +1,19 @@
+#include <locale.h>
+#include <stdio.h>
+
+#include "runes.h"
+
+int main (int argc, char *argv[])
+{
+ RunesTerm t;
+
+ setlocale(LC_ALL, "");
+
+ runes_term_init(&t, argc, argv);
+
+ uv_run(t.loop, UV_RUN_DEFAULT);
+
+ runes_term_cleanup(&t);
+
+ return 0;
+}
diff --git a/src/runes.h b/src/runes.h
new file mode 100644
index 0000000..8c2861b
--- /dev/null
+++ b/src/runes.h
@@ -0,0 +1,35 @@
+#ifndef _RUNES_H
+#define _RUNES_H
+
+#include <cairo.h>
+#include <pango/pangocairo.h>
+#include <uv.h>
+
+#define RUNES_READ_BUFFER_LENGTH 4096
+
+struct runes_term;
+struct runes_window;
+struct runes_pty;
+struct runes_loop_data;
+
+typedef struct runes_term RunesTerm;
+typedef struct runes_window RunesWindowBackend;
+typedef struct runes_pty RunesPtyBackend;
+typedef struct runes_loop_data RunesLoopData;
+
+struct runes_loop_data {
+ uv_work_t req;
+ RunesTerm *t;
+};
+
+#include "window-xlib.h"
+#include "pty-unix.h"
+
+#include "term.h"
+#include "display.h"
+#include "parser.h"
+#include "config.h"
+
+#define UNUSED(x) ((void)x)
+
+#endif
diff --git a/src/term.c b/src/term.c
new file mode 100644
index 0000000..fe21752
--- /dev/null
+++ b/src/term.c
@@ -0,0 +1,33 @@
+#include "runes.h"
+
+void runes_term_init(RunesTerm *t, int argc, char *argv[])
+{
+ runes_config_init(t, argc, argv);
+
+ /* doing most of the pty initialization right at the beginning, because
+ * libuv will set up a bunch of state (including potentially things like
+ * spawning threads) when that is initialized, and i'm not really sure how
+ * that interacts with forking */
+ runes_pty_backend_spawn_subprocess(t);
+
+ runes_display_init(t);
+ runes_window_backend_create_window(t, argc, argv);
+
+ runes_display_set_window_size(t);
+
+ /* have to initialize these here instead of in display_init because they
+ * depend on the window size being set */
+ t->scroll_top = 0;
+ t->scroll_bottom = t->rows - 1;
+
+ t->loop = uv_default_loop();
+ runes_window_backend_start_loop(t);
+ runes_pty_backend_start_loop(t);
+}
+
+void runes_term_cleanup(RunesTerm *t)
+{
+ runes_display_cleanup(t);
+ runes_window_backend_cleanup(t);
+ runes_pty_backend_cleanup(t);
+}
diff --git a/src/term.h b/src/term.h
new file mode 100644
index 0000000..8f9d6a4
--- /dev/null
+++ b/src/term.h
@@ -0,0 +1,63 @@
+#ifndef _RUNES_TERM_H
+#define _RUNES_TERM_H
+
+struct runes_term {
+ RunesWindowBackend w;
+ RunesPtyBackend pty;
+
+ cairo_t *cr;
+ cairo_t *backend_cr;
+ cairo_t *alternate_cr;
+ uv_loop_t *loop;
+
+ cairo_pattern_t *cursorcolor;
+
+ cairo_pattern_t *fgdefault;
+ cairo_pattern_t *bgdefault;
+ cairo_pattern_t *colors[8];
+ cairo_pattern_t *brightcolors[8];
+
+ int fgcolor;
+ int bgcolor;
+
+ int row;
+ int col;
+ int saved_row;
+ int saved_col;
+ int scroll_top;
+ int scroll_bottom;
+
+ int rows;
+ int cols;
+ int xpixel;
+ int ypixel;
+ int fontx;
+ int fonty;
+ int default_rows;
+ int default_cols;
+
+ char *cmd;
+
+ char *font_name;
+ PangoLayout *layout;
+
+ char readbuf[RUNES_READ_BUFFER_LENGTH];
+ int readlen;
+ int remaininglen;
+
+ char bold_is_bright;
+ char bold_is_bold;
+ char bold;
+ char inverse;
+ char hide_cursor;
+ char unfocused;
+ char audible_bell;
+
+ char application_keypad;
+ char application_cursor;
+};
+
+void runes_term_init(RunesTerm *t, int argc, char *argv[]);
+void runes_term_cleanup(RunesTerm *t);
+
+#endif
diff --git a/src/window-xlib.c b/src/window-xlib.c
new file mode 100644
index 0000000..0051fae
--- /dev/null
+++ b/src/window-xlib.c
@@ -0,0 +1,532 @@
+#include <cairo-xlib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+#include <X11/cursorfont.h>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+
+#include "runes.h"
+
+static char *atom_names[RUNES_NUM_ATOMS] = {
+ "WM_DELETE_WINDOW",
+ "_NET_WM_PING",
+ "_NET_WM_PID",
+ "_NET_WM_ICON_NAME",
+ "_NET_WM_NAME",
+ "UTF8_STRING",
+ "WM_PROTOCOLS",
+ "RUNES_FLUSH",
+ "RUNES_VISUAL_BELL",
+ "RUNES_AUDIBLE_BELL"
+};
+
+struct function_key {
+ KeySym sym;
+ char *str;
+ size_t len;
+};
+
+#define RUNES_KEY(sym, str) { sym, str, sizeof(str) - 1 }
+static struct function_key keys[] = {
+ RUNES_KEY(XK_Up, "\e[A"),
+ RUNES_KEY(XK_Down, "\e[B"),
+ RUNES_KEY(XK_Right, "\e[C"),
+ RUNES_KEY(XK_Left, "\e[D"),
+ RUNES_KEY(XK_Page_Up, "\e[5~"),
+ RUNES_KEY(XK_Page_Down, "\e[6~"),
+ RUNES_KEY(XK_Home, "\e[H"),
+ RUNES_KEY(XK_End, "\e[F"),
+ RUNES_KEY(XK_F1, "\eOP"),
+ RUNES_KEY(XK_F2, "\eOQ"),
+ RUNES_KEY(XK_F3, "\eOR"),
+ RUNES_KEY(XK_F4, "\eOS"),
+ RUNES_KEY(XK_F5, "\e[15~"),
+ RUNES_KEY(XK_F6, "\e[17~"),
+ RUNES_KEY(XK_F7, "\e[18~"),
+ RUNES_KEY(XK_F8, "\e[19~"),
+ RUNES_KEY(XK_F9, "\e[20~"),
+ RUNES_KEY(XK_F10, "\e[21~"),
+ RUNES_KEY(XK_F11, "\e[23~"),
+ RUNES_KEY(XK_F12, "\e[24~"),
+ RUNES_KEY(XK_F13, "\e[25~"),
+ RUNES_KEY(XK_F14, "\e[26~"),
+ RUNES_KEY(XK_F15, "\e[28~"),
+ RUNES_KEY(XK_F16, "\e[29~"),
+ RUNES_KEY(XK_F17, "\e[31~"),
+ RUNES_KEY(XK_F18, "\e[32~"),
+ RUNES_KEY(XK_F19, "\e[33~"),
+ RUNES_KEY(XK_F20, "\e[34~"),
+ /* XXX keypad keys need to go here too */
+ RUNES_KEY(XK_VoidSymbol, "")
+};
+
+static struct function_key application_keypad_keys[] = {
+ /* XXX i don't have a keypad on my laptop, need to get one for testing */
+ RUNES_KEY(XK_VoidSymbol, "")
+};
+
+static struct function_key application_cursor_keys[] = {
+ RUNES_KEY(XK_Up, "\eOA"),
+ RUNES_KEY(XK_Down, "\eOB"),
+ RUNES_KEY(XK_Right, "\eOC"),
+ RUNES_KEY(XK_Left, "\eOD"),
+ /* XXX home/end? */
+ RUNES_KEY(XK_VoidSymbol, "")
+};
+#undef RUNES_KEY
+
+static void runes_window_backend_get_next_event(uv_work_t *req);
+static void runes_window_backend_process_event(uv_work_t *req, int status);
+static void runes_window_backend_resize_window(
+ RunesTerm *t, int width, int height);
+static void runes_window_backend_flush(RunesTerm *t);
+static void runes_window_backend_draw_cursor(RunesTerm *t);
+static void runes_window_backend_set_urgent(RunesTerm *t);
+static void runes_window_backend_clear_urgent(RunesTerm *t);
+
+void runes_window_backend_create_window(RunesTerm *t, int argc, char *argv[])
+{
+ RunesWindowBackend *w = &t->w;
+ pid_t pid;
+ XClassHint class_hints = { "runes", "runes" };
+ XWMHints wm_hints;
+ XSizeHints normal_hints;
+ unsigned long white;
+ XIM im;
+ Cursor cursor;
+ XColor cursor_fg, cursor_bg;
+ Visual *vis;
+ cairo_surface_t *surface;
+
+ wm_hints.flags = InputHint | StateHint;
+ wm_hints.input = True;
+ wm_hints.initial_state = NormalState;
+
+ normal_hints.flags = PMinSize | PResizeInc | PBaseSize;
+
+ normal_hints.min_width = t->fontx;
+ normal_hints.min_height = t->fonty;
+ normal_hints.width_inc = t->fontx;
+ normal_hints.height_inc = t->fonty;
+ normal_hints.base_width = t->fontx * t->default_cols;
+ normal_hints.base_height = t->fonty * t->default_rows;
+
+ XInitThreads();
+
+ w->dpy = XOpenDisplay(NULL);
+ white = WhitePixel(w->dpy, DefaultScreen(w->dpy));
+ w->w = XCreateSimpleWindow(
+ w->dpy, DefaultRootWindow(w->dpy),
+ 0, 0, normal_hints.base_width, normal_hints.base_height,
+ 0, white, white);
+
+ XSetLocaleModifiers("");
+ im = XOpenIM(w->dpy, NULL, NULL, NULL);
+ w->ic = XCreateIC(
+ im,
+ XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
+ XNClientWindow, w->w,
+ XNFocusWindow, w->w,
+ NULL
+ );
+ if (w->ic == NULL) {
+ fprintf(stderr, "failed\n");
+ exit(1);
+ }
+
+ XInternAtoms(w->dpy, atom_names, RUNES_NUM_ATOMS, False, w->atoms);
+ XSetWMProtocols(w->dpy, w->w, w->atoms, RUNES_NUM_PROTOCOL_ATOMS);
+
+ Xutf8SetWMProperties(
+ w->dpy, w->w, "runes", "runes", argv, argc,
+ &normal_hints, &wm_hints, &class_hints);
+
+ pid = getpid();
+ XChangeProperty(
+ w->dpy, w->w, w->atoms[RUNES_ATOM_NET_WM_PID],
+ XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&pid, 1);
+
+ runes_window_backend_set_icon_name(t, "runes", 5);
+ runes_window_backend_set_window_title(t, "runes", 5);
+
+ cursor = XCreateFontCursor(w->dpy, XC_xterm);
+ cursor_fg.red = cursor_fg.green = cursor_fg.blue = 65535;
+ cursor_bg.red = cursor_bg.green = cursor_bg.blue = 0;
+ XRecolorCursor(w->dpy, cursor, &cursor_fg, &cursor_bg);
+ XDefineCursor(w->dpy, w->w, cursor);
+
+ vis = DefaultVisual(w->dpy, DefaultScreen(w->dpy));
+ surface = cairo_xlib_surface_create(
+ w->dpy, w->w, vis, normal_hints.base_width, normal_hints.base_height);
+ t->backend_cr = cairo_create(surface);
+ cairo_surface_destroy(surface);
+
+ XMapWindow(w->dpy, w->w);
+}
+
+void runes_window_backend_start_loop(RunesTerm *t)
+{
+ RunesWindowBackend *w = &t->w;
+ unsigned long mask;
+ void *data;
+
+ XGetICValues(w->ic, XNFilterEvents, &mask, NULL);
+ XSelectInput(
+ w->dpy, w->w,
+ mask|KeyPressMask|ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|PointerMotionHintMask|EnterWindowMask|LeaveWindowMask|StructureNotifyMask|ExposureMask|FocusChangeMask);
+ XSetICFocus(w->ic);
+
+ data = malloc(sizeof(RunesXlibLoopData));
+ ((RunesLoopData *)data)->req.data = data;
+ ((RunesLoopData *)data)->t = t;
+
+ uv_queue_work(
+ t->loop, data,
+ runes_window_backend_get_next_event,
+ runes_window_backend_process_event);
+}
+
+void runes_window_backend_request_flush(RunesTerm *t)
+{
+ XEvent e;
+
+ e.xclient.type = ClientMessage;
+ e.xclient.window = t->w.w;
+ e.xclient.format = 32;
+ e.xclient.data.l[0] = t->w.atoms[RUNES_ATOM_RUNES_FLUSH];
+
+ XSendEvent(t->w.dpy, t->w.w, False, NoEventMask, &e);
+ XLockDisplay(t->w.dpy);
+ XFlush(t->w.dpy);
+ XUnlockDisplay(t->w.dpy);
+}
+
+void runes_window_backend_request_visual_bell(RunesTerm *t)
+{
+ XEvent e;
+
+ e.xclient.type = ClientMessage;
+ e.xclient.window = t->w.w;
+ e.xclient.format = 32;
+ e.xclient.data.l[0] = t->w.atoms[RUNES_ATOM_RUNES_VISUAL_BELL];
+
+ XSendEvent(t->w.dpy, t->w.w, False, NoEventMask, &e);
+ XLockDisplay(t->w.dpy);
+ XFlush(t->w.dpy);
+ XUnlockDisplay(t->w.dpy);
+}
+
+void runes_window_backend_request_audible_bell(RunesTerm *t)
+{
+ XEvent e;
+
+ e.xclient.type = ClientMessage;
+ e.xclient.window = t->w.w;
+ e.xclient.format = 32;
+ e.xclient.data.l[0] = t->w.atoms[RUNES_ATOM_RUNES_AUDIBLE_BELL];
+
+ XSendEvent(t->w.dpy, t->w.w, False, NoEventMask, &e);
+ XLockDisplay(t->w.dpy);
+ XFlush(t->w.dpy);
+ XUnlockDisplay(t->w.dpy);
+}
+
+void runes_window_backend_request_close(RunesTerm *t)
+{
+ XEvent e;
+
+ e.xclient.type = ClientMessage;
+ e.xclient.window = t->w.w;
+ e.xclient.message_type = t->w.atoms[RUNES_ATOM_WM_PROTOCOLS];
+ e.xclient.format = 32;
+ e.xclient.data.l[0] = t->w.atoms[RUNES_ATOM_WM_DELETE_WINDOW];
+ e.xclient.data.l[1] = CurrentTime;
+
+ XSendEvent(t->w.dpy, t->w.w, False, NoEventMask, &e);
+}
+
+void runes_window_backend_get_size(RunesTerm *t, int *xpixel, int *ypixel)
+{
+ cairo_surface_t *surface;
+
+ surface = cairo_get_target(t->backend_cr);
+ *xpixel = cairo_xlib_surface_get_width(surface);
+ *ypixel = cairo_xlib_surface_get_height(surface);
+}
+
+void runes_window_backend_set_icon_name(RunesTerm *t, char *name, size_t len)
+{
+ RunesWindowBackend *w = &t->w;
+
+ XChangeProperty(
+ w->dpy, w->w, XA_WM_ICON_NAME,
+ w->atoms[RUNES_ATOM_UTF8_STRING], 8, PropModeReplace,
+ (unsigned char *)name, len);
+ XChangeProperty(
+ w->dpy, w->w, w->atoms[RUNES_ATOM_NET_WM_ICON_NAME],
+ w->atoms[RUNES_ATOM_UTF8_STRING], 8, PropModeReplace,
+ (unsigned char *)name, len);
+}
+
+void runes_window_backend_set_window_title(
+ RunesTerm *t, char *name, size_t len)
+{
+ RunesWindowBackend *w = &t->w;
+
+ XChangeProperty(
+ w->dpy, w->w, XA_WM_NAME,
+ w->atoms[RUNES_ATOM_UTF8_STRING], 8, PropModeReplace,
+ (unsigned char *)name, len);
+ XChangeProperty(
+ w->dpy, w->w, w->atoms[RUNES_ATOM_NET_WM_NAME],
+ w->atoms[RUNES_ATOM_UTF8_STRING], 8, PropModeReplace,
+ (unsigned char *)name, len);
+}
+
+void runes_window_backend_cleanup(RunesTerm *t)
+{
+ RunesWindowBackend *w = &t->w;
+ XIM im;
+
+ cairo_destroy(t->backend_cr);
+ im = XIMOfIC(w->ic);
+ XDestroyIC(w->ic);
+ XCloseIM(im);
+ XDestroyWindow(w->dpy, w->w);
+ XCloseDisplay(w->dpy);
+}
+
+static void runes_window_backend_get_next_event(uv_work_t *req)
+{
+ RunesXlibLoopData *data;
+
+ data = (RunesXlibLoopData *)req->data;
+ XNextEvent(data->data.t->w.dpy, &data->e);
+}
+
+static void runes_window_backend_process_event(uv_work_t *req, int status)
+{
+ RunesXlibLoopData *data = req->data;
+ XEvent *e = &data->e;
+ RunesTerm *t = data->data.t;
+ RunesWindowBackend *w = &t->w;
+ int should_close = 0;
+
+ UNUSED(status);
+
+ if (!XFilterEvent(e, None)) {
+ switch (e->type) {
+ case KeyPress: {
+ char *buf = NULL;
+ size_t len = 8;
+ KeySym sym;
+ Status s;
+ size_t chars;
+
+ buf = malloc(len);
+
+ for (;;) {
+ chars = Xutf8LookupString(
+ w->ic, &e->xkey, buf, len - 1, &sym, &s);
+ if (s == XBufferOverflow) {
+ len = chars + 1;
+ buf = realloc(buf, len);
+ continue;
+ }
+ break;
+ }
+
+ switch (s) {
+ case XLookupChars:
+ case XLookupBoth:
+ runes_pty_backend_write(t, buf, chars);
+ break;
+ case XLookupKeySym: {
+ struct function_key *key;
+
+ if (t->application_keypad) {
+ if (t->application_cursor) {
+ key = &application_cursor_keys[0];
+ while (key->sym != XK_VoidSymbol) {
+ if (key->sym == sym) {
+ break;
+ }
+ key++;
+ }
+ if (key->sym != XK_VoidSymbol) {
+ runes_pty_backend_write(t, key->str, key->len);
+ break;
+ }
+ }
+ key = &application_keypad_keys[0];
+ while (key->sym != XK_VoidSymbol) {
+ if (key->sym == sym) {
+ break;
+ }
+ key++;
+ }
+ if (key->sym != XK_VoidSymbol) {
+ runes_pty_backend_write(t, key->str, key->len);
+ break;
+ }
+ }
+ key = &keys[0];
+ while (key->sym != XK_VoidSymbol) {
+ if (key->sym == sym) {
+ break;
+ }
+ key++;
+ }
+ if (key->sym != XK_VoidSymbol) {
+ runes_pty_backend_write(t, key->str, key->len);
+ break;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ free(buf);
+ break;
+ }
+ case Expose:
+ runes_window_backend_flush(t);
+ break;
+ case ConfigureNotify:
+ while (XCheckTypedWindowEvent(w->dpy, w->w, ConfigureNotify, e));
+ runes_window_backend_resize_window(
+ t, e->xconfigure.width, e->xconfigure.height);
+ break;
+ case FocusIn:
+ runes_window_backend_clear_urgent(t);
+ runes_display_focus_in(t);
+ runes_window_backend_flush(t);
+ break;
+ case FocusOut:
+ runes_display_focus_out(t);
+ runes_window_backend_flush(t);
+ break;
+ case ClientMessage: {
+ Atom a = e->xclient.data.l[0];
+ if (a == w->atoms[RUNES_ATOM_WM_DELETE_WINDOW]) {
+ should_close = 1;
+ }
+ else if (a == w->atoms[RUNES_ATOM_NET_WM_PING]) {
+ e->xclient.window = DefaultRootWindow(w->dpy);
+ XSendEvent(
+ w->dpy, e->xclient.window, False,
+ SubstructureNotifyMask | SubstructureRedirectMask,
+ e
+ );
+ }
+ else if (a == w->atoms[RUNES_ATOM_RUNES_FLUSH]) {
+ runes_window_backend_flush(t);
+ }
+ else if (a == w->atoms[RUNES_ATOM_RUNES_VISUAL_BELL]) {
+ cairo_pattern_t *white;
+ struct timespec tm = { 0, 20000000 };
+
+ runes_window_backend_set_urgent(t);
+ white = cairo_pattern_create_rgb(1.0, 1.0, 1.0);
+ cairo_set_source(t->backend_cr, white);
+ cairo_paint(t->backend_cr);
+ cairo_pattern_destroy(white);
+ cairo_surface_flush(cairo_get_target(t->backend_cr));
+ XFlush(w->dpy);
+ nanosleep(&tm, NULL);
+ runes_window_backend_flush(t);
+ }
+ else if (a == w->atoms[RUNES_ATOM_RUNES_AUDIBLE_BELL]) {
+ XBell(w->dpy, 0);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ if (!should_close) {
+ uv_queue_work(
+ t->loop, req, runes_window_backend_get_next_event,
+ runes_window_backend_process_event);
+ }
+ else {
+ runes_pty_backend_request_close(t);
+ free(req);
+ }
+}
+
+static void runes_window_backend_resize_window(
+ RunesTerm *t, int width, int height)
+{
+ /* XXX no idea why shrinking the window dimensions to 0 makes xlib think
+ * that the dimension is 65535 */
+ if (width < 1 || width >= 65535) {
+ width = 1;
+ }
+ if (height < 1 || height >= 65535) {
+ height = 1;
+ }
+
+ if (width != t->xpixel || height != t->ypixel) {
+ cairo_xlib_surface_set_size(
+ cairo_get_target(t->backend_cr), width, height);
+ runes_display_set_window_size(t);
+ }
+}
+
+static void runes_window_backend_flush(RunesTerm *t)
+{
+ cairo_set_source_surface(t->backend_cr, cairo_get_target(t->cr), 0.0, 0.0);
+ cairo_paint(t->backend_cr);
+ runes_window_backend_draw_cursor(t);
+ cairo_surface_flush(cairo_get_target(t->backend_cr));
+}
+
+static void runes_window_backend_draw_cursor(RunesTerm *t)
+{
+ if (!t->hide_cursor) {
+ cairo_save(t->backend_cr);
+ cairo_set_source(t->backend_cr, t->cursorcolor);
+ if (t->unfocused) {
+ cairo_set_line_width(t->backend_cr, 1);
+ cairo_rectangle(
+ t->backend_cr,
+ t->col * t->fontx + 0.5, t->row * t->fonty + 0.5,
+ t->fontx, t->fonty);
+ cairo_stroke(t->backend_cr);
+ }
+ else {
+ cairo_rectangle(
+ t->backend_cr,
+ t->col * t->fontx, t->row * t->fonty,
+ t->fontx, t->fonty);
+ cairo_fill(t->backend_cr);
+ }
+ cairo_restore(t->backend_cr);
+ }
+}
+
+static void runes_window_backend_set_urgent(RunesTerm *t)
+{
+ XWMHints *hints;
+
+ hints = XGetWMHints(t->w.dpy, t->w.w);
+ hints->flags |= XUrgencyHint;
+ XSetWMHints(t->w.dpy, t->w.w, hints);
+ XFree(hints);
+}
+
+static void runes_window_backend_clear_urgent(RunesTerm *t)
+{
+ XWMHints *hints;
+
+ hints = XGetWMHints(t->w.dpy, t->w.w);
+ hints->flags &= ~XUrgencyHint;
+ XSetWMHints(t->w.dpy, t->w.w, hints);
+ XFree(hints);
+}
diff --git a/src/window-xlib.h b/src/window-xlib.h
new file mode 100644
index 0000000..c7b8960
--- /dev/null
+++ b/src/window-xlib.h
@@ -0,0 +1,46 @@
+#ifndef _RUNES_WINDOW_XLIB_H
+#define _RUNES_XLIB_H
+
+#include <X11/Xlib.h>
+
+enum runes_atoms {
+ RUNES_ATOM_WM_DELETE_WINDOW,
+ RUNES_ATOM_NET_WM_PING,
+ RUNES_NUM_PROTOCOL_ATOMS,
+ RUNES_ATOM_NET_WM_PID = 2,
+ RUNES_ATOM_NET_WM_ICON_NAME,
+ RUNES_ATOM_NET_WM_NAME,
+ RUNES_ATOM_UTF8_STRING,
+ RUNES_ATOM_WM_PROTOCOLS,
+ RUNES_ATOM_RUNES_FLUSH,
+ RUNES_ATOM_RUNES_VISUAL_BELL,
+ RUNES_ATOM_RUNES_AUDIBLE_BELL,
+ RUNES_NUM_ATOMS
+};
+
+struct runes_window {
+ Display *dpy;
+ Window w;
+ XIC ic;
+
+ Atom atoms[RUNES_NUM_ATOMS];
+};
+
+typedef struct {
+ RunesLoopData data;
+ XEvent e;
+} RunesXlibLoopData;
+
+void runes_window_backend_create_window(RunesTerm *t, int argc, char *argv[]);
+void runes_window_backend_start_loop(RunesTerm *t);
+void runes_window_backend_request_flush(RunesTerm *t);
+void runes_window_backend_request_visual_bell(RunesTerm *t);
+void runes_window_backend_request_audible_bell(RunesTerm *t);
+void runes_window_backend_request_close(RunesTerm *t);
+void runes_window_backend_get_size(RunesTerm *t, int *xpixel, int *ypixel);
+void runes_window_backend_set_icon_name(RunesTerm *t, char *name, size_t len);
+void runes_window_backend_set_window_title(
+ RunesTerm *t, char *name, size_t len);
+void runes_window_backend_cleanup(RunesTerm *t);
+
+#endif