]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/write_entry.c
ncurses 6.1 - patch 20180331
[ncurses.git] / ncurses / tinfo / write_entry.c
index f55686fe11c1b9a1a422fc077903418198e86f08..843cc2ea35a0b6635b9e82df79229b36bc57b579 100644 (file)
@@ -50,7 +50,7 @@
 #define TRACE_NUM(n)           /* nothing */
 #endif
 
 #define TRACE_NUM(n)           /* nothing */
 #endif
 
-MODULE_ID("$Id: write_entry.c,v 1.102 2018/02/11 20:24:28 Julien.Cristau Exp $")
+MODULE_ID("$Id: write_entry.c,v 1.104 2018/04/01 00:51:04 tom Exp $")
 
 static int total_written;
 static int total_parts;
 
 static int total_written;
 static int total_parts;
@@ -796,7 +796,8 @@ _nc_write_object(TERMTYPE2 *tp, char *buffer, unsigned *offset, unsigned limit)
 
 #if NCURSES_XNAMES
     if (extended_object(tp)) {
 
 #if NCURSES_XNAMES
     if (extended_object(tp)) {
-       unsigned extcnt = (unsigned) NUM_EXT_NAMES(tp);
+       unsigned ext_total = (unsigned) NUM_EXT_NAMES(tp);
+       unsigned ext_usage = ext_total;
 
        if (even_boundary(nextfree))
            return (ERR);
 
        if (even_boundary(nextfree))
            return (ERR);
@@ -810,10 +811,16 @@ _nc_write_object(TERMTYPE2 *tp, char *buffer, unsigned *offset, unsigned limit)
            return (ERR);
 
        nextfree += compute_offsets(tp->ext_Names,
            return (ERR);
 
        nextfree += compute_offsets(tp->ext_Names,
-                                   (size_t) extcnt,
+                                   (size_t) ext_total,
                                    offsets + tp->ext_Strings);
        TRACE_OUT(("after extended capnames, nextfree=%d", nextfree));
                                    offsets + tp->ext_Strings);
        TRACE_OUT(("after extended capnames, nextfree=%d", nextfree));
-       strmax = tp->ext_Strings + extcnt;
+       strmax = tp->ext_Strings + ext_total;
+       for (i = 0; i < tp->ext_Strings; ++i) {
+           if (VALID_STRING(tp->Strings[i + STRCOUNT])) {
+               ext_usage++;
+           }
+       }
+       TRACE_OUT(("will write %u/%lu strings", ext_usage, (unsigned long) strmax));
 
        /*
         * Write the extended header
 
        /*
         * Write the extended header
@@ -821,7 +828,7 @@ _nc_write_object(TERMTYPE2 *tp, char *buffer, unsigned *offset, unsigned limit)
        LITTLE_ENDIAN(buf + 0, tp->ext_Booleans);
        LITTLE_ENDIAN(buf + 2, tp->ext_Numbers);
        LITTLE_ENDIAN(buf + 4, tp->ext_Strings);
        LITTLE_ENDIAN(buf + 0, tp->ext_Booleans);
        LITTLE_ENDIAN(buf + 2, tp->ext_Numbers);
        LITTLE_ENDIAN(buf + 4, tp->ext_Strings);
-       LITTLE_ENDIAN(buf + 6, strmax);
+       LITTLE_ENDIAN(buf + 6, ext_usage);
        LITTLE_ENDIAN(buf + 8, nextfree);
        TRACE_OUT(("WRITE extended-header @%d", *offset));
        if (Write(buf, 10, 1) != 1)
        LITTLE_ENDIAN(buf + 8, nextfree);
        TRACE_OUT(("WRITE extended-header @%d", *offset));
        if (Write(buf, 10, 1) != 1)
@@ -868,7 +875,7 @@ _nc_write_object(TERMTYPE2 *tp, char *buffer, unsigned *offset, unsigned limit)
        /*
         * Write the extended names
         */
        /*
         * Write the extended names
         */
-       for (i = 0; i < extcnt; i++) {
+       for (i = 0; i < ext_total; i++) {
            TRACE_OUT(("WRITE ext_Names[%d]=%s", (int) i, tp->ext_Names[i]));
            if (!WRITE_STRING(tp->ext_Names[i]))
                return (ERR);
            TRACE_OUT(("WRITE ext_Names[%d]=%s", (int) i, tp->ext_Names[i]));
            if (!WRITE_STRING(tp->ext_Names[i]))
                return (ERR);