Fix generate.pl for Perl 5.6.1.
[pspp] / src / str.c
index 9d2d0b3c4023226cb08b57dcb9f4b222057b8347..0ad0e2f5899647d7b923afd1fe59e9d7f8ec6bef 100644 (file)
--- a/src/str.c
+++ b/src/str.c
@@ -14,8 +14,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA. */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA. */
 
 #include <config.h>
 #include "str.h"
@@ -95,7 +95,7 @@ mm_reverse (void *p, size_t nbytes)
    HAYSTACK_LEN.  Returns a pointer to the needle found. */
 char *
 mm_find_reverse (const char *haystack, size_t haystack_len,
-        const char *needle, size_t needle_len)
+                 const char *needle, size_t needle_len)
 {
   int i;
   for (i = haystack_len - needle_len; i >= 0; i--)
@@ -104,6 +104,26 @@ mm_find_reverse (const char *haystack, size_t haystack_len,
   return 0;
 }
 
+/* Compares the SIZE bytes in A to those in B, disregarding case,
+   and returns a strcmp()-type result. */
+int
+mm_case_compare (const void *a_, const void *b_, size_t size)
+{
+  const unsigned char *a = a_;
+  const unsigned char *b = b_;
+
+  while (size-- > 0) 
+    {
+      unsigned char ac = toupper (*a++);
+      unsigned char bc = toupper (*b++);
+
+      if (ac != bc) 
+        return ac > bc ? 1 : -1;
+    }
+
+  return 0;
+}
+
 /* Compares A of length A_LEN to B of length B_LEN.  The shorter
    string is considered to be padded with spaces to the length of
    the longer. */
@@ -194,6 +214,31 @@ st_pad_copy (char *dest, const char *src, size_t n)
       dest[n - 1] = 0;
     }
 }
+
+/* Copies SRC to DST, truncating DST to N-1 characters if
+   necessary.  Always appends a null character. */
+void
+st_trim_copy (char *dst, const char *src, size_t n) 
+{
+  size_t len = strlen (src);
+  assert (n > 0);
+  if (len + 1 < n)
+    memcpy (dst, src, len + 1);
+  else 
+    {
+      memcpy (dst, src, n - 1);
+      dst[n - 1] = '\0';
+    }
+}
+
+
+/* Converts each character in S to uppercase. */
+void
+st_uppercase (char *s) 
+{
+  for (; *s != '\0'; s++)
+    *s = toupper ((unsigned char) *s);
+}
 \f
 /* Initializes ST with initial contents S. */
 void
@@ -326,6 +371,13 @@ ds_c_str (const struct string *st)
   return st->string;
 }
 
+/* Returns the string data inside ST. */
+char *
+ds_data (const struct string *st)
+{
+  return st->string;
+}
+
 /* Returns a pointer to the null terminator ST.
    This might not be an actual null character unless ds_c_str() has
    been called since the last modification to ST. */
@@ -521,7 +573,7 @@ ds_get_config_line (FILE *stream, struct string *st, struct file_locator *where)
 /* Creates a new lengthed string LS with contents as a copy of
    S. */
 void
-ls_create (struct len_string *ls, const char *s)
+ls_create (struct fixed_string *ls, const char *s)
 {
   ls->length = strlen (s);
   ls->string = xmalloc (ls->length + 1);
@@ -531,7 +583,7 @@ ls_create (struct len_string *ls, const char *s)
 /* Creates a new lengthed string LS with contents as a copy of
    BUFFER with length LEN. */
 void
-ls_create_buffer (struct len_string *ls,
+ls_create_buffer (struct fixed_string *ls,
                  const char *buffer, size_t len)
 {
   ls->length = len;
@@ -542,7 +594,7 @@ ls_create_buffer (struct len_string *ls,
 
 /* Sets the fields of LS to the specified values. */
 void
-ls_init (struct len_string *ls, const char *string, size_t length)
+ls_init (struct fixed_string *ls, const char *string, size_t length)
 {
   ls->string = (char *) string;
   ls->length = length;
@@ -550,49 +602,49 @@ ls_init (struct len_string *ls, const char *string, size_t length)
 
 /* Copies the fields of SRC to DST. */
 void
-ls_shallow_copy (struct len_string *dst, const struct len_string *src)
+ls_shallow_copy (struct fixed_string *dst, const struct fixed_string *src)
 {
   *dst = *src;
 }
 
 /* Frees the memory backing LS. */
 void
-ls_destroy (struct len_string *ls)
+ls_destroy (struct fixed_string *ls)
 {
   free (ls->string);
 }
 
 /* Sets LS to a null pointer value. */
 void
-ls_null (struct len_string *ls)
+ls_null (struct fixed_string *ls)
 {
   ls->string = NULL;
 }
 
 /* Returns nonzero only if LS has a null pointer value. */
 int
-ls_null_p (const struct len_string *ls)
+ls_null_p (const struct fixed_string *ls)
 {
   return ls->string == NULL;
 }
 
 /* Returns nonzero only if LS is a null pointer or has length 0. */
 int
-ls_empty_p (const struct len_string *ls)
+ls_empty_p (const struct fixed_string *ls)
 {
   return ls->string == NULL || ls->length == 0;
 }
 
 /* Returns the length of LS, which must not be null. */
 size_t
-ls_length (const struct len_string *ls)
+ls_length (const struct fixed_string *ls)
 {
   return ls->length;
 }
 
 /* Returns a pointer to the character string in LS. */
 char *
-ls_c_str (const struct len_string *ls)
+ls_c_str (const struct fixed_string *ls)
 {
   return (char *) ls->string;
 }
@@ -600,7 +652,7 @@ ls_c_str (const struct len_string *ls)
 /* Returns a pointer to the null terminator of the character string in
    LS. */
 char *
-ls_end (const struct len_string *ls)
+ls_end (const struct fixed_string *ls)
 {
   return (char *) (ls->string + ls->length);
 }