tsm: remove and depend on libtsm

TSM was extracted from kmscon sources so it can more easily be used by
other emulators. It is available at:
  http://cgit.freedesktop.org/~dvdhrm/libtsm

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
This commit is contained in:
David Herrmann 2013-10-23 16:55:59 +02:00
parent 972ec107cf
commit 96b28e953d
20 changed files with 32 additions and 6529 deletions

1
.gitignore vendored
View File

@ -19,7 +19,6 @@ configure
*.tar.xz
libtool
libeloop.pc
libtsm.pc
libuvt.pc
libuterm.pc
m4/

View File

@ -11,10 +11,6 @@ LIBELOOP_CURRENT = 1
LIBELOOP_REVISION = 0
LIBELOOP_AGE = 0
LIBTSM_CURRENT = 1
LIBTSM_REVISION = 0
LIBTSM_AGE = 0
LIBUVT_CURRENT = 1
LIBUVT_REVISION = 0
LIBUVT_AGE = 0
@ -44,11 +40,9 @@ EXTRA_DIST = \
docs/kmscon.service \
docs/kmsconvt@.service \
docs/pc/libeloop.pc.in \
docs/pc/libtsm.pc.in \
docs/pc/libuvt.pc.in \
docs/pc/libuterm.pc.in \
docs/sym/libeloop.sym \
docs/sym/libtsm.sym \
docs/sym/libuvt.sym \
docs/sym/libuterm.sym
CLEANFILES =
@ -242,45 +236,6 @@ libeloop_la_CPPFLAGS += $(DBUS_CFLAGS)
libeloop_la_LIBADD += $(DBUS_LIBS)
endif
#
# libtsm
# The Terminal-emulator State Machine is a library that implements the whole VTE
# layer and everything related to it. It has no external dependencies so it can
# be used to implement any kind of terminal emulator or debugger.
#
if BUILD_ENABLE_TSM
lib_LTLIBRARIES += libtsm.la
include_HEADERS += \
src/tsm_screen.h \
src/tsm_unicode.h \
src/tsm_vte.h
pkgconfig_DATA += docs/pc/libtsm.pc
endif
libtsm_la_SOURCES = \
src/tsm_screen.h \
src/tsm_screen.c \
src/tsm_unicode.h \
src/tsm_unicode.c \
src/tsm_vte.h \
src/tsm_vte.c \
src/tsm_vte_charsets.c \
external/wcwidth.h \
external/wcwidth.c
libtsm_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
$(XKBCOMMON_CFLAGS)
libtsm_la_LIBADD = \
$(XKBCOMMON_LIBS) \
libshl.la
EXTRA_libtsm_la_DEPENDENCIES = ${top_srcdir}/docs/sym/libtsm.sym
libtsm_la_LDFLAGS = \
$(AM_LDFLAGS) \
-version-info $(LIBTSM_CURRENT):$(LIBTSM_REVISION):$(LIBTSM_AGE) \
-Wl,--version-script="$(top_srcdir)/docs/sym/libtsm.sym"
#
# libuvt
# Implementation of Virtual Terminals in user-space with the help of CUSE/FUSE
@ -506,11 +461,12 @@ mod_freetype2_la_SOURCES = \
src/kmscon_mod_freetype2.c
mod_freetype2_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
$(FREETYPE2_CFLAGS)
$(FREETYPE2_CFLAGS) \
$(TSM_CFLAGS)
mod_freetype2_la_LIBADD = \
$(FREETYPE2_LIBS) \
$(TSM_LIBS) \
-lpthread \
libtsm.la \
libshl.la
mod_freetype2_la_LDFLAGS = \
$(AM_LDFLAGS) \
@ -527,11 +483,12 @@ mod_pango_la_SOURCES = \
src/kmscon_mod_pango.c
mod_pango_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
$(PANGO_CFLAGS)
$(PANGO_CFLAGS) \
$(TSM_CFLAGS)
mod_pango_la_LIBADD = \
$(PANGO_LIBS) \
$(TSM_LIBS) \
-lpthread \
libtsm.la \
libshl.la
mod_pango_la_LDFLAGS = \
$(AM_LDFLAGS) \
@ -657,9 +614,11 @@ nodist_kmscon_SOURCES =
kmscon_CPPFLAGS = \
$(AM_CPPFLAGS) \
$(XKBCOMMON_CFLAGS)
$(XKBCOMMON_CFLAGS) \
$(TSM_CFLAGS)
kmscon_LDADD = \
$(XKBCOMMON_LIBS) \
$(TSM_LIBS) \
libeloop.la \
libuterm.la \
libshl.la \
@ -675,7 +634,6 @@ endif
if BUILD_ENABLE_SESSION_TERMINAL
kmscon_SOURCES += src/kmscon_terminal.c
kmscon_LDADD += libtsm.la
endif
#

2
README
View File

@ -10,6 +10,7 @@ Website:
== Requirements ==
Kmscon requires the following software:
- libtsm: terminal emulator state machine
- libudev: providing input, video, etc. device hotplug support (>=v172)
- libxkbcommon: providing internationalized keyboard handling
@ -93,7 +94,6 @@ Released tarballs can be found at:
on the command line:
--enable-kmscon: Build kmscon application [default: on]
--enable-eloop: Build eloop event loop library [default: off]
--enable-tsm: Build TSM terminal state-machine library [default: off]
--enable-uterm: Build uterm library [default: off]
--enable-uvt: Build UVT library [default: off]

View File

@ -120,6 +120,11 @@ PKG_CHECK_MODULES([PIXMAN], [pixman-1],
AC_SUBST(PIXMAN_CFLAGS)
AC_SUBST(PIXMAN_LIBS)
PKG_CHECK_MODULES([TSM], [libtsm],
[have_tsm=yes], [have_tsm=no])
AC_SUBST(TSM_CFLAGS)
AC_SUBST(TSM_LIBS)
#
# Parse arguments
# This parses all arguments that are given via "--enable-XY" or "--with-XY" and
@ -149,18 +154,6 @@ elif test "x$enable_eloop" = "x" ; then
fi
AC_MSG_RESULT([$enable_eloop])
# TSM
AC_MSG_CHECKING([whether user wants TSM])
AC_ARG_ENABLE([tsm],
[AS_HELP_STRING([--enable-tsm],
[build tsm library])])
if test "x$enable_all" = "xyes" ; then
enable_tsm="yes"
elif test "x$enable_tsm" = "x" ; then
enable_tsm="no (default)"
fi
AC_MSG_RESULT([$enable_tsm])
# UVT
AC_MSG_CHECKING([whether user wants UVT])
AC_ARG_ENABLE([uvt],
@ -465,25 +458,6 @@ else
eloop_missing="enable-eloop"
fi
# TSM
tsm_avail=no
tsm_missing=""
if test ! "x$enable_tsm" = "xno" ; then
tsm_avail=yes
if test "x$have_xkbcommon" = "xno" ; then
tsm_avail=no
tsm_missing="libxkbcommon"
fi
if test "x$tsm_avail" = "xno" ; then
if test "x$enable_tsm" = "xyes" ; then
AC_ERROR([missing for TSM: $tsm_missing])
fi
fi
else
tsm_missing="enable-tsm"
fi
# UVT
uvt_avail=no
uvt_missing=""
@ -737,9 +711,9 @@ session_terminal_avail=no
session_terminal_missing=""
if test ! "x$enable_session_terminal" = "xno" ; then
session_terminal_avail=yes
if test "x$tsm_avail" = "xno" ; then
if test "x$have_tsm" = "xno" ; then
session_terminal_avail=no
session_terminal_missing="$tsm_missing"
session_terminal_missing="libtsm"
fi
if test "x$session_terminal_avail" = "xno" ; then
@ -761,9 +735,9 @@ if test ! "x$enable_kmscon" = "xno" ; then
kmscon_missing="$eloop_missing,$kmscon_missing"
fi
if test "x$tsm_avail" = "xno" ; then
if test "x$have_tsm" = "xno" ; then
kmscon_avail=no
kmscon_missing="$tsm_missing,$kmscon_missing"
kmscon_missing="libtsm,$kmscon_missing"
fi
if test "x$uterm_avail" = "xno" ; then
@ -803,7 +777,6 @@ session_terminal_enabled=no
if test "x$session_terminal_avail" = "xyes" ; then
if test "x${enable_session_terminal% *}" = "xyes" ; then
session_terminal_enabled=yes
enable_tsm=yes
fi
fi
@ -927,14 +900,6 @@ if test "x$uvt_avail" = "xyes" ; then
fi
fi
# tsm
tsm_enabled=no
if test "x$tsm_avail" = "xyes" ; then
if test "x${enable_tsm% *}" = "xyes" ; then
tsm_enabled=yes
fi
fi
# eloop
eloop_enabled=no
if test "x$eloop_avail" = "xyes" ; then
@ -997,10 +962,6 @@ AM_CONDITIONAL([BUILD_ENABLE_ELOOP_DBUS],
AM_CONDITIONAL([BUILD_ENABLE_ELOOP],
[test "x$eloop_enabled" = "xyes"])
# TSM
AM_CONDITIONAL([BUILD_ENABLE_TSM],
[test "x$tsm_enabled" = "xyes"])
# UVT
AM_CONDITIONAL([BUILD_ENABLE_UVT],
[test "x$uvt_enabled" = "xyes"])
@ -1202,7 +1163,6 @@ fi
AC_CONFIG_FILES([Makefile
docs/pc/libeloop.pc
docs/pc/libtsm.pc
docs/pc/libuvt.pc
docs/pc/libuterm.pc])
AC_OUTPUT
@ -1223,7 +1183,6 @@ AC_MSG_NOTICE([Build configuration:
Applications and Libraries:
kmscon: $kmscon_enabled ($kmscon_avail: $kmscon_missing)
uterm: $uterm_enabled ($uterm_avail: $uterm_missing)
tsm: $tsm_enabled ($tsm_avail: $tsm_missing)
uvt: $uvt_enabled ($uvt_avail: $uvt_missing)
eloop: $eloop_enabled ($eloop_avail: $eloop_missing)

View File

@ -1,11 +0,0 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: tsm
Description: Terminal-emulator State Machine
URL: @PACKAGE_URL@
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -ltsm
Cflags: -I${includedir}

View File

@ -1,137 +0,0 @@
/***
* libtsm - Terminal-Emulator State Machine
*
* Copyright (c) 2012-2013 David Herrmann <dh.herrmann@googlemail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
***/
LIBTSM_1 {
global:
tsm_symbol_default;
local:
*;
};
LIBTSM_2 {
global:
tsm_symbol_table_new;
tsm_symbol_table_ref;
tsm_symbol_table_unref;
tsm_symbol_make;
tsm_symbol_append;
tsm_symbol_get;
tsm_symbol_get_width;
tsm_ucs4_get_width;
tsm_ucs4_to_utf8;
tsm_ucs4_to_utf8_alloc;
tsm_utf8_mach_new;
tsm_utf8_mach_free;
tsm_utf8_mach_feed;
tsm_utf8_mach_get;
tsm_utf8_mach_reset;
tsm_screen_new;
tsm_screen_ref;
tsm_screen_unref;
tsm_screen_set_opts;
tsm_screen_reset_opts;
tsm_screen_get_opts;
tsm_screen_get_width;
tsm_screen_get_height;
tsm_screen_resize;
tsm_screen_set_margins;
tsm_screen_set_max_sb;
tsm_screen_clear_sb;
tsm_screen_sb_up;
tsm_screen_sb_down;
tsm_screen_sb_page_up;
tsm_screen_sb_page_down;
tsm_screen_sb_reset;
tsm_screen_set_def_attr;
tsm_screen_reset;
tsm_screen_set_flags;
tsm_screen_reset_flags;
tsm_screen_get_flags;
tsm_screen_get_cursor_x;
tsm_screen_get_cursor_y;
tsm_screen_set_tabstop;
tsm_screen_reset_tabstop;
tsm_screen_reset_all_tabstops;
tsm_screen_write;
tsm_screen_newline;
tsm_screen_scroll_up;
tsm_screen_scroll_down;
tsm_screen_move_to;
tsm_screen_move_up;
tsm_screen_move_down;
tsm_screen_move_left;
tsm_screen_move_right;
tsm_screen_move_line_end;
tsm_screen_move_line_home;
tsm_screen_tab_right;
tsm_screen_tab_left;
tsm_screen_insert_lines;
tsm_screen_delete_lines;
tsm_screen_insert_chars;
tsm_screen_delete_chars;
tsm_screen_erase_cursor;
tsm_screen_erase_chars;
tsm_screen_erase_cursor_to_end;
tsm_screen_erase_home_to_cursor;
tsm_screen_erase_current_line;
tsm_screen_erase_screen_to_cursor;
tsm_screen_erase_cursor_to_screen;
tsm_screen_erase_screen;
tsm_screen_selection_reset;
tsm_screen_selection_start;
tsm_screen_selection_target;
tsm_screen_selection_copy;
tsm_screen_draw;
tsm_vte_unicode_lower;
tsm_vte_new;
tsm_vte_ref;
tsm_vte_unref;
tsm_vte_set_palette;
tsm_vte_reset;
tsm_vte_hard_reset;
tsm_vte_input;
tsm_vte_handle_keyboard;
tsm_vte_unicode_upper;
tsm_vte_dec_supplemental_graphics;
tsm_vte_dec_special_graphics;
} LIBTSM_1;

View File

@ -40,6 +40,7 @@
#include <fontconfig/fontconfig.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include <libtsm.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdlib.h>
@ -48,7 +49,6 @@
#include "shl_dlist.h"
#include "shl_hashtable.h"
#include "shl_log.h"
#include "tsm_unicode.h"
#include "uterm_video.h"
#define LOG_SUBSYSTEM "font_freetype2"

View File

@ -45,6 +45,7 @@
#include <errno.h>
#include <glib.h>
#include <libtsm.h>
#include <pango/pango.h>
#include <pango/pangoft2.h>
#include <pthread.h>
@ -55,7 +56,6 @@
#include "shl_dlist.h"
#include "shl_hashtable.h"
#include "shl_log.h"
#include "tsm_unicode.h"
#include "uterm_video.h"
#define LOG_SUBSYSTEM "font_pango"

View File

@ -597,7 +597,6 @@ int kmscon_conf_new(struct conf_ctx **out)
CONF_OPTION_BOOL(0, "hwaccel", &conf->hwaccel, false),
CONF_OPTION(0, 0, "gpus", &conf_gpus, NULL, NULL, NULL, &conf->gpus, KMSCON_GPU_ALL),
CONF_OPTION_STRING(0, "render-engine", &conf->render_engine, NULL),
CONF_OPTION_BOOL(0, "render-timing", &conf->render_timing, false),
/* Font Options */
CONF_OPTION_STRING(0, "font-engine", &conf->font_engine, "pango"),

View File

@ -142,8 +142,6 @@ struct kmscon_conf_t {
unsigned int gpus;
/* render engine */
char *render_engine;
/* print render-engine timing information */
bool render_timing;
/* Font Options */
/* font engine */

View File

@ -32,6 +32,7 @@
#include <errno.h>
#include <inttypes.h>
#include <libtsm.h>
#include <stdlib.h>
#include <string.h>
#include "conf.h"
@ -43,8 +44,6 @@
#include "shl_dlist.h"
#include "shl_log.h"
#include "text.h"
#include "tsm_screen.h"
#include "tsm_vte.h"
#include "uterm_input.h"
#include "uterm_video.h"
@ -121,8 +120,11 @@ static void do_redraw_screen(struct screen *scr)
scr->pending = false;
do_clear_margins(scr);
tsm_screen_draw(scr->term->console, kmscon_text_prepare_cb,
kmscon_text_draw_cb, kmscon_text_render_cb, scr->txt);
kmscon_text_prepare(scr->txt);
tsm_screen_draw(scr->term->console, kmscon_text_draw_cb, scr->txt);
kmscon_text_render(scr->txt);
ret = uterm_display_swap(scr->disp, false);
if (ret) {
log_warning("cannot swap display %p", scr->disp);
@ -613,9 +615,6 @@ int kmscon_terminal_register(struct kmscon_session **out,
if (ret)
goto err_free;
tsm_screen_set_max_sb(term->console, term->conf->sb_size);
if (term->conf->render_timing)
tsm_screen_set_opts(term->console,
TSM_SCREEN_OPT_RENDER_TIMING);
ret = tsm_vte_new(&term->vte, term->console, write_event, term,
log_llog, NULL);

View File

@ -437,21 +437,12 @@ void kmscon_text_abort(struct kmscon_text *txt)
txt->rendering = false;
}
int kmscon_text_prepare_cb(struct tsm_screen *con, void *data)
{
return kmscon_text_prepare(data);
}
int kmscon_text_draw_cb(struct tsm_screen *con,
uint32_t id, const uint32_t *ch, size_t len,
unsigned int width,
unsigned int posx, unsigned int posy,
const struct tsm_screen_attr *attr, void *data)
const struct tsm_screen_attr *attr,
tsm_age_t age, void *data)
{
return kmscon_text_draw(data, id, ch, len, width, posx, posy, attr);
}
int kmscon_text_render_cb(struct tsm_screen *con, void *data)
{
return kmscon_text_render(data);
}

View File

@ -34,10 +34,10 @@
#define KMSCON_TEXT_H
#include <errno.h>
#include <libtsm.h>
#include <stdlib.h>
#include "font.h"
#include "kmscon_module.h"
#include "tsm_screen.h"
#include "uterm_video.h"
/* text renderer */
@ -100,13 +100,12 @@ int kmscon_text_draw(struct kmscon_text *txt,
int kmscon_text_render(struct kmscon_text *txt);
void kmscon_text_abort(struct kmscon_text *txt);
int kmscon_text_prepare_cb(struct tsm_screen *con, void *data);
int kmscon_text_draw_cb(struct tsm_screen *con,
uint32_t id, const uint32_t *ch, size_t len,
unsigned int width,
unsigned int posx, unsigned int posy,
const struct tsm_screen_attr *attr, void *data);
int kmscon_text_render_cb(struct tsm_screen *con, void *data);
const struct tsm_screen_attr *attr,
tsm_age_t age, void *data);
/* modularized backends */

File diff suppressed because it is too large Load Diff

View File

@ -1,196 +0,0 @@
/*
* TSM - Screen Management
*
* Copyright (c) 2011-2012 David Herrmann <dh.herrmann@googlemail.com>
* Copyright (c) 2011 University of Tuebingen
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Screen Management
* This screen does not emulate any terminal at all. This subsystem just
* provides functions to draw a screen to a framebuffer and modifying the state
* of it.
*/
#ifndef TSM_SCREEN_H
#define TSM_SCREEN_H
#include <inttypes.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>
#include "tsm_unicode.h"
/* screen objects */
struct tsm_screen;
/**
* tsm_log_t:
* @data: user-provided data
* @file: Source code file where the log message originated or NULL
* @line: Line number in source code or 0
* @func: C function name or NULL
* @subs: Subsystem where the message came from or NULL
* @sev: Kernel-style severity between 0=FATAL and 7=DEBUG
* @format: printf-formatted message
* @args: arguments for printf-style @format
*
* This is the type of a logging callback function. You can always pass NULL
* instead of such a function to disable logging.
*/
typedef void (*tsm_log_t) (void *data,
const char *file,
int line,
const char *func,
const char *subs,
unsigned int sev,
const char *format,
va_list args);
#define TSM_SCREEN_INSERT_MODE 0x01
#define TSM_SCREEN_AUTO_WRAP 0x02
#define TSM_SCREEN_REL_ORIGIN 0x04
#define TSM_SCREEN_INVERSE 0x08
#define TSM_SCREEN_HIDE_CURSOR 0x10
#define TSM_SCREEN_FIXED_POS 0x20
#define TSM_SCREEN_ALTERNATE 0x40
#define TSM_SCREEN_OPT_RENDER_TIMING 0x01
struct tsm_screen_attr {
int8_t fccode; /* foreground color code or <0 for rgb */
int8_t bccode; /* background color code or <0 for rgb */
uint8_t fr; /* foreground red */
uint8_t fg; /* foreground green */
uint8_t fb; /* foreground blue */
uint8_t br; /* background red */
uint8_t bg; /* background green */
uint8_t bb; /* background blue */
unsigned int bold : 1; /* bold character */
unsigned int underline : 1; /* underlined character */
unsigned int inverse : 1; /* inverse colors */
unsigned int protect : 1; /* cannot be erased */
};
typedef int (*tsm_screen_prepare_cb) (struct tsm_screen *con,
void *data);
typedef int (*tsm_screen_draw_cb) (struct tsm_screen *con,
uint32_t id,
const uint32_t *ch,
size_t len,
unsigned int width,
unsigned int posx,
unsigned int posy,
const struct tsm_screen_attr *attr,
void *data);
typedef int (*tsm_screen_render_cb) (struct tsm_screen *con,
void *data);
int tsm_screen_new(struct tsm_screen **out, tsm_log_t log, void *log_data);
void tsm_screen_ref(struct tsm_screen *con);
void tsm_screen_unref(struct tsm_screen *con);
void tsm_screen_set_opts(struct tsm_screen *scr, unsigned int opts);
void tsm_screen_reset_opts(struct tsm_screen *scr, unsigned int opts);
unsigned int tsm_screen_get_opts(struct tsm_screen *scr);
unsigned int tsm_screen_get_width(struct tsm_screen *con);
unsigned int tsm_screen_get_height(struct tsm_screen *con);
int tsm_screen_resize(struct tsm_screen *con, unsigned int x,
unsigned int y);
int tsm_screen_set_margins(struct tsm_screen *con,
unsigned int top, unsigned int bottom);
void tsm_screen_set_max_sb(struct tsm_screen *con, unsigned int max);
void tsm_screen_clear_sb(struct tsm_screen *con);
void tsm_screen_sb_up(struct tsm_screen *con, unsigned int num);
void tsm_screen_sb_down(struct tsm_screen *con, unsigned int num);
void tsm_screen_sb_page_up(struct tsm_screen *con, unsigned int num);
void tsm_screen_sb_page_down(struct tsm_screen *con, unsigned int num);
void tsm_screen_sb_reset(struct tsm_screen *con);
void tsm_screen_set_def_attr(struct tsm_screen *con,
const struct tsm_screen_attr *attr);
void tsm_screen_reset(struct tsm_screen *con);
void tsm_screen_set_flags(struct tsm_screen *con, unsigned int flags);
void tsm_screen_reset_flags(struct tsm_screen *con, unsigned int flags);
unsigned int tsm_screen_get_flags(struct tsm_screen *con);
unsigned int tsm_screen_get_cursor_x(struct tsm_screen *con);
unsigned int tsm_screen_get_cursor_y(struct tsm_screen *con);
void tsm_screen_set_tabstop(struct tsm_screen *con);
void tsm_screen_reset_tabstop(struct tsm_screen *con);
void tsm_screen_reset_all_tabstops(struct tsm_screen *con);
void tsm_screen_write(struct tsm_screen *con, tsm_symbol_t ch,
const struct tsm_screen_attr *attr);
void tsm_screen_newline(struct tsm_screen *con);
void tsm_screen_scroll_up(struct tsm_screen *con, unsigned int num);
void tsm_screen_scroll_down(struct tsm_screen *con, unsigned int num);
void tsm_screen_move_to(struct tsm_screen *con, unsigned int x,
unsigned int y);
void tsm_screen_move_up(struct tsm_screen *con, unsigned int num,
bool scroll);
void tsm_screen_move_down(struct tsm_screen *con, unsigned int num,
bool scroll);
void tsm_screen_move_left(struct tsm_screen *con, unsigned int num);
void tsm_screen_move_right(struct tsm_screen *con, unsigned int num);
void tsm_screen_move_line_end(struct tsm_screen *con);
void tsm_screen_move_line_home(struct tsm_screen *con);
void tsm_screen_tab_right(struct tsm_screen *con, unsigned int num);
void tsm_screen_tab_left(struct tsm_screen *con, unsigned int num);
void tsm_screen_insert_lines(struct tsm_screen *con, unsigned int num);
void tsm_screen_delete_lines(struct tsm_screen *con, unsigned int num);
void tsm_screen_insert_chars(struct tsm_screen *con, unsigned int num);
void tsm_screen_delete_chars(struct tsm_screen *con, unsigned int num);
void tsm_screen_erase_cursor(struct tsm_screen *con);
void tsm_screen_erase_chars(struct tsm_screen *con, unsigned int num);
void tsm_screen_erase_cursor_to_end(struct tsm_screen *con,
bool protect);
void tsm_screen_erase_home_to_cursor(struct tsm_screen *con,
bool protect);
void tsm_screen_erase_current_line(struct tsm_screen *con,
bool protect);
void tsm_screen_erase_screen_to_cursor(struct tsm_screen *con,
bool protect);
void tsm_screen_erase_cursor_to_screen(struct tsm_screen *con,
bool protect);
void tsm_screen_erase_screen(struct tsm_screen *con, bool protect);
void tsm_screen_selection_reset(struct tsm_screen *con);
void tsm_screen_selection_start(struct tsm_screen *con,
unsigned int posx,
unsigned int posy);
void tsm_screen_selection_target(struct tsm_screen *con,
unsigned int posx,
unsigned int posy);
int tsm_screen_selection_copy(struct tsm_screen *con, char **out);
void tsm_screen_draw(struct tsm_screen *con,
tsm_screen_prepare_cb prepare_cb,
tsm_screen_draw_cb draw_cb,
tsm_screen_render_cb render_cb,
void *data);
#endif /* TSM_SCREEN_H */

View File

@ -1,624 +0,0 @@
/*
* TSM - Unicode Handling
*
* Copyright (c) 2011 David Herrmann <dh.herrmann@googlemail.com>
* Copyright (c) 2011-2012 University of Tuebingen
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* The tsm-utf8-state-machine is based on the wayland-compositor demos:
*
* Copyright © 2008 Kristian Høgsberg
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of the copyright holders not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. The copyright holders make
* no representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Unicode Helpers
* This implements several helpers for Unicode/UTF8/UCS4 input and output. See
* below for comments on each helper.
*/
#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include "external/wcwidth.h"
#include "shl_array.h"
#include "shl_hashtable.h"
#include "shl_misc.h"
#include "tsm_unicode.h"
/*
* Unicode Symbol Handling
* The main goal of the tsm_symbol_* functions is to provide a datatype which
* can contain the representation of any printable character. This includes all
* basic Unicode characters but also combined characters.
* To avoid all the memory management we still represent a character as a single
* integer value (tsm_symbol_t) but internally we allocate a string which is
* represented by this value.
*
* A tsm_symbol_t is an integer which represents a single character point.
* For most Unicode characters this is simply the UCS4 representation. In fact,
* every UCS4 characters is a valid tsm_symbol_t object.
* However, Unicode standard allows combining marks. Therefore, some characters
* consists of more than one Unicode character.
* A global symbol-table provides all those combined characters as single
* integers. You simply create a valid base character and append your combining
* marks and the table will return a new valid tsm_symbol_t. It is no longer
* a valid UCS4 value, though. But no memory management is needed as all
* tsm_symbol_t objects are simple integers.
*
* The symbol table contains two-way
* references. The Hash Table contains all the symbols with the symbol ucs4
* string as key and the symbol ID as value.
* The index array contains the symbol ID as key and a pointer to the ucs4
* string as value. But the hash table owns the ucs4 string.
* This allows fast implementations of *_get() and *_append() without long
* search intervals.
*
* When creating a new symbol, we simply return the UCS4 value as new symbol. We
* do not add it to our symbol table as it is only one character. However, if a
* character is appended to an existing symbol, we create a new ucs4 string and
* push the new symbol into the symbol table.
*/
SHL_EXPORT
const tsm_symbol_t tsm_symbol_default = 0;
struct tsm_symbol_table {
unsigned long ref;
uint32_t next_id;
struct shl_array *index;
struct shl_hashtable *symbols;
};
/* TODO: remove the default context */
static struct tsm_symbol_table *tsm_symbol_table_default;
static unsigned int hash_ucs4(const void *key)
{
unsigned int val = 5381;
size_t i;
const uint32_t *ucs4 = key;
i = 0;
while (ucs4[i] <= TSM_UCS4_MAX) {
val = val * 33 + ucs4[i];
++i;
}
return val;
}
static bool cmp_ucs4(const void *a, const void *b)
{
size_t i;
const uint32_t *v1, *v2;
v1 = a;
v2 = b;
i = 0;
while (1) {
if (v1[i] > TSM_UCS4_MAX && v2[i] > TSM_UCS4_MAX)
return true;
if (v1[i] > TSM_UCS4_MAX && v2[i] <= TSM_UCS4_MAX)
return false;
if (v1[i] <= TSM_UCS4_MAX && v2[i] > TSM_UCS4_MAX)
return false;
if (v1[i] != v2[i])
return false;
++i;
}
}
SHL_EXPORT
int tsm_symbol_table_new(struct tsm_symbol_table **out)
{
struct tsm_symbol_table *tbl;
int ret;
static const uint32_t *val = NULL; /* we need a valid lvalue */
if (!out)
return -EINVAL;
tbl = malloc(sizeof(*tbl));
if (!tbl)
return -ENOMEM;
memset(tbl, 0, sizeof(*tbl));
tbl->ref = 1;
tbl->next_id = TSM_UCS4_MAX + 2;
ret = shl_array_new(&tbl->index, sizeof(uint32_t*), 4);
if (ret)
goto err_free;
/* first entry is not used so add dummy */
shl_array_push(tbl->index, &val);
ret = shl_hashtable_new(&tbl->symbols, hash_ucs4, cmp_ucs4,
free, NULL);
if (ret)
goto err_array;
*out = tbl;
return 0;
err_array:
shl_array_free(tbl->index);
err_free:
free(tbl);
return ret;
}
SHL_EXPORT
void tsm_symbol_table_ref(struct tsm_symbol_table *tbl)
{
if (!tbl || !tbl->ref)
return;
++tbl->ref;
}
SHL_EXPORT
void tsm_symbol_table_unref(struct tsm_symbol_table *tbl)
{
if (!tbl || !tbl->ref || --tbl->ref)
return;
shl_hashtable_free(tbl->symbols);
shl_array_free(tbl->index);
free(tbl);
}
SHL_EXPORT
tsm_symbol_t tsm_symbol_make(uint32_t ucs4)
{
if (ucs4 > TSM_UCS4_MAX)
return 0;
else
return ucs4;
}
/*
* This decomposes a symbol into a ucs4 string and a size value. If \sym is a
* valid UCS4 character, this returns a pointer to \sym and writes 1 into \size.
* Therefore, the returned value may get destroyed if your \sym argument gets
* destroyed.
* If \sym is a composed ucs4 string, then the returned value points into the
* hash table of the symbol table and lives as long as the symbol table does.
*
* This always returns a valid value. If an error happens, the default character
* is returned. If \size is NULL, then the size value is omitted.
*/
SHL_EXPORT
const uint32_t *tsm_symbol_get(struct tsm_symbol_table *tbl,
tsm_symbol_t *sym, size_t *size)
{
uint32_t *ucs4, idx;
int ret;
if (*sym <= TSM_UCS4_MAX) {
if (size)
*size = 1;
return sym;
}
if (!tbl)
tbl = tsm_symbol_table_default;
if (!tbl) {
ret = tsm_symbol_table_new(&tbl);
if (ret) {
if (size)
*size = 1;
return &tsm_symbol_default;
}
tsm_symbol_table_default = tbl;
}
idx = *sym - (TSM_UCS4_MAX + 1);
if (idx >= shl_array_get_length(tbl->index))
ucs4 = NULL;
else
ucs4 = *SHL_ARRAY_AT(tbl->index, uint32_t*, idx);
if (!ucs4) {
if (size)
*size = 1;
return &tsm_symbol_default;
}
if (size) {
*size = 0;
while (ucs4[*size] <= TSM_UCS4_MAX)
++*size;
}
return ucs4;
}
SHL_EXPORT
tsm_symbol_t tsm_symbol_append(struct tsm_symbol_table *tbl,
tsm_symbol_t sym, uint32_t ucs4)
{
uint32_t buf[TSM_UCS4_MAXLEN + 1], nsym, *nval;
const uint32_t *ptr;
size_t s;
void *tmp;
bool res;
int ret;
if (!tbl)
tbl = tsm_symbol_table_default;
if (!tbl) {
ret = tsm_symbol_table_new(&tbl);
if (ret)
return sym;
tsm_symbol_table_default = tbl;
}
if (ucs4 > TSM_UCS4_MAX)
return sym;
ptr = tsm_symbol_get(tbl, &sym, &s);
if (s >= TSM_UCS4_MAXLEN)
return sym;
memcpy(buf, ptr, s * sizeof(uint32_t));
buf[s++] = ucs4;
buf[s++] = TSM_UCS4_MAX + 1;
res = shl_hashtable_find(tbl->symbols, &tmp, buf);
if (res)
return (uint32_t)(long)tmp;
nval = malloc(sizeof(uint32_t) * s);
if (!nval)
return sym;
memcpy(nval, buf, s * sizeof(uint32_t));
nsym = tbl->next_id + 1;
/* Out of IDs; we actually have 2 Billion IDs so this seems
* very unlikely but lets be safe here */
if (nsym <= tbl->next_id++)
goto err_id;
ret = shl_hashtable_insert(tbl->symbols, nval, (void*)(long)nsym);
if (ret)
goto err_id;
ret = shl_array_push(tbl->index, &nval);
if (ret)
goto err_symbol;
return nsym;
err_symbol:
shl_hashtable_remove(tbl->symbols, nval);
err_id:
--tbl->next_id;
free(nval);
return sym;
}
SHL_EXPORT
unsigned int tsm_symbol_get_width(struct tsm_symbol_table *tbl,
tsm_symbol_t sym)
{
int ret;
const uint32_t *ch;
size_t len;
if (!tbl)
tbl = tsm_symbol_table_default;
if (!tbl) {
ret = tsm_symbol_table_new(&tbl);
if (ret)
return sym;
tsm_symbol_table_default = tbl;
}
ch = tsm_symbol_get(tbl, &sym, &len);
if (len == 0)
return 0;
return tsm_ucs4_get_width(*ch);
}
/*
* Convert UCS4 character to UTF-8. This creates one of:
* 0xxxxxxx
* 110xxxxx 10xxxxxx
* 1110xxxx 10xxxxxx 10xxxxxx
* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
* This is based on the same function from "terminology" from the Enlightenment
* project. See COPYING for more information.
*
* @txt must point to a 4 byte-buffer. A number between 0 and 4 is returned and
* indicates how long the written UTF8 string is.
*
* Please note @g is a real UCS4 code and not a tsm_symbol_t object!
*
* Unicode symbols between 0xD800 and 0xDFFF are not assigned and reserved for
* UTF16 compatibility. It is an error to encode them. Same applies to numbers
* greater than 0x10FFFF, the range 0xFDD0-0xFDEF and codepoints ending with
* 0xFFFF or 0xFFFE.
*/
SHL_EXPORT
unsigned int tsm_ucs4_get_width(uint32_t ucs4)
{
int ret;
ret = mk_wcwidth(ucs4);
if (ret <= 0)
return 0;
return ret;
}
SHL_EXPORT
size_t tsm_ucs4_to_utf8(uint32_t g, char *txt)
{
if (g >= 0xd800 && g <= 0xdfff)
return 0;
if (g > 0x10ffff || (g & 0xffff) == 0xffff || (g & 0xffff) == 0xfffe)
return 0;
if (g >= 0xfdd0 && g <= 0xfdef)
return 0;
if (g < (1 << 7)) {
txt[0] = g & 0x7f;
return 1;
} else if (g < (1 << (5 + 6))) {
txt[0] = 0xc0 | ((g >> 6) & 0x1f);
txt[1] = 0x80 | ((g ) & 0x3f);
return 2;
} else if (g < (1 << (4 + 6 + 6))) {
txt[0] = 0xe0 | ((g >> 12) & 0x0f);
txt[1] = 0x80 | ((g >> 6) & 0x3f);
txt[2] = 0x80 | ((g ) & 0x3f);
return 3;
} else if (g < (1 << (3 + 6 + 6 + 6))) {
txt[0] = 0xf0 | ((g >> 18) & 0x07);
txt[1] = 0x80 | ((g >> 12) & 0x3f);
txt[2] = 0x80 | ((g >> 6) & 0x3f);
txt[3] = 0x80 | ((g ) & 0x3f);
return 4;
} else {
return 0;
}
}
SHL_EXPORT
char *tsm_ucs4_to_utf8_alloc(const uint32_t *ucs4, size_t len, size_t *len_out)
{
char *val;
size_t i, pos;
val = malloc(4 * len);
if (!val)
return NULL;
pos = 0;
for (i = 0; i < len; ++i)
pos += tsm_ucs4_to_utf8(ucs4[i], &val[pos]);
if (!pos) {
free(val);
return NULL;
}
if (len_out)
*len_out = pos;
return val;
}
/*
* UTF8 State Machine
* This state machine parses UTF8 and converts it into a stream of Unicode
* characters (UCS4 values). A state-machine is represented by a
* "struct tsm_utf8_mach" object. It has no global state and all functions are
* re-entrant if called with different state-machine objects.
*
* tsm_utf8_mach_new(): This creates a new state-machine and resets it to its
* initial state. Returns 0 on success.
*
* tsm_uft8_mach_free(): This destroys a state-machine and frees all internally
* allocated memory.
*
* tsm_utf8_mach_reset(): Reset a given state-machine to its initial state. This
* is the same state the machine is in after it got created.
*
* tsm_uft8_mach_feed(): Feed one byte of the UTF8 input stream into the
* state-machine. This function returns the new state of the state-machine after
* this character has been parsed. If it is TSM_UTF8_ACCEPT or TSM_UTF8_REJECT,
* then there is a pending UCS4 character that you should retrieve via
* tsm_utf8_mach_get(). If it is TSM_UTF8_ACCEPT, then a character was
* successfully parsed. If it is TSM_UTF8_REJECT, the input was invalid UTF8 and
* some error recovery was tried or a replacement character was choosen. All
* other states mean that the machine needs more input to parse the stream.
*
* tsm_utf8_mach_get(): Returns the last parsed character. It has no effect on
* the state machine so you can call it multiple times.
*
* Internally, we use TSM_UTF8_START whenever the state-machine is reset. This
* can be used to ignore the last read input or to simply reset the machine.
* TSM_UTF8_EXPECT* is used to remember how many bytes are still to be read to
* get a full UTF8 sequence.
* If an error occurs during reading, we go to state TSM_UTF8_REJECT and the
* user will read a replacement character. If further errors occur, we go to
* state TSM_UTF8_START to avoid printing multiple replacement characters for a
* single misinterpreted UTF8 sequence. However, under some circumstances it may
* happen that we stay in TSM_UTF8_REJECT and a next replacement character is
* returned.
* It is difficult to decide how to interpret wrong input but this machine seems
* to be quite good at deciding what to do. Generally, we prefer discarding or
* replacing input instead of trying to decipher ASCII values from the invalid
* data. This guarantees that we do not send wrong values to the terminal
* emulator. Some might argue that an ASCII fallback would be better. However,
* this means that we might send very weird escape-sequences to the VTE layer.
* Especially with C1 codes applications can really break many terminal features
* so we avoid any non-ASCII+non-UTF8 input to prevent this.
*/
struct tsm_utf8_mach {
int state;
uint32_t ch;
};
SHL_EXPORT
int tsm_utf8_mach_new(struct tsm_utf8_mach **out)
{
struct tsm_utf8_mach *mach;
if (!out)
return -EINVAL;
mach = malloc(sizeof(*mach));
if (!mach)
return -ENOMEM;
memset(mach, 0, sizeof(*mach));
mach->state = TSM_UTF8_START;
*out = mach;
return 0;
}
SHL_EXPORT
void tsm_utf8_mach_free(struct tsm_utf8_mach *mach)
{
if (!mach)
return;
free(mach);
}
SHL_EXPORT
int tsm_utf8_mach_feed(struct tsm_utf8_mach *mach, char ci)
{
uint32_t c;
if (!mach)
return TSM_UTF8_START;
c = ci;
switch (mach->state) {
case TSM_UTF8_START:
case TSM_UTF8_ACCEPT:
case TSM_UTF8_REJECT:
if (c == 0xC0 || c == 0xC1) {
/* overlong encoding for ASCII, reject */
mach->state = TSM_UTF8_REJECT;
} else if ((c & 0x80) == 0) {
/* single byte, accept */
mach->ch = c;
mach->state = TSM_UTF8_ACCEPT;
} else if ((c & 0xC0) == 0x80) {
/* parser out of sync, ignore byte */
mach->state = TSM_UTF8_START;
} else if ((c & 0xE0) == 0xC0) {
/* start of two byte sequence */
mach->ch = (c & 0x1F) << 6;
mach->state = TSM_UTF8_EXPECT1;
} else if ((c & 0xF0) == 0xE0) {
/* start of three byte sequence */
mach->ch = (c & 0x0F) << 12;
mach->state = TSM_UTF8_EXPECT2;
} else if ((c & 0xF8) == 0xF0) {
/* start of four byte sequence */
mach->ch = (c & 0x07) << 18;
mach->state = TSM_UTF8_EXPECT3;
} else {
/* overlong encoding, reject */
mach->state = TSM_UTF8_REJECT;
}
break;
case TSM_UTF8_EXPECT3:
mach->ch |= (c & 0x3F) << 12;
if ((c & 0xC0) == 0x80)
mach->state = TSM_UTF8_EXPECT2;
else
mach->state = TSM_UTF8_REJECT;
break;
case TSM_UTF8_EXPECT2:
mach->ch |= (c & 0x3F) << 6;
if ((c & 0xC0) == 0x80)
mach->state = TSM_UTF8_EXPECT1;
else
mach->state = TSM_UTF8_REJECT;
break;
case TSM_UTF8_EXPECT1:
mach->ch |= c & 0x3F;
if ((c & 0xC0) == 0x80)
mach->state = TSM_UTF8_ACCEPT;
else
mach->state = TSM_UTF8_REJECT;
break;
default:
mach->state = TSM_UTF8_REJECT;
break;
}
return mach->state;
}
SHL_EXPORT
uint32_t tsm_utf8_mach_get(struct tsm_utf8_mach *mach)
{
if (!mach || mach->state != TSM_UTF8_ACCEPT)
return TSM_UCS4_REPLACEMENT;
return mach->ch;
}
SHL_EXPORT
void tsm_utf8_mach_reset(struct tsm_utf8_mach *mach)
{
if (!mach)
return;
mach->state = TSM_UTF8_START;
}

View File

@ -1,91 +0,0 @@
/*
* TSM - Unicode Handling
*
* Copyright (c) 2011-2012 David Herrmann <dh.herrmann@googlemail.com>
* Copyright (c) 2011 University of Tuebingen
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Unicode Helpers
* This file provides small helpers to make working with Unicode/UTF8/UCS4 input
* and output much easier.
*/
#ifndef TSM_UNICODE_H
#define TSM_UNICODE_H
#include <inttypes.h>
#include <stdlib.h>
/* UCS4 helpers */
#define TSM_UCS4_MAX (0x7fffffffUL)
#define TSM_UCS4_INVALID (TSM_UCS4_MAX + 1)
#define TSM_UCS4_REPLACEMENT (0xfffdUL)
#define TSM_UCS4_MAXLEN 10
/* symbols */
struct tsm_symbol_table;
typedef uint32_t tsm_symbol_t;
extern const tsm_symbol_t tsm_symbol_default;
int tsm_symbol_table_new(struct tsm_symbol_table **out);
void tsm_symbol_table_ref(struct tsm_symbol_table *tbl);
void tsm_symbol_table_unref(struct tsm_symbol_table *tbl);
tsm_symbol_t tsm_symbol_make(uint32_t ucs4);
tsm_symbol_t tsm_symbol_append(struct tsm_symbol_table *tbl,
tsm_symbol_t sym, uint32_t ucs4);
const uint32_t *tsm_symbol_get(struct tsm_symbol_table *tbl,
tsm_symbol_t *sym, size_t *size);
unsigned int tsm_symbol_get_width(struct tsm_symbol_table *tbl,
tsm_symbol_t sym);
/* ucs4 to utf8 converter */
unsigned int tsm_ucs4_get_width(uint32_t ucs4);
size_t tsm_ucs4_to_utf8(uint32_t ucs4, char *out);
char *tsm_ucs4_to_utf8_alloc(const uint32_t *ucs4, size_t len, size_t *len_out);
/* utf8 state machine */
struct tsm_utf8_mach;
enum tsm_utf8_mach_state {
TSM_UTF8_START,
TSM_UTF8_ACCEPT,
TSM_UTF8_REJECT,
TSM_UTF8_EXPECT1,
TSM_UTF8_EXPECT2,
TSM_UTF8_EXPECT3,
};
int tsm_utf8_mach_new(struct tsm_utf8_mach **out);
void tsm_utf8_mach_free(struct tsm_utf8_mach *mach);
int tsm_utf8_mach_feed(struct tsm_utf8_mach *mach, char c);
uint32_t tsm_utf8_mach_get(struct tsm_utf8_mach *mach);
void tsm_utf8_mach_reset(struct tsm_utf8_mach *mach);
#endif /* TSM_UNICODE_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,85 +0,0 @@
/*
* TSM - VT Emulator
*
* Copyright (c) 2011 David Herrmann <dh.herrmann@googlemail.com>
* Copyright (c) 2011 University of Tuebingen
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Virtual Terminal Emulator
* This is a vt100 implementation. It is written from scratch. It uses the
* screen state-machine as output and is tightly bound to it.
*/
#ifndef TSM_VTE_H
#define TSM_VTE_H
#include <stdlib.h>
#include "tsm_screen.h"
#include "tsm_unicode.h"
/* available character sets */
typedef tsm_symbol_t tsm_vte_charset[96];
extern tsm_vte_charset tsm_vte_unicode_lower;
extern tsm_vte_charset tsm_vte_unicode_upper;
extern tsm_vte_charset tsm_vte_dec_supplemental_graphics;
extern tsm_vte_charset tsm_vte_dec_special_graphics;
/* virtual terminal emulator */
struct tsm_vte;
/* keep in sync with shl_xkb_mods */
enum tsm_vte_modifier {
TSM_SHIFT_MASK = (1 << 0),
TSM_LOCK_MASK = (1 << 1),
TSM_CONTROL_MASK = (1 << 2),
TSM_ALT_MASK = (1 << 3),
TSM_LOGO_MASK = (1 << 4),
};
/* keep in sync with TSM_INPUT_INVALID */
#define TSM_VTE_INVALID 0xffffffff
typedef void (*tsm_vte_write_cb) (struct tsm_vte *vte,
const char *u8,
size_t len,
void *data);
int tsm_vte_new(struct tsm_vte **out, struct tsm_screen *con,
tsm_vte_write_cb write_cb, void *data,
tsm_log_t log, void *log_data);
void tsm_vte_ref(struct tsm_vte *vte);
void tsm_vte_unref(struct tsm_vte *vte);
int tsm_vte_set_palette(struct tsm_vte *vte, const char *palette);
void tsm_vte_reset(struct tsm_vte *vte);
void tsm_vte_hard_reset(struct tsm_vte *vte);
void tsm_vte_input(struct tsm_vte *vte, const char *u8, size_t len);
bool tsm_vte_handle_keyboard(struct tsm_vte *vte, uint32_t keysym,
uint32_t ascii, unsigned int mods,
uint32_t unicode);
#endif /* TSM_VTE_H */

View File

@ -1,501 +0,0 @@
/*
* TSM - VT Emulator
*
* Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* VTE Character Sets
* These are predefined charactersets that can be loaded into GL and GR. By
* default we use unicode_lower and unicode_upper, that is, both sets have the
* exact unicode mapping. unicode_lower is effectively ASCII and unicode_upper
* as defined by the unicode standard.
* Several other character sets are defined here. However, all of them are
* limited to the 96 character space of GL or GR. Everything beyond GR (which
* was not supported by the classic VTs by DEC but is available in VT emulators
* that support unicode/UTF8) is always mapped to unicode and cannot be changed
* by these character sets. Even mapping GL and GR is only available for
* backwards compatibility as new applications can use the Unicode functionality
* of the VTE.
*
* Moreover, mapping GR is almost unnecessary to support. In fact, Unicode UTF-8
* support in VTE works by reading every incoming data as UTF-8 stream. This
* maps GL/ASCII to ASCII, as UTF-8 is backwards compatible to ASCII, however,
* everything that has the 8th bit set is a >=2-byte haracter in UTF-8. That is,
* this is in no way backwards compatible to >=VT220 8bit support. Therefore, if
* someone maps a character set into GR and wants to use them with this VTE,
* then they must already send UTF-8 characters to use GR (all GR characters are
* 8-bits). Hence, they can easily also send the correct UTF-8 character for the
* unicode mapping.
* The only advantage is that most characters in many sets are 3-byte UTF-8
* characters and by mapping the set into GR/GL you can use 2 or 1 byte UTF-8
* characters which saves bandwidth.
* Another reason is, if you have older applications that use the VT220 8-bit
* support and you put a ASCII/8bit-extension to UTF-8 converter in between, you
* need these mappings to have the application behave correctly if it uses GL/GR
* mappings extensively.
*
* Anyway, we support GL/GR mappings so here are the most commonly used maps as
* defined by Unicode-standard, DEC-private maps and other famous charmaps.
*
* Characters 1-32 are always the control characters (part of CL) and cannot be
* mapped. Characters 34-127 (94 characters) are part of GL and can be mapped.
* Characters 33 and 128 are not part of GL and always mapped by VTE but are
* included here in the maps for alignment reasons but always set to 0.
*/
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "shl_misc.h"
#include "tsm_vte.h"
/*
* Lower Unicode character set. This maps the characters to the basic ASCII
* characters 33-126. These are all graphics characters defined in ASCII. The
* first an last entry are never used so we can safely set them to anything.
*/
SHL_EXPORT
tsm_vte_charset tsm_vte_unicode_lower = {
[0] = 0,
[1] = 33,
[2] = 34,
[3] = 35,
[4] = 36,
[5] = 37,
[6] = 38,
[7] = 39,
[8] = 40,
[9] = 41,
[10] = 42,
[11] = 43,
[12] = 44,
[13] = 45,
[14] = 46,
[15] = 47,
[16] = 48,
[17] = 49,
[18] = 50,
[19] = 51,
[20] = 52,
[21] = 53,
[22] = 54,
[23] = 55,
[24] = 56,
[25] = 57,
[26] = 58,
[27] = 59,
[28] = 60,
[29] = 61,
[30] = 62,
[31] = 63,
[32] = 64,
[33] = 65,
[34] = 66,
[35] = 67,
[36] = 68,
[37] = 69,
[38] = 70,
[39] = 71,
[40] = 72,
[41] = 73,
[42] = 74,
[43] = 75,
[44] = 76,
[45] = 77,
[46] = 78,
[47] = 79,
[48] = 80,
[49] = 81,
[50] = 82,
[51] = 83,
[52] = 84,
[53] = 85,
[54] = 86,
[55] = 87,
[56] = 88,
[57] = 89,
[58] = 90,
[59] = 91,
[60] = 92,
[61] = 93,
[62] = 94,
[63] = 95,
[64] = 96,
[65] = 97,
[66] = 98,
[67] = 99,
[68] = 100,
[69] = 101,
[70] = 102,
[71] = 103,
[72] = 104,
[73] = 105,
[74] = 106,
[75] = 107,
[76] = 108,
[77] = 109,
[78] = 110,
[79] = 111,
[80] = 112,
[81] = 113,
[82] = 114,
[83] = 115,
[84] = 116,
[85] = 117,
[86] = 118,
[87] = 119,
[88] = 120,
[89] = 121,
[90] = 122,
[91] = 123,
[92] = 124,
[93] = 125,
[94] = 126,
[95] = 0,
};
/*
* Upper Unicode Table
* This maps all characters to the upper unicode characters 161-254. These are
* not compatible to any older 8 bit character sets. See the Unicode standard
* for the definitions of each symbol. Again, the first an last entry are never
* used so set them to 0.
*/
SHL_EXPORT
tsm_vte_charset tsm_vte_unicode_upper = {
[0] = 0,
[1] = 161,
[2] = 162,
[3] = 163,
[4] = 164,
[5] = 165,
[6] = 166,
[7] = 167,
[8] = 168,
[9] = 169,
[10] = 170,
[11] = 171,
[12] = 172,
[13] = 173,
[14] = 174,
[15] = 175,
[16] = 176,
[17] = 177,
[18] = 178,
[19] = 179,
[20] = 180,
[21] = 181,
[22] = 182,
[23] = 183,
[24] = 184,
[25] = 185,
[26] = 186,
[27] = 187,
[28] = 188,
[29] = 189,
[30] = 190,
[31] = 191,
[32] = 192,
[33] = 193,
[34] = 194,
[35] = 195,
[36] = 196,
[37] = 197,
[38] = 198,
[39] = 199,
[40] = 200,
[41] = 201,
[42] = 202,
[43] = 203,
[44] = 204,
[45] = 205,
[46] = 206,
[47] = 207,
[48] = 208,
[49] = 209,
[50] = 210,
[51] = 211,
[52] = 212,
[53] = 213,
[54] = 214,
[55] = 215,
[56] = 216,
[57] = 217,
[58] = 218,
[59] = 219,
[60] = 220,
[61] = 221,
[62] = 222,
[63] = 223,
[64] = 224,
[65] = 225,
[66] = 226,
[67] = 227,
[68] = 228,
[69] = 229,
[70] = 230,
[71] = 231,
[72] = 232,
[73] = 233,
[74] = 234,
[75] = 235,
[76] = 236,
[77] = 237,
[78] = 238,
[79] = 239,
[80] = 240,
[81] = 241,
[82] = 242,
[83] = 243,
[84] = 244,
[85] = 245,
[86] = 246,
[87] = 247,
[88] = 248,
[89] = 249,
[90] = 250,
[91] = 251,
[92] = 252,
[93] = 253,
[94] = 254,
[95] = 0,
};
/*
* The DEC supplemental graphics set. For its definition see here:
* http://vt100.net/docs/vt220-rm/table2-3b.html
* Its basically a mixture of common European symbols that are not part of
* ASCII. Most often, this is mapped into GR to extend the basci ASCII part.
*
* This is very similar to unicode_upper, however, few symbols differ so do not
* mix them up!
*/
SHL_EXPORT
tsm_vte_charset tsm_vte_dec_supplemental_graphics = {
[0] = 0,
[1] = 161,
[2] = 162,
[3] = 163,
[4] = 0,
[5] = 165,
[6] = 0,
[7] = 167,
[8] = 164,
[9] = 169,
[10] = 170,
[11] = 171,
[12] = 0,
[13] = 0,
[14] = 0,
[15] = 0,
[16] = 176,
[17] = 177,
[18] = 178,
[19] = 179,
[20] = 0,
[21] = 181,
[22] = 182,
[23] = 183,
[24] = 0,
[25] = 185,
[26] = 186,
[27] = 187,
[28] = 188,
[29] = 189,
[30] = 0,
[31] = 191,
[32] = 192,
[33] = 193,
[34] = 194,
[35] = 195,
[36] = 196,
[37] = 197,
[38] = 198,
[39] = 199,
[40] = 200,
[41] = 201,
[42] = 202,
[43] = 203,
[44] = 204,
[45] = 205,
[46] = 206,
[47] = 207,
[48] = 0,
[49] = 209,
[50] = 210,
[51] = 211,
[52] = 212,
[53] = 213,
[54] = 214,
[55] = 338,
[56] = 216,
[57] = 217,
[58] = 218,
[59] = 219,
[60] = 220,
[61] = 376,
[62] = 0,
[63] = 223,
[64] = 224,
[65] = 225,
[66] = 226,
[67] = 227,
[68] = 228,
[69] = 229,
[70] = 230,
[71] = 231,
[72] = 232,
[73] = 233,
[74] = 234,
[75] = 235,
[76] = 236,
[77] = 237,
[78] = 238,
[79] = 239,
[80] = 0,
[81] = 241,
[82] = 242,
[83] = 243,
[84] = 244,
[85] = 245,
[86] = 246,
[87] = 339,
[88] = 248,
[89] = 249,
[90] = 250,
[91] = 251,
[92] = 252,
[93] = 255,
[94] = 0,
[95] = 0,
};
/*
* DEC special graphics character set. See here for its definition:
* http://vt100.net/docs/vt220-rm/table2-4.html
* This contains several characters to create ASCII drawings and similar. Its
* commonly mapped into GR to extend the basic ASCII characters.
*
* Lower 62 characters map to ASCII 33-64, everything beyond is special and
* commonly used for ASCII drawings. It depends on the Unicode Standard 3.2 for
* the extended horizontal scan-line characters 3, 5, 7, and 9.
*/
SHL_EXPORT
tsm_vte_charset tsm_vte_dec_special_graphics = {
[0] = 0,
[1] = 33,
[2] = 34,
[3] = 35,
[4] = 36,
[5] = 37,
[6] = 38,
[7] = 39,
[8] = 40,
[9] = 41,
[10] = 42,
[11] = 43,
[12] = 44,
[13] = 45,
[14] = 46,
[15] = 47,
[16] = 48,
[17] = 49,
[18] = 50,
[19] = 51,
[20] = 52,
[21] = 53,
[22] = 54,
[23] = 55,
[24] = 56,
[25] = 57,
[26] = 58,
[27] = 59,
[28] = 60,
[29] = 61,
[30] = 62,
[31] = 63,
[32] = 64,
[33] = 65,
[34] = 66,
[35] = 67,
[36] = 68,
[37] = 69,
[38] = 70,
[39] = 71,
[40] = 72,
[41] = 73,
[42] = 74,
[43] = 75,
[44] = 76,
[45] = 77,
[46] = 78,
[47] = 79,
[48] = 80,
[49] = 81,
[50] = 82,
[51] = 83,
[52] = 84,
[53] = 85,
[54] = 86,
[55] = 87,
[56] = 88,
[57] = 89,
[58] = 90,
[59] = 91,
[60] = 92,
[61] = 93,
[62] = 94,
[63] = 0,
[64] = 9830,
[65] = 9618,
[66] = 9225,
[67] = 9228,
[68] = 9229,
[69] = 9226,
[70] = 176,
[71] = 177,
[72] = 9252,
[73] = 9227,
[74] = 9496,
[75] = 9488,
[76] = 9484,
[77] = 9492,
[78] = 9532,
[79] = 9146,
[80] = 9147,
[81] = 9472,
[82] = 9148,
[83] = 9149,
[84] = 9500,
[85] = 9508,
[86] = 9524,
[87] = 9516,
[88] = 9474,
[89] = 8804,
[90] = 8805,
[91] = 960,
[92] = 8800,
[93] = 163,
[94] = 8901,
[95] = 0,
};