Print this page
libiberty/testsuite: Avoid conflicting getline()


  29 #ifdef HAVE_STRING_H
  30 #include <string.h>
  31 #endif
  32 #if HAVE_STDLIB_H
  33 # include <stdlib.h>
  34 #endif
  35 
  36 struct line
  37 {
  38   size_t alloced;
  39   char *data;
  40 };
  41 
  42 static unsigned int lineno;
  43 
  44 /* Safely read a single line of arbitrary length from standard input.  */
  45 
  46 #define LINELEN 80
  47 
  48 static void
  49 getline(buf)
  50      struct line *buf;
  51 {
  52   char *data = buf->data;
  53   size_t alloc = buf->alloced;
  54   size_t count = 0;
  55   int c;
  56 
  57   if (data == 0)
  58     {
  59       data = xmalloc (LINELEN);
  60       alloc = LINELEN;
  61     }
  62 
  63   /* Skip comment lines.  */
  64   while ((c = getchar()) == '#')
  65     {
  66       while ((c = getchar()) != EOF && c != '\n');
  67       lineno++;
  68     }
  69 


 179   struct line input;
 180   struct line expect;
 181   char *result;
 182   int failures = 0;
 183   int tests = 0;
 184 
 185   if (argc > 1)
 186     {
 187       fprintf (stderr, "usage: %s < test-set\n", argv[0]);
 188       return 2;
 189     }
 190 
 191   format.data = 0;
 192   input.data = 0;
 193   expect.data = 0;
 194 
 195   for (;;)
 196     {
 197       const char *inp;
 198       
 199       getline (&format);
 200       if (feof (stdin))
 201         break;
 202 
 203       getline (&input);
 204       getline (&expect);
 205 
 206       inp = protect_end (input.data);
 207 
 208       tests++;
 209 
 210       no_params = 0;
 211       ret_postfix = 0;
 212       is_v3_ctor = 0;
 213       is_v3_dtor = 0;
 214       if (format.data[0] == '\0')
 215         style = auto_demangling;
 216       else if (format.data[0] != '-')
 217         {
 218           style = cplus_demangle_name_to_style (format.data);
 219           if (style == unknown_demangling)
 220             {
 221               printf ("FAIL at line %d: unknown demangling style %s\n",
 222                       lineno, format.data);
 223               failures++;
 224               continue;


 305           continue;
 306         }
 307 
 308       cplus_demangle_set_style (style);
 309 
 310       result = cplus_demangle (inp,
 311                                DMGL_PARAMS|DMGL_ANSI|DMGL_TYPES
 312                                |(ret_postfix ? DMGL_RET_POSTFIX : 0));
 313 
 314       if (result
 315           ? strcmp (result, expect.data)
 316           : strcmp (input.data, expect.data))
 317         {
 318           fail (lineno, format.data, input.data, result, expect.data);
 319           failures++;
 320         }
 321       free (result);
 322 
 323       if (no_params)
 324         {
 325           getline (&expect);
 326           result = cplus_demangle (inp, DMGL_ANSI|DMGL_TYPES);
 327 
 328           if (result
 329               ? strcmp (result, expect.data)
 330               : strcmp (input.data, expect.data))
 331             {
 332               fail (lineno, format.data, input.data, result, expect.data);
 333               failures++;
 334             }
 335           free (result);
 336         }
 337     }
 338 
 339   free (format.data);
 340   free (input.data);
 341   free (expect.data);
 342 
 343   printf ("%s: %d tests, %d failures\n", argv[0], tests, failures);
 344   return failures ? 1 : 0;
 345 }


  29 #ifdef HAVE_STRING_H
  30 #include <string.h>
  31 #endif
  32 #if HAVE_STDLIB_H
  33 # include <stdlib.h>
  34 #endif
  35 
  36 struct line
  37 {
  38   size_t alloced;
  39   char *data;
  40 };
  41 
  42 static unsigned int lineno;
  43 
  44 /* Safely read a single line of arbitrary length from standard input.  */
  45 
  46 #define LINELEN 80
  47 
  48 static void
  49 _getline(buf)
  50      struct line *buf;
  51 {
  52   char *data = buf->data;
  53   size_t alloc = buf->alloced;
  54   size_t count = 0;
  55   int c;
  56 
  57   if (data == 0)
  58     {
  59       data = xmalloc (LINELEN);
  60       alloc = LINELEN;
  61     }
  62 
  63   /* Skip comment lines.  */
  64   while ((c = getchar()) == '#')
  65     {
  66       while ((c = getchar()) != EOF && c != '\n');
  67       lineno++;
  68     }
  69 


 179   struct line input;
 180   struct line expect;
 181   char *result;
 182   int failures = 0;
 183   int tests = 0;
 184 
 185   if (argc > 1)
 186     {
 187       fprintf (stderr, "usage: %s < test-set\n", argv[0]);
 188       return 2;
 189     }
 190 
 191   format.data = 0;
 192   input.data = 0;
 193   expect.data = 0;
 194 
 195   for (;;)
 196     {
 197       const char *inp;
 198       
 199       _getline (&format);
 200       if (feof (stdin))
 201         break;
 202 
 203       _getline (&input);
 204       _getline (&expect);
 205 
 206       inp = protect_end (input.data);
 207 
 208       tests++;
 209 
 210       no_params = 0;
 211       ret_postfix = 0;
 212       is_v3_ctor = 0;
 213       is_v3_dtor = 0;
 214       if (format.data[0] == '\0')
 215         style = auto_demangling;
 216       else if (format.data[0] != '-')
 217         {
 218           style = cplus_demangle_name_to_style (format.data);
 219           if (style == unknown_demangling)
 220             {
 221               printf ("FAIL at line %d: unknown demangling style %s\n",
 222                       lineno, format.data);
 223               failures++;
 224               continue;


 305           continue;
 306         }
 307 
 308       cplus_demangle_set_style (style);
 309 
 310       result = cplus_demangle (inp,
 311                                DMGL_PARAMS|DMGL_ANSI|DMGL_TYPES
 312                                |(ret_postfix ? DMGL_RET_POSTFIX : 0));
 313 
 314       if (result
 315           ? strcmp (result, expect.data)
 316           : strcmp (input.data, expect.data))
 317         {
 318           fail (lineno, format.data, input.data, result, expect.data);
 319           failures++;
 320         }
 321       free (result);
 322 
 323       if (no_params)
 324         {
 325           _getline (&expect);
 326           result = cplus_demangle (inp, DMGL_ANSI|DMGL_TYPES);
 327 
 328           if (result
 329               ? strcmp (result, expect.data)
 330               : strcmp (input.data, expect.data))
 331             {
 332               fail (lineno, format.data, input.data, result, expect.data);
 333               failures++;
 334             }
 335           free (result);
 336         }
 337     }
 338 
 339   free (format.data);
 340   free (input.data);
 341   free (expect.data);
 342 
 343   printf ("%s: %d tests, %d failures\n", argv[0], tests, failures);
 344   return failures ? 1 : 0;
 345 }