-#if 0
-static void
+static inline void
write_str(FILE *fp, const char *str)
{
- if (fputs (str, fp) == EOF || putc (0, fp) == EOF)
+ if (fputs(str, fp) == EOF || putc(0, fp) == EOF)
{
- perror("write error");
+ perror("write error str");
exit(1);
}
}
-#endif
/*
* Array of Ids
}
static int
-cmp_ids (const void *pa, const void *pb, void *dp)
+cmp_ids(const void *pa, const void *pb, void *dp)
{
Id a = *(Id *)pa;
Id b = *(Id *)pb;
if (sids[i] == marker)
break;
if (i > 1)
- sat_sort(sids, i, sizeof (Id), cmp_ids, 0);
+ sat_sort(sids, i, sizeof(Id), cmp_ids, 0);
if ((len - i) > 2)
sat_sort(sids + i + 1, len - i - 1, sizeof(Id), cmp_ids, 0);
if (sids[i] == marker)
break;
if (i > 1)
- sat_sort(sids, i, sizeof (Id), cmp_ids, 0);
+ sat_sort(sids, i, sizeof(Id), cmp_ids, 0);
if ((len - i) > 2)
sat_sort(sids + i + 1, len - i - 1, sizeof(Id), cmp_ids, 0);
solv_flags |= SOLV_FLAG_PREFIX_POOL;
write_u32(fp, solv_flags);
+ /*
+ * calculate prefix encoding of the strings
+ */
+ unsigned char *prefixcomp = sat_malloc(nstrings);
+ unsigned int compsum = 0;
+ char *old_str = "";
+
+ prefixcomp[0] = 0;
+ for (i = 1; i < nstrings; i++)
+ {
+ char *str = spool->stringspace + spool->strings[needid[i].map];
+ int same;
+ for (same = 0; same < 255; same++)
+ if (!old_str[same] || old_str[same] != str[same])
+ break;
+ prefixcomp[i] = same;
+ compsum += same;
+ old_str = str;
+ }
+
+ /*
+ * write strings
+ */
+ write_u32(fp, sizeid);
+ /* we save compsum bytes but need 1 extra byte for every string */
+ write_u32(fp, sizeid + (nstrings ? nstrings - 1 : 0) - compsum);
+ if (sizeid + (nstrings ? nstrings - 1 : 0) != compsum)
+ {
+ for (i = 1; i < nstrings; i++)
+ {
+ char *str = spool->stringspace + spool->strings[needid[i].map];
+ write_u8(fp, prefixcomp[i]);
+ write_str(fp, str + prefixcomp[i]);
+ }
+ }
+ sat_free(prefixcomp);
+
+#if 0
/* Build the prefix-encoding of the string pool. We need to know
the size of that before writing it to the file, so we have to
build a separate buffer for that. As it's temporarily possible
break;
*pp++ = same;
len = strlen(str + same) + 1;
- memcpy (pp, str + same, len);
+ memcpy(pp, str + same, len);
pp += len;
old_str = str;
}
}
}
sat_free(prefix);
+#endif
/*
* write RelDeps