/****************************************************************************
- * Copyright (c) 1999-2013,2016 Free Software Foundation, Inc. *
+ * Copyright (c) 1999-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
#include <tic.h>
-MODULE_ID("$Id: alloc_ttype.c,v 1.28 2016/05/28 23:22:52 tom Exp $")
+MODULE_ID("$Id: alloc_ttype.c,v 1.29 2017/04/09 23:15:34 tom Exp $")
#if NCURSES_XNAMES
/*
to->num = (unsigned short) (to->num + (ext - to->ext))
static void
-realign_data(TERMTYPE *to, char **ext_Names,
+realign_data(TERMTYPE2 *to, char **ext_Names,
int ext_Booleans,
int ext_Numbers,
int ext_Strings)
if (to->ext_Numbers != ext_Numbers) {
EXTEND_NUM(num_Numbers, ext_Numbers);
- TYPE_REALLOC(short, to->num_Numbers, to->Numbers);
+ TYPE_REALLOC(NCURSES_INT2, to->num_Numbers, to->Numbers);
for (n = to->ext_Numbers - 1,
m = ext_Numbers - 1,
base = to->num_Numbers - (m + 1); m >= 0; m--) {
* Returns the first index in ext_Names[] for the given token-type
*/
static unsigned
-_nc_first_ext_name(TERMTYPE *tp, int token_type)
+_nc_first_ext_name(TERMTYPE2 *tp, int token_type)
{
unsigned first;
* Returns the last index in ext_Names[] for the given token-type
*/
static unsigned
-_nc_last_ext_name(TERMTYPE *tp, int token_type)
+_nc_last_ext_name(TERMTYPE2 *tp, int token_type)
{
unsigned last;
* Lookup an entry from extended-names, returning -1 if not found
*/
static int
-_nc_find_ext_name(TERMTYPE *tp, char *name, int token_type)
+_nc_find_ext_name(TERMTYPE2 *tp, char *name, int token_type)
{
unsigned j;
unsigned first = _nc_first_ext_name(tp, token_type);
* (e.g., Booleans[]).
*/
static int
-_nc_ext_data_index(TERMTYPE *tp, int n, int token_type)
+_nc_ext_data_index(TERMTYPE2 *tp, int n, int token_type)
{
switch (token_type) {
case BOOLEAN:
* data.
*/
static bool
-_nc_del_ext_name(TERMTYPE *tp, char *name, int token_type)
+_nc_del_ext_name(TERMTYPE2 *tp, char *name, int token_type)
{
int first;
* index into the corresponding data array is returned.
*/
static int
-_nc_ins_ext_name(TERMTYPE *tp, char *name, int token_type)
+_nc_ins_ext_name(TERMTYPE2 *tp, char *name, int token_type)
{
unsigned first = _nc_first_ext_name(tp, token_type);
unsigned last = _nc_last_ext_name(tp, token_type);
case NUMBER:
tp->ext_Numbers++;
tp->num_Numbers++;
- TYPE_REALLOC(short, tp->num_Numbers, tp->Numbers);
+ TYPE_REALLOC(NCURSES_INT2, tp->num_Numbers, tp->Numbers);
for (k = (unsigned) (tp->num_Numbers - 1); k > j; k--)
tp->Numbers[k] = tp->Numbers[k - 1];
break;
* cancellation of a name that is inherited from another entry.
*/
static void
-adjust_cancels(TERMTYPE *to, TERMTYPE *from)
+adjust_cancels(TERMTYPE2 *to, TERMTYPE2 *from)
{
int first = to->ext_Booleans + to->ext_Numbers;
int last = first + to->ext_Strings;
}
NCURSES_EXPORT(void)
-_nc_align_termtype(TERMTYPE *to, TERMTYPE *from)
+_nc_align_termtype(TERMTYPE2 *to, TERMTYPE2 *from)
{
int na = (int) NUM_EXT_NAMES(to);
int nb = (int) NUM_EXT_NAMES(from);
}
#endif
-NCURSES_EXPORT(void)
-_nc_copy_termtype(TERMTYPE *dst, const TERMTYPE *src)
+#define srcINT 1
+#define dstINT 2
+
+/*
+ * TERMTYPE and TERMTYPE2 differ only with regard to the values in Numbers.
+ * Use 'mode' to decide which to use.
+ */
+static void
+copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode)
{
-#if NCURSES_XNAMES
+#if NCURSES_XNAMES || NCURSES_EXT_NUMBERS
unsigned i;
#endif
+#if NCURSES_EXT_NUMBERS
+ short *oldptr = 0;
+ int *newptr = 0;
+#endif
+ DEBUG(2, ("copy_termtype"));
*dst = *src; /* ...to copy the sizes and string-tables */
TYPE_MALLOC(NCURSES_SBOOL, NUM_BOOLEANS(dst), dst->Booleans);
- TYPE_MALLOC(short, NUM_NUMBERS(dst), dst->Numbers);
TYPE_MALLOC(char *, NUM_STRINGS(dst), dst->Strings);
memcpy(dst->Booleans,
src->Booleans,
NUM_BOOLEANS(dst) * sizeof(dst->Booleans[0]));
- memcpy(dst->Numbers,
- src->Numbers,
- NUM_NUMBERS(dst) * sizeof(dst->Numbers[0]));
memcpy(dst->Strings,
src->Strings,
NUM_STRINGS(dst) * sizeof(dst->Strings[0]));
+#if NCURSES_EXT_NUMBERS
+ if ((mode & dstINT) == 0) {
+ DEBUG(2, ("...convert int ->short"));
+ TYPE_MALLOC(short, NUM_NUMBERS(dst), oldptr);
+ ((TERMTYPE *) dst)->Numbers = oldptr;
+ } else {
+ DEBUG(2, ("...copy without changing size"));
+ TYPE_MALLOC(int, NUM_NUMBERS(dst), newptr);
+ dst->Numbers = newptr;
+ }
+ if ((mode == srcINT) && (oldptr != 0)) {
+ DEBUG(2, ("...copy int ->short"));
+ for (i = 0; i < NUM_NUMBERS(dst); ++i) {
+ if (src->Numbers[i] > MAX_OF_TYPE(short)) {
+ oldptr[i] = MAX_OF_TYPE(short);
+ } else {
+ oldptr[i] = (short) src->Numbers[i];
+ }
+ }
+ } else if ((mode == dstINT) && (newptr != 0)) {
+ DEBUG(2, ("...copy short ->int"));
+ for (i = 0; i < NUM_NUMBERS(dst); ++i) {
+ newptr[i] = ((const short *) (src->Numbers))[i];
+ }
+ } else {
+ DEBUG(2, ("...copy %s without change",
+ (mode & dstINT)
+ ? "int"
+ : "short"));
+ memcpy(dst->Numbers,
+ src->Numbers,
+ NUM_NUMBERS(dst) * ((mode & dstINT)
+ ? sizeof(int)
+ : sizeof(short)));
+ }
+#else
+ (void) mode;
+ TYPE_MALLOC(short, NUM_NUMBERS(dst), dst->Numbers);
+ memcpy(dst->Numbers,
+ src->Numbers,
+ NUM_NUMBERS(dst) * sizeof(dst->Numbers[0]));
+#endif
+
/* FIXME: we probably should also copy str_table and ext_str_table,
* but tic and infocmp are not written to exploit that (yet).
*/
}
#endif
}
+
+/*
+ * This entrypoint is used by tack.
+ */
+NCURSES_EXPORT(void)
+_nc_copy_termtype(TERMTYPE *dst, const TERMTYPE *src)
+{
+ DEBUG(2, ("_nc_copy_termtype..."));
+ copy_termtype((TERMTYPE2 *) dst, (const TERMTYPE2 *) src, 0);
+}
+
+#if NCURSES_EXT_NUMBERS
+NCURSES_EXPORT(void)
+_nc_copy_termtype2(TERMTYPE2 *dst, const TERMTYPE2 *src)
+{
+ DEBUG(2, ("_nc_copy_termtype2..."));
+ copy_termtype(dst, src, srcINT | dstINT);
+}
+
+/*
+ * Use this for exporting the internal TERMTYPE2 to the legacy format used via
+ * the CUR macro by applications.
+ */
+NCURSES_EXPORT(void)
+_nc_export_termtype2(TERMTYPE *dst, const TERMTYPE2 *src)
+{
+ DEBUG(2, ("_nc_export_termtype2..."));
+ copy_termtype((TERMTYPE2 *) dst, src, srcINT);
+}
+
+/* FIXME - this will go away when conversion is complete */
+NCURSES_EXPORT(void)
+_nc_import_termtype2(TERMTYPE2 *dst, const TERMTYPE *src)
+{
+ DEBUG(2, ("_nc_import_termtype2..."));
+ copy_termtype(dst, (const TERMTYPE2 *) src, dstINT);
+}
+#endif /* NCURSES_EXT_NUMBERS */