Debian Codegraph @

texk/web2c/tangleboot.pin

raw
1 {2:}{4:}{$C-,A+,D-}{[$C+,D+]}
2 {:4}program TANGLE(webfile,changefile,Pascalfile,pool);
3 const{8:}bufsize=1000;maxbytes=65535;maxtoks=65535;maxnames=10239;
4 maxtexts=10239;hashsize=8501;longestname=400;linelength=72;
5 outbufsize=144;stacksize=100;maxidlength=50;defunambiglength=32;
6 {:8}type{11:}ASCIIcode=0..255;
7 {:11}{12:}textfile=packed file of ASCIIcode;{:12}{37:}eightbits=0..255;
8 sixteenbits=0..65535;{:37}{39:}namepointer=0..maxnames;
9 {:39}{43:}textpointer=0..maxtexts;
10 {:43}{78:}outputstate=record endfield:sixteenbits;bytefield:sixteenbits;
11 namefield:namepointer;replfield:textpointer;modfield:0..12287;end;
12 {:78}var{9:}history:0..3;{:9}{13:}xord:array[ASCIIcode]of ASCIIcode;
13 xchr:array[ASCIIcode]of ASCIIcode;{:13}{23:}webfile:textfile;
14 changefile:textfile;{:23}{25:}Pascalfile:textfile;pool:textfile;
15 {:25}{27:}buffer:array[0..bufsize]of ASCIIcode;
16 {:27}{29:}phaseone:boolean;
17 {:29}{38:}bytemem:packed array[0..2,0..maxbytes]of ASCIIcode;
18 tokmem:packed array[0..4,0..maxtoks]of eightbits;
19 bytestart:array[0..maxnames]of sixteenbits;
20 tokstart:array[0..maxtexts]of sixteenbits;
21 link:array[0..maxnames]of sixteenbits;
22 ilk:array[0..maxnames]of sixteenbits;equiv:array[0..maxnames]of integer;
23 textlink:array[0..maxtexts]of sixteenbits;{:38}{40:}nameptr:namepointer;
24 stringptr:namepointer;byteptr:array[0..2]of 0..maxbytes;
25 poolchecksum:integer;{:40}{44:}textptr:textpointer;
26 tokptr:array[0..4]of 0..maxtoks;z:0..4;
27 {maxtokptr:array[0..4]of 0..maxtoks;}{:44}{50:}idfirst:0..bufsize;
28 idloc:0..bufsize;doublechars:0..bufsize;
29 hash,chophash:array[0..hashsize]of sixteenbits;
30 choppedid:array[0..maxidlength]of ASCIIcode;
31 {:50}{65:}modtext:array[0..longestname]of ASCIIcode;
32 {:65}{70:}lastunnamed:textpointer;{:70}{79:}curstate:outputstate;
33 stack:array[1..stacksize]of outputstate;stackptr:0..stacksize;
34 {:79}{80:}zo:0..4;{:80}{82:}bracelevel:eightbits;
35 {:82}{86:}curval:integer;
36 {:86}{94:}outbuf:array[0..outbufsize]of ASCIIcode;outptr:0..outbufsize;
37 breakptr:0..outbufsize;semiptr:0..outbufsize;
38 {:94}{95:}outstate:eightbits;outval,outapp:integer;outsign:ASCIIcode;
39 lastsign:-1..+1;{:95}{100:}outcontrib:array[1..linelength]of ASCIIcode;
40 {:100}{124:}ii:integer;line:integer;otherline:integer;templine:integer;
41 limit:0..bufsize;loc:0..bufsize;inputhasended:boolean;changing:boolean;
42 {:124}{126:}changebuffer:array[0..bufsize]of ASCIIcode;
43 changelimit:0..bufsize;{:126}{143:}curmodule:namepointer;
44 scanninghex:boolean;{:143}{156:}nextcontrol:eightbits;
45 {:156}{164:}currepltext:textpointer;{:164}{171:}modulecount:0..12287;
46 {:171}{179:}{troubleshooting:boolean;ddt:integer;dd:integer;
47 debugcycle:integer;debugskipped:integer;}{:179}{185:}{wo:0..2;}
48 {:185}{200:}webname,chgname,pascalname,poolname:constcstring;
49 forceuppercase,forcelowercase,allowunderlines,strictmode:boolean;
50 unambiglength:0..maxidlength;{:200}{30:}{procedure debughelp;forward;}
51 {:30}{31:}procedure error;var j:0..outbufsize;k,l:0..bufsize;
52 begin if phaseone then{32:}begin if changing then write(stdout,
53 '. (change file ')else write(stdout,'. (');
54 writeln(stdout,'l.',line:1,')');if loc>=limit then l:=limit else l:=loc;
55 for k:=1 to l do if buffer[k-1]=9 then write(stdout,' ')else write(
56 stdout,xchr[buffer[k-1]]);writeln(stdout);
57 for k:=1 to l do write(stdout,' ');
58 for k:=l+1 to limit do write(stdout,xchr[buffer[k-1]]);
59 write(stdout,' ');
60 end{:32}else{33:}begin writeln(stdout,'. (l.',line:1,')');
61 for j:=1 to outptr do write(stdout,xchr[outbuf[j-1]]);
62 write(stdout,'... ');end{:33};fflush(stdout);history:=2;
63 {debugskipped:=debugcycle;debughelp;}end;
64 {:31}{188:}procedure parsearguments;const noptions=9;
65 var longoptions:array[0..noptions]of getoptstruct;
66 getoptreturnval:integer;optionindex:cinttype;currentoption:0..noptions;
67 len:integer;begin{190:}currentoption:=0;
68 longoptions[currentoption].name:='help';
69 longoptions[currentoption].hasarg:=0;longoptions[currentoption].flag:=0;
70 longoptions[currentoption].val:=0;currentoption:=currentoption+1;
71 {:190}{191:}longoptions[currentoption].name:='version';
72 longoptions[currentoption].hasarg:=0;longoptions[currentoption].flag:=0;
73 longoptions[currentoption].val:=0;currentoption:=currentoption+1;
74 {:191}{192:}longoptions[currentoption].name:='mixedcase';
75 longoptions[currentoption].hasarg:=0;longoptions[currentoption].flag:=0;
76 longoptions[currentoption].val:=0;currentoption:=currentoption+1;
77 {:192}{193:}longoptions[currentoption].name:='uppercase';
78 longoptions[currentoption].hasarg:=0;longoptions[currentoption].flag:=0;
79 longoptions[currentoption].val:=0;currentoption:=currentoption+1;
80 {:193}{194:}longoptions[currentoption].name:='lowercase';
81 longoptions[currentoption].hasarg:=0;longoptions[currentoption].flag:=0;
82 longoptions[currentoption].val:=0;currentoption:=currentoption+1;
83 {:194}{195:}longoptions[currentoption].name:='underlines';
84 longoptions[currentoption].hasarg:=0;longoptions[currentoption].flag:=0;
85 longoptions[currentoption].val:=0;currentoption:=currentoption+1;
86 {:195}{196:}longoptions[currentoption].name:='strict';
87 longoptions[currentoption].hasarg:=0;longoptions[currentoption].flag:=0;
88 longoptions[currentoption].val:=0;currentoption:=currentoption+1;
89 {:196}{197:}longoptions[currentoption].name:='loose';
90 longoptions[currentoption].hasarg:=0;longoptions[currentoption].flag:=0;
91 longoptions[currentoption].val:=0;currentoption:=currentoption+1;
92 {:197}{198:}longoptions[currentoption].name:='length';
93 longoptions[currentoption].hasarg:=1;longoptions[currentoption].flag:=0;
94 longoptions[currentoption].val:=0;currentoption:=currentoption+1;
95 {:198}{199:}longoptions[currentoption].name:=0;
96 longoptions[currentoption].hasarg:=0;longoptions[currentoption].flag:=0;
97 longoptions[currentoption].val:=0;{:199};
98 unambiglength:=defunambiglength;
99 repeat getoptreturnval:=getoptlongonly(argc,argv,'',longoptions,
100 addressof(optionindex));if getoptreturnval=-1 then begin;
101 end else if getoptreturnval=63 then begin usage('tangle');
102 end else if(strcmp(longoptions[optionindex].name,'help')=0)then begin
103 usagehelp(TANGLEHELP,nil);
104 end else if(strcmp(longoptions[optionindex].name,'version')=0)then begin
105 printversionandexit('This is TANGLE, Version 4.6',nil,'D.E. Knuth',nil);
106 end else if(strcmp(longoptions[optionindex].name,'mixedcase')=0)then
107 begin forceuppercase:=false;forcelowercase:=false;
108 end else if(strcmp(longoptions[optionindex].name,'uppercase')=0)then
109 begin forceuppercase:=true;forcelowercase:=false;
110 end else if(strcmp(longoptions[optionindex].name,'lowercase')=0)then
111 begin forceuppercase:=false;forcelowercase:=true;
112 end else if(strcmp(longoptions[optionindex].name,'underlines')=0)then
113 begin allowunderlines:=true;
114 end else if(strcmp(longoptions[optionindex].name,'strict')=0)then begin
115 strictmode:=true;
116 end else if(strcmp(longoptions[optionindex].name,'loose')=0)then begin
117 strictmode:=false;
118 end else if(strcmp(longoptions[optionindex].name,'length')=0)then begin
119 len:=atoi(optarg);if(len<=0)or(len>maxidlength)then len:=maxidlength;
120 unambiglength:=len;end;until getoptreturnval=-1;
121 {189:}if(optind+1>argc)or(optind+3<argc)then begin writeln(stderr,
122 'tangle',': Need one to three file arguments.');usage('tangle');end;
123 webname:=extendfilename(cmdline(optind),'web');
124 if optind+2<=argc then begin if strcmp(chartostring('-'),cmdline(optind
125 +1))<>0 then chgname:=extendfilename(cmdline(optind+1),'ch');end;
126 if optind+3=argc then begin pascalname:=extendfilename(cmdline(optind+2)
127 ,chartostring('p'));
128 poolname:=extendfilename(removesuffix(pascalname),'pool');
129 end else begin pascalname:=basenamechangesuffix(webname,'.web','.p');
130 poolname:=basenamechangesuffix(webname,'.web','.pool');end;{:189}end;
131 {:188}procedure initialize;var{16:}i:0..255;{:16}{41:}wi:0..2;
132 {:41}{45:}zi:0..4;{:45}{51:}h:0..hashsize;
133 {:51}begin kpsesetprogramname(argv[0],'tangle');parsearguments;
134 {10:}history:=0;{:10}{14:}xchr[32]:=' ';xchr[33]:='!';xchr[34]:='"';
135 xchr[35]:='#';xchr[36]:='$';xchr[37]:='%';xchr[38]:='&';xchr[39]:='''';
136 xchr[40]:='(';xchr[41]:=')';xchr[42]:='*';xchr[43]:='+';xchr[44]:=',';
137 xchr[45]:='-';xchr[46]:='.';xchr[47]:='/';xchr[48]:='0';xchr[49]:='1';
138 xchr[50]:='2';xchr[51]:='3';xchr[52]:='4';xchr[53]:='5';xchr[54]:='6';
139 xchr[55]:='7';xchr[56]:='8';xchr[57]:='9';xchr[58]:=':';xchr[59]:=';';
140 xchr[60]:='<';xchr[61]:='=';xchr[62]:='>';xchr[63]:='?';xchr[64]:='@';
141 xchr[65]:='A';xchr[66]:='B';xchr[67]:='C';xchr[68]:='D';xchr[69]:='E';
142 xchr[70]:='F';xchr[71]:='G';xchr[72]:='H';xchr[73]:='I';xchr[74]:='J';
143 xchr[75]:='K';xchr[76]:='L';xchr[77]:='M';xchr[78]:='N';xchr[79]:='O';
144 xchr[80]:='P';xchr[81]:='Q';xchr[82]:='R';xchr[83]:='S';xchr[84]:='T';
145 xchr[85]:='U';xchr[86]:='V';xchr[87]:='W';xchr[88]:='X';xchr[89]:='Y';
146 xchr[90]:='Z';xchr[91]:='[';xchr[92]:='\';xchr[93]:=']';xchr[94]:='^';
147 xchr[95]:='_';xchr[96]:='`';xchr[97]:='a';xchr[98]:='b';xchr[99]:='c';
148 xchr[100]:='d';xchr[101]:='e';xchr[102]:='f';xchr[103]:='g';
149 xchr[104]:='h';xchr[105]:='i';xchr[106]:='j';xchr[107]:='k';
150 xchr[108]:='l';xchr[109]:='m';xchr[110]:='n';xchr[111]:='o';
151 xchr[112]:='p';xchr[113]:='q';xchr[114]:='r';xchr[115]:='s';
152 xchr[116]:='t';xchr[117]:='u';xchr[118]:='v';xchr[119]:='w';
153 xchr[120]:='x';xchr[121]:='y';xchr[122]:='z';xchr[123]:='{';
154 xchr[124]:='|';xchr[125]:='}';xchr[126]:='~';xchr[0]:=' ';
155 xchr[127]:=' ';{:14}{17:}for i:=1 to 31 do xchr[i]:=chr(i);
156 for i:=128 to 255 do xchr[i]:=chr(i);
157 {:17}{18:}for i:=0 to 255 do xord[chr(i)]:=32;
158 for i:=1 to 255 do xord[xchr[i]]:=i;xord[' ']:=32;
159 {:18}{21:}{:21}{26:}rewrite(Pascalfile,pascalname);
160 {:26}{42:}for wi:=0 to 2 do begin bytestart[wi]:=0;byteptr[wi]:=0;end;
161 bytestart[3]:=0;nameptr:=1;stringptr:=256;poolchecksum:=271828;
162 {:42}{46:}for zi:=0 to 4 do begin tokstart[zi]:=0;tokptr[zi]:=0;end;
163 tokstart[5]:=0;textptr:=1;z:=1 mod 5;{:46}{48:}ilk[0]:=0;equiv[0]:=0;
164 {:48}{52:}for h:=0 to hashsize-1 do begin hash[h]:=0;chophash[h]:=0;end;
165 {:52}{71:}lastunnamed:=0;textlink[0]:=0;{:71}{144:}scanninghex:=false;
166 {:144}{152:}modtext[0]:=32;{:152}{180:}{troubleshooting:=true;
167 debugcycle:=1;debugskipped:=0;troubleshooting:=false;debugcycle:=99999;}
168 {:180}end;{:2}{24:}procedure openinput;
169 begin webfile:=kpseopenfile(webname,kpsewebformat);
170 if chgname then changefile:=kpseopenfile(chgname,kpsewebformat);end;
171 {:24}{28:}function inputln(var f:textfile):boolean;
172 var finallimit:0..bufsize;begin limit:=0;finallimit:=0;
173 if eof(f)then inputln:=false else begin while not eoln(f)do begin buffer
174 [limit]:=xord[getc(f)];limit:=limit+1;
175 if buffer[limit-1]<>32 then finallimit:=limit;
176 if limit=bufsize then begin while not eoln(f)do vgetc(f);limit:=limit-1;
177 if finallimit>limit then finallimit:=limit;begin writeln(stdout);
178 write(stdout,'! Input line too long');end;loc:=0;error;end;end;
179 readln(f);limit:=finallimit;inputln:=true;end;end;
180 {:28}{49:}procedure printid(p:namepointer);var k:0..maxbytes;w:0..2;
181 begin if p>=nameptr then write(stdout,'IMPOSSIBLE')else begin w:=p mod 3
182 ;
183 for k:=bytestart[p]to bytestart[p+3]-1 do write(stdout,xchr[bytemem[w,k]
184 ]);end;end;{:49}{53:}function idlookup(t:eightbits):namepointer;
185 label 31,32;var c:eightbits;i:0..bufsize;h:0..hashsize;k:0..maxbytes;
186 w:0..2;l:0..bufsize;p,q:namepointer;s:0..maxidlength;
187 begin l:=idloc-idfirst;{54:}h:=buffer[idfirst];i:=idfirst+1;
188 while i<idloc do begin h:=(h+h+buffer[i])mod hashsize;i:=i+1;end{:54};
189 {55:}p:=hash[h];
190 while p<>0 do begin if bytestart[p+3]-bytestart[p]=l then{56:}begin i:=
191 idfirst;k:=bytestart[p];w:=p mod 3;
192 while(i<idloc)and(buffer[i]=bytemem[w,k])do begin i:=i+1;k:=k+1;end;
193 if i=idloc then goto 31;end{:56};p:=link[p];end;p:=nameptr;
194 link[p]:=hash[h];hash[h]:=p;31:{:55};
195 if(p=nameptr)or(t<>0)then{57:}begin if((p<>nameptr)and(t<>0)and(ilk[p]=0
196 ))or((p=nameptr)and(t=0)and(buffer[idfirst]<>34))then{58:}begin i:=
197 idfirst;s:=0;h:=0;
198 while(i<idloc)and(s<unambiglength)do begin if(buffer[i]<>95)or(
199 allowunderlines and not strictmode)then begin if(strictmode or
200 forceuppercase)and(buffer[i]>=97)and(buffer[i]<=122)then choppedid[s]:=
201 buffer[i]-32 else if(not strictmode and forcelowercase)and(buffer[i]>=65
202 )and(buffer[i]<=90)then choppedid[s]:=buffer[i]+32 else choppedid[s]:=
203 buffer[i];h:=(h+h+choppedid[s])mod hashsize;s:=s+1;end;i:=i+1;end;
204 choppedid[s]:=0;end{:58};
205 if p<>nameptr then{59:}begin if ilk[p]=0 then begin if t=1 then begin
206 writeln(stdout);write(stdout,'! This identifier has already appeared');
207 error;end;{60:}q:=chophash[h];
208 if q=p then chophash[h]:=equiv[p]else begin while equiv[q]<>p do q:=
209 equiv[q];equiv[q]:=equiv[p];end{:60};end else begin writeln(stdout);
210 write(stdout,'! This identifier was defined before');error;end;
211 ilk[p]:=t;
212 end{:59}else{61:}begin if(t=0)and(buffer[idfirst]<>34)then{62:}begin q:=
213 chophash[h];while q<>0 do begin{63:}begin k:=bytestart[q];s:=0;
214 w:=q mod 3;
215 while(k<bytestart[q+3])and(s<unambiglength)do begin c:=bytemem[w,k];
216 if c<>95 or(allowunderlines and not strictmode)then begin if(strictmode
217 or forceuppercase)and(c>=97)and(c<=122)then c:=c-32 else if(not
218 strictmode and forcelowercase)and(c>=65)and(c<=90)then c:=c+32;
219 if choppedid[s]<>c then goto 32;s:=s+1;end;k:=k+1;end;
220 if(k=bytestart[q+3])and(choppedid[s]<>0)then goto 32;
221 begin writeln(stdout);write(stdout,'! Identifier conflict with ');end;
222 for k:=bytestart[q]to bytestart[q+3]-1 do write(stdout,xchr[bytemem[w,k]
223 ]);error;q:=0;32:end{:63};q:=equiv[q];end;equiv[p]:=chophash[h];
224 chophash[h]:=p;end{:62};w:=nameptr mod 3;k:=byteptr[w];
225 if k+l>maxbytes then begin writeln(stdout);
226 write(stderr,'! Sorry, ','byte memory',' capacity exceeded');error;
227 history:=3;uexit(1);end;
228 if nameptr>maxnames-3 then begin writeln(stdout);
229 write(stderr,'! Sorry, ','name',' capacity exceeded');error;history:=3;
230 uexit(1);end;i:=idfirst;while i<idloc do begin bytemem[w,k]:=buffer[i];
231 k:=k+1;i:=i+1;end;byteptr[w]:=k;bytestart[nameptr+3]:=k;
232 nameptr:=nameptr+1;
233 if buffer[idfirst]<>34 then ilk[p]:=t else{64:}begin ilk[p]:=1;
234 if l-doublechars=2 then equiv[p]:=buffer[idfirst+1]+1073741824 else
235 begin if stringptr=256 then rewritebin(pool,poolname);
236 equiv[p]:=stringptr+1073741824;l:=l-doublechars-1;
237 if l>99 then begin writeln(stdout);
238 write(stdout,'! Preprocessed string is too long');error;end;
239 stringptr:=stringptr+1;write(pool,xchr[48+l div 10],xchr[48+l mod 10]);
240 poolchecksum:=poolchecksum+poolchecksum+l;
241 while poolchecksum>536870839 do poolchecksum:=poolchecksum-536870839;
242 i:=idfirst+1;while i<idloc do begin write(pool,xchr[buffer[i]]);
243 poolchecksum:=poolchecksum+poolchecksum+buffer[i];
244 while poolchecksum>536870839 do poolchecksum:=poolchecksum-536870839;
245 if(buffer[i]=34)or(buffer[i]=64)then i:=i+2 else i:=i+1;end;
246 writeln(pool);end;end{:64};end{:61};end{:57};idlookup:=p;end;
247 {:53}{66:}function modlookup(l:sixteenbits):namepointer;label 31;
248 var c:0..4;j:0..longestname;k:0..maxbytes;w:0..2;p:namepointer;
249 q:namepointer;begin c:=2;q:=0;p:=ilk[0];
250 while p<>0 do begin{68:}begin k:=bytestart[p];w:=p mod 3;c:=1;j:=1;
251 while(k<bytestart[p+3])and(j<=l)and(modtext[j]=bytemem[w,k])do begin k:=
252 k+1;j:=j+1;end;
253 if k=bytestart[p+3]then if j>l then c:=1 else c:=4 else if j>l then c:=3
254 else if modtext[j]<bytemem[w,k]then c:=0 else c:=2;end{:68};q:=p;
255 if c=0 then p:=link[q]else if c=2 then p:=ilk[q]else goto 31;end;
256 {67:}w:=nameptr mod 3;k:=byteptr[w];
257 if k+l>maxbytes then begin writeln(stdout);
258 write(stderr,'! Sorry, ','byte memory',' capacity exceeded');error;
259 history:=3;uexit(1);end;
260 if nameptr>maxnames-3 then begin writeln(stdout);
261 write(stderr,'! Sorry, ','name',' capacity exceeded');error;history:=3;
262 uexit(1);end;p:=nameptr;if c=0 then link[q]:=p else ilk[q]:=p;
263 link[p]:=0;ilk[p]:=0;c:=1;equiv[p]:=0;
264 for j:=1 to l do bytemem[w,k+j-1]:=modtext[j];byteptr[w]:=k+l;
265 bytestart[nameptr+3]:=k+l;nameptr:=nameptr+1;{:67};
266 31:if c<>1 then begin begin writeln(stdout);
267 write(stdout,'! Incompatible section names');error;end;p:=0;end;
268 modlookup:=p;end;
269 {:66}{69:}function prefixlookup(l:sixteenbits):namepointer;var c:0..4;
270 count:0..maxnames;j:0..longestname;k:0..maxbytes;w:0..2;p:namepointer;
271 q:namepointer;r:namepointer;begin q:=0;p:=ilk[0];count:=0;r:=0;
272 while p<>0 do begin{68:}begin k:=bytestart[p];w:=p mod 3;c:=1;j:=1;
273 while(k<bytestart[p+3])and(j<=l)and(modtext[j]=bytemem[w,k])do begin k:=
274 k+1;j:=j+1;end;
275 if k=bytestart[p+3]then if j>l then c:=1 else c:=4 else if j>l then c:=3
276 else if modtext[j]<bytemem[w,k]then c:=0 else c:=2;end{:68};
277 if c=0 then p:=link[p]else if c=2 then p:=ilk[p]else begin r:=p;
278 count:=count+1;q:=ilk[p];p:=link[p];end;if p=0 then begin p:=q;q:=0;end;
279 end;if count<>1 then if count=0 then begin writeln(stdout);
280 write(stdout,'! Name does not match');error;
281 end else begin writeln(stdout);write(stdout,'! Ambiguous prefix');error;
282 end;prefixlookup:=r;end;
283 {:69}{73:}procedure storetwobytes(x:sixteenbits);
284 begin if tokptr[z]+2>maxtoks then begin writeln(stdout);
285 write(stderr,'! Sorry, ','token',' capacity exceeded');error;history:=3;
286 uexit(1);end;tokmem[z,tokptr[z]]:=x div 256;
287 tokmem[z,tokptr[z]+1]:=x mod 256;tokptr[z]:=tokptr[z]+2;end;
288 {:73}{74:}{procedure printrepl(p:textpointer);var k:0..maxtoks;
289 a:sixteenbits;zp:0..4;
290 begin if p>=textptr then write(stdout,'BAD')else begin k:=tokstart[p];
291 zp:=p mod 5;while k<tokstart[p+5]do begin a:=tokmem[zp,k];
292 if a>=128 then[75:]begin k:=k+1;
293 if a<168 then begin a:=(a-128)*256+tokmem[zp,k];printid(a);
294 if bytemem[a mod 3,bytestart[a]]=34 then write(stdout,'"')else write(
295 stdout,' ');end else if a<208 then begin write(stdout,'@<');
296 printid((a-168)*256+tokmem[zp,k]);write(stdout,'@>');
297 end else begin a:=(a-208)*256+tokmem[zp,k];
298 write(stdout,'@',xchr[123],a:1,'@',xchr[125]);end;
299 end[:75]else[76:]case a of 9:write(stdout,'@',xchr[123]);
300 10:write(stdout,'@',xchr[125]);12:write(stdout,'@''');
301 13:write(stdout,'@"');125:write(stdout,'@$');0:write(stdout,'#');
302 64:write(stdout,'@@');2:write(stdout,'@=');3:write(stdout,'@\');
303 others:write(stdout,xchr[a])end[:76];k:=k+1;end;end;end;}
304 {:74}{84:}procedure pushlevel(p:namepointer);
305 begin if stackptr=stacksize then begin writeln(stdout);
306 write(stderr,'! Sorry, ','stack',' capacity exceeded');error;history:=3;
307 uexit(1);end else begin stack[stackptr]:=curstate;stackptr:=stackptr+1;
308 curstate.namefield:=p;curstate.replfield:=equiv[p];
309 zo:=curstate.replfield mod 5;
310 curstate.bytefield:=tokstart[curstate.replfield];
311 curstate.endfield:=tokstart[curstate.replfield+5];curstate.modfield:=0;
312 end;end;{:84}{85:}procedure poplevel;label 10;
313 begin if textlink[curstate.replfield]=0 then begin if(ilk[curstate.
314 namefield]=3)or(ilk[curstate.namefield]=4)then{91:}begin nameptr:=
315 nameptr-1;textptr:=textptr-1;z:=textptr mod 5;
316 {if tokptr[z]>maxtokptr[z]then maxtokptr[z]:=tokptr[z];}
317 tokptr[z]:=tokstart[textptr];
318 {byteptr[nameptr mod 3]:=byteptr[nameptr mod 3]-1;}end{:91};
319 end else if textlink[curstate.replfield]<maxtexts then begin curstate.
320 replfield:=textlink[curstate.replfield];zo:=curstate.replfield mod 5;
321 curstate.bytefield:=tokstart[curstate.replfield];
322 curstate.endfield:=tokstart[curstate.replfield+5];goto 10;end;
323 stackptr:=stackptr-1;if stackptr>0 then begin curstate:=stack[stackptr];
324 zo:=curstate.replfield mod 5;end;10:end;
325 {:85}{87:}function getoutput:sixteenbits;label 20,30,31;
326 var a:sixteenbits;b:eightbits;bal:sixteenbits;k:0..maxbytes;w:0..2;
327 begin 20:if stackptr=0 then begin a:=0;goto 31;end;
328 if curstate.bytefield=curstate.endfield then begin curval:=-curstate.
329 modfield;poplevel;if curval=0 then goto 20;a:=129;goto 31;end;
330 a:=tokmem[zo,curstate.bytefield];
331 curstate.bytefield:=curstate.bytefield+1;
332 if a<128 then if a=0 then{92:}begin pushlevel(nameptr-1);goto 20;
333 end{:92}else goto 31;a:=(a-128)*256+tokmem[zo,curstate.bytefield];
334 curstate.bytefield:=curstate.bytefield+1;
335 if a<10240 then{89:}begin case ilk[a]of 0:begin curval:=a;a:=130;end;
336 1:begin curval:=equiv[a]-1073741824;a:=128;end;2:begin pushlevel(a);
337 goto 20;end;
338 3,4:begin{90:}while(curstate.bytefield=curstate.endfield)and(stackptr>0)
339 do poplevel;
340 if(stackptr=0)or((ilk[a]=3)and(tokmem[zo,curstate.bytefield]<>40))or((
341 ilk[a]=4)and(tokmem[zo,curstate.bytefield]<>91))then begin begin writeln
342 (stdout);write(stdout,'! No parameter given for ');end;printid(a);error;
343 goto 20;end;{93:}bal:=1;curstate.bytefield:=curstate.bytefield+1;
344 while true do begin b:=tokmem[zo,curstate.bytefield];
345 curstate.bytefield:=curstate.bytefield+1;
346 if b=0 then storetwobytes(nameptr+32767)else begin if b>=128 then begin
347 begin if tokptr[z]=maxtoks then begin writeln(stdout);
348 write(stderr,'! Sorry, ','token',' capacity exceeded');error;history:=3;
349 uexit(1);end;tokmem[z,tokptr[z]]:=b;tokptr[z]:=tokptr[z]+1;end;
350 b:=tokmem[zo,curstate.bytefield];
351 curstate.bytefield:=curstate.bytefield+1;
352 end else case b of 40:if ilk[a]=3 then bal:=bal+1;
353 41:if ilk[a]=3 then begin bal:=bal-1;if bal=0 then goto 30;end;
354 91:if ilk[a]=4 then bal:=bal+1;93:if ilk[a]=4 then begin bal:=bal-1;
355 if bal=0 then goto 30;end;
356 39:repeat begin if tokptr[z]=maxtoks then begin writeln(stdout);
357 write(stderr,'! Sorry, ','token',' capacity exceeded');error;history:=3;
358 uexit(1);end;tokmem[z,tokptr[z]]:=b;tokptr[z]:=tokptr[z]+1;end;
359 b:=tokmem[zo,curstate.bytefield];
360 curstate.bytefield:=curstate.bytefield+1;until b=39;others:end;
361 begin if tokptr[z]=maxtoks then begin writeln(stdout);
362 write(stderr,'! Sorry, ','token',' capacity exceeded');error;history:=3;
363 uexit(1);end;tokmem[z,tokptr[z]]:=b;tokptr[z]:=tokptr[z]+1;end;end;end;
364 30:{:93};equiv[nameptr]:=textptr;ilk[nameptr]:=2;w:=nameptr mod 3;
365 k:=byteptr[w];{if k=maxbytes then begin writeln(stdout);
366 write(stderr,'! Sorry, ','byte memory',' capacity exceeded');error;
367 history:=3;uexit(1);end;bytemem[w,k]:=35;k:=k+1;byteptr[w]:=k;}
368 if nameptr>maxnames-3 then begin writeln(stdout);
369 write(stderr,'! Sorry, ','name',' capacity exceeded');error;history:=3;
370 uexit(1);end;bytestart[nameptr+3]:=k;nameptr:=nameptr+1;
371 if textptr>maxtexts-5 then begin writeln(stdout);
372 write(stderr,'! Sorry, ','text',' capacity exceeded');error;history:=3;
373 uexit(1);end;textlink[textptr]:=0;tokstart[textptr+5]:=tokptr[z];
374 textptr:=textptr+1;z:=textptr mod 5{:90};pushlevel(a);goto 20;end;
375 others:begin writeln(stdout);
376 write(stderr,'! This can''t happen (','output',')');error;history:=3;
377 uexit(1);end end;goto 31;end{:89};if a<20480 then{88:}begin a:=a-10240;
378 if equiv[a]<>0 then pushlevel(a)else if a<>0 then begin begin writeln(
379 stdout);write(stdout,'! Not present: <');end;printid(a);
380 write(stdout,'>');error;end;goto 20;end{:88};curval:=a-20480;a:=129;
381 curstate.modfield:=curval;31:{if troubleshooting then debughelp;}
382 getoutput:=a;end;{:87}{97:}procedure flushbuffer;var k:0..outbufsize;
383 b:0..outbufsize;begin b:=breakptr;
384 if(semiptr<>0)and(outptr-semiptr<=linelength)then breakptr:=semiptr;
385 for k:=1 to breakptr do write(Pascalfile,xchr[outbuf[k-1]]);
386 writeln(Pascalfile);line:=line+1;
387 if line mod 100=0 then begin write(stdout,'.');
388 if line mod 500=0 then write(stdout,line:1);fflush(stdout);end;
389 if breakptr<outptr then begin if outbuf[breakptr]=32 then begin breakptr
390 :=breakptr+1;if breakptr>b then b:=breakptr;end;
391 for k:=breakptr to outptr-1 do outbuf[k-breakptr]:=outbuf[k];end;
392 outptr:=outptr-breakptr;breakptr:=b-breakptr;semiptr:=0;
393 if outptr>linelength then begin begin writeln(stdout);
394 write(stdout,'! Long line must be truncated');error;end;
395 outptr:=linelength;end;end;{:97}{99:}procedure appval(v:integer);
396 var k:0..outbufsize;begin k:=outbufsize;repeat outbuf[k]:=v mod 10;
397 v:=v div 10;k:=k-1;until v=0;repeat k:=k+1;
398 begin outbuf[outptr]:=outbuf[k]+48;outptr:=outptr+1;end;
399 until k=outbufsize;end;{:99}{101:}procedure sendout(t:eightbits;
400 v:sixteenbits);label 20;var k:0..linelength;
401 begin{102:}20:case outstate of 1:if t<>3 then begin breakptr:=outptr;
402 if t=2 then begin outbuf[outptr]:=32;outptr:=outptr+1;end;end;
403 2:begin begin outbuf[outptr]:=44-outapp;outptr:=outptr+1;end;
404 if outptr>linelength then flushbuffer;breakptr:=outptr;end;
405 3,4:begin{103:}if(outval<0)or((outval=0)and(lastsign<0))then begin
406 outbuf[outptr]:=45;outptr:=outptr+1;
407 end else if outsign>0 then begin outbuf[outptr]:=outsign;
408 outptr:=outptr+1;end;appval(abs(outval));
409 if outptr>linelength then flushbuffer;{:103};outstate:=outstate-2;
410 goto 20;end;
411 5:{104:}begin if(t=3)or({105:}((t=2)and(v=3)and(((outcontrib[1]=68)and(
412 outcontrib[2]=73)and(outcontrib[3]=86))or((outcontrib[1]=100)and(
413 outcontrib[2]=105)and(outcontrib[3]=118))or((outcontrib[1]=77)and(
414 outcontrib[2]=79)and(outcontrib[3]=68))or((outcontrib[1]=109)and(
415 outcontrib[2]=111)and(outcontrib[3]=100))))or((t=0)and((v=42)or(v=47)))
416 {:105})then begin{103:}if(outval<0)or((outval=0)and(lastsign<0))then
417 begin outbuf[outptr]:=45;outptr:=outptr+1;
418 end else if outsign>0 then begin outbuf[outptr]:=outsign;
419 outptr:=outptr+1;end;appval(abs(outval));
420 if outptr>linelength then flushbuffer;{:103};outsign:=43;outval:=outapp;
421 end else outval:=outval+outapp;outstate:=3;goto 20;end{:104};
422 0:if t<>3 then breakptr:=outptr;others:end{:102};
423 if t<>0 then for k:=1 to v do begin outbuf[outptr]:=outcontrib[k];
424 outptr:=outptr+1;end else begin outbuf[outptr]:=v;outptr:=outptr+1;end;
425 if outptr>linelength then flushbuffer;
426 if(t=0)and((v=59)or(v=125))then begin semiptr:=outptr;breakptr:=outptr;
427 end;if t>=2 then outstate:=1 else outstate:=0 end;
428 {:101}{106:}procedure sendsign(v:integer);
429 begin case outstate of 2,4:outapp:=outapp*v;3:begin outapp:=v;
430 outstate:=4;end;5:begin outval:=outval+outapp;outapp:=v;outstate:=4;end;
431 others:begin breakptr:=outptr;outapp:=v;outstate:=2;end end;
432 lastsign:=outapp;end;{:106}{107:}procedure sendval(v:integer);
433 label 666,10;
434 begin case outstate of 1:begin{110:}if(outptr=breakptr+3)or((outptr=
435 breakptr+4)and(outbuf[breakptr]=32))then if((outbuf[outptr-3]=68)and(
436 outbuf[outptr-2]=73)and(outbuf[outptr-1]=86))or((outbuf[outptr-3]=100)
437 and(outbuf[outptr-2]=105)and(outbuf[outptr-1]=118))or((outbuf[outptr-3]=
438 77)and(outbuf[outptr-2]=79)and(outbuf[outptr-1]=68))or((outbuf[outptr-3]
439 =109)and(outbuf[outptr-2]=111)and(outbuf[outptr-1]=100))then goto 666
440 {:110};outsign:=32;outstate:=3;outval:=v;breakptr:=outptr;lastsign:=+1;
441 end;
442 0:begin{109:}if(outptr=breakptr+1)and((outbuf[breakptr]=42)or(outbuf[
443 breakptr]=47))then goto 666{:109};outsign:=0;outstate:=3;outval:=v;
444 breakptr:=outptr;lastsign:=+1;end;{108:}2:begin outsign:=43;outstate:=3;
445 outval:=outapp*v;end;3:begin outstate:=5;outapp:=v;
446 begin writeln(stdout);
447 write(stdout,'! Two numbers occurred without a sign between them');
448 error;end;end;4:begin outstate:=5;outapp:=outapp*v;end;
449 5:begin outval:=outval+outapp;outapp:=v;begin writeln(stdout);
450 write(stdout,'! Two numbers occurred without a sign between them');
451 error;end;end;{:108}others:goto 666 end;goto 10;
452 666:{111:}if v>=0 then begin if outstate=1 then begin breakptr:=outptr;
453 begin outbuf[outptr]:=32;outptr:=outptr+1;end;end;appval(v);
454 if outptr>linelength then flushbuffer;outstate:=1;
455 end else begin begin outbuf[outptr]:=40;outptr:=outptr+1;end;
456 begin outbuf[outptr]:=45;outptr:=outptr+1;end;appval(-v);
457 begin outbuf[outptr]:=41;outptr:=outptr+1;end;
458 if outptr>linelength then flushbuffer;outstate:=0;end{:111};10:end;
459 {:107}{113:}procedure sendtheoutput;label 2,21,22;var curchar:eightbits;
460 k:0..linelength;j:0..maxbytes;w:0..2;n:integer;
461 begin while stackptr>0 do begin curchar:=getoutput;
462 21:case curchar of 0:;
463 {116:}65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,
464 87,88,89,90:begin if forcelowercase then outcontrib[1]:=curchar+32 else
465 outcontrib[1]:=curchar;sendout(2,1);end;
466 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115
467 ,116,117,118,119,120,121,122:begin if forceuppercase then outcontrib[1]
468 :=curchar-32 else outcontrib[1]:=curchar;sendout(2,1);end;
469 130:begin k:=0;j:=bytestart[curval];w:=curval mod 3;
470 while(k<maxidlength)and(j<bytestart[curval+3])do begin k:=k+1;
471 outcontrib[k]:=bytemem[w,j];j:=j+1;
472 if forceuppercase and(outcontrib[k]>=97)and(outcontrib[k]<=122)then
473 outcontrib[k]:=outcontrib[k]-32 else if forcelowercase and(outcontrib[k]
474 >=65)and(outcontrib[k]<=90)then outcontrib[k]:=outcontrib[k]+32 else if
475 not allowunderlines and(outcontrib[k]=95)then k:=k-1;end;sendout(2,k);
476 end;{:116}{119:}48,49,50,51,52,53,54,55,56,57:begin n:=0;
477 repeat curchar:=curchar-48;if n>=214748364 then begin writeln(stdout);
478 write(stdout,'! Constant too big');error;end else n:=10*n+curchar;
479 curchar:=getoutput;until(curchar>57)or(curchar<48);sendval(n);k:=0;
480 if curchar=101 then curchar:=69;if curchar=69 then goto 2 else goto 21;
481 end;125:sendval(poolchecksum);12:begin n:=0;curchar:=48;
482 repeat curchar:=curchar-48;if n>=268435456 then begin writeln(stdout);
483 write(stdout,'! Constant too big');error;end else n:=8*n+curchar;
484 curchar:=getoutput;until(curchar>55)or(curchar<48);sendval(n);goto 21;
485 end;13:begin n:=0;curchar:=48;
486 repeat if curchar>=65 then curchar:=curchar-55 else curchar:=curchar-48;
487 if n>=134217728 then begin writeln(stdout);
488 write(stdout,'! Constant too big');error;end else n:=16*n+curchar;
489 curchar:=getoutput;
490 until(curchar>70)or(curchar<48)or((curchar>57)and(curchar<65));
491 sendval(n);goto 21;end;128:sendval(curval);46:begin k:=1;
492 outcontrib[1]:=46;curchar:=getoutput;
493 if curchar=46 then begin outcontrib[2]:=46;sendout(1,2);
494 end else if(curchar>=48)and(curchar<=57)then goto 2 else begin sendout(0
495 ,46);goto 21;end;end;{:119}43,45:sendsign(44-curchar);
496 {114:}4:begin outcontrib[1]:=97;outcontrib[2]:=110;outcontrib[3]:=100;
497 sendout(2,3);end;5:begin outcontrib[1]:=110;outcontrib[2]:=111;
498 outcontrib[3]:=116;sendout(2,3);end;6:begin outcontrib[1]:=105;
499 outcontrib[2]:=110;sendout(2,2);end;31:begin outcontrib[1]:=111;
500 outcontrib[2]:=114;sendout(2,2);end;24:begin outcontrib[1]:=58;
501 outcontrib[2]:=61;sendout(1,2);end;26:begin outcontrib[1]:=60;
502 outcontrib[2]:=62;sendout(1,2);end;28:begin outcontrib[1]:=60;
503 outcontrib[2]:=61;sendout(1,2);end;29:begin outcontrib[1]:=62;
504 outcontrib[2]:=61;sendout(1,2);end;30:begin outcontrib[1]:=61;
505 outcontrib[2]:=61;sendout(1,2);end;32:begin outcontrib[1]:=46;
506 outcontrib[2]:=46;sendout(1,2);end;{:114}39:{117:}begin k:=1;
507 outcontrib[1]:=39;repeat if k<linelength then k:=k+1;
508 outcontrib[k]:=getoutput;until(outcontrib[k]=39)or(stackptr=0);
509 if k=linelength then begin writeln(stdout);
510 write(stdout,'! String too long');error;end;sendout(1,k);
511 curchar:=getoutput;if curchar=39 then outstate:=6;goto 21;end{:117};
512 {115:}33,34,35,36,37,38,40,41,42,44,47,58,59,60,61,62,63,64,91,92,93,94,
513 95,96,123,124{:115}:sendout(0,curchar);
514 {121:}9:begin if bracelevel=0 then sendout(0,123)else sendout(0,91);
515 bracelevel:=bracelevel+1;end;
516 10:if bracelevel>0 then begin bracelevel:=bracelevel-1;
517 if bracelevel=0 then sendout(0,125)else sendout(0,93);
518 end else begin writeln(stdout);write(stdout,'! Extra @}');error;end;
519 129:begin k:=2;
520 if bracelevel=0 then outcontrib[1]:=123 else outcontrib[1]:=91;
521 if curval<0 then begin outcontrib[k]:=58;curval:=-curval;k:=k+1;end;
522 n:=10;while curval>=n do n:=10*n;repeat n:=n div 10;
523 outcontrib[k]:=48+(curval div n);curval:=curval mod n;k:=k+1;until n=1;
524 if outcontrib[2]<>58 then begin outcontrib[k]:=58;k:=k+1;end;
525 if bracelevel=0 then outcontrib[k]:=125 else outcontrib[k]:=93;
526 sendout(1,k);end;{:121}127:begin sendout(3,0);outstate:=6;end;
527 2:{118:}begin k:=0;repeat if k<linelength then k:=k+1;
528 outcontrib[k]:=getoutput;until(outcontrib[k]=2)or(stackptr=0);
529 if k=linelength then begin writeln(stdout);
530 write(stdout,'! Verbatim string too long');error;end;sendout(1,k-1);
531 end{:118};3:{122:}begin sendout(1,0);
532 while outptr>0 do begin if outptr<=linelength then breakptr:=outptr;
533 flushbuffer;end;outstate:=0;end{:122};others:begin writeln(stdout);
534 write(stdout,'! Can''t output ASCII code ',curchar:1);error;end end;
535 goto 22;2:{120:}repeat if k<linelength then k:=k+1;
536 outcontrib[k]:=curchar;curchar:=getoutput;
537 if(outcontrib[k]=69)and((curchar=43)or(curchar=45))then begin if k<
538 linelength then k:=k+1;outcontrib[k]:=curchar;curchar:=getoutput;
539 end else if curchar=101 then curchar:=69;
540 until(curchar<>69)and((curchar<48)or(curchar>57));
541 if k=linelength then begin writeln(stdout);
542 write(stdout,'! Fraction too long');error;end;sendout(3,k);
543 goto 21{:120};22:end;end;{:113}{127:}function linesdontmatch:boolean;
544 label 10;var k:0..bufsize;begin linesdontmatch:=true;
545 if changelimit<>limit then goto 10;
546 if limit>0 then for k:=0 to limit-1 do if changebuffer[k]<>buffer[k]then
547 goto 10;linesdontmatch:=false;10:end;
548 {:127}{128:}procedure primethechangebuffer;label 22,30,10;
549 var k:0..bufsize;begin changelimit:=0;
550 {129:}while true do begin line:=line+1;
551 if not inputln(changefile)then goto 10;if limit<2 then goto 22;
552 if buffer[0]<>64 then goto 22;
553 if(buffer[1]>=88)and(buffer[1]<=90)then buffer[1]:=buffer[1]+32;
554 if buffer[1]=120 then goto 30;
555 if(buffer[1]=121)or(buffer[1]=122)then begin loc:=2;
556 begin writeln(stdout);write(stdout,'! Where is the matching @x?');error;
557 end;end;22:end;30:{:129};{130:}repeat line:=line+1;
558 if not inputln(changefile)then begin begin writeln(stdout);
559 write(stdout,'! Change file ended after @x');error;end;goto 10;end;
560 until limit>0;{:130};{131:}begin changelimit:=limit;
561 if limit>0 then for k:=0 to limit-1 do changebuffer[k]:=buffer[k];
562 end{:131};10:end;{:128}{132:}procedure checkchange;label 10;
563 var n:integer;k:0..bufsize;begin if linesdontmatch then goto 10;n:=0;
564 while true do begin changing:=not changing;templine:=otherline;
565 otherline:=line;line:=templine;line:=line+1;
566 if not inputln(changefile)then begin begin writeln(stdout);
567 write(stdout,'! Change file ended before @y');error;end;changelimit:=0;
568 changing:=not changing;templine:=otherline;otherline:=line;
569 line:=templine;goto 10;end;
570 {133:}if limit>1 then if buffer[0]=64 then begin if(buffer[1]>=88)and(
571 buffer[1]<=90)then buffer[1]:=buffer[1]+32;
572 if(buffer[1]=120)or(buffer[1]=122)then begin loc:=2;
573 begin writeln(stdout);write(stdout,'! Where is the matching @y?');error;
574 end;end else if buffer[1]=121 then begin if n>0 then begin loc:=2;
575 begin writeln(stdout);
576 write(stdout,'! Hmm... ',n:1,' of the preceding lines failed to match');
577 error;end;end;goto 10;end;end{:133};{131:}begin changelimit:=limit;
578 if limit>0 then for k:=0 to limit-1 do changebuffer[k]:=buffer[k];
579 end{:131};changing:=not changing;templine:=otherline;otherline:=line;
580 line:=templine;line:=line+1;
581 if not inputln(webfile)then begin begin writeln(stdout);
582 write(stdout,'! WEB file ended during a change');error;end;
583 inputhasended:=true;goto 10;end;if linesdontmatch then n:=n+1;end;
584 10:end;{:132}{135:}procedure getline;label 20;
585 begin 20:if changing then{137:}begin line:=line+1;
586 if not inputln(changefile)then begin begin writeln(stdout);
587 write(stdout,'! Change file ended without @z');error;end;buffer[0]:=64;
588 buffer[1]:=122;limit:=2;end;
589 if limit>1 then if buffer[0]=64 then begin if(buffer[1]>=88)and(buffer[1
590 ]<=90)then buffer[1]:=buffer[1]+32;
591 if(buffer[1]=120)or(buffer[1]=121)then begin loc:=2;
592 begin writeln(stdout);write(stdout,'! Where is the matching @z?');error;
593 end;end else if buffer[1]=122 then begin primethechangebuffer;
594 changing:=not changing;templine:=otherline;otherline:=line;
595 line:=templine;end;end;end{:137};
596 if not changing then begin{136:}begin line:=line+1;
597 if not inputln(webfile)then inputhasended:=true else if changelimit>0
598 then checkchange;end{:136};if changing then goto 20;end;loc:=0;
599 buffer[limit]:=32;end;
600 {:135}{139:}function controlcode(c:ASCIIcode):eightbits;
601 begin case c of 64:controlcode:=64;39:controlcode:=12;
602 34:controlcode:=13;36:controlcode:=125;32,9:controlcode:=136;
603 42:begin write(stdout,'*',modulecount+1:1);fflush(stdout);
604 controlcode:=136;end;68,100:controlcode:=133;70,102:controlcode:=132;
605 123:controlcode:=9;125:controlcode:=10;80,112:controlcode:=134;
606 84,116,94,46,58:controlcode:=131;38:controlcode:=127;
607 60:controlcode:=135;61:controlcode:=2;92:controlcode:=3;
608 others:controlcode:=0 end;end;{:139}{140:}function skipahead:eightbits;
609 label 30;var c:eightbits;
610 begin while true do begin if loc>limit then begin getline;
611 if inputhasended then begin c:=136;goto 30;end;end;buffer[limit+1]:=64;
612 while buffer[loc]<>64 do loc:=loc+1;if loc<=limit then begin loc:=loc+2;
613 c:=controlcode(buffer[loc-1]);if(c<>0)or(buffer[loc-1]=62)then goto 30;
614 end;end;30:skipahead:=c;end;{:140}{141:}procedure skipcomment;label 10;
615 var bal:eightbits;c:ASCIIcode;begin bal:=0;
616 while true do begin if loc>limit then begin getline;
617 if inputhasended then begin begin writeln(stdout);
618 write(stdout,'! Input ended in mid-comment');error;end;goto 10;end;end;
619 c:=buffer[loc];loc:=loc+1;{142:}if c=64 then begin c:=buffer[loc];
620 if(c<>32)and(c<>9)and(c<>42)then loc:=loc+1 else begin begin writeln(
621 stdout);write(stdout,'! Section ended in mid-comment');error;end;
622 loc:=loc-1;goto 10;
623 end end else if(c=92)and(buffer[loc]<>64)then loc:=loc+1 else if c=123
624 then bal:=bal+1 else if c=125 then begin if bal=0 then goto 10;
625 bal:=bal-1;end{:142};end;10:end;{:141}{145:}function getnext:eightbits;
626 label 20,30,31;var c:eightbits;d:eightbits;j,k:0..longestname;
627 begin 20:if loc>limit then begin getline;
628 if inputhasended then begin c:=136;goto 31;end;end;c:=buffer[loc];
629 loc:=loc+1;
630 if scanninghex then{146:}if((c>=48)and(c<=57))or((c>=65)and(c<=70))then
631 goto 31 else scanninghex:=false{:146};
632 case c of 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85
633 ,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111
634 ,112,113,114,115,116,117,118,119,120,121,122:{148:}begin if((c=101)or(c=
635 69))and(loc>1)then if(buffer[loc-2]<=57)and(buffer[loc-2]>=48)then c:=0;
636 if c<>0 then begin loc:=loc-1;idfirst:=loc;repeat loc:=loc+1;
637 d:=buffer[loc];
638 until((d<48)or((d>57)and(d<65))or((d>90)and(d<97))or(d>122))and(d<>95);
639 if loc>idfirst+1 then begin c:=130;idloc:=loc;end;end else c:=69;
640 end{:148};34:{149:}begin doublechars:=0;idfirst:=loc-1;
641 repeat d:=buffer[loc];loc:=loc+1;
642 if(d=34)or(d=64)then if buffer[loc]=d then begin loc:=loc+1;d:=0;
643 doublechars:=doublechars+1;
644 end else begin if d=64 then begin writeln(stdout);
645 write(stdout,'! Double @ sign missing');error;
646 end end else if loc>limit then begin begin writeln(stdout);
647 write(stdout,'! String constant didn''t end');error;end;d:=34;end;
648 until d=34;idloc:=loc-1;c:=130;end{:149};
649 64:{150:}begin c:=controlcode(buffer[loc]);loc:=loc+1;
650 if c=0 then goto 20 else if c=13 then scanninghex:=true else if c=135
651 then{151:}begin{153:}k:=0;
652 while true do begin if loc>limit then begin getline;
653 if inputhasended then begin begin writeln(stdout);
654 write(stdout,'! Input ended in section name');error;end;goto 30;end;end;
655 d:=buffer[loc];{154:}if d=64 then begin d:=buffer[loc+1];
656 if d=62 then begin loc:=loc+2;goto 30;end;
657 if(d=32)or(d=9)or(d=42)then begin begin writeln(stdout);
658 write(stdout,'! Section name didn''t end');error;end;goto 30;end;k:=k+1;
659 modtext[k]:=64;loc:=loc+1;end{:154};loc:=loc+1;
660 if k<longestname-1 then k:=k+1;if(d=32)or(d=9)then begin d:=32;
661 if modtext[k-1]=32 then k:=k-1;end;modtext[k]:=d;end;
662 30:{155:}if k>=longestname-2 then begin begin writeln(stdout);
663 write(stdout,'! Section name too long: ');end;
664 for j:=1 to 25 do write(stdout,xchr[modtext[j]]);write(stdout,'...');
665 if history=0 then history:=1;end{:155};
666 if(modtext[k]=32)and(k>0)then k:=k-1;{:153};
667 if k>3 then begin if(modtext[k]=46)and(modtext[k-1]=46)and(modtext[k-2]=
668 46)then curmodule:=prefixlookup(k-3)else curmodule:=modlookup(k);
669 end else curmodule:=modlookup(k);
670 end{:151}else if c=131 then begin repeat c:=skipahead;until c<>64;
671 if buffer[loc-1]<>62 then begin writeln(stdout);
672 write(stdout,'! Improper @ within control text');error;end;goto 20;end;
673 end{:150};
674 {147:}46:if buffer[loc]=46 then begin if loc<=limit then begin c:=32;
675 loc:=loc+1;end;
676 end else if buffer[loc]=41 then begin if loc<=limit then begin c:=93;
677 loc:=loc+1;end;end;
678 58:if buffer[loc]=61 then begin if loc<=limit then begin c:=24;
679 loc:=loc+1;end;end;
680 61:if buffer[loc]=61 then begin if loc<=limit then begin c:=30;
681 loc:=loc+1;end;end;
682 62:if buffer[loc]=61 then begin if loc<=limit then begin c:=29;
683 loc:=loc+1;end;end;
684 60:if buffer[loc]=61 then begin if loc<=limit then begin c:=28;
685 loc:=loc+1;end;
686 end else if buffer[loc]=62 then begin if loc<=limit then begin c:=26;
687 loc:=loc+1;end;end;
688 40:if buffer[loc]=42 then begin if loc<=limit then begin c:=9;
689 loc:=loc+1;end;
690 end else if buffer[loc]=46 then begin if loc<=limit then begin c:=91;
691 loc:=loc+1;end;end;
692 42:if buffer[loc]=41 then begin if loc<=limit then begin c:=10;
693 loc:=loc+1;end;end;{:147}32,9:goto 20;123:begin skipcomment;goto 20;end;
694 125:begin begin writeln(stdout);write(stdout,'! Extra }');error;end;
695 goto 20;end;others:if c>=128 then goto 20 else end;
696 31:{if troubleshooting then debughelp;}getnext:=c;end;
697 {:145}{157:}procedure scannumeric(p:namepointer);label 21,30;
698 var accumulator:integer;nextsign:-1..+1;q:namepointer;val:integer;
699 begin{158:}accumulator:=0;nextsign:=+1;
700 while true do begin nextcontrol:=getnext;
701 21:case nextcontrol of 48,49,50,51,52,53,54,55,56,57:begin{160:}val:=0;
702 repeat if val>=214748364 then begin writeln(stdout);
703 write(stdout,'! Constant too big');error;
704 end else val:=10*val+nextcontrol-48;nextcontrol:=getnext;
705 until(nextcontrol>57)or(nextcontrol<48){:160};
706 begin accumulator:=accumulator+nextsign*(val);nextsign:=+1;end;goto 21;
707 end;12:begin{161:}val:=0;nextcontrol:=48;
708 repeat if val>=268435456 then begin writeln(stdout);
709 write(stdout,'! Constant too big');error;
710 end else val:=8*val+nextcontrol-48;nextcontrol:=getnext;
711 until(nextcontrol>55)or(nextcontrol<48){:161};
712 begin accumulator:=accumulator+nextsign*(val);nextsign:=+1;end;goto 21;
713 end;13:begin{162:}val:=0;nextcontrol:=48;
714 repeat if nextcontrol>=65 then nextcontrol:=nextcontrol-7;
715 if val>=134217728 then begin writeln(stdout);
716 write(stdout,'! Constant too big');error;
717 end else val:=16*val+nextcontrol-48;nextcontrol:=getnext;
718 until(nextcontrol>70)or(nextcontrol<48)or((nextcontrol>57)and(
719 nextcontrol<65)){:162};begin accumulator:=accumulator+nextsign*(val);
720 nextsign:=+1;end;goto 21;end;130:begin q:=idlookup(0);
721 if ilk[q]<>1 then begin nextcontrol:=42;goto 21;end;
722 begin accumulator:=accumulator+nextsign*(equiv[q]-1073741824);
723 nextsign:=+1;end;end;43:;45:nextsign:=-nextsign;
724 132,133,135,134,136:goto 30;59:begin writeln(stdout);
725 write(stdout,'! Omit semicolon in numeric definition');error;end;
726 others:{159:}begin begin writeln(stdout);
727 write(stdout,'! Improper numeric definition will be flushed');error;end;
728 repeat nextcontrol:=skipahead until(nextcontrol>=132);
729 if nextcontrol=135 then begin loc:=loc-2;nextcontrol:=getnext;end;
730 accumulator:=0;goto 30;end{:159}end;end;30:{:158};
731 if abs(accumulator)>=1073741824 then begin begin writeln(stdout);
732 write(stdout,'! Value too big: ',accumulator:1);error;end;
733 accumulator:=0;end;equiv[p]:=accumulator+1073741824;end;
734 {:157}{165:}procedure scanrepl(t:eightbits);label 22,30,31,21;
735 var a:sixteenbits;b:ASCIIcode;bal:eightbits;begin bal:=0;
736 while true do begin 22:a:=getnext;case a of 40:if t=3 then bal:=bal+1;
737 41:if t=3 then if bal=0 then begin writeln(stdout);
738 write(stdout,'! Extra )');error;end else bal:=bal-1;
739 91:if t=4 then bal:=bal+1;
740 93:if t=4 then if bal=0 then begin writeln(stdout);
741 write(stdout,'! Extra ]');error;end else bal:=bal-1;
742 39:{168:}begin b:=39;
743 while true do begin begin if tokptr[z]=maxtoks then begin writeln(stdout
744 );write(stderr,'! Sorry, ','token',' capacity exceeded');error;
745 history:=3;uexit(1);end;tokmem[z,tokptr[z]]:=b;tokptr[z]:=tokptr[z]+1;
746 end;
747 if b=64 then if buffer[loc]=64 then loc:=loc+1 else begin writeln(stdout
748 );write(stdout,'! You should double @ signs in strings');error;end;
749 if loc=limit then begin begin writeln(stdout);
750 write(stdout,'! String didn''t end');error;end;buffer[loc]:=39;
751 buffer[loc+1]:=0;end;b:=buffer[loc];loc:=loc+1;
752 if b=39 then begin if buffer[loc]<>39 then goto 31 else begin loc:=loc+1
753 ;begin if tokptr[z]=maxtoks then begin writeln(stdout);
754 write(stderr,'! Sorry, ','token',' capacity exceeded');error;history:=3;
755 uexit(1);end;tokmem[z,tokptr[z]]:=39;tokptr[z]:=tokptr[z]+1;end;end;end;
756 end;31:end{:168};35:if(t=3)or(t=4)then a:=0;
757 {167:}130:begin a:=idlookup(0);
758 begin if tokptr[z]=maxtoks then begin writeln(stdout);
759 write(stderr,'! Sorry, ','token',' capacity exceeded');error;history:=3;
760 uexit(1);end;tokmem[z,tokptr[z]]:=(a div 256)+128;
761 tokptr[z]:=tokptr[z]+1;end;a:=a mod 256;end;
762 135:if t<>135 then goto 30 else begin begin if tokptr[z]=maxtoks then
763 begin writeln(stdout);
764 write(stderr,'! Sorry, ','token',' capacity exceeded');error;history:=3;
765 uexit(1);end;tokmem[z,tokptr[z]]:=(curmodule div 256)+168;
766 tokptr[z]:=tokptr[z]+1;end;a:=curmodule mod 256;end;
767 2:{169:}begin begin if tokptr[z]=maxtoks then begin writeln(stdout);
768 write(stderr,'! Sorry, ','token',' capacity exceeded');error;history:=3;
769 uexit(1);end;tokmem[z,tokptr[z]]:=2;tokptr[z]:=tokptr[z]+1;end;
770 buffer[limit+1]:=64;
771 21:if buffer[loc]=64 then begin if loc<limit then if buffer[loc+1]=64
772 then begin begin if tokptr[z]=maxtoks then begin writeln(stdout);
773 write(stderr,'! Sorry, ','token',' capacity exceeded');error;history:=3;
774 uexit(1);end;tokmem[z,tokptr[z]]:=64;tokptr[z]:=tokptr[z]+1;end;
775 loc:=loc+2;goto 21;end;
776 end else begin begin if tokptr[z]=maxtoks then begin writeln(stdout);
777 write(stderr,'! Sorry, ','token',' capacity exceeded');error;history:=3;
778 uexit(1);end;tokmem[z,tokptr[z]]:=buffer[loc];tokptr[z]:=tokptr[z]+1;
779 end;loc:=loc+1;goto 21;end;if loc>=limit then begin writeln(stdout);
780 write(stdout,'! Verbatim string didn''t end');error;
781 end else if buffer[loc+1]<>62 then begin writeln(stdout);
782 write(stdout,'! You should double @ signs in verbatim strings');error;
783 end;loc:=loc+2;end{:169};
784 133,132,134:if t<>135 then goto 30 else begin begin writeln(stdout);
785 write(stdout,'! @',xchr[buffer[loc-1]],' is ignored in Pascal text');
786 error;end;goto 22;end;136:goto 30;{:167}others:end;
787 begin if tokptr[z]=maxtoks then begin writeln(stdout);
788 write(stderr,'! Sorry, ','token',' capacity exceeded');error;history:=3;
789 uexit(1);end;tokmem[z,tokptr[z]]:=a;tokptr[z]:=tokptr[z]+1;end;end;
790 30:nextcontrol:=a;
791 {166:}if bal>0 then if t=3 then begin if bal=1 then begin writeln(stdout
792 );write(stdout,'! Missing )');error;end else begin writeln(stdout);
793 write(stdout,'! Missing ',bal:1,' )''s');error;end;
794 while bal>0 do begin begin if tokptr[z]=maxtoks then begin writeln(
795 stdout);write(stderr,'! Sorry, ','token',' capacity exceeded');error;
796 history:=3;uexit(1);end;tokmem[z,tokptr[z]]:=41;tokptr[z]:=tokptr[z]+1;
797 end;bal:=bal-1;end;end else begin if bal=1 then begin writeln(stdout);
798 write(stdout,'! Missing ]');error;end else begin writeln(stdout);
799 write(stdout,'! Missing ',bal:1,' ]''s');error;end;
800 while bal>0 do begin begin if tokptr[z]=maxtoks then begin writeln(
801 stdout);write(stderr,'! Sorry, ','token',' capacity exceeded');error;
802 history:=3;uexit(1);end;tokmem[z,tokptr[z]]:=93;tokptr[z]:=tokptr[z]+1;
803 end;bal:=bal-1;end;end{:166};
804 if textptr>maxtexts-5 then begin writeln(stdout);
805 write(stderr,'! Sorry, ','text',' capacity exceeded');error;history:=3;
806 uexit(1);end;currepltext:=textptr;tokstart[textptr+5]:=tokptr[z];
807 textptr:=textptr+1;if z=4 then z:=0 else z:=z+1;end;
808 {:165}{170:}procedure definemacro(t:eightbits);var p:namepointer;
809 begin p:=idlookup(t);scanrepl(t);equiv[p]:=currepltext;
810 textlink[currepltext]:=0;end;{:170}{172:}procedure scanmodule;
811 label 22,30,10;var p:namepointer;begin modulecount:=modulecount+1;
812 {173:}nextcontrol:=0;
813 while true do begin 22:while nextcontrol<=132 do begin nextcontrol:=
814 skipahead;if nextcontrol=135 then begin loc:=loc-2;nextcontrol:=getnext;
815 end;end;if nextcontrol<>133 then goto 30;nextcontrol:=getnext;
816 if(nextcontrol<>130)or(buffer[idfirst]=34)then begin begin writeln(
817 stdout);write(stdout,'! Definition flushed, must start with ',
818 'identifier of length > 1');error;end;goto 22;end;nextcontrol:=getnext;
819 if nextcontrol=61 then begin scannumeric(idlookup(1));goto 22;
820 end else if nextcontrol=30 then begin definemacro(2);goto 22;
821 end else{174:}if nextcontrol=40 then begin nextcontrol:=getnext;
822 if nextcontrol=35 then begin nextcontrol:=getnext;
823 if nextcontrol=41 then begin nextcontrol:=getnext;
824 if nextcontrol=61 then begin begin writeln(stdout);
825 write(stdout,'! Use == for macros');error;end;nextcontrol:=30;end;
826 if nextcontrol=30 then begin definemacro(3);goto 22;end;end;end;
827 end else if nextcontrol=91 then begin nextcontrol:=getnext;
828 if nextcontrol=35 then begin nextcontrol:=getnext;
829 if nextcontrol=93 then begin nextcontrol:=getnext;
830 if nextcontrol=61 then begin begin writeln(stdout);
831 write(stdout,'! Use == for macros');error;end;nextcontrol:=30;end;
832 if nextcontrol=30 then begin definemacro(4);goto 22;end;end;end;
833 end{:174};begin writeln(stdout);
834 write(stdout,'! Definition flushed since it starts badly');error;end;
835 end;30:{:173};{175:}case nextcontrol of 134:p:=0;135:begin p:=curmodule;
836 {176:}repeat nextcontrol:=getnext;until nextcontrol<>43;
837 if(nextcontrol<>61)and(nextcontrol<>30)then begin begin writeln(stdout);
838 write(stdout,'! Pascal text flushed, = sign is missing');error;end;
839 repeat nextcontrol:=skipahead;until nextcontrol=136;goto 10;end{:176};
840 end;others:goto 10 end;{177:}storetwobytes(53248+modulecount);{:177};
841 scanrepl(135);
842 {178:}if p=0 then begin textlink[lastunnamed]:=currepltext;
843 lastunnamed:=currepltext;
844 end else if equiv[p]=0 then equiv[p]:=currepltext else begin p:=equiv[p]
845 ;while textlink[p]<maxtexts do p:=textlink[p];textlink[p]:=currepltext;
846 end;textlink[currepltext]:=maxtexts;{:178};{:175};10:end;
847 {:172}{181:}{procedure debughelp;label 888,10;var k:integer;
848 begin debugskipped:=debugskipped+1;
849 if debugskipped<debugcycle then goto 10;debugskipped:=0;
850 while true do begin begin writeln(stdout);write(stdout,'#');end;
851 fflush(stdout);read(stdin,ddt);
852 if ddt<0 then goto 10 else if ddt=0 then begin goto 888;
853 888:ddt:=0;
854 end else begin read(stdin,dd);case ddt of 1:printid(dd);2:printrepl(dd);
855 3:for k:=1 to dd do write(stdout,xchr[buffer[k]]);
856 4:for k:=1 to dd do write(stdout,xchr[modtext[k]]);
857 5:for k:=1 to outptr do write(stdout,xchr[outbuf[k]]);
858 6:for k:=1 to dd do write(stdout,xchr[outcontrib[k]]);
859 others:write(stdout,'?')end;end;end;10:end;}
860 {:181}{182:}begin initialize;{134:}openinput;line:=0;otherline:=0;
861 changing:=true;primethechangebuffer;changing:=not changing;
862 templine:=otherline;otherline:=line;line:=templine;limit:=0;loc:=1;
863 buffer[0]:=32;inputhasended:=false;{:134};
864 write(stdout,'This is TANGLE, Version 4.6');
865 writeln(stdout,versionstring);{183:}phaseone:=true;modulecount:=0;
866 repeat nextcontrol:=skipahead;until nextcontrol=136;
867 while not inputhasended do scanmodule;
868 {138:}if changelimit<>0 then begin for ii:=0 to changelimit-1 do buffer[
869 ii]:=changebuffer[ii];limit:=changelimit;changing:=true;line:=otherline;
870 loc:=changelimit;begin writeln(stdout);
871 write(stdout,'! Change file entry did not match');error;end;end{:138};
872 phaseone:=false;{:183};{for ii:=0 to 4 do maxtokptr[ii]:=tokptr[ii];}
873 {112:}if textlink[0]=0 then begin begin writeln(stdout);
874 write(stdout,'! No output was specified.');end;
875 if history=0 then history:=1;end else begin begin writeln(stdout);
876 write(stdout,'Writing the output file');end;fflush(stdout);
877 {83:}stackptr:=1;bracelevel:=0;curstate.namefield:=0;
878 curstate.replfield:=textlink[0];zo:=curstate.replfield mod 5;
879 curstate.bytefield:=tokstart[curstate.replfield];
880 curstate.endfield:=tokstart[curstate.replfield+5];curstate.modfield:=0;
881 {:83};{96:}outstate:=0;outptr:=0;breakptr:=0;semiptr:=0;outbuf[0]:=0;
882 line:=1;{:96};sendtheoutput;{98:}breakptr:=outptr;semiptr:=0;
883 flushbuffer;if bracelevel<>0 then begin writeln(stdout);
884 write(stdout,'! Program ended at brace level ',bracelevel:1);error;end;
885 {:98};begin writeln(stdout);write(stdout,'Done.');end;end{:112};
886 if stringptr>256 then{184:}begin begin writeln(stdout);
887 write(stdout,stringptr-256:1,' strings written to string pool file.');
888 end;write(pool,'*');
889 for ii:=1 to 9 do begin outbuf[ii]:=poolchecksum mod 10;
890 poolchecksum:=poolchecksum div 10;end;
891 for ii:=9 downto 1 do write(pool,xchr[48+outbuf[ii]]);writeln(pool);
892 end{:184};{[186:]begin writeln(stdout);
893 write(stdout,'Memory usage statistics:');end;begin writeln(stdout);
894 write(stdout,nameptr:1,' names, ',textptr:1,' replacement texts;');end;
895 begin writeln(stdout);write(stdout,byteptr[0]:1);end;
896 for wo:=1 to 2 do write(stdout,'+',byteptr[wo]:1);
897 if phaseone then for ii:=0 to 4 do maxtokptr[ii]:=tokptr[ii];
898 write(stdout,' bytes, ',maxtokptr[0]:1);
899 for ii:=1 to 4 do write(stdout,'+',maxtokptr[ii]:1);
900 write(stdout,' tokens.');[:186];}
901 {187:}case history of 0:begin writeln(stdout);
902 write(stdout,'(No errors were found.)');end;1:begin writeln(stdout);
903 write(stdout,'(Did you see the warning message above?)');end;
904 2:begin writeln(stdout);
905 write(stdout,'(Pardon me, but I think I spotted something wrong.)');end;
906 3:begin writeln(stdout);
907 write(stdout,'(That was a fatal error, my friend.)');end;end{:187};
908 writeln(stdout);if(history<>0)and(history<>1)then uexit(1)else uexit(0);
909 end.{:182}