- /* 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];
+ DEBUG(2, (T_CALLED("copy_termtype(dst=%p, src=%p, mode=%d)"), (void *)
+ dst, (const void *) src, mode));
+ *dst = *src; /* ...to copy the sizes and string-tables */
+
+ TYPE_MALLOC(NCURSES_SBOOL, NUM_BOOLEANS(dst), dst->Booleans);
+ TYPE_MALLOC(char *, NUM_STRINGS(dst), dst->Strings);
+
+ memcpy(dst->Booleans,
+ src->Booleans,
+ NUM_BOOLEANS(dst) * sizeof(dst->Booleans[0]));
+ memcpy(dst->Strings,
+ src->Strings,
+ NUM_STRINGS(dst) * sizeof(dst->Strings[0]));
+
+ new_table = NULL;
+ for (pass = 0; pass < 2; ++pass) {
+ size_t str_size = 0;
+ if (src->term_names != NULL) {
+ if (pass) {
+ dst->term_names = new_table + str_size;
+ strcpy(dst->term_names + str_size, src->term_names);
+ }
+ str_size += strlen(src->term_names) + 1;
+ }
+ for_each_string(i, src) {
+ if (VALID_STRING(src->Strings[i])) {
+ if (pass) {
+ strcpy(new_table + str_size, src->Strings[i]);
+ dst->Strings[i] = new_table + str_size;
+ }
+ str_size += strlen(src->Strings[i]) + 1;
+ }
+ }
+ if (pass) {
+ dst->str_table = new_table;
+ } else {
+ ++str_size;
+ if ((new_table = malloc(str_size)) == NULL)
+ _nc_err_abort(MSG_NO_MEMORY);
+ }
+ }