1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
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 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 /* Read a table, line by line, from a file.
24 A table line has several forms:
29 type == table_colon_entry
31 Fields points to a NULL terminated list of pointers.
35 <tab> <text> <nl> { <tab> <text> <nl> }
36 type == table_code_entry
38 The leading tab at the start of each line is discarded.
39 fields[i] is the i'th line with the <nl> discarded.
44 "{" <ignore-text> <nl> { <text> <nl> } "}" <ignore-text> <nl>
45 type == table_code_entry
47 The leading/trailing {/} lines are discarded.
48 Lines containing two leading spaces have those spaces striped.
49 fields[i] is the i'th line with the <nl> discarded.
51 In addition, the table parser reconises and handles internally the
52 following (when not in a code block):
54 "#" <line-nr> '"' <file> '"'
56 As per CPP/CC, treat following lines as if they were taken from
57 <file> starting at <line-nr>
59 No support for CPP's "#if/#else/#endif" style conditions are
62 typedef struct _table table;
70 typedef struct _table_entry table_entry;
74 table_entry_type type;
79 /* List of directories to search when opening a pushed file. Current
80 directory is always searched first */
81 typedef struct _table_include table_include;
82 struct _table_include {
88 /* Open/read a table file. Since the file is read once during open
89 (and then closed immediatly) there is no close method. */
91 extern table *table_open
92 (const char *file_name);
94 extern table_entry *table_read
98 /* Push the the state of the current file and open FILE_NAME. When
99 the end of FILE_NAME is reached, return to the pushed file */
101 extern void table_push
104 table_include *search,
105 const char *file_name);
108 /* Expand the specified field_nr using the internal expansion table.
109 A field is only expanded when explicitly specified. */
111 extern void table_expand_field
116 /* Given a code entry, write the code to FILE. Since any
117 leading/trailing braces were striped as part of the read, they are
120 extern void table_print_code
127 extern void dump_line_ref
130 const line_ref *line,
133 extern void dump_table_entry
136 const table_entry *entry,
141 /* Utilities for skipping around text */
143 extern char *skip_digits
146 extern char *skip_spaces
149 extern char *skip_to_separator
153 extern char *back_spaces