Respect the constness of caseproto.
[pspp-builds.git] / src / data / caseproto.c
index 1b6827dbc3327847d13e5961ccce224d8c4f1967..68df141ba9f9638f72914b1822789764ac712d33 100644 (file)
@@ -59,6 +59,26 @@ caseproto_create (void)
   return proto;
 }
 
+
+struct caseproto *
+caseproto_clone (const struct caseproto *in)
+{
+  struct caseproto *proto = xmalloc (caseproto_size (in->n_widths));
+  proto->ref_cnt = 1;
+
+  proto->n_widths = in->n_widths;
+  proto->allocated_widths = in->allocated_widths;
+  
+  memcpy (proto->widths, in->widths, proto->n_widths *  sizeof *proto->widths);
+
+  proto->n_long_strings = in->n_long_strings;
+  proto->long_strings = NULL;
+  if ( proto->n_long_strings > 0)
+    caseproto_refresh_long_string_cache__ (proto);
+
+  return proto;
+}
+
 static void
 do_unref (void *proto_)
 {
@@ -330,7 +350,7 @@ caseproto_refresh_long_string_cache__ (const struct caseproto *proto_)
                                  * sizeof *proto->long_strings);
   n = 0;
   for (i = 0; i < proto->n_widths; i++)
-    if (proto->widths[i] >= MIN_LONG_STRING)
+    if (proto->widths[i] > MAX_SHORT_STRING)
       proto->long_strings[n++] = i;
   assert (n == proto->n_long_strings);
 }
@@ -406,6 +426,6 @@ count_long_strings (const struct caseproto *proto, size_t idx, size_t count)
 
   n = 0;
   for (i = 0; i < count; i++)
-    n += proto->widths[idx + i] >= MIN_LONG_STRING;
+    n += proto->widths[idx + i] > MAX_SHORT_STRING;
   return n;
 }