Commit | Line | Data |
---|---|---|
a41ae56c | 1 | Original BTL Ratfor System for 4.2 |
6ae7c017 KB |
2 | /*- |
3 | * %sccs.include.proprietary.c% | |
4 | */ | |
5 | ||
476fcd16 | 6 | #ifndef lint |
6ae7c017 KB |
7 | static char sccsid[] = "@(#)r2.c 1.3 (Berkeley) %G%"; |
8 | #endif /* not lint */ | |
476fcd16 | 9 | |
a41ae56c CC |
10 | #include "r.h" |
11 | ||
12 | extern int hollerith; | |
13 | ||
14 | char outbuf[80]; | |
15 | int outp = 0; | |
16 | int cont = 0; | |
17 | int contchar = '&'; | |
18 | ||
19 | char comment[320]; | |
20 | int comptr = 0; | |
21 | int indent = 0; | |
22 | ||
23 | outdon() { | |
24 | outbuf[outp] = '\0'; | |
25 | if (outp > 0) | |
26 | fprintf(outfil, "%s\n", outbuf); | |
27 | outp = cont = 0; | |
28 | } | |
29 | ||
30 | putcom(s) char *s; { | |
31 | if (printcom) { | |
32 | ptc('c'); | |
33 | outtab(); | |
34 | pts(s); | |
35 | outdon(); | |
36 | } | |
37 | } | |
38 | ||
39 | outcode(xp) char *xp; { | |
40 | register c, c1, j; | |
41 | char *q, *p; | |
42 | ||
43 | p = (char *) xp; /* shut lint up */ | |
44 | if (cont == 0 && comptr > 0) /* flush comment if not on continuation */ | |
45 | flushcom(); | |
46 | while( (c = *p++) ){ | |
47 | c1 = *p; | |
48 | if (type[c] == LET || type[c] == DIG) { | |
49 | pts(p-1); | |
50 | break; | |
51 | } | |
52 | switch(c){ | |
53 | ||
54 | case '"': case '\'': | |
55 | j = 0; | |
56 | for (q=p; *q; q++) { | |
57 | if (*q == '\\') | |
58 | q++; | |
59 | j++; | |
60 | } | |
61 | if (outp+j+2 > 71) | |
62 | contcard(); | |
63 | if (hollerith) { | |
64 | outnum(--j); | |
65 | ptc('h'); | |
66 | } else | |
67 | ptc(c); | |
68 | while (*p != c) { | |
69 | if (*p == '\\') | |
70 | p++; | |
71 | ptc(*p++); | |
72 | } | |
73 | if (!hollerith) | |
74 | ptc(c); | |
75 | p++; | |
76 | break; | |
77 | case '$': case '\\': | |
78 | if (strlen(p-1)+outp > 71) | |
79 | contcard(); | |
80 | if (c1 == '"' || c1 == '\'') { | |
81 | ptc(c1); | |
82 | p++; | |
83 | } else | |
84 | for (p--; *p; p++) | |
85 | ptc(*p); | |
86 | break; | |
87 | case '%': | |
88 | outp = 0; | |
89 | while (*p) | |
90 | ptc(*p++); | |
91 | break; | |
92 | case '>': | |
93 | if( c1=='=' ){ | |
94 | pts(".ge."); p++; | |
95 | } else | |
96 | pts(".gt."); | |
97 | break; | |
98 | case '<': | |
99 | if( c1=='=' ){ | |
100 | pts(".le."); p++; | |
101 | } else if( c1=='>' ){ | |
102 | pts(".ne."); p++; | |
103 | } else | |
104 | pts(".lt."); | |
105 | break; | |
106 | case '=': | |
107 | if( c1=='=' ){ | |
108 | pts(".eq."); p++; | |
109 | } else | |
110 | ptc('='); | |
111 | break; | |
112 | case '!': case '^': | |
113 | if( c1=='=' ){ | |
114 | pts(".ne."); p++; | |
115 | } else | |
116 | pts(".not."); | |
117 | break; | |
118 | case '&': | |
119 | if( c1=='&' ) | |
120 | p++; | |
121 | pts(".and."); | |
122 | break; | |
123 | case '|': | |
124 | if( c1=='|' ) | |
125 | p++; | |
126 | pts(".or."); | |
127 | break; | |
128 | case '\t': | |
129 | outtab(); | |
130 | break; | |
131 | case '\n': | |
132 | ptc(' '); | |
133 | break; | |
134 | default: | |
135 | ptc(c); | |
136 | break; | |
137 | } | |
138 | } | |
139 | } | |
140 | ||
141 | ptc(c) char c; { | |
142 | if( outp > 71 ) | |
143 | contcard(); | |
144 | outbuf[outp++] = c; | |
145 | } | |
146 | ||
147 | pts(s) char *s; { | |
148 | if (strlen(s)+outp > 71) | |
149 | contcard(); | |
150 | while(*s) | |
151 | ptc(*s++); | |
152 | } | |
153 | ||
154 | contcard(){ | |
155 | int n; | |
156 | outbuf[outp] = '\0'; | |
157 | fprintf(outfil, "%s\n", outbuf); | |
158 | n = 6; | |
159 | if (printcom) { | |
160 | n += INDENT * indent + 1; | |
161 | if (n > 35) n = 35; | |
162 | } | |
163 | for( outp=0; outp<n; outbuf[outp++] = ' ' ); | |
164 | outbuf[contfld-1] = contchar; | |
165 | cont++; | |
166 | if (cont > 19) | |
167 | error("more than 19 continuation cards"); | |
168 | } | |
169 | ||
170 | outtab(){ | |
171 | int n; | |
172 | n = 6; | |
173 | if (printcom) { | |
174 | n += INDENT * indent; | |
175 | if (n > 35) n = 35; | |
176 | } | |
177 | while (outp < n) | |
178 | ptc(' '); | |
179 | } | |
180 | ||
181 | outnum(n) int n; { | |
182 | int a; | |
183 | if( a = n/10 ) | |
184 | outnum(a); | |
185 | ptc(n%10 + '0'); | |
186 | } | |
187 | ||
188 | outcont(n) int n; { | |
189 | transfer = 0; | |
190 | if (n == 0 && outp == 0) | |
191 | return; | |
192 | if( n > 0 ) | |
193 | outnum(n); | |
194 | outcode("\tcontinue"); | |
195 | outdon(); | |
196 | } | |
197 | ||
198 | outgoto(n) int n; { | |
199 | if (transfer != 0) | |
200 | return; | |
201 | outcode("\tgoto "); | |
202 | outnum(n); | |
203 | outdon(); | |
204 | } | |
205 | ||
206 | flushcom() { | |
207 | int i, j; | |
208 | if (printcom == 0) | |
209 | comptr = 0; | |
210 | else if (cont == 0 && comptr > 0) { | |
211 | for (i=j=0; i < comptr; i++) | |
212 | if (comment[i] == '\n') { | |
213 | comment[i] = '\0'; | |
214 | fprintf(outfil, "%s\n", &comment[j]); | |
215 | j = i + 1; | |
216 | } | |
217 | comptr = 0; | |
218 | } | |
219 | } |