1*c42dbd0eSchristos /* demanguse.c -- libiberty demangler usage
2*c42dbd0eSchristos Copyright (C) 2021-2022 Free Software Foundation, Inc.
3*c42dbd0eSchristos
4*c42dbd0eSchristos This file is part of GNU Binutils.
5*c42dbd0eSchristos
6*c42dbd0eSchristos This program is free software; you can redistribute it and/or modify
7*c42dbd0eSchristos it under the terms of the GNU General Public License as published by
8*c42dbd0eSchristos the Free Software Foundation; either version 3 of the License, or
9*c42dbd0eSchristos (at your option) any later version.
10*c42dbd0eSchristos
11*c42dbd0eSchristos This program is distributed in the hope that it will be useful,
12*c42dbd0eSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of
13*c42dbd0eSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*c42dbd0eSchristos GNU General Public License for more details.
15*c42dbd0eSchristos
16*c42dbd0eSchristos You should have received a copy of the GNU General Public License
17*c42dbd0eSchristos along with this program; if not, write to the Free Software
18*c42dbd0eSchristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
19*c42dbd0eSchristos 02110-1301, USA. */
20*c42dbd0eSchristos
21*c42dbd0eSchristos #include <stdio.h>
22*c42dbd0eSchristos #include <string.h>
23*c42dbd0eSchristos #include "demangle.h"
24*c42dbd0eSchristos #include "demanguse.h"
25*c42dbd0eSchristos
26*c42dbd0eSchristos /* Print the list of demangling styles to STREAM. A one line MSG is
27*c42dbd0eSchristos printed before the styles. Output is limited to 80 columns, with
28*c42dbd0eSchristos continuation lines being indented by leading spaces in MSG. */
29*c42dbd0eSchristos
30*c42dbd0eSchristos void
display_demangler_styles(FILE * stream,const char * msg)31*c42dbd0eSchristos display_demangler_styles (FILE *stream, const char *msg)
32*c42dbd0eSchristos {
33*c42dbd0eSchristos const struct demangler_engine *info = libiberty_demanglers;
34*c42dbd0eSchristos int col;
35*c42dbd0eSchristos int lead_spaces = 0;
36*c42dbd0eSchristos const char *cont = "";
37*c42dbd0eSchristos
38*c42dbd0eSchristos while (msg[lead_spaces] == ' ')
39*c42dbd0eSchristos ++lead_spaces;
40*c42dbd0eSchristos col = fprintf (stream, "%s", msg);
41*c42dbd0eSchristos while (info->demangling_style_name)
42*c42dbd0eSchristos {
43*c42dbd0eSchristos if (col + strlen (info->demangling_style_name) >= 75)
44*c42dbd0eSchristos {
45*c42dbd0eSchristos fprintf (stream, "%.1s\n", cont);
46*c42dbd0eSchristos col = fprintf (stream, "%.*s", lead_spaces, msg);
47*c42dbd0eSchristos cont = "";
48*c42dbd0eSchristos }
49*c42dbd0eSchristos col += fprintf (stream, "%s\"%s\"", cont, info->demangling_style_name);
50*c42dbd0eSchristos cont = ", ";
51*c42dbd0eSchristos ++info;
52*c42dbd0eSchristos }
53*c42dbd0eSchristos fprintf (stream, "\n");
54*c42dbd0eSchristos }
55