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