initial version of autocovariance function
[pspp-builds.git] / src / libpspp / str.c
index 70edaeede16c0ac5bdf871d620b690cbd7118d59..655774d63d57c8e1b9b146b9d513edc8abe2a387 100644 (file)
@@ -236,6 +236,21 @@ str_lowercase (char *s)
   for (; *s != '\0'; s++)
     *s = tolower ((unsigned char) *s);
 }
+
+/* Formats FORMAT into DST, as with sprintf(), and returns the
+   address of the terminating null written to DST. */
+char *
+spprintf (char *dst, const char *format, ...) 
+{
+  va_list args;
+  int count;
+
+  va_start (args, format);
+  count = vsprintf (dst, format, args);
+  va_end (args);
+
+  return dst + count;
+}
 \f
 /* Initializes ST with initial contents S. */
 void
@@ -247,13 +262,13 @@ ds_create (struct string *st, const char *s)
   strcpy (st->string, s);
 }
 
-/* Initializes ST, making room for at least CAPACITY characters. */
+/* Initializes ST as an empty string. */
 void
-ds_init (struct string *st, size_t capacity)
+ds_init (struct string *st)
 {
   st->length = 0;
-  st->capacity = MAX (8, capacity);
-  st->string = xmalloc (st->capacity + 1);
+  st->capacity = 0;
+  st->string = NULL;
 }
 
 /* Frees ST. */
@@ -285,7 +300,7 @@ ds_init_substring (struct string *dst,
                    const struct string *src, size_t idx, size_t cnt)
 {
   assert (dst != src);
-  ds_init (dst, cnt);
+  ds_init (dst);
   ds_assign_substring (dst, src, idx, cnt);
 }