Fix ECOFF objcopy to actually copy debugging information.
[deliverable/binutils-gdb.git] / gas / listing.c
CommitLineData
5d9f0ecf
SC
1/* listing.c - mainting assembly listings
2 Copyright (C) 1991, 1992 Free Software Foundation, Inc.
c593cf41
SC
3
4This file is part of GAS, the GNU Assembler.
5
6GAS is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GAS is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GAS; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
5d9f0ecf
SC
19
20/*
c593cf41
SC
21 Contributed by Steve Chamberlain
22 sac@cygnus.com
23
24
25 A listing page looks like:
58d4951d 26
c593cf41
SC
27 LISTING_HEADER sourcefilename pagenumber
28 TITLE LINE
29 SUBTITLE LINE
30 linenumber address data source
31 linenumber address data source
32 linenumber address data source
33 linenumber address data source
34
35 If not overridden, the listing commands are:
36
58d4951d
ILT
37 .title "stuff"
38 Put "stuff" onto the title line
c593cf41
SC
39 .sbttl "stuff"
40 Put stuff onto the subtitle line
41
5d9f0ecf
SC
42 If these commands come within 10 lines of the top of the page, they
43 will affect the page they are on, as well as any subsequent page
c593cf41
SC
44
45 .eject
46 Thow a page
47 .list
48 Increment the enable listing counter
49 .nolist
50 Decrement the enable listing counter
51
52 .psize Y[,X]
53 Set the paper size to X wide and Y high. Setting a psize Y of
54 zero will suppress form feeds except where demanded by .eject
55
58d4951d 56 If the counter goes below zero, listing is suppressed.
c593cf41
SC
57
58
59 Listings are a maintained by read calling various listing_<foo>
60 functions. What happens most is that the macro NO_LISTING is not
61 defined (from the Makefile), then the macro LISTING_NEWLINE expands
62 into a call to listing_newline. The call is done from read.c, every
63 time it sees a newline, and -l is on the command line.
64
65 The function listing_newline remembers the frag associated with the
66 newline, and creates a new frag - note that this is wasteful, but not
67 a big deal, since listing slows things down a lot anyway. The
68 function also rememebers when the filename changes.
69
70 When all the input has finished, and gas has had a chance to settle
71 down, the listing is output. This is done by running down the list of
72 frag/source file records, and opening the files as needed and printing
73 out the bytes and chars associated with them.
74
75 The only things which the architecture can change about the listing
76 are defined in these macros:
77
78 LISTING_HEADER The name of the architecture
79 LISTING_WORD_SIZE The make of the number of bytes in a word, this determines
80 the clumping of the output data. eg a value of
81 2 makes words look like 1234 5678, whilst 1
82 would make the same value look like 12 34 56
83 78
84 LISTING_LHS_WIDTH Number of words of above size for the lhs
85
86 LISTING_LHS_WIDTH_SECOND Number of words for the data on the lhs
87 for the second line
88
89 LISTING_LHS_CONT_LINES Max number of lines to use up for a continutation
90 LISTING_RHS_WIDTH Number of chars from the input file to print
91 on a line
92*/
5d9f0ecf 93
58d4951d
ILT
94#include <ctype.h>
95
5d9f0ecf
SC
96#include "as.h"
97#include <obstack.h>
98#include "input-file.h"
7143f43c 99
5d9f0ecf
SC
100#ifndef NO_LISTING
101#ifndef LISTING_HEADER
102#define LISTING_HEADER "GAS LISTING"
103#endif
104#ifndef LISTING_WORD_SIZE
105#define LISTING_WORD_SIZE 4
106#endif
107#ifndef LISTING_LHS_WIDTH
108#define LISTING_LHS_WIDTH 1
109#endif
110#ifndef LISTING_LHS_WIDTH_SECOND
111#define LISTING_LHS_WIDTH_SECOND 1
112#endif
113#ifndef LISTING_RHS_WIDTH
114#define LISTING_RHS_WIDTH 100
115#endif
58d4951d 116#ifndef LISTING_LHS_CONT_LINES
5d9f0ecf
SC
117#define LISTING_LHS_CONT_LINES 4
118#endif
119
120
c593cf41
SC
121
122
b3ca913f 123/* This structure remembers which .s were used */
58d4951d 124typedef struct file_info_struct
c593cf41
SC
125{
126 char *filename;
127 int linenum;
128 FILE *file;
129 struct file_info_struct *next;
130 int end_pending;
5d9f0ecf 131
58d4951d
ILT
132}
133
134file_info_type;
135
136
c593cf41
SC
137/* this structure rememebrs which line from which file goes into which
138 frag */
139typedef struct list_info_struct
140{
141 /* Frag which this line of source is nearest to */
142 fragS *frag;
143 /* The actual line in the source file */
144 unsigned int line;
145 /* Pointer to the file info struct for the file which this line
146 belongs to */
147 file_info_type *file;
148
149 /* Next in list */
150 struct list_info_struct *next;
a39116f1 151
c593cf41
SC
152
153 /* Pointer to the file info struct for the high level language
154 source line that belongs here */
155 file_info_type *hll_file;
58d4951d 156
c593cf41
SC
157 /* High level language source line */
158 int hll_line;
58d4951d 159
c593cf41
SC
160
161 /* Pointer to any error message associated with this line */
162 char *message;
58d4951d
ILT
163
164 enum
165 {
166 EDICT_NONE,
167 EDICT_SBTTL,
168 EDICT_TITLE,
169 EDICT_NOLIST,
170 EDICT_LIST,
171 EDICT_EJECT
172 } edict;
c593cf41 173 char *edict_arg;
58d4951d
ILT
174
175}
176
177list_info_type;
5d9f0ecf 178
c593cf41 179
5d9f0ecf
SC
180static struct list_info_struct *head;
181struct list_info_struct *listing_tail;
182extern int listing;
58d4951d 183extern unsigned int physical_input_line;
5d9f0ecf
SC
184extern fragS *frag_now;
185
c593cf41 186
5d9f0ecf
SC
187static int paper_width = 200;
188static int paper_height = 60;
189
c593cf41 190
5d9f0ecf 191/* this static array is used to keep the text of data to be printed
c593cf41
SC
192 before the start of the line.
193 It is stored so we can give a bit more info on the next line. To much, and large
194 initialized arrays will use up lots of paper.
195 */
5d9f0ecf
SC
196
197static char data_buffer[100];
198static unsigned int data_buffer_size;
199
58d4951d
ILT
200
201/* Prototypes. */
202static void listing_message PARAMS ((const char *name, const char *message));
203static file_info_type *file_info PARAMS ((const char *file_name));
204static void new_frag PARAMS ((void));
205static char *buffer_line PARAMS ((file_info_type *file,
206 char *line, unsigned int size));
207static void listing_page PARAMS ((list_info_type *list));
208static unsigned int calc_hex PARAMS ((list_info_type *list));
209static void print_lines PARAMS ((list_info_type *list,
210 char *string,
211 unsigned int address));
212static void list_symbol_table PARAMS ((void));
213static void print_source PARAMS ((file_info_type *current_file,
214 list_info_type *list,
215 char *buffer,
216 unsigned int width));
217static int debugging_pseudo PARAMS ((char *line));
218static void listing_listing PARAMS ((char *name));
219
220
5d9f0ecf 221static void
58d4951d
ILT
222listing_message (name, message)
223 const char *name;
224 const char *message;
c593cf41 225{
58d4951d
ILT
226 unsigned int l = strlen (name) + strlen (message) + 1;
227 char *n = (char *) xmalloc (l);
228 strcpy (n, name);
229 strcat (n, message);
230 if (listing_tail != (list_info_type *) NULL)
231 {
232 listing_tail->message = n;
233 }
234
c593cf41
SC
235}
236
237
5d9f0ecf
SC
238
239
58d4951d
ILT
240void
241listing_warning (message)
242 const char *message;
5d9f0ecf 243{
58d4951d 244 listing_message ("Warning:", message);
5d9f0ecf
SC
245}
246
58d4951d
ILT
247void
248listing_error (message)
249 const char *message;
5d9f0ecf 250{
58d4951d 251 listing_message ("Error:", message);
5d9f0ecf
SC
252}
253
c593cf41
SC
254
255
256
5d9f0ecf
SC
257static file_info_type *file_info_head;
258
259static file_info_type *
58d4951d
ILT
260file_info (file_name)
261 const char *file_name;
5d9f0ecf 262{
c593cf41
SC
263 /* Find an entry with this file name */
264 file_info_type *p = file_info_head;
58d4951d
ILT
265
266 while (p != (file_info_type *) NULL)
267 {
268 if (strcmp (p->filename, file_name) == 0)
269 return p;
270 p = p->next;
271 }
c593cf41
SC
272
273 /* Make new entry */
274
58d4951d 275 p = (file_info_type *) xmalloc (sizeof (file_info_type));
c593cf41
SC
276 p->next = file_info_head;
277 file_info_head = p;
58d4951d
ILT
278 p->filename = xmalloc (strlen (file_name) + 1);
279 strcpy (p->filename, file_name);
c593cf41
SC
280 p->linenum = 0;
281 p->end_pending = 0;
7143f43c 282
58d4951d
ILT
283 p->file = fopen (p->filename, "rb");
284 if (p->file)
285 fgetc (p->file);
7143f43c 286
c593cf41 287 return p;
c593cf41 288}
5d9f0ecf
SC
289
290
58d4951d
ILT
291static void
292new_frag ()
b3ca913f 293{
58d4951d
ILT
294
295 frag_wane (frag_now);
296 frag_new (0);
c593cf41 297
b3ca913f
SC
298}
299
58d4951d
ILT
300void
301listing_newline (ps)
302 char *ps;
5d9f0ecf 303{
c593cf41 304 extern char *file_name;
58d4951d
ILT
305 static unsigned int last_line = 0xffff;
306
5d9f0ecf 307
c593cf41 308 list_info_type *new;
58d4951d 309 if (physical_input_line != last_line)
c593cf41 310 {
58d4951d
ILT
311 last_line = physical_input_line;
312 new_frag ();
313
314 new = (list_info_type *) xmalloc (sizeof (list_info_type));
315 new->frag = frag_now;
316 new->line = physical_input_line;
317 new->file = file_info (file_name);
318
319 if (listing_tail)
320 {
321 listing_tail->next = new;
322 }
323 else
324 {
325 head = new;
326 }
327 listing_tail = new;
328 new->next = (list_info_type *) NULL;
329 new->message = (char *) NULL;
330 new->edict = EDICT_NONE;
331 new->hll_file = (file_info_type *) NULL;
332 new->hll_line = 0;
333 new_frag ();
c593cf41 334 }
c593cf41 335}
5d9f0ecf 336
3340f7e5 337
58d4951d 338/*
c593cf41
SC
339 This function returns the next source line from the file supplied,
340 truncated to size. It appends a fake line to the end of each input
341 file to make
342*/
5d9f0ecf
SC
343
344static char *
58d4951d
ILT
345buffer_line (file, line, size)
346 file_info_type * file;
347 char *line;
348 unsigned int size;
5d9f0ecf 349{
c593cf41
SC
350 unsigned int count = 0;
351 int c;
58d4951d 352
c593cf41
SC
353 char *p = line;
354
355 /* If we couldn't open the file, return an empty line */
58d4951d
ILT
356 if (file->file == (FILE *) NULL)
357 {
358 return "";
359 }
c593cf41 360
ab737e51 361 if (file->linenum == 0)
58d4951d 362 rewind (file->file);
ab737e51 363
58d4951d
ILT
364 if (file->end_pending == 10)
365 {
366 *p++ = '\n';
367 fseek (file->file, 0, 0);
c593cf41
SC
368 file->linenum = 0;
369 file->end_pending = 0;
58d4951d
ILT
370 }
371 c = fgetc (file->file);
372
7143f43c 373
c593cf41
SC
374 size -= 1; /* leave room for null */
375
58d4951d
ILT
376 while (c != EOF && c != '\n')
377 {
378 if (count < size)
379 *p++ = c;
380 count++;
381
382 c = fgetc (file->file);
383
384 }
385 if (c == EOF)
386 {
387 file->end_pending++;
388 *p++ = '.';
389 *p++ = '.';
390 *p++ = '.';
391 }
392 file->linenum++;
c593cf41
SC
393 *p++ = 0;
394 return line;
395}
396
5d9f0ecf 397
58d4951d 398static const char *fn;
5d9f0ecf
SC
399
400static unsigned int eject; /* Eject pending */
58d4951d
ILT
401static unsigned int page; /* Current page number */
402static char *title; /* current title */
5d9f0ecf 403static char *subtitle; /* current subtitle */
58d4951d 404static unsigned int on_page; /* number of lines printed on current page */
5d9f0ecf 405
3340f7e5 406
c593cf41 407static void
58d4951d
ILT
408listing_page (list)
409 list_info_type *list;
c593cf41
SC
410{
411 /* Grope around, see if we can see a title or subtitle edict coming up
412 soon (we look down 10 lines of the page and see if it's there)*/
58d4951d 413 if ((eject || (on_page >= paper_height)) && paper_height != 0)
c593cf41 414 {
58d4951d
ILT
415 unsigned int c = 10;
416 int had_title = 0;
417 int had_subtitle = 0;
c593cf41 418
58d4951d
ILT
419 page++;
420
421 while (c != 0 && list)
422 {
423 if (list->edict == EDICT_SBTTL && !had_subtitle)
424 {
425 had_subtitle = 1;
426 subtitle = list->edict_arg;
427 }
428 if (list->edict == EDICT_TITLE && !had_title)
429 {
430 had_title = 1;
431 title = list->edict_arg;
432 }
433 list = list->next;
434 c--;
435 }
436
437
438 if (page > 1)
439 {
440 printf ("\f");
441 }
442
443 printf ("%s %s \t\t\tpage %d\n", LISTING_HEADER, fn, page);
444 printf ("%s\n", title);
445 printf ("%s\n", subtitle);
446 on_page = 3;
447 eject = 0;
c593cf41 448 }
c593cf41 449}
5d9f0ecf
SC
450
451
58d4951d
ILT
452static unsigned int
453calc_hex (list)
454 list_info_type * list;
5d9f0ecf 455{
c593cf41 456 list_info_type *first = list;
c593cf41 457 unsigned int address = ~0;
58d4951d 458
c593cf41
SC
459 fragS *frag;
460 fragS *frag_ptr;
461
58d4951d
ILT
462 unsigned int byte_in_frag = 0;
463
c593cf41
SC
464
465 /* Find first frag which says it belongs to this line */
58d4951d
ILT
466 frag = list->frag;
467 while (frag && frag->line != list)
468 frag = frag->fr_next;
c593cf41
SC
469
470 frag_ptr = frag;
471
472 data_buffer_size = 0;
58d4951d 473
c593cf41 474 /* Dump all the frags which belong to this line */
58d4951d 475 while (frag_ptr != (fragS *) NULL && frag_ptr->line == first)
c593cf41 476 {
58d4951d
ILT
477 /* Print as many bytes from the fixed part as is sensible */
478 while (byte_in_frag < frag_ptr->fr_fix && data_buffer_size < sizeof (data_buffer) - 10)
479 {
480 if (address == ~0)
481 {
482 address = frag_ptr->fr_address;
483 }
484
485 sprintf (data_buffer + data_buffer_size,
486 "%02X",
487 (frag_ptr->fr_literal[byte_in_frag]) & 0xff);
488 data_buffer_size += 2;
489 byte_in_frag++;
490 }
c593cf41 491 {
58d4951d
ILT
492 unsigned int var_rep_max = byte_in_frag;
493 unsigned int var_rep_idx = byte_in_frag;
494
495 /* Print as many bytes from the variable part as is sensible */
496 while (byte_in_frag < frag_ptr->fr_var * frag_ptr->fr_offset
497 && data_buffer_size < sizeof (data_buffer) - 10)
498 {
499 if (address == ~0)
500 {
501 address = frag_ptr->fr_address;
502 }
503 sprintf (data_buffer + data_buffer_size,
504 "%02X",
505 (frag_ptr->fr_literal[var_rep_idx]) & 0xff);
506#if 0
507 data_buffer[data_buffer_size++] = '*';
508 data_buffer[data_buffer_size++] = '*';
c593cf41 509#endif
58d4951d
ILT
510 data_buffer_size += 2;
511
512 var_rep_idx++;
513 byte_in_frag++;
514
515 if (var_rep_idx >= frag_ptr->fr_var)
516 var_rep_idx = var_rep_max;
517 }
518 }
519
520 frag_ptr = frag_ptr->fr_next;
c593cf41 521 }
c593cf41
SC
522 data_buffer[data_buffer_size++] = 0;
523 return address;
524}
525
526
527
528
529
5d9f0ecf
SC
530
531static void
58d4951d
ILT
532print_lines (list, string, address)
533 list_info_type *list;
534 char *string;
535 unsigned int address;
c593cf41
SC
536{
537 unsigned int idx;
538 unsigned int nchars;
539 unsigned int lines;
58d4951d 540 unsigned int byte_in_word = 0;
c593cf41 541 char *src = data_buffer;
58d4951d 542
c593cf41 543 /* Print the stuff on the first line */
58d4951d
ILT
544 listing_page (list);
545 nchars = (LISTING_WORD_SIZE * 2 + 1) * LISTING_LHS_WIDTH;
c593cf41 546 /* Print the hex for the first line */
58d4951d 547 if (address == ~0)
c593cf41 548 {
58d4951d
ILT
549 printf ("% 4d ", list->line);
550 for (idx = 0; idx < nchars; idx++)
551 printf (" ");
552
553 printf ("\t%s\n", string ? string : "");
c593cf41 554 on_page++;
58d4951d
ILT
555 listing_page (0);
556
c593cf41 557 }
58d4951d
ILT
558 else
559 {
560 if (had_errors ())
561 {
562 printf ("% 4d ???? ", list->line);
563 }
564 else
565 {
566 printf ("% 4d %04x ", list->line, address);
567 }
c593cf41 568
58d4951d
ILT
569 /* And the data to go along with it */
570 idx = 0;
571
572 while (*src && idx < nchars)
c593cf41 573 {
58d4951d
ILT
574 printf ("%c%c", src[0], src[1]);
575 src += 2;
c593cf41 576 byte_in_word++;
58d4951d
ILT
577 if (byte_in_word == LISTING_WORD_SIZE)
578 {
579 printf (" ");
580 idx++;
581 byte_in_word = 0;
582 }
583 idx += 2;
c593cf41 584 }
c593cf41 585
58d4951d
ILT
586 for (; idx < nchars; idx++)
587 printf (" ");
588
589 printf ("\t%s\n", string ? string : "");
590 on_page++;
591 listing_page (list);
592 if (list->message)
593 {
594 printf ("**** %s\n", list->message);
595 listing_page (list);
596 on_page++;
597 }
c593cf41 598
58d4951d
ILT
599 for (lines = 0;
600 lines < LISTING_LHS_CONT_LINES
601 && *src;
602 lines++)
603 {
604 nchars = ((LISTING_WORD_SIZE * 2) + 1) * LISTING_LHS_WIDTH_SECOND - 1;
605 idx = 0;
606 /* Print any more lines of data, but more compactly */
607 printf ("% 4d ", list->line);
608
609 while (*src && idx < nchars)
610 {
611 printf ("%c%c", src[0], src[1]);
612 src += 2;
613 idx += 2;
614 byte_in_word++;
615 if (byte_in_word == LISTING_WORD_SIZE)
616 {
617 printf (" ");
618 idx++;
619 byte_in_word = 0;
620 }
621 }
622
623 printf ("\n");
624 on_page++;
625 listing_page (list);
626
627 }
628
629
630 }
631}
5d9f0ecf
SC
632
633
634static void
58d4951d 635list_symbol_table ()
5d9f0ecf 636{
c593cf41 637 extern symbolS *symbol_rootP;
58d4951d
ILT
638
639 symbolS *ptr;
c593cf41 640 eject = 1;
58d4951d
ILT
641 listing_page (0);
642 printf ("DEFINED SYMBOLS\n");
c593cf41 643 on_page++;
58d4951d
ILT
644
645 for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr))
c593cf41 646 {
58d4951d
ILT
647 if (ptr->sy_frag->line)
648 {
649 if (S_GET_NAME (ptr))
650 {
651 char buf[30];
652 valueT val = S_GET_VALUE (ptr);
653
654 /* @@ Note that this is dependent on the compilation options,
655 not solely on the target characteristics. */
656 if (sizeof (val) == 4 && sizeof (int) == 4)
657 sprintf (buf, "%08lx", (unsigned long) val);
658#if defined (BFD_ASSEMBLER) && defined (BFD64)
659 else if (sizeof (val) > 4)
660 {
661 char buf1[30];
662 sprintf_vma (buf1, val);
663 strcpy (buf, "00000000");
664 strcpy (buf + 8 - strlen (buf1), buf1);
665 }
666#endif
667 else
668 abort ();
669
670 printf ("%20s:%-5d %s:%s %s\n",
671 ptr->sy_frag->line->file->filename,
672 ptr->sy_frag->line->line,
673 segment_name (S_GET_SEGMENT (ptr)),
674 buf, S_GET_NAME (ptr));
675
676 on_page++;
677 listing_page (0);
678 }
679 }
c593cf41 680
c593cf41 681 }
58d4951d 682 printf ("\n");
c593cf41 683 on_page++;
58d4951d
ILT
684 listing_page (0);
685 printf ("UNDEFINED SYMBOLS\n");
c593cf41 686 on_page++;
58d4951d
ILT
687 listing_page (0);
688
689 for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr))
c593cf41 690 {
58d4951d
ILT
691 if (S_GET_NAME (ptr) && strlen (S_GET_NAME (ptr)) != 0)
692 {
693 if (ptr->sy_frag->line == 0)
694 {
695 printf ("%s\n", S_GET_NAME (ptr));
696 on_page++;
697 listing_page (0);
698 }
699 }
c593cf41 700 }
c593cf41 701}
5d9f0ecf 702
58d4951d
ILT
703static void
704print_source (current_file, list, buffer, width)
705 file_info_type *current_file;
706 list_info_type *list;
707 char *buffer;
708 unsigned int width;
c593cf41 709{
58d4951d
ILT
710 if (current_file->file)
711 {
c593cf41 712 while (current_file->linenum < list->hll_line)
58d4951d
ILT
713 {
714 char *p = buffer_line (current_file, buffer, width);
715 printf ("%4d:%-13s **** %s\n", current_file->linenum, current_file->filename, p);
716 on_page++;
717 listing_page (list);
718 }
c593cf41
SC
719 }
720}
b3ca913f 721
a39116f1 722/* Sometimes the user doesn't want to be bothered by the debugging
58d4951d 723 records inserted by the compiler, see if the line is suspicious */
5d9f0ecf 724
a39116f1 725static int
58d4951d
ILT
726debugging_pseudo (line)
727 char *line;
a39116f1 728{
58d4951d
ILT
729 while (isspace (*line))
730 line++;
731
732 if (*line != '.')
733 return 0;
c593cf41 734
c593cf41
SC
735 line++;
736
58d4951d
ILT
737 if (strncmp (line, "def", 3) == 0)
738 return 1;
739 if (strncmp (line, "val", 3) == 0)
740 return 1;
741 if (strncmp (line, "scl", 3) == 0)
742 return 1;
743 if (strncmp (line, "line", 4) == 0)
744 return 1;
745 if (strncmp (line, "endef", 5) == 0)
746 return 1;
747 if (strncmp (line, "ln", 2) == 0)
748 return 1;
749 if (strncmp (line, "type", 4) == 0)
750 return 1;
751 if (strncmp (line, "size", 4) == 0)
752 return 1;
753 if (strncmp (line, "dim", 3) == 0)
754 return 1;
755 if (strncmp (line, "tag", 3) == 0)
756 return 1;
757
758 if (strncmp (line, "stabs", 5) == 0)
759 return 1;
760 if (strncmp (line, "stabn", 5) == 0)
761 return 1;
762
c593cf41
SC
763 return 0;
764
765}
5d9f0ecf 766
58d4951d
ILT
767static void
768listing_listing (name)
769 char *name;
c593cf41
SC
770{
771 list_info_type *list = head;
58d4951d 772 file_info_type *current_hll_file = (file_info_type *) NULL;
c593cf41
SC
773 char *message;
774 char *buffer;
775 char *p;
c593cf41
SC
776 int show_listing = 1;
777 unsigned int width;
58d4951d
ILT
778
779 buffer = xmalloc (LISTING_RHS_WIDTH);
c593cf41
SC
780 eject = 1;
781 list = head;
782
58d4951d
ILT
783 while (list != (list_info_type *) NULL && 0)
784 {
785 if (list->next)
786 list->frag = list->next->frag;
787 list = list->next;
788
789 }
c593cf41 790
c593cf41
SC
791 list = head->next;
792
793
58d4951d 794 while (list)
c593cf41 795 {
58d4951d
ILT
796 width = LISTING_RHS_WIDTH > paper_width ? paper_width :
797 LISTING_RHS_WIDTH;
c593cf41 798
58d4951d
ILT
799 switch (list->edict)
800 {
801 case EDICT_LIST:
802 show_listing++;
803 break;
804 case EDICT_NOLIST:
805 show_listing--;
806 break;
807 case EDICT_EJECT:
808 break;
809 case EDICT_NONE:
810 break;
811 case EDICT_TITLE:
812 title = list->edict_arg;
813 break;
814 case EDICT_SBTTL:
815 subtitle = list->edict_arg;
816 break;
817 default:
818 abort ();
819 }
c593cf41 820
58d4951d
ILT
821 if (show_listing > 0)
822 {
823 /* Scan down the list and print all the stuff which can be done
824 with this line (or lines). */
825 message = 0;
826
827 if (list->hll_file)
828 {
829 current_hll_file = list->hll_file;
830 }
831
832 if (current_hll_file && list->hll_line && listing & LISTING_HLL)
833 {
834 print_source (current_hll_file, list, buffer, width);
835 }
836
837 p = buffer_line (list->file, buffer, width);
838
839 if (!((listing & LISTING_NODEBUG) && debugging_pseudo (p)))
840 {
841 print_lines (list, p, calc_hex (list));
842 }
843
844 if (list->edict == EDICT_EJECT)
845 {
846 eject = 1;
847 }
848 }
849 else
850 {
c593cf41 851
58d4951d
ILT
852 p = buffer_line (list->file, buffer, width);
853 }
c593cf41 854
58d4951d 855 list = list->next;
c593cf41 856 }
58d4951d 857 free (buffer);
c593cf41 858}
5d9f0ecf 859
58d4951d
ILT
860void
861listing_print (name)
862 char *name;
5d9f0ecf 863{
c593cf41 864 title = "";
58d4951d
ILT
865 subtitle = "";
866
867 if (listing & LISTING_NOFORM)
868 {
869 paper_height = 0;
870 }
871
872 if (listing & LISTING_LISTING)
873 {
874 listing_listing (name);
875
876 }
877 if (listing & LISTING_SYMBOLS)
878 {
879 list_symbol_table ();
880 }
881}
5d9f0ecf
SC
882
883
884void
58d4951d
ILT
885listing_file (name)
886 const char *name;
5d9f0ecf 887{
58d4951d 888 fn = name;
5d9f0ecf
SC
889}
890
58d4951d
ILT
891void
892listing_eject ()
5d9f0ecf 893{
58d4951d 894 listing_tail->edict = EDICT_EJECT;
5d9f0ecf
SC
895}
896
897void
58d4951d 898listing_flags ()
5d9f0ecf 899{
58d4951d
ILT
900 while ((*input_line_pointer++) && (*input_line_pointer != '\n'))
901 input_line_pointer++;
902
c593cf41 903}
58d4951d 904
c593cf41 905void
58d4951d
ILT
906listing_list (on)
907 unsigned int on;
c593cf41
SC
908{
909 listing_tail->edict = on ? EDICT_LIST : EDICT_NOLIST;
5d9f0ecf 910}
3340f7e5 911
c593cf41 912
5d9f0ecf 913void
58d4951d 914listing_psize ()
5d9f0ecf 915{
58d4951d 916 paper_height = get_absolute_expression ();
c593cf41 917
58d4951d
ILT
918 if (paper_height < 0 || paper_height > 1000)
919 {
920 paper_height = 0;
921 as_warn ("strange paper height, set to no form");
922 }
923 if (*input_line_pointer == ',')
924 {
925 input_line_pointer++;
926 paper_width = get_absolute_expression ();
927 }
5d9f0ecf
SC
928}
929
930
931void
58d4951d
ILT
932listing_title (depth)
933 unsigned int depth;
a39116f1 934{
c593cf41
SC
935 char *start;
936 char *title;
937 unsigned int length;
58d4951d
ILT
938
939 SKIP_WHITESPACE ();
940 if (*input_line_pointer == '\"')
941 {
c593cf41
SC
942 input_line_pointer++;
943 start = input_line_pointer;
58d4951d
ILT
944
945 while (*input_line_pointer)
c593cf41 946 {
58d4951d
ILT
947 if (*input_line_pointer == '\"')
948 {
949 length = input_line_pointer - start;
950 title = xmalloc (length + 1);
951 memcpy (title, start, length);
952 title[length] = 0;
953 listing_tail->edict = depth ? EDICT_SBTTL : EDICT_TITLE;
954 listing_tail->edict_arg = title;
955 input_line_pointer++;
956 demand_empty_rest_of_line ();
957 return;
958 }
959 else if (*input_line_pointer == '\n')
960 {
961 as_bad ("New line in title");
962 demand_empty_rest_of_line ();
963 return;
964 }
965 else
966 {
967 input_line_pointer++;
968 }
c593cf41 969 }
c593cf41 970 }
58d4951d
ILT
971 else
972 {
973 as_bad ("expecting title in quotes");
974 }
c593cf41
SC
975}
976
5d9f0ecf
SC
977
978
979void
58d4951d
ILT
980listing_source_line (line)
981 unsigned int line;
5d9f0ecf 982{
58d4951d 983 new_frag ();
c593cf41 984 listing_tail->hll_line = line;
58d4951d
ILT
985 new_frag ();
986
c593cf41 987}
5d9f0ecf 988
c593cf41 989void
58d4951d
ILT
990listing_source_file (file)
991 const char *file;
c593cf41 992{
58d4951d 993 listing_tail->hll_file = file_info (file);
c593cf41 994}
5d9f0ecf 995
b3ca913f 996
58d4951d 997
c593cf41
SC
998#else
999
1000
1001/* Dummy functions for when compiled without listing enabled */
1002
58d4951d
ILT
1003void
1004listing_flags ()
c593cf41 1005{
58d4951d 1006 s_ignore (0);
c593cf41
SC
1007}
1008
58d4951d
ILT
1009void
1010listing_list (on)
1011 unsigned int on;
b3ca913f 1012{
58d4951d 1013 s_ignore (0);
c593cf41
SC
1014}
1015
58d4951d
ILT
1016void
1017listing_eject ()
c593cf41 1018{
58d4951d 1019 s_ignore (0);
c593cf41 1020}
58d4951d
ILT
1021
1022void
1023listing_psize ()
c593cf41 1024{
58d4951d 1025 s_ignore (0);
c593cf41 1026}
b3ca913f 1027
58d4951d
ILT
1028void
1029listing_title (depth)
1030 unsigned int depth;
c593cf41 1031{
58d4951d 1032 s_ignore (0);
c593cf41 1033}
58d4951d 1034
b3ca913f 1035void
58d4951d
ILT
1036listing_file (name)
1037 const char *name;
b3ca913f 1038{
c593cf41
SC
1039
1040}
1041
58d4951d
ILT
1042void
1043listing_newline (name)
1044 char *name;
c593cf41 1045{
58d4951d 1046
b3ca913f
SC
1047}
1048
58d4951d
ILT
1049void
1050listing_source_line (n)
1051 unsigned int n;
c593cf41 1052{
58d4951d 1053
c593cf41 1054}
58d4951d
ILT
1055void
1056listing_source_file (n)
1057 const char *n;
c593cf41 1058{
c593cf41 1059
58d4951d 1060}
c593cf41
SC
1061
1062#endif
This page took 0.244944 seconds and 4 git commands to generate.