table.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* The IGEN simulator generator for GDB, the GNU Debugger.
  2. Copyright 2002-2022 Free Software Foundation, Inc.
  3. Contributed by Andrew Cagney.
  4. This file is part of GDB.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. /* Read a table, line by line, from a file.
  16. A table line has several forms:
  17. Field line:
  18. <text> { ":" <text> }
  19. type == table_colon_entry
  20. Fields points to a NULL terminated list of pointers.
  21. Tab indented block:
  22. <tab> <text> <nl> { <tab> <text> <nl> }
  23. type == table_code_entry
  24. The leading tab at the start of each line is discarded.
  25. fields[i] is the i'th line with the <nl> discarded.
  26. Code block:
  27. "{" <ignore-text> <nl> { <text> <nl> } "}" <ignore-text> <nl>
  28. type == table_code_entry
  29. The leading/trailing {/} lines are discarded.
  30. Lines containing two leading spaces have those spaces striped.
  31. fields[i] is the i'th line with the <nl> discarded.
  32. In addition, the table parser reconises and handles internally the
  33. following (when not in a code block):
  34. "#" <line-nr> '"' <file> '"'
  35. As per CPP/CC, treat following lines as if they were taken from
  36. <file> starting at <line-nr>
  37. No support for CPP's "#if/#else/#endif" style conditions are
  38. planned. */
  39. typedef struct _table table;
  40. typedef enum
  41. {
  42. table_colon_entry,
  43. table_code_entry,
  44. }
  45. table_entry_type;
  46. typedef struct _table_entry table_entry;
  47. struct _table_entry
  48. {
  49. table *file;
  50. line_ref *line;
  51. table_entry_type type;
  52. int nr_fields;
  53. char **field;
  54. };
  55. /* List of directories to search when opening a pushed file. Current
  56. directory is always searched first */
  57. typedef struct _table_include table_include;
  58. struct _table_include
  59. {
  60. char *dir;
  61. table_include *next;
  62. };
  63. /* Open/read a table file. Since the file is read once during open
  64. (and then closed immediately) there is no close method. */
  65. extern table *table_open (const char *file_name);
  66. extern table_entry *table_read (table *file);
  67. /* Push the the state of the current file and open FILE_NAME. When
  68. the end of FILE_NAME is reached, return to the pushed file */
  69. extern void table_push
  70. (table *file, line_ref *line, table_include *search, const char *file_name);
  71. /* Expand the specified field_nr using the internal expansion table.
  72. A field is only expanded when explicitly specified. */
  73. extern void table_expand_field (table_entry *entry, int field_nr);
  74. /* Given a code entry, write the code to FILE. Since any
  75. leading/trailing braces were striped as part of the read, they are
  76. not written. */
  77. extern void table_print_code (lf *file, table_entry *entry);
  78. /* Debugging */
  79. extern void dump_line_ref
  80. (lf *file, char *prefix, const line_ref *line, char *suffix);
  81. extern void dump_table_entry
  82. (lf *file, char *prefix, const table_entry *entry, char *suffix);
  83. /* Utilities for skipping around text */
  84. extern char *skip_digits (char *chp);
  85. extern char *skip_spaces (char *chp);
  86. extern char *skip_to_separator (char *chp, char *separators);
  87. extern char *back_spaces (char *start, char *chp);