]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/ppc/table.c
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 #include <sys/types.h>
50 table_open(char *file_name
,
57 /* create a file descriptor */
60 file
->nr_fields
= nr_fields
;
62 /* save the file name */
63 file
->file_name
= (char*)zalloc(strlen(file_name
) + 1);
64 ASSERT(file
->file_name
!= NULL
);
65 strcpy(file
->file_name
, file_name
);
68 fd
= open(file
->file_name
, O_RDONLY
, 0);
71 /* determine the size */
72 if (fstat(fd
, &stat_buf
) < 0) {
73 perror("table_open.fstat");
76 file
->size
= stat_buf
.st_size
;
78 /* allocate this much memory */
79 file
->buffer
= (char*)zalloc(file
->size
+1);
80 if(file
->buffer
== NULL
) {
81 perror("table_open.calloc.file->size+1");
84 file
->pos
= file
->buffer
;
87 if (read(fd
, file
->buffer
, file
->size
) < file
->size
) {
88 perror("table_open.read");
91 file
->buffer
[file
->size
] = '\0';
100 table_entry_read(table
*file
)
105 /* skip comments/blanks */
107 /* leading white space */
108 while (*file
->pos
!= '\0'
109 && *file
->pos
!= '\n'
110 && isspace(*file
->pos
))
113 if (*file
->pos
== '#') {
116 } while (*file
->pos
!= '\0' && *file
->pos
!= '\n');
119 if (*file
->pos
== '\n') {
126 if (*file
->pos
== '\0')
129 /* create this new entry */
130 entry
= (table_entry
*)zalloc(sizeof(table_entry
)
131 + (file
->nr_fields
+ 1) * sizeof(char*));
132 ASSERT(entry
!= NULL
);
133 entry
->file_name
= file
->file_name
;
134 entry
->nr_fields
= file
->nr_fields
;
136 /* break the line into its colon delimitered fields */
137 for (field
= 0; field
< file
->nr_fields
-1; field
++) {
138 entry
->fields
[field
] = file
->pos
;
139 while(*file
->pos
&& *file
->pos
!= ':' && *file
->pos
!= '\n')
141 if (*file
->pos
== ':') {
147 /* any trailing stuff not the last field */
148 ASSERT(field
== file
->nr_fields
-1);
149 entry
->fields
[field
] = file
->pos
;
150 while (*file
->pos
&& *file
->pos
!= '\n') {
153 if (*file
->pos
== '\n') {
158 entry
->line_nr
= file
->line_nr
;
160 /* if following lines tab indented, put in the annex */
161 if (*file
->pos
== '\t') {
162 entry
->annex
= file
->pos
;
166 } while (*file
->pos
!= '\0' && *file
->pos
!= '\n');
167 if (*file
->pos
== '\n') {
171 } while (*file
->pos
!= '\0' && *file
->pos
== '\t');
172 if (file
->pos
[-1] == '\n')
173 file
->pos
[-1] = '\0';
185 dump_table_entry(table_entry
*entry
,
188 printf("(table_entry*)%p\n", entry
);
195 dumpf(indent
, "(fields");
196 for (field
= 0; field
< entry
->nr_fields
; field
++) {
197 printf("%c%s", sep
, entry
->fields
[field
]);
202 dumpf(indent
, "(line_nr %d)\n", entry
->line_nr
);
204 dumpf(indent
, "(file_name %s)\n", entry
->file_name
);
206 dumpf(indent
, "(annex\n%s\n", entry
->annex
);
207 dumpf(indent
, " )\n");
214 table_entry_lf_c_line_nr(lf
*file
,
217 lf_print_c_line_nr(file
, entry
->line_nr
, entry
->file_name
);