|
|
1.1 root 1: /* mjm: started with rhfcc.c (OCT 78, JAN 79)
2: * Made version to be called from "cc -F[qunl]"; /lib/fpp
3: * When SMALL DEFINEd,
4: * SYMTABSZ, OB, N changed to fit into 16k
5: */
6: /* #define SMALL /* mjm: so will fit on LSX with 16K */
7: #define MARK (-1)
8: #ifndef SMALL
9: #define SYMTABSZ 4096
10: #define N 200
11: #define OB 200
12: #endif
13: #ifdef SMALL
14: #define SYMTABSZ 1024 /* mjm: was 4096 (11/20 only 16K) */
15: #define N 100 /* mjm: was 200 */
16: #define OB 100 /* mjm: was 200 */
17: #endif
18: #define ON 77
19:
20: #define SHARPBUFL 128 /* chars in # lines max */
21: #define HEADLEN 4 /* chars in Q object header */
22: #define SHARPLEN 60 /* max chars in filename from # lines */
23: static char sharptext[SHARPLEN];
24: static int sharpn0,sharpn1; /* n1 = value from line n0 = inputno */
25:
26: extern int unixfmt; /* if set, use unix format floating point */
27: extern int unsign; /* 1 for unsigned allowed, 0 for not */
28: static struct obj {
29: int type,size;
30: char text[2];
31: };
32: static char ib[N],ugb[N];
33: static int ibp = {N}, ugbp = {0};
34: static int ifp,ofp;
35: static char ob[OB];
36: static int obp,lpos;
37: static inputno;
38: static nopt,qopt,uopt, lopt; /* mjm: no popt,vopt,eopt; but lopt */
39: static char *infile;
40: char *symtout; /* mjm: file for rhsymtab.c (command arg) */
41:
42: main(ac,av)
43: int ac;
44: char **av;
45: {
46: int i;
47: char *s;
48: if(ac < 4) { /* mjm */
49: printf("fpp arg count error\n"); /* mjm */
50: exit(1);
51: }
52: if(ac == 5) { /* mjm */
53: s = av[4];
54: while(*s)
55: switch(*s++) {
56: case 'q': qopt=1; break;
57: case 'n': nopt=1; break;
58: case 'u': uopt=1; break;
59: case 'l': lopt=1; break;
60: }
61: }
62: if(nopt) unixfmt=0;
63: else unixfmt=1;
64:
65: if(uopt) unsign=0; /* no unsigned declaration in output */
66: else unsign=1; /* declare _ftou() and _ntou() unsigned */
67:
68: infile=av[1];
69: if((ifp=open(infile,0))<0) abt("can't open .i for read");
70: if((ofp=creat(av[2],0666))<0) abt("can't open fcc write file");
71: symtout = av[3]; /* mjm */
72: symtab(SYMTABSZ);
73:
74: file();
75: flushout();
76: close(ifp);
77: close(ofp);
78: unlink(symtout); /* mjm: rm symbol table file */
79: exit(0);
80: }
81:
82: abt(s)
83: char *s;
84: {
85: pdiag("abt",s); /* mjm */
86: flushout();
87: exit(1);
88: }
89:
90: warn(s)
91: char *s;
92: {
93: if(qopt==0)
94: pdiag("warn",s);
95: }
96:
97: gc() /* get a character */
98: {
99: int i,j;
100: if((i=gc2())!='/')return(i); /* not a comment */
101: if((j=gc2())!='*') {
102: ug(j); /* not a comment */
103: return(i);
104: }
105: /* skip till end of comment */
106: while(1) {
107: while((i=gc2())!='*') if(i==0)abt("unclosed comment");
108: if((i=gc2())=='/') return(' '); /*replace comment by blank*/
109: ug(i);
110: }
111: }
112:
113: gc2() /* used to be gc(): this entry doesn't strip comments */
114: {
115: int i,j,k;
116: register char *temp; /* buffer for # line */
117: char outtemp[16+SHARPLEN]; /* buffer for # number on line numbers */
118: char *s; /* mjm */
119: static int newline = 1; /* if 1, next char starts a new line. check for # */
120: if(ugbp==0) {
121: gc2top: if(ibp>=N) {
122: j=read(ifp,ib,N);
123: if(j<0)j=0;
124: for(i=j; i<N; i++) ib[i]=0;
125: ibp=0;
126: }
127: if(newline) { /* check for # line to skip */
128: newline=0;
129: if(lopt) /* mjm: only to get extra line numbers */
130: if(sharptext[0]) { /* toss out # n file if ever seen # */
131: for(k=0; outtemp[k]="# "[k]; k++);
132: outtemp[i=k+5]=0; /* convert 5 digits */
133: j=inputno-sharpn0+sharpn1;
134: while(j) {
135: outtemp[--i]=j%10+'0';
136: j/=10;
137: }
138: while(outtemp[k++]=outtemp[i++]);
139: outtemp[k-1] = ' '; /* mjm */
140: s = sharptext; /* mjm: filename also */
141: while(outtemp[k++] = *s++) ; /* mjm */
142: outtemp[k-1]='\n';
143: write(ofp,outtemp,k);
144: }
145: if(ib[ibp]=='#') {
146: temp=(char *)getq(SHARPBUFL-HEADLEN); /* get buffer for line */
147: for(i=0; i<SHARPBUFL;) {
148: if((temp[i++]=gc2())=='\n')break;
149: }
150: write(ofp,temp,i);
151: sharpn0=inputno;
152: j=1; while(temp[j]==' ')j++;
153: if(temp[j]=='\n')goto skipx;
154: sharpn1=0;
155: while(temp[j]>='0'&&temp[j]<='9')sharpn1=sharpn1*10
156: +temp[j++]-'0';
157: while(temp[j]==' ')j++;
158: if(temp[j]=='\n')goto skipx;
159: i=0;
160: while(temp[j]!='\n'&&i<SHARPLEN-1)
161: sharptext[i++]=temp[j++];
162: sharptext[i]=0;
163: skipx:
164: free(temp);
165: goto gc2top;
166: }
167: }
168: inputno+=newline=ib[ibp]=='\n'; /* ha! */
169: while((j=ib[ibp++])=='\\') {
170: if((i=gc())!='\n') {
171: ug(i);
172: return('\\');
173: }
174: }
175: return(j);
176: }
177: return(ugb[ugbp--]);
178: }
179:
180: ug(c) /* unget a character */
181: int c;
182: {
183: ugb[++ugbp]=c;
184: if(ugbp>=N-1)abt("unget buffer overflow");
185: return(c);
186: }
187:
188:
189: outq(op)
190: struct obj *op;
191: {
192: int i,j,k;
193: int c;
194: char *s;
195: k=op->size;
196: s=op->text;
197: for(i=0; i<k; i++) {
198: c= *s++;
199: ob[obp++]=c;
200: if(c=='\n') flushout();
201: lpos+= c!=MARK;
202: if(lpos>ON||obp>=OB) partial();
203: }
204: }
205:
206: flushout()
207: {
208: int i,j,k;
209: if(obp<=0)return(0);
210: for(i=j=0; i<obp; i++) {
211: if(ob[i]!=MARK)ob[j++]=ob[i];
212: }
213: if(j==0)ob[j++]='\n';
214: if(ob[j-1]!='\n')ob[j++]='\n';
215: if(write(ofp,ob,j)<=0) {
216: obp=0;
217: abt("write error");
218: }
219: lpos=obp=0;
220: }
221:
222: partial()
223: {
224: int i,j,k,l;
225: for(i=j=k=0; i<obp; i++) {
226: if(ob[i]==MARK) {
227: if(k<ON) j=i;
228: }
229: else k++;
230: }
231: if(j==0) {
232: l=obp;
233: for(i=ON; i>0; --i)if(ob[i-1]!='\\')break;
234: if(i==0)abt("funny line in 'partial()'");
235: k=ob[i];
236: j=ob[i+1];
237: ob[i]='\\';
238: ob[i+1]='\n';
239: obp=i+2;
240: flushout();
241: obp=l;
242: ob[i]=k;
243: ob[i+1]=j;
244: for(j=lpos=0; i<l; i++) {
245: lpos+= (ob[j++]=ob[i])!=MARK;
246: }
247: obp=j;
248: return(0);
249: }
250: else {
251: ob[j++]='\n';
252: l=obp;
253: obp=j;
254: flushout();
255: for(i=lpos=0; j<l; j++) {
256: lpos+= (ob[i++]=ob[j])!=MARK;
257: }
258: obp=i;
259: return(0);
260: }
261: }
262: static pdiag(name,s) /* mjm: replaces printif() and printf's in abt and warn */
263: char *name, *s;
264: {
265: printf("%s line %d:", sharptext,inputno-sharpn0+sharpn1);
266: printf(" fpp %s: %s\n", name,s);
267: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.