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.
35 int line_nr
; /* nr complete lines written, curr line is line_nr+1 */
48 /* create a file object */
49 lf
*new_lf
= ZALLOC(lf
);
50 ASSERT(new_lf
!= NULL
);
51 new_lf
->number_lines
= number_lines
;
52 new_lf
->file_name
= (real_name
== NULL
56 /* attach to stdout if pipe */
57 if (!strcmp(name
, "-")) {
58 new_lf
->stream
= stdout
;
61 /* create a new file */
62 new_lf
->stream
= fopen(name
, "w");
63 ASSERT(new_lf
->stream
!= NULL
);
72 if (file
->stream
!= stdout
) {
73 if (fclose(file
->stream
)) {
74 perror("lf_close.fclose");
90 else if (file
->line_blank
) {
92 for (pad
= file
->indent
; pad
> 0; pad
--)
93 putc(' ', file
->stream
);
96 putc(chr
, file
->stream
);
100 lf_indent_suppress(lf
*file
)
102 file
->line_blank
= 0;
111 if (string
!= NULL
) {
112 for (chp
= string
; *chp
!= '\0'; chp
++) {
113 lf_putchr(file
, *chp
);
119 do_lf_putunsigned(lf
*file
,
123 do_lf_putunsigned(file
, u
/ 10);
124 lf_putchr(file
, (u
% 10) + '0');
134 lf_putchr(file
, '0');
135 else if (decimal
< 0) {
136 lf_putchr(file
, '-');
137 do_lf_putunsigned(file
, -decimal
);
139 else if (decimal
> 0) {
140 do_lf_putunsigned(file
, decimal
);
156 vsprintf(buf
, fmt
, ap
);
157 /* FIXME - this is really stuffed but so is vsprintf() on a sun! */
158 ASSERT(strlen(buf
) > 0 && strlen(buf
) < sizeof(buf
));
159 lf_putstr(file
, buf
);
165 lf_print_c_code(lf
*file
, char *code
)
168 int in_bit_field
= 0;
169 while (*chp
!= '\0') {
173 lf_indent_suppress(file
);
174 while (*chp
!= '\0' && *chp
!= '\n') {
175 if (chp
[0] == '{' && !isspace(chp
[1])) {
177 lf_putchr(file
, '_');
179 else if (in_bit_field
&& chp
[0] == ':') {
180 lf_putchr(file
, '_');
182 else if (in_bit_field
&& *chp
== '}') {
183 lf_putchr(file
, '_');
187 lf_putchr(file
, *chp
);
192 error("bit field paren miss match some where\n");
194 lf_putchr(file
, '\n');
198 lf_putchr(file
, '\n');
203 lf_print_c_line_nr(lf
*file
,
207 if (file
->number_lines
) {
208 lf_indent_suppress(file
);
209 lf_putstr(file
, "#line ");
210 lf_putint(file
, line_nr
);
211 lf_putstr(file
, " \"");
212 lf_putstr(file
, file_name
);
213 lf_putstr(file
, "\"\n");
218 lf_print_lf_c_line_nr(lf
*file
)
220 lf_print_c_line_nr(file
, file
->line_nr
+2, file
->file_name
);
221 /* line_nr == last_line, want to number from next */
225 lf_indent(lf
*file
, int delta
)
227 file
->indent
+= delta
;
232 lf_print_copyleft(lf
*file
)
235 /* This file is part of the program psim.
237 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
239 This program is free software; you can redistribute it and/or modify
240 it under the terms of the GNU General Public License as published by
241 the Free Software Foundation; either version 2 of the License, or
242 (at your option) any later version.
244 This program is distributed in the hope that it will be useful,
245 but WITHOUT ANY WARRANTY; without even the implied warranty of
246 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
247 GNU General Public License for more details.
249 You should have received a copy of the GNU General Public License
250 along with this program; if not, write to the Free Software
251 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
255 This file was generated by the program gen */
261 lf_print_binary(lf
*file
, int decimal
, int width
)
266 for (bit
= 1 << (width
-1); bit
!= 0; bit
>>= 1) {
268 lf_putchr(file
, '1');
270 lf_putchr(file
, '0');