1 /*
2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18 /** \file listing.c
19 \brief Fortran source listing file module.
20 */
21
22 #include "gbldefs.h"
23 #include "global.h"
24 #include "version.h"
25
26 static int pgpos = 1; /* line position within page of next line */
27 static FILE *lf; /* listing file descriptor */
28 static int pgno; /* page number of next page */
29
30 #define LPP 60
31
32 static void list_ln(char *, char *);
33
34 void
list_init(FILE * fd)35 list_init(FILE *fd)
36 {
37 register char **p;
38 char buf[80], buf1[40], buf2[20], buf3[20];
39 static char *sevtxt[4] = {"inform", "warn", "severe", "fatal"};
40
41 lf = fd;
42 pgno = 1;
43
44 /* WARNING: watch for overflowing buf */
45 if (!DBGBIT(14, 3)) {
46
47 /* ... put out switch line. */
48 sprintf(
49 buf, "Switches: -%s -%s -%s -%s -%s -%s",
50 (flg.asmcode ? "asm" : "noasm"), (flg.dclchk ? "dclchk" : "nodclchk"),
51 (flg.debug ? "debug" : "nodebug"), (flg.dlines ? "dlines" : "nodlines"),
52 (flg.line ? "line" : "noline"), (flg.list ? "list" : "nolist"));
53 list_line(buf);
54
55 /* -idir lines: */
56 for (p = flg.idir; p && *p; p++)
57 list_ln(" -idir ", *p);
58
59 sprintf(buf, " -inform %s -opt %d -%s -%s -%s", sevtxt[flg.inform],
60 flg.opt, (flg.save ? "save" : "nosave"),
61 (flg.object ? "object" : "noobject"),
62 (flg.onetrip ? "onetrip" : "noonetrip"));
63 list_line(buf);
64
65 buf2[0] = buf3[0] = 0;
66 if (flg.depchk) {
67 if (flg.depwarn)
68 strcpy(buf2, "-depchk warn");
69 else
70 strcpy(buf2, "-depchk on");
71 } else
72 strcpy(buf2, "-depchk off");
73 sprintf(buf, " %s -%s %s %s", buf2,
74 (flg.standard ? "standard" : "nostandard"),
75 (flg.extend_source == 132 ? "-extend" : " "),
76 (flg.profile ? "-profile" : " "));
77 list_line(buf);
78
79 strcpy(buf1, "-show");
80 if (flg.include && flg.xref && flg.code)
81 strcat(buf1, " all");
82 else {
83 if (flg.include)
84 strcat(buf1, " include");
85 if (flg.xref)
86 strcat(buf1, " xref");
87 if (flg.code)
88 strcat(buf1, " code");
89 }
90 if (!strcmp(buf1, "-show"))
91 strcpy(buf1, " ");
92 buf2[0] = buf3[0] = 0;
93 sprintf(buf, " -%s -%s %s %s %s",
94 (flg.symbol ? "symbol" : "nosymbol"),
95 (flg.ucase ? "upcase" : "noupcase"), buf1, buf2, buf3);
96 list_line(buf);
97
98 /* ... put out filename line. */
99 list_ln("\nFilename: ", gbl.src_file);
100 }
101
102 list_line("");
103
104 }
105
106 void
list_line(char * txt)107 list_line(char *txt)
108 {
109 list_ln("", txt);
110 }
111
112 static void
list_ln(char * beg,char * txt)113 list_ln(char *beg, char *txt)
114 {
115 if (pgpos == 1 && !DBGBIT(14, 3)) {
116 if (!lf)
117 return; /* in case error msg written before file
118 * opened */
119 fprintf(lf, "\n\n\n%s (Version %8s) %s page %d\n\n",
120 version.lang, version.vsn, gbl.datetime, pgno);
121 pgno++;
122 pgpos = 6;
123 }
124
125 fprintf(lf, "%s%s\n", beg, txt);
126 #if DEBUG
127 if (DBGBIT(0, 4))
128 fprintf(gbl.dbgfil, "%s%s\n", beg, txt);
129 #endif
130 pgpos++;
131
132 if (pgpos == LPP + 4 && !DBGBIT(14, 3)) {
133 fprintf(lf, "\n\n\n");
134 pgpos = 1;
135 }
136
137 }
138
139 void
list_page(void)140 list_page(void)
141 {
142
143 if (lf)
144 if (!(DBGBIT(14, 3) || DBGBIT(0, 32)))
145 while (pgpos != 1)
146 list_line("");
147
148 }
149