1: # Use perl
2eval 'exec /usr/local/bin/perl -S $0 "$@"'
3  if $running_under_some_shell;
4
5# This is html2ps version 1.0 beta7, an HTML-to-PostScript converter.
6#   Copyright (C) 1995-2010 Jan Karrman.
7#
8#   This program is free software; you can redistribute it and/or modify
9#   it under the terms of the GNU General Public License as published by
10#   the Free Software Foundation; either version 2 of the License, or
11#   (at your option) any later version.
12#
13#   This program is distributed in the hope that it will be useful,
14#   but WITHOUT ANY WARRANTY; without even the implied warranty of
15#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16#   GNU General Public License for more details.
17#
18#   You should have received a copy of the GNU General Public License
19#   along with this program; if not, write to the Free Software
20#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21#
22# Author: Jan Karrman, Dept. of Information Technology, Uppsala University,
23#         Sweden, e-mail: jan@it.uu.se.
24
25
26# Set the name of the global configuration file. See the installation notes
27# and manual page for more details on configuration files.
28
29$LIBPAPER=1;
30$globrc='/usr/local/etc/html2psrc';
31$ug='/usr/local/share/html2ps/html2ps.html';
32
33$conf=<<'EOR';
34@html2ps {
35  package {
36    PerlMagick: 0;
37    ImageMagick: 0;
38    pbmplus: 0;
39    netpbm: 0;
40    djpeg: 0;
41    Ghostscript: 0;
42    TeX: 0;
43    dvips: 0;
44    libwww-perl: 0;
45    geturl: "";
46    check: "";
47    path: "";
48  }
49  paper {
50    type: libpaper;
51    height: "";
52    width: "";
53  }
54  option {
55    twoup: 0;
56    base: "";
57    check: 0;
58    toc: "";
59    debug: 0;
60    DSC: 0;
61    encoding: "ISO-8859-1";
62    rcfile: "";
63    frame: 0;
64    grayscale: 0;
65    help: 0;
66    hyphenate: 0;
67    scaleimage: 1;
68    cookie: "";
69    language: "";
70    landscape: 0;
71    scalemath: 1;
72    mainchapter: 1;
73    number: 0;
74    startno: "";
75    output: "";
76    original: 0;
77    rootdir: "";
78    xref: 0;
79    scaledoc: 1;
80    style: "";
81    titlepage: 0;
82    text: 0;
83    underline: 0;
84    colour: 0;
85    version: 0;
86    web: "";
87    duplex: "";
88  }
89  margin {
90    middle: 2cm;
91  }
92  xref {
93    text: "[p $N]";
94    passes: 1;
95  }
96  quote {
97    en {
98      open: "&ldquo;";
99      close: "&rdquo;";
100      open2: "`";
101      close2: "'";
102    }
103    sv {
104      open: "&rdquo;";
105      close: "&rdquo;";
106      open2: "'";
107      close2: "'";
108    }
109    da {
110      open: "&raquo;";
111      close: "&laquo;";
112    }
113    no {
114      open: "&laquo;";
115      close: "&raquo;";
116    }
117    fr {
118      open: "&laquo;&nbsp;";
119      close: "&nbsp;&raquo;";
120    }
121    de {
122      open: "&bdquo;";
123      close: "&ldquo;";
124      open2: "&sbquo;";
125      close2: "`";
126    }
127    fi: sv;
128    es: en;
129    it: no;
130    nn: no;
131    nb: no;
132  }
133  toc {
134    heading: "<H1>Table of Contents</H1>";
135    level: 6;
136    indent: 1em;
137  }
138  titlepage {
139    content: "<DIV align=center>
140      <H1><BIG>$T</BIG></H1>
141      <H2>$[author]</H2></DIV>";
142    margin-top: 4cm;
143  }
144  font {
145    times {
146      names: "Times-Roman
147              Times-Italic
148              Times-Bold
149              Times-BoldItalic";
150    }
151    new-century-schoolbook {
152      names: "NewCenturySchlbk-Roman
153              NewCenturySchlbk-Italic
154              NewCenturySchlbk-Bold
155              NewCenturySchlbk-BoldItalic";
156    }
157    helvetica {
158      names: "Helvetica
159              Helvetica-Oblique
160              Helvetica-Bold
161              Helvetica-BoldOblique";
162    }
163    helvetica-narrow {
164      names: "Helvetica-Narrow
165              Helvetica-Narrow-Oblique
166              Helvetica-Narrow-Bold
167              Helvetica-Narrow-BoldOblique";
168    }
169    palatino {
170      names: "Palatino-Roman
171              Palatino-Italic
172              Palatino-Bold
173              Palatino-BoldItalic";
174    }
175    avantgarde {
176      names: "AvantGarde-Book
177              AvantGarde-BookOblique
178              AvantGarde-Demi
179              AvantGarde-DemiOblique";
180    }
181    bookman {
182      names: "Bookman-Light
183              Bookman-LightItalic
184              Bookman-Demi
185              Bookman-DemiItalic";
186    }
187    courier {
188      names: "Courier
189              Courier-Oblique
190              Courier-Bold
191              Courier-BoldOblique";
192    }
193  }
194  hyphenation {
195    min: 8;
196    start: 4;
197    end: 3;
198    en {
199      file: "";
200      extfile: "";
201    }
202  }
203  header {
204    left: "";
205    center: "";
206    right: "";
207    odd-left: "";
208    odd-center: "";
209    odd-right: "";
210    even-left: "";
211    even-center: "";
212    even-right: "";
213    font-family: Helvetica;
214    font-size: 8pt;
215    font-style: normal;
216    font-weight: normal;
217    color: black;
218    alternate: 1;
219  }
220  footer {
221    left: "";
222    center: "";
223    right: "";
224    odd-left: "";
225    odd-center: "";
226    odd-right: "";
227    even-left: "";
228    even-center: "";
229    even-right: "";
230    font-family: Helvetica;
231    font-size: 8pt;
232    font-style: normal;
233    font-weight: normal;
234    color: black;
235    alternate: 1;
236  }
237  frame {
238    width: 0.6pt;
239    margin: 0.5cm;
240    color: black;
241  }
242  justify {
243    word: 15pt;
244    letter: 0pt;
245  }
246  draft {
247    text: DRAFT;
248    print: "";
249    dir: 0;
250    font-family: Helvetica;
251    font-style: normal;
252    font-weight: bold;
253    color: F0F0F0;
254  }
255  colour {
256    black: 000000;
257    green: 008000;
258    silver: C0C0C0;
259    lime: 00FF00;
260    gray: 808080;
261    olive: 808000;
262    white: FFFFFF;
263    yellow: FFFF00;
264    maroon: 800000;
265    navy: 000080;
266    red: FF0000;
267    blue: 0000FF;
268    purple: 800080;
269    teal: 008080;
270    fuchsia: FF00FF;
271    aqua: 00FFFF;
272  }
273  html2psrc: "$HOME/.html2psrc";
274  imgalt: "[IMAGE]";
275  datefmt: "%e %b %Y  %R";
276  locale: "";
277  doc-sep: "<!--NewPage-->";
278  ball-radius: 0.25em;
279  numbstyle: 0;
280  showurl: 0;
281  seq-number: 0;
282  extrapage: 1;
283  break-table: 0;
284  forms: 1;
285  textarea-data: 0;
286  page-break: 1;
287  expand-acronyms: 0;
288  spoof: "";
289  ssi: 0;
290  prefilled: 0;
291}
292
293BODY {
294  font-family: Times;
295  font-size: 11pt;
296  text-align: left;
297  background: white;
298}
299
300H1, H2, H3, H4, H5, H6 {
301  font-weight: bold;
302  margin-top: 0.8em;
303  margin-bottom: 0.5em;
304}
305H1 { font-size: 19pt }
306H2 { font-size: 17pt }
307H3 { font-size: 15pt }
308H4 { font-size: 13pt }
309H5 { font-size: 12pt }
310H6 { font-size: 11pt }
311
312P, OL, UL, DL, BLOCKQUOTE, PRE {
313  margin-top: 1em;
314  margin-bottom: 1em;
315}
316
317P {
318  line-height: 1.2em;
319  text-indent: 0;
320}
321
322OL, UL, DD { margin-left: 2em }
323
324TT, KBD, PRE { font-family: Courier }
325
326PRE { font-size: 9pt }
327
328BLOCKQUOTE {
329  margin-left: 1em;
330  margin-right: 1em;
331}
332
333ADDRESS {
334  margin-top: 0.5em;
335  margin-bottom: 0.5em;
336}
337
338TABLE {
339  margin-top: 1.3em;
340  margin-bottom: 1em;
341}
342
343DIV.noprint { display: none }
344
345DEL { text-decoration: line-through }
346
347A:link, HR { color: black }
348
349@page {
350  margin-left: 2.5cm;
351  margin-right: 2.5cm;
352  margin-top: 3cm;
353  margin-bottom: 3cm;
354}
355
356EOR
357
358eval "require POSIX";
359$posix = !$@;
360
361%extend=('quote',1, 'font',1, 'colour',1, 'hyphenation',1);
362%fal=("serif","times", "sans_serif","helvetica", "monospace","courier");
363@fo=("p","pre","h1","h2","h3","h4","h5","h6","i","b","tt","kbd","cite","samp",
364 "address","blockquote","ol","ul","dl","dt","dd","table","header","footer");
365%quote=('','en');
366%valid=('font',1, 'font_files',1, 'margin,left',1, 'margin,right',1,
367 'margin,top',1, 'margin,bottom',1);
368%cm=('cm',1, 'mm',0.1, 'in',2.54, 'pt',2.54/72, 'pc',2.54/6);
369%pt=('cm',72/2.54, 'mm',72/25.4, 'in',72, 'pt',1, 'pc',12);
370%space=('thinsp',6, '#8201',6, 'ensp',2, '#8194',2, 'emsp',1, '#8195',1);
371$space=join('|',keys %space);
372%vars=("T","Ti", "N","Pn", "U","UR", "H","h", "A","Au");
373%height=("letter",27.9, "legal",35.6, "arche",121.9, "archd",91.4, "archc",61,
374 "archb",45.7, "archa",30.5, "flsa",33, "flse",33, "halfletter",21.6,
375 "11x17",43.2, "ledger",27.9);
376%width=("letter",21.6, "legal",21.6, "arche",91.4, "archd",61, "archc",45.7,
377 "archb",30.5, "archa",22.9, "flsa",21.6, "flse",21.6, "halfletter",14,
378 "11x17",27.9, "ledger",43.2);
379
380$version="html2ps version 1.0 beta7";
381$opts="2|b:|c|C:|d|D|e:|f:|F|g|h|H|i:|k:|l:|L|m:|M:|n|N:|o:|O|r:|R|s:|S:|t|T|"
382 ."u|U|v|W:|x:";
383%optalias=( 'twoup','2', 'base','b', 'check','c', 'toc','C', 'debug','d',
384 'DSC','D', 'encoding','e', 'rcfile','f', 'frame','F', 'grayscale','g',
385 'help','h', 'hyphenate','H', 'scaleimage','i', 'cookie','k', 'language','l',
386 'landscape','L', 'scalemath','m', 'mainchapter','M', 'number','n',
387 'startno','N', 'output','o', 'original','O', 'rootdir','r', 'xref','R',
388 'scaledoc','s', 'style','S', 'titlepage','t', 'text','T', 'underline','u',
389 'colour','U', 'version','v', 'web','W', 'duplex','x');
390%type=( 'paper,height',2, 'paper,width',2, 'option,i',3, 'option,m',3,
391 'option,M',4, 'option,N',4, 'option,s',3, 'option,x',4, 'xref,passes',4,
392 'draft,print',5);
393
394$usage=<<EOU;
395Usage:
396 html2ps [-2cdDFghHLnORtTuUv] [-b URL] [-C string] [-e encoding]
397  [-f file[:file[:...]]] [-i num] [-k file] [-l lang] [-m num] [-M num]
398  [-N num] [-o file] [-r path] [-s num] [-S string] [-W string] [-x num]
399  [file|URL [file|URL [...]]]
400
401EOU
402
403$usage.="The html2ps users guide is available as $ug\n\n" if(-r $ug);
404
405$args="@ARGV";
406&Getopts($opts) || die $usage;
407
408if($opt_d) {
409  open(DBG,">html2ps.dbg") || die "Error opening debug file: html2ps.dbg\n";
410  print STDERR "***** Writing debug info to html2ps.dbg\n";
411  print DBG "***** $version\n***** Command: $0 $args\n***** Perl: $]\n";
412  print DBG "***** HTML2PSPATH=$ENV{'HTML2PSPATH'}\n";
413}
414undef $/;
415$user=0;
416$V='(-?\d+\.?\d*|-?\d*\.?\d+)';
417&getconf($conf);
418&pagedef;
419undef %AT_page;
420for(@fo,"draft") {
421  eval "\$deffnt{'$_'}=defined \$$_\{'font-family'\}?"
422      ."\$$_\{'font-family'\}:\$body{'font-family'}";
423}
424$user=1;
425if(open(RC,"<$globrc")) {
426  $conf=<RC>;
427  print DBG "***** Global file $globrc:\n$conf" if($opt_d);
428  &getconf($conf);
429  close RC;
430} else {
431  &dbg("Warning: cannot open the global resource file: $globrc\n") if($globrc);
432}
433$html2psrc=~s/^(~|\$HOME)/$ENV{"HOME"}/;
434$prc=$html2psrc;
435if($opt_f) {
436  ($prc=$opt_f)=~s/^:/$html2psrc:/;
437  $prc=~s/:$/:$html2psrc/;
438  $prc=~s/::/:$html2psrc:/;
439}
440$cwd=$posix?POSIX::getcwd():"";
441opendir(DIR,$cwd);
442@local=readdir DIR;
443closedir DIR;
444$globrc=~/html2psrc/;
445$gdir=$`;
446$hpath=$ENV{"HTML2PSPATH"}?$ENV{"HTML2PSPATH"}:".:";
447$hpath=~s/^:/$gdir:/;
448$hpath=~s/:$/:$gdir/;
449$hpath=~s/::/:$gdir:/;
450$cur=$hpath=~s/(^|:)\.($|:)/$1$cwd$2/;
451@hpath=split(/:/,$hpath);
452for(@hpath) {
453  if(opendir(DIR,$_)) {
454    @files=readdir DIR;
455    $files{$_}=" @files ";
456    closedir DIR;
457  }
458}
459@rc=split(/:/,$prc);
460for $rc (@rc) {
461  $found=0;
462  S:for $dir (@hpath) {
463    if(-r $rc && !grep(/^$rc$/,@local) || $files{$dir}=~/ $rc /) {
464      chdir $dir if($files{$dir}=~/ $rc / && $cwd);
465      if(open(RC,"<$rc")) {
466        $conf=<RC>;
467        print DBG "***** Personal file $rc:\n$conf" if($opt_d);
468        &getconf($conf);
469        close RC;
470        $found=1;
471      }
472      last S;
473    }
474  }
475  &dbg("Error opening resource file: $rc\n") if($opt_f && !$found);
476}
477chdir $cwd if($cwd);
478$user=2;
479&getconf($opt_S) if($opt_S);
480print DBG "*****\n" if($opt_d);
481&pagedef;
482($pagew,$pageh)=split /\s+/, $AT_page{'size'} if(defined $AT_page{'size'});
483
484require Image::Magick if($package{'PerlMagick'});
485$geturl=$package{'geturl'};
486$ulanch="f";
487$f=72/2.54;
488$giftopm="giftopnm" if($package{'netpbm'});
489$giftopm="giftoppm" if($package{'pbmplus'});
490
491for(keys %option){eval "\$opt_$_='$option{$_}' if(!defined \$opt_$_)"};
492die $usage if $opt_h;
493die "$version\n" if $opt_v;
494&dbg("$version\n") if ($opt_v||$opt_d);
495die "Ghostscript is required to generate DSC PostScript\n"
496 if($opt_D && !$package{'Ghostscript'});
497die "Ghostscript is required to generate cross references\n"
498 if($opt_R && !$package{'Ghostscript'});
499$tmpname=$posix?POSIX::tmpnam():"h2p_$$";
500($scr=$tmpname)=~/\w+$/;
501$tempdir=$`;
502
503if($opt_u) {$ulanch="t"};
504if(defined $opt_x && $opt_x!~/^[0-2]$/) {
505  die "Illegal duplex value: $opt_x\n";
506}
507$V='(-?\d+\.?\d*|-?\d*\.?\d+)';
508for $o ($opt_s,$opt_i,$opt_m,$opt_N) {
509  die "Non numeric: $o\n" if(defined($o) && $o!~/^$V$/);
510}
511
512$twoup=$opt_2?"t":"f";
513$xp=$extrapage?"t":"f";
514
515die "Invalid option: -W $opt_W\n" if($opt_W!~/^[abflprsL\d]*$/);
516$tocdoc=$opt_C=~/[ft]/;
517if($tocdoc && !defined $opt_W) {$opt_W=4};
518$mult=$#ARGV>0 || $opt_W;
519$maxlev=$opt_W=~/(\d+)/?$1:4;
520$link=$opt_W=~/l/;
521$local=$opt_W=~/s/;
522$rel=$opt_W=~/r/;
523$below=$opt_W=~/b/;
524$layer=$opt_W=~/L/;
525$prompt=$opt_W=~/p/;
526
527if($opt_C && $opt_C!~/^(b?[ft]|[ft]b?|b?h|hb?)$/)
528  {die "Invalid option: -C $opt_C\n"};
529$tc=$opt_C?"t":"f";
530$rev=$opt_C=~/t/;
531$first=$opt_C=~/b/ || $opt_R;
532$th=$tocdoc?"f":"t";
533$oeh=0;
534$oef=0;
535
536@now=localtime;
537@gmnow=gmtime;
538POSIX::setlocale(&POSIX::LC_TIME,$locale) if($posix);
539$R='(\s*>|[^a-zA-Z0-9>][^>]*>)';
540$S='([\w.:/%-]+)|"([^"]*)"|\'([^\']*)\'';
541$X='[\da-fA-F]';
542$IM='(gif|jpeg|jpg|png|xbm|xpm|ps|eps)';
543
544for('odd-left','odd-center','odd-right','even-left','even-center','even-right')
545 {
546  $oeh=1 if defined $header{$_};
547  $oef=1 if defined $footer{$_};
548}
549%metarc=();
550for $a ('left','center','right') {
551  if(defined $header{"odd-$a"} || defined $header{"even-$a"}) {
552    $oeh=1;
553  }
554  if(defined $footer{"odd-$a"} || defined $footer{"even-$a"}) {
555    $oef=1;
556  }
557  for('','odd-','even-') {
558    $apa=$header{$_.$a};
559    $numb=1 if($apa=~/(^|[^\$])\$N/);
560    &spec($header{$_.$a});
561    &spec($footer{$_.$a});
562    $header{$_.$a}="($apa)";
563    $apa=$footer{$_.$a};
564    $numb=1 if($apa=~/(^|[^\$])\$N/);
565    $footer{$_.$a}="($apa)";
566    &varsub($header{$_.$a},$footer{$_.$a});
567  }
568}
569if($oeh) {
570  $yz="/YY [[{$header{'odd-left'}}{$header{'even-left'}}]"
571     ."[{$header{'odd-right'}}{$header{'even-right'}}]"
572     ."[{$header{'odd-center'}}{$header{'even-center'}}]] D\n";
573} else {
574  $ind=$header{'alternate'};
575  $yz="/YY [[{$header{'left'}}$ind][{$header{'right'}}".(1-$ind)
576     ."][{$header{'center'}}2]] D\n";
577}
578if($oef) {
579  $yz.="/ZZ [[{$footer{'odd-left'}}{$footer{'even-left'}}]"
580      ."[{$footer{'odd-right'}}{$footer{'even-right'}}]"
581      ."[{$footer{'odd-center'}}{$footer{'even-center'}}]] D";
582} else {
583  $ind=$footer{'alternate'};
584  $yz.="/ZZ [[{$footer{'left'}}$ind][{$footer{'right'}}".(1-$ind)
585      ."][{$footer{'center'}}2]] D";
586}
587$number=$opt_n || !$numb && ($opt_C || $opt_N || $opt_R)?"t":"f";
588$tih=$titlepage{'content'};
589$toch=$toc{'heading'};
590for ($imgalt,$xref{'text'},$tih,$toch,$inh,$draft{'text'}) {
591  &spec($_);
592}
593
594for ($paper{'height'},$paper{'width'},$margin{'middle'},$frame{'margin'},
595     $mlr,$mrl,$mtl,$mbl,$mll,$mrr,$mtr,$mbr,$pagew,$pageh) {
596  &getval($_,1);
597}
598$opt_s*=0.65 if($opt_2 && $opt_L);
599$opt_N=1 if(!defined $opt_N);
600$opt_N=int($opt_N-1);
601$mm=int($margin{'middle'}*$f);
602$is=0.8*$opt_i;
603$msc=1/$opt_s;
604$mag=1200*$opt_m*$opt_s;
605$xref=$opt_R?"t":"f";
606$xref{'text'}=~s/\$N/) WB pN WB (/g;
607
608$d=int($f*$frame{'margin'});
609for (0..10) {
610  $temp=2**(-$_/2);
611  $width{"a$_"}=int($temp*2**(-1/4)*1000+.5)/10;
612  $height{"a$_"}=int($temp*2**(1/4)*1000+.5)/10;
613  $width{"b$_"}=int($temp*1000+.5)/10;
614  $height{"b$_"}=int($temp*2**(1/2)*1000+.5)/10;
615}
616if(!$pagew || !$pageh) {
617  if ($LIBPAPER) {
618    my $env_com;
619    if ("\L$paper{'type'}" ne 'libpaper') {
620      $env_com = "/usr/bin/env PAPERSIZE=\"$paper{'type'}\"";
621    }
622    my $_w = `$env_com /usr/local/bin/paperconf -wc`;
623    my $_h = `$env_com /usr/local/bin/paperconf -hc`;
624    my $_n = `$env_com /usr/local/bin/paperconf -n`;
625    if ($_w ne '' and $_h ne '') {
626      $paper{'width'} = $_w;
627      $paper{'height'} = $_h;
628      $paper{'type'} = $_n;
629      ($pagew,$pageh)=($paper{'width'},$paper{'height'});
630    } else {
631      &dbg("Unknown paper type: $paper{'type'}\n");
632    }
633  } else { # !LIBPAPER
634  if($width{"\L$paper{'type'}"}) {
635    $paper{'width'}=$width{"\L$paper{'type'}"} if(!defined $paper{'width'});
636    $paper{'height'}=$height{"\L$paper{'type'}"} if(!defined $paper{'height'});
637    ($pagew,$pageh)=($paper{'width'},$paper{'height'});
638  } elsif($paper{'type'}) {
639    &dbg("Unknown paper type: $paper{'type'}\n");
640  }
641  } # LIBPAPER
642}
643if($opt_L) {
644  $wl=$pageh-$mll-$mrl;
645  $wr=$pageh-$mlr-$mrr;
646  $hl=int(($pagew-$mtl-$mbl)*$f+.5);
647  $hr=int(($pagew-$mtr-$mbr)*$f+.5);
648  $xl=int($mtl*$f+.5);
649  $xr=int($mtr*$f+.5);
650  $yl=int($mll*$f+.5);
651  $yr=int($mlr*$f+.5);
652  $rot=" 90 rotate";
653} else {
654  $wl=$pagew-$mll-$mrl;
655  $wr=$pagew-$mlr-$mrr;
656  $hl=int(($pageh-$mtl-$mbl)*$f+.5);
657  $hr=int(($pageh-$mtr-$mbr)*$f+.5);
658  $xl=int($mll*$f+.5);
659  $xr=int($mlr*$f+.5);
660  $yl=int(($pageh-$mtl)*$f+.5);
661  $yr=int(($pageh-$mtr)*$f+.5);
662  $rot="";
663}
664
665if($opt_2) {
666  $wl=($wl-$margin{'middle'})/2;
667  $wr=($wr-$margin{'middle'})/2;
668}
669$wl=int($wl*$f+.5);
670$wr=int($wr*$f+.5);
671$pag=int($pageh*$f+.5);
672$fe=$opt_F?"t":"f";
673$cf=$opt_U?"t":"f";
674$tp=$opt_t?"t":"f";
675$rm=$numbstyle?"t":"f";
676$pa=$showurl?"t":"f";
677$nh=$seq_number?"t":"f";
678$bt=$break_table?"t":"f";
679$ea=$expand_acronyms?"t":"f";
680$fi=$prefilled?"t":"f";
681$latin1=$opt_e=~/ISO-8859-1/i;
682$lt=$del{'text-decoration'}=~/^line-through$/i?"SE":"WB";
683if(!$opt_x && defined $opt_x) {
684  $dupl="[{false statusdict/setduplexmode get exec} stopped cleartomark";
685}
686if($opt_x) {
687  $dupl="[{true statusdict/setduplexmode get exec} stopped cleartomark";
688}
689if($opt_x==2) {
690  $dupl.="\n[{true statusdict/settumble get exec} stopped cleartomark";
691}
692
693%head=("html",1, "head",1, "title",1, "base",1, "meta",1, "link",1, "style",1,
694 "script",1, "isindex",1);
695%algn=("left",1, "center",2, "right",3, "justify",4, "char",5);
696%f=("void",1, "above",2, "below",3, "hsides",4, "lhs",5, "rhs",6, "vsides",7,
697    "box",8, "border",9);
698%r=("none",1, "groups",2, "rows",3, "cols",4, "all",5);
699%v=("top",1, "middle",2, "bottom",3, "baseline",4);
700%it=("radio",0, "checkbox",1, "text",2, "password",2, "image",3);
701%ssy=(200,"\\", 201, "(", 202, ")");
702%lity=("I",0, "i",1, "A",2, "a",3, "1",4, "disc",5, "square",6, "circle",7);
703$ltr=join('|',keys %lity);
704%tex=('`a',"\340", '\^a',"\342", '`e',"\350", '`e',"\350", 'c\{c\}',"\347",
705      "'e","\351", '\^e',"\352", '"e',"\353", '\^i',"\356", '"i',"\357",
706      '\^o',"\364", '`u',"\371", '\^u',"\373", '"u',"\374", '"y',"\377",
707      'aa',"\345", '"a',"\344", '"o',"\366", 'ae',"\346", 'oe',"\225");
708$opt_M = 1 unless defined $opt_M;
709@hind=(int($opt_M)-1,0,0,0,0,0);
710$ltrs='A-Za-z\222-\226\300-\377';
711%ent=(
712"lsquo|#8216",96,
713"rsquo|#8217",39,
714"circ|#710",141,
715"tilde|#732",142,
716"permil|#8240",143,
717"dagger|#8224",144,
718"Dagger|#8225",145,
719"Yuml|#376",146,
720"scaron|#353",147,
721"Scaron|#352",148,
722"oelig|#339",149,
723"OElig|#338",150,
724"lsaquo|#8249",151,
725"rsaquo|#8250",152,
726"sbquo|#8218",153,
727"bdquo|#8222",154,
728"ldquo|#8220",155,
729"rdquo|#8221",156,
730"ndash|#8211",157,
731"mdash|#8212",158,
732"trade|#8482",159,
733"nbsp",160,
734"iexcl",161,
735"cent",162,
736"pound",163,
737"curren",164,
738"yen",165,
739"brvbar",166,
740"sect",167,
741"uml",168,
742"copy",169,
743"ordf",170,
744"laquo",171,
745"not",172,
746"reg",174,
747"macr",175,
748"deg",176,
749"plusmn",177,
750"sup2",178,
751"sup3",179,
752"acute",180,
753"micro",181,
754"para",182,
755"middot",183,
756"cedil",184,
757"sup1",185,
758"ordm",186,
759"raquo",187,
760"frac14",188,
761"frac12",189,
762"frac34",190,
763"iquest",191,
764"Agrave",192,
765"Aacute",193,
766"Acirc",194,
767"Atilde",195,
768"Auml",196,
769"Aring",197,
770"AElig",198,
771"Ccedil",199,
772"Egrave",200,
773"Eacute",201,
774"Ecirc",202,
775"Euml",203,
776"Igrave",204,
777"Iacute",205,
778"Icirc",206,
779"Iuml",207,
780"ETH",208,
781"Ntilde",209,
782"Ograve",210,
783"Oacute",211,
784"Ocirc",212,
785"Otilde",213,
786"Ouml",214,
787"times",215,
788"Oslash",216,
789"Ugrave",217,
790"Uacute",218,
791"Ucirc",219,
792"Uuml",220,
793"Yacute",221,
794"THORN",222,
795"szlig",223,
796"agrave",224,
797"aacute",225,
798"acirc",226,
799"atilde",227,
800"auml",228,
801"aring",229,
802"aelig",230,
803"ccedil",231,
804"egrave",232,
805"eacute",233,
806"ecirc",234,
807"euml",235,
808"igrave",236,
809"iacute",237,
810"icirc",238,
811"iuml",239,
812"eth",240,
813"ntilde",241,
814"ograve",242,
815"oacute",243,
816"ocirc",244,
817"otilde",245,
818"ouml",246,
819"divide",247,
820"oslash",248,
821"ugrave",249,
822"uacute",250,
823"ucirc",251,
824"uuml",252,
825"yacute",253,
826"thorn",254,
827"yuml",255);
828%symb=(
829"alpha|#945",141,
830"beta|#946",142,
831"gamma|#947",147,
832"delta|#948",144,
833"epsilon|#949",145,
834"zeta|#950",172,
835"eta|#951",150,
836"theta|#952",161,
837"thetasym|#977",112,
838"iota|#953",151,
839"kappa|#954",153,
840"lambda|#955",154,
841"mu|#956",155,
842"nu|#957",156,
843"xi|#958",170,
844"pi|#960",160,
845"piv|#982",166,
846"omicron|#959",157,
847"rho|#961",162,
848"sigma|#963",163,
849"sigmaf|#962",126,
850"tau|#964",164,
851"upsilon|#965",165,
852"upsih|#978",241,
853"phi|#966",146,
854"phiv",152,
855"chi|#967",143,
856"psi|#968",171,
857"omega|#969",167,
858"Alpha|#913",101,
859"Beta|#914",102,
860"Gamma|#915",107,
861"Delta|#916",104,
862"Epsilon|#917",105,
863"Zeta|#918",132,
864"Eta|#919",110,
865"Theta|#920",121,
866"Iota|#921",111,
867"Kappa|#922",113,
868"Lambda|#923",114,
869"Mu|#924",115,
870"Nu|#925",116,
871"Xi|#926",130,
872"Omicron|#927",117,
873"Pi|#928",120,
874"Rho|#929",122,
875"Sigma|#931",123,
876"Tau|#932",124,
877"Upsilon|#933",125,
878"Phi|#934",106,
879"Chi|#935",103,
880"Psi|#936",131,
881"Omega|#937",127,
882"fnof|#402",246,
883"perp|#8869",136,
884"plusmn|#177",261,
885"cdot|#183",327,
886"or|#8744",332,
887"and|#8743",331,
888"le|#8804",243,
889"ge|#8805",263,
890"equiv|#8801",272,
891"cong|#8773",100,
892"asymp|#8776",273,
893"ne|#8800",271,
894"sub|#8834",314,
895"sube|#8838",315,
896"sup|#8835",311,
897"supe|#8839",312,
898"isin|#8712",316,
899"larr|#8592",254,
900"rarr|#8594",256,
901"uarr|#8593",255,
902"darr|#8595",257,
903"harr|#8596",253,
904"lArr|#8656",334,
905"rArr|#8658",336,
906"uArr|#8657",335,
907"dArr|#8659",337,
908"hArr|#8660",333,
909"forall|#8704","042",
910"exist|#8707","044",
911"infin|#8734",245,
912"nabla|#8711",321,
913"part|#8706",266,
914"hellip|#8230",274,
915"int|#8747",362,
916"sum|#8721",345,
917"prod|#8719",325,
918"real|#8476",302,
919"image|#8465",301,
920"bull|#8226",267,
921"prime|#8242",242,
922"Prime|#8243",262,
923"oline|#8254",140,
924"frasl|#8260",244,
925"weierp|#8472",303,
926"alefsym|#8501",300,
927"crarr|#8629",277,
928"empty|#8709",306,
929"notin|#8713",317,
930"ni|#8715","047",
931"minus|#8722","055",
932"lowast|#8727","052",
933"radic|#8730",326,
934"prop|#8733",265,
935"ang|#8736",320,
936"cap|#8745",307,
937"cup|#8746",310,
938"sim|#8764",176,
939"nsub|#8836",313,
940"oplus|#8853",305,
941"otimes|#8855",304,
942"sdot|#8901",327,
943"lceil|#8968",351,
944"rceil|#8969",371,
945"lfloor|#8970",353,
946"rfloor|#8971",373,
947"lang|#9001",341,
948"rang|#9002",361,
949"spades|#9824",252,
950"clubs|#9827",247,
951"hearts|#9829",251,
952"diams|#9830",250,
953"loz|#9674",340);
954
955$pc=')WB NL NP(';
956$nimg=-1;
957$nm=-1;
958@font=();
959@size=();
960@styl=();
961@alig=();
962@colr=();
963@topm=();
964@botm=();
965@lftm=();
966@rgtm=();
967@z1=();
968@z2=();
969@z3=();
970&Subst($doc_sep);
971($toct=$toch)=~s|<[\w/!?][^>]*>||g;
972$dh="/h0 [()($toct)] D\n";
973&Subst($toch);
974$toch=~s/  H\(/ -1 H(/g;
975$toch="($toch)";
976&varsub($toch);
977&Subst($tih);
978$tih=~s/  H\(/ -1 H(/g;
979$tih="($tih)";
980&varsub($tih);
981$mn=0;
982$nfont=0;
983$mi=0;
984for (@fo) {&setel($_)};
985%arr=%draft;
986&fs("draft");
987
988if(!$latin1 && !defined $fontid{"times"}) {
989  $fontid{"times"}=$nfont++;
990  @docfonts=(@docfonts,split(/\s+/,$font_names{"times"}));
991}
992$wind=0;
993$wf="t";
994if(!$latin1) {
995  $wind=$fontid{"times"};
996  $wf="f";
997}
998
999for $k (keys %font_files){
1000  @ff=split(/\s+/,$font_files{$k});
1001  @fn=split(/\s+/,$font_names{$k});
1002  for (0..3) {
1003    if($ff[$_]) {
1004      $ff{$fn[$_]}=$ff[$_];
1005    } elsif(!$ff{$fn[$_]}) {
1006      $ff{$fn[$_]}=$ff[0];
1007    }
1008    $fr{$fn[$_]}=$k;
1009  }
1010}
1011$pta=defined $p{"text-align"}?$p{"text-align"}:$body{"text-align"};
1012$pal=0;
1013$pal=1 if($pta=~/^c/i);
1014$pal=2 if($pta=~/^r/i);
1015$pal=3 if($pta=~/^j/i);
1016$bgcol=&col2rgb($body{"background"});
1017if(!$bgcol) {$bgcol="[16#FF 16#FF 16#FF]"};
1018if(!$p{"color"}) {$p{"color"}="black"};
1019$tcol=&col2rgb($p{"color"});
1020$lcol=&col2rgb($a__link{"color"});
1021if($lcol) {
1022  $Lc="/Lc t D\n/Dl $lcol D\n";
1023  $Lc.=$tcol ne $lcol?"/LX t D":"/LX f D";
1024} else {
1025  $Lc="/Lc f D\n/LX f D";
1026}
1027$pcol=&col2rgb($pre{"color"});
1028if(!$pcol) {$pcol="[0 0 0]"};
1029$deftbg=&col2rgb($table{"background"});
1030$hc=&col2rgb($hr{"color"});
1031if(!$hc) {$hc="[0 0 0]"};
1032$fcol=&col2rgb($frame{"color"});
1033if(!$fcol) {$fcol="[0 0 0]"};
1034for ($p{"font-size"},$pre{"font-size"},$header{"font-size"},$frame{'width'},
1035 $footer{"font-size"},$justify{'letter'},$justify{'word'},
1036 $titlepage{'margin-top'}) {
1037  &getval($_,2);
1038}
1039for ($p{"line-height"},$p{"text-indent"},$p{"margin-top"},$toc{'indent'},
1040     $ball_radius) {
1041  &getval($_,0);
1042}
1043$fl="/FL [/".join("\n/",@docfonts)."] D";
1044for $k (keys %ff) {
1045  $f=$ff{$k};
1046  if(defined $fontid{$fr{$k}} && !defined($cont{$f})) {
1047    open(FONT,"<$f") || &dbg("Error opening fontfile $f\n");
1048    ($cont{$f}=<FONT>)=~s/(^|\r?\n|\r)%.*//g;
1049    close FONT;
1050  }
1051}
1052$fontdef="";
1053for (keys %cont) {
1054  $fontdef.=$cont{$_};
1055}
1056&ent($yz);
1057&ent($xref{'text'});
1058&ent($draft{'text'});
1059
1060$lnum=0;
1061for (keys %quote_open) {
1062  $lid{$_}=$lnum++;
1063  if(!defined $quote_close{$_}) {$quote_close{$_}=$quote_open{$_}};
1064  if(!defined $quote_open2{$_}) {$quote_open2{$_}=$quote_open{$_}};
1065  if(!defined $quote_close2{$_}) {$quote_close2{$_}=$quote_close{$_}};
1066  &ent($quote_open{$_});
1067  &ent($quote_close{$_});
1068  &ent($quote_open2{$_});
1069  &ent($quote_close2{$_});
1070  push(@qo,$quote_open{$_});
1071  push(@qc,$quote_close{$_});
1072  push(@qo2,$quote_open2{$_});
1073  push(@qc2,$quote_close2{$_});
1074}
1075$qo=join(')(',@qo);
1076$qc=join(')(',@qc);
1077$qo2=join(')(',@qo2);
1078$qc2=join(')(',@qc2);
1079$hyphenation_file{''}=$hyphenation_file{'en'};
1080$br=$collapse_br?"f":"t";
1081$gd=0;
1082$ddr=defined $draft{'print'};
1083if($ddr) {
1084  if($draft{'print'}==0) {
1085    $draft="f";
1086  } else {
1087    $gd=1;
1088    $draft="t";
1089  }
1090}
1091if(-e '/dev/null' || !-e 'nul') {
1092  $pathsep=':';
1093  $gs='gs';
1094} else {
1095  $pathsep=';';
1096  $gs='gswin32c';
1097}
1098$gb=$gs_bug?"t":"f";
1099for (keys %quote) {$lid{$_}=$lid{$quote{$_}}};
1100$ENV{'PATH'}.="$pathsep$package{'path'}" if($package{'path'});
1101$delim="%-- End of variable part --";
1102$cd="/Cd {aload length 2 idiv dup dict begin {D} repeat currentdict end} D";
1103
1104$mysymb=<<EOF;
1105/MySymbol 10 dict dup begin
1106 /FontType 3 D /FontMatrix [.001 0 0 .001 0 0 ] D /FontBBox [25 -10 600 600] D
1107 /Encoding 256 array D 0 1 255{Encoding exch /.notdef put}for
1108 Encoding (e) 0 get /euro put
1109 /Metrics 2 dict D Metrics begin
1110  /.notdef 0 D
1111  /euro 651 D
1112 end
1113 /BBox 2 dict D BBox begin
1114  /.notdef [0 0 0 0] D
1115  /euro [25 -10 600 600] D
1116 end
1117 /CharacterDefs 2 dict D CharacterDefs begin
1118  /.notdef {} D
1119  /euro{newpath 114 600 moveto 631 600 lineto 464 200 lineto 573 200 lineto
1120   573 0 lineto -94 0 lineto 31 300 lineto -10 300 lineto closepath clip
1121   50 setlinewidth newpath 656 300 moveto 381 300 275 0 360 arc stroke
1122   -19 350 moveto 600 0 rlineto -19 250 moveto 600 0 rlineto stroke}d
1123 end
1124 /BuildChar{0 begin
1125  /char E D /fontdict E D /charname fontdict /Encoding get char get D
1126  fontdict begin
1127   Metrics charname get 0 BBox charname get aload pop setcachedevice
1128   CharacterDefs charname get exec
1129  end
1130 end}D
1131 /BuildChar load 0 3 dict put /UniqueID 1 D
1132end
1133definefont pop
1134EOF
1135
1136$P0=<<EOC;
1137%%Creator: $version
1138%%EndComments
1139save
11402000 dict begin
1141/d {bind def} bind def
1142/D {def} d
1143/t true D
1144/f false D
1145$fl
1146/WF $wf D
1147/WI $wind D
1148/F $opt_s D
1149/IW $wr F div D
1150/IL $hr F div D
1151/PS $pag D
1152/EF [@font] D
1153/EZ [@size] D
1154/Ey [@styl] D
1155/EG [@alig] D
1156/Tm [@topm] D
1157/Bm [@botm] D
1158/Lm [@lftm] D
1159/Rm [@rgtm] D
1160/EU [@colr] D
1161/NO $number D
1162$yz
1163/Ts EZ 0 get D
1164/TU $twoup D
1165/Xp $xp D
1166/AU $ulanch D
1167/SN $opt_N D
1168/Cf $cf D
1169/Tp $tp D
1170/Fe $fe D
1171/TI $toc{'indent'} Ts mul D
1172/Fm $d D
1173/xL $xl D
1174/xR $xr D
1175/yL $yl D
1176/yR $yr D
1177/Wl $wl F div D
1178/Wr $wr F div D
1179/hL $hl F div D
1180/hR $hr F div D
1181/FE {newpath Fm neg Fm M CP BB IW Fm add Fm L IW Fm add IL Fm add neg L CP BB
1182 Fm neg IL Fm add neg L closepath} D
1183/LA {PM 0 eq{/IW Wl D /IL hL D}{/IW Wr D /IL hR D}ie /W IW D /LL W D /LS W D
1184 TU PM 0 eq and{IW $mm F div add SA{Sf div}if 0 translate}
1185 {PM 0 eq{xL yL}{xR yR}ie translate$rot F SA{Sf mul}if dup scale
1186 CS CF FS Cf{CA CL get VC}if /Bb f D}ie 0 0 M
1187 TF not Tc or {Cf{gsave SA{1 Sf div dup scale}if Cb VC FE fill grestore}if}if}D
1188/Pi $p{"text-indent"} Ts mul D
1189/SG [$is $opt_i $msc] D
1190/Ab $justify{'word'} D
1191/J $justify{'letter'} D
1192/Tc $tc D
1193/NH $toc{'level'} D
1194/Nf $nh D
1195/Pa $pa D
1196/LH $p{"line-height"} D
1197/XR $xref D
1198/Xr {/pN E D ( $xref{'text'} )WB} D
1199/Db $bgcol D
1200/Dt $tcol D
1201/eA $ea D
1202/Fi $fi D
1203/bT $bt D
1204$Lc
1205/Br $ball_radius D
1206/IA ($imgalt) D
1207/DS {/PF f D($doc_sep)pop RC ZF} D
1208/Gb $gb D
1209/Mb $br D
1210/Hc $hc D
1211/Bl 3 D
1212/MI -$mi D
1213/DX ($draft{'text'}) D
1214/Di $draft{'dir'} D
1215/Tt $titlepage{'margin-top'} D
1216/Th {$tih} D
1217/tH {$toch} D
1218/FD $fontid{"\L$font"} D
1219/Dy $styl D
1220/cD $col D
1221/FW $frame{'width'} D
1222/FU $fcol D
1223/ET {/RM $rm D /A0 $pal D /PN SN D /OU t D /Ou t D /W IW D /LL W D D1
1224 Ms not TP and{Ip}if /TF f D} D
1225$dupl
1226$delim
1227$mysymb
1228EOC
1229
1230$reenc=<<EOD;
1231WF{FL{reencodeISO D}forall}{4 1 FL length 1 sub{FL E get reencodeISO D}for}ie
1232/Symbol dup dup findfont dup length dict begin
1233 {1 index /FID ne{D}{pop pop}ie}forall /Encoding [Encoding aload pop]
1234 dup 128 /therefore put D currentdict end definefont D
1235EOD
1236$defs=<<EOD;
1237/reencodeISO {
1238 dup dup findfont dup length dict begin{1 index /FID ne{D}{pop pop}ie}forall
1239 /Encoding ISOLatin1Encoding D currentdict end definefont} D
1240/ISOLatin1Encoding [
1241/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
1242/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
1243/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
1244/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
1245/space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright
1246/parenleft/parenright/asterisk/plus/comma/hyphen/period/slash
1247/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon
1248/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N
1249/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright
1250/asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m
1251/n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde
1252/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
1253/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
1254/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
1255/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
1256/.notdef/space/exclamdown/cent/sterling/currency/yen/brokenbar
1257/section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot
1258/hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior
1259/acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine
1260/guillemotright/onequarter/onehalf/threequarters/questiondown
1261/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla
1262/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex
1263/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis
1264/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute
1265/Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis
1266/aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave
1267/iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex
1268/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis
1269/yacute/thorn/ydieresis
1270] D
1271[128/backslash 129/parenleft 130/parenright 141/circumflex 142/tilde
1272143/perthousand 144/dagger 145/daggerdbl 146/Ydieresis 147/scaron 148/Scaron
1273149/oe 150/OE 151/guilsinglleft 152/guilsinglright 153/quotesinglbase
1274154/quotedblbase 155/quotedblleft 156/quotedblright 157/endash 158/emdash
1275159/trademark]
1276aload length 2 idiv 1 1 3 -1 roll{pop ISOLatin1Encoding 3 1 roll put}for
1277/colorimage where{pop}{
1278 /colorimage {
1279  pop pop /Pr E D {/Cv Pr D /Gr Cv length 3 idiv string D 0 1 Gr length 1 sub
1280   {Gr E dup /i E 3 mul D Cv i get 0.299 mul Cv i 1 add get 0.587 mul add
1281    Cv i 2 add get 0.114 mul add cvi put}for Gr} image} D
1282}ie
1283/pdfmark where{pop}{userdict /pdfmark /cleartomark load put}ie
1284EOD
1285
1286$P1=<<EOT;
1287$cd
1288/EX {EC cvx exec} D
1289/DU {} d
1290/BB {pop pop}d
1291/ie {ifelse} d
1292/E {exch} d
1293/M {moveto} d
1294/R {rmoveto} d
1295/L {lineto} d
1296/RL {rlineto} d
1297/CP {currentpoint} d
1298/SW {stringwidth} d
1299/GI {getinterval} d
1300/PI {putinterval} d
1301/Sg {setgray} d
1302/LW {setlinewidth} d
1303/S {dup () ne OU and{0 Co R AT 3 eq LB and HF not and A1 0 ne A2 0 ne or and
1304 {A2 0 32 A1 0 6 -1 roll awidthshow}{show}ie 0 Co neg R}{pop}ie
1305 OU PH 3 eq or{/Ms t D}if} D
1306/U {OU{gsave CP currentfont /FontInfo get /UnderlinePosition get
1307 0 E currentfont /FontMatrix get dtransform E pop add newpath M dup SW pop
1308 CJ 0 RL stroke grestore}if} D
1309/B {OU Br 0 gt and{CP Ts neg Ts .33 mul R gsave 0 Sg
1310 CP newpath Ts Br mul 0 360 arc closepath UI 2 mod 0 eq{stroke}{fill}ie
1311 grestore M CP E Ts Br 1 add mul sub E BB /Ms t D}if}D
1312/NP {Ms TP not or PA and OU and{TP{OR}if f1{mF k2 /mF E D /YC 0 D}if
1313 TP TU not PM 0 eq or and{showpage}if DU Ip TE not{LA}if 0.6 LW
1314 /CI 0 D /TP t D /Hs f D /hl 6 D /Hv 6 D /HI hi D /Ms f D}if Bs XO BO M} D
1315/Np {LE sub CP E pop gt PL 0 eq and{NP}if}D
1316/Ip {/PN PN 1 add D /Pn RM{1}{4}ie PN Ns D /PM PN SN sub 2 mod D} D
1317/GP {E dup 3 -1 roll get PN 1 add 2 mod get dup type /integertype eq
1318 {get 0 get}{E pop}ie}d
1319/Fc {dup 2 GP exec SW pop /S1 E D dup 1 GP exec SW pop /S2 E D 0 GP exec SW
1320 pop /S3 E D S1 0 gt{S2 2 mul S1 add S3 2 mul S1 add 2 copy lt{E}if pop}{0}ie
1321 S2 S3 add 2 copy lt{E}if pop IW .9 mul div dup 1 gt{1 E div}{pop 1}ie}D
1322/OR {Df{Sd}if tp not{gsave SA{1 Sf div dup scale}if Fe{Cf{FU VC}if FW LW
1323 1 setlinejoin FE stroke}if /YO {60 F div dup 40 gt{pop 40}if}D /cs CS D
1324 /cf CF D /CF 0 D /pf PF D /PF f D /Fn FN D /At AT D /AT 0 D /FN EF Hf 1 add
1325 get D Fz Fs FS ZZ Fc Fz mul Fs FS EU Hf 1 add get dup type /arraytype eq
1326 Cf and{VC}{pop 0 Sg}ie IW IL neg YO sub M ZZ 1 GP exec dup SW pop neg 0 R Sh
1327 0 IL neg YO sub M ZZ 0 GP exec Sh ZZ 2 GP exec dup SW pop IW E sub 2 div
1328 IL neg YO sub M Sh Fz Fs FS NO{/AW IW Pn SW pop sub D AW 2 div IL neg YO sub
1329 S1 0 gt S2 AW .45 mul gt or S3 AW .45 mul gt or{Fz 2 mul sub}if M Pn Sh}if
1330 EU Hf get dup type /arraytype eq Cf and{VC}{pop 0 Sg}ie YY Fc /FN EF Hf get D
1331 Hz mul HS FS IW YO M YY 1 GP exec dup SW pop neg 0 R Sh 0 YO M YY 0 GP exec Sh
1332 YY 2 GP exec dup SW pop IW E sub 2 div YO M Sh /FN Fn D /AT At D t Pb XO SZ
1333 SL get neg R /PF pf D grestore /CF 0 D cs cf FS}if}D
1334/Sh {dup () ne{CP Hz 4 div sub BB show CP CS add BB}{pop}ie}D
1335/Pb {/OU E D /Ou OU D /PB t D 0 0 M Ba{/Sa save D /BP t D /Fl t D RC /PL 0 D
1336 /PH 0 D /W IW D /LE IL .7 mul D /EO 0 D SI ZF /YA 0 D /BO 0 D /C1 () D
1337 BA 0 Ts neg R Bb{Xl Yl Xh Yh}if Bb CP Sa restore M
1338 {/Yh E D /Xh E D /Yl E D /Xl E D}if /Fl t D}if
1339 BL /OU t D /HM f D /Ou t D /PB f D} D
1340/Bs {/BP Ba not D}D
1341$defs$fontdef$reenc
1342/SF {/CS E D SZ SL CS put FO SL FN put /YI CS LH neg mul D dup ST cvs ( ) join
1343 CS ST cvs join C1 E join ( NF ) join /C1 E D CS NF /Wf WF FN 0 gt or D
1344 /BW Wf{( ) SW pop}{0}ie D}D
1345/NF {/cS E D /cF E D cF 0 ge{FL cF get}{cF -1 eq{/Symbol}{/MySymbol}ie}ie
1346 findfont cS scalefont setfont} D
1347/FS {CF or /CF E D FR SL CF put CF CF 0 ge{FN 4 mul add}if E SF} D
1348/PC {SH /BP f D fin not GL not and{NL}if /HM t D /LL LS D} D
1349/BS {/TX E D Wf{/fin f D /CW 0 D /LK 0 D /SC 0 D
1350 /RT TX D {RT ( ) search{/NW E D pop /RT E D /WH NW SW pop D CW WH add LL gt
1351 {TX SC LK SC sub 1 sub NN GI GL{SH cF cS OC
1352 2 copy cS ne E cF ne or{NF}{pop pop}ie}{PC /CW WH BW add D}ie
1353 /SC LK D}
1354 {GL{JC}if
1355 /CW CW WH add BW add D /HM t D}ie /GL f D /Ph f D
1356 /LK LK NW length 1 add add D}{pop exit}ie}loop
1357 /fin t D TX SC LK SC sub GI SH RT () ne{GL not{CC}if}if
1358 /LC TX length D /WH RT SW pop D CW WH add Hy{HC SW pop add}if LL gt
1359 {RT GL{SH cF cS OC 2 copy cS ne E cF ne or{NF}{pop pop}ie
1360 Hy{/Ph t D}if /LL LS D}{NL /LL LS D SH}ie}
1361 {RT PC Hy{CC}if /Ph Ph Hy or D}ie RT () ne{/GL t D /HM t D}if}
1362 {TX SW pop LL le{TX SH}{/NW () D 0 2 TX length 1 sub
1363 {/CW E D TX 0 CW GI dup SW pop LL gt{pop NW SH /HM t D NL/LL W XO sub MR sub D
1364 /CW CW 2 sub NN D /TX TX CW TX length CW sub GI D TX BS exit}
1365 {/NW E D}ie}for}ie}ie /HM t D}D
1366/CC {C0 length 0 gt{JC}if /C0 [C1 L1 YA YB Mf NS NB TB AF Bw] D
1367 /C1 () D /L0 L1 D /YA 0 D /YB 0 D /Mf 0 D /NS 0 D /NB 0 D}D
1368/JC {C0 aload length 0 gt{pop pop pop NB add /NB E D NS add /NS E D
1369 dup Mf gt{/Mf E D}{pop}ie dup YB gt{/YB E D}{pop}ie
1370 dup YA gt{/YA E D}{pop}ie pop C1 join /C1 E D /C0 [] D}if}D
1371/OC {C0 length 0 gt{C1 L1 L0 sub YA YB Mf NS NB TB AF Bw GL C0 aload pop
1372 /Bw E D /AF E D /TB E D /NB E D /NS E D /Mf E D /YB E D /YA E D /C0 [] D
1373 /L1 E D /C1 E D Ph{HC SH}if NL /GL E D /Bw E D /AF E D /TB E D /NB E D /NS E D
1374 /Mf E D /YB E D /YA E D /L1 E D /LL W L1 sub XO sub MR sub WH sub D /CW 0 D
1375 C1 E join /C1 E D}if}D
1376/BT {/LB t D dup length string copy RS dup dup () ne E ( ) ne and
1377 {/CI 0 D /LS LL D /LL W L1 sub XO sub MR sub D BS}
1378 {dup ( ) eq{/GL f D}if dup () eq L1 0 eq or{pop}{SH /BP f D /Ph f D}ie}ie
1379 /LB f D} D
1380/BL {CP E pop XO E M} D
1381/NL {JC /GL f D /SK W XO sub MR sub L1 sub TB{Bw add}if D
1382 /YA LF{Mf HM Fl not and PF or{LH mul}if}{0 /LF t D}ie YA 2 copy lt{E}if pop D
1383 C1 () ne{/FB YB Mf SA{Sf mul}if 4 div 2 copy lt{E}if pop D}if Fl{/Ya YA D}if
1384 CP E pop YA sub YB sub LE neg lt Fl not and PB not and{NP}if NT TL BL
1385 OU PF not and PB or{/RE L1 TB{Bw sub}if
1386 W XO sub MR sub div YA YB add LE BO add div 2 copy lt{E}if pop D
1387 RE 1 gt{BL 1 RE div dup scale}if}if
1388 AT 2 le{SK AT mul 2 div YA neg R}if
1389 AT 3 eq{0 YA neg R TB{/NB NB 1 sub D /NS NS 1 sub D}if /NB NB 1 sub NN D
1390 /A3 NS 6 mul NB add D NS NB add 0 eq
1391  {/A1 0 D /A2 0 D}
1392  {NS 0 eq{/A1 SK NB div dup J gt{pop 0}if D /A2 0 D}{J A3 mul SK lt
1393   {/A1 J D /A2 SK J NB mul sub NS div dup Ab gt{/A1 0 D pop 0}if D}
1394   {/A1 SK A3 div D /A2 A1 6 mul D}ie}ie}ie /A1 A1 NN D /A2 A2 NN D}if
1395 AT 4 eq{0 YA neg R PH 2 le{PD 0 lt{/PD L1 D}if PD M1 gt{/M1 PD D}if
1396 L1 PD sub M2 gt{/M2 L1 PD sub D}if}{DV ID 1 sub get 0 ge{Lo 0 R}if}ie}if
1397 F0 cF ne Cs cS ne or{F0 Cs NF}if
1398 /ms Ms D /Ms f D CP FB sub
1399 C1 cvx exec XO EO sub L1 add TB{BW sub}if dup LM gt{/LM E D}{pop}ie
1400 PH 0 eq PH 4 eq or Ms and{HF not{/PO t D /AH t D}if
1401 BB CP YA add E AT 3 eq LB and{A1 sub}if TB{BW sub}if E BB}
1402 {pop pop}ie Ms HM PH 3 eq and or{/BP f D /Fl f D}if
1403 /Lo 0 D /L1 0 D /F0 cF D /Cs cS D BP not{0 YB NN neg R}if
1404 OU f1 and mF not and{k2 /f1 f D}if
1405 OU PF not and PB or{RE 1 gt{RE dup scale}if}if /Ms ms Ms or D
1406 /C1 AF{(Cp )}{()}ie D /YA 0 D /YB 0 D BL
1407 AT 4 eq LB not and PH 3 ge and
1408 {ID DV length lt{DV ID get dup 0 ge{DO E sub /Lo E D /L1 Lo D}{pop}ie
1409 /ID ID 1 add D}if}if /T t D CD{/LN LN 1 add D PD}if
1410 /PD -1 D /NS 0 D /NB 0 D /TB f D /Ph f D /Mf 0 D /HM f D} D
1411/RS {/TM E D /CN 0 D TM{10 eq{TM CN ( ) PI}if /CN CN 1 add D}forall
1412 /CN 0 D /BK HM EN and{0}{1}ie D TM
1413 {dup 32 ne{TM CN 3 2 roll put /CN CN 1 add D /BK 0 D}
1414 {pop BK 0 eq{TM CN 32 put /CN CN 1 add D}if /BK 1 D}ie}forall
1415 TM 0 CN GI dup dup () ne E ( ) ne and
1416 {dup CN 1 sub get 32 eq{/EN f D}{/EN t D}ie}if} D
1417/join {2 copy length E length add string dup 4 2 roll 2 index 0 3 index
1418 PI E length E PI}d
1419/WR {(\\n) search{dup () ne BP not or
1420 {Li 4 le CP E pop YI Li mul add LE add 0 lt and PL 0 eq and{NP}if
1421 SH NL pop /Li Li 1 sub D WR}{pop pop WR}ie}{SH}ie /CI 0 D /BP f D} D
1422/SH {dup dup () ne E ( ) ne and PF or CS Mf gt and{/Mf CS D}if
1423 T not Wf and{( ) E join /T t D}if dup BP{/MF CS D}if
1424 AT 3 eq{2 copy length dup 0 gt{/NB E NB add D
1425 {( ) search{/NS NS 1 add D pop pop}{pop exit}ie}loop}{pop pop}ie}if
1426 CD PD 0 lt and{dup DC search{SW pop /PD E L1 add D pop pop}{pop}ie}if
1427 0 Np dup SW pop L1 add /L1 E D dup () ne
1428 {C1 (\\() join E join (\\)) join AU AF and UF or Wf and{( U ) join}if
1429 sF{( s ) join}if ( S ) join
1430 /C1 E D dup length 1 sub get 32 eq /TB E D /Bw BW D}{pop pop}ie} D
1431/BG {AI LG BC add add 0 eq} D
1432/ON {OU{Ty AR AI NN get dup 1 add Ln Ns Ty 2 mod 0 eq{(.  )}{(\\)  )}ie join
1433 dup SW pop neg 0 R CP E 0 lt{0 E M}{pop}ie CP BB show /Ms t D}if} D
1434/Ln {AR AI 3 -1 roll put}D
1435/SP {dup CI lt BP not and{dup CI sub 0 E R /CI E D}{pop}ie} D
1436/BN {PF{WR /HM f D}{BT NL}ie} D
1437/NN {dup 0 lt{pop 0}if} D
1438/h {(h) HI ST cvs join cvx exec dup 1 get E Nf{0 get E join}{pop}ie} D
1439/H {/fn FN D /Hi E 1 add D 1 sub /HL E D /H2 HL 2 add D /GS EZ H2 get D
1440 E Tm H2 get GS mul BE dup 0 gt{1 sub}{pop EG H2 get dup 0 lt{pop AT}if}ie NA
1441 WW Np /SL SL 1 add D /FN EF H2 get D GS Ey H2 get FS
1442 EU H2 get Sc Hs not HL Hl lt and Hs HL hl lt and or Hi 0 eq or
1443 {/HI Hi D /Hs t D /hl HL D /Hv HL D}if HL Hl lt{/hi Hi D}if
1444 Nf HI 0 gt and{(h) Hi ST cvs join cvx exec 0 get WB}if
1445 /HF t D /AH f D /PO f D} D
1446/EH {Bm H2 get GS mul BE OA /SL SL 1 sub NN D /CF 0 D /FN fn D
1447 SZ SL get FR SL get FS /HF f D /GS Ts D ()Ec} D
1448/P {E PF{WR}{PO{EP}{BN}ie Ts 4 mul Np AE not{Tm 0 get Ts mul neg SP}if
1449 dup 0 ge AH and{Pi Pd}if}ie 1 sub dup 0 lt{pop AV AL get}if /AT E D /PO t D} D
1450/EP {PF{WR}{BN Ts 4 mul Np}ie AE not{Bm 0 get Ts mul neg SP}if
1451 /AT AV AL get D /PO f D} D
1452/BE {E PO{EP}{BN}ie Ts 4 mul Np neg SP} D
1453/HR {/Aw W EO sub D /RW E dup 0 gt{Aw mul}{neg}ie dup Aw gt{pop Aw}if D /RZ E D
1454 E BN Ts neg SP 1 sub 2 div Aw RW sub mul EO add CP E pop M PF{0 Ps neg R}if
1455 0 Np OU{gsave RZ LW Cf{Hc VC}{0 Sg}ie CP BB RW 0 RL CP BB stroke grestore}if
1456 /CI 0 D /BP f D PF not{Ts neg SP}if /Ms t D} D
1457/AD {I NL EG 14 get dup 0 lt{pop AT}if NA /AE t D Tm 14 get Ts mul neg SP
1458 Cf{EU 14 get dup -1 eq{pop CA CL get}if Sc}if} D
1459/DA {BN ()ES OA /AE f D ()Ec Bm 14 get Ts mul neg SP} D
1460/PR {/MW E D /Li E D Tm 1 get Ps mul BE 0 NA /FN Fp D /PF t D SI /SL SL 1 add D
1461 /CF 0 D Ps CS mul Ts div MW WC mul CS mul Ts div dup LL gt PL 0 eq and
1462 {LL div div}{pop}ie Ey 1 get FS CP E pop LE add YI neg div cvi dup Li lt
1463 AH and{4 lt YI Li mul 5 mul LE add 0 gt or PL 0 eq and{NP}if}{pop}ie
1464 EU 1 get Sc /GS Ps D}D
1465/RP {WR NL () /PF f D SI /FN 0 D ES Bm 1 get Ps mul neg SP OA /GS Ts D} D
1466/SI {/XO Lm 15 get BC NN mul Lm 16 get AI UI sub NN mul add
1467 Lm 17 get UI NN mul add Lm 20 get LG NN mul add Ts mul
1468 PF{Lm 1 get Ps mul add}if EO add D
1469 /MR Rm 15 get BC NN mul Rm 16 get AI UI sub NN mul add
1470 Rm 17 get UI NN mul add Rm 20 get LG NN mul add Ts mul
1471 PF{Rm 1 get Ps mul add}if D /LL W XO sub MR sub D} D
1472/DT {/cC E D BN /LG LG 1 sub D SI /LG LG 1 add D WW 2 div Np BL} D
1473/DD {WB Cc 0 eq cC 0 eq and L1 0 eq or Lm 20 get Ts mul L1 sub TB{BW add}if
1474 Ts 2 div lt or NL /LF E D SI BL /cC 0 D} D
1475/DL {Dc LG Cc put /Cc E D BG{Tm 18 get Ts mul BE}{BN}ie /LG LG 1 add D BL} D
1476/LD {BN LG 0 gt{/LG LG 1 sub D}if /Cc Dc LG get D SI
1477 BG{()Bm 18 get Ts mul BE}if BL} D
1478/UL {BG{Tm 17 get Ts mul BE}{BN}ie NR AI NN 0 put /UI UI 1 add D
1479 /AI AI 1 add D SI BL} D
1480/LU {BN /UI UI 1 sub D /AI AI 1 sub D SI BG{()Bm 17 get Ts mul BE}if BL} D
1481/OL {E BG{Tm 16 get Ts mul BE}{BN}ie TR AI NN Ty put /Ty E D NR AI NN 1 put
1482 /AI AI 1 add D SI BL 1 Ln} D
1483/LO {BN /AI AI 1 sub D /Ty TR AI get D SI BG{()Bm 16 get Ts mul BE}if BL} D
1484/LI {E BN -1 SP /BP f D /CI 0 D 0 Np NR AI 1 sub NN get 1 eq
1485 {dup dup 0 gt E 4 le and{/Ty E D}{pop}ie
1486 /L1 L1 Ty AR AI NN get Ns SW pop XO sub dup 0 lt{pop 0}if add D ( ON )}
1487 {pop ( B )}ie C1 E join /C1 E D CS Mf gt{/Mf CS D}if BL} D
1488/BQ {Tm 15 get Ts mul BE /BC BC 1 add D SI BL} D
1489/QB {Bm 15 get Ts mul BE /BC BC 1 sub D SI BL} D
1490/Al {E EP 1 sub dup 0 lt{pop AV AL get}if NA} D
1491/Ea {EP OA} D
1492/WB {PF{WR}{BT}ie} D
1493/F1 {WB /FN 0 D CS 0 FS} D
1494/F2 {WB /FN WI D CS 0 FS} D
1495/HY {/Hy t D WB /Hy f D} D
1496/YH {WB} D
1497/A {/LT E D LT 1 eq{/RN E D}if /Lh E D WB /C1 C1 ( Cp ) join D
1498 Lc AF not and{Cl Sc}if /AF t D} D
1499/EA {Lc AF and{Ec}{WB}ie TL Pa AF and Lh 0 ne and
1500 {( \\() Lh join (\\)) join /AF f D WB}if /AF f D} D
1501/TL {C1 ( Tl ) apa /C1 E D} d
1502/apa {AF OU and Lh 0 ne LT 1 eq or and{LT 1 eq{RN ( /) E ST cvs join}
1503 {(\\() Lh join (\\)) join}ie E join join}{pop}ie} d
1504/Cp {/Xc CP /Yc E D D} D
1505/SS {Cf{dup 0 ge{EU E get dup -1 eq{pop CA CL get}if}{pop CA CL get}ie Sc}
1506 {pop}ie SZ SL get /SL SL 1 add D} D
1507/I {WB 8 SS 1 FS} D
1508/EM {WB 8 SS /CF CF 1 xor D 0 FS} D
1509/BD {WB 9 SS 2 FS} D
1510/TT {WB 10 SS /FN Fp D 0 FS} D
1511/KB {WB 11 SS /FN Fp D 2 FS} D
1512/CT {WB 12 SS 1 FS} D
1513/SM {WB 13 SS /FN Fp D 0 FS} D
1514/Q {/QL QL 1 add D QO QL 2 mod get La get join WB} D
1515/EQ {QC QL 2 mod get La get join WB /QL QL 1 sub D} D
1516/RO {WB -1 SS /CF 0 D 0 FS} D
1517/SY {WB -1 SS -1 FS} D
1518/MY {WB -1 SS -2 FS} D
1519/ES {WB /SL SL 1 sub NN D /CF 0 D /FN FO SL get D SZ SL get FR SL get FS ()Ec}D
1520/FZ {3 sub 1.2 E exp GS mul E WB TL /C1 C1 ( Cp ) join D /SL SL 1 add D 0 FS} D
1521/Ef {WB TL ()ES /C1 C1 ( Cp ) join D} D
1522/BZ {dup /Bf E D FZ}D
1523/Sc {dup -1 ne Cf and{/CL CL 1 add D dup 0 eq{pop [0 0 0]}if
1524 dup CA E CL E put VS ( VC ) join C1 E join /C1 E D}{pop}ie} D
1525/Ec {WB Cf{/CL CL 1 sub NN D CA CL get VS ( VC ) join C1 E join /C1 E D}if} D
1526/VS {dup type /arraytype eq{([) E {ST cvs join ( ) join}forall (]) join}if} D
1527/VC {{255 div}forall setrgbcolor} D
1528/Sl {dup type /integertype ne{Ds}if /La E D WB}d
1529/UN {WB /UF t D} D
1530/NU {WB /UF f D} D
1531/SE {WB /sF t D} D
1532/XE {WB /sF f D} D
1533/sM {/C1 C1 ( k1 ) join D}d
1534/eM {/C1 C1 ( k2 ) join D}d
1535/k1 {/YC CP E pop Ts add D /mF t D /f1 t D}d
1536/k2 {gsave 3 LW -9 CP E pop Ts 0.2 mul sub M -9 YC L stroke grestore /mF f D}d
1537/Ac {/AC E D WB}d
1538/Ca {eA{( \\()join AC join(\\) )join}if WB}d
1539/s {OU{gsave 0 CS .25 mul R dup SW pop CJ 0 RL stroke grestore}if}D
1540/CJ {AT 3 eq LB and{E dup dup length 1 sub A1 mul E
1541 {( ) search{pop pop E A2 add E}{pop exit}ie}loop 3 -1 roll add
1542 W CP pop sub 2 copy gt{E}if pop}if}D
1543/So {/Co E D} D
1544/SO {C1 Yo ST cvs join ( So ) join /C1 E D (j) SW pop 2 div Pd} D
1545/Se {E WB CS E div Pd}D
1546/Pd {dup type /stringtype eq{SW pop}if dup /L1 E L1 add D
1547 ST cvs ( 0 R ) join C1 E join /C1 E D} D
1548/Sp {0.35 CO} D
1549/Sb {-0.2 CO} D
1550/CO {OV Io Yo put /Yo E CS mul Yo add D /Io Io 1 add D -1.5 Io mul 3 add FZ SO
1551 CS Yo add dup YA gt{/YA E D}{pop}ie
1552 Yo neg dup YB gt{/YB E D}{pop}ie} D
1553/Es {ES /Io Io 1 sub NN D /Yo OV Io get D SO} D
1554/SB {/N2 0 D 0 1 NI{/N E D{IX N2 get 0 lt{/N2 N2 1 add D}{exit}ie}loop
1555 /K WS N get FC N get mul D /NY AY N2 get D /BV NY array D
1556 0 1 NY 1 sub{/TM K string D currentfile TM readhexstring pop pop BV E TM put}
1557 for BM N BV put /N2 N2 1 add D}for} D
1558/IC [{/MA E D /MB 0 D}{2 div /MA E D /MB MA D}{/MB E CS sub D /MA CS D}
1559 {pop /MA YS AB mul D /MB 1 AB sub YS mul D}{pop /MA 0 D /MB 0 D}] D
1560/IP {BV N get /N N 1 add D} D
1561/II {/K E D IX K get 0 lt{/EC E D}if /TY E D
1562 TY 4 eq{/Y E D /X E D}if TY 3 eq{/AB E D}if
1563 /XW AX K get D /YW AY K get D /IS SG IT K get get D /XS XW IS mul D
1564 /YS YW IS mul D YS IC TY get exec /MA MA Fl not{3 add}if D} D
1565/IM {II /ty TY D /xs XS D /ys YS D /ya YA D /yb YB D /ma MA D /mb MB D /k K D
1566 /ec EC D /BP f D /CI 0 D WB TL L1 xs add dup XO add MR add W gt
1567 {pop /ma ma Fl{3 add}if D NL /YA ma D /YB mb D /YS ys D /L1 xs D}
1568 {/L1 E D ma YA gt{/YA ma D}if mb YB gt{/YB mb D}if}ie /TB f D
1569 OU{CP E pop YS sub LE neg lt Fl not and PB not and{NP /YA ma D /YB mb D}if
1570 /BP f D ty ST cvs ( ) join IX k get 0 lt{(\\() join ec join (\\) ) join}if
1571 k ST cvs join ty 3 eq{AB ST cvs ( ) join E join}if
1572 ty 4 eq{X ST cvs ( ) join Y ST cvs join ( ) join E join}if C1 E join
1573 ( DI ) join FP 2 eq FP 1 eq AF and or{( FM ) join}if
1574 ( Il Cp ) apa /C1 E D /EN f D}if /HM t D /T f D} D
1575/DI {II /Xc CP /Yc E D D /YN YW neg D /HM t D /CI 0 D /K2 IX K get D gsave
1576 TY 4 eq{OX X IS mul add OY FY add YS sub Y IS mul sub}
1577 {/FY YS D CP MB sub 2 copy /OY E D /OX E D}ie
1578 translate K2 0 ge{/DP AZ K2 get D /BV BM K2 get D XS YS scale /N 0 D XW YW DP
1579 [XW 0 0 YN 0 YW] {IP} FC K2 get 1 eq{image}{f 3 colorimage}ie}
1580 {EX}ie grestore XS 0 R /Ms t D} D
1581/FM {gsave 0 Sg CP MB sub translate XS neg 0 M 0 YS RL XS 0 RL 0 YS neg RL
1582 XS neg 0 RL stroke grestore} D
1583/NA {/AT E D /AL AL 1 add D AV AL AT put} D
1584/OA {AL 0 gt{/AL AL 1 sub D /AT AV AL get D}if} D
1585/D1 {/BR {CP E pop E BN Mb{CP E pop eq{0 YI R}if}{pop}ie} D
1586 /Sn {OU{C1 E ST cvs join ( Ld ) join /C1 E D}{pop}ie} D} D
1587/D1 {/BR {BN} D /Sn {OU {C1 E ST cvs join ( Ld ) join /C1 E D} {pop} ie} D} D
1588/TC {/TF t D /ML 0 D HN{SW pop dup ML gt{/ML E D}{pop}ie}forall NP /RM RM not D
1589 RC /OU Tc D Ep /PN 0 D Ms not TP and{Ip}if /W IW ML sub Ts sub D
1590 /A0 0 D TH{/BR {( ) join BT} D /Sn {pop} D /Au () D}if} D
1591/TN {0 eq{E EA PF HF or not XR and{HN E get Xr}{pop}ie}
1592 {OU{Tn 0 ge{() BN}if /Tn E D}{pop}ie WB}ie} D
1593/NT {OU LB not and Tn 0 ge and{PL 0 eq{Ms not{CS CF FS}if CP dup
1594 /y E YA sub D W 9 sub CS -1.8 mul XO L1 add 2 add{y M (.) show}for
1595 HN Tn get dup SW pop IW E sub y M show CP BB M}if /Tn -1 D}if} D
1596/Ld {/DN E D HN DN Pn put [/View [/XYZ -4 Fl{PS}{CP YA add US E pop}ie null]
1597 /Dest DN ST cvs cvn /DEST pdfmark} D
1598/C {ND 1 eq{1 sub}if TI mul /XO E D NL Nf not{pop()}if 0 3 -1 roll 1 A} D
1599/OP {BP not{NP}if PN 2 mod 0 eq{/Ms t D NP}if}D
1600/Ep {Xp PN 2 mod 0 eq and OU and{/Pn (-) D showpage /PM 1 D LA}if}D
1601/Dg [73 86 88 76 67 68 77] D
1602/Rd [0 [1 1 0][2 1 0][3 1 0][2 1 1][1 1 1][2 2 1][3 3 1][4 4 1][2 1 2]] D
1603/Ns {/m E D /c E 32 mul D /j m 1000 idiv D /p j 12 add string D
1604 c 96 le m 0 gt and{c 32 le {/i 0 D /d 77 D /l 100 D /m m j 1000 mul sub D
1605  j -1 1 {pop p i d c add put /i i 1 add D}for
1606  4 -2 0 {/j E D /n m l idiv D /m m n l mul sub D /d Dg j get D
1607   n 0 gt {/x Rd n get D x 0 get -1 1 {pop p i d c add put /i i 1 add D}for
1608   p i x 1 get sub Dg x 2 get j add get c add put}if /l l 10 idiv D
1609  }for p 0 i GI}
1610  {/i ST length 1 sub D m {1 sub dup 0 ge{dup 26 mod c add 1 add
1611   ST i 3 -1 roll put 26 idiv dup 0 eq{pop exit}if}if /i i 1 sub D}loop
1612   ST i ST length i sub GI}ie}
1613 {m p cvs}ie} D
1614/US {matrix currentmatrix matrix defaultmatrix matrix invertmatrix
1615 matrix concatmatrix transform} D
1616/GB {Gb{US}if}D
1617/Tl {/Rn E D Xc CP pop ne{
1618 [/Rect [Xc 1 sub Yc cS 0.25 mul sub GB CP E 1 add E cS 0.85 mul add GB]
1619  /Subtype /Link /Border [0 0 Cf Lc and LX and AU or{0}{1}ie] Rn type
1620  /nametype eq {/Dest Rn}{/Action [/Subtype /URI /URI Rn] Cd}ie
1621  /ANN pdfmark}if} D
1622/Il {/Rn E D [/Rect [Xc Yc GB Xc XS add Yc YS add GB] /Subtype /Link
1623 /Border [0 0 0] Rn type /nametype eq{/Dest Rn}
1624 {/Action [/Subtype /URI /URI Rn] Cd}ie /ANN pdfmark} D
1625/XP {[{/Z Bz 2 div D Z 0 R Z Z RL Z neg Z RL Z neg Z neg RL Z Z neg RL
1626 Fi cH 1 eq and{fill}if} {Bz 0 RL 0 Bz RL Bz neg 0 RL 0 Bz neg RL
1627 Fi cH 1 eq and{fill}if} {0 -5 R Bz 0 RL 0 21 RL Bz neg 0 RL 0 -21 RL}]} D
1628/MS {/Sm E D WB}D
1629/O {BN()Sm BX} D
1630/O {BN()0 Sm BX} D
1631/BX {/Bt E D Bt 2 lt{/Ch E D CS 0.8 mul}{11 mul}ie W XO sub MR sub
1632 2 copy gt{E}if pop /HZ E D Bt 2 eq{Fi not{pop()}if ( )E join /Ft E D TT
1633 /PF t D /MW 1 D /Li 1 D /Fw Ft SW pop D Fw HZ gt{/HZ Fw 8 add D}if
1634 HZ ST cvs( )join}{WB Ch ST cvs( )join}ie L1 HZ add XO add MR add W gt{NL}if
1635 Bt 2 eq{Ft ES Fw neg HM{CS sub}if Pd}if Bt ST cvs join( Bx )join
1636 Bt 2 eq HM and{CS Pd}if C1 E join /C1 E D /L1 L1 HZ add D /T f D
1637 ( ) Pd /PF f D Bt 2 lt{YA CS .8 mul lt{/YA CS .8 mul D}if}
1638 {YB 5 lt{/YB 5 D}if YA 21 lt{/YA 21 D}if}ie /CI 0 D} D
1639/Bx {dup 2 eq{E /Bz E D}{E /cH E D /Bz CS .8 mul D}ie
1640 OU {gsave 0 Sg XP E get exec stroke grestore}{pop}ie Bz 0 R /Ms t D}D
1641/SD {FD 4 mul Dy add DZ NF newpath 0 0 M DX t charpath pathbbox
1642 3 -1 roll sub /DY E D E dup /X1 E D sub WM mul WX DY mul add WM DG mul E div
1643 /DF E D /DR WX DF mul DY mul WM div 2 div D} d
1644/Sd {gsave 0 IL Di mul neg translate IL IW atan Di 0 eq{neg}if rotate
1645 FD 4 mul Dy add DZ NF DR X1 sub DY 2 div neg M cD VC DX show grestore} d
1646/Pt {/tp t D Tp{NP /Pn (TP) D 0 Tt neg R Th BN NP Ep ET RC ZF}if /tp f D} D
1647/RC {/AI 0 D /LG 0 D /BC 0 D /UI 0 D /PF f D /Cc 0 D /cC 0 D /Dc 10 array D
1648 /NR [0 1 9{pop 0}for] D /La Ds D /AR 10 array D /TR 10 array D /AV 30 array D
1649 SI /AL -1 D /AT A0 D AT NA /OV 9 array D /Yo 0 D /Co 0 D /Io 0 D /Hy f D
1650 /Ph f D /CL -1 D Ct Sc}D
1651/ZF {/FR [0 1 30{pop 0}for] D /SZ [0 1 30{pop 0}for] D /FO [0 1 30{pop 0}for] D
1652 /SL 0 D /CF 0 D /FN 0 D 0 Ts SF}D
1653/QO [[($qo)][($qo2)]] D
1654/QC [[($qc)][($qc2)]] D
1655/Hf EF length 2 sub D
1656/Hz EZ Hf get D
1657/HS Ey Hf get D
1658/Fz EZ Hf 1 add get D
1659/Fs Ey Hf 1 add get D
1660/LE IL D
1661/Ps EZ 1 get D
1662/Fp EF 1 get D
1663/XO 0 D
1664/YI 0 D
1665/CI 0 D
1666/FP 0 D
1667/WW Ts 7 mul D
1668/Mf 0 D
1669/YA 0 D
1670/YB 0 D
1671/Cs Ts D
1672/GS Ts D
1673/F0 0 D
1674/NS 0 D
1675/NB 0 D
1676/N 0 D
1677/C0 [] D
1678/C1 () D
1679/Lo 0 D
1680/L1 0 D
1681/LM 0 D
1682/PH 0 D
1683/EC 0 D
1684/Lh 0 D
1685/LT 0 D
1686/CH 1 string D
1687/ST 16 string D
1688/CA 9 array D
1689/HC (\\255) D
1690/HM f D
1691/PF f D
1692/EN f D
1693/TB f D
1694/UF f D
1695/sF f D
1696/AE f D
1697/AF f D
1698/BP t D
1699/CD f D
1700/PA t D
1701/GL f D
1702/T t D
1703/HF f D
1704/AH f D
1705/SA f D
1706/PB f D
1707/f1 f D
1708/mF f D
1709/OX 0 D
1710/OY 0 D
1711/FY 0 D
1712/EO 0 D
1713/FB 0 D
1714/PL 0 D
1715/Bw 0 D
1716/PD -1 D
1717/TP f D
1718/tp f D
1719/TH $th D
1720/Ty 4 D
1721/Tn -1 D
1722/Fl t D
1723/LB t D
1724/PM 1 D
1725/Ms f D
1726/Ba f D
1727/Bb f D
1728/Hl 3 D
1729/hl 6 D
1730/Hv 6 D
1731/Hs f D
1732/HI 0 D
1733/hi 0 D
1734/PO t D
1735/TE f D
1736/LF t D
1737/BO 0 D
1738/Sm 1 D
1739/Bf 3 D
1740/A1 0 D
1741/A2 0 D
1742/Ds $lid{'en'} D
1743/QL -1 D
1744/Cb Db D
1745/Ct Dt D
1746/Cl Dl D
1747EOT
1748
1749$tbl=<<EOT;
1750/TS {
1751 tables E get /table E D
1752 table aload pop /rdesc E D /cdesc E D /tdesc E D
1753 tdesc aload pop /capalg E D /caption E D /rules E D /frame E D /nfoot E D
1754  /nhead E D /ncol E D /nrow E D /border E D /twid E D /units E D /talign E D
1755  /flow E D /clear E D /tclass E D pop pop
1756 /w W D /eps 0.1 D /OU f D /PL 1 D
1757 /FN EF 21 get D EZ 21 get Ey 21 get FS
1758 0 1 1{
1759  /pass E D
1760  0 1 nrow{
1761   /irow E D
1762   /cells rdesc irow get 6 get D
1763   0 1 ncol{
1764    /icol E D
1765    /cell cells icol get D
1766    cell 0 ne{
1767     cell aload pop /ang E D /CB E D pop pop pop
1768     /DV E D /bot E D /top E D /right E D /left E D /nowrap E D /valign E D
1769     /dp E D /align E D /rspan E D /cspan E D /cclass E D /ctype E D /cmax E D
1770     /cmin E D /proc E D
1771     rspan 0 eq{/rspan nrow irow sub 1 add D}if
1772     cspan 0 eq{/cspan ncol icol sub 1 add D}if
1773     pass 0 eq cspan 1 eq and pass 1 eq cspan 1 gt and or{
1774      /W 1e5 D /LL W D /PH 1 D
1775      ctype 1 eq{() BD}if
1776      RC align NA
1777      AT 4 eq{/CD t D /DC dp D /LN 0 D /M1 0 D /M2 0 D}{/CD f D}ie
1778      0 0 M /LM 0 D proc exec BN
1779      AT 4 eq{
1780       LN array astore cell 15 3 -1 roll put
1781       cdesc icol get dup dup 5 get M1 lt{5 M1 put}{5 get /M1 E D}ie
1782       dup 6 get M2 lt{6 M2 put}{6 get /M2 E D}ie
1783       /LM M1 M2 add D
1784      }if
1785      /CD f D
1786      ang 0 ne{/LM CP E pop neg D}if
1787      /thiswid LM left add right add eps add D
1788      /oldmin 0 D /oldmax 0 D
1789      0 1 cspan 1 sub{
1790       icol add cdesc E get dup 2 get /oldmax E oldmax add D
1791       1 get /oldmin E oldmin add D
1792      }for
1793      thiswid oldmax ge{
1794       0 1 cspan 1 sub{
1795        icol add cdesc E get dup 2 E 2 get oldmax 0 eq
1796         {pop thiswid cspan div}{thiswid mul oldmax div}ie
1797        put
1798       }for
1799      }if
1800      nowrap 1 eq{
1801       thiswid oldmin ge{
1802        0 1 cspan 1 sub{
1803         icol add cdesc E get dup 1 E 1 get oldmin 0 eq
1804          {pop thiswid cspan div}{thiswid mul oldmin div}ie
1805         put
1806        }for
1807       }if
1808      }{
1809       /W 0 D /LL W D /PH 2 D
1810       ctype 1 eq{() ES () BD}if
1811       0 0 M /LM 0 D RC proc exec BN
1812       /thiswid LM left add right add eps add D
1813       thiswid oldmin ge{
1814        0 1 cspan 1 sub{
1815         icol add cdesc E get dup 1 E 1 get oldmin 0 eq
1816          {pop thiswid cspan div}{thiswid mul oldmin div}ie
1817         put
1818        }for
1819       }if
1820      }ie
1821      ctype 1 eq{() ES}if
1822     }if
1823    }if
1824   }for
1825  }for
1826 }for
1827 /tmin 0 D /tmax 0 D
1828 0 1 ncol{
1829  cdesc E get dup 1 get E 2 get 2 copy gt{pop dup}if
1830  tmax add /tmax E D tmin add /tmin E D
1831 }for
1832 twid 0 lt{twid neg IW gt{IW neg}{twid}ie /twid E D}if
1833 tdesc 0 twid neg tmin 2 copy lt{E}if pop put
1834 tdesc 1 twid neg tmax 2 copy lt{E}if pop put
1835 /W w D /LL W D /OU t D /PH 0 D /PL 0 D
1836} D
1837/PT {
1838 /PL PL 1 add D
1839 tables E get /table E D Tm 21 get Ts mul BE
1840 PL 2 ge{save}if
1841 /SL SL 1 add D /FN EF 21 get D EZ 21 get Ey 21 get FS
1842 table aload pop /rdesc E D /cdesc E D /tdesc E D
1843 tdesc aload pop /capalg E D /caption E D /rules E D /frame E D /nfoot E D
1844  /nhead E D /ncol E D /nrow E D /border E D /twid E D /units E D /talign E D
1845  /flow E D /clear E D /tclass E D /tmax E D /tmin E D
1846 /w W D /xo XO D /mr MR D /ll LL D /lg LG D /ai AI D /bc BC D /nr NR D /ar AR D
1847 /tr TR D /ui UI D /ph PH D /a0 A0 D /pf PF D /at AT D /av AV D /al AL D
1848 /Le LE D /la La D
1849 talign 0 lt{/talign AL 0 gt{AV AL get}{A0 2 le{A0}{0}ie}ie D}if
1850 ph 1 eq ph 2 eq or{
1851  NL ph 1 eq{tmax}{tmin}ie dup XO add LM gt{/LM E XO add D}{pop}ie LM E
1852 }{
1853  /PH 3 D /LE 1e5 D RC %ZF
1854  border 0 gt{/border 1 D}if
1855  /twidth 0 D /avail W xo sub D
1856  twid 0 eq{0 1 ncol{cdesc E get dup 2 get E 3 get dup 0 gt{div neg dup twid lt
1857   {/twid E D}{pop}ie}{pop pop}ie}for}if
1858  /twid twid dup 0 lt{neg avail 2 copy gt{E}if pop}{avail mul}ie D
1859  /OK t D 0 1 ncol{cdesc E get dup 1 get E 3 get twid mul gt{/OK f D}if}for
1860  0 1 ncol{
1861   cdesc E get dup 1 get /colmin E D dup 3 get /cwid E twid mul D dup
1862   tmax avail le{2 get}if
1863   tmin avail le tmax avail gt and{
1864    dup 2 get E 1 get dup 3 1 roll sub avail tmin sub mul tmax tmin sub div add
1865   }if
1866   tmin avail gt{1 get}if
1867   0 E colmin cwid lt OK and{pop cwid}if dup /twidth E twidth add D put
1868  }for
1869  /OU f D CP
1870  tmin twid le{
1871   0 1 ncol{cdesc E get dup 0 get twidth div twid mul 0 E put}for
1872   /twidth twid D
1873  }if
1874  CP printcap CP E pop sub /caphig E D pop
1875  0 1 1{
1876   /pass E D
1877   0 1 nrow{
1878    /irow E D
1879    /cells rdesc irow get 6 get D
1880    0 1 ncol{
1881     /icol E D
1882     /cell cells icol get D
1883     cell 0 ne{
1884      cell aload pop /ang E D /CB E D pop pop pop
1885      /DV E D /bot E D /top E D /right E D /left E D /nowrap E D /valign E D
1886      /dp E D /align E D /rspan E D /cspan E D /cclass E D /ctype E D /cmax E D
1887      /cmin E D /proc E D
1888      rspan 0 eq{/rspan nrow irow sub 1 add D}if
1889      cspan 0 eq{/cspan ncol icol sub 1 add D}if
1890      /W 0 D
1891      0 1 cspan 1 sub{icol add cdesc E get 0 get /W E W add D}for
1892      pass 0 eq rspan 1 eq and pass 1 eq rspan 1 gt and or{
1893       ctype 1 eq{() BD}if
1894       /W W left sub right sub D /XO 0 D /EO 0 D SI
1895       /A0 align D RC align NA
1896       AT 4 eq{
1897        /DC dp D /DO 0 D /ID 1 D
1898        0 1 DV length 1 sub{DV E get dup DO gt{/DO E D}{pop}ie}for
1899        /Lo DO DV 0 get sub D /L1 Lo D
1900       }if
1901       0 0 M /BP t D /Fl t D /MF 0 D /FB 0 D
1902       proc exec T not{/CI 0 D}if BN 0 FB neg R MF 0 eq{/MF CS D}if
1903       CP /thishig E neg bot add top add CI add D pop
1904       ang 0 ne{/thishig LM bot add top add D}if
1905       cell 16 MF put cell 17 Ya put cell 18 thishig put
1906       valign 4 eq{
1907        /below thishig Ya sub D
1908        rdesc irow get dup dup 4 get Ya lt
1909         {4 Ya put}{4 get /Ya E D}ie
1910        dup 5 get below lt{5 below put}{5 get /below E D}ie
1911        /thishig Ya below add D
1912       }if
1913       ctype 1 eq{()ES}if
1914       /oldhig 0 D
1915       0 1 rspan 1 sub{
1916        irow add rdesc E get 0 get /oldhig E oldhig add D
1917       }for
1918       thishig oldhig ge{
1919        0 1 rspan 1 sub{
1920         irow add rdesc E get dup 0 E 0 get oldhig 0 eq
1921          {pop thishig rspan div}{thishig mul oldhig div}ie
1922         put
1923        }for
1924       }if
1925      }if
1926     }if
1927    }for
1928   }for
1929  }for M RC %ZF
1930  /thight 0 D /racc 0 D /maxh 0 D /brk 0 D /rbeg nhead nfoot add D
1931  0 1 nrow{
1932   rdesc E get dup 0 get dup /thight E thight add D
1933   brk 0 eq{/racc E D}{/racc E racc add D}ie
1934   racc maxh gt{/maxh racc D}if 2 get /brk E D
1935  }for
1936  ph 3 ge{thight caphig add E}if
1937  ph 0 eq ph 4 eq or{
1938   /PH 4 D /LE Le D /OU Ou D /yoff 0 D /headsz 0 D
1939   0 1 nhead 1 sub{rdesc E get 0 get headsz add /headsz E D}for
1940   /footsz 0 D
1941   0 1 nfoot 1 sub{rdesc E nhead add get 0 get footsz add /footsz E D}for
1942   /ahig LE BO add MI add D /maxh maxh headsz add footsz add D
1943   /thight thight headsz add footsz add D
1944   tmin avail gt maxh ahig gt or
1945    {/Sf avail tmin div dup ahig maxh div gt{pop ahig maxh div}if D /SA t D}
1946    {/Sf 1 D}ie
1947   tclass 1 eq thight LE 15 sub gt and
1948    {/SA t D LE 15 sub thight div dup Sf lt{/Sf E D}{pop}ie}if
1949   SA{Sf Sf scale /ll ll Sf div D /xo xo Sf div D /LE LE Sf div D
1950    /mr mr Sf div D /BO BO Sf div D /ahig ahig Sf div D}if
1951   nhead nfoot add getwid
1952   LE CP E pop add capalg 0 eq{caphig sub}if
1953   bT{f}{dup thight lt thight ahig lt and}ie
1954   E headsz sub footsz sub rwid lt or{NP}if
1955   capalg 0 eq{printcap -8 SP}if
1956   CP /ycur E D pop
1957   printhead
1958   rbeg 1 nrow{/row E D row
1959    getwid
1960    ycur yoff add rwid sub footsz sub LE add 0 lt
1961    {nfoot 0 gt{printfoot}if Tf NP /rbeg irow1 D
1962     Ba{MI /MI MI SA{Sf div}if D MI SP /MI E D}if
1963     CP /ycur E D pop /yoff 0 D printhead}if
1964    irow1 printrow
1965   }for
1966   printfoot /row row 1 add D Tf
1967   0 ycur yoff add M
1968   capalg 1 eq{/EO 0 D SI -3 SP printcap}if
1969   Sf 1 lt{1 Sf div dup scale /ll ll Sf mul D /xo xo Sf mul D /LE LE Sf mul D
1970    /mr mr Sf mul D /BO BO Sf mul D /SA f D}if
1971   /EO 0 D
1972  }if
1973 }ie
1974 /W w D /XO xo D /MR mr D /LL ll D /LG lg D /AI ai D /BC bc D /NR nr D /AR ar D
1975 /TR tr D /UI ui D /PH ph D /A0 a0 D /PF pf D /AT at D /AV av D /AL al D
1976 /La la D
1977 /SL SL 1 sub NN D /CF 0 D /FN 0 D SZ SL get FR SL get FS Wf not{()F2}if
1978 PL 2 ge{Ms E restore Ms or /Ms E D PH 1 eq PH 2 eq or
1979  {/LM E D}if PH 3 ge{/CI 0 D NL 0 E neg R}if
1980 }if
1981 /PL PL 1 sub D /CI 0 D /BP f D /PO f D () Bm 21 get Ts mul BE BL %CF CS SF
1982} D
1983/printcap{
1984 capalg 0 ge{
1985  SA{/W w Sf div D}
1986   {talign 1 eq{/XO xo ll twidth sub 2 div add D}if
1987    talign 2 eq{/XO xo ll twidth sub add D}if
1988    /W XO twidth add D
1989   }ie /XO xo D /LL W XO sub MR sub D
1990  /PA f D /Fl capalg 0 eq D
1991  1 NA BL caption exec BN OA /PA t D
1992 }if
1993} D
1994/getwid{
1995 /irow1 E D
1996 /irow2 irow1 D
1997 /rwid 0 D
1998 {rdesc irow2 get dup 0 get rwid add /rwid E D 2 get 0 eq
1999  {exit}{/irow2 irow2 1 add D}ie
2000 }loop
2001} D
2002/printrow{
2003 /xoff ll twidth PL 2 ge{Sf div}if sub talign mul 2 div D
2004 /xleft xoff xo add D
2005 /irow E D
2006 /cells rdesc irow get 6 get D
2007 0 1 ncol{
2008  /icol E D
2009  /cell cells icol get D
2010  cell 0 ne{
2011   cell aload pop /ang E D /CB E D /cvsize E D /above E D /fontsz E D
2012   /DV E D /bot E D /top E D /right E D /left E D /nowrap E D /valign E D
2013   /dp E D /align E D /rspan E D /cspan E D /cclass E D /ctype E D /cmax E D
2014   /cmin E D /proc E D
2015   rspan 0 eq{/rspan nrow irow sub 1 add D}if
2016   cspan 0 eq{/cspan ncol icol sub 1 add D}if
2017   /width 0 D
2018   0 1 cspan 1 sub{icol add cdesc E get 0 get /width E width add D}for
2019   /rhight rdesc irow get 0 get D
2020   /hight rhight D
2021   1 1 rspan 1 sub{irow add rdesc E get 0 get /hight E hight add D}for
2022   /W xo xoff add width add right sub D
2023   ang 0 ne{/W xo xoff add hight add right sub D}if
2024   /EO xo xoff add left add D SI
2025   Cf{
2026    gsave CB VC xo xoff add ycur yoff add M
2027    0 hight neg RL width 0 RL 0 hight RL width neg 0 RL fill
2028    grestore
2029   }if
2030   ctype 1 eq{() BD}if
2031   /A0 align D RC
2032   AT 4 eq{
2033    /DC dp D /ID 1 D /DO cdesc icol get 5 get D /Lo DO DV 0 get sub D /L1 Lo D
2034   }if
2035   ang 0 ne{
2036    gsave ang 90 eq
2037     {xoff ycur add hight cvsize sub 2 div sub ycur hight sub xoff sub}
2038     {xoff ycur sub width add hight cvsize sub 2 div add ycur xoff add}ie
2039    translate ang rotate
2040   }if
2041   valign 3 le{0 ycur yoff add top sub
2042    hight cvsize sub valign 1 sub mul 2 div sub M}
2043   {0 ycur yoff add top sub above add rdesc irow get 4 get sub M}ie
2044   /PA f D /BP t D /Fl t D
2045   BL proc exec BN
2046   ang 0 ne{grestore}if
2047   /PA t D
2048   ctype 1 eq{() ES}if
2049  }if
2050  /xoff xoff cdesc icol get 0 get add D
2051 }for
2052 /yoff yoff rhight sub D
2053} D
2054/printhead {0 1 nhead 1 sub{printrow}for} D
2055/printfoot {nhead 1 nhead nfoot add 1 sub{printrow}for} D
2056/Tf {
2057 OU{rules 2 ge{/yoff 0 D
2058   gsave 0 Sg
2059   [0 1 nhead 1 sub{}for rbeg 1 row 1 sub{}for nhead 1 nhead nfoot add 1 sub{}for]{
2060    /irow E D
2061    /xoff ll twidth PL 2 ge{Sf div}if sub talign mul 2 div D
2062    /cells rdesc irow get 6 get D
2063    0 1 ncol{
2064     /icol E D
2065     /cell cells icol get D
2066     cell 0 ne{
2067      /rspan cell 6 get D
2068      /cspan cell 5 get D
2069      rspan 0 eq{/rspan nrow irow sub 1 add D}if
2070      cspan 0 eq{/cspan ncol icol sub 1 add D}if
2071      /width 0 D
2072      0 1 cspan 1 sub{icol add cdesc E get 0 get /width E width add D}for
2073      /rhight rdesc irow get 0 get D
2074      /hight rhight D
2075      1 1 rspan 1 sub{irow add rdesc E get 0 get /hight E hight add D}for
2076      xo xoff add width add ycur yoff add M
2077      0 hight neg icol cspan add 1 sub ncol lt
2078       {cdesc icol 1 add get 4 get dup rules 3 le{1 eq}{pop t}ie
2079        {1 eq{0.8}{0.3}ie
2080        LW RL CP stroke M}{pop R}ie}{R}ie
2081      irow nhead nfoot add 1 sub ne nfoot 0 eq or
2082       {irow rspan add 1 sub nrow lt
2083       {rdesc irow rspan add get 3 get}{nfoot 0 eq{0}{1}ie}ie
2084       dup rules 2 mod 0 eq{1 eq}{pop t}ie
2085       {1 eq irow rspan add nhead eq or irow rspan add row eq nfoot 0 gt and or
2086        {0.8}{0.3}ie LW width neg 0 RL CP stroke M}{pop}ie}if
2087     }if
2088     /xoff xoff cdesc icol get 0 get add D
2089    }for
2090    /yoff yoff rhight sub D
2091   }forall
2092   grestore
2093   /Ms t D
2094  }if
2095  frame 1 gt{
2096   gsave
2097   1 LW 0 Sg
2098   xleft ycur M CP BB
2099   0 yoff frame 5 eq frame 7 ge or{RL}{R}ie
2100   twidth 0 frame 3 eq frame 4 eq or frame 8 ge or{RL}{R}ie CP BB
2101   0 yoff neg frame 6 ge{RL}{R}ie
2102   twidth neg 0 frame 2 eq frame 4 eq or frame 8 ge or{RL}{R}ie
2103   closepath stroke
2104   grestore
2105   /Ms t D
2106  }if
2107 }if
2108} D
2109EOT
2110
2111&openps if($opt_o);
2112$ntab=-1;
2113$tables="/tables [";
2114@docs=$#ARGV<0?("-"):@ARGV;
2115if($tocdoc) {$#docs=0};
2116for (@docs) {$levl{$_}=1};
2117$nref=0;
2118$nhd=0;
2119$nlnk=1;
2120$ndoc=0;
2121$nrem=0;
2122$toc=$first?"Pt\n":"";
2123$toc.="/BO 0 D TC /Ba f D Bs /AU f D /UR () D RC ZF\n";
2124$toc.="()F2" if(!$latin1);
2125$toc.=" tH WB\n" if(!$tocdoc);
2126$fl1="";
2127$fl2="";
2128$np="NP RC ZF";
2129$P3="";
2130while($html=shift @docs) {
2131  $ndoc++;
2132  $ba2="";
2133  $P2="(";
2134  $banner="";
2135  undef @links;
2136  $level=$levl{$html};
2137  if(&h2p) {
2138    if($ndoc==1) {
2139      $toc=~s/\$T/$ti/g;
2140      $toc=~s/\$A/$au/g;
2141      $toc=~s/[\200-\377]+/)F1($&)F2(/g if(!$latin1);
2142    }
2143    if($layer) {
2144      @docs=(@docs,@links);
2145    } else {
2146      @docs=(@links,@docs);
2147    }
2148    $rem=$#docs+1;
2149    if($rem && $opt_W) {
2150      &dbg("At least $rem document".($rem>1?"s":"")." remaining\n");
2151    }
2152    if($banner) {
2153      $_="/Ba t D /BA {($banner)BN} D\nBs f Pb CP /BO E D pop\n";
2154      &Subst($_);
2155      s/  H\(/ -1 H(/g;
2156    } else {
2157      $_="/Ba f D /BO 0 D Bs";
2158    }
2159    if($tocdoc && $first && $ndoc==1) {
2160      $TC=" TC\n";
2161      $et=" NP Ep ET /Tc f D";
2162    } else {
2163      $TC="";
2164      $et="";
2165    }
2166    $_.="\n/UR ($html) D\n/Ti ($ti) D\n/Au ($au) D\n/Df $draft D\n/ME [";
2167    for $i (sort {$metarc{$a} <=> $metarc{$b}} keys %metarc){
2168      $_.="($meta{$i})";
2169    }
2170    $_.="] D\n$TC";
2171    if($ndoc==1) {$top=$_};
2172    if(!$tocdoc) {
2173      $toc.="ND 1 gt{Ts 3 mul Np $refs{$html}()0 C()BD($ti)ES()$refs{$html}"
2174           ." 1 TN()EA()BN}if\n";
2175    }
2176    $hv=0;
2177    while($P2=~s/(\d) (\d)  H\(([^\s<)]*)/$1 $2 $nhd H($3)WB $nref Sn(/) {
2178      $nhd++;
2179      if($hv+1<$2) {
2180        for($hv+1..$2-1) {
2181          push(@z1,-$nref);
2182          push(@z2,$_);
2183        }
2184      }
2185      $hv=$2;
2186      $hind[$hv-1]++;
2187      for $i ($hv..5) {$hind[$i]=0};
2188      $hind=join('.',@hind[0..$hv-1]);
2189      $hst=$3;
2190      $'=~/\)EH/;
2191      ($htxt=$hst.$`)=~s/\)EA\(//g;
2192      if(!$tocdoc) {
2193        $toc.="$hv NH le{$nref($hind\\240\\240)$hv C($htxt)$nref 1 TN()EA()BN}if\n";
2194      }
2195      push(@z1,$nref);
2196      push(@z2,$hv);
2197      $nref++;
2198      $htxt=~s/(\s+|\)BR\()/ /g;
2199      $htxt=~s/(^\s+|\)[^(]*\(|\s+$)//g;
2200      $htxt=~s/\\(200|201|202)/\\$ssy{$1}/g;
2201      $htxt="" if(!$latin1);
2202      $dh.="/h$nhd [($hind\\240\\240)($htxt)] D\n";
2203    }
2204    if($tocdoc) {
2205      if($ndoc==1 && !$first) {
2206        $toc="TC RC ZF $_ $P2 WB () BN\n";
2207        $P2="";
2208        $P3="";
2209        $np="";
2210        $_="";
2211      }
2212    }
2213    $P3.="$fl1\n/Cb $bg D /Ct $tcol D /Cl $lcol D /CL -1 D Ct Sc\n";
2214    if($ndoc==1 && !$first) {$P3.="Pt\n"};
2215    $P3.="$fl2\n$_\n$np\n$P2";
2216    if($tocdoc && $ndoc==1 && !$first) {
2217      $np="/Cb $bg D NP RC ZF";
2218    } else {
2219      $fl1="WB NL$et";
2220      $fl2="DS";
2221      $np="0 BO R";
2222    }
2223  }
2224}
2225
2226$P3.=($P3!~/\)\s*$/?"()":"")."WB NL";
2227if(!$tocdoc && $first && $nhd){$P3="$toc/OU t D /Cb $bg D NP Ep ET $P3"};
2228if(!$first && ($tocdoc || !$tocdoc && $nhd)){$P3.=" $toc"};
2229
2230if($ntab>=0) {
2231  $_="$tables] D";
2232  &ack($_);
2233  y/\t\f/ /;
2234  s/[\200-\377]/sprintf("\\%3.3o",ord($&))/eg;
2235  s/\)XX/)9 9 PR/g;
2236  s/  H\(/ -1 H(/g;
2237  $tables=$_;
2238}
2239$_="%!PS\n%%Title: $title\n$P0$P1";
2240if($nimg>=0) {
2241  $_.="/AX [".join(' ',@XS)."] D\n/AY [".join(' ',@YS)."] D\n"
2242     ."/IX [".join(' ',@IX)."] D\n/IT [".join(' ',@IT)."] D\n";
2243  if($nm>=0) {
2244    $_.="/AZ [".join(' ',@DP)."] D\n/WS [".join(' ',@WS)."] D\n"
2245       ."/FC [".join(' ',@FC)."] D\n/NI $nm D\n/BM ".($nm+1)." array D\nSB\n";
2246    for $i (0..$nm) {$_.="$BM[$i]\n\n"}
2247  }
2248  $_.="\n$pv%Endpv\n" if($nps);
2249}
2250@kw=split(/[, ]+/,$kw);
2251@Kw=();
2252for $i (@kw){push(@Kw,$i) if(!grep(/^\Q$i\E$/,@Kw))};
2253$kw=join(', ',@Kw);
2254for $i (0..$#z2) {
2255  $n=0;
2256  $j=$i;
2257  while($j++<=$#z2 && $z2[$j]>$z2[$i]) {$n++ if($z2[$j]==$z2[$i]+1)};
2258  push(@z3,$n);
2259}
2260$tdef=$ntab>=0?"$tbl$tables\n0 1 $ntab\{TS}for RC ZF\n":"";
2261$hd="/Hr [@z1]D\n/HV [@z2]D\n/Cn [@z3]D";
2262&cut($hd);
2263if($gd) {
2264  $sd="/Df t D /DG IW IW mul IL IL mul add sqrt D IW IL IW IL lt{E}if"
2265  ." /WM E D /WX E D /DZ 180 D gsave SD /DZ DZ DF mul D SD grestore\n";
2266} else {
2267  $sd="/Df f D\n";
2268}
2269$_.=<<EOD;
2270[/Creator ($version) /Author ($Au) /Keywords ($kw) /Subject ($su)
2271 /Title ($title) /DOCINFO pdfmark
2272/ND $ndoc D
2273/HN [1 1 $nref\{pop (??)}for] D
2274$dh$hd
2275Hr length 0 gt{[/PageMode /UseOutlines /DOCVIEW pdfmark}if
2276/Hn 1 D
22770 1 Hr length 1 sub{
2278 /Bn E D [Cn Bn get dup 0 gt{/Count E HV Bn get Bl ge{neg}if}{pop}ie
2279 /Dest Hr Bn get dup abs ST cvs cvn E 0 ge{(h)Hn ST cvs join cvx exec
2280 dup 1 get E Nf{0 get E join}{pop}ie /Hn Hn 1 add D}{()}ie
2281 /Title E dup length 255 gt{0 255 getinterval}if /OUT pdfmark}for
2282ZF /FN Fp D Ps 0 FS /WC Wf{( )}{<A1A1>}ie SW pop D
2283ET RC ZF
2284$sd$rfs$tdef$top$P3
2285/TE t D NP /OU t D TU PM 1 eq and{/Pn () D showpage}if end restore
2286EOD
2287
2288if(($first || $opt_R) && $xref{'passes'}) {
2289  &dbg("Inserting cross references\n") if($opt_d);
2290  for $i (1..$xref{'passes'}) {&ref};
2291}
2292&fin;
2293
2294sub h2p {
2295  if($html eq '-') {
2296    $_=<>;
2297  } elsif($html=~m|://|) {
2298    if(($prompt || $nrem>50) && $level>1) {
2299      &prompt("Retrieve document $html (y/n/q)? ",$ans);
2300      if($ans=~/q/i) {undef @docs};
2301      return 0 unless($ans=~/y/i);
2302    }
2303    &geturl($html,$_) || return;
2304    $nrem++;
2305    if($contyp!~m|text/html|i) {$_=" <plaintext>\n$_"};
2306    unless(($ba2)=$html=~m|(.*://.*/)|) {$ba2=$html."/"};
2307  } else {
2308    if(open(FILE,"<$html")) {
2309      &dbg("Reading $html\n") if($opt_W || $opt_d);
2310      $_=<FILE>;
2311      if(!/<HTML/i && $html!~/html?$/i && ($html!~/\.ps$/i || $ndoc>1)) {
2312        $_=" <plaintext>\n$_";
2313      }
2314      close FILE;
2315      $var{DOCUMENT_NAME}=$html;
2316      if($posix) {
2317        $var{LAST_MODIFIED}=POSIX::strftime("%c",localtime((stat $html)[9]));
2318        $var{DATE_LOCAL}=POSIX::strftime("%c",@now);
2319        $var{DATE_GMT}=POSIX::strftime("%c",@gmnow);
2320      }
2321      $mod=(stat $html)[9];
2322    } else {
2323      &dbg("*** Error opening $html\n");
2324      return 0;
2325    }
2326  }
2327
2328  if(/^%!/ && /$delim/) {
2329    $psin=1;
2330    &openps if($opt_o);
2331    $_=$P0.$';
2332    for $s ("b","c","cw","g","t") {
2333      &dbg("Option -$s ignored\n") if(eval "\$opt_$s");
2334    }
2335    &fin;
2336  }
2337
2338  &hb($_,$head);
2339  $head=~/<title$R\s*([\w\W]*)<\/title/i;
2340  ($ti=$2)=~s/\s+/ /g;
2341  $ti=$doctit{$html} if(!$ti);
2342  $ti=~s/\s*$//g;
2343  &spec($ti);
2344  &ent($ti);
2345  $ti="<Untitled>" if(!$ti);
2346  $title=$ti if(!$title);
2347  $draft="f" if(!$ddr);
2348  %meta=();
2349  $au="";
2350  while($head=~/<meta\s[^>]*(name|http-equiv)\s*=\s*["']?\s*(\w+)$R/gi) {
2351    $k=lc $2;
2352    ($v)=$&=~/content\s*=\s*["']\s*([^"']+)/i;
2353    $v=~s/\s+/ /g;
2354    $v=~s/\s*$//g;
2355    &spec($v);
2356    &ent($v);
2357    $meta{$k}=$v;
2358    if($k=~/author/) {$au=$au?"$au, $v":$v};
2359    if($k=~/keywords/) {$kw=$kw?"$kw, $v":$v};
2360    if($k=~/subject/ && !$su) {$su=$v};
2361    if(!$ddr && $k=~/status/ && $v=~/draft/i) {$draft="t";$gd=1};
2362  }
2363  $Au.=($Au?" + ":"").$au if($au);
2364  $b2=$opt_b;
2365  unless($b2) {
2366    ($b2)=$head=~/<base\s+href\s*=\s*"([^"]*)"$R/i;
2367    unless($b2) {($b2)=$head=~/<base\s+href\s*=\s*([\w\.-]+)$R/i}
2368    unless($b2) {$b2=$ba2}
2369  }
2370  $b2=~s|[^/]*$||;
2371  ($b1)=$b2=~m|(.*://[^/]*)/|;
2372  unless($b1) {$b1=$opt_r};
2373  unless($b2) {$b2=$html=~m|(.*/)[^/]*$|?$1:""};
2374  if(!defined $B2) {$B2=$b2};
2375  $levl{$b2.$html}=$levl{$html};
2376
2377  while($link && $head=~/<link\s+[^>]*rel\s*=\s*["']?next$R/gi) {
2378    if(($lnk)=$&=~/href\s*=\s*["']?\s*([^"' >]*)/gi) {
2379      if($lnk=~m|.+//[^/]+$|) {$lnk=$&."/"}
2380      if($lnk=~m|://|) {
2381        $rlnk=0;
2382      } else {
2383        $rlnk=1;
2384        if($lnk=~m|^/|) {$lnk=$b1.$lnk} else {$lnk=$b2.$lnk}
2385      }
2386      while($lnk!~m|^\.\./| && $lnk=~m|[^/]*/\.\./|) {$lnk=$`.$'};
2387      $lnk=~s|/\./|/|g;
2388      if(&follow && !$levl{$lnk}) {
2389        $levl{$lnk}=$level+1;
2390        push(@links,$lnk);
2391      }
2392    }
2393  }
2394  ($battr)=/<BODY$R/i;
2395  ($lang)=$battr=~/\slang\s*=\s*['"]?([a-zA-Z-]+)/i;
2396  ($lang)=$head=~/<html[^>]+lang\s*=\s*['"]?([a-zA-Z-]+)/i if(!$lang);
2397  $lang=$opt_l if($opt_l);
2398  $lang='en' if(!$lang);
2399  $lang=lc $lang;
2400  if($battr=~/\stext\s*=\s*['"]?\s*#?(\w+)/i) {$tcol=&col2rgb($1)};
2401  if(!$tcol) {$tcol="Dt"};
2402  if($battr=~/\slink\s*=\s*['"]?\s*#?(\w+)/i) {$lcol=&col2rgb($1)};
2403  if(!$lcol) {$lcol="Dl"};
2404  &inihyph if($opt_H);
2405  ($bg)=$battr=~/BGCOLOR\s*=\s*["']?\s*#?(\w+)/i;
2406  $bg=&col2rgb($bg);
2407  if($bg) {
2408    ($red,$grn,$blu)=@cvec;
2409  } else {
2410    ($red,$grn,$blu)=$bgcol=~/#(\w+).*#(\w+).*#(\w+)/;
2411    $bg="Db";
2412  }
2413
2414  $temp="";
2415  while(/<object$R/i) {
2416    $temp.=$`;
2417    $tag=$&;
2418    $end=$';
2419    $type=$tag=~/type\s*=\s*($S)/i?$+:"";
2420    $uaddr=$tag=~/data\s*=\s*($S)/i?$+:"";
2421    if($type=~/^text\/(html|plain)$/i
2422     || !$type && $uaddr=~m"(\.html?|://.+/|://[^/]+)$"i) {
2423      $tag=~/data\s*=\s*/i;
2424      if(&open($uaddr,"<$idoc")) {
2425        if($type=~/plain/i) {
2426          $idoc="<XMP>$idoc</XMP>";
2427        } else {
2428          &hb($idoc,$dum);
2429        }
2430        $_=$idoc;
2431        $_.=$' if($end=~/<\/object>/i);
2432      } else {
2433        &dbg("\n*** Error opening $uaddr\n");
2434        $_=$end;
2435      }
2436    } else {
2437      $temp.=$tag;
2438      $_=$end;
2439    }
2440  }
2441  $_=$temp.$_;
2442
2443  if($opt_c && defined $package{'check'}) {
2444    $file=$html;
2445    if($html=~m|://|) {
2446      open(SCRATCH,">$scr");
2447      print SCRATCH;
2448      close SCRATCH;
2449      $file="$scr";
2450    }
2451    &dbg(`$package{'check'} $file`);
2452  }
2453
2454  if(!$latin1) {
2455    if($opt_e=~/EUC-/i) {
2456      s/([\216\217\241-\376].)+/\000$&\000/g;
2457      &spec($_);
2458      s/\000(.+?)\000/)F1($1)F2(/g;
2459    } elsif($opt_e=~/SHIFT-JIS/i) {
2460      s/[\201-\237\340-\374][@-~\200-\374]/$&\000/g;
2461      s/[\241-\337]+(?!\000)/$&\000/g;
2462      s/[ -~\t\n\r\240]+(?!\000)/\002$&\001/g;
2463      &spec($_);
2464      s/\000//g;
2465    } else {
2466      while(/\e\$B([^\e]*)/) {
2467        $beg=$`;
2468        $end=$';
2469        $mat=$1;
2470        $mat=~s/\s//g;
2471        $_="$beg\001$mat$end";
2472      }
2473      s/\e\([BJ]/\002/g;
2474      &spec($_);
2475    }
2476    s/\001/)F1(/g;
2477    s/\002/)F2(/g;
2478    $_=")F2($_";
2479    y/\000-\010\013\016-\037\177//d;
2480  } else {
2481    &spec($_);
2482    y/\000-\010\013\016-\037\177-\237//d;
2483  }
2484  s/(\r\n|\r)/\n/g;
2485  $refs{$html}=$nref++ if(!defined $refs{$html});
2486  $_="\004$lang\004)WB $refs{$html} Sn($_";
2487
2488#  Yes, I know Perl has case-insensitive pattern matching. But on my system
2489#  it takes about 10 times longer to run!
2490
2491  $pt="";
2492  if(/<[pP][lL][aA][iI][nN][tT][eE][xX][tT]$R/) {$_=$`;$pt=$'};
2493  while($_){
2494    if(/(<[lL][iI][sS][tT][iI][nN][gG]$R)/) {$_=$`; $tag=$1; $rest=$';
2495      if(/<[xX][mM][pP]$R/){$_=$`; &Subst($_); $P2.="$_)XX("; $_=$'.$tag.$rest;
2496        if(m|</[xX][mM][pP]$R|) {$P2.="$`)RP("; $_=$'}
2497        else {$P2.=$'; $_=""}}
2498      else {&Subst($_); $P2.="$_)XX("; $_=$rest;
2499        if(m|</[lL][iI][sS][tT][iI][nN][gG]$R|) {$P2.="$`)RP("; $_=$'}
2500        else {$P2.=$'; $_=""}}}
2501    elsif(/<[xX][mM][pP]$R/) {$_=$`; &Subst($_); $P2.="$_)XX("; $_=$';
2502      if(m|</[xX][mM][pP]$R|) {$P2.="$`)RP("; $_=$'}
2503      else {$P2.=$'; $_=""}}
2504    else {&Subst($_);$P2.=$_; $_=""}
2505  }
2506  $pt=~s/\f/$pc/g;
2507  if($pt) {$P2.=")XX($pt"};
2508  $P2.=")";
2509  if($plain) {$P2.="RP ()"};
2510  while($P2=~/XX\(/) {
2511    $beg=$`;
2512    $'=~/\)(RP|$)/;
2513    $mat=$`;
2514    $end=$&.$';
2515    $mat=~s/(.*\n){30}.*/$&)WR(/g;
2516    ($temp=$mat)=~s/\)[^(]+\(//g;
2517    @prel=split(' *\n',$temp);
2518    $maxl=0;
2519    for $line (@prel) {
2520      $line=~s/\\.../x/g;
2521      while($line=~/\t+/) {
2522        $sp=' ' x (length($&)*8-length($`)%8);
2523        $line=~s/\t+/$sp/;
2524        $mat=~s/\t+/$sp/;
2525      }
2526      $ll=length($line);
2527      $maxl=$ll if($ll > $maxl);
2528    }
2529    $P2="$beg ".($#prel+1)." $maxl PR($mat$end";
2530  }
2531  $P1=~s/[\200-\377]/sprintf("\\%3.3o",ord($&))/eg;
2532  $P2=~s/[\200-\377]/sprintf("\\%3.3o",ord($&))/eg;
2533  $P2=~y/\t\f/ /;
2534  1;
2535}
2536sub Subst{
2537  local($_)=@_;
2538  if($page_break) {
2539    s/<!--NewPage-->/$pc/g;
2540    s/<(\?|hr\s+class\s*=\s*["']?)\s*page-break$R/$pc/gi;
2541  }
2542  s/<!--OddPage-->/)WB NL OP(/g;
2543  if($ssi && $html!~m|://|) {
2544    while(/<!--#(include|config|echo)\s+(\w+)\s*="([^"]+)"\s*-->/) {
2545      $inc="";
2546      $file=$3;
2547      my ($prefix, $suffix) = ($`,$');
2548      if($1 eq "include" && ($file !~m"^/|\.\." || $opt_r)) {
2549        if(substr($file,0,1) ne "/") {
2550          $file=$B2.$file;
2551        } elsif($2 eq "virtual") {
2552          $file=$opt_r.$file;
2553        }
2554        if(open INC,"<$file") {
2555          $inc=<INC>;
2556          &spec($inc);
2557          close INC;
2558        }
2559      } elsif ($1 eq "config" && $2 eq "timefmt") {
2560        if($posix) {
2561          $var{LAST_MODIFIED}=POSIX::strftime($3,localtime((stat $html)[9]));
2562          $var{DATE_LOCAL}=POSIX::strftime($3,@now);
2563          $var{DATE_GMT}=POSIX::strftime($3,@gmnow);
2564        }
2565      } elsif ($1 eq "echo") {
2566        $inc=$var{$3};
2567      }
2568      $_=$prefix.$inc.$suffix;    }
2569  }
2570  s/(&shy;?|&#173;?|<!--hy-->)/)HY(/g;
2571  while(/<!--/) {
2572    $_=$`;
2573    &getcom;
2574    $_.=$rest;
2575  }
2576  $temp="";
2577  while(/<([^"'>]*=\s*["'])/) {
2578    $temp.=$`."<";
2579    $_=$1.$';
2580    while(/^[^"'>]*=\s*(["'])/) {
2581      $temp.=$&;
2582      $_=$';
2583      if(/$1/) {
2584        ($tg=$`)=~y/>/\003/;
2585        $temp.=$tg.$&;
2586        $_=$';
2587      }
2588    }
2589  }
2590  $_=$temp.$_;
2591  $a='[aA][lL][iI][gG][nN]';
2592  $Y='[sS][tT][yY][lL][eE]';
2593  $A="($a\\s*=\"?|$Y\\s*=\\s*\"?[tT][eE][xX][tT]-\\s*$a:)";
2594  $I='[lL][eE][fF][tT]';
2595  $C='[cC][eE][nN][tT][eE][rR]';
2596  $D='[rR][iI][gG][hH][tT]';
2597  $J='[jJ][uU][sS][tT][iI][fF][yY]';
2598  $s='[sS][eE][lL][eE][cC][tT]';
2599  $F='[fF][oO][nN][tT]';
2600  $U='[cC][oO][lL][oO][rR]';
2601  $O='[cC][oO][mM][pP][aA][cC][tT]';
2602  s/<\w+[^>]*\s+[iI][dD]\s*=\s*($S)[^>]*>/$&<a name="$+">/g;
2603  s|<[dD][eE][lL]$R[\w\W]*?</[dD][eE][lL]>||g if($del{'display'}=~/^none$/);
2604  $ndiv=1;
2605  s|</?[dD][iI][vV]\d$R||g;
2606  s|<(/?)([dD][iI][vV])([>\s])|"<$1$2".($1?--$ndiv:$ndiv++).$3|eg;
2607  while(/<[dD][iI][vV](\d+)$R/) {
2608    $dbeg=$`;
2609    $dnum=$1;
2610    $dattr=$2;
2611    $dend=$';
2612    $div="";
2613    $ediv="";
2614    if($2=~/class\s*=\s*["']?noprint$R/i) {
2615      $_=$dbeg;
2616      $_.=$' if($dend=~/<\/[dD][iI][vV]$dnum>/);
2617    } else {
2618      if($dattr=~/$A\s*($I|$C|$D|$J)/) {
2619        $div.=")".$algn{"\L$2"}." Al(";
2620        $ediv.=")Ea(";
2621      }
2622      if($dattr=~/lang\s*=\s*["']?([a-zA-Z-]+)/i) {
2623        $lang=lc $1;
2624        $div.="\004$lang\004";
2625        &inihyph if($opt_H);
2626        $dbeg=~/(\004[^\004]*\004)[^\004]*$/;
2627        $ediv.=$1;
2628      }
2629      $dend=~s|</[dD][iI][vV]$dnum>|$ediv)BR(|;
2630      $_="$dbeg$div)BR($dend";
2631    }
2632  }
2633  s|<$C$R|)2 Al(|g;
2634  s|</$C$R|)Ea(|g;
2635  s/(<\w+[^>]*>)\n|\n(<\/\w+>)/$+/g;
2636  s|(<[lL][iI])$R\s*<[pP]>|)0 P($1$2|g;
2637  s/<[hH]([1-6])\s+$A\s*($I|$C|$D|$J)$R/)$algn{"\L$3"} $1  H(/g;
2638  s|<[hH]([1-6])$R|)0 $1  H(|g;
2639  s|</[hH][1-6]>|)EH(|g;
2640  s|<[bB][rR]$R|)BR(|g;
2641  s/<[pP]\s+[^>]*$A\s*($I|$C|$D|$J)$R/)$algn{"\L$2"} P(/g;
2642  s|<[pP]$R|)0 P(|g;
2643  s|</[pP]>|)EP(|g;
2644  s|<[aA][dD][dD][rR][eE][sS][sS]$R|)AD(|g;
2645  s|</[aA][dD][dD][rR][eE][sS][sS]>|)DA(|g;
2646  s|<[pP][rR][eE]$R\n?|)XX(|g;
2647  s|\n? *</[pP][rR][eE]>|)RP(|g;
2648  s|<[dD][tT]\s[^>]*$O$R|)1 DT(|g;
2649  s|<[dD][tT]$R|)0 DT(|g;
2650  s|<[dD][dD]$R|)DD(|g;
2651  s|<[dD][lL]\s[^>]*$O$R|)1 DL(|g;
2652  s|<[dD][lL]$R|)0 DL(|g;
2653  s|</[dD][lL]>|)LD(|g;
2654  s|<[uU][lL]$R|)UL(|g;
2655  s|</[uU][lL]>|)LU(|g;
2656  s|<[mM][eE][nN][uU]$R|)UL(|g;
2657  s|</[mM][eE][nN][uU]>|)LU(|g;
2658  s|<[dD][iI][rR]$R|)UL(|g;
2659  s|</[dD][iI][rR]>|)LU(|g;
2660  s|<[oO][lL]\s[^>]*[sS][tT][aA][rR][tT]\s*=\s*['"]?(-?\d+)$R|$&)WB $1 Ln(|g;
2661  s|<[oO][lL]\s[^>]*[tT][yY][pP][eE]\s*=\s*['"]?([1iIaA])$R|)$lity{$1} OL(|g;
2662  s|<[oO][lL]$R|)4 OL(|g;
2663  s|</[oO][lL]>|)LO(|g;
2664  s|<[lL][iI]\s[^>]*[vV][aA][lL][uU][eE]\s*=\s*['"]?(-?\d+)$R|$&)WB $1 Ln(|g;
2665  s|<[lL][iI]\s[^>]*[tT][yY][pP][eE]\s*=\s*['"]?($ltr)$R|)$lity{$1} LI(|g;
2666  s|<[lL][iI]$R|)-1 LI(|g;
2667  s|</[lL][iI]$R||g;
2668  s"<([bB][qQ]|[bB][lL][oO][cC][kK][qQ][uU][oO][tT][eE])$R")BQ("g;
2669  s"</([bB][qQ]|[bB][lL][oO][cC][kK][qQ][uU][oO][tT][eE])>")QB("g;
2670  s|<[sS][tT][rR][oO][nN][gG]$R|)BD(|g;
2671  s|</[sS][tT][rR][oO][nN][gG]>|)ES(|g;
2672  s|<[sS][aA][mM][pP]$R|)SM(|g;
2673  s|</[sS][aA][mM][pP]>|)ES(|g;
2674  s|<[qQ]$R(\s*)|$2)Q(|g;
2675  s|(\s*)</[qQ]>|)EQ($1|g;
2676  s|<[cC][iI][tT][eE]$R|)CT(|g;
2677  s|</[cC][iI][tT][eE]>|)ES(|g;
2678  s|<[vV][aA][rR]$R|)I(|g;
2679  s|</[vV][aA][rR]>|)ES(|g;
2680  s|<[bB]$R|)BD(|g;
2681  s|</[bB]>|)ES(|g;
2682  s|<[iI]$R|)I(|g;
2683  s|</[iI]>|)ES(|g;
2684  s|<[tT][tT]$R|)TT(|g;
2685  s|</[tT][tT]>|)ES(|g;
2686  s|<[uU]$R|)UN(|g;
2687  s|</[uU]>|)NU(|g;
2688  s|<[sS]([tT][rR][iI][kK][eE])?$R|)SE(|g;
2689  s|</[sS]([tT][rR][iI][kK][eE])?>|)XE(|g;
2690  s|<[dD][fF][nN]$R|)I(|g;
2691  s|</[dD][fF][nN]>|)ES(|g;
2692  s|<[eE][mM]$R|)EM(|g;
2693  s|</[eE][mM]>|)ES(|g;
2694  s|<[cC][oO][dD][eE]$R|)SM(|g;
2695  s|</[cC][oO][dD][eE]>|)ES(|g;
2696  s|<[kK][bB][dD]$R|)KB(|g;
2697  s|</[kK][bB][dD]>|)ES(|g;
2698  s|<[bB][iI][gG]$R|)4 FZ(|g;
2699  s|</[bB][iI][gG]>|)ES(|g;
2700  s|<[sS][mM][aA][lL][lL]$R|)2 FZ(|g;
2701  s|</[sS][mM][aA][lL][lL]>|)ES(|g;
2702  s|<[iI][nN][sS]$R|)sM WB(|g;
2703  s|</[iI][nN][sS]>|)WB eM(|g;
2704  s|<[dD][eE][lL]$R|)sM $lt(|g;
2705  s|</[dD][eE][lL]>|)XE eM(|g;
2706  s|<[aA][cC][rR][oO][nN][yY][mM][^>]+[tT][iI][tT][lL][eE]\s*=\s*($S)[^>]*>|)($+)Ac(|g;
2707  s|</[aA][cC][rR][oO][nN][yY][mM]>|)Ca(|g;
2708  s|<[sS][cC][rR][iI][pP][tT][\w\W]*?</[sS][cC][rR][iI][pP][tT]>||g;
2709  s|<[fF][oO][rR][mM][\w\W]*?</[fF][oO][rR][mM]>||g if(!$forms);
2710  s|</?[fF][oO][rR][mM]$R|)Ts BE(|g;
2711  s/<$s[^>]*[mM][uU][lL][tT][iI][pP][lL][eE]$R/)1 MS(<table>/g;
2712  s/<$s$R/)0 MS(<table>/g;
2713  s|</$s>|</table>|g;
2714  s/<[oO][pP][tT][iI][oO][nN]$R/<tr><td>)O(/g;
2715  while(/<[iI][nN][pP][uU][tT]$R/) {
2716    $beg=$`;
2717    $iattr=$1;
2718    $rest=$';
2719    $it=2;
2720    if($iattr=~/type\s*=\s*["']?(\w+)/i) {$it=$it{"\L$1"}};
2721    if(defined($it) && $it<2) {
2722      $it=($iattr=~/\schecked\W/i?1:0) ." $it";
2723    } elsif($it==2) {
2724      $siz=$iattr=~/size\s*=\s*["']?(\d+)/i?$1:12;
2725      $ival=$iattr=~/value\s*=\s*($S)/i?$+:"";
2726      $it="($ival)$siz $it";
2727    }
2728    if(defined($it)) {
2729      $cmd=$it==3?"<img $iattr":")$it BX(";
2730    } else {
2731      $cmd="";
2732    }
2733    $_=$beg.$cmd.$rest;
2734  }
2735  while(/<[tT][eE][xX][tT][aA][rR][eE][aA]$R/) {
2736    $beg=$`;
2737    $txatr=$1;
2738    $rest=$';
2739    if($rest=~m|</[tT][eE][xX][tT][aA][rR][eE][aA]>|) {
2740      $rest=$';
2741      $data=$prefilled||$textarea_data?$`:"";
2742      $rows=4;
2743      $cols=20;
2744      if($txatr=~/rows\s*=\s*["']?(\d+)/i) {$rows=$1};
2745      if($txatr=~/cols\s*=\s*["']?(\d+)/i) {$cols=$1};
2746      $nl=$data=~y/\n/\n/;
2747      for ($nl..$rows) {$data.="\n"};
2748      $data=~/(.*\n){$rows}/;
2749      $tfont=$prefilled?"TT":"0 FZ";
2750      ($data=$&)=~s/.*\n/<tr height=24><td valign=top>)$tfont($&)ES(/g;
2751      $wi=10*$cols;
2752      $frame=$prefilled?"frame=box":"border";
2753      $_="$beg<table $frame width=$wi cellpadding=2>$data</table>$rest";
2754    } else {
2755      $_=$beg.$rest;
2756    }
2757  }
2758  $nfnt=1;
2759  s|<(/?)($F)([>\s])|"<$1$2".($1?--$nfnt:$nfnt++).$3|eg;
2760  while(/<$F(\d+)([^>]*)$U\s*=\s*["']?\s*#?(\w+)$R/) {
2761    $rgb=&col2rgb($3);
2762    $_=$`.($rgb?")WB $rgb Sc(":"")."<font$2$4";
2763    $temp=$';
2764    $temp=~s|</$F$1>|</font>)Ec(| if($rgb);
2765    $_.=$temp;
2766  }
2767  $base{"+"}="Bf add ";
2768  $base{"-"}="Bf add ";
2769  s/<$F\d*\s[^>]*[sS][iI][zZ][eE]\s*=\s*["']?([+-]?)(\d+\.?\d*)$R/)$1$2 $base{$1}FZ(/g;
2770  s|<$F\d*$R|)3 FZ(|g;
2771  s|</$F\d*>|)Ef(|g;
2772  s|<[bB][aA][sS][eE]$F\s[^>]*[sS][iI][zZ][eE]\s*=\s*["']?(\d+)$R|)$1 BZ(|g;
2773  while(/(<[aA]\s+[^>]*)[nN][aA][mM][eE]\s*=\s*(["']?)([^"'\s>]*)$R([^\s<)]*)/) {
2774    $lnk="$html#$3";
2775    $refs{$lnk}=$nref++ unless(defined $refs{$lnk});
2776    $_="$`$1$4$5)WB $refs{$lnk} Sn($'";
2777  }
2778  while(/<[aA]\s+[^>]*[hH][rR][eE][fF]\s*=\s*["']?\s*([^"'\s>]*)$R/) {
2779    $beg=$`;
2780    $tag=$&;
2781    $rest=$';
2782    $lnk=$1;
2783    $revtoc=$tag=~/rev\s*=['"]?\s*toc/i;
2784    $html=~m|[^/]*$|;
2785    $lnk=~s/^\Q$&#/#/;
2786    $loc=$lnk=~/^#/;
2787    if($loc) {
2788      $html=~m|[^/]*$|;
2789      $lnk=$&.$lnk;
2790    }
2791    if($lnk=~m|.+//[^/]+$|) {$lnk=$&."/"}
2792    if($lnk=~m|://|) {
2793      $rlnk=0;
2794    } else {
2795      $rlnk=1;
2796      if($lnk=~m|^/|) {$lnk=$b1.$lnk} elsif($lnk!~m|^\w+:|) {$lnk=$b2.$lnk};
2797    }
2798    while($lnk!~m|^\.\./| && $lnk=~m|[^/]*/\.\./|) {$lnk=$`.$'};
2799    $lnk=~s"(^|/)\./"$1"g;
2800    ($doc)=$lnk=~/([^#]*)/;
2801    ($doctit{$doc})=$tag=~/title\s*=['"]([^'"]*)['"]/i;
2802    $T=0;
2803    $anch=2;
2804    if($loc || grep(/^\Q$doc\E$/,(@docs,@links))
2805     || $opt_W && !$link && $level<=$maxlev && &follow){
2806      $refs{$lnk}=$nref++ unless(defined $refs{$lnk});
2807      $anch="$refs{$lnk} 1";
2808      $ltype=$rev && $revtoc && $ndoc==1 || $opt_C=~/f/ && $ndoc==1?1:0;
2809      $rest=~s|</a>|)$refs{$lnk} $ltype TN TL()Ec /AF f D(|i;
2810      if(&follow && !$levl{$doc}) {
2811        &dbg("Link: $doc\n") if($opt_d);
2812        $levl{$doc}=$level+1;
2813        push(@links,$doc);
2814      }
2815    } elsif(defined $refs{$lnk}) {
2816      $anch="$refs{$lnk} 1";
2817    }
2818    $addr=$dum{$lnk}?"R$dum{$lnk}":0;
2819    if(!$dum{$lnk} && $lnk=~m|://|) {
2820      $dum{$lnk}=$nlnk++;
2821      $rfs.="/R$dum{$lnk} ($lnk) D\n";
2822      $addr="R$dum{$lnk}";
2823    }
2824    $_=$beg.")$addr $anch A(".$rest;
2825  }
2826  s|</[aA]>|)EA(|g;
2827  if((!$mult || $doc_sep eq $pc && $mult)
2828   && m|<[bB][aA][nN][nN][eE][rR]$R([\w\W]*)</[bB][aA][nN][nN][eE][rR]>|) {
2829    $banner=$2;
2830    $_=$`.$';
2831  }
2832  while(/<[tT][aA][bB][lL][eE]([^>]*)>/) {
2833    local($beg)=$`;
2834    local($rest)=$';
2835    $tattr=$1;
2836    $tag=$&;
2837    $rest=~/(<\/[tT][aA][bB][lL][eE]>|$)/;
2838    $table=$`;
2839    $rest=$';
2840    while($table=~/<[tT][aA][bB][lL][eE]([^>]*)>/) {
2841      $tattr=$1;
2842      $table=$';
2843      $beg.=$tag.$`;
2844      $tag=$&;
2845    }
2846    ($tla)=$tattr=~/lang\s*=\s*["']?([a-zA-Z-]+)/i;
2847    if(!$tla) {($tla)=$beg=~/\004_?([^\004]*)\004[^\004]*$/};
2848    $ntab++;
2849    $table=~s/^\s*//;
2850    undef %cells;
2851    undef %rd;
2852    undef @cali;
2853    undef @cval;
2854    undef @cgrp;
2855    undef @cwid;
2856    undef @codc;
2857    undef @r0;
2858    undef @c0;
2859    ($capat,$cap)=$table=~m|<caption$R([\w\W]*)</caption>|i;
2860    $capat=~/ALIGN\s*=\s*["']?\s*(\w+)/i;
2861    $capa=0;
2862    $capa=1 if("\L$1" eq "bottom");
2863    $capa=-1 if($cap!~/\S/);
2864    $bord=0;
2865    if($tattr=~/border/i) {
2866      ($bord)=$'=~/^\s*=\s*["']?(\d+)/;
2867      if(!$bord && $bord ne "0") {$bord=1};
2868    }
2869    ($talgn)=$tattr=~/ALIGN\s*=\s*["']?\s*(\w+)/i;
2870    $tal=-1;
2871    $tal=0 if($talgn=~/^left$/i);
2872    $tal=1 if($talgn=~/^center$/i);
2873    $tal=2 if($talgn=~/^right$/i);
2874    ($fra)=$tattr=~/FRAME\s*=\s*["']?\s*(\w+)/i;
2875    if($fra && $f{"\L$fra"}) {$fra=$f{"\L$fra"}} else {$fra=$bord?9:1};
2876    ($rul)=$tattr=~/RULES\s*=\s*["']?\s*(\w+)/i;
2877    if($rul && $r{"\L$rul"}) {$rul=$r{"\L$rul"}} else {$rul=$bord?5:1};
2878    unless(($twid)=$tattr=~/WIDTH\s*=\s*["']?(\d+\.?\d*%?)/i) {$twid=0};
2879    $twid=$twid=~/%$/?$`/100:-$twid;
2880    ($cpad)=$tattr=~/CELLPADDING\s*=\s*["']?\s*$V/i;
2881    if($tattr=~/CELLSPACING\s*=\s*["']?\s*$V/i && $1!=0) {$cpad+=$1/2};
2882    ($tbg)=$tattr=~/BGCOLOR\s*=\s*["']?\s*#?(\w+)/i;
2883    $tbg=&col2rgb($tbg);
2884    ($tcl)=$tattr=~/CLASS\s*=\s*["']?\s*(\w+)/i;
2885    $tcl="\L$tcl" eq "telelista"? 1: 0;
2886    $ic=0;
2887    $span=1;
2888    undef $gal;
2889    undef $gva;
2890    undef $odc;
2891    undef $gwi;
2892    $cgs=0;
2893    while($table=~/<[cC][oO][lL]([^>]*>)/g && $span>0) {
2894      $cola=$1;
2895      $ab=$`;
2896      $aft=$';
2897      $cola=~/(^|\s)ALIGN\s*=\s*["']?\s*(\w+)/i;
2898      $alg=$algn{"\L$2"};
2899      ($val)=$cola=~/VALIGN\s*=\s*["']?\s*(\w+)/i;
2900      $val=$v{"\L$val"};
2901      ($odc)=$cola=~/CHAR\s*=\s*["']?(.)/i;
2902      unless(($wid)=$cola=~/WIDTH\s*=\s*["'](\d+%?)/i) {$wid=0};
2903      if($wid=~/%$/) {$wid=$`/100};
2904      ($span)=$cola=~/SPAN\s*=\s*["']?\s*(\d+)/i;
2905      if(!$span && $span ne "0") {$span=1};
2906      $us=1;
2907      if($cola=~/^GROUP/i) {
2908        $gal=$alg;
2909        $gva=$val;
2910        $gdc=$odc;
2911        $gwi=$wid;
2912        $cgs=1;
2913        if($aft=~/<COL\s/i) {
2914          $us=$`=~m|</?COLGROUP|i;
2915        }
2916      } else {
2917        while($ab=~/<COLGROUP/i) {$ab=$'};
2918        if($ab=~m|</COLGROUP|i) {
2919          undef $gal;
2920          undef $gva;
2921          undef $odc;
2922          undef $gwi;
2923        }
2924        if(!$alg) {$alg=$gal};
2925        if(!$val) {$val=$gva};
2926        if(!$odc) {$odc=$gdc};
2927        if(!$wid) {$wid=$gwi};
2928        if($span eq "0") {
2929          $ic++;
2930          push(@cali,$alg);
2931          push(@cval,$val);
2932          push(@cwid,$wid);
2933          push(@codc,$odc);
2934          push(@cgrp,1);
2935        }
2936      }
2937      if($us) {
2938        for (1..$span) {
2939          $ic++;
2940          push(@cali,$alg);
2941          push(@cval,$val);
2942          push(@cwid,$wid);
2943          push(@codc,$odc);
2944          push(@cgrp,$cgs);
2945          $cgs=0;
2946        }
2947      }
2948    }
2949    $table=~/<t[hd][\s>]/i;
2950    if($`!~/<tr/i) {$table="<TR>$table"};
2951    $nrow=-1;
2952    $ncol=-1;
2953    $nhead=0;
2954    $nfoot=0;
2955    $nb=0;
2956    unless($table=~/<tbody$R/i || $table=~s|</tfoot>|$&<tbody>|i) {
2957      $table=~s|</thead>|$&<tbody>|i;
2958    }
2959    while($table=~/<[tT][rR]\s*([^>]*)>/g) {
2960      $nrow++;
2961      $ab=$`;
2962      $row=$';
2963      $rattr=$1;
2964      for $j (@c0) {
2965        $cells{"$nrow,$j,0"}=1;
2966      }
2967      $rgrp=0;
2968      if($ab=~/<tbody$R/i) {
2969        $ib=0;
2970        while($ab=~/<[tT][bB][oO][dD][yY]$R/g) {
2971          $ib++;
2972          $battr=$1;
2973          if($ib>$nb) {
2974            $rgrp=1;
2975            $nb=$ib;
2976          }
2977        }
2978      } else {
2979        if($ab=~/<tfoot$R/i) {
2980          $nfoot++;
2981          $battr=$1;
2982        } elsif($ab=~/<thead$R/i) {
2983          $nhead++;
2984          $battr=$1;
2985        }
2986      }
2987      $battr=~/(^|\s)ALIGN\s*=\s*["']?\s*(\w+)/i;
2988      $balgn=$algn{"\L$2"};
2989      $battr=~/VALIGN\s*=\s*["']?\s*(\w+)/i;
2990      $bva=$v{"\L$1"};
2991      ($bdc)=$battr=~/CHAR\s*=\s*["']?(.)/i;
2992      $rd{"$nrow,0"}=0;
2993      $rd{"$nrow,1"}=0;
2994      $rd{"$nrow,2"}=0 unless($rd{"$nrow,2"});
2995      $rd{"$nrow,3"}=$rgrp;
2996      $rattr=~/(^|\s)ALIGN\s*=\s*["']?\s*(\w+)/i;
2997      $ralgn=$algn{"\L$2"};
2998      $rattr=~/VALIGN\s*=\s*["']?\s*(\w+)/i;
2999      $rva=$v{"\L$1"};
3000      ($rla[$nrow])=$rattr=~/lang\s*=\s*["']?([a-zA-Z-]+)/i;
3001      ($rbg)=$rattr=~/BGCOLOR\s*=\s*["']?\s*#?(\w+)/i;
3002      $rbg[$nrow]=&col2rgb($rbg);
3003      ($rdc)=$rattr=~/CHAR\s*=\s*["']?(.)/i;
3004      if($row=~/<tr/i) {$row=$`};
3005      $rh[$nrow]=$rattr=~/HEIGHT\s*=\s*["']?(\d+)/i?$1:0;
3006      $icol=0;
3007      $colsp=1;
3008      while($row=~/<[tT]([hH]|[dD])(\s*[^>]*)>/g && $colsp>0) {
3009        $cattr=$2;
3010        $cell=$';
3011        $ctype=$1=~/h/i?1:0;
3012        if($cell=~/<t[hd]/i) {$cell=$`};
3013        $cell=~s/\s+$//;
3014        $cell=~s/\)HY\($/\255/;
3015        $cell=~s/[\200-\377]([^\\]|\\20.)/$&)WB(/g if(!$latin1);
3016        ($rowsp)=$cattr=~/ROWSPAN\s*=\s*["']?(\d+)/i;
3017        $rsp=$rowsp;
3018        if(!$rsp) {
3019          if($rsp eq "0") {
3020            push(@c0,$icol);
3021          } else {
3022            $rowsp=1;
3023          }
3024          $rsp=1;
3025        }
3026        ($colsp)=$cattr=~/COLSPAN\s*=\s*["']?(\d+)/i;
3027        $csp=$colsp;
3028        if(!$csp) {
3029          if($csp eq "0") {
3030            push(@r0,$nrow);
3031            $csp=$ncol-$icol<0? 1: $ncol-$icol+1;
3032          } else {
3033            $colsp=1;
3034            $csp=1;
3035          }
3036        }
3037        ($cdc)=$cattr=~/CHAR\s*=\s*["']?(.)/i;
3038        while($cells{"$nrow,$icol,0"}==1) {$icol++};
3039#
3040        for $i ($nrow..$nrow+$rsp-2) {$rd{"$i,2"}=1};
3041        for $j ($icol..$icol+$csp-1) {
3042          for $i ($nrow..$nrow+$rsp-1) {
3043            $cells{"$i,$j,0"}=1;
3044          }
3045        }
3046        if($colsp) {
3047          for $j ($ncol+1..$icol+$csp) {
3048            for $i (@r0) {
3049              $cells{"$i,$j,0"}=1;
3050            }
3051          }
3052        }
3053        if($ic<$icol+$csp) {
3054          for ($ic..$icol+$csp-1) {
3055            push(@cali,$cali[$ic-1]);
3056            push(@cval,$cval[$ic-1]);
3057            push(@cgrp,0);
3058          }
3059          $ic=$icol+$csp;
3060        }
3061        $cal=$ctype;
3062        $cal=$balgn-1 if($balgn);
3063        $cal=$ralgn-1 if($ralgn);
3064        $cal=$cali[$icol]-1 if($cali[$icol]);
3065        if($cattr=~/(^|\s)ALIGN\s*=\s*["']?\s*(\w+)/i) {
3066          $cal=$algn{"\L$2"}-1 if($algn{"\L$2"});
3067        }
3068        $cvl=2;
3069        $cvl=$cval[$icol] if($cval[$icol]);
3070        $cvl=$bva if($bva);
3071        $cvl=$rva if($rva);
3072        if($cattr=~/VALIGN\s*=\s*["']?\s*(\w+)/i) {
3073          $cvl=$v{"\L$1"} if($v{"\L$1"});
3074        }
3075        ($cbg)=$cattr=~/BGCOLOR\s*=\s*["']?\s*#?(\w+)/i;
3076        $cbg=&col2rgb($cbg);
3077        for($rbg[$nrow],$tbg,$deftbg,$bg) {$cbg=$_ if(!$cbg)};
3078        $now=0;
3079        $ro=$cattr=~/class\s*=\s*["']?rot(-?90)/i?$1:0;
3080        if($cattr=~/NOWRAP/i || $cal==4 || $ro) {$now=1};
3081        $dc=".";
3082        $dc=$bdc if($bdc || $bdc eq "0");
3083        $dc=$rdc if($rdc || $rdc eq "0");
3084        $dc=$codc[$icol] if($codc[$icol] || $codc[$icol] eq "0");
3085        $dc=$cdc if($cdc || $cdc eq "0");
3086        ($wid)=$cattr=~/WIDTH\s*=\s*["'](\d+%?)/i;
3087        if($wid=~/%$/) {$wid=$`/100};
3088        if($wid>$cwid[$icol]) {$cwid[$icol]=$wid};
3089        if($cpad || $cpad eq "0") {
3090          $clm=$cpad;
3091          $crm=$cpad;
3092          $ctm=$cpad;
3093          $cbm=$cpad;
3094        } else {
3095          $clm=$rul<5?8:4;
3096          $crm=$rul<5?8:4;
3097          $ctm=2;
3098          $cbm=6;
3099        }
3100        if($tcl==1) {
3101          $clm=$icol>0?12:2;
3102          $crm=12;
3103          $ctm=0;
3104          $cbm=0;
3105        }
3106        if($rul==1 && $fra==1 && $icol==0 && $tal==0) {$clm=0};
3107        ($lang)=$cattr=~/lang\s*=\s*["']?([a-zA-Z-]+)/i;
3108        for($rla[$nrow],$tla) {$lang=$_ if(!$lang)};
3109        $lang=lc $lang;
3110        &inihyph if($opt_H);
3111        $cbg=~/#(\w+).*#(\w+).*#(\w+)/;
3112        &img($cell,$1,$2,$3);
3113        @cll=("{(\004$lang\004)WB($cell)}",0,0,$ctype,0,$colsp,$rowsp,$cal,
3114         "($dc)",$cvl,$now,$clm,$crm,$ctm,$cbm,0,0,0,0,$cbg,$ro);
3115        for $i (0..$#cll) {$cells{"$nrow,$icol,$i"}=$cll[$i]};
3116        $icol+=$csp;
3117        if($icol-1>$ncol) {$ncol=$icol-1};
3118      }
3119    }
3120    for $j (0..$ncol) {
3121      for $i (0..$nrow) {
3122        if($cells{"$i,$j,0"} && $cells{"$i,$j,0"}!=1) {
3123          if($cells{"$i,$j,6"}>$nrow-$i+1) {$cells{"$i,$j,6"}=$nrow-$i+1};
3124          if($cells{"$i,$j,6"}>1) {$rd{"$i,2"}=1};
3125        }
3126      }
3127    }
3128    $rd{"$nrow,2"}=0;
3129    $rw="[";
3130    for $i (0..$nrow) {
3131      $rw.="[$rh[$i] ".$rd{"$i,1"}." ".$rd{"$i,2"}." ".$rd{"$i,3"}." 0 0 [";
3132      for $j (0..$ncol) {
3133        $cbg="";
3134        for($rbg[$i],$tbg,$deftbg,$bg) {$cbg=$_ if(!$cbg)};
3135        $temp="[{()}0 0 0 0 1 1 0(.)0 0 $clm $crm $ctm $cbm 0 0 0 0 $cbg $ro]";
3136        if($cells{"$i,$j,0"}==1) {
3137          $temp="0";
3138        } elsif($cells{"$i,$j,0"}) {
3139          $temp="[";
3140          for $k (0..$#cll) {
3141            $temp.=$cells{"$i,$j,$k"}." ";
3142          }
3143          $temp.="]";
3144        }
3145        $rw.="$temp\n";
3146      }
3147      $rw.="]]\n";
3148    }
3149    if($nrow==$nhead+$nfoot-1) {
3150      $nhead=0;
3151      $nfoot=0;
3152    }
3153    $tdesc="[0 0 $tcl 0 0 $tal 0 $twid $bord $nrow $ncol"
3154           ." $nhead $nfoot $fra $rul {($cap)} $capa]\n";
3155    $cdesc="[";
3156    for (0..$ncol) {
3157      unless($wid=$cwid[$_]) {$wid=0};
3158      $cdesc.="[0 0 0 $wid $cgrp[$_] 0 0]";
3159    }
3160    $cdesc.="]\n";
3161    $tables.="[$tdesc $cdesc $rw]]\n";
3162    $_=$beg.")$ntab PT(".$rest;
3163  }
3164  &img($_,$red,$grn,$blu);
3165  &ack($_);
3166  $_[0]=$_;
3167}
3168sub getcom{
3169  $com=$&;
3170  $'=~/--\s*(--|>)/;
3171  $com.=$`.$&;
3172  $rest=$';
3173  while($1 eq "--") {
3174    $'=~/(>)/ if($'!~/--\s*(--|>)/);
3175    $com.=$`.$&;
3176    $rest=$';
3177  }
3178}
3179sub getl {
3180  ($l)=@_;
3181  if(!$lid{$l}) {
3182    while($l=~s/-[^-]+$// && !$lid{$l}) {};
3183  }
3184  $lid{$l};
3185}
3186sub ack {
3187  local($_)=@_;
3188  chdir $tempdir;
3189  while (/<[mM][aA][tT][hH]/) {
3190    $beg=$`;
3191    $rest=$&.$';
3192    $rest=~m|</[mM][aA][tT][hH]>|;
3193    $end=$';
3194    $math=$`;
3195    if(&math2sym($math)) {
3196      $_=$beg.$sym.$end;
3197    } elsif($package{'TeX'} && $package{'dvips'}) {
3198      $math=~s|\\200|\\|g;
3199      $math=~s|\\201|\(|g;
3200      $math=~s|\\202|\)|g;
3201      &math2tex($math);
3202      open(SCRATCH,">$scr.tex");
3203      print SCRATCH $tex;
3204      close SCRATCH;
3205      `tex $scr.tex`;
3206      `dvips -E -o $scr.ps $scr.dvi`;
3207      open(LOG,"$scr.log");
3208      $log=<LOG>;
3209      close LOG;
3210      ($h,$d)=$log=~/[\w\W]*$prog: +([\d.]+)pt: +([\d.]+)/ ? ($1,$2) : (1,0);
3211      $above=$h+$d>0?sprintf("%.4f",$h/($h+$d)):0;
3212      open(PS,"$scr.ps");
3213      $pic=<PS>;
3214      if($pic=~/^%!/ && $pic=~/%%BoundingBox: +$V +$V +$V +$V/) {
3215        $xs=$3-$1;
3216        $ys=$4-$2;
3217        $llx=$1;
3218        $lly=$2;
3219        $ps="";
3220        for $i (split(/\n/,$pic)) {
3221          $ps.=$i."\n" if($i && $i!~/^%/);
3222        }
3223        if($ps=~/\nTeXDict begin/) {
3224          if(!$ph) {
3225            $ph="/DH {1 F div dup scale /showpage {} D\n$`$&} D\n%EndDH\n";
3226            $pv=$ph.$pv;
3227          }
3228          $ps="save -$llx -$lly translate\nDH$' restore";
3229        }
3230      }
3231      $nimg++;
3232      $nps--;
3233      push(@XS,$xs);
3234      push(@YS,$ys);
3235      push(@IX,$nps);
3236      push(@IT,2);
3237      $pv.="/P$nimg {$ps} D\n";
3238      $eps{"P$nimg"}=$ps;
3239      $_=$beg.")$above 3 (P$nimg) $nimg IM(".$end;
3240    } else {
3241      $math=~s/<math$R//i;
3242      $_=$beg.$math.$end;
3243    }
3244  }
3245  chdir $cwd;
3246  s|<[sS][uU][bB]$R|)Sb(|g;
3247  s|<[sS][uU][pP]$R|)Sp(|g;
3248  s"</[sS][uU]([bB]|[pP])>")Es("g;
3249  s|<[A-Za-z/!?]\w*$R||g;
3250  &ent($_);
3251  y/\003/>/;
3252  s/\004([^\004]*)\004/")".&getl($1)." Sl($&"/eg;
3253  if($opt_H) {
3254    &dbg("Inserting potential hyphenation points\n") if($opt_d && $ndoc>0);
3255    $temp="";
3256    while(/\004([^\004]*)\004/) {
3257      $temp.=$`;
3258      $lang=$1;
3259      $end=$';
3260      if($end=~/\004([^\004]*)\004/) {
3261        $htext=$`;
3262        $end=$&.$';
3263      } else {
3264        $htext=$end;
3265        $end="";
3266      }
3267      $apa="";
3268      while($htext=~/(..?)\(([^)]*)/) {
3269        $slut=$';
3270        if($1 eq "XX") {
3271          $apa.=$`.$&;
3272          if($'=~/RP\(/) {
3273            $apa.=$`;
3274            $htext=$&.$';
3275          } else {
3276            $apa.=$slut;
3277            $htext="";
3278          }
3279        } elsif($1 eq ") ") {
3280          $apa.=$`.$&;
3281          $htext=$';
3282        } else {
3283          $apa.="$`$1(";
3284          $htext=$';
3285          ($txt=$2)=~s/[$ltrs]{$hyphenation{'min'},}/&hyph($&)/eg;
3286          $apa.=$txt;
3287        }
3288      }
3289      $_=$apa.$slut.$end;
3290    }
3291    $_=$temp.$_;
3292  }
3293  s/\004([^\004]*)\004//g;
3294  $_[0]=$_;
3295}
3296sub ent {
3297  local($_)=@_;
3298  s|&#x($X+);?|"&#".hex($1).";"|egi;
3299  for $char (keys %ent) {s/&($char)(;|$|(?=\W))/chr($ent{$char})/eg};
3300  for $char (keys %symb) {s/&($char)(;|$|(?=\W))/)SY(\\$symb{$char})ES(/g};
3301  s/&(euro|#8364)(;|$|(?=\W))/)MY(e)ES(/g;
3302  s|&lt;?|<|g;
3303  s|&gt;?|>|g;
3304  s|&quot;?|"|g;
3305  s/&($space);?/)$space{$1} Se(/g;
3306  s|&#(\d+);?|$1==38?"\005":$1<256?chr($1):$&|eg;
3307  s/(\005|&amp;?)/\&/g;
3308  $_[0]=$_;
3309}
3310sub spec {
3311  $_[0]=~s/(\\|&#92(;|$|(?=\W)))/\\200/g;
3312  $_[0]=~s/(\(|&#40(;|$|(?=\W)))/\\201/g;
3313  $_[0]=~s/(\)|&#41(;|$|(?=\W)))/\\202/g;
3314  $_[0]=~s/&(there4|#8756|#[xX]2234)(;|$|(?=\W))/)SY(\\200)ES(/g;
3315}
3316sub math2tex {
3317  local($_)=@_;
3318  local($beg,$rest);
3319  %a=("line","overline",
3320  "cub","overbrace",
3321  "hat","widehat",
3322  "tilde","widetilde",
3323  "larr", "overleftarrow",
3324  "rarr", "overrightarrow");
3325  %b=("line","underline",
3326  "cub","underbrace",
3327  "hat","widehat",
3328  "tilde","widetilde");
3329  %s=("medium","\\big",
3330  "large","\\Big",
3331  "huge","\\bigg");
3332  ($mattr)=/<math$R/i;
3333  $st=$mattr=~/class\s*=\s*["']?chem/i?'\rm ':'';
3334  $di=$mattr=~/class\s*=\s*["']?displayed/i?'\displaystyle ':'';
3335  s/<math$R//gi;
3336  s/\\/\\backslash/g;
3337  s/__/_\\>_/gi;
3338  s/\^\^/^\\>^/gi;
3339  s/_([^_]+)_/_{$1}/g;
3340  s/\^([^^]+)\^/^{$1}/g;
3341  s/&thinsp;?/\\,/g;
3342  s/&sp;?/\\>/g;
3343  s/&emsp;?/\\;/g;
3344  s/&nbsp;?/\\>/g;
3345  s/&epsi;?/\\varepsilon /g;
3346  s/&upsi;?/\\upsilon /g;
3347  s/&piv;?/\\varpi /g;
3348  s/&sigmav;?/\\varsigma /g;
3349  s/&thetav;?/\\vartheta /g;
3350  s/&phiv;?/\\varphi /g;
3351  s/&Upsi;?/\\Upsilon /g;
3352  s/&omicron;?/o/g;
3353  s/&plusmn;?/\\pm /g;
3354  s/&or;?/\\vee /g;
3355  s/&and;?/\\wedge /g;
3356  s/&ap;?/\\approx /g;
3357  s/&sube;?/\\subseteq /g;
3358  s/&sub;?/\\subset /g;
3359  s/&supe;?/\\supseteq /g;
3360  s/&sup;?/\\supset /g;
3361  s/&isin;?/\\in /g;
3362  s/&larr;?/\\leftarrow /g;
3363  s/&rarr;?([_^])/\\mathop\\rightarrow\\limits$1 /g;
3364  s/&rarr;?/\\rightarrow /g;
3365  s/&uarr;?/\\uparrow /g;
3366  s/&darr;?/\\downarrow /g;
3367  s/&harr;?/\\leftrightarrow /g;
3368  s/&lArr;?/\\Leftarrow /g;
3369  s/&rArr;?/\\Rightarrow /g;
3370  s/&uArr;?/\\Uparrow /g;
3371  s/&dArr;?/\\Downarrow /g;
3372  s/&exist;?/\\exists /g;
3373  s/&inf;?/\\infty /g;
3374  s/&?int;?/\\int\\limits /g;
3375  s/&?sum;?/\\sum\\limits /g;
3376  s/&?prod;?/\\prod\\limits /g;
3377  s/&pd;?/\\partial /g;
3378  s/&lcub;?/\\{/g;
3379  s/&rcub;?/\\}/g;
3380  s/<t>/\\hbox{/gi;
3381  s/<b>/\\bf /gi;
3382  s/<bt>/{\\bf\\hbox{/gi;
3383  s/<sub$R/_{/gi;
3384  s/<sup$R/\^{/gi;
3385  s/<box\s*size=["']?(\w+)["']?>/{\\def\\lft{$s{$1}}\\def\\rgt{$s{$1}}/gi;
3386  s/<box$R/{/gi;
3387  s/<text\s*>/\\hbox{/gi;
3388  s/([\(\[\|])\s*<left>/\\lft$1/gi;
3389  s/<right>/\\rgt /gi;
3390  s/<(atop|choose|over)>/\\\L$1 /gi;
3391  s/<of>/}\\of{/gi;
3392  s/<bar>/\\overline{/gi;
3393  s/<vec>/\\overrightarrow{/gi;
3394  s/<hat>/\\widehat{/gi;
3395  s/<tilde>/\\widetilde{/gi;
3396  s/<(sqrt|root|vec|dot|ddot|hat|tilde)>/\\\L$1\{/gi;
3397  while(/<above\s+sym\s*=\s*["']?equals["']?\s*>/i) {
3398    $beg=$`."\\overline{\\overline{";
3399    $rest=$';
3400    $rest=~s/<\/above>/}}/i;
3401    $_=$beg.$rest;
3402  }
3403  s/<above\s*>/\\overline{/gi;
3404  s/<above\s+sym\s*=\s*["']?(\w+)["']?\s*>/\\$a{$1}\{/gi;
3405  s/<below\s*>/\\underline{/gi;
3406  s/<below\s+sym\s*=\s*["']?(\w+)["']?\s*>/\\$b{$1}\{/gi;
3407  s/<\/(math|row|item|b)>//gi;
3408  s/<\/(box|t|sup|sub|sqrt|root|vec|bar|dot|ddot|hat|tilde|above|below|text|array)>/}/gi;
3409  s/<\/bt>/}}/gi;
3410  s/&lt;?/< /gi;
3411  s/&gt;?/>/gi;
3412  s/&(\w+);?/\\$1 /gi;
3413  s/<array$R/\\matrix{/gi;
3414  s/<row>\s*<item$R//i;
3415  s/<row>\s*<item$R/\\cr /gi;
3416  s/<item>/&/gi;
3417  s/<[^ ]$R//gi;
3418  s/\n*$//;
3419  $tex="\\batchmode\\magnification=$mag\\hsize=40cm\\nopagenumbers\n"
3420 ."\\def\\lft{\\left}\\def\\rgt{\\right}\n\\setbox0=\\hbox{\$$st$di".$_."\$}\n"
3421 ."\\immediate\\write0{$prog: \\the\\ht0: \\the\\dp0}\\box0\n\\end\n";
3422}
3423sub Getopts {
3424  local($optlist)=@_;
3425  local(@args,$_,$opt,$opts,$rest,$olist,$plist,$found,@popts);
3426  local($errs)=0;
3427  @args=split( /\|/, $optlist );
3428  for $opt (@args) {
3429    if(substr($opt,-1,1) ne ':') {$olist.=$opt}
3430    else {$plist.=$opt}
3431  }
3432  @popts=split(/:/,$plist);
3433  while(@ARGV && ($_=$ARGV[0]) =~ /^-(.*)/) {
3434    $opt=$1;
3435    if($opt=~/^-/ && $optalias{"\L$'"}) {$opt=$optalias{"\L$'"}};
3436    if($opt =~ /^[$olist]+$/) {
3437      while ($char=chop $opt) {eval "\$opt_$char=1"}
3438      shift(@ARGV);
3439    }
3440    else {
3441      $found=0;
3442      for $opts (@popts) {
3443        $rest=substr($opt,length($opts));
3444        if(index($opt,$opts)==0) {
3445          $found=1;
3446          shift(@ARGV);
3447          if(length($rest)==0) {
3448            ++$errs unless @ARGV;
3449            $rest=shift(@ARGV);
3450          }
3451          eval "\$opt_$opts=\$rest";
3452        }
3453      }
3454      if(!$found) {
3455        &dbg("Unknown option: $opt\n");
3456        ++$errs;
3457        shift(@ARGV);
3458      }
3459    }
3460  }
3461  $errs==0;
3462}
3463sub openps {
3464  open(STDOUT,">$opt_o") || die "*** Error opening $opt_o for output\n";
3465}
3466sub getalt {
3467  if($imgcmd eq "img") {
3468    $alt="";
3469    $match=0;
3470    if($img=~/alt\s*=\s*"([^"]*)"/i) {$alt=$1; $match=1};
3471    if(!$match && $img=~/alt\s*=\s*([\w\.-]+)/i) {$alt=$1; $match=1};
3472    if(!$match) {$alt=")WB IA WB("};
3473    $text="$alt )WB(";
3474    return;
3475  }
3476  if($imgcmd eq "hr") {
3477    $text=$img=~/align\s*=\s*["']?(left|center|right)/i?")$algn{lc $1} ":")2 ";
3478    $text.=$img=~/size\s*=\s*["']?$V/i?$1:.6;
3479    $wd=1;
3480    if($img=~/width\s*=\s*["']?$V(%?)/i) {$wd=$2?$1/100:-$1};
3481    $text.=" $wd HR(";
3482    return;
3483  }
3484  if($imgcmd eq "fig") {
3485    $text=")BN(";
3486  }
3487}
3488sub xbmtops {
3489  $fc=1;
3490  $dp=1;
3491  ($xs,$ys)=$pic=~/^#define.* (\d+)[\w\W]*^#define.* (\d+)/;
3492  $nd=2*int(($xs+7)/8)*$ys;
3493  ($pic)=$pic=~/[^#].* char.*[\w\W]*{([\w\W]*)}/;
3494  $pic=~s/[ ,\n\r]*0x[ ,]*//g;
3495  $pic=~y/01246789bdef/f7bd91e62480/;
3496  $bm=unpack("H*", pack("h*",$pic));
3497}
3498sub pmtops {
3499  pmtoraw($pm) if($pm=~/^P([1-3])/);
3500  $pm=~/^P([4-6])/;
3501  $maptype=$1;
3502  return if(!$maptype);
3503  $pm=$';
3504  $bm="";
3505  $nint=3;
3506  $dp=8;
3507  if($maptype==4) {
3508    $nint=2;
3509    $dp=1;
3510  }
3511  undef @num;
3512  $found=0;
3513  while($pm && $found<$nint) {
3514    if($pm=~/^\s*(\d+)/) {$num[$found]=$1};
3515    if($num[$found]) {
3516      $found++;
3517      $pm=$';
3518    } elsif($pm=~/^\s*#.*\n/) {
3519      $pm=$';
3520    } else {
3521      return;
3522    }
3523  }
3524  ($b)=$pm=~/\s([\w\W]*)/;
3525  ($xs,$ys,$bits)=@num;
3526  return if($bits>255);
3527  $fc=1;
3528  if($maptype==6) {
3529    $fc=3;
3530    $nd=6*$xs*$ys;
3531    $bm=unpack("H*",$b);
3532  } else {
3533    $bm=unpack("H*",$b);
3534    if($maptype==4) {
3535      $nd=2*int(($xs+7)/8)*$ys;
3536      $bm=~y/0123456789abcdef/fedcba9876543210/;
3537    } else {
3538      $nd=2*$xs*$ys;
3539    }
3540  }
3541}
3542sub trans {
3543  $next = 13;
3544  $temp = ord substr($pic,10,1);
3545  if($temp & 0x80) {$next += 3*2**(($temp & 0x07) + 1)} else {return};
3546  $byte = ord substr($pic,$next,1);
3547  while($byte != 0x3b && $next <= length $pic) {
3548    if($byte == 0x21) {
3549      if(ord substr($pic,$next+1,1) == 0xf9) {
3550        if(ord substr($pic,$next+3,1) & 0x01) {
3551          &dbg("Transparent\n") if($opt_d);
3552          $src{$URL}=$pic;
3553          $idx = 3*(ord substr($pic,$next+6,1))+13;
3554          substr($pic,$idx,3) = pack("H*",$red.$grn.$blu) if($idx<length $pic);
3555        }
3556        return;
3557        $next += 2;
3558        &skip;
3559      } else {
3560        $next += 2;
3561        &skip;
3562      }
3563    } elsif($byte == 0x2c) {
3564      $next += 10;
3565      $temp = ord substr($pic,$next-1,1);
3566      if($temp & 0x80) {$next += 3*2**(($temp & 0x07) + 1)};
3567      $next++;
3568      &skip;
3569    } else {return}
3570  }
3571}
3572sub skip {
3573  $byte = ord substr($pic,$next,1);
3574  while($byte != 0) {
3575    $next += $byte + 1;
3576    $byte = ord substr($pic,$next,1);
3577  }
3578  $next++;
3579  $byte = ord substr($pic,$next,1);
3580}
3581sub run {
3582  &dbg("@_\n") if($opt_d);
3583  $pm=`@_`;
3584}
3585sub geturl {
3586  local($url)=@_;
3587  &dbg("Retrieving $url");
3588  if($package{'libwww-perl'} || $package{'jfriedl'}) {
3589    warn "\n";
3590    &gu();
3591    if($code==401) {
3592      &prompt("\nDocument requires username and password\n\nUsername: ",$user);
3593      &prompt("Password: ",$pass);
3594      &gu($user,$pass);
3595    }
3596    $_[1]=$cont;
3597  } elsif(defined $geturl) {
3598    &dbg("...");
3599    $_[1]=`$geturl '$url'`;
3600    if($?) {
3601      &dbg("\n*** Error opening $url\n");
3602      return 0;
3603    }
3604    &dbg("done\n");
3605    if($_[1]=~/\r?\n\r?\n/) {
3606      $_[1]=$';
3607      $dhead=$`;
3608      ($code)=$dhead=~/HTTP\/\S+ +(\d+)/i;
3609      ($contyp)=$dhead=~/Content-type:\s+(.*)/i;
3610    } else {
3611      $code=500;
3612    }
3613  }
3614  $_[0]=$url;
3615  $code<300;
3616}
3617sub gu {
3618  if($package{'libwww-perl'}) {
3619    require LWP::UserAgent;
3620    $ua=new LWP::UserAgent;
3621    $ua->env_proxy();
3622    if ($opt_k) {
3623      require HTTP::Cookies;
3624      $cookie_jar = HTTP::Cookies::Netscape->new(File => $opt_k, AutoSave => 1);
3625      $ua->cookie_jar($cookie_jar);
3626    }
3627    $req = HTTP::Request->new(GET => $url);
3628    $req->authorization_basic(@_) if(@_);
3629    $ua->agent($spoof) if($spoof);
3630    my $res = $ua->request($req);
3631    $code=$res->code;
3632    $contyp=$res->header('content-type');
3633    $cont=$res->content;
3634  } else {
3635    require "www.pl";
3636    @opts=@_?("authorization=$_[0]:$_[1]"):();
3637    push(@opts,"quiet") if(!$opt_d);
3638    $www::useragent=$spoof if($spoof);
3639    ($status,$memo,%info)=&www::open_http_url(*FILE,$url,@opts);
3640    $code=$info{'CODE'};
3641    ($contyp)=$info{'HEADER'}=~/Content-type:\s+(.*)/i;
3642    $cont=<FILE>;
3643  }
3644}
3645sub pictops {
3646  if($opt_g) {
3647    $fc=1;
3648    $pg1="pgm";
3649    $pg2="|ppmtopgm";
3650  } else {
3651    $fc=3;
3652    $pg1="ppm";
3653    $pg2="";
3654  }
3655  ($type)=$URL=~/([^\?]+)\??/;
3656  ($type)=$type=~/\.(\w+)$/;
3657  $bm="";
3658  $ps="";
3659  $pm="";
3660  if($opt_U && $src{$URL} && !$cmd{$URL.$red.$grn.$blu}) {
3661    $pic=$src{$URL};
3662  } elsif($URL=~m|://|) {
3663    &geturl($URL,$pic) || return;
3664  } else {
3665    $flag=0;
3666    if($opt_O) {
3667      $orig=$URL;
3668      unless($orig=~s/\.\w*$/.ps/) {$orig.=".ps"};
3669      if(open(ORIG,"<$orig")) {
3670        $pic=<ORIG>;
3671        close ORIG;
3672        if($pic=~/^%!/ && $pic=~/%%BoundingBox:/) {
3673          $flag=1;
3674          &dbg("Using $orig as original for $URL\n") if($opt_d);
3675        }
3676      }
3677    }
3678    if(!$flag) {
3679      if(open(PIC,"<$URL")) {
3680        binmode PIC;
3681        $pic=<PIC>;
3682        close PIC;
3683      } else {
3684        &dbg("*** Error opening $URL\n");
3685        return;
3686      }
3687    }
3688  }
3689  $pic=~s/^[\n\r]*//;
3690  &trans if($pic=~/^GIF/);
3691  if($pic=~/^P[1-6]/) {
3692    $pm=$pic;
3693  } else {
3694    open(SCRATCH,">$scr");
3695    binmode(SCRATCH);
3696    print SCRATCH "$pic";
3697    close SCRATCH;
3698    if($pic=~/^%!/ && $pic=~/%%BoundingBox: +$V +$V +$V +$V/) {
3699      $xs=$3-$1;
3700      $ys=$4-$2;
3701      $ps="save\n0 0 M\nIS IS scale\n/showpage {}D\n".(0-$1)." ".(0-$2)." translate\n";
3702      for $i (split(/\n/,$pic)) {
3703        $ps.=$i."\n" if($i && $i!~/^%/);
3704      }
3705      $ps.="restore";
3706    } elsif($type=~/.xbm$/i || $pic=~/^#define/) {
3707      &xbmtops;
3708    } elsif($package{'ImageMagick'}) {
3709      if($package{'PerlMagick'}) {
3710        $imobj=Image::Magick->new;
3711        $mess=$imobj->Read($scr);
3712        if($mess) {
3713          &dbg("$mess\n");
3714        } else {
3715          $mess=$imobj->Write("$scr\.$pg1");
3716          &dbg("$mess\n") if($mess);
3717        }
3718        undef $imobj;
3719      } else {
3720#        &run("convert $scr $pg1:-");
3721        &run("convert $scr $scr\.$pg1");
3722      }
3723      open(PNM,"$scr\.$pg1");
3724      binmode PNM;
3725      $pm=<PNM>;
3726      close PNM;
3727      if(!$pm && $pic=~/^\377\330/ && $package{'djpeg'}) {
3728        &run("djpeg $scr$pg2");
3729      }
3730    } elsif($pic=~/^\377\330/ && $package{'djpeg'}) {
3731      &run("djpeg $scr$pg2");
3732    } elsif($package{'pbmplus'} || $package{'netpbm'}) {
3733      if($pic=~/^GIF/) {
3734        &run("$giftopm $scr");
3735      } else {
3736        &run("anytopnm $scr");
3737      }
3738      if($opt_g && $pm=~/^P6/) {
3739        open(SCRATCH,">$scr");
3740        binmode(SCRATCH);
3741        print SCRATCH $pm;
3742        close SCRATCH;
3743        &run("ppmtopgm $scr");
3744      }
3745    }
3746  }
3747  &pmtops if(!$bm);
3748  return if(!$bm);
3749  $bm=substr($bm,0,$nd);
3750  $pad=$nd-length($bm);
3751  if($pad) {$bm.="f" x $pad};
3752  $bm=~s/(.{60})/$1\n/g;
3753}
3754sub math2sym {
3755  local($_)=@_;
3756  s/<math$R//gi;
3757  for $char (keys %symb) {s/&($char)(;|$|(?=\W))/\\$symb{$char}/g};
3758  $stat=!/([&<][a-zA-Z]|[_^{])/;
3759  s/[a-zA-Z\s]*[a-zA-Z][a-zA-Z\s]*/)ES()I($&)ES()SY(/g;
3760  s/(\\200|\\201|\\202)/)RO($&)ES(/g;
3761  $sym=")SY($_)ES(";
3762  $stat;
3763}
3764sub varsub {
3765  for (@_) {
3766    s/\\\\/\000/g;
3767    s/\([^)]+\)/()$&join /g;
3768    s/(^|[^\\])\$(T|N|U|H|A)/$1)join $vars{$2} join(/g;
3769    s/(^|[^\\])\$D\{"(.*?)"\}/"$1".POSIX::strftime($+,@now)/eg if($posix);
3770    s/(^|[^\\])\$D/"$1".POSIX::strftime($datefmt,@now)/eg if($posix);
3771#    while(/(?=[^\\])\${([^}]+)}/) {
3772    while(/(?=[^\\])\$\[([^]]+)\]/) {
3773      if(!defined $metarc{lc $1}) {
3774        $metarc{lc $1}=$mn++;
3775      }
3776      $_="$`)join ME $metarc{lc $1} get join($'";
3777    }
3778    s/\\\$/\$/g;
3779    s/\000/\\\\/g;
3780    s/\(\)join//g;
3781    s/\(\) ?(\([^)]*\)|\w+) ?join/ $1/g;
3782  }
3783}
3784sub follow {
3785  return 0 if(!$opt_W);
3786  $H=$lnk=~/\.html?(#|$)/i || $lnk=~m|.+//.+/[^/\.]*$|;
3787  $T=$rev && ($revtoc && $ndoc==1 || $ndoc>1 && $H);
3788  $L=$b1=~m|://| && $lnk=~m"^$b1(/|$)" || $b1!~m|://| && $lnk!~m|://|;
3789  $B=$B2 && $lnk=~/^$B2/ || !$B2 && $lnk!~m"(^\.\.|://)";
3790  return $rlnk && ($H || $T) if($rel);
3791  return $L && ($H || $T) if($local);
3792  return $B && ($H || $T) if($below);
3793  return $H || $T if($rev);
3794  $H;
3795}
3796sub DSC {
3797  &dbg("Generating DSC PostScript\n") if($opt_d);
3798  %op=("moveto",2, "rmoveto",2, "lineto",2, "rlineto",2, "translate",2,
3799       "scale",2, "show",1, "awidthshow",6, "stroke",0, "save",0, "restore",0,
3800       "gsave",0, "grestore",0, "showpage",0, "newpath",0, "setlinewidth",1,
3801       "setlinejoin",1, "setgray",1, "closepath",0, "fill",0, "arc",5,
3802       "setrgbcolor",3, "rotate",1, "image",5, "colorimage",7);
3803  %sho=("moveto","M", "rmoveto","RM", "lineto","L", "rlineto","RL", "show","S",
3804        "showpage","N", "awidthshow","A");
3805  $i=0;
3806  $po="/OU true D\n";
3807  for (keys %op) {
3808    $cmd=$sho{$_}?$sho{$_}:$_;
3809    push(@val,$cmd);
3810    $in{$_}=$i++;
3811    $j=$op{$_}+1;
3812    $extra="";
3813    if(/showpage/) {$extra="Bb{Xl Yl Xh Yh}if Pn "};
3814    if(/image/) {$extra="K2 ";$j++};
3815    $t=$op{$_}?"$op{$_} copy $extra$in{$_} $j array astore":"[$extra$in{$_}]";
3816    $po.="/$_ {OU {$t ==} if $_}d\n";
3817  }
3818  $po.="/pdfmark {$i] ==} D\n";
3819  $in{"pdfmark"}=$i++;
3820  push(@val,"pdfmark");
3821  $po.="/NF {OU{2 copy E $i 3 array astore ==}if ONF}d\n"
3822      ."/EX {[IS EC] ==} D\n/Cd {} D\n/DU {TU PM 1 eq and TP and{Pn ==}if}d\n"
3823      ."/BB {US Bb{dup Yl lt{dup /Yl E D}if dup Yh gt{/Yh E D}{pop}ie\n"
3824      ." dup Xl lt{dup /Xl E D}if dup Xh gt{/Xh E D}{pop}ie}\n"
3825      ." {/Yl E D /Yh Yl D /Xl E D /Xh Xl D /Bb t D}ie}D\n";
3826  $in{"Nf"}=$i++;
3827  s|/(NF.*)|/O$1|;
3828  s|/BB .*|$po|;
3829  push(@val,"Nf");
3830  if($psin) {
3831    ($ti)=/%%Title: (.*)/;
3832    if(m|/BM (\d+)|) {
3833      $nbit=$1;
3834      for $vec ("IT","WS") {
3835        /\/$vec \[(.*)\]/;
3836        @$vec=split(' ',$1);
3837      }
3838      /\nSB/;
3839      for (0..$nbit-1) {
3840        $'=~/\n\n/;
3841        push(@BM,$`);
3842      }
3843    }
3844    ($epsf)=/(\n\/P\d+_?\d* [\w\W]*)%Endpv/;
3845    while($epsf=~/\n\/(P\d+_?\d*) \{/g) {
3846      $pid=$1;
3847      $rest=$';
3848      $temp=$'=~/\/P\d+_?\d* \{/?$`:$rest;
3849      ($eps{$pid})=$temp=~/([\w\W]*)} D/;
3850    }
3851    if(/\/DH {/) {
3852      $'=~/%EndDH/;
3853      $ph="/DH {$`";
3854    }
3855  }
3856  $j=-1;
3857  for $i (0..$#IT) {
3858    $j++ if($IT[$i] == 0);
3859    push(@ix,$j);
3860  }
3861  $dfn="/F $opt_s D\n$ph";
3862  for (keys %sho) {
3863    $dfn.="/$sho{$_} {$_} d\n";
3864  }
3865
3866  open(SCR,">$scr.ps");
3867  print SCR "$_ quit\n";
3868  close SCR;
3869  $cd{')]'}="Cd ";
3870  $io="($in{'image'}|$in{'colorimage'})";
3871  $_="";
3872  $temp="";
3873  $pn="";
3874  $start=1;
3875  $EPS="%%EndPageSetup";
3876  $pp=0;
3877  $n=0;
3878
3879  for $line (split(/\r?\n/,`$gs -q -dNODISPLAY $scr.ps -c quit`)) {
3880    if(!$pp) {
3881      $mv="";
3882      $cx="";
3883      $cy="";
3884    }
3885    if($start && $line!~/ $in{"pdfmark"}\]$/) {
3886      $pdf=$temp;
3887      $temp="";
3888      $start=0;
3889    }
3890    $pp=$line=~/^\[(\S+) (\S+) ($in{'moveto'}|$in{'rmoveto'}|$in{'Nf'})\]$/;
3891    S:{
3892      if($pp && $3==$in{"Nf"}) {
3893        $fn="$1 $2 $val[$3]\n";
3894        last S;
3895      }
3896      if($pp && $3==$in{"moveto"}) {
3897        $cx=$1;
3898        $cy=$2;
3899        $mv=sprintf("%.1f %.1f %s\n",$1,$2,$val[$3]);
3900        last S;
3901      }
3902      if($pp && $3==$in{"rmoveto"}) {
3903        if($mv) {
3904          $cx+=$1;
3905          $cy+=$2;
3906          $mv=sprintf("%.1f %.1f %s\n",$cx,$cy,$val[$in{"moveto"}]);
3907        } else {
3908          $temp.=sprintf("%.1f %.1f %s\n",$1,$2,$val[$3]) if($1||$2);
3909        }
3910        last S;
3911      }
3912      if($line=~s/^\[(.*)\((\S*)\) ($in{"showpage"})\]$/pgsave restore $val[$3]/) {
3913        $pbb="";
3914        if($1) {
3915          ($llx,$lly,$urx,$ury)=split(/ /,$1);
3916          $llx=int($llx);
3917          $lly=int($lly);
3918          $urx=int($urx+1);
3919          $ury=int($ury+1);
3920          $pbb="%%PageBoundingBox: $llx $lly $urx $ury\n";
3921          if(!defined($Llx) || $llx<$Llx) {$Llx=$llx};
3922          if(!defined($Lly) || $lly<$Lly) {$Lly=$lly};
3923          if(!defined($Urx) || $urx>$Urx) {$Urx=$urx};
3924          if(!defined($Ury) || $ury>$Ury) {$Ury=$ury};
3925        }
3926        $pn.="," if($pn && $2);
3927        $n++;
3928        @df=();
3929        for(0..$#docfonts) {
3930          push(@df,$docfonts[$_]) if($uf{$_}==$n);
3931        }
3932        push(@df,"Symbol") if($uf{"-1"}==$n);
3933        $fu="";
3934        $tmp=@df?"%%PageResources: font":"";
3935        &splitline(@df);
3936        $_.="%%Page: $pn$2 $n\n$fu$pbb%%BeginPageSetup\n/pgsave save D\n$temp$line\n";
3937        $EPS="%%EndPageSetup";
3938        $temp="";
3939        $line="";
3940        $fn="";
3941        $mv="";
3942        $pn="";
3943        last S;
3944      }
3945      if($line=~/^\[([^(]*)(\(.*\)) ($in{"show"}|$in{"awidthshow"})\]$/) {
3946        if(length $2>2) {
3947          $line="$fn$1$2 $val[$3]";
3948          if($fn=~/(\S+) Nf/ && $uf{$1}!=$n+1) {
3949            $uf{$1}=$n+1;
3950            $fnt=$1<0?"Symbol":$docfonts[$1];
3951            $line="%%IncludeResource: font $fnt\n$line";
3952          }
3953          $fn="";
3954          $pp=0;
3955        } else {
3956          $pp=1;
3957        }
3958        last S;
3959      }
3960      if($line=~/^\[(\S+) (\S+) ($in{"scale"})\]$/) {
3961        $line=$1!=1||$2!=1?"$1 $2 $val[$3]\n$EPS":"$EPS";
3962        $EPS="";
3963        last S;
3964      }
3965      if($line=~/^\[(.*) (\d+) $io\]$/) {
3966        $li=$BM[$2]=~y/\n/\n/+2;
3967        $line="\/picstr $WS[$ix[$2]] string D\n$1\n"
3968             ."%%BeginData: $li Hex Lines\n$val[$3]\n$BM[$2]\n%%EndData";
3969        last S;
3970      }
3971      if($line=~/^\((.*)\)$/) {
3972        $pn=$1;
3973        $line="";
3974        last S;
3975      }
3976      last S if($line=~s/^\[([^\/].* )?(\d+)\]$/$1$val[$2]/);
3977      last S if($line=~s/(\)\])? (\/\w+) $in{"pdfmark"}\]$/$1 $cd{$1}$2 pdfmark/);
3978      last S if($line=~s/^\[(\S+) \((P\d+.*)\)\]$/\/IS $1 D\n$eps{$2}/);
3979      &dbg("$line\n");
3980    }
3981    if(!$pp && $mv.$line) {
3982      $mv=~s/\.0//g;
3983      $temp.="$mv$line\n";
3984    }
3985  }
3986  @nf=();
3987  @sf=();
3988  $fontdef="";
3989  for(0..$#docfonts) {
3990    $ff=$ff{$docfonts[$_]};
3991    if($ff && $uf{$_}>0) {
3992      push(@sf,$docfonts[$_]);
3993      $fontdef.="%%BeginResource: font $docfonts[$_]\n$cont{$ff}\n%%EndResource\n";
3994      $cont{$ff}="";
3995    }
3996    push(@nf,$docfonts[$_]) if(!$ff && $uf{$_}>0);
3997  }
3998  push(@nf,"Symbol") if($uf{"-1"}>0);
3999  $ti="@ARGV" unless($psin);
4000  $or=$opt_L?"Landscape":"Portrait";
4001  $setup="%%BeginSetup\n";
4002  $setup.="$dupl\n" if($dupl);
4003  $setup.="$fontdef" if($fontdef);
4004  $fu="";
4005  $tmp=@nf?"%%DocumentNeededResources: font":"";
4006  &splitline(@nf);
4007  $tmp=@sf?"%%DocumentSuppliedResources: font":"";
4008  &splitline(@sf);
4009  s/\\(200|201|202)/\\$ssy{$1}/g;
4010  $dd="Clean7Bit";
4011  $dd="Clean8Bit" if(($fontdef.$_)=~/[\200-\377]/);
4012  $dd="Binary" if(($fontdef.$_)=~/[\000-\010\013-\014\016-\036]/);
4013  $time=localtime;
4014  print <<EOT;
4015%!PS-Adobe-3.0
4016%%Title: $title
4017%%Creator: $version
4018%%CreationDate: $time
4019$fu%%DocumentData: $dd
4020%%Orientation: $or
4021%%BoundingBox: $Llx $Lly $Urx $Ury
4022%%Pages: $n
4023%%EndComments
4024%%BeginProlog
4025/d {bind def} bind def
4026/D {def} d
4027/ie {ifelse} d
4028/E {exch} d
4029/t true D
4030/f false D
4031$fl
4032$cd
4033$defs
4034$mysymb/Nf {dup 0 ge{FL E get}{-1 eq{/Symbol}{/MySymbol}ie}ie findfont
4035 E scalefont setfont} D
4036/IP {currentfile picstr readhexstring pop} D
4037/WF $wf D
4038$dfn%%EndProlog
4039$setup$reenc$pdf%%EndSetup
4040$_%%EOF
4041EOT
4042}
4043sub splitline {
4044  for (@_) {
4045    if(length($tmp.$_)>78) {
4046      $fu.="$tmp\n";
4047      $tmp="%%+ font";
4048    }
4049    $tmp.=" $_";
4050  }
4051  $fu.="$tmp\n" if($tmp);
4052}
4053sub ref {
4054  @pnum=();
4055  /.*\s*$/;
4056  open(SCR,">$scr.ps");
4057  print SCR "$`HN{==}forall $& quit\n";
4058  close SCR;
4059  $pnum=`$gs -q -dNODISPLAY $scr.ps -c quit`;
4060  while($pnum=~/\([^)]*\)/g) {push(@pnum,$&)};
4061  $pnum="@pnum";
4062  &cut($pnum);
4063  s|/HN [^D]*D|/HN [$pnum] D|;
4064}
4065sub cut {
4066  $_[0]=~s/(.{70}[^ \n]*) ([^ ])/$1\n$2/g;
4067}
4068sub fin {
4069  if($opt_D) {
4070    &DSC;
4071  } else {
4072    print;
4073  }
4074  if($opt_d) {
4075    print DBG "\n";
4076    close DBG;
4077  }
4078  unlink "$scr","$scr.ps","$scr.ppm","$scr.tex","$scr.dvi","$scr.log" if($scr);
4079  exit;
4080}
4081sub col2rgb {
4082  $rgb=$colour{"\L$_[0]"}?($colour{"\L$_[0]"}):$_[0];
4083  @cvec=$rgb=~/($X$X)($X$X)($X$X)/?($1,$2,$3):();
4084  @cvec?"[16#$1 16#$2 16#$3]":"";
4085}
4086sub inihyph {
4087  if($hyphenation_file{$lang}) {
4088    $hyfile=$hyphenation_file{$lang};
4089  } else {
4090    &dbg("No hyphenation file for language '$lang'\n");
4091    $lng=$lang;
4092    while($lng=~s/-?[^-]+$// && !$hyphenation_file{$lng}) {};
4093    $hyfile=$hyphenation_file{$lng};
4094    &dbg(" ..using $hyfile\n");
4095  }
4096  if($init{$hyfile}) {
4097    $rep{$lang}=$refl{$hyfile};
4098    return;
4099  }
4100  if(open(HYPH,"<$hyfile")) {
4101    &dbg("Reading hyphenation patterns from $hyfile\n") if($opt_d);
4102    <HYPH>=~/\\patterns{.*/;
4103    close HYPH;
4104    $def=$`;
4105    ($patterns=$')=~s/\^\^($X$X)/chr hex $1/eg;
4106    $upp{$lang}='';
4107    $low{$lang}='';
4108    while ($def=~/\\lccode(`\\?\^\^|")($X$X)=(`\\?\^\^|")($X$X)/g) {
4109      if($2 ne $4) {
4110        $uc=$2;
4111        $lc=$4;
4112        if($`=~/\n$/ || $`!~/%.*$/) {
4113          $upp{$lang}.=chr hex $uc;
4114          $low{$lang}.=chr hex $lc;
4115        }
4116      }
4117    }
4118    while ($def=~/\\let\\(\w+)=(\^\^|")($X$X)/g) {
4119      $key=$1;
4120      $value=chr hex $3;
4121      $tex{$key}=$value if($`=~/\n$/ || $`!~/%.*$/);
4122    }
4123    for $key (keys %tex) {
4124      $patterns=~s/\\$key */$tex{$key}/g;
4125    }
4126    if($lang=~/^de/) {
4127      %de=('"a',228, '"o',246, '"u',252, '\3', 223);
4128      $patterns=~s/\\c\{[^}]*\}//g;
4129      $patterns=~s/\\n\{([^}]*)\}/$1/g;
4130      $patterns=~s/("a|"o|"u|\\3)/chr $de{$1}/eg;
4131      $upp{"de"}=~s/\337//;
4132      $low{"de"}=~s/\377//;
4133    }
4134    if($lang=~/^is/ && !$upp{"is"}) {
4135      %is=("'a","\341", "'e","\351", "'i","\355", "'o","\363", "'u","\372",
4136           "'y","\375", '"x',"\346", '"o',"\366", "'d","\360", "`t","\376");
4137      $isch=join("|",keys %is);
4138      $patterns=~s/($isch)/$is{$1}/g;
4139      $upp{"is"}="\301\311\315\323\332\335\306\326\336\320";
4140      $low{"is"}="\341\351\355\363\372\375\346\366\376\360";
4141    }
4142    if($lang=~/^fi/ && !$upp{"fi"}) {
4143      $upp{"fi"}="\304\326";
4144      $low{"fi"}="\344\366";
4145    }
4146    if($lang=~/^fr/ && !$upp{"fr"}) {
4147      $upp{"fr"}="\300\302\307\311\310\312\313\316\317\324\326\333\226";
4148      $low{"fr"}="\340\342\347\351\350\352\353\356\357\364\366\373\225";
4149    }
4150    if($lang=~/^es/ && !$upp{"es"}) {
4151      $upp{"es"}="\301\311\315\323\321\332\334";
4152      $low{"es"}="\341\351\355\363\361\372\374";
4153    }
4154    $patterns=~s/\{([\w\W]*?)\}/[$1]/g;
4155    $patterns=~/}/;
4156    $end=$`;
4157    if($def.$'=~/\\hyphenation\[.*/) {
4158      $'=~/]/;
4159      $hyext=$`;
4160    }
4161    ($patterns=$end)=~s/%.*//g;
4162    for $key (split('\s+',$patterns)) {
4163      $value=$key;
4164      $key=~s/\d//g;
4165      $value=~s/^([$ltrs.])/0$1/;
4166      $value=~s/[$ltrs](\d)/$1/g;
4167      $value=~s/[$ltrs.]/0/g;
4168      $patt{"$key,$lang"}=$value if($value=~/^\d+$/);
4169    }
4170  } else {
4171    &dbg("Cannot open hyphenation file: $hyfile\n");
4172  }
4173  $hext=$hyphenation_extfile{$lang};
4174  for(split('\s*:\s*',$hext)) {
4175    if(open(HEXT,"<$_")) {
4176      &dbg("Reading hyphenation extensions from $_\n") if($opt_d);
4177      $hyext.=<HEXT>;
4178      close HEXT;
4179    } else {
4180      &dbg("Cannot open hyphenation extension file: $_\n");
4181    }
4182  }
4183  if($hyext) {
4184    for $key (keys %tex) {
4185      $hyext=~s/$key */$tex{$key}/g;
4186    }
4187    for $key (split('\s+',$hyext)) {
4188      $key=~s/\s+//g;
4189      $value="00$key\0";
4190      $key=~s/-//g;
4191      $value=~s/[$ltrs]/0/g;
4192      $value=~s/0-/1/g;
4193      $hext{"$key,$lang"}=$value;
4194    }
4195  }
4196  $refl{$hyfile}=$lang;
4197  $rep{$lang}=$lang;
4198  $init{$hyfile}=1;
4199}
4200sub hyph {
4201  $word="\L$_[0]";
4202  eval "\$word=~y/$upp{$rep{$lang}}/$low{$rep{$lang}}/" if($upp{$rep{$lang}});
4203  $len=length($word);
4204  $h=$hext{"$word,$rep{$lang}"};
4205  if($h) {
4206    @br=split(//,$h);
4207  } else {
4208    @br=(0) x ($len+3);
4209    for $i (0..$len) {
4210      for $j (0..$len-$i) {
4211        $str=substr(".$word.",$j,$i+2);
4212        $pstr=$patt{"$str,$rep{$lang}"};
4213        if($pstr) {
4214          @patt=split(//,$pstr);
4215          for $k (0..$#patt) {
4216            $br[$k+$j]=$patt[$k] if($br[$k+$j]<$patt[$k]);
4217          }
4218        }
4219      }
4220    }
4221  }
4222  $hword="";
4223  for $i (0..$len-1) {
4224    $hword.=substr($_[0],$i,1);
4225    if(($h || $i>$hyphenation{'start'}-2 && $i<$len-$hyphenation{'end'})
4226      && $br[$i+2]%2==1) {$hword.=")HY("};
4227  }
4228  $hword.=")YH(" if(length $word < length $hword);
4229  $hword;
4230}
4231sub setel {
4232  $el=$_[0];
4233  eval "\%arr=\%$el";
4234  &fs($el);
4235  push(@font,$fontid{"\L$font"});
4236  push(@styl,$styl);
4237  push(@size,$arr{'font-size'});
4238  push(@alig,$algn{$arr{'text-align'}}-1);
4239  push(@topm,$arr{'margin-top'});
4240  push(@botm,$arr{'margin-bottom'});
4241  push(@lftm,$arr{'margin-left'});
4242  push(@rgtm,$arr{'margin-right'});
4243  push(@colr,$col eq "[16#00 16#00 16#00]"?0:$col);
4244  $temp=$arr{'margin-top'}*$arr{'font-size'};
4245  $mi=$temp if($temp>$mi);
4246  $temp=$arr{'margin-bottom'}*$arr{'font-size'};
4247  $mi=$temp if($temp>$mi);
4248}
4249sub fs {
4250  $arr{'font-family'}='times' if($el ne 'p' && !$latin1 && !defined $arr{$_});
4251  for ("font-family","font-size") {
4252    $arr{$_}=$body{$_} if(!defined $arr{$_});
4253  }
4254  ($font=$arr{'font-family'})=~s/\W/-/g;
4255  if(!$font_names{"\L$font"}) {$font=$fal{$font}};
4256  if(!$font_names{"\L$font"}) {
4257    &dbg("Unknown font: $arr{'font-family'}, using $deffnt{$_[0]}\n");
4258    $font=$deffnt{$_[0]};
4259  }
4260  if(!defined $fontid{"\L$font"}) {
4261    $fontid{"\L$font"}=$nfont++;
4262    @names=split(/\s+/,$font_names{"\L$font"});
4263    for($#names+1..3) {push(@names,$names[0])};
4264    @docfonts=(@docfonts,@names);
4265  }
4266  &getval($arr{"font-size"},2);
4267  for ('left','right','top','bottom') {
4268    $arr{"margin-$_"}=0 if(!defined $arr{"margin-$_"});
4269  }
4270  for ($arr{"text-indent"},$arr{"margin-top"},$arr{"margin-bottom"},
4271       $arr{"margin-left"},$arr{"margin-right"}) {
4272    &getval($_,0);
4273  }
4274  $styl=$arr{'font-style'}=~/^(i|o)/+2*($arr{'font-weight'}=~/^b/);
4275  $col=$arr{'color'}?&col2rgb($arr{'color'}):-1;
4276}
4277sub img {
4278  local($_,$red,$grn,$blu)=@_;
4279  local($beg,$end);
4280  ($red,$grn,$blu)=("FF","FF","FF") if(!$opt_U || $red.$grn.$blu !~ /^\w{6}$/);
4281  while (/<(img|fig|hr|overlay|object)\s/i) {
4282    $imgcmd="\L$1";
4283    $beg=$`;
4284    $'=~/>/;
4285    $img=" $`";
4286    $end=$';
4287    $img=~s/\n/ /g;
4288    if($imgcmd ne "object" || $img=~/data\s*=\s*['"]?([\w\/\.:~%-]+\.$IM)/i
4289       || $img=~/type\s*=\s*['"]?(image\/|application\/postscript)/i){
4290    if($opt_T) {
4291      &getalt;
4292    } else {
4293      $al=0;
4294      $off="";
4295      ($align)=$img=~/align\s*=\s*['"]?(\w*)/i;
4296      if($align=~/^middle$/i) {$al=1};
4297      if($align=~/^top$/i) {$al=2};
4298      if($imgcmd eq "overlay") {
4299        $al=4;
4300        $xoff=0;
4301        $yoff=0;
4302        if($img=~/\s*x\s*=\s*['"]?(\d+)/i) {$xoff=$1};
4303        if($img=~/\s*y\s*=\s*['"]?(\d+)/i) {$yoff=$1};
4304        $off="$xoff $yoff ";
4305      }
4306      $url="";
4307      if($img=~/\s(src|data)\s*=\s*($S)/i) {($url)=$+=~/([^ \n]*)/};
4308      &dbg("Image: $url\n") if($opt_d && $url);
4309      $URL=$url;
4310      unless($url=~m|://|) {
4311        $url=~s/^file://;
4312        if($url=~m|^/|) {$URL=$b1.$url} else {$URL=$b2.$url}
4313      }
4314      while($URL!~m|^\.\./| && $URL=~m|[^/]*/\.\./|) {$URL=$`.$'};
4315      $URL=~s|/\./|/|g;
4316      $text=$src{$URL}?$cmd{$URL.$red.$grn.$blu}:$cmd{$URL};
4317      if(!$text || $opt_U && $src{$URL} && !$cmd{$URL.$red.$grn.$blu}) {
4318        if(!$url || $failed{$url}) {
4319          &getalt;
4320        } else {
4321          &pictops;
4322          if($bm || $ps) {
4323            &dbg("Size: $xs*$ys\n") if($opt_d);
4324            $nimg++;
4325            push(@XS,$xs);
4326            push(@YS,$ys);
4327            if($bm) {
4328              $nm++;
4329              push(@DP,$dp);
4330              push(@BM,$bm);
4331              push(@WS,int(($xs-1)*$dp/8)+1);
4332              push(@FC,$fc);
4333              push(@IX,$nm);
4334              push(@IT,0);
4335            }
4336            if($ps) {
4337              $nps--;
4338              push(@IX,$nps);
4339              push(@IT,1);
4340              $nli=30000;
4341              $n=1;
4342              $npr=$ps=~s|(.*\n){$nli}|sprintf("$&} D\n/P$nimg\_%d {",$n++)|eg;
4343              if($npr) {
4344                $proc=" (";
4345                for $i (0..$npr) {
4346                  $proc.="P$nimg\_$i ";
4347                }
4348                $proc.=")";
4349                $pv.="/P$nimg\_0 {$ps} D\n";
4350                $eps{"P$nimg\_0"}=$ps;
4351              } else {
4352                $proc=" (P$nimg)";
4353                $pv.="/P$nimg {$ps} D\n";
4354                $eps{"P$nimg"}=$ps;
4355              }
4356            }
4357            $text="$proc $nimg IM(";
4358            $cmd{$URL}=$text if(!$cmd{$URL});
4359            $cmd{$URL.$red.$grn.$blu}=$text if($src{$URL});
4360            $proc="";
4361            $end=$' if($imgcmd eq "object" && $end=~m|</object>|i);
4362          } else {
4363            &getalt;
4364            $failed{"$url"}=1;
4365          }
4366        }
4367      } elsif($imgcmd eq "object" && $end=~m|</object>|i) {
4368        $end=$';
4369      }
4370    }
4371    if($cmd{$URL}) {
4372      $text=")".$off.$al.$text;
4373      if($imgcmd eq "fig") {
4374        $end=~m|</fig>|i;
4375        $fig=$`;
4376        $end=$';
4377        $over="";
4378        while($fig=~/(<overlay$R)/ig) {$over.=$1};
4379        ($dum,$cap)=$fig=~m|<caption$R([\w\W]*)</caption>|i;
4380        ($dum,$cred)=$fig=~m|<credit$R([\w\W]*)</credit>|i;
4381        $text=")BN($text$over)BN($cap)BN($cred)BN(";
4382      }
4383    }
4384    }
4385    $_=$beg.$text.$end;
4386  }
4387  s|<[hH][rR]$R|)2 1 1 HR(|g;
4388  $_[0]=$_;
4389}
4390sub getval{
4391  local($val,$unit)=$_[0]=~/$V\s*(\w*)/g;
4392  $val*=$cm{$unit} if($_[1]==1 && defined $cm{$unit});
4393  $val*=$pt{$unit} if($_[1]==2 && defined $pt{$unit});
4394  $_[0]=$val;
4395}
4396sub getconf {
4397  local($_)=@_;
4398  while(/\@import\s+(([\w.\/-]+)|"([^"]*)"|'([^']*)')\s*;/) {
4399    if(open(SS,"<$+") && !$read{$+}) {
4400      $conf=<SS>;
4401      $_=$`.$conf.$';
4402      print DBG "***** $+:\n$conf" if($opt_d);
4403      close SS;
4404      $read{$+}=1;
4405    } else {
4406      &dbg($read{$+}?"Infinite \@import loop: $+\n":"Error opening: $+\n");
4407      $_=$`.$';
4408    }
4409  }
4410  @block=();
4411  while(&getblk($_)){};
4412}
4413sub getblk {
4414  local($_)=@_;
4415  local ($beg,$match,$end,$blk,$key,$val,$id,$temp);
4416  while(/^\s*\/\*/) {
4417    /\*\/|$/;
4418    $_=$';
4419  }
4420  return 0 if !/\S/;
4421  /[\w,:.@\s-]+\{/;
4422  $_=$';
4423  ($id=$&)=~s/^\s*|\s*\{//g;
4424  $id=lc $id;
4425  push(@block,"\L$id");
4426  if($#block==1) {
4427    $valid{$id}=1 if(!$user);
4428    if($id eq "color") {$id="colour"};
4429    if(!$valid{$id}) {
4430      &dbg("Error in configuration file: unknown block name '$id'\n");
4431    }
4432  }
4433  $blk="";
4434  W:while(/\s*(\/\*|[\w][\w-]*\s*:|[\w,:.\s-]+\{|\})\s*/) {
4435    $blk.=$1 if($1 ne "/*");
4436    $beg=$`;
4437    $match=$1;
4438    $end=$';
4439    S:{
4440      if($match=~/\{$/) {
4441        $temp=$match.$end;
4442        $blk.=&getblk($temp);
4443        $_=$temp;
4444        last S;
4445      }
4446      if($match=~/:$/) {
4447        ($key=$`)=~s/\s*$//;
4448#        $end=~/([\w.\$-]+|"[^"]*"|'[^']*')\s*;?/;
4449        $end=~/("[^"]*"|'[^']*'|.*?(?= *(\/\*|;|}|$)))/m;
4450        $blk.=$`.$&;
4451        $_=$';
4452        ($val=$1)=~s/^["']|["']$//g;
4453        $val=~s/'|\\/\\$&/g;
4454        $typ=1;
4455        $typ=2 if($val=~/^$V(cm|mm|in|pt|pc|em)$/);
4456        $typ=3 if($val=~/^$V$/);
4457        $typ=4 if($val=~/^-?\d+$/);
4458        $typ=5 if($val eq "0" || $val eq "1");
4459        if($block[0] eq '@html2ps') {
4460          if($#block==0) {
4461            if(!$user) {
4462              $valid{$key}=1;
4463              $type{$key}=$typ if(!defined $type{$key});
4464            }
4465            if($valid{$key}) {
4466              if($typ>=$type{$key}) {
4467                $key=~s/-/_/g;
4468                eval "\$$key='$val'" if($user || $val ne '');
4469#                print DBG "\$$key='$val'\n" if($opt_d && $user);
4470              } elsif($user) {
4471                &dbg("Error in configuration file: bad value for $key: $val\n");
4472              }
4473            } else {
4474              &dbg("Error in configuration file: unknown key '$key'\n");
4475            }
4476          }
4477          if($#block==1) {
4478            if($id eq "option" && $optalias{$key}) {$key=$optalias{$key}};
4479            if(!$user) {
4480              $valid{"$id,$key"}=1;
4481              $type{"$id,$key"}=$typ if(!defined $type{"$id,$key"});
4482            }
4483            if($valid{"$id,$key"} || $extend{$id}) {
4484              if($typ>=$type{"$id,$key"} || $id eq "colour") {
4485                eval "\$$id\{'$key'}='$val'" if($user || $val ne '');
4486#                print DBG "\$$id\{'$key'}='$val'\n" if($opt_d && $user);
4487              } elsif($user) {
4488                &dbg("Error in configuration file: bad value for $key: $val\n");
4489              }
4490            } else {
4491              &dbg("Error in block '$id' in configuration file:"
4492                  ." unknown key '$key'\n");
4493            }
4494          }
4495          if($#block>1) {
4496            $temp="$block[$#block-1]_$key";
4497            $valid{$temp}=1 if(!$user);
4498            $parblk=$block[$#block-1];
4499            if($valid{$temp}) {
4500              eval "\$$parblk\_$key\{'$id'}='$val'";
4501#              print DBG "\$$parblk\_$key\{'$id'}='$val'\n" if($opt_d && $user);
4502            } elsif($valid{$parblk}) {
4503              &dbg("Error in block '$parblk' in configuration file:"
4504                  ." unknown key '$key'\n");
4505            }
4506          }
4507        } else {
4508          for $i (split(',\s*',$id)) {
4509            $i=~s/@/AT_/;
4510            $i=~s/\./_/;
4511            $i=~s/ *:/__/;
4512            eval "\$$i\{'\L$key'}='\L$val'";
4513#            print DBG "\$$i\{'\L$key'}='\L$val'\n" if($opt_d && $user);
4514          }
4515        }
4516        last S;
4517      }
4518      if($match eq "/*") {
4519        /\*\/|$/;
4520        $_=$';
4521        last S;
4522      }
4523    last W;
4524    }
4525  }
4526  pop(@block);
4527  $_[0]=$end;
4528  $blk;
4529}
4530sub prompt {
4531  local($/)="\n";
4532  &dbg($_[0]);
4533  chop($_[1]=<STDIN>);
4534}
4535sub dbg {
4536  print STDERR $_[0];
4537  print DBG $_[0];
4538}
4539sub hb {
4540  local($_)=@_;
4541  local($head,$body,$beg,$end,$match,$tag);
4542#If neither </HEAD> nor <BODY> can be found, find the separation point (messy).
4543  if(!/<(body|\/head)/i || $`=~/<plaintext|<xmp|<listing|<!--/i) {
4544    $head="";
4545    $int="";
4546    S1: while(/<(\/?\w+|!--|!|\?)/) {
4547      S2:{
4548        $beg=$`;
4549        $end=$';
4550        $match=$&;
4551        $tag=$1;
4552        if($tag eq "!--") {
4553          $int.=$`;
4554          &getcom;
4555          $int.=$com;
4556          $_=$rest;
4557          last S2;
4558        }
4559        if($tag=~/[!?]/) {
4560          $end=~/>/;
4561          $int.="$beg$match$`>";
4562          $_=$';
4563          last S2;
4564        }
4565        $tag=~s|/||;
4566        last S1 if(!$head{"\L$tag"});
4567        $end=~/$R/;
4568        $head.=$int.$beg.$match.$&;
4569        $int="";
4570        $_=$';
4571      }
4572    }
4573    $body=$int.$_;
4574  } else {
4575    $head=$`;
4576    $body=$&.$';
4577  }
4578  $_[0]=$body;
4579  $_[1]=$head;
4580}
4581sub open {
4582  if($_[0]=~m|://|) {
4583    &geturl($_[0],$_[1]);
4584  } elsif(open(FILE,"<$_[0]")) {
4585    $_[1]=<FILE>;
4586    close FILE;
4587  } else {
4588    0;
4589  }
4590}
4591sub pagedef {
4592  for $margin ('left','right','top','bottom') {
4593    ($m)=$margin=~/(.)/;
4594    if(defined $margin{$margin}) {
4595      &dbg("'margin { margin-$margin:... }' is obsolete, use '\@page'\n");
4596      $AT_page{"margin-$margin"}=$margin{$margin} if(!defined $AT_page{"margin-$margin"});
4597    }
4598    for $page ('left','right') {
4599      ($p)=$page=~/(.)/;
4600        eval "\$m$m$p=\$AT_page\{'margin'} if(defined \$AT_page\{'margin'})";
4601        eval "\$m$m$p=\$AT_page\{'margin-$margin'} if(defined \$AT_page\{'margin-$margin'})";
4602        eval "\$m$m$p=\$AT_page__$page\{'margin'} if(defined \$AT_page__$page\{'margin'})";
4603        eval "\$m$m$p=\$AT_page__$page\{'margin-$margin'} if(defined \$AT_page__$page\{'margin-$margin'})";
4604    }
4605  }
4606}
4607sub pmtoraw {
4608  @pars=();
4609  ($temp)=@_;
4610  for $i (0..3) {
4611    1 while ($temp=~s/^\s*#.*//);
4612    next if($pars[0] eq 'P1' && $i == 3);
4613    $temp=~s/\s*(\S+)\s*//;
4614    $pars[$i]=$1;
4615  }
4616  $temp=~s/#.*//g;
4617  $pars[0]=~s/\d/$&+3/e;
4618  $_[0]="$pars[0]\n$pars[1] $pars[2]\n";
4619  if($pars[0] eq 'P4') {
4620    $temp=~s/\s//g;
4621    $_[0].=pack("B*",$temp);
4622  } else {
4623    $_[0].="255\n";
4624    while ($temp=~/\d+/g) {
4625      $_[0].=pack("C",int(255*$&/$pars[3]+.5));
4626    }
4627  }
4628}
4629