- dst->Booleans = typeMalloc(NCURSES_SBOOL, NUM_BOOLEANS(dst));
- 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];
+
+ 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]));
+
+#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