1 /* Demangler test program,
2 Copyright (C) 2002 Free Software Foundation, Inc.
3 Written by Zack Weinberg <zack@codesourcery.com
5 This file is part of GNU libiberty.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include "libiberty.h"
36 static unsigned int lineno
;
38 /* Safely read a single line of arbitrary length from standard input. */
46 char *data
= buf
->data
;
47 size_t alloc
= buf
->alloced
;
53 data
= xmalloc (LINELEN
);
57 /* Skip comment lines. */
58 while ((c
= getchar()) == '#')
60 while ((c
= getchar()) != EOF
&& c
!= '\n');
64 /* c is the first character on the line, and it's not a comment
65 line: copy this line into the buffer and return. */
66 while (c
!= EOF
&& c
!= '\n')
71 data
= xrealloc (data
, alloc
);
83 /* The tester operates on a data file consisting of triples of lines:
88 The format switch is expected to be either the empty string, a
89 line of the form --format=<name>, or just <name> by itself. */
91 #define FORMATS "--format="
92 #define FORMATL (sizeof FORMATS - 1)
99 enum demangling_styles style
;
110 fprintf (stderr
, "usage: %s < test-set\n", argv
[0]);
129 fstyle
= format
.data
;
130 if (!strncmp (fstyle
, FORMATS
, FORMATL
))
133 if (fstyle
[0] == '\0')
134 style
= auto_demangling
;
136 style
= cplus_demangle_name_to_style (fstyle
);
138 if (style
== unknown_demangling
)
140 printf ("FAIL at line %d: unknown demangling style %s\n",
146 cplus_demangle_set_style (style
);
148 result
= cplus_demangle (input
.data
,
149 DMGL_PARAMS
|DMGL_ANSI
|DMGL_VERBOSE
|DMGL_TYPES
);
152 ? strcmp (result
, expect
.data
)
153 : strcmp (input
.data
, expect
.data
))
156 FAIL at line %d, style %s:\n\
173 printf ("%s: %d tests, %d failures\n", argv
[0], tests
, failures
);
174 return failures
? 1 : 0;