|
|
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((getline <file) > 0){ ! 308: if($0 ~ /@\(#\)dcs:[cC][Ss]macros/){ ! 309: print saveline ! 310: return ! 311: } ! 312: if($0 ~ /^\.lf/){ ! 313: File=$NF ! 314: saveline=$0 ! 315: if((getline <File)<=0){ ! 316: print "This paper contains preprocessor output evidenced by " saveline| "cat 1>&2" ! 317: print "and I can't find the source file " File|"cat 1>&2" ! 318: while((getline < file) >0 && $0 ~ /^\.lf/) ! 319: print $0| "cat 1>&2" ! 320: print "paper not submitted" | "cat 1>&2" ! 321: exit 1 ! 322: } ! 323: } ! 324: else File = file ! 325: } ! 326: else { ! 327: print "cannot open file " file | "cat 1>&2" ! 328: return ! 329: } ! 330: if(File in seen){ ! 331: close(File) ! 332: return ! 333: } ! 334: if(delim != "" && !ismonk){ ! 335: print ".EQ\ndelim off\n.EN" ! 336: eflag=1 ! 337: } ! 338: seen[File] = 1 ! 339: first=1 ! 340: while(1){ ! 341: if(first==0)if((getline <File)<=0)break ! 342: first = 0 ! 343: if($0 ~ /^\.ig/){ ! 344: while((getline<File)>0 && $0 !~ /^\.\./); ! 345: continue ! 346: } ! 347: if($0 ~ /^\.(de|am)/){ ! 348: if(fintbl && $0 ~ /^\.de 35/){ ! 349: print tbloutput|"cat 1>&2" ! 350: print "The tbl output is in the .so file named:" File|"cat 1>&2" ! 351: exit 1 ! 352: } ! 353: indef=1 ! 354: xname = $2 ! 355: } ! 356: if(indef && $0 ~ /^\.(BM|BP|PI)/)incmacro["." xname]=1 ! 357: if($0 ~ /^\.\.$/)indef=0 ! 358: if($0 ~ /^\.sy/ && indef == 0){ ! 359: print "the .sy commands in this paper will not be handled" indef|"cat 1>&2" ! 360: if(debug ~ /-d/){ ! 361: print $0 ! 362: continue ! 363: } ! 364: print "paper not submitted" | "cat 1>&2" ! 365: exit 1 ! 366: } ! 367: if($0 ~ TSstr)fintbl=1 ! 368: if($0 ~ TEstr)fintbl=0 ! 369: if($0 ~ PSstr)getpic(File,0,1,"") ! 370: else if($0 ~ /\|comment/)comment(File) ! 371: else if($0 ~ /\|(insert|source)/)mgetfile() ! 372: else if($0 ~ /\|author/)author(File) ! 373: else if($0 ~ /\|title[^a-z_]/)title(File) ! 374: else if(($1 in incmacro)&& (NF > 1)&&!indef) ! 375: tryall() ! 376: else if($0 ~ /^\.so/){ ! 377: if(!indef)getfile($2) ! 378: else hasso["." xname]=1 ! 379: } ! 380: else print $0 ! 381: } ! 382: close(File) ! 383: if(eflag){ ! 384: print ".EQ\n" delim "\n.EN" ! 385: eflat = 0 ! 386: } ! 387: } ! 388: function doinclude(cmd, fname, fileflag, file){ ! 389: if(fname ~ "/"){ ! 390: n=split(fname,name,"/") ! 391: if(fileflag)print cmd " " name[n] >(dir "/" file) ! 392: else print cmd " " name[n] ! 393: } ! 394: else if(fileflag)print cmd " " fname >(dir "/" file) ! 395: else print cmd " " fname ! 396: while((getline<fname)>0){ ! 397: if($0 ~ /^[\.]+include/) ! 398: doinclude($1, $2, 1, fname) ! 399: else print $0 >(dir "/" fname) ! 400: } ! 401: close(fname) ! 402: } ! 403: function getpic(file,flag,iscmd, ofile, rfile, inmonk, pflag, i, pdelim){ ! 404: pflag = 1 ! 405: inmonk=0 ! 406: if(iscmd && $0 !~ /^\./ && $0 !~ /\|begin/){ ! 407: i=$0 ! 408: pdelim=getdel() ! 409: $0=i ! 410: } ! 411: else pdelim=PEstr ! 412: rfile=file ! 413: while(1){ ! 414: if(flag){ ! 415: if(rfile == ""){ ! 416: if(getline <= 0)break ! 417: } ! 418: else if((getline<rfile)<=0){ ! 419: if(!inmonk)break ! 420: inmonk=0 ! 421: close(rfile) ! 422: rfile=file ! 423: if(ofile != "")print "...\\\"end insert" >>ofile ! 424: else print "...\\\"end insert" ! 425: continue ! 426: } ! 427: } ! 428: flag=1 ! 429: if($0 ~ /\|(insert|source)/){ ! 430: if(ofile != "")print "...\\\"begin insert" >>ofile ! 431: else print "...\\\"begin insert" ! 432: rfile=getname() ! 433: inmonk=1 ! 434: continue ! 435: } ! 436: if(!inmonk && $0 ~ pdelim){ ! 437: pflag=0 ! 438: if(ofile != "")print $0 >>ofile ! 439: else print $0 ! 440: break ! 441: } ! 442: if($0 ~ /(copy|include)/){ ! 443: for(i=1;i<NF;i++) ! 444: if($i ~ /(copy|include)/)break ! 445: i++ ! 446: if (($i !~ "thru") && ($i !~ "through")) { ! 447: havecopy($1, $i, i, ofile); ! 448: } ! 449: else { ! 450: if(ofile != "")print $0 >>ofile ! 451: else print $0 ! 452: } ! 453: } ! 454: else if($0 ~ /^\.sp -1/){ #sign in pic output included ! 455: print picoutput|"cat 1>&2" ! 456: exit 1 ! 457: } ! 458: else { ! 459: if(ofile != "")print $0 >>ofile ! 460: else print $0 ! 461: } ! 462: } ! 463: return(pflag) ! 464: } ! 465: function getdel(){ ! 466: if($0 !~ /^\|/ && $0 ~ /..*\|/)sub(/^..*\|/,"\|") ! 467: sub(/\|[a-z \t]*/,"") ! 468: ldelim = substr($0, 0, 1) ! 469: sub(/./,"") ! 470: b = substr(monkdel,index(monkdel,ldelim)+1,1) ! 471: prdelim = b ! 472: return("\\" b) ! 473: } ! 474: function comment(fname, rdelim){ #print comment to avoid losing lines ! 475: print $0 ! 476: rdelim = getdel() ! 477: if($0 ~ rdelim)return ! 478: if(fname == ""){ ! 479: while(getline > 0){ ! 480: print $0 ! 481: if($0 ~ rdelim)break ! 482: } ! 483: } ! 484: else while((getline<fname)>0){ ! 485: print $0 ! 486: if($0 ~ rdelim)break ! 487: } ! 488: } ! 489: # reorder author/title in monk ! 490: function author(fname, rdelim){ ! 491: if(titleflag)print $0 ! 492: else if(sauthor == "")sauthor = $0 ! 493: else sauthor = sauthor "\n" $0 ! 494: rdelim = getdel() ! 495: if($0 !~ rdelim){ ! 496: while(1){ ! 497: if(fname == ""){ ! 498: if(getline <= 0)break ! 499: } ! 500: else { ! 501: if((getline<fname) <= 0)break ! 502: } ! 503: if(titleflag)print $0 ! 504: else sauthor = sauthor "\n" $0 ! 505: if($0 ~ rdelim)break ! 506: } ! 507: } ! 508: } ! 509: function title(fname, rdelim){ ! 510: print $0 ! 511: rdelim = getdel() ! 512: if($0 !~ rdelim){ ! 513: if(fname == "") ! 514: while(getline > 0){ ! 515: print $0 ! 516: if($0 ~ rdelim)break ! 517: } ! 518: else while((getline<fname) > 0){ ! 519: print $0 ! 520: if($0 ~ rdelim)break ! 521: } ! 522: } ! 523: if(sauthor != ""){ ! 524: print sauthor ! 525: sauthor = "" ! 526: } ! 527: titleflag=1 ! 528: } ! 529: function mgetfile( rname){ ! 530: rname=getname() ! 531: if(rname in seen)return ! 532: ismonk=1 ! 533: getfile(rname) ! 534: } ! 535: function getname( del,n){ ! 536: del=getdel() ! 537: n=split($0, xa, del) ! 538: if(n>0)return(xa[1]) ! 539: else return($0) ! 540: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.