X-Git-Url: http://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=ncurses%2Ftinfo%2Falloc_ttype.c;h=13710775d0227c31f418b3f8b45fc818e6f9f054;hb=cdbe3d3df7ca08989c4aaead5164309466e519eb;hp=116245e4dd8be17eafadfe4e85cad4f82cbb8449;hpb=92e187a3459ab7ce1613a3684ca6642447c73620;p=ncurses.git diff --git a/ncurses/tinfo/alloc_ttype.c b/ncurses/tinfo/alloc_ttype.c index 116245e4..13710775 100644 --- a/ncurses/tinfo/alloc_ttype.c +++ b/ncurses/tinfo/alloc_ttype.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1999-2009,2010 Free Software Foundation, Inc. * + * Copyright (c) 1999-2010,2012 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 * @@ -42,7 +42,7 @@ #include -MODULE_ID("$Id: alloc_ttype.c,v 1.21 2010/05/01 19:32:33 tom Exp $") +MODULE_ID("$Id: alloc_ttype.c,v 1.24 2012/03/01 01:21:56 tom Exp $") #if NCURSES_XNAMES /* @@ -90,6 +90,9 @@ find_name(char **table, int length, char *name) return FALSE; } +#define EXTEND_NUM(num, ext) \ + to->num = (unsigned short) (to->num + (ext - to->ext)) + static void realign_data(TERMTYPE *to, char **ext_Names, int ext_Booleans, @@ -100,7 +103,7 @@ realign_data(TERMTYPE *to, char **ext_Names, int limit = (to->ext_Booleans + to->ext_Numbers + to->ext_Strings); if (to->ext_Booleans != ext_Booleans) { - to->num_Booleans += (ext_Booleans - to->ext_Booleans); + EXTEND_NUM(num_Booleans, ext_Booleans); to->Booleans = typeRealloc(NCURSES_SBOOL, to->num_Booleans, to->Booleans); for (n = to->ext_Booleans - 1, m = ext_Booleans - 1, @@ -114,7 +117,7 @@ realign_data(TERMTYPE *to, char **ext_Names, to->ext_Booleans = UShort(ext_Booleans); } if (to->ext_Numbers != ext_Numbers) { - to->num_Numbers += (ext_Numbers - to->ext_Numbers); + EXTEND_NUM(num_Numbers, ext_Numbers); to->Numbers = typeRealloc(short, to->num_Numbers, to->Numbers); for (n = to->ext_Numbers - 1, m = ext_Numbers - 1, @@ -128,7 +131,7 @@ realign_data(TERMTYPE *to, char **ext_Names, to->ext_Numbers = UShort(ext_Numbers); } if (to->ext_Strings != ext_Strings) { - to->num_Strings += (ext_Strings - to->ext_Strings); + EXTEND_NUM(num_Strings, ext_Strings); to->Strings = typeRealloc(char *, to->num_Strings, to->Strings); for (n = to->ext_Strings - 1, m = ext_Strings - 1, @@ -470,7 +473,7 @@ _nc_align_termtype(TERMTYPE *to, TERMTYPE *from) #endif NCURSES_EXPORT(void) -_nc_copy_termtype(TERMTYPE *dst, TERMTYPE *src) +_nc_copy_termtype(TERMTYPE *dst, const TERMTYPE *src) { unsigned i; @@ -479,13 +482,15 @@ _nc_copy_termtype(TERMTYPE *dst, TERMTYPE *src) dst->Numbers = typeMalloc(short, NUM_NUMBERS(dst)); dst->Strings = typeMalloc(char *, NUM_STRINGS(dst)); - /* FIXME: use memcpy for these and similar loops */ - for_each_boolean(i, dst) - dst->Booleans[i] = src->Booleans[i]; - for_each_number(i, dst) - dst->Numbers[i] = src->Numbers[i]; - for_each_string(i, dst) - dst->Strings[i] = src->Strings[i]; + 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])); /* FIXME: we probably should also copy str_table and ext_str_table, * but tic and infocmp are not written to exploit that (yet).