Make unibilium work at all

This commit is contained in:
Přemysl Eric Janouch 2016-07-24 00:27:25 +02:00
parent 1f2a32ed97
commit 9b7c801c37
Signed by: p
GPG Key ID: B715679E3A361BE6
2 changed files with 22 additions and 11 deletions

View File

@ -48,16 +48,22 @@ set (lib_headers
${PROJECT_BINARY_DIR}/termo-config.h)
# Project libraries
# We need ncurses for one of the demos, so we're always looking
if (NCURSESW_FOUND)
include_directories (${NCURSESW_INCLUDE_DIRS})
set (curses_libraries ${NCURSESW_LIBRARIES})
elseif (CURSES_FOUND)
include_directories (${CURSES_INCLUDE_DIR})
set (curses_libraries ${CURSES_LIBRARY})
endif (NCURSESW_FOUND)
if (unibilium_FOUND)
include_directories (${unibilium_INCLUDE_DIRS})
set (lib_libraries ${unibilium_LIBRARIES})
add_definitions (-DHAVE_UNIBILIUM)
elseif (NCURSESW_FOUND)
elseif (curses_libraries)
include_directories (${NCURSESW_INCLUDE_DIRS})
set (lib_libraries ${NCURSESW_LIBRARIES})
elseif (CURSES_FOUND)
include_directories (${CURSES_INCLUDE_DIR})
set (lib_libraries ${CURSES_LIBRARY})
set (lib_libraries ${curses_libraries})
else (CURSES_FOUND)
message (SEND_ERROR "Unibilium not found, Curses not found")
endif (unibilium_FOUND)
@ -90,7 +96,7 @@ add_executable (demo-async EXCLUDE_FROM_ALL demo-async.c)
target_link_libraries (demo-async termo-static ${lib_libraries})
add_executable (demo-draw EXCLUDE_FROM_ALL demo-draw.c)
target_link_libraries (demo-draw termo-static ${lib_libraries})
target_link_libraries (demo-draw termo-static ${lib_libraries} ${curses_libraries})
add_executable (demo EXCLUDE_FROM_ALL demo.c)
target_link_libraries (demo termo-static ${lib_libraries})

View File

@ -227,15 +227,19 @@ load_terminfo (termo_ti_t *ti, const char *term)
if (node && !insert_seq (ti, value, node))
{
free (node);
// FIXME: unibi leak
return false;
}
}
// Clone the behaviour of ncurses for xterm mouse support
const char *set_mouse_string = NULL;
#ifdef HAVE_UNIBILIUM
const char *set_mouse_string = unibi_get_str (unibi, "XM");
size_t xm = unibi_add_ext_str (unibi, "XM", NULL);
if (xm != SIZE_MAX)
set_mouse_string = unibi_get_ext_str (unibi, xm);
#else
const char *set_mouse_string = tigetstr ("XM");
set_mouse_string = tigetstr ("XM");
#endif
if (!set_mouse_string || set_mouse_string == (char *) -1)
ti->set_mouse_string = strdup ("\E[?1000%?%p1%{1}%=%th%el%;");
@ -257,6 +261,7 @@ load_terminfo (termo_ti_t *ti, const char *term)
if (!insert_seq (ti, mouse_report_string, node))
{
free (node);
// FIXME: unibi leak
return false;
}
}
@ -334,9 +339,9 @@ set_mouse (termo_ti_t *ti, bool enable)
{
#ifdef HAVE_UNIBILIUM
unibi_var_t params[9] = { enable, 0, 0, 0, 0, 0, 0, 0, 0 };
char start_string[unibi_run (ti->set_mouse_string, params, NULL, 0)];
unibi_run (ti->set_mouse_string, params,
start_string, sizeof start_string);
char start_string[unibi_run (ti->set_mouse_string, params, NULL, 0) + 1];
start_string[unibi_run (ti->set_mouse_string, params,
start_string, sizeof start_string - 1)] = 0;
#else
char *start_string = tparm (ti->set_mouse_string,
enable, 0, 0, 0, 0, 0, 0, 0, 0);