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.
44 int line_nr
; /* nr complete lines written, curr line is line_nr+1 */
49 lf_file_references references
;
57 lf_file_references references
,
61 /* create a file object */
62 lf
*new_lf
= ZALLOC(lf
);
63 ASSERT (new_lf
!= NULL
);
64 new_lf
->references
= references
;
66 new_lf
->name
= (real_name
== NULL
? name
: real_name
);
67 new_lf
->program
= program
;
68 /* attach to stdout if pipe */
69 if (!strcmp(name
, "-")) {
70 new_lf
->stream
= stdout
;
73 /* create a new file */
74 new_lf
->stream
= fopen(name
, "w");
75 if (new_lf
->stream
== NULL
) {
87 if (file
->stream
!= stdout
) {
88 if (fclose(file
->stream
)) {
89 perror("lf_close.fclose");
104 file
->line_blank
= 1;
106 else if (file
->line_blank
) {
108 for (pad
= file
->indent
; pad
> 0; pad
--)
109 putc(' ', file
->stream
);
111 file
->line_blank
= 0;
113 putc(chr
, file
->stream
);
125 for (i
= 0; i
< strlen_string
; i
++)
126 nr
+= lf_putchr (file
, string
[i
]);
132 lf_indent_suppress(lf
*file
)
134 file
->line_blank
= 0;
144 if (string
!= NULL
) {
145 for (chp
= string
; *chp
!= '\0'; chp
++) {
146 nr
+= lf_putchr(file
, *chp
);
153 do_lf_putunsigned(lf
*file
,
158 nr
+= do_lf_putunsigned(file
, u
/ 10);
159 nr
+= lf_putchr(file
, (u
% 10) + '0');
171 nr
+= lf_putchr(file
, '0');
172 else if (decimal
< 0) {
173 nr
+= lf_putchr(file
, '-');
174 nr
+= do_lf_putunsigned(file
, -decimal
);
176 else if (decimal
> 0) {
177 nr
+= do_lf_putunsigned(file
, decimal
);
195 vsprintf (buf
, fmt
, ap
);
196 /* FIXME - this is really stuffed but so is vsprintf() on a sun! */
197 ASSERT (strlen (buf
) < sizeof (buf
));
198 nr
+= lf_putstr (file
, buf
);
205 lf_print__line_ref (lf
*file
,
208 return lf_print__external_ref (file
, line
->line_nr
, line
->file_name
);
212 lf_print__external_ref (lf
*file
,
214 const char *file_name
)
217 switch (file
->references
)
219 case lf_include_references
:
220 lf_indent_suppress(file
);
221 nr
+= lf_putstr (file
, "#line ");
222 nr
+= lf_putint (file
, line_nr
);
223 nr
+= lf_putstr (file
, " \"");
224 nr
+= lf_putstr (file
, file_name
);
225 nr
+= lf_putstr (file
, "\"\n");
227 case lf_omit_references
:
228 nr
+= lf_putstr (file
, "/* ");
229 nr
+= lf_putstr (file
, file_name
);
230 nr
+= lf_putstr (file
, ":");
231 nr
+= lf_putint (file
, line_nr
);
232 nr
+= lf_putstr (file
, "*/\n");
239 lf_print__internal_ref (lf
*file
)
242 nr
+= lf_print__external_ref (file
, file
->line_nr
+2, file
->name
);
243 /* line_nr == last_line, want to number from next */
248 lf_indent (lf
*file
, int delta
)
250 file
->indent
+= delta
;
255 lf_print__gnu_copyleft (lf
*file
)
258 switch (file
->type
) {
261 nr
+= lf_printf(file
, "\
262 /* This file is part of the program psim.
264 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
266 This program is free software; you can redistribute it and/or modify
267 it under the terms of the GNU General Public License as published by
268 the Free Software Foundation; either version 2 of the License, or
269 (at your option) any later version.
271 This program is distributed in the hope that it will be useful,
272 but WITHOUT ANY WARRANTY; without even the implied warranty of
273 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
274 GNU General Public License for more details.
276 You should have received a copy of the GNU General Public License
277 along with this program; if not, write to the Free Software
278 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
282 This file was generated by the program %s */
283 ", filter_filename(file
->program
));
294 lf_putbin(lf
*file
, int decimal
, int width
)
299 for (bit
= 1 << (width
-1); bit
!= 0; bit
>>= 1) {
301 nr
+= lf_putchr(file
, '1');
303 nr
+= lf_putchr(file
, '0');
309 lf_print__this_file_is_empty(lf
*file
,
313 switch (file
->type
) {
316 nr
+= lf_printf (file
,
317 "/* This generated file (%s) is intentionally left blank",
320 nr
+= lf_printf (file
, " - %s", reason
);
321 nr
+= lf_printf (file
, " */\n");
324 ERROR ("Bad switch");
330 lf_print__ucase_filename(lf
*file
)
333 const char *chp
= file
->name
;
334 while (*chp
!= '\0') {
337 nr
+= lf_putchr(file
, toupper(ch
));
340 nr
+= lf_putchr(file
, '_');
342 nr
+= lf_putchr(file
, ch
);
349 lf_print__file_start(lf
*file
)
352 switch (file
->type
) {
355 nr
+= lf_print__gnu_copyleft(file
);
356 nr
+= lf_printf(file
, "\n");
357 nr
+= lf_printf(file
, "#ifndef ");
358 nr
+= lf_print__ucase_filename(file
);
359 nr
+= lf_printf(file
, "\n");
360 nr
+= lf_printf(file
, "#define ");
361 nr
+= lf_print__ucase_filename(file
);
362 nr
+= lf_printf(file
, "\n");
363 nr
+= lf_printf(file
, "\n");
373 lf_print__file_finish(lf
*file
)
376 switch (file
->type
) {
379 nr
+= lf_printf(file
, "\n");
380 nr
+= lf_printf(file
, "#endif /* _");
381 nr
+= lf_print__ucase_filename(file
);
382 nr
+= lf_printf(file
, "_*/\n");
392 lf_print__function_type (lf
*file
,
395 const char *trailing_space
)
398 nr
+= lf_printf (file
, "%s\\\n(%s)", prefix
, type
);
399 if (trailing_space
!= NULL
)
400 nr
+= lf_printf (file
, "%s", trailing_space
);
405 lf_print__function_type_function (lf
*file
,
406 print_function
*print_type
,
408 const char *trailing_space
)
411 nr
+= lf_printf (file
, "%s\\\n(", prefix
);
412 nr
+= print_type (file
);
413 nr
+= lf_printf (file
, ")");
414 if (trailing_space
!= NULL
)
415 nr
+= lf_printf (file
, "%s", trailing_space
);