struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / sdas / asxxsrc / aslist.c
blob1ad094197150b810cf1ecd51c86d4a138d8d95ed
1 /* aslist.c */
3 /*
4 * Copyright (C) 1989-2009 Alan R. Baldwin
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Alan R. Baldwin
21 * 721 Berkeley St.
22 * Kent, Ohio 44240
24 * With enhancements from
26 * John L. Hartman (JLH)
27 * jhartman at compuserve dot com
30 #include "asxxxx.h"
32 /*)Module aslist.c
34 * The module aslist.c contains all the functions used
35 * to generate the assembler list and symbol output files.
37 * aslist.c contains the following functions:
38 * VOID list()
39 * VOID list1()
40 * VOID list2()
41 * VOID slew()
42 * VOID lstsym()
44 * The module aslist.c contains no local/static variables
47 /*)Function VOID list()
49 * The function list() generates the listing output
50 * which includes the input source, line numbers,
51 * and generated code. Numerical output may be selected
52 * as hexadecimal, decimal, or octal.
54 * local variables:
55 * char * il pointer to assembler-source listing line
56 * int l_addr laddr (int) truncated to 2-bytes
57 * int n number of bytes listed per line
58 * int nb computed number of assembled bytes
59 * int nl number of bytes listed on this line
60 * int listing listing enable flags
61 * int paging computed paging enable flag
62 * char * wp pointer to the assembled data bytes
63 * int * wpt pointer to the data byte mode
64 * char * frmt pointer to format string
66 * global variables:
67 * int a_bytes T line addressing size
68 * int bflag -b(b), listing mode flag
69 * int cb[] array of assembler output values
70 * int cbt[] array of assembler relocation types
71 * describing the data in cb[]
72 * int * cp pointer to assembler output array cb[]
73 * int * cpt pointer to assembler relocation type
74 * output array cbt[]
75 * char eb[] array of generated error codes
76 * char * ep pointer into error list
77 * array eb[]
78 * char * ib string buffer containing
79 * assembler-source text line for processing
80 * char * ic string buffer containing
81 * assembler-source text line for listing
82 * a_uint laddr address of current assembler line,
83 * equate, or value of .if argument
84 * FILE * lfp list output file handle
85 * int line current assembler source line number
86 * int lmode listing mode
87 * int lnlist LIST-NLIST state
88 * int srcline source file line number
89 * int uflag -u, disable .list/.nlist processing
90 * int xflag -x, listing radix flag
92 * functions called:
93 * int fprintf() c_library
94 * VOID list1() aslist.c
95 * int putc() c_library
96 * VOID slew() asslist.c
98 * side effects:
99 * Listing or symbol output updated.
102 /* The Output Formats, No Cycle Count
103 | Tabs- | | | | | |
104 11111111112222222222333333333344444-----
105 012345678901234567890123456789012345678901234-----
106 | | | | |
107 ee XXXX xx xx xx xx xx xx LLLLL ************* HEX(16)
108 ee 000000 ooo ooo ooo ooo LLLLL ************* OCTAL(16)
109 ee DDDDD ddd ddd ddd ddd LLLLL ************* DECIMAL(16)
110 XXXX
111 OOOOOO
112 DDDDD
114 | Tabs- | | | | | |
115 11111111112222222222333333333344444-----
116 012345678901234567890123456789012345678901234-----
117 | | | | |
118 ee XXXXXX xx xx xx xx xx xx xx LLLLL ********* HEX(24)
119 ee OO000000 ooo ooo ooo ooo ooo LLLLL ********* OCTAL(24)
120 ee DDDDDDDD ddd ddd ddd ddd ddd LLLLL ********* DECIMAL(24)
121 XXXXXX
122 OOOOOOOO
123 DDDDDDDD
125 | Tabs- | | | | | |
126 11111111112222222222333333333344444-----
127 012345678901234567890123456789012345678901234-----
128 | | | | |
129 ee XXXXXXXX xx xx xx xx xx xx xx LLLLL ********* HEX(32)
130 eeOOOOO000000 ooo ooo ooo ooo ooo LLLLL ********* OCTAL(32)
131 ee DDDDDDDDDD ddd ddd ddd ddd ddd LLLLL ********* DECIMAL(32)
132 XXXXXXXX
133 OOOOOOOOOOO
134 DDDDDDDDDD
137 /* The Output Formats, With Cycle Count [nn]
138 | Tabs- | | | | | |
139 11111111112222222222333333333344444-----
140 012345678901234567890123456789012345678901234-----
141 | | | | |
142 ee XXXX xx xx xx xx xx[nn]LLLLL ************* HEX(16)
143 ee 000000 ooo ooo ooo [nn]LLLLL ************* OCTAL(16)
144 ee DDDDD ddd ddd ddd [nn]LLLLL ************* DECIMAL(16)
145 XXXX
146 OOOOOO
147 DDDDD
149 | Tabs- | | | | | |
150 11111111112222222222333333333344444-----
151 012345678901234567890123456789012345678901234-----
152 | | | | |
153 ee XXXXXX xx xx xx xx xx xx[nn]LLLLL ********* HEX(24)
154 ee OO000000 ooo ooo ooo ooo [nn]LLLLL ********* OCTAL(24)
155 ee DDDDDDDD ddd ddd ddd ddd [nn]LLLLL ********* DECIMAL(24)
156 XXXXXX
157 OOOOOOOO
158 DDDDDDDD
160 | Tabs- | | | | | |
161 11111111112222222222333333333344444-----
162 012345678901234567890123456789012345678901234-----
163 | | | | |
164 ee XXXXXXXX xx xx xx xx xx xx[nn]LLLLL ********* HEX(32)
165 eeOOOOO000000 ooo ooo ooo ooo [nn]LLLLL ********* OCTAL(32)
166 ee DDDDDDDDDD ddd ddd ddd ddd [nn]LLLLL ********* DECIMAL(32)
167 XXXXXXXX
168 OOOOOOOOOOO
169 DDDDDDDDDD
172 VOID
173 list(void)
175 char *frmt, *wp;
176 int *wpt;
177 int n, nb, nl;
178 a_uint l_addr;
179 int listing, paging;
180 const char *il;
182 /* ib/ic are dynamically allocated */
183 if (bflag != 0) {
184 il = ib;
185 } else {
186 il = ic;
190 * Get Correct Line Number
192 line = srcline;
195 * Internal Listing
197 listing = lnlist;
200 * Listing Control Override
202 if (uflag) {
203 listing = LIST_BITS;
204 if (lmode == NLIST) {
205 lmode = SLIST;
210 * Paging Control
212 paging = !pflag && ((lnlist & LIST_PAG) || (uflag == 1)) ? 1 : 0;
215 * ALIST/BLIST Output Processing
217 if (lmode == ALIST) {
218 outchk(ASXHUGE,ASXHUGE);
220 if (lmode == ALIST || lmode == BLIST) {
221 outdot();
225 * Check NO-LIST Conditions
227 if ((lfp == NULL) || (lmode == NLIST)) {
228 return;
232 * ALIST/BLIST Output Processing
234 if (lmode == ALIST) {
235 outchk(ASXHUGE,ASXHUGE);
240 * Move to next line.
242 slew(lfp, paging);
245 * LIST_ERR - Output a maximum of NERR error codes with listing.
247 if (listing & LIST_ERR) {
248 while (ep < &eb[NERR])
249 *ep++ = ' ';
250 fprintf(lfp, "%.2s", eb);
251 } else {
252 fprintf(lfp, " ");
256 * SLIST
257 * Source listing Option.
259 if (lmode == SLIST) {
260 if (listing & LIST_LOC) {
261 switch(a_bytes) {
262 default:
263 case 2: frmt = "%24s%5u %s\n"; break;
264 case 3:
265 case 4: frmt = "%32s%5u %s\n"; break;
267 fprintf(lfp, frmt, "", line, il);
268 } else {
269 switch(a_bytes) {
270 default:
271 case 2: frmt = "%29s %s\n"; break;
272 case 3:
273 case 4: frmt = "%37s %s\n"; break;
275 fprintf(lfp, frmt, "", il);
277 return;
281 * Truncate (int) to N-Bytes
283 l_addr = laddr;
286 * ELIST
287 * Equate Listing Option
289 if (lmode == ELIST) {
290 if (listing & LIST_EQT) {
291 switch (xflag) {
292 default:
293 case 0: /* HEX */
294 #ifdef LONGINT
295 switch(a_bytes) {
296 default:
297 case 2: frmt = "%19s%04lX"; break;
298 case 3: frmt = "%25s%06lX"; break;
299 case 4: frmt = "%23s%08lX"; break;
301 #else
302 switch(a_bytes) {
303 default:
304 case 2: frmt = "%19s%04X"; break;
305 case 3: frmt = "%25s%06X"; break;
306 case 4: frmt = "%23s%08X"; break;
308 #endif
309 break;
311 case 1: /* OCTAL */
312 #ifdef LONGINT
313 switch(a_bytes) {
314 default:
315 case 2: frmt = "%17s%06lo"; break;
316 case 3: frmt = "%23s%08lo"; break;
317 case 4: frmt = "%20s%011lo"; break;
319 #else
320 switch(a_bytes) {
321 default:
322 case 2: frmt = "%17s%06o"; break;
323 case 3: frmt = "%23s%08o"; break;
324 case 4: frmt = "%20s%011o"; break;
326 #endif
327 break;
329 case 2: /* DECIMAL */
330 #ifdef LONGINT
331 switch(a_bytes) {
332 default:
333 case 2: frmt = "%18s%05lu"; break;
334 case 3: frmt = "%23s%08lu"; break;
335 case 4: frmt = "%21s%010lu"; break;
337 #else
338 switch(a_bytes) {
339 default:
340 case 2: frmt = "%18s%05u"; break;
341 case 3: frmt = "%23s%08u"; break;
342 case 4: frmt = "%21s%010u"; break;
344 #endif
345 break;
347 fprintf(lfp, frmt, "", l_addr);
348 } else {
349 switch(a_bytes) {
350 default:
351 case 2: frmt = "%23s"; break;
352 case 3:
353 case 4: frmt = "%31s"; break;
355 fprintf(lfp, frmt, "");
357 if ((listing & LIST_LIN) && (listing & LIST_SRC)) {
358 fprintf(lfp, " %5u %s\n", line, il);
359 } else
360 if (listing & LIST_LIN) {
361 fprintf(lfp, " %5u\n", line);
362 } else
363 if (listing & LIST_SRC) {
364 fprintf(lfp, " %5s %s\n", "", il);
365 } else {
366 fprintf(lfp, "\n");
368 return;
372 * LIST_LOC - Location Address
374 if (listing & LIST_LOC) {
375 switch (xflag) {
376 default:
377 case 0: /* HEX */
378 #ifdef LONGINT
379 switch(a_bytes) {
380 default:
381 case 2: frmt = " %04lX"; break;
382 case 3: frmt = " %06lX"; break;
383 case 4: frmt = " %08lX"; break;
385 #else
386 switch(a_bytes) {
387 default:
388 case 2: frmt = " %04X"; break;
389 case 3: frmt = " %06X"; break;
390 case 4: frmt = " %08X"; break;
392 #endif
393 break;
395 case 1: /* OCTAL */
396 #ifdef LONGINT
397 switch(a_bytes) {
398 default:
399 case 2: frmt = " %06lo"; break;
400 case 3: frmt = " %08lo"; break;
401 case 4: frmt = "%011lo"; break;
403 #else
404 switch(a_bytes) {
405 default:
406 case 2: frmt = " %06o"; break;
407 case 3: frmt = " %08o"; break;
408 case 4: frmt = "%011o"; break;
410 #endif
411 break;
413 case 2: /* DECIMAL */
414 #ifdef LONGINT
415 switch(a_bytes) {
416 default:
417 case 2: frmt = " %05lu"; break;
418 case 3: frmt = " %08lu"; break;
419 case 4: frmt = " %010lu"; break;
421 #else
422 switch(a_bytes) {
423 default:
424 case 2: frmt = " %05u"; break;
425 case 3: frmt = " %08u"; break;
426 case 4: frmt = " %010u"; break;
428 #endif
429 break;
431 fprintf(lfp, frmt, l_addr);
432 } else {
433 switch(a_bytes) {
434 default:
435 case 2: frmt = "%5s"; break;
436 case 3:
437 case 4: frmt = "%10s"; break;
439 fprintf(lfp, frmt, "");
443 * ALIST/BLIST Listing Options
445 if (lmode == ALIST || lmode == BLIST) {
446 if (listing & LIST_LIN) {
447 switch (xflag) {
448 default:
449 case 0: /* HEX */
450 switch(a_bytes) {
451 default:
452 case 2: frmt = "%19s%5u %s\n"; break;
453 case 3:
454 case 4: frmt = "%22s%5u %s\n"; break;
456 break;
458 case 1: /* OCTAL */
459 switch(a_bytes) {
460 default:
461 case 2: frmt = "%17s%5u %s\n"; break;
462 case 3:
463 case 4: frmt = "%21s%5u %s\n"; break;
465 break;
467 case 2: /* DECIMAL */
468 switch(a_bytes) {
469 default:
470 case 2: frmt = "%17s%5u %s\n"; break;
471 case 3:
472 case 4: frmt = "%21s%5u %s\n"; break;
474 break;
476 fprintf(lfp, frmt, "", line, il);
477 } else {
478 switch (xflag) {
479 default:
480 case 0: /* HEX */
481 switch(a_bytes) {
482 default:
483 case 2: frmt = "%19s%5s %s\n"; break;
484 case 3:
485 case 4: frmt = "%22s%5s %s\n"; break;
487 break;
489 case 1: /* OCTAL */
490 switch(a_bytes) {
491 default:
492 case 2: frmt = "%17s%5s %s\n"; break;
493 case 3:
494 case 4: frmt = "%21s%5s %s\n"; break;
496 break;
498 case 2: /* DECIMAL */
499 switch(a_bytes) {
500 default:
501 case 2: frmt = "%17s%5s %s\n"; break;
502 case 3:
503 case 4: frmt = "%21s%5s %s\n"; break;
505 break;
507 fprintf(lfp, frmt, "", "", il);
509 return;
513 * LIST_BIN - Binary Listing Option
514 * LIST_CYC - Opcode Cycles Option
515 * LIST_LIN - Line Number Option
516 * LIST_SRC - Source Listing Option
518 if (!(listing & (LIST_BIN | LIST_CYC | LIST_LIN | LIST_SRC))) {
519 fprintf(lfp, "\n");
520 return;
524 * Format
526 switch (xflag) {
527 default:
528 case 0: /* HEX */
529 switch(a_bytes) {
530 default:
531 case 2: n = 6; frmt = "%7s"; break;
532 case 3:
533 case 4: n = 7; frmt = "%12s"; break;
535 break;
537 case 1: /* OCTAL */
538 switch(a_bytes) {
539 default:
540 case 2: n = 4; frmt = "%9s"; break;
541 case 3:
542 case 4: n = 5; frmt = "%13s"; break;
544 break;
546 case 2: /* DECIMAL */
547 switch(a_bytes) {
548 default:
549 case 2: n = 4; frmt = "%9s"; break;
550 case 3:
551 case 4: n = 5; frmt = "%13s"; break;
553 break;
556 wp = cb;
557 wpt = cbt;
558 nb = (int) (cp - cb);
561 * If we list cycles, decrease max. bytes on first line.
563 nl = (!cflag && !(opcycles & OPCY_NONE) && (listing & LIST_CYC)) ? (n-1) : n;
566 * First line of output for this source line with data.
568 if (listing & (LIST_LIN | LIST_SRC)) {
569 list1(wp, wpt, nb, nl, 1, listing);
570 if ((listing & LIST_LIN) && (listing & LIST_SRC)) {
571 fprintf(lfp, "%5u %s", line, il);
572 } else
573 if (listing & LIST_LIN) {
574 fprintf(lfp, "%5u", line);
575 } else
576 if (listing & LIST_SRC) {
577 fprintf(lfp, "%5s %s", "", il);
579 } else {
580 list1(wp, wpt, nb, nl, listing & LIST_CYC, listing);
582 fprintf(lfp, "\n");
585 * Subsequent lines of output if more data.
587 if (listing & LIST_BIN) {
588 while ((nb - nl) > 0) {
589 nb -= nl;
590 wp += nl;
591 wpt += nl;
592 nl = n;
593 slew(lfp, paging);
594 fprintf(lfp, frmt, "");
595 list1(wp, wpt, nb, nl, 0, listing);
596 putc('\n', lfp);
601 /*)Function VOID list1(wp, wpt, nw, n, f, g)
603 * int g listing enable flags
604 * int f fill blank fields (1)
605 * int n number of bytes listed per line
606 * int nb number of data bytes
607 * int * wp pointer to data bytes
608 * int * wpt pointer to data byte mode
610 * local variables:
611 * int i loop counter
613 * global variables:
614 * int xflag -x, listing radix flag
616 * functions called:
617 * VOID list2() asslist.c
618 * int fprintf() c_library
620 * side effects:
621 * Data formatted and output to listing.
624 VOID
625 list1(char *wp, int *wpt, int nb, int n, int f, int g)
627 int i;
628 char *frmt1, *frmt2;
630 switch (xflag) {
631 default:
632 case 0: /* HEX */
633 frmt1 = "%02X";
634 frmt2 = " ";
635 break;
637 case 1: /* OCTAL */
638 frmt1 = "%03o";
639 frmt2 = " ";
640 break;
642 case 2: /* DECIMAL */
643 frmt1 = "%03u";
644 frmt2 = " ";
645 break;
648 if (nb > n)
649 nb = n;
652 * Output bytes.
654 for (i=0; i<nb; ++i) {
655 if (g & LIST_BIN) {
656 list2(*wpt++);
657 fprintf(lfp, frmt1, (*wp++)&0377);
658 } else {
659 fprintf(lfp, "%s", frmt2);
664 * Output blanks if required.
666 if (f) {
667 while (i++ < n) {
668 fprintf(lfp, "%s", frmt2);
673 * If we list cycles, put them out, first line only
675 if (f && (g & LIST_CYC) && !cflag && !(opcycles & OPCY_NONE)) {
676 fprintf(lfp, "%s%c%2d%c",
677 (xflag != 0) ? " " : "", CYCNT_BGN, opcycles, CYCNT_END);
678 } else
679 if (f) {
680 fprintf(lfp, " ");
684 /*)Function VOID list2(wpt)
686 * int * wpt pointer to relocation mode
688 * The function list2() outputs the selected
689 * relocation flag as specified by fflag.
691 * local variables:
692 * int c relocation flag character
693 * int t relocation mode
695 * global variables:
696 * int fflag -f(f), relocations flagged flag
698 * functions called:
699 * int putc() c_library
701 * side effects:
702 * Relocation flag output to listing file.
705 VOID
706 list2(int t)
708 int c;
710 c = ' ';
713 * Designate a relocatable word by `.
715 if (fflag == 1) {
716 if (t & R_RELOC) {
717 c = '`';
719 } else
721 * Designate a relocatable word by its mode:
722 * page0 or paged *
723 * unsigned u (v)
724 * operand offset p (q)
725 * relocatable symbol r (s)
727 if (fflag >= 2) {
728 if (t & R_RELOC) {
729 if (t & R_PCR) {
730 c = 'p';
731 } else
732 if (t & (R_PAG0|R_PAGN)) {
733 c = '*';
734 } else
735 if (t & R_USGN) {
736 c = 'u';
737 } else {
738 c = 'r';
740 if (t & R_HIGH) c += 1;
745 * Output the selected mode.
747 putc(c, lfp);
750 /*)Function VOID slew(fp, flag)
752 * FILE * fp file handle for listing
753 * int flag enable pagination
755 * The function slew() increments the page line count.
756 * If the page overflows and pagination is enabled:
757 * 1) put out a page skip,
758 * 2) a title,
759 * 3) a subtitle,
760 * 4) and reset the line count.
762 * local variables:
763 * none
765 * global variables:
766 * int a_bytes T line addressing size
767 * char cpu[] cpu type string
768 * int lop current line number on page
769 * int page current page number
770 * char stb[] Subtitle string buffer
771 * char tb[] Title string buffer
773 * functions called:
774 * int fprintf() c_library
776 * side effects:
777 * Increments page line counter, on overflow
778 * a new page header is output to the listing file.
781 VOID
782 slew(FILE *fp, int flag)
784 char *frmt;
785 char np[132];
786 char tp[132];
787 int n;
789 if (lop++ >= NLPP) {
790 if (flag) {
792 *12345678901234567890123456789012345678901234567890123456789012345678901234567890
793 *ASxxxx Assembler Vxx.xx (Motorola 6809) Page 1
795 sprintf(tp, "ASxxxx Assembler %s (%s)", VERSION, cpu);
796 sprintf(np, "Page %u", ++page);
798 * Total string length is 78 characters.
800 n = 78 - strlen(tp) - strlen(np);
802 * Output string.
804 fprintf(fp, "\f%s%*s%s\n", tp, n, " " ,np);
806 *12345678901234567890123456789012345678901234567890123456789012345678901234567890
807 *Hexadecimal [16-Bits] Sun Sep 15 17:22:25 2013
809 switch(xflag) {
810 default:
811 case 0: frmt = "Hexadecimal [%d-Bits]\n"; break;
812 case 1: frmt = "Octal [%d-Bits]\n"; break;
813 case 2: frmt = "Decimal [%d-Bits]\n"; break;
815 fprintf(fp, frmt, 8 * a_bytes);
816 fprintf(fp, "%s\n", tb);
817 fprintf(fp, "%s\n\n", stb);
818 lop = 6;
819 } else {
820 lop = 1;
825 /* sdas specific */
826 /* Used for qsort call in lstsym */
827 static int _cmpSym(const void *p1, const void *p2)
829 struct sym **s1 = (struct sym **)(p1);
830 struct sym **s2 = (struct sym **)(p2);
831 return strcmp((*s1)->s_id,(*s2)->s_id);
833 /* end sdas specific */
835 /*)Function VOID lstsym(fp)
837 * FILE * fp file handle for output
839 * The function lstsym() outputs alphabetically
840 * sorted symbol and area tables.
842 * local variables:
843 * int c temporary
844 * int i loop counter
845 * int j temporary
846 * int k temporary
847 * int n temporary
848 * int nmsym number of symbols
849 * int narea number of areas
850 * int nbank number of banks
851 * sym ** p pointer to an array of
852 * pointers to symbol structures
853 * int paging computed paging enable flag
854 * char * ptr pointer to an id string
855 * a_uint sa temporary
856 * sym * sp pointer to symbol structure
857 * area * ap pointer to an area structure
859 * global variables:
860 * int a_bytes T line addressing size
861 * area * areap pointer to an area structure
862 * char aretbl[] string "Area Table"
863 * sym dot defined as sym[0]
864 * int lnlist LIST-NLIST state
865 * char stb[] Subtitle string buffer
866 * sym * symhash[] array of pointers to NHASH
867 * linked symbol lists
868 * char symtbl[] string "Symbol Table"
869 * FILE * tfp symbol table output file handle
870 * int uflag LIST-NLIST override flag
871 * int wflag -w, wide listing flag
872 * int xflag -x, listing radix flag
874 * functions called:
875 * int fprintf() c_library
876 * int putc() c_library
877 * VOID slew() aslist.c
878 * int strcmp() c_library
879 * char * strcpy() c_library
880 * char * new() assym.c
882 * side effects:
883 * Symbol and area tables output.
886 VOID
887 lstsym(FILE *fp)
889 int i, j, k, n, paging;
890 int nmsym, narea, nbank;
891 a_uint sa;
892 char *frmt, *ptr;
893 struct sym *sp;
894 struct sym **p;
895 struct area *ap;
898 * Symbol Table Header
900 strcpy(stb, &symtbl[0]);
901 lop = NLPP;
902 if (fp == tfp) {
903 page = 0;
904 paging = 1;
905 } else {
906 paging = !pflag && ((lnlist & LIST_PAG) || (uflag == 1)) ? 1 : 0;
908 slew(fp, 1);
911 * Find number of symbols
913 nmsym = 0;
914 for (i=0; i<NHASH; i++) {
915 sp = symhash[i];
916 while (sp) {
917 if (sp != &dot)
918 ++nmsym;
919 sp = sp->s_sp;
922 if (nmsym == 0)
923 goto atable;
926 * Allocate space for an array of pointers to symbols
927 * and load array.
929 p = (struct sym **) new (sizeof((struct sym *) sp)*nmsym);
930 if (p == NULL) {
931 fprintf(fp, "Insufficient space to build Symbol Table.\n");
932 return;
934 nmsym = 0;
935 for (i=0; i<NHASH; i++) {
936 sp = symhash[i];
937 while (sp) {
938 if (sp != &dot)
939 p[nmsym++] = sp;
940 sp = sp->s_sp;
944 /* sdas specific */
945 #if 0
946 /* BUBBLE SORT?? WTF??? */
948 * Bubble Sort on Symbol Table Array
950 j = 1;
951 c = nmsym - 1;
952 while (j) {
953 j = 0;
954 for (i=0; i<c; ++i) {
955 if (strcmp(&p[i]->s_id[0],&p[i+1]->s_id[0]) > 0) {
956 j = 1;
957 sp = p[i+1];
958 p[i+1] = p[i];
959 p[i] = sp;
963 #else
965 qsort(p, nmsym, sizeof(struct sym *), _cmpSym);
966 #endif
967 /* end sdas specific */
970 * Symbol Table Output
972 for (i=0; i<nmsym;) {
973 sp = p[i];
974 if (sp->s_area) {
975 j = sp->s_area->a_ref;
976 switch(xflag) {
977 default:
978 case 0: frmt = " %2X "; break;
979 case 1: frmt = "%3o "; break;
980 case 2: frmt = "%3u "; break;
982 fprintf(fp, frmt, j);
983 } else {
984 fprintf(fp, " ");
987 ptr = &sp->s_id[0];
988 if (wflag) {
989 fprintf(fp, "%-60.60s", ptr ); /* JLH */
990 } else {
991 fprintf(fp, "%-8.8s", ptr);
993 if (sp->s_flag & S_ASG) {
994 fprintf(fp, "=");
995 } else {
996 fprintf(fp, " ");
998 if (sp->s_type == S_NEW) {
999 switch(a_bytes) {
1000 default:
1001 case 2:
1002 switch(xflag) {
1003 default:
1004 case 0: frmt = " **** "; break;
1005 case 1: frmt = "****** "; break;
1006 case 2: frmt = " ***** "; break;
1008 break;
1010 case 3:
1011 switch(xflag) {
1012 default:
1013 case 0: frmt = " ****** "; break;
1014 case 1: frmt = "******** "; break;
1015 case 2: frmt = "******** "; break;
1017 break;
1019 case 4:
1020 switch(xflag) {
1021 default:
1022 case 0: frmt = " ******** "; break;
1023 case 1: frmt = "*********** "; break;
1024 case 2: frmt = " ********** "; break;
1026 break;
1029 fprintf(fp, "%s", frmt);
1030 } else {
1031 sa = sp->s_addr;
1032 #ifdef LONGINT
1033 switch(a_bytes) {
1034 default:
1035 case 2:
1036 switch(xflag) {
1037 default:
1038 case 0: frmt = " %04lX "; break;
1039 case 1: frmt = "%06lo "; break;
1040 case 2: frmt = " %05lu "; break;
1042 break;
1044 case 3:
1045 switch(xflag) {
1046 default:
1047 case 0: frmt = " %06lX "; break;
1048 case 1: frmt = "%08lo "; break;
1049 case 2: frmt = "%08lu "; break;
1051 break;
1053 case 4:
1054 switch(xflag) {
1055 default:
1056 case 0: frmt = " %08lX "; break;
1057 case 1: frmt = "%011lo "; break;
1058 case 2: frmt = " %010lu "; break;
1060 break;
1062 #else
1063 switch(a_bytes) {
1064 default:
1065 case 2:
1066 switch(xflag) {
1067 default:
1068 case 0: frmt = " %04X "; break;
1069 case 1: frmt = "%06o "; break;
1070 case 2: frmt = " %05u "; break;
1072 break;
1074 case 3:
1075 switch(xflag) {
1076 default:
1077 case 0: frmt = " %06X "; break;
1078 case 1: frmt = "%08o "; break;
1079 case 2: frmt = "%08u "; break;
1081 break;
1083 case 4:
1084 switch(xflag) {
1085 default:
1086 case 0: frmt = " %08X "; break;
1087 case 1: frmt = "%011o "; break;
1088 case 2: frmt = " %010u "; break;
1090 break;
1092 #endif
1093 fprintf(fp, frmt, sa);
1096 j = 0;
1097 if (sp->s_flag & S_GBL) {
1098 putc('G', fp);
1099 ++j;
1101 if (sp->s_flag & S_LCL) {
1102 putc('L', fp);
1103 ++j;
1105 if (sp->s_area != NULL) {
1106 putc('R', fp);
1107 ++j;
1109 if (sp->s_type == S_NEW) {
1110 putc('X', fp);
1111 ++j;
1113 if (wflag) {
1114 putc('\n', fp); /* JLH */
1115 slew(fp, paging);
1116 ++i;
1117 } else {
1118 if (++i % 3 == 0) {
1119 putc('\n', fp);
1120 slew(fp, paging);
1121 } else
1122 if (i < nmsym) {
1123 while (j++ < 4)
1124 putc(' ', fp);
1125 fprintf(fp, "| ");
1129 if (nmsym % 3) {
1130 putc('\n', fp);
1132 putc('\n', fp);
1135 * Area Table Header
1138 atable:
1139 strcpy(stb, &aretbl[0]);
1140 lop = NLPP;
1141 slew(fp, 1);
1144 * Area Table Output
1146 narea = 0;
1147 nbank = 1;
1148 ap = areap;
1149 while (ap) {
1150 ++narea;
1151 ap = ap->a_ap;
1154 for (n=0; n<nbank; ++n) {
1155 for (i=0; i<narea; ++i) {
1156 ap = areap;
1157 for (j=i+1; j<narea; ++j)
1158 ap = ap->a_ap;
1159 j = ap->a_ref;
1160 switch(xflag) {
1161 default:
1162 case 0: frmt = " %2X "; break;
1163 case 1: frmt = " %3o "; break;
1164 case 2: frmt = " %3u "; break;
1166 fprintf(fp, frmt, j);
1168 ptr = &ap->a_id[0];
1169 if (wflag) {
1170 fprintf(fp, "%-40.40s", ptr );
1171 } else {
1172 fprintf(fp, "%-8.8s", ptr);
1175 sa = ap->a_size;
1176 k = ap->a_flag;
1177 #ifdef LONGINT
1178 switch(a_bytes) {
1179 default:
1180 case 2:
1181 switch(xflag) {
1182 default:
1183 case 0: frmt = " size %4lX flags %4X\n"; break;
1184 case 1: frmt = " size %6lo flags %6o\n"; break;
1185 case 2: frmt = " size %5lu flags %6u\n"; break;
1187 break;
1189 case 3:
1190 switch(xflag) {
1191 default:
1192 case 0: frmt = " size %6lX flags %4X\n"; break;
1193 case 1: frmt = " size %8lo flags %6o\n"; break;
1194 case 2: frmt = " size %8lu flags %6u\n"; break;
1196 break;
1198 case 4:
1199 switch(xflag) {
1200 default:
1201 case 0: frmt = " size %8lX flags %4X\n"; break;
1202 case 1: frmt = " size %11lo flags %6o\n"; break;
1203 case 2: frmt = " size %10lu flags %6u\n"; break;
1205 break;
1207 #else
1208 switch(a_bytes) {
1209 default:
1210 case 2:
1211 switch(xflag) {
1212 default:
1213 case 0: frmt = " size %4X flags %4X\n"; break;
1214 case 1: frmt = " size %6o flags %6o\n"; break;
1215 case 2: frmt = " size %5u flags %6u\n"; break;
1217 break;
1219 case 3:
1220 switch(xflag) {
1221 default:
1222 case 0: frmt = " size %6X flags %4X\n"; break;
1223 case 1: frmt = " size %8o flags %6o\n"; break;
1224 case 2: frmt = " size %8u flags %6u\n"; break;
1226 break;
1228 case 4:
1229 switch(xflag) {
1230 default:
1231 case 0: frmt = " size %8X flags %4X\n"; break;
1232 case 1: frmt = " size %11o flags %6o\n"; break;
1233 case 2: frmt = " size %10u flags %6u\n"; break;
1235 break;
1237 #endif
1238 fprintf(fp, frmt, sa, k);
1239 slew(fp, paging);
1242 putc('\n', fp);