|
|
1.1 root 1: BEGIN {seen[""] = 0
2: monkdel = "\(\)\[\]<>{\}\"\"\'\'\`\'"
3: EQstr="(^\\.EQ)|(\\|begin *[(<[{'\"\`]equation *)|(\\|equation[^_])"
4: ENstr="(^\\.EN)|(\\|end *[(<[{'\"\`]equation)"
5: TSstr="(^\\.TS)|(\\|begin *[(<[{'\"\`]table *)|(\\|table[^_])"
6: TEstr="(^\\.TE)|(\\|end *[(<[{'\"\`]table)"
7: GSstr="(^\\.GS)|(\\|begin *[(<[{'\"\`]ped *)|(\\|ped[^_])"
8: GEstr="(^\\.GE)|(\\|end *[(<[{'\"\`]ped)"
9: PSstr="(^\\.(PS|G1))|(\\|begin *[(<[{'\"\`](picture|graph) *)|(\\|(picture|graph)[^_])"
10: PEstr="(^\\.(P[EF]|G2))|(\\|end *[(<[{'\"\`](picture|graph))"
11: ISstr="(^\\.IS)|(\\|begin *[(<[{'\"\`]ideal *)|(\\|ideal[^_])"
12: IEstr="(^\\.I[EF])|(\\|end *[(<[{'\"\`]ideal)"
13: picoutput = "This paper appears to have pic output included.\nWe do not accept papers with pic output.\nPlease resubmit it with the pic input instead.\nIf the pic input is in separate files, you can include it by saying:\n.PS <picfile"
14: tbloutput = "This paper appears to have tbl output included.\nWe do not accept papers with tbl output.\nPlease resubmit it with the tbl input instead.\n"
15: tpedoutput = "This paper appears to have tped output included.\nWe do not accept papers with tped output.\nPlease resubmit it with the tped input instead.\n"
16: intbl = ineq = tped = 0
17: ndelim=""
18: macs=".BM .BP .BI"
19: n=split(macs,arr," ")
20: for(i=1;i<=n;i++)
21: incmacro[arr[i]]=1
22: }
23: /^\.ig/ {
24: while(getline>0 && $0 !~ /^\.\./);
25: next
26: }
27: # inmacro seeded with .BM .BP .PI also has
28: # macros including picture macro, try to open all args
29: /^\./ {
30: if(($1 in incmacro) && (NF > 1)){
31: tryall()
32: next
33: }
34: }
35: # .so - get input file
36: # or .de that includes .so - try to get file as arg2
37: /^\.so/ || $1 in hasso {
38: getfile($2)
39: next
40: }
41: /\|comment/ {
42: comment("")
43: next
44: }
45: /\|(insert|source)/ {
46: mgetfile()
47: next
48: }
49: /\|author/ {
50: author("")
51: next
52: }
53: /\|title[^a-z_]/ {
54: title("")
55: next
56: }
57: # bwk macro
58: /^\.ge/ {
59: system( "trget " NF " " $2 " " $3 " " $4 " " $5 )
60: close( "trget " NF " " $2 " " $3 " " $4 " " $5 )
61: next
62: }
63: # bwk macro
64: /^\.ru/ {
65: system( $2 " " $3 " " $4 " " $5 " " $6 " " $7 " " $8 " " $9 )
66: close( $2 " " $3 " " $4 " " $5 " " $6 " " $7 " " $8 " " $9 )
67: next
68: }
69: # inline .sy - execute
70: /^\.sy/ {
71: system( $2 " " $3 " " $4 " " $5 " " $6 " " $7 " " $8 " " $9 )
72: close( $2 " " $3 " " $4 " " $5 " " $6 " " $7 " " $8 " " $9 )
73: next
74: }
75: /^\.bm/ {
76: next
77: }
78: # switch in and out of eqn
79: $0 ~ EQstr { ineq = 1
80: print $0
81: if($0 !~ /^\./ && $0 !~ /\|begin/)
82: ndelim=getdel()
83: next
84: }
85: $0 ~ ENstr { ineq = 0}
86: # switch in and out of tbl
87: $0 ~ TSstr { intbl = 1
88: print $0
89: if($0 !~ /^\./ && $0 !~ /\|begin/)
90: ndelim=getdel()
91: next
92: }
93: $0 ~ TEstr { intbl = 0}
94: # all tbl output has this - unlikely otherwise - reject
95: /^\.de 35/ {
96: if(intbl){
97: print tbloutput|"cat 1>&2"
98: exit 1
99: }
100: }
101: # save eqn delimiters - # bad for tbl, pic - warn
102: /^[ ]*delim[ ]*/ {
103: if(ineq){
104: if($2 ~ /#/)
105: print "eqn delimiters in " $0 " will break tbl, pic etc"|"cat 1>&2"
106: delim = $0
107: }
108: }
109: # macro definition - check for embedded picture macros
110: # bitmaps, or .so
111: /^\.(de|am)/ {
112: if($0 ~ /IS/)
113: print ".IS is defined in " file " check it for ideal"|"cat 1>&2"
114: print $0
115: xname = $2
116: while((getline) > 0){
117: if($0 ~ /^\.ig/){
118: while((getline) >0 && $0 !~ /^\.\./);
119: continue
120: }
121: if($0 ~ /^\.\./)break
122: if($0 ~ /^\.(BM|BP|PI)/)incmacro["." xname]=1
123: if($0 ~ /^\.so/){
124: hasso["." xname] = 1
125: print "The .so embedded in macro " xname " may cause files not to be shipped " | "cat 1>&2"
126: defso = 1
127: }
128: print $0
129: }
130: }
131: # .PS <file
132: # check if file contains .PS
133: # replace .PS <file with file (and .PS in needed)
134: # copy other files if copy thru included
135: /^\.PS[ \t]*</ {
136: gsub(/ /,"")
137: a=substr($0,index($0,"<")+1)
138: if((getline<a) >0){
139: pflag=0
140: start=1
141: if($0 ~ /^\./){
142: print $0
143: pflag=1
144: if($0 !~ /^\.PS/){
145: while(getline<a > 0){
146: if($0 !~ /^\./)break
147: print $0
148: if($0 ~ /^\.PS/)pflag=0
149: }
150: if(pflag)print ".PS"
151: start=0
152: }
153: }
154: else{ print ".PS"
155: start=0
156: }
157: pflag = getpic(a,start,0,"")
158: if(pflag)print ".PE"
159: close(a)
160: }
161: else {
162: print "couldn't open pic file:" a|"cat 1>&2"
163: print "from line: " $0|"cat 1>&2"
164: exit 1
165: }
166: next
167: }
168: # tped .GS may name file to include
169: # if so, copy file; replace full path with file name
170: # else toggle tped flag
171: $0 ~ GSstr {
172: if($0 ~ /^\.GS/ && NF > 1){
173: for(t=2; t<=NF;t++){
174: if($t !~ "-" && $t !~ "="){
175: system( "cp " $t " " dir )
176: close( "cp " $t " " dir )
177: if($0 ~ "/"){
178: nstat=split($0,stat,"/")
179: cmd = ""
180: for(xx=1;xx<t;xx++)
181: cmd= cmd $xx " "
182: print cmd stat[nstat]
183: }
184: else print $0
185: next
186: }
187: }
188: }
189: intped=1
190: print $0
191: if($0 !~ /^\./ && $0 !~ /\|begin/)
192: ndelim=getdel()
193: next
194: }
195: $0 ~ GEstr {
196: intped=0
197: }
198: # .sp -1 clue of included tped output
199: /^\.sp -1/ {
200: if(intped){
201: print tpedout|"cat 1>&2"
202: exit 1
203: }
204: }
205: # grap/pic may include file
206: $0 ~ PSstr {
207: getpic("",0,1,"")
208: next
209: }
210: # ideal - may include file
211: $0 ~ ISstr {
212: print $0
213: if($0 !~ /^\./ && $0 !~ /\|begin/)
214: idelim=getdel()
215: else idelim=IEstr
216: while(getline){
217: if($0 ~ idelim){
218: print $0
219: next
220: }
221: else if($0 ~ /^[\.]+include/)
222: doinclude($1, $2, 0)
223: else print $0
224: }
225: }
226: # macro called that includes .so probably not included
227: /^\./ {
228: if($1 in hasso)
229: print $2 "with embedded .so called"| "cat 1>&2"
230: }
231: /.*/ {
232: if(ndelim != "")
233: if($0 ~ ndelim){
234: ineq=intbl=0
235: ndelim=""
236: }
237: print $0
238: }
239: function havecopy(cmd, file, i, ofile, quotes,n,rname,NAME,j){
240: if(file ~ /"/){
241: quotes=1
242: n = split(file, name, "\"")
243: if(n>1)rname = name[2]
244: }
245: else {
246: rname = file
247: quotes=0
248: }
249: if(rname ~ "/"){
250: n = split(rname,nn, "/")
251: NAME=nn[n]
252: }
253: else NAME=rname
254: if(i > 2)for(j=2;j<i;j++)cmd = cmd " " $j
255: if(quotes)cmd = cmd " \"" NAME "\""
256: else cmd = cmd " " NAME
257: if(NF >= i+1)
258: for(j=i+1; j<=NF; j++)cmd = cmd " " $j
259: if(ofile != "")print cmd >>ofile
260: else print cmd
261: if(rname in seen)return
262: getpic(rname,1,0,dir "/" NAME)
263: close(rname)
264: close(dir "/" NAME)
265: seen[rname]=1
266: }
267: function tryall( cmd,i,tryit,found){
268: cmd=$1
269: found=0
270: for(i=2;i<=NF;i++){
271: if((getline tryit <$i)>0){
272: found=1
273: cmd= cmd " " getcopy($i)
274: }
275: else cmd = cmd " " $i
276: close($i)
277: }
278: print cmd
279: if(!found){
280: print "no files found in " cmd|"cat 1>&2"
281: }
282: }
283: function getcopy(file, rname,quotes,n,NAME){
284: rname=file
285: quotes=0
286: if(file ~ /"/){
287: quotes=1
288: n=split(file,name,"\"")
289: if(n>1)rname=name[2]
290: }
291: system( "cp " rname " " dir )
292: close( "cp " rname " " dir )
293: if(rname ~ "/"){
294: n = split(rname,nn, "/")
295: NAME=nn[n]
296: }
297: else NAME=rname
298: if(quotes)return("\"" NAME "\"")
299: else return(NAME)
300: }
301: function getfile(file, File, eflag,first,indef,xname,fintbl,finpic,saveline){
302: if(file ~ /\/usr\/lib\//|| file ~ /\/exptools\//){
303: print $0
304: return
305: }
306: saveline=$0
307: if(file ~ /\\\"/)sub(/\\\".*/,"",file)
308: if((getline <file) > 0){
309: if($0 ~ /@\(#\)dcs:[cC][Ss]macros/){
310: print saveline
311: return
312: }
313: if($0 ~ /^\.lf/){
314: File=$NF
315: saveline=$0
316: if((getline <File)<=0){
317: print "This paper contains preprocessor output evidenced by " saveline| "cat 1>&2"
318: print "and I can't find the source file " File|"cat 1>&2"
319: while((getline < file) >0 && $0 ~ /^\.lf/)
320: print $0| "cat 1>&2"
321: print "paper not submitted" | "cat 1>&2"
322: exit 1
323: }
324: }
325: else File = file
326: }
327: else {
328: close(file)
329: print "cannot open file " file | "cat 1>&2"
330: return
331: }
332: if(File in seen){
333: close(File)
334: return
335: }
336: if(delim != "" && !ismonk){
337: print ".EQ\ndelim off\n.EN"
338: eflag=1
339: }
340: seen[File] = 1
341: first=1
342: while(1){
343: if(first==0)if((getline <File)<=0)break
344: first = 0
345: if($0 ~ /^\.ig/){
346: while((getline<File)>0 && $0 !~ /^\.\./);
347: continue
348: }
349: if($0 ~ /^\.(de|am)/){
350: if(fintbl && $0 ~ /^\.de 35/){
351: print tbloutput|"cat 1>&2"
352: print "The tbl output is in the .so file named:" File|"cat 1>&2"
353: exit 1
354: }
355: indef=1
356: xname = $2
357: }
358: if(indef && $0 ~ /^\.(BM|BP|PI)/)incmacro["." xname]=1
359: if($0 ~ /^\.\.$/)indef=0
360: if($0 ~ /^\.sy/ && indef == 0){
361: print "the .sy commands in this paper will not be handled" indef|"cat 1>&2"
362: if(debug ~ /-d/){
363: print $0
364: continue
365: }
366: print "paper not submitted" | "cat 1>&2"
367: exit 1
368: }
369: if($0 ~ TSstr)fintbl=1
370: if($0 ~ TEstr)fintbl=0
371: if($0 ~ PSstr)getpic(File,0,1,"")
372: else if($0 ~ /\|comment/)comment(File)
373: else if($0 ~ /\|(insert|source)/)mgetfile()
374: else if($0 ~ /\|author/)author(File)
375: else if($0 ~ /\|title[^a-z_]/)title(File)
376: else if(($1 in incmacro)&& (NF > 1)&&!indef)
377: tryall()
378: else if($0 ~ /^\.so/){
379: if(!indef)getfile($2)
380: else hasso["." xname]=1
381: }
382: else print $0
383: }
384: close(File)
385: if(eflag){
386: print ".EQ\n" delim "\n.EN"
387: eflat = 0
388: }
389: }
390: function doinclude(cmd, fname, fileflag, file){
391: if(fname ~ "/"){
392: n=split(fname,name,"/")
393: if(fileflag)print cmd " " name[n] >(dir "/" file)
394: else print cmd " " name[n]
395: }
396: else if(fileflag)print cmd " " fname >(dir "/" file)
397: else print cmd " " fname
398: while((getline<fname)>0){
399: if($0 ~ /^[\.]+include/)
400: doinclude($1, $2, 1, fname)
401: else print $0 >(dir "/" fname)
402: }
403: close(fname)
404: }
405: function getpic(file,flag,iscmd, ofile, rfile, inmonk, pflag, i, pdelim,first){
406: pflag = 1
407: inmonk=0
408: if(iscmd && $0 !~ /^\./ && $0 !~ /\|begin/){
409: i=$0
410: pdelim=getdel()
411: $0=i
412: }
413: else pdelim=PEstr
414: rfile=file
415: first=0
416: while(1){
417: if(flag){
418: if(rfile == ""){
419: if(getline <= 0)break
420: }
421: else if((getline<rfile)<=0){
422: if(!inmonk)break
423: inmonk=0
424: close(rfile)
425: rfile=file
426: if(ofile != "")print "...\\\"end insert" >>ofile
427: else print "...\\\"end insert"
428: continue
429: }
430: }
431: flag=first=1
432: if($0 ~ /\|(insert|source)/){
433: if(ofile != "")print "...\\\"begin insert" >>ofile
434: else print "...\\\"begin insert"
435: rfile=getname()
436: inmonk=1
437: continue
438: }
439: if(!inmonk && $0 ~ pdelim){
440: pflag=0
441: if(ofile != "")print $0 >>ofile
442: else print $0
443: break
444: }
445: if($0 ~ /(copy|include)/){
446: for(i=1;i<NF;i++)
447: if($i ~ /(copy|include)/)break
448: i++
449: if (($i !~ "^thru$") && ($i !~ "^through$")) {
450: havecopy($1, $i, i, ofile);
451: }
452: else {
453: if(ofile != "")print $0 >>ofile
454: else print $0
455: }
456: }
457: else if($0 ~ /^\.sp -1/){ #sign in pic output included
458: print picoutput|"cat 1>&2"
459: exit 1
460: }
461: else {
462: if(ofile != "")print $0 >>ofile
463: else print $0
464: }
465: }
466: if(!first){
467: close(rfile)
468: print "can't open file " rfile|"cat 1>&2"
469: exit 1
470: }
471: return(pflag)
472: }
473: function getdel(){
474: if($0 !~ /^\|/ && $0 ~ /..*\|/)sub(/^..*\|/,"\|")
475: sub(/\|[a-z \t]*/,"")
476: ldelim = substr($0, 0, 1)
477: sub(/./,"")
478: b = substr(monkdel,index(monkdel,ldelim)+1,1)
479: prdelim = b
480: return("\\" b)
481: }
482: function comment(fname, rdelim){ #print comment to avoid losing lines
483: print $0
484: rdelim = getdel()
485: if($0 ~ rdelim)return
486: if(fname == ""){
487: while(getline > 0){
488: print $0
489: if($0 ~ rdelim)break
490: }
491: }
492: else while((getline<fname)>0){
493: print $0
494: if($0 ~ rdelim)break
495: }
496: }
497: # reorder author/title in monk
498: function author(fname, rdelim){
499: if(titleflag)print $0
500: else if(sauthor == "")sauthor = $0
501: else sauthor = sauthor "\n" $0
502: rdelim = getdel()
503: if($0 !~ rdelim){
504: while(1){
505: if(fname == ""){
506: if(getline <= 0)break
507: }
508: else {
509: if((getline<fname) <= 0)break
510: }
511: if(titleflag)print $0
512: else sauthor = sauthor "\n" $0
513: if($0 ~ rdelim)break
514: }
515: }
516: }
517: function title(fname, rdelim){
518: print $0
519: rdelim = getdel()
520: if($0 !~ rdelim){
521: if(fname == "")
522: while(getline > 0){
523: print $0
524: if($0 ~ rdelim)break
525: }
526: else while((getline<fname) > 0){
527: print $0
528: if($0 ~ rdelim)break
529: }
530: }
531: if(sauthor != ""){
532: print sauthor
533: sauthor = ""
534: }
535: titleflag=1
536: }
537: function mgetfile( rname){
538: rname=getname()
539: if(rname in seen)return
540: ismonk=1
541: getfile(rname)
542: }
543: function getname( del,n){
544: del=getdel()
545: n=split($0, xa, del)
546: if(n>0)return(xa[1])
547: else return($0)
548: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.