Remove K&R cruft.
[gnulib.git] / lib / readtokens.c
index 651b5ef..bb42772 100644 (file)
@@ -1,5 +1,5 @@
 /* readtokens.c  -- Functions for reading tokens from an input stream.
-   Copyright (C) 1990-1991 Jim Meyering.
+   Copyright (C) 1990-1991, 1999, 2001, 2003 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -49,8 +49,8 @@
 #endif /* not STDC_HEADERS and not HAVE_STRING_H */
 
 #include "readtokens.h"
-void *xmalloc ();
-void *xrealloc ();
+#include "unlocked-io.h"
+#include "xalloc.h"
 
 #define STREQ(a,b) ((a) == (b) || ((a) && (b) && *(a) == *(b) \
                                   && strcmp(a, b) == 0))
@@ -62,7 +62,7 @@ init_tokenbuffer (tokenbuffer)
      token_buffer *tokenbuffer;
 {
   tokenbuffer->size = INITIAL_TOKEN_LENGTH;
-  tokenbuffer->buffer = ((char *) xmalloc (INITIAL_TOKEN_LENGTH));
+  tokenbuffer->buffer = xmalloc (INITIAL_TOKEN_LENGTH);
 }
 
 /* Read a token from `stream' into `tokenbuffer'.
@@ -77,11 +77,10 @@ init_tokenbuffer (tokenbuffer)
    and on files that aren't newline-terminated.  */
 
 long
-readtoken (stream, delim, n_delim, tokenbuffer)
-     FILE *stream;
-     const char *delim;
-     int n_delim;
-     token_buffer *tokenbuffer;
+readtoken (FILE *stream,
+          const char *delim,
+          int n_delim,
+          token_buffer *tokenbuffer)
 {
   char *p;
   int c, i, n;
@@ -109,11 +108,12 @@ readtoken (stream, delim, n_delim, tokenbuffer)
   if (!same_delimiters)
     {
       const char *t;
+      unsigned int j;
       saved_delim = delim;
-      for (i = 0; i < sizeof (isdelim); i++)
-       isdelim[i] = 0;
+      for (j = 0; j < sizeof (isdelim); j++)
+       isdelim[j] = 0;
       for (t = delim; *t; t++)
-       isdelim[(unsigned int) *t] = 1;
+       isdelim[(unsigned char) *t] = 1;
     }
 
   p = tokenbuffer->buffer;
@@ -164,14 +164,12 @@ readtoken (stream, delim, n_delim, tokenbuffer)
    %%% realloc() of `tokens' just before returning? */
 
 int
-readtokens (stream, projected_n_tokens, delim, n_delim,
-           tokens_out, token_lengths)
-     FILE *stream;
-     int projected_n_tokens;
-     const char *delim;
-     int n_delim;
-     char ***tokens_out;
-     long **token_lengths;
+readtokens (FILE *stream,
+           int projected_n_tokens,
+           const char *delim,
+           int n_delim,
+           char ***tokens_out,
+           long **token_lengths)
 {
   token_buffer tb, *token = &tb;
   int token_length;
@@ -186,8 +184,8 @@ readtokens (stream, projected_n_tokens, delim, n_delim,
   else
     projected_n_tokens = 64;
   sz = projected_n_tokens;
-  tokens = (char **) xmalloc (sz * sizeof (char *));
-  lengths = (long *) xmalloc (sz * sizeof (long));
+  tokens = xmalloc (sz * sizeof (char *));
+  lengths = xmalloc (sz * sizeof (long));
 
   init_tokenbuffer (token);
   for (;;)
@@ -197,8 +195,8 @@ readtokens (stream, projected_n_tokens, delim, n_delim,
       if (n_tokens >= sz)
        {
          sz *= 2;
-         tokens = (char **) xrealloc (tokens, sz * sizeof (char *));
-         lengths = (long *) xrealloc (lengths, sz * sizeof (long));
+         tokens = xrealloc (tokens, sz * sizeof (char *));
+         lengths = xrealloc (lengths, sz * sizeof (long));
        }
 
       if (token_length < 0)
@@ -208,7 +206,7 @@ readtokens (stream, projected_n_tokens, delim, n_delim,
          lengths[n_tokens] = -1;
          break;
        }
-      tmp = (char *) xmalloc ((token_length + 1) * sizeof (char));
+      tmp = xmalloc ((token_length + 1) * sizeof (char));
       lengths[n_tokens] = token_length;
       tokens[n_tokens] = strncpy (tmp, token->buffer,
                                  (unsigned) (token_length + 1));