demanguse.c 1.7 KB

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