#!/usr/bin/perl # This is html2ps version 1.0 beta3, an HTML-to-PostScript converter. # Copyright (C) 1995-2000 Jan Karrman. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # Author: Jan Karrman, Dept. of Scientific Computing, Uppsala University, # Sweden, e-mail: jan@tdb.uu.se. # Set the name of the global configuration file. See the installation notes # and manual page for more details on configuration files. $globrc='/etc/html2psrc'; $ug='/usr/share/doc/html2ps/html2ps.html'; $conf=<<'EOR'; @html2ps { package { PerlMagick: 0; ImageMagick: 0; pbmplus: 0; netpbm: 0; djpeg: 0; Ghostscript: 0; TeX: 0; dvips: 0; libwww-perl: 0; jfriedl: 0; geturl: ""; check: ""; path: ""; } paper { type: A4; height: ""; width: ""; } option { twoup: 0; base: ""; check: 0; toc: ""; debug: 0; DSC: 0; encoding: "ISO-8859-1"; rcfile: ""; frame: 0; grayscale: 0; help: 0; hyphenate: 0; scaleimage: 1; cookie: ""; language: ""; landscape: 0; scalemath: 1; number: 0; startno: ""; output: ""; original: 0; rootdir: ""; xref: 0; scaledoc: 1; style: ""; titlepage: 0; text: 0; underline: 0; colour: 0; version: 0; web: ""; duplex: ""; } margin { middle: 2cm; } xref { text: "[p $N]"; passes: 1; } quote { en { open: "“"; close: "”"; open2: "`"; close2: "'"; } sv { open: "”"; close: "”"; open2: "'"; close2: "'"; } da { open: "»"; close: "«"; } no { open: "«"; close: "»"; } fr { open: "« "; close: " »"; } de { open: "„"; close: "“"; open2: "‚"; close2: "`"; } fi: sv; es: en; it: no; nn: no; nb: no; } toc { heading: "

Table of Contents

"; level: 6; indent: 1em; } titlepage { content: "

$T

$[author]

"; margin-top: 1cm; } font { times { names: "Times-Roman Times-Italic Times-Bold Times-BoldItalic"; } new-century-schoolbook { names: "NewCenturySchlbk-Roman NewCenturySchlbk-Italic NewCenturySchlbk-Bold NewCenturySchlbk-BoldItalic"; } helvetica { names: "Helvetica Helvetica-Oblique Helvetica-Bold Helvetica-BoldOblique"; } helvetica-narrow { names: "Helvetica-Narrow Helvetica-Narrow-Oblique Helvetica-Narrow-Bold Helvetica-Narrow-BoldOblique"; } palatino { names: "Palatino-Roman Palatino-Italic Palatino-Bold Palatino-BoldItalic"; } avantgarde { names: "AvantGarde-Book AvantGarde-BookOblique AvantGarde-Demi AvantGarde-DemiOblique"; } bookman { names: "Bookman-Light Bookman-LightItalic Bookman-Demi Bookman-DemiItalic"; } courier { names: "Courier Courier-Oblique Courier-Bold Courier-BoldOblique"; } } hyphenation { min: 8; start: 4; end: 3; en { file: ""; extfile: ""; } } header { left: ""; center: ""; right: ""; odd-left: ""; odd-center: ""; odd-right: ""; even-left: ""; even-center: ""; even-right: ""; font-family: Helvetica; font-size: 8pt; font-style: normal; font-weight: normal; color: black; alternate: 1; } footer { left: ""; center: ""; right: ""; odd-left: ""; odd-center: ""; odd-right: ""; even-left: ""; even-center: ""; even-right: ""; font-family: Helvetica; font-size: 8pt; font-style: normal; font-weight: normal; color: black; alternate: 1; } frame { width: 0.6pt; margin: 0.5cm; color: black; } justify { word: 15pt; letter: 0pt; } draft { text: DRAFT; print: ""; dir: 0; font-family: Helvetica; font-style: normal; font-weight: bold; color: F0F0F0; } colour { black: 000000; green: 008000; silver: C0C0C0; lime: 00FF00; gray: 808080; olive: 808000; white: FFFFFF; yellow: FFFF00; maroon: 800000; navy: 000080; red: FF0000; blue: 0000FF; purple: 800080; teal: 008080; fuchsia: FF00FF; aqua: 00FFFF; } html2psrc: "$HOME/.html2psrc"; imgalt: "[IMAGE]"; datefmt: "%e %b %Y %R"; locale: ""; doc-sep: ""; ball-radius: 0.25em; numbstyle: 0; showurl: 0; seq-number: 0; extrapage: 1; break-table: 0; forms: 1; textarea-data: 0; page-break: 1; expand-acronyms: 0; spoof: ""; ssi: 1; prefilled: 0; } BODY { font-family: Times; font-size: 11pt; text-align: left; background: white; } H1, H2, H3, H4, H5, H6 { font-weight: bold; margin-top: 0.8em; margin-bottom: 0.5em; } H1 { font-size: 19pt } H2 { font-size: 17pt } H3 { font-size: 15pt } H4 { font-size: 13pt } H5 { font-size: 12pt } H6 { font-size: 11pt } P, OL, UL, DL, BLOCKQUOTE, PRE { margin-top: 1em; margin-bottom: 1em; } P { line-height: 1.2em; text-indent: 0; } OL, UL, DD { margin-left: 2em } TT, KBD, PRE { font-family: Courier } PRE { font-size: 11pt } BLOCKQUOTE { margin-left: 1em; margin-right: 1em; } ADDRESS { margin-top: 0.5em; margin-bottom: 0.5em; } TABLE { margin-top: 1.3em; margin-bottom: 1em; } DIV.noprint { display: none } DEL { text-decoration: line-through } A:link, HR { color: black } @page { margin-left: 1cm; margin-right: 1cm; margin-top: 0cm; margin-bottom: 0.5cm; } EOR eval "require POSIX"; $posix = !$@; %extend=('quote',1, 'font',1, 'colour',1, 'hyphenation',1); %fal=("serif","times", "sans_serif","helvetica", "monospace","courier"); @fo=("p","pre","h1","h2","h3","h4","h5","h6","i","b","tt","kbd","cite","samp", "address","blockquote","ol","ul","dl","dt","dd","table","header","footer"); %quote=('','en'); %valid=('font',1, 'font_files',1, 'margin,left',1, 'margin,right',1, 'margin,top',1, 'margin,bottom',1); %cm=('cm',1, 'mm',0.1, 'in',2.54, 'pt',2.54/72, 'pc',2.54/6); %pt=('cm',72/2.54, 'mm',72/25.4, 'in',72, 'pt',1, 'pc',12); %space=('thinsp',6, '#8201',6, 'ensp',2, '#8194',2, 'emsp',1, '#8195',1); $space=join('|',keys %space); %vars=("T","Ti", "N","Pn", "U","UR", "H","h", "A","Au"); %height=("letter",27.9, "legal",35.6, "arche",121.9, "archd",91.4, "archc",61, "archb",45.7, "archa",30.5, "flsa",33, "flse",33, "halfletter",21.6, "11x17",43.2, "ledger",27.9); %width=("letter",21.6, "legal",21.6, "arche",91.4, "archd",61, "archc",45.7, "archb",30.5, "archa",22.9, "flsa",21.6, "flse",21.6, "halfletter",14, "11x17",27.9, "ledger",43.2); $version="html2ps version 1.0 beta3"; $opts="2|b:|c|C:|d|D|e:|f:|F|g|h|H|i:|k:|l:|L|m:|n|N:|o:|O|r:|R|s:|S:|t|T|u|" ."U|v|W:|x:"; %optalias=( 'twoup','2', 'base','b', 'check','c', 'toc','C', 'debug','d', 'DSC','D', 'encoding','e', 'rcfile','f', 'frame','F', 'grayscale','g', 'help','h', 'hyphenate','H', 'scaleimage','i', 'cookie','k', 'language','l', 'landscape','L', 'scalemath','m', 'number','n', 'startno','N', 'output','o', 'original','O', 'rootdir','r', 'xref','R', 'scaledoc','s', 'style','S', 'titlepage','t', 'text','T', 'underline','u', 'colour','U', 'version','v', 'web','W', 'duplex','x'); %type=( 'paper,height',2, 'paper,width',2, 'option,i',3, 'option,m',3, 'option,N',4, 'option,s',3, 'option,x',4, 'xref,passes',4, 'draft,print',5); $usage=<html2ps.dbg") || die "Error opening debug file: html2ps.dbg\n"; print STDERR "***** Writing debug info to html2ps.dbg\n"; print DBG "***** $version\n***** Command: $0 $args\n***** Perl: $]\n"; print DBG "***** HTML2PSPATH=$ENV{'HTML2PSPATH'}\n"; } undef $/; $user=0; $V='(-?\d+\.?\d*|-?\d*\.?\d+)'; &getconf($conf); &pagedef; undef %AT_page; for(@fo,"draft") { eval "\$deffnt{'$_'}=defined \$$_\{'font-family'\}?" ."\$$_\{'font-family'\}:\$body{'font-family'}"; } $user=1; if(open(RC,$globrc)) { $conf=; print DBG "***** Global file $globrc:\n$conf" if($opt_d); &getconf($conf); close RC; } else { &dbg("Warning: cannot open the global resource file: $globrc\n") if($globrc); } $html2psrc=~s/^(~|\$HOME)/$ENV{"HOME"}/; $prc=$html2psrc; if($opt_f) { ($prc=$opt_f)=~s/^:/$html2psrc:/; $prc=~s/:$/:$html2psrc/; $prc=~s/::/:$html2psrc:/; } $cwd=$posix?POSIX::getcwd():""; opendir(DIR,$cwd); @local=readdir DIR; closedir DIR; $globrc=~/html2psrc/; $gdir=$`; $hpath=$ENV{"HTML2PSPATH"}?$ENV{"HTML2PSPATH"}:".:"; $hpath=~s/^:/$gdir:/; $hpath=~s/:$/:$gdir/; $hpath=~s/::/:$gdir:/; $cur=$hpath=~s/(^|:)\.($|:)/$1$cwd$2/; @hpath=split(/:/,$hpath); for(@hpath) { if(opendir(DIR,$_)) { @files=readdir DIR; $files{$_}=" @files "; closedir DIR; } } @rc=split(/:/,$prc); for $rc (@rc) { $found=0; S:for $dir (@hpath) { if(-r $rc && !grep(/^$rc$/,@local) || $files{$dir}=~/ $rc /) { chdir $dir if($files{$dir}=~/ $rc / && $cwd); if(open(RC,$rc)) { $conf=; print DBG "***** Personal file $rc:\n$conf" if($opt_d); &getconf($conf); close RC; $found=1; } last S; } } &dbg("Error opening resource file: $rc\n") if($opt_f && !$found); } chdir $cwd if($cwd); $user=2; &getconf($opt_S) if($opt_S); print DBG "*****\n" if($opt_d); &pagedef; ($pagew,$pageh)=split /\s+/, $AT_page{'size'} if(defined $AT_page{'size'}); require Image::Magick if($package{'PerlMagick'}); $geturl=$package{'geturl'}; $ulanch="f"; $f=72/2.54; $giftopm="giftopnm" if($package{'netpbm'}); $giftopm="giftoppm" if($package{'pbmplus'}); for(keys %option){eval "\$opt_$_='$option{$_}' if(!defined \$opt_$_)"}; die $usage if $opt_h; die "$version\n" if $opt_v; &dbg("$version\n") if ($opt_v||$opt_d); die "Ghostscript is required to generate DSC PostScript\n" if($opt_D && !$package{'Ghostscript'}); die "Ghostscript is required to generate cross references\n" if($opt_R && !$package{'Ghostscript'}); $tmpname=$posix?POSIX::tmpnam():"h2p_$$"; ($scr=$tmpname)=~/\w+$/; $tempdir=$`; if($opt_u) {$ulanch="t"}; if(defined $opt_x && $opt_x!~/^[0-2]$/) { die "Illegal duplex value: $opt_x\n"; } $V='(-?\d+\.?\d*|-?\d*\.?\d+)'; for $o ($opt_s,$opt_i,$opt_m,$opt_N) { die "Non numeric: $o\n" if(defined($o) && $o!~/^$V$/); } $twoup=$opt_2?"t":"f"; $xp=$extrapage?"t":"f"; die "Invalid option: -W $opt_W\n" if($opt_W!~/^[abflprsL\d]*$/); $tocdoc=$opt_C=~/[ft]/; if($tocdoc && !defined $opt_W) {$opt_W=4}; $mult=$#ARGV>0 || $opt_W; $maxlev=$opt_W=~/(\d+)/?$1:4; $link=$opt_W=~/l/; $local=$opt_W=~/s/; $rel=$opt_W=~/r/; $below=$opt_W=~/b/; $layer=$opt_W=~/L/; $prompt=$opt_W=~/p/; if($opt_C && $opt_C!~/^(b?[ft]|[ft]b?|b?h|hb?)$/) {die "Invalid option: -C $opt_C\n"}; $tc=$opt_C?"t":"f"; $rev=$opt_C=~/t/; $first=$opt_C=~/b/ || $opt_R; $th=$tocdoc?"f":"t"; $oeh=0; $oef=0; @now=localtime; @gmnow=gmtime; POSIX::setlocale(&POSIX::LC_TIME,$locale) if($posix); $R='(\s*>|[^a-zA-Z0-9>][^>]*>)'; $S='([\w.:/%-]+)|"([^"]*)"|\'([^\']*)\''; $X='[\da-fA-F]'; $IM='(gif|jpeg|jpg|png|xbm|xpm|ps|eps)'; for('odd-left','odd-center','odd-right','even-left','even-center','even-right') { $oeh=1 if defined $header{$_}; $oef=1 if defined $footer{$_}; } %metarc=(); for $a ('left','center','right') { if(defined $header{"odd-$a"} || defined $header{"even-$a"}) { $oeh=1; } if(defined $footer{"odd-$a"} || defined $footer{"even-$a"}) { $oef=1; } for('','odd-','even-') { $apa=$header{$_.$a}; $numb=1 if($apa=~/(^|[^\$])\$N/); &spec($header{$_.$a}); &spec($footer{$_.$a}); $header{$_.$a}="($apa)"; $apa=$footer{$_.$a}; $numb=1 if($apa=~/(^|[^\$])\$N/); $footer{$_.$a}="($apa)"; &varsub($header{$_.$a},$footer{$_.$a}); } } if($oeh) { $yz="/YY [[{$header{'odd-left'}}{$header{'even-left'}}]" ."[{$header{'odd-right'}}{$header{'even-right'}}]" ."[{$header{'odd-center'}}{$header{'even-center'}}]] D\n"; } else { $ind=$header{'alternate'}; $yz="/YY [[{$header{'left'}}$ind][{$header{'right'}}".(1-$ind) ."][{$header{'center'}}2]] D\n"; } if($oef) { $yz.="/ZZ [[{$footer{'odd-left'}}{$footer{'even-left'}}]" ."[{$footer{'odd-right'}}{$footer{'even-right'}}]" ."[{$footer{'odd-center'}}{$footer{'even-center'}}]] D"; } else { $ind=$footer{'alternate'}; $yz.="/ZZ [[{$footer{'left'}}$ind][{$footer{'right'}}".(1-$ind) ."][{$footer{'center'}}2]] D"; } $number=$opt_n || !$numb && ($opt_C || $opt_N || $opt_R)?"t":"f"; $tih=$titlepage{'content'}; $toch=$toc{'heading'}; for ($imgalt,$xref{'text'},$tih,$toch,$inh,$draft{'text'}) { &spec($_); } for ($paper{'height'},$paper{'width'},$margin{'middle'},$frame{'margin'}, $mlr,$mrl,$mtl,$mbl,$mll,$mrr,$mtr,$mbr,$pagew,$pageh) { &getval($_,1); } $opt_s*=0.65 if($opt_2 && $opt_L); $opt_N=1 if(!defined $opt_N); $opt_N=int($opt_N-1); $mm=int($margin{'middle'}*$f); $is=0.8*$opt_i; $msc=1/$opt_s; $mag=1200*$opt_m*$opt_s; $xref=$opt_R?"t":"f"; $xref{'text'}=~s/\$N/) WB pN WB (/g; $d=int($f*$frame{'margin'}); for (0..10) { $temp=2**(-$_/2); $width{"a$_"}=int($temp*2**(-1/4)*1000+.5)/10; $height{"a$_"}=int($temp*2**(1/4)*1000+.5)/10; $width{"b$_"}=int($temp*1000+.5)/10; $height{"b$_"}=int($temp*2**(1/2)*1000+.5)/10; } if(!$pagew || !$pageh) { if($width{"\L$paper{'type'}"}) { $paper{'width'}=$width{"\L$paper{'type'}"} if(!defined $paper{'width'}); $paper{'height'}=$height{"\L$paper{'type'}"} if(!defined $paper{'height'}); ($pagew,$pageh)=($paper{'width'},$paper{'height'}); } elsif($paper{'type'}) { &dbg("Unknown paper type: $paper{'type'}\n"); } } if($opt_L) { $wl=$pageh-$mll-$mrl; $wr=$pageh-$mlr-$mrr; $hl=int(($pagew-$mtl-$mbl)*$f+.5); $hr=int(($pagew-$mtr-$mbr)*$f+.5); $xl=int($mtl*$f+.5); $xr=int($mtr*$f+.5); $yl=int($mll*$f+.5); $yr=int($mlr*$f+.5); $rot=" 90 rotate"; } else { $wl=$pagew-$mll-$mrl; $wr=$pagew-$mlr-$mrr; $hl=int(($pageh-$mtl-$mbl)*$f+.5); $hr=int(($pageh-$mtr-$mbr)*$f+.5); $xl=int($mll*$f+.5); $xr=int($mlr*$f+.5); $yl=int(($pageh-$mtl)*$f+.5); $yr=int(($pageh-$mtr)*$f+.5); $rot=""; } if($opt_2) { $wl=($wl-$margin{'middle'})/2; $wr=($wr-$margin{'middle'})/2; } $wl=int($wl*$f+.5); $wr=int($wr*$f+.5); $pag=int($pageh*$f+.5); $fe=$opt_F?"t":"f"; $cf=$opt_U?"t":"f"; $tp=$opt_t?"t":"f"; $rm=$numbstyle?"t":"f"; $pa=$showurl?"t":"f"; $nh=$seq_number?"t":"f"; $bt=$break_table?"t":"f"; $ea=$expand_acronyms?"t":"f"; $fi=$prefilled?"t":"f"; $latin1=$opt_e=~/ISO-8859-1/i; $lt=$del{'text-decoration'}=~/^line-through$/i?"SE":"WB"; if(!$opt_x && defined $opt_x) { $dupl="[{false statusdict/setduplexmode get exec} stopped cleartomark"; } if($opt_x) { $dupl="[{true statusdict/setduplexmode get exec} stopped cleartomark"; } if($opt_x==2) { $dupl.="\n[{true statusdict/settumble get exec} stopped cleartomark"; } %head=("html",1, "head",1, "title",1, "base",1, "meta",1, "link",1, "style",1, "script",1, "isindex",1); %algn=("left",1, "center",2, "right",3, "justify",4, "char",5); %f=("void",1, "above",2, "below",3, "hsides",4, "lhs",5, "rhs",6, "vsides",7, "box",8, "border",9); %r=("none",1, "groups",2, "rows",3, "cols",4, "all",5); %v=("top",1, "middle",2, "bottom",3, "baseline",4); %it=("radio",0, "checkbox",1, "text",2, "password",2, "image",3); %ssy=(200,"\\", 201, "(", 202, ")"); %lity=("I",0, "i",1, "A",2, "a",3, "1",4, "disc",5, "square",6, "circle",7); $ltr=join('|',keys %lity); %tex=('`a',"\340", '\^a',"\342", '`e',"\350", '`e',"\350", 'c\{c\}',"\347", "'e","\351", '\^e',"\352", '"e',"\353", '\^i',"\356", '"i',"\357", '\^o',"\364", '`u',"\371", '\^u',"\373", '"u',"\374", '"y',"\377", 'aa',"\345", '"a',"\344", '"o',"\366", 'ae',"\346", 'oe',"\225"); @hind=(0,0,0,0,0,0); $ltrs='A-Za-z\222-\226\300-\377'; %ent=( "lsquo|#8216",96, "rsquo|#8217",39, "circ|#710",141, "tilde|#732",142, "permil|#8240",143, "dagger|#8224",144, "Dagger|#8225",145, "Yuml|#376",146, "scaron|#353",147, "Scaron|#352",148, "oelig|#339",149, "OElig|#338",150, "lsaquo|#8249",151, "rsaquo|#8250",152, "sbquo|#8218",153, "bdquo|#8222",154, "ldquo|#8220",155, "rdquo|#8221",156, "ndash|#8211",157, "mdash|#8212",158, "trade|#8482",159, "nbsp",160, "iexcl",161, "cent",162, "pound",163, "curren",164, "yen",165, "brvbar",166, "sect",167, "uml",168, "copy",169, "ordf",170, "laquo",171, "not",172, "reg",174, "macr",175, "deg",176, "plusmn",177, "sup2",178, "sup3",179, "acute",180, "micro",181, "para",182, "middot",183, "cedil",184, "sup1",185, "ordm",186, "raquo",187, "frac14",188, "frac12",189, "frac34",190, "iquest",191, "Agrave",192, "Aacute",193, "Acirc",194, "Atilde",195, "Auml",196, "Aring",197, "AElig",198, "Ccedil",199, "Egrave",200, "Eacute",201, "Ecirc",202, "Euml",203, "Igrave",204, "Iacute",205, "Icirc",206, "Iuml",207, "ETH",208, "Ntilde",209, "Ograve",210, "Oacute",211, "Ocirc",212, "Otilde",213, "Ouml",214, "times",215, "Oslash",216, "Ugrave",217, "Uacute",218, "Ucirc",219, "Uuml",220, "Yacute",221, "THORN",222, "szlig",223, "agrave",224, "aacute",225, "acirc",226, "atilde",227, "auml",228, "aring",229, "aelig",230, "ccedil",231, "egrave",232, "eacute",233, "ecirc",234, "euml",235, "igrave",236, "iacute",237, "icirc",238, "iuml",239, "eth",240, "ntilde",241, "ograve",242, "oacute",243, "ocirc",244, "otilde",245, "ouml",246, "divide",247, "oslash",248, "ugrave",249, "uacute",250, "ucirc",251, "uuml",252, "yacute",253, "thorn",254, "yuml",255); %symb=( "alpha|#945",141, "beta|#946",142, "gamma|#947",147, "delta|#948",144, "epsilon|#949",145, "zeta|#950",172, "eta|#951",150, "theta|#952",161, "thetasym|#977",112, "iota|#953",151, "kappa|#954",153, "lambda|#955",154, "mu|#956",155, "nu|#957",156, "xi|#958",170, "pi|#960",160, "piv|#982",166, "omicron|#959",157, "rho|#961",162, "sigma|#963",163, "sigmaf|#962",126, "tau|#964",164, "upsilon|#965",165, "upsih|#978",241, "phi|#966",146, "phiv",152, "chi|#967",143, "psi|#968",171, "omega|#969",167, "Alpha|#913",101, "Beta|#914",102, "Gamma|#915",107, "Delta|#916",104, "Epsilon|#917",105, "Zeta|#918",132, "Eta|#919",110, "Theta|#920",121, "Iota|#921",111, "Kappa|#922",113, "Lambda|#923",114, "Mu|#924",115, "Nu|#925",116, "Xi|#926",130, "Omicron|#927",117, "Pi|#928",120, "Rho|#929",122, "Sigma|#931",123, "Tau|#932",124, "Upsilon|#933",125, "Phi|#934",106, "Chi|#935",103, "Psi|#936",131, "Omega|#937",127, "fnof|#402",246, "perp|#8869",136, "plusmn|#177",261, "cdot|#183",327, "or|#8744",332, "and|#8743",331, "le|#8804",243, "ge|#8805",263, "equiv|#8801",272, "cong|#8773",100, "asymp|#8776",273, "ne|#8800",271, "sub|#8834",314, "sube|#8838",315, "sup|#8835",311, "supe|#8839",312, "isin|#8712",316, "larr|#8592",254, "rarr|#8594",256, "uarr|#8593",255, "darr|#8595",257, "harr|#8596",253, "lArr|#8656",334, "rArr|#8658",336, "uArr|#8657",335, "dArr|#8659",337, "hArr|#8660",333, "forall|#8704","042", "exist|#8707","044", "infin|#8734",245, "nabla|#8711",321, "part|#8706",266, "hellip|#8230",274, "int|#8747",362, "sum|#8721",345, "prod|#8719",325, "real|#8476",302, "image|#8465",301, "bull|#8226",267, "prime|#8242",242, "Prime|#8243",262, "oline|#8254",140, "frasl|#8260",244, "weierp|#8472",303, "alefsym|#8501",300, "crarr|#8629",277, "empty|#8709",306, "notin|#8713",317, "ni|#8715","047", "minus|#8722","055", "lowast|#8727","052", "radic|#8730",326, "prop|#8733",265, "ang|#8736",320, "cap|#8745",307, "cup|#8746",310, "sim|#8764",176, "nsub|#8836",313, "oplus|#8853",305, "otimes|#8855",304, "sdot|#8901",327, "lceil|#8968",351, "rceil|#8969",371, "lfloor|#8970",353, "rfloor|#8971",373, "lang|#9001",341, "rang|#9002",361, "spades|#9824",252, "clubs|#9827",247, "hearts|#9829",251, "diams|#9830",250, "loz|#9674",340); $pc=')WB NL NP('; $nimg=-1; $nm=-1; @font=(); @size=(); @styl=(); @alig=(); @colr=(); @topm=(); @botm=(); @lftm=(); @rgtm=(); @z1=(); @z2=(); @z3=(); &Subst($doc_sep); ($toct=$toch)=~s|<[\w/!?][^>]*>||g; $dh="/h0 [()($toct)] D\n"; &Subst($toch); $toch=~s/ H\(/ -1 H(/g; $toch="($toch)"; &varsub($toch); &Subst($tih); $tih=~s/ H\(/ -1 H(/g; $tih="($tih)"; &varsub($tih); $mn=0; $nfont=0; $mi=0; for (@fo) {&setel($_)}; %arr=%draft; &fs("draft"); if(!$latin1 && !defined $fontid{"times"}) { $fontid{"times"}=$nfont++; @docfonts=(@docfonts,split(/\s+/,$font_names{"times"})); } $wind=0; $wf="t"; if(!$latin1) { $wind=$fontid{"times"}; $wf="f"; } for $k (keys %font_files){ @ff=split(/\s+/,$font_files{$k}); @fn=split(/\s+/,$font_names{$k}); for (0..3) { if($ff[$_]) { $ff{$fn[$_]}=$ff[$_]; } elsif(!$ff{$fn[$_]}) { $ff{$fn[$_]}=$ff[0]; } $fr{$fn[$_]}=$k; } } $pta=defined $p{"text-align"}?$p{"text-align"}:$body{"text-align"}; $pal=0; $pal=1 if($pta=~/^c/i); $pal=2 if($pta=~/^r/i); $pal=3 if($pta=~/^j/i); $bgcol=&col2rgb($body{"background"}); if(!$bgcol) {$bgcol="[16#FF 16#FF 16#FF]"}; if(!$p{"color"}) {$p{"color"}="black"}; $tcol=&col2rgb($p{"color"}); $lcol=&col2rgb($a__link{"color"}); if($lcol) { $Lc="/Lc t D\n/Dl $lcol D\n"; $Lc.=$tcol ne $lcol?"/LX t D":"/LX f D"; } else { $Lc="/Lc f D\n/LX f D"; } $pcol=&col2rgb($pre{"color"}); if(!$pcol) {$pcol="[0 0 0]"}; $deftbg=&col2rgb($table{"background"}); $hc=&col2rgb($hr{"color"}); if(!$hc) {$hc="[0 0 0]"}; $fcol=&col2rgb($frame{"color"}); if(!$fcol) {$fcol="[0 0 0]"}; for ($p{"font-size"},$pre{"font-size"},$header{"font-size"},$frame{'width'}, $footer{"font-size"},$justify{'letter'},$justify{'word'}, $titlepage{'margin-top'}) { &getval($_,2); } for ($p{"line-height"},$p{"text-indent"},$p{"margin-top"},$toc{'indent'}, $ball_radius) { &getval($_,0); } $fl="/FL [/".join("\n/",@docfonts)."] D"; for $k (keys %ff) { $f=$ff{$k}; if(defined $fontid{$fr{$k}} && !defined($cont{$f})) { open(FONT,$f) || &dbg("Error opening fontfile $f\n"); ($cont{$f}=)=~s/(^|\r?\n|\r)%.*//g; close FONT; } } $fontdef=""; for (keys %cont) { $fontdef.=$cont{$_}; } &ent($yz); &ent($xref{'text'}); &ent($draft{'text'}); $lnum=0; for (keys %quote_open) { $lid{$_}=$lnum++; if(!defined $quote_close{$_}) {$quote_close{$_}=$quote_open{$_}}; if(!defined $quote_open2{$_}) {$quote_open2{$_}=$quote_open{$_}}; if(!defined $quote_close2{$_}) {$quote_close2{$_}=$quote_close{$_}}; &ent($quote_open{$_}); &ent($quote_close{$_}); &ent($quote_open2{$_}); &ent($quote_close2{$_}); push(@qo,$quote_open{$_}); push(@qc,$quote_close{$_}); push(@qo2,$quote_open2{$_}); push(@qc2,$quote_close2{$_}); } $qo=join(')(',@qo); $qc=join(')(',@qc); $qo2=join(')(',@qo2); $qc2=join(')(',@qc2); $hyphenation_file{''}=$hyphenation_file{'en'}; $br=$collapse_br?"f":"t"; $gd=0; $ddr=defined $draft{'print'}; if($ddr) { if($draft{'print'}==0) { $draft="f"; } else { $gd=1; $draft="t"; } } if(-e '/dev/null' || !-e 'nul') { $pathsep=':'; $gs='gs'; } else { $pathsep=';'; $gs='gswin32c'; } $gb=$gs_bug?"t":"f"; for (keys %quote) {$lid{$_}=$lid{$quote{$_}}}; $ENV{'PATH'}.="$pathsep$package{'path'}" if($package{'path'}); $delim="%-- End of variable part --"; $cd="/Cd {aload length 2 idiv dup dict begin {D} repeat currentdict end} D"; $mysymb=<1?"s":"")." remaining\n"); } if($banner) { $_="/Ba t D /BA {($banner)BN} D\nBs f Pb CP /BO E D pop\n"; &Subst($_); s/ H\(/ -1 H(/g; } else { $_="/Ba f D /BO 0 D Bs"; } if($tocdoc && $first && $ndoc==1) { $TC=" TC\n"; $et=" NP Ep ET /Tc f D"; } else { $TC=""; $et=""; } $_.="\n/UR ($html) D\n/Ti ($ti) D\n/Au ($au) D\n/Df $draft D\n/ME ["; for $i (sort {$metarc{$a} <=> $metarc{$b}} keys %metarc){ $_.="($meta{$i})"; } $_.="] D\n$TC"; if($ndoc==1) {$top=$_}; if(!$tocdoc) { $toc.="ND 1 gt{Ts 3 mul Np $refs{$html}()0 C()BD($ti)ES()$refs{$html}" ." 1 TN()EA()BN}if\n"; } $hv=0; while($P2=~s/(\d) (\d) H\(([^\s<)]*)/$1 $2 $nhd H($3)WB $nref Sn(/) { $nhd++; if($hv+1<$2) { for($hv+1..$2-1) { push(@z1,-$nref); push(@z2,$_); } } $hv=$2; $hind[$hv-1]++; for $i ($hv..5) {$hind[$i]=0}; $hind=join('.',@hind[0..$hv-1]); $hst=$3; $'=~/\)EH/; ($htxt=$hst.$`)=~s/\)EA\(//g; if(!$tocdoc) { $toc.="$hv NH le{$nref($hind\\240\\240)$hv C($htxt)$nref 1 TN()EA()BN}if\n"; } push(@z1,$nref); push(@z2,$hv); $nref++; $htxt=~s/(\s+|\)BR\()/ /g; $htxt=~s/(^\s+|\)[^(]*\(|\s+$)//g; $htxt="" if(!$latin1); $dh.="/h$nhd [($hind\\240\\240)($htxt)] D\n"; } if($tocdoc) { if($ndoc==1 && !$first) { $toc="TC RC ZF $_ $P2 WB () BN\n"; $P2=""; $P3=""; $np=""; $_=""; } } $P3.="$fl1\n/Cb $bg D /Ct $tcol D /Cl $lcol D /CL -1 D Ct Sc\n"; if($ndoc==1 && !$first) {$P3.="Pt\n"}; $P3.="$fl2\n$_\n$np\n$P2"; if($tocdoc && $ndoc==1 && !$first) { $np="/Cb $bg D NP RC ZF"; } else { $fl1="WB NL$et"; $fl2="DS"; $np="0 BO R"; } } } $P3.=($P3!~/\)\s*$/?"()":"")."WB NL"; if(!$tocdoc && $first && $nhd){$P3="$toc/OU t D /Cb $bg D NP Ep ET $P3"}; if(!$first && ($tocdoc || !$tocdoc && $nhd)){$P3.=" $toc"}; if($ntab>=0) { $_="$tables] D"; &ack($_); y/\t\f/ /; s/[\200-\377]/sprintf("\\%3.3o",ord($&))/eg; s/\)XX/)9 9 PR/g; s/ H\(/ -1 H(/g; $tables=$_; } $_="%!PS\n%%Title: $title\n$P0$P1"; if($nimg>=0) { $_.="/AX [".join(' ',@XS)."] D\n/AY [".join(' ',@YS)."] D\n" ."/IX [".join(' ',@IX)."] D\n/IT [".join(' ',@IT)."] D\n"; if($nm>=0) { $_.="/AZ [".join(' ',@DP)."] D\n/WS [".join(' ',@WS)."] D\n" ."/FC [".join(' ',@FC)."] D\n/NI $nm D\n/BM ".($nm+1)." array D\nSB\n"; for $i (0..$nm) {$_.="$BM[$i]\n\n"} } $_.="\n$pv%Endpv\n" if($nps); } @kw=split(/[, ]+/,$kw); @Kw=(); for $i (@kw){push(@Kw,$i) if(!grep(/^$i$/,@Kw))}; $kw=join(', ',@Kw); for $i (0..$#z2) { $n=0; $j=$i; while($j++<=$#z2 && $z2[$j]>$z2[$i]) {$n++ if($z2[$j]==$z2[$i]+1)}; push(@z3,$n); } $tdef=$ntab>=0?"$tbl$tables\n0 1 $ntab\{TS}for RC ZF\n":""; $hd="/Hr [@z1]D\n/HV [@z2]D\n/Cn [@z3]D"; &cut($hd); if($gd) { $sd="/Df t D /DG IW IW mul IL IL mul add sqrt D IW IL IW IL lt{E}if" ." /WM E D /WX E D /DZ 180 D gsave SD /DZ DZ DF mul D SD grestore\n"; } else { $sd="/Df f D\n"; } $_.=<}ie SW pop D ET RC ZF $sd$rfs$tdef$top$P3 /TE t D NP TU PM 0 eq and{/Pn () D showpage}if end restore EOD if(($first || $opt_R) && $xref{'passes'}) { &dbg("Inserting cross references\n") if($opt_d); for $i (1..$xref{'passes'}) {&ref}; } &fin; sub h2p { if($html eq '-') { $_=<>; } elsif($html=~m|://|) { if(($prompt || $nrem>50) && $level>1) { &prompt("Retrieve document $html (y/n/q)? ",$ans); if($ans=~/q/i) {undef @docs}; return 0 unless($ans=~/y/i); } &geturl($html,$_) || return; $nrem++; if($contyp!~m|text/html|i) {$_=" \n$_"}; unless(($ba2)=$html=~m|(.*://.*/)|) {$ba2=$html."/"}; } else { if(open(FILE,$html)) { &dbg("Reading $html\n") if($opt_W || $opt_d); $_=<FILE>; if(!/<HTML/i && $html!~/html?$/i && ($html!~/\.ps$/i || $ndoc>1)) { $_=" <plaintext>\n$_"; } close FILE; $var{DOCUMENT_NAME}=$html; if($posix) { $var{LAST_MODIFIED}=POSIX::strftime("%c",localtime((stat $html)[9])); $var{DATE_LOCAL}=POSIX::strftime("%c",@now); $var{DATE_GMT}=POSIX::strftime("%c",@gmnow); } $mod=(stat $html)[9]; } else { &dbg("*** Error opening $html\n"); return 0; } } if(/^%!/ && /$delim/) { $psin=1; &openps if($opt_o); $_=$P0.$'; for $s ("b","c","cw","g","t") { &dbg("Option -$s ignored\n") if(eval "\$opt_$s"); } &fin; } &hb($_,$head); $head=~/<title$R\s*([\w\W]*)<\/title/i; ($ti=$2)=~s/\s+/ /g; $ti=$doctit{$html} if(!$ti); $ti=~s/\s*$//g; &spec($ti); &ent($ti); $ti="<Untitled>" if(!$ti); $title=$ti if(!$title); $draft="f" if(!$ddr); %meta=(); $au=""; while($head=~/<meta\s[^>]*(name|http-equiv)\s*=\s*["']?\s*(\w+)$R/gi) { $k=lc $2; ($v)=$&=~/content\s*=\s*["']\s*([^"']+)/i; $v=~s/\s+/ /g; $v=~s/\s*$//g; &spec($v); &ent($v); $meta{$k}=$v; if($k=~/author/) {$au=$au?"$au, $v":$v}; if($k=~/keywords/) {$kw=$kw?"$kw, $v":$v}; if($k=~/subject/ && !$su) {$su=$v}; if(!$ddr && $k=~/status/ && $v=~/draft/i) {$draft="t";$gd=1}; } $Au.=($Au?" + ":"").$au if($au); $b2=$opt_b; unless($b2) { ($b2)=$head=~/<base\s+href\s*=\s*"([^"]*)"$R/i; unless($b2) {($b2)=$head=~/<base\s+href\s*=\s*([\w\.-]+)$R/i} unless($b2) {$b2=$ba2} } $b2=~s|[^/]*$||; ($b1)=$b2=~m|(.*://[^/]*)/|; unless($b1) {$b1=$opt_r}; unless($b2) {$b2=$html=~m|(.*/)[^/]*$|?$1:""}; if(!defined $B2) {$B2=$b2}; $levl{$b2.$html}=$levl{$html}; while($link && $head=~/<link\s+[^>]*rel\s*=\s*["']?next$R/gi) { if(($lnk)=$&=~/href\s*=\s*["']?\s*([^"' >]*)/gi) { if($lnk=~m|.+//[^/]+$|) {$lnk=$&."/"} if($lnk=~m|://|) { $rlnk=0; } else { $rlnk=1; if($lnk=~m|^/|) {$lnk=$b1.$lnk} else {$lnk=$b2.$lnk} } while($lnk!~m|^\.\./| && $lnk=~m|[^/]*/\.\./|) {$lnk=$`.$'}; $lnk=~s|/\./|/|g; if(&follow && !$levl{$lnk}) { $levl{$lnk}=$level+1; push(@links,$lnk); } } } ($battr)=/<BODY$R/i; ($lang)=$battr=~/\slang\s*=\s*['"]?([a-zA-Z-]+)/i; ($lang)=$head=~/<html[^>]+lang\s*=\s*['"]?([a-zA-Z-]+)/i if(!$lang); $lang=$opt_l if($opt_l); $lang='en' if(!$lang); $lang=lc $lang; if($battr=~/\stext\s*=\s*['"]?\s*#?(\w+)/i) {$tcol=&col2rgb($1)}; if(!$tcol) {$tcol="Dt"}; if($battr=~/\slink\s*=\s*['"]?\s*#?(\w+)/i) {$lcol=&col2rgb($1)}; if(!$lcol) {$lcol="Dl"}; &inihyph if($opt_H); ($bg)=$battr=~/BGCOLOR\s*=\s*["']?\s*#?(\w+)/i; $bg=&col2rgb($bg); if($bg) { ($red,$grn,$blu)=@cvec; } else { ($red,$grn,$blu)=$bgcol=~/#(\w+).*#(\w+).*#(\w+)/; $bg="Db"; } $temp=""; while(/<object$R/i) { $temp.=$`; $tag=$&; $end=$'; $type=$tag=~/type\s*=\s*($S)/i?$+:""; $uaddr=$tag=~/data\s*=\s*($S)/i?$+:""; if($type=~/^text\/(html|plain)$/i || !$type && $uaddr=~m"(\.html?|://.+/|://[^/]+)$"i) { $tag=~/data\s*=\s*/i; if(&open($uaddr,$idoc)) { if($type=~/plain/i) { $idoc="<XMP>$idoc</XMP>"; } else { &hb($idoc,$dum); } $_=$idoc; $_.=$' if($end=~/<\/object>/i); } else { &dbg("\n*** Error opening $uaddr\n"); $_=$end; } } else { $temp.=$tag; $_=$end; } } $_=$temp.$_; if($opt_c && defined $package{'check'}) { $file=$html; if($html=~m|://|) { open(SCRATCH,">$scr"); print SCRATCH $head; print SCRATCH; close SCRATCH; $file="$scr"; } &dbg(`$package{'check'} $file`); } if(!$latin1) { if($opt_e=~/EUC-/i) { s/([\216\217\241-\376].)+/\000$&\000/g; &spec($_); s/\000(.+?)\000/)F1($1)F2(/g; } elsif($opt_e=~/SHIFT-JIS/i) { s/[\201-\237\340-\374][@-~\200-\374]/$&\000/g; s/[\241-\337]+(?!\000)/$&\000/g; s/[ -~\t\n\r\240]+(?!\000)/\002$&\001/g; &spec($_); s/\000//g; } else { while(/\e\$B([^\e]*)/) { $beg=$`; $end=$'; $mat=$1; $mat=~s/\s//g; $_="$beg\001$mat$end"; } s/\e\([BJ]/\002/g; &spec($_); } s/\001/)F1(/g; s/\002/)F2(/g; $_=")F2($_"; y/\000-\010\013\016-\037\177//d; } else { &spec($_); y/\000-\010\013\016-\037\177-\237//d; } s/(\r\n|\r)/\n/g; $refs{$html}=$nref++ if(!defined $refs{$html}); $_="\004$lang\004)WB $refs{$html} Sn($_"; # Yes, I know Perl has case-insensitive pattern matching. But on my system # it takes about 10 times longer to run! $pt=""; if(/<[pP][lL][aA][iI][nN][tT][eE][xX][tT]$R/) {$_=$`;$pt=$'}; while($_){ if(/(<[lL][iI][sS][tT][iI][nN][gG]$R)/) {$_=$`; $tag=$1; $rest=$'; if(/<[xX][mM][pP]$R/){$_=$`; &Subst($_); $P2.="$_)XX("; $_=$'.$tag.$rest; if(m|</[xX][mM][pP]$R|) {$P2.="$`)RP("; $_=$'} else {$P2.=$'; $_=""}} else {&Subst($_); $P2.="$_)XX("; $_=$rest; if(m|</[lL][iI][sS][tT][iI][nN][gG]$R|) {$P2.="$`)RP("; $_=$'} else {$P2.=$'; $_=""}}} elsif(/<[xX][mM][pP]$R/) {$_=$`; &Subst($_); $P2.="$_)XX("; $_=$'; if(m|</[xX][mM][pP]$R|) {$P2.="$`)RP("; $_=$'} else {$P2.=$'; $_=""}} else {&Subst($_);$P2.=$_; $_=""} } $pt=~s/\f/$pc/g; if($pt) {$P2.=")XX($pt"}; $P2.=")"; if($plain) {$P2.="RP ()"}; while($P2=~/XX\(/) { $beg=$`; $'=~/\)(RP|$)/; $mat=$`; $end=$&.$'; $mat=~s/(.*\n){30}.*/$&)WR(/g; ($temp=$mat)=~s/\)[^(]+\(//g; @prel=split(' *\n',$temp); $maxl=0; for $line (@prel) { $line=~s/\\.../x/g; while($line=~/\t+/) { $sp=' ' x (length($&)*8-length($`)%8); $line=~s/\t+/$sp/; $mat=~s/\t+/$sp/; } $ll=length($line); $maxl=$ll if($ll > $maxl); } $P2="$beg ".($#prel+1)." $maxl PR($mat$end"; } $P1=~s/[\200-\377]/sprintf("\\%3.3o",ord($&))/eg; $P2=~s/[\200-\377]/sprintf("\\%3.3o",ord($&))/eg; $P2=~y/\t\f/ /; 1; } sub Subst{ local($_)=@_; if($page_break) { s/<!--NewPage-->/$pc/g; s/<(\?|hr\s+class\s*=\s*["']?)\s*page-break$R/$pc/gi; } s/<!--OddPage-->/)WB NL OP(/g; if($ssi && $html!~m|://|) { while(/<!--#(include|config|echo)\s+(\w+)\s*="([^"]+)"\s*-->/) { $inc=""; $file=$3; if($1 eq "include" && (substr($file,0,1) ne "/" || $opt_r)) { if(substr($file,0,1) ne "/") { $file=$B2.$file; } elsif($2 eq "virtual") { $file=$opt_r.$file; } if(open INC,$file) { $inc=<INC>; &spec($inc); close INC; } } elsif ($1 eq "config" && $2 eq "timefmt") { if($posix) { $var{LAST_MODIFIED}=POSIX::strftime($3,localtime((stat $html)[9])); $var{DATE_LOCAL}=POSIX::strftime($3,@now); $var{DATE_GMT}=POSIX::strftime($3,@gmnow); } } elsif ($1 eq "echo") { $inc=$var{$3}; } $_=$`.$inc.$'; } } s/(&shy;?|&#173;?|<!--hy-->)/)HY(/g; while(/<!--/) { $_=$`; &getcom; $_.=$rest; } $temp=""; while(/<([^"'>]*=\s*["'])/) { $temp.=$`."<"; $_=$1.$'; while(/^[^"'>]*=\s*(["'])/) { $temp.=$&; $_=$'; if(/$1/) { ($tg=$`)=~y/>/\003/; $temp.=$tg.$&; $_=$'; } } } $_=$temp.$_; $a='[aA][lL][iI][gG][nN]'; $Y='[sS][tT][yY][lL][eE]'; $A="($a\\s*=\"?|$Y\\s*=\\s*\"?[tT][eE][xX][tT]-\\s*$a:)"; $I='[lL][eE][fF][tT]'; $C='[cC][eE][nN][tT][eE][rR]'; $D='[rR][iI][gG][hH][tT]'; $J='[jJ][uU][sS][tT][iI][fF][yY]'; $s='[sS][eE][lL][eE][cC][tT]'; $F='[fF][oO][nN][tT]'; $U='[cC][oO][lL][oO][rR]'; $O='[cC][oO][mM][pP][aA][cC][tT]'; s/<\w+[^>]*\s+[iI][dD]\s*=\s*($S)[^>]*>/$&<a name="$+">/g; s|<[dD][eE][lL]$R[\w\W]*?</[dD][eE][lL]>||g if($del{'display'}=~/^none$/); $ndiv=1; s|</?[dD][iI][vV]\d$R||g; s|<(/?)([dD][iI][vV])([>\s])|"<$1$2".($1?--$ndiv:$ndiv++).$3|eg; while(/<[dD][iI][vV](\d+)$R/) { $dbeg=$`; $dnum=$1; $dattr=$2; $dend=$'; $div=""; $ediv=""; if($2=~/class\s*=\s*["']?noprint$R/i) { $_=$dbeg; $_.=$' if($dend=~/<\/[dD][iI][vV]$dnum>/); } else { if($dattr=~/$A\s*($I|$C|$D|$J)/) { $div.=")".$algn{"\L$2"}." Al("; $ediv.=")Ea("; } if($dattr=~/lang\s*=\s*["']?([a-zA-Z-]+)/i) { $lang=lc $1; $div.="\004$lang\004"; &inihyph if($opt_H); $dbeg=~/(\004[^\004]*\004)[^\004]*$/; $ediv.=$1; } $dend=~s|</[dD][iI][vV]$dnum>|$ediv)BR(|; $_="$dbeg$div)BR($dend"; } } s|<$C$R|)2 Al(|g; s|</$C$R|)Ea(|g; s|<(\w+)/([^/]+)/|<$1>$2</$1>|g; s/(<\w+[^>]*>)\n|\n(<\/\w+>)/$+/g; s|(<[lL][iI])$R\s*<[pP]>|)0 P($1$2|g; s/<[hH]([1-6])\s+$A\s*($I|$C|$D|$J)$R/)$algn{"\L$3"} $1 H(/g; s|<[hH]([1-6])$R|)0 $1 H(|g; s|</[hH][1-6]>|)EH(|g; s|<[bB][rR]$R|)BR(|g; s/<[pP]\s+[^>]*$A\s*($I|$C|$D|$J)$R/)$algn{"\L$2"} P(/g; s|<[pP]$R|)0 P(|g; s|</[pP]>|)EP(|g; s|<[aA][dD][dD][rR][eE][sS][sS]$R|)AD(|g; s|</[aA][dD][dD][rR][eE][sS][sS]>|)DA(|g; s|<[pP][rR][eE]$R\n?|)XX(|g; s|\n? *</[pP][rR][eE]>|)RP(|g; s|<[dD][tT]\s[^>]*$O$R|)1 DT(|g; s|<[dD][tT]$R|)0 DT(|g; s|<[dD][dD]$R|)DD(|g; s|<[dD][lL]\s[^>]*$O$R|)1 DL(|g; s|<[dD][lL]$R|)0 DL(|g; s|</[dD][lL]>|)LD(|g; s|<[uU][lL]$R|)UL(|g; s|</[uU][lL]>|)LU(|g; s|<[mM][eE][nN][uU]$R|)UL(|g; s|</[mM][eE][nN][uU]>|)LU(|g; s|<[dD][iI][rR]$R|)UL(|g; s|</[dD][iI][rR]>|)LU(|g; s|<[oO][lL]\s[^>]*[sS][tT][aA][rR][tT]\s*=\s*['"]?(-?\d+)$R|$&)WB $1 Ln(|g; s|<[oO][lL]\s[^>]*[tT][yY][pP][eE]\s*=\s*['"]?([1iIaA])$R|)$lity{$1} OL(|g; s|<[oO][lL]$R|)4 OL(|g; s|</[oO][lL]>|)LO(|g; s|<[lL][iI]\s[^>]*[vV][aA][lL][uU][eE]\s*=\s*['"]?(-?\d+)$R|$&)WB $1 Ln(|g; s|<[lL][iI]\s[^>]*[tT][yY][pP][eE]\s*=\s*['"]?($ltr)$R|)$lity{$1} LI(|g; s|<[lL][iI]$R|)-1 LI(|g; s|</[lL][iI]$R||g; s"<([bB][qQ]|[bB][lL][oO][cC][kK][qQ][uU][oO][tT][eE])$R")BQ("g; s"</([bB][qQ]|[bB][lL][oO][cC][kK][qQ][uU][oO][tT][eE])>")QB("g; s|<[sS][tT][rR][oO][nN][gG]$R|)BD(|g; s|</[sS][tT][rR][oO][nN][gG]>|)ES(|g; s|<[sS][aA][mM][pP]$R|)SM(|g; s|</[sS][aA][mM][pP]>|)ES(|g; s|<[qQ]$R(\s*)|$2)Q(|g; s|(\s*)</[qQ]>|)EQ($1|g; s|<[cC][iI][tT][eE]$R|)CT(|g; s|</[cC][iI][tT][eE]>|)ES(|g; s|<[vV][aA][rR]$R|)I(|g; s|</[vV][aA][rR]>|)ES(|g; s|<[bB]$R|)BD(|g; s|</[bB]>|)ES(|g; s|<[iI]$R|)I(|g; s|</[iI]>|)ES(|g; s|<[tT][tT]$R|)TT(|g; s|</[tT][tT]>|)ES(|g; s|<[uU]$R|)UN(|g; s|</[uU]>|)NU(|g; s|<[sS]([tT][rR][iI][kK][eE])?$R|)SE(|g; s|</[sS]([tT][rR][iI][kK][eE])?>|)XE(|g; s|<[dD][fF][nN]$R|)I(|g; s|</[dD][fF][nN]>|)ES(|g; s|<[eE][mM]$R|)EM(|g; s|</[eE][mM]>|)ES(|g; s|<[cC][oO][dD][eE]$R|)SM(|g; s|</[cC][oO][dD][eE]>|)ES(|g; s|<[kK][bB][dD]$R|)KB(|g; s|</[kK][bB][dD]>|)ES(|g; s|<[bB][iI][gG]$R|)4 FZ(|g; s|</[bB][iI][gG]>|)ES(|g; s|<[sS][mM][aA][lL][lL]$R|)2 FZ(|g; s|</[sS][mM][aA][lL][lL]>|)ES(|g; s|<[iI][nN][sS]$R|)sM WB(|g; s|</[iI][nN][sS]>|)WB eM(|g; s|<[dD][eE][lL]$R|)sM $lt(|g; s|</[dD][eE][lL]>|)XE eM(|g; s|<[aA][cC][rR][oO][nN][yY][mM][^>]+[tT][iI][tT][lL][eE]\s*=\s*($S)[^>]*>|)($+)Ac(|g; s|</[aA][cC][rR][oO][nN][yY][mM]>|)Ca(|g; s|<[fF][oO][rR][mM][\w\W]*?</[fF][oO][rR][mM]>||g if(!$forms); s|</?[fF][oO][rR][mM]$R|)Ts BE(|g; s/<$s[^>]*[mM][uU][lL][tT][iI][pP][lL][eE]$R/)1 MS(<table>/g; s/<$s$R/)0 MS(<table>/g; s|</$s>|</table>|g; s/<[oO][pP][tT][iI][oO][nN]$R/<tr><td>)O(/g; while(/<[iI][nN][pP][uU][tT]$R/) { $beg=$`; $iattr=$1; $rest=$'; $it=2; if($iattr=~/type\s*=\s*["']?(\w+)/i) {$it=$it{"\L$1"}}; if($it<2) { $it=($iattr=~/\schecked\W/i?1:0) ." $it"; } elsif($it==2) { $siz=$iattr=~/size\s*=\s*["']?(\d+)/i?$1:12; $ival=$iattr=~/value\s*=\s*($S)/i?$+:""; $it="($ival)$siz $it"; } if(defined($it)) { $cmd=$it==3?"<img $iattr":")$it BX("; } else { $cmd=""; } $_=$beg.$cmd.$rest; } while(/<[tT][eE][xX][tT][aA][rR][eE][aA]$R/) { $beg=$`; $txatr=$1; $rest=$'; if($rest=~m|</[tT][eE][xX][tT][aA][rR][eE][aA]>|) { $rest=$'; $data=$prefilled||$textarea_data?$`:""; $rows=4; $cols=20; if($txatr=~/rows\s*=\s*["']?(\d+)/i) {$rows=$1}; if($txatr=~/cols\s*=\s*["']?(\d+)/i) {$cols=$1}; $nl=$data=~y/\n/\n/; for ($nl..$rows) {$data.="\n"}; $data=~/(.*\n){$rows}/; $tfont=$prefilled?"TT":"0 FZ"; ($data=$&)=~s/.*\n/<tr height=24><td valign=top>)$tfont($&)ES(/g; $wi=10*$cols; $frame=$prefilled?"frame=box":"border"; $_="$beg<table $frame width=$wi cellpadding=2>$data</table>$rest"; } else { $_=$beg.$rest; } } $nfnt=1; s|<(/?)($F)([>\s])|"<$1$2".($1?--$nfnt:$nfnt++).$3|eg; while(/<$F(\d+)([^>]*)$U\s*=\s*["']?\s*#?(\w+)$R/) { $rgb=&col2rgb($3); $_=$`.($rgb?")WB $rgb Sc(":"")."<font$2$4"; $temp=$'; $temp=~s|</$F$1>|</font>)Ec(| if($rgb); $_.=$temp; } $base{"+"}="Bf add "; $base{"-"}="Bf add "; s/<$F\d*\s[^>]*[sS][iI][zZ][eE]\s*=\s*["']?([+-]?)(\d+\.?\d*)$R/)$1$2 $base{$1}FZ(/g; s|<$F\d*$R|)3 FZ(|g; s|</$F\d*>|)Ef(|g; s|<[bB][aA][sS][eE]$F\s[^>]*[sS][iI][zZ][eE]\s*=\s*["']?(\d+)$R|)$1 BZ(|g; while(/(<[aA]\s+[^>]*)[nN][aA][mM][eE]\s*=\s*(["']?)([^"'\s>]*)$R([^\s<)]*)/) { $lnk="$html#$3"; $refs{$lnk}=$nref++ unless(defined $refs{$lnk}); $_="$`$1$4$5)WB $refs{$lnk} Sn($'"; } while(/<[aA]\s+[^>]*[hH][rR][eE][fF]\s*=\s*["']?\s*([^"'\s>]*)$R/) { $beg=$`; $tag=$&; $rest=$'; $lnk=$1; $revtoc=$tag=~/rev\s*=['"]?\s*toc/i; $html=~m|[^/]*$|; $lnk=~s/^\Q$&#/#/; $loc=$lnk=~/^#/; if($loc) { $html=~m|[^/]*$|; $lnk=$&.$lnk; } if($lnk=~m|.+//[^/]+$|) {$lnk=$&."/"} if($lnk=~m|://|) { $rlnk=0; } else { $rlnk=1; if($lnk=~m|^/|) {$lnk=$b1.$lnk} elsif($lnk!~m|^\w+:|) {$lnk=$b2.$lnk}; } while($lnk!~m|^\.\./| && $lnk=~m|[^/]*/\.\./|) {$lnk=$`.$'}; $lnk=~s"(^|/)\./"$1"g; ($doc)=$lnk=~/([^#]*)/; ($doctit{$doc})=$tag=~/title\s*=['"]([^'"]*)['"]/i; $T=0; $anch=2; if($loc || grep(/^\Q$doc\E$/,(@docs,@links)) || $opt_W && !$link && $level<=$maxlev && &follow){ $refs{$lnk}=$nref++ unless(defined $refs{$lnk}); $anch="$refs{$lnk} 1"; $ltype=$rev && $revtoc && $ndoc==1 || $opt_C=~/f/ && $ndoc==1?1:0; $rest=~s|</a>|)$refs{$lnk} $ltype TN TL()Ec /AF f D(|i; if(&follow && !$levl{$doc}) { &dbg("Link: $doc\n") if($opt_d); $levl{$doc}=$level+1; push(@links,$doc); } } elsif(defined $refs{$lnk}) { $anch="$refs{$lnk} 1"; } $addr=$dum{$lnk}?"R$dum{$lnk}":0; if(!$dum{$lnk} && $lnk=~m|://|) { $dum{$lnk}=$nlnk++; $rfs.="/R$dum{$lnk} ($lnk) D\n"; $addr="R$dum{$lnk}"; } $_=$beg.")$addr $anch A(".$rest; } s|</[aA]>|)EA(|g; if((!$mult || $doc_sep eq $pc && $mult) && m|<[bB][aA][nN][nN][eE][rR]$R([\w\W]*)</[bB][aA][nN][nN][eE][rR]>|) { $banner=$2; $_=$`.$'; } while(/<[tT][aA][bB][lL][eE]([^>]*)>/) { local($beg)=$`; local($rest)=$'; $tattr=$1; $tag=$&; $rest=~/(<\/[tT][aA][bB][lL][eE]>|$)/; $table=$`; $rest=$'; while($table=~/<[tT][aA][bB][lL][eE]([^>]*)>/) { $tattr=$1; $table=$'; $beg.=$tag.$`; $tag=$&; } ($tla)=$tattr=~/lang\s*=\s*["']?([a-zA-Z-]+)/i; if(!$tla) {($tla)=$beg=~/\004_?([^\004]*)\004[^\004]*$/}; $ntab++; $table=~s/^\s*//; undef %cells; undef %rd; undef @cali; undef @cval; undef @cgrp; undef @cwid; undef @codc; undef @r0; undef @c0; ($capat,$cap)=$table=~m|<caption$R([\w\W]*)</caption>|i; $capat=~/ALIGN\s*=\s*["']?\s*(\w+)/i; $capa=0; $capa=1 if("\L$1" eq "bottom"); $capa=-1 if($cap!~/\S/); $bord=0; if($tattr=~/border/i) { ($bord)=$'=~/^\s*=\s*["']?(\d+)/; if(!$bord && $bord ne "0") {$bord=1}; } ($talgn)=$tattr=~/ALIGN\s*=\s*["']?\s*(\w+)/i; $tal=-1; $tal=0 if($talgn=~/^left$/i); $tal=1 if($talgn=~/^center$/i); $tal=2 if($talgn=~/^right$/i); ($fra)=$tattr=~/FRAME\s*=\s*["']?\s*(\w+)/i; if($fra && $f{"\L$fra"}) {$fra=$f{"\L$fra"}} else {$fra=$bord?9:1}; ($rul)=$tattr=~/RULES\s*=\s*["']?\s*(\w+)/i; if($rul && $r{"\L$rul"}) {$rul=$r{"\L$rul"}} else {$rul=$bord?5:1}; unless(($twid)=$tattr=~/WIDTH\s*=\s*["']?(\d+\.?\d*%?)/i) {$twid=0}; $twid=$twid=~/%$/?$`/100:-$twid; ($cpad)=$tattr=~/CELLPADDING\s*=\s*["']?\s*$V/i; if($tattr=~/CELLSPACING\s*=\s*["']?\s*$V/i && $1!=0) {$cpad+=$1/2}; ($tbg)=$tattr=~/BGCOLOR\s*=\s*["']?\s*#?(\w+)/i; $tbg=&col2rgb($tbg); ($tcl)=$tattr=~/CLASS\s*=\s*["']?\s*(\w+)/i; $tcl="\L$tcl" eq "telelista"? 1: 0; $ic=0; $span=1; undef $gal; undef $gva; undef $odc; undef $gwi; $cgs=0; while($table=~/<[cC][oO][lL]([^>]*>)/g && $span>0) { $cola=$1; $ab=$`; $aft=$'; $cola=~/(^|\s)ALIGN\s*=\s*["']?\s*(\w+)/i; $alg=$algn{"\L$2"}; ($val)=$cola=~/VALIGN\s*=\s*["']?\s*(\w+)/i; $val=$v{"\L$val"}; ($odc)=$cola=~/CHAR\s*=\s*["']?(.)/i; unless(($wid)=$cola=~/WIDTH\s*=\s*["'](\d+%?)/i) {$wid=0}; if($wid=~/%$/) {$wid=$`/100}; ($span)=$cola=~/SPAN\s*=\s*["']?\s*(\d+)/i; if(!$span && $span ne "0") {$span=1}; $us=1; if($cola=~/^GROUP/i) { $gal=$alg; $gva=$val; $gdc=$odc; $gwi=$wid; $cgs=1; if($aft=~/<COL\s/i) { $us=$`=~m|</?COLGROUP|i; } } else { while($ab=~/<COLGROUP/i) {$ab=$'}; if($ab=~m|</COLGROUP|i) { undef $gal; undef $gva; undef $odc; undef $gwi; } if(!$alg) {$alg=$gal}; if(!$val) {$val=$gva}; if(!$odc) {$odc=$gdc}; if(!$wid) {$wid=$gwi}; if($span eq "0") { $ic++; push(@cali,$alg); push(@cval,$val); push(@cwid,$wid); push(@codc,$odc); push(@cgrp,1); } } if($us) { for (1..$span) { $ic++; push(@cali,$alg); push(@cval,$val); push(@cwid,$wid); push(@codc,$odc); push(@cgrp,$cgs); $cgs=0; } } } $table=~/<t[hd][\s>]/i; if($`!~/<tr/i) {$table="<TR>$table"}; $nrow=-1; $ncol=-1; $nhead=0; $nfoot=0; $nb=0; unless($table=~/<tbody$R/i || $table=~s|</tfoot>|$&<tbody>|i) { $table=~s|</thead>|$&<tbody>|i; } while($table=~/<[tT][rR]\s*([^>]*)>/g) { $nrow++; $ab=$`; $row=$'; $rattr=$1; for $j (@c0) { $cells{"$nrow,$j,0"}=1; } $rgrp=0; if($ab=~/<tbody$R/i) { $ib=0; while($ab=~/<[tT][bB][oO][dD][yY]$R/g) { $ib++; $battr=$1; if($ib>$nb) { $rgrp=1; $nb=$ib; } } } else { if($ab=~/<tfoot$R/i) { $nfoot++; $battr=$1; } elsif($ab=~/<thead$R/i) { $nhead++; $battr=$1; } } $battr=~/(^|\s)ALIGN\s*=\s*["']?\s*(\w+)/i; $balgn=$algn{"\L$2"}; $battr=~/VALIGN\s*=\s*["']?\s*(\w+)/i; $bva=$v{"\L$1"}; ($bdc)=$battr=~/CHAR\s*=\s*["']?(.)/i; $rd{"$nrow,0"}=0; $rd{"$nrow,1"}=0; $rd{"$nrow,2"}=0 unless($rd{"$nrow,2"}); $rd{"$nrow,3"}=$rgrp; $rattr=~/(^|\s)ALIGN\s*=\s*["']?\s*(\w+)/i; $ralgn=$algn{"\L$2"}; $rattr=~/VALIGN\s*=\s*["']?\s*(\w+)/i; $rva=$v{"\L$1"}; ($rla[$nrow])=$rattr=~/lang\s*=\s*["']?([a-zA-Z-]+)/i; ($rbg)=$rattr=~/BGCOLOR\s*=\s*["']?\s*#?(\w+)/i; $rbg[$nrow]=&col2rgb($rbg); ($rdc)=$rattr=~/CHAR\s*=\s*["']?(.)/i; if($row=~/<tr/i) {$row=$`}; $rh[$nrow]=$rattr=~/HEIGHT\s*=\s*["']?(\d+)/i?$1:0; $icol=0; $colsp=1; while($row=~/<[tT]([hH]|[dD])(\s*[^>]*)>/g && $colsp>0) { $cattr=$2; $cell=$'; $ctype=$1=~/h/i?1:0; if($cell=~/<t[hd]/i) {$cell=$`}; $cell=~s/\s+$//; $cell=~s/\)HY\($/\255/; $cell=~s/[\200-\377]([^\\]|\\20.)/$&)WB(/g if(!$latin1); ($rowsp)=$cattr=~/ROWSPAN\s*=\s*["']?(\d+)/i; $rsp=$rowsp; if(!$rsp) { if($rsp eq "0") { push(@c0,$icol); } else { $rowsp=1; } $rsp=1; } ($colsp)=$cattr=~/COLSPAN\s*=\s*["']?(\d+)/i; $csp=$colsp; if(!$csp) { if($csp eq "0") { push(@r0,$nrow); $csp=$ncol-$icol<0? 1: $ncol-$icol+1; } else { $colsp=1; $csp=1; } } ($cdc)=$cattr=~/CHAR\s*=\s*["']?(.)/i; while($cells{"$nrow,$icol,0"}==1) {$icol++}; # for $i ($nrow..$nrow+$rsp-2) {$rd{"$i,2"}=1}; for $j ($icol..$icol+$csp-1) { for $i ($nrow..$nrow+$rsp-1) { $cells{"$i,$j,0"}=1; } } if($colsp) { for $j ($ncol+1..$icol+$csp) { for $i (@r0) { $cells{"$i,$j,0"}=1; } } } if($ic<$icol+$csp) { for ($ic..$icol+$csp-1) { push(@cali,$cali[$ic-1]); push(@cval,$cval[$ic-1]); push(@cgrp,0); } $ic=$icol+$csp; } $cal=$ctype; $cal=$balgn-1 if($balgn); $cal=$ralgn-1 if($ralgn); $cal=$cali[$icol]-1 if($cali[$icol]); if($cattr=~/(^|\s)ALIGN\s*=\s*["']?\s*(\w+)/i) { $cal=$algn{"\L$2"}-1 if($algn{"\L$2"}); } $cvl=2; $cvl=$cval[$icol] if($cval[$icol]); $cvl=$bva if($bva); $cvl=$rva if($rva); if($cattr=~/VALIGN\s*=\s*["']?\s*(\w+)/i) { $cvl=$v{"\L$1"} if($v{"\L$1"}); } ($cbg)=$cattr=~/BGCOLOR\s*=\s*["']?\s*#?(\w+)/i; $cbg=&col2rgb($cbg); for($rbg[$nrow],$tbg,$deftbg,$bg) {$cbg=$_ if(!$cbg)}; $now=0; $ro=$cattr=~/class\s*=\s*["']?rot(-?90)/i?$1:0; if($cattr=~/NOWRAP/i || $cal==4 || $ro) {$now=1}; $dc="."; $dc=$bdc if($bdc || $bdc eq "0"); $dc=$rdc if($rdc || $rdc eq "0"); $dc=$codc[$icol] if($codc[$icol] || $codc[$icol] eq "0"); $dc=$cdc if($cdc || $cdc eq "0"); ($wid)=$cattr=~/WIDTH\s*=\s*["'](\d+%)/i; if($wid=~/%$/) {$wid=$`/100}; if($wid>$cwid[$icol]) {$cwid[$icol]=$wid}; if($cpad || $cpad eq "0") { $clm=$cpad; $crm=$cpad; $ctm=$cpad; $cbm=$cpad; } else { $clm=$rul<5?8:4; $crm=$rul<5?8:4; $ctm=2; $cbm=6; } if($tcl==1) { $clm=$icol>0?12:2; $crm=12; $ctm=0; $cbm=0; } if($rul==1 && $fra==1 && $icol==0 && $tal==0) {$clm=0}; ($lang)=$cattr=~/lang\s*=\s*["']?([a-zA-Z-]+)/i; for($rla[$nrow],$tla) {$lang=$_ if(!$lang)}; $lang=lc $lang; &inihyph if($opt_H); $cbg=~/#(\w+).*#(\w+).*#(\w+)/; &img($cell,$1,$2,$3); @cll=("{(\004$lang\004)WB($cell)}",0,0,$ctype,0,$colsp,$rowsp,$cal, "($dc)",$cvl,$now,$clm,$crm,$ctm,$cbm,0,0,0,0,$cbg,$ro); for $i (0..$#cll) {$cells{"$nrow,$icol,$i"}=$cll[$i]}; $icol+=$csp; if($icol-1>$ncol) {$ncol=$icol-1}; } } for $j (0..$ncol) { for $i (0..$nrow) { if($cells{"$i,$j,0"} && $cells{"$i,$j,0"}!=1) { if($cells{"$i,$j,6"}>$nrow-$i+1) {$cells{"$i,$j,6"}=$nrow-$i+1}; if($cells{"$i,$j,6"}>1) {$rd{"$i,2"}=1}; } } } $rd{"$nrow,2"}=0; $rw="["; for $i (0..$nrow) { $rw.="[$rh[$i] ".$rd{"$i,1"}." ".$rd{"$i,2"}." ".$rd{"$i,3"}." 0 0 ["; for $j (0..$ncol) { $cbg=""; for($rbg[$i],$tbg,$deftbg,$bg) {$cbg=$_ if(!$cbg)}; $temp="[{()}0 0 0 0 1 1 0(.)0 0 $clm $crm $ctm $cbm 0 0 0 0 $cbg $ro]"; if($cells{"$i,$j,0"}==1) { $temp="0"; } elsif($cells{"$i,$j,0"}) { $temp="["; for $k (0..$#cll) { $temp.=$cells{"$i,$j,$k"}." "; } $temp.="]"; } $rw.="$temp\n"; } $rw.="]]\n"; } if($nrow==$nhead+$nfoot-1) { $nhead=0; $nfoot=0; } $tdesc="[0 0 $tcl 0 0 $tal 0 $twid $bord $nrow $ncol" ." $nhead $nfoot $fra $rul {($cap)} $capa]\n"; $cdesc="["; for (0..$ncol) { unless($wid=$cwid[$_]) {$wid=0}; $cdesc.="[0 0 0 $wid $cgrp[$_] 0 0]"; } $cdesc.="]\n"; $tables.="[$tdesc $cdesc $rw]]\n"; $_=$beg.")$ntab PT(".$rest; } &img($_,$red,$grn,$blu); &ack($_); $_[0]=$_; } sub getcom{ $com=$&; $'=~/--\s*(--|>)/; $com.=$`.$&; $rest=$'; while($1 eq "--") { $'=~/(>)/ if($'!~/--\s*(--|>)/); $com.=$`.$&; $rest=$'; } } sub getl { ($l)=@_; if(!$lid{$l}) { while($l=~s/-[^-]+$// && !$lid{$l}) {}; } $lid{$l}; } sub ack { local($_)=@_; chdir $tempdir; while (/<[mM][aA][tT][hH]/) { $beg=$`; $rest=$&.$'; $rest=~m|</[mM][aA][tT][hH]>|; $end=$'; $math=$`; if(&math2sym($math)) { $_=$beg.$sym.$end; } elsif($package{'TeX'} && $package{'dvips'}) { $math=~s|\\200|\\|g; $math=~s|\\201|\(|g; $math=~s|\\202|\)|g; &math2tex($math); open(SCRATCH,">$scr.tex"); print SCRATCH $tex; close SCRATCH; `tex $scr.tex`; `dvips -E -o $scr.ps $scr.dvi`; open(LOG,"$scr.log"); $log=<LOG>; close LOG; ($h,$d)=$log=~/[\w\W]*$prog: +([\d.]+)pt: +([\d.]+)/ ? ($1,$2) : (1,0); $above=$h+$d>0?sprintf("%.4f",$h/($h+$d)):0; open(PS,"$scr.ps"); $pic=<PS>; if($pic=~/^%!/ && $pic=~/%%BoundingBox: +$V +$V +$V +$V/) { $xs=$3-$1; $ys=$4-$2; $llx=$1; $lly=$2; $ps=""; for $i (split(/\n/,$pic)) { $ps.=$i."\n" if($i && $i!~/^%/); } if($ps=~/\nTeXDict begin/) { if(!$ph) { $ph="/DH {1 F div dup scale /showpage {} D\n$`$&} D\n%EndDH\n"; $pv=$ph.$pv; } $ps="save -$llx -$lly translate\nDH$' restore"; } } $nimg++; $nps--; push(@XS,$xs); push(@YS,$ys); push(@IX,$nps); push(@IT,2); $pv.="/P$nimg {$ps} D\n"; $eps{"P$nimg"}=$ps; $_=$beg.")$above 3 (P$nimg) $nimg IM(".$end; } else { $math=~s/<math$R//i; $_=$beg.$math.$end; } } chdir $cwd; s|<[sS][uU][bB]$R|)Sb(|g; s|<[sS][uU][pP]$R|)Sp(|g; s"</[sS][uU]([bB]|[pP])>")Es("g; s|<[A-Za-z/!?]\w*$R||g; &ent($_); y/\003/>/; s/\004([^\004]*)\004/")".&getl($1)." Sl($&"/eg; if($opt_H) { &dbg("Inserting potential hyphenation points\n") if($opt_d && $ndoc>0); $temp=""; while(/\004([^\004]*)\004/) { $temp.=$`; $lang=$1; $end=$'; if($end=~/\004([^\004]*)\004/) { $htext=$`; $end=$&.$'; } else { $htext=$end; $end=""; } $apa=""; while($htext=~/(..?)\(([^)]*)/) { $slut=$'; if($1 eq "XX") { $apa.=$`.$&; if($'=~/RP\(/) { $apa.=$`; $htext=$&.$'; } else { $apa.=$slut; $htext=""; } } elsif($1 eq ") ") { $apa.=$`.$&; $htext=$'; } else { $apa.="$`$1("; $htext=$'; ($txt=$2)=~s/[$ltrs]{$hyphenation{'min'},}/&hyph($&)/eg; $apa.=$txt; } } $_=$apa.$slut.$end; } $_=$temp.$_; } s/\004([^\004]*)\004//g; $_[0]=$_; } sub ent { local($_)=@_; s|&#x($X+);?|"&#".hex($1).";"|egi; for $char (keys %ent) {s/&($char)(;|$|(?=\W))/chr($ent{$char})/eg}; for $char (keys %symb) {s/&($char)(;|$|(?=\W))/)SY(\\$symb{$char})ES(/g}; s/&(euro|#8364)(;|$|(?=\W))/)MY(e)ES(/g; s|&lt;?|<|g; s|&gt;?|>|g; s|&quot;?|"|g; s/&($space);?/)$space{$1} Se(/g; s|&#(\d+);?|$1==38?"\005":$1<256?chr($1):$&|eg; s/(\005|&amp;?)/\&/g; $_[0]=$_; } sub spec { $_[0]=~s/(\\|&#92(;|$|(?=\W)))/\\200/g; $_[0]=~s/(\(|&#40(;|$|(?=\W)))/\\201/g; $_[0]=~s/(\)|&#41(;|$|(?=\W)))/\\202/g; $_[0]=~s/&(there4|#8756|#[xX]2234)(;|$|(?=\W))/)SY(\\200)ES(/g; } sub math2tex { local($_)=@_; local($beg,$rest); %a=("line","overline", "cub","overbrace", "hat","widehat", "tilde","widetilde", "larr", "overleftarrow", "rarr", "overrightarrow"); %b=("line","underline", "cub","underbrace", "hat","widehat", "tilde","widetilde"); %s=("medium","\\big", "large","\\Big", "huge","\\bigg"); ($mattr)=/<math$R/i; $st=$mattr=~/class\s*=\s*["']?chem/i?'\rm ':''; $di=$mattr=~/class\s*=\s*["']?displayed/i?'\displaystyle ':''; s/<math$R//gi; s/\\/\\backslash/g; s/__/_\\>_/gi; s/\^\^/^\\>^/gi; s/_([^_]+)_/_{$1}/g; s/\^([^^]+)\^/^{$1}/g; s/&thinsp;?/\\,/g; s/&sp;?/\\>/g; s/&emsp;?/\\;/g; s/&nbsp;?/\\>/g; s/&epsi;?/\\varepsilon /g; s/&upsi;?/\\upsilon /g; s/&piv;?/\\varpi /g; s/&sigmav;?/\\varsigma /g; s/&thetav;?/\\vartheta /g; s/&phiv;?/\\varphi /g; s/&Upsi;?/\\Upsilon /g; s/&omicron;?/o/g; s/&plusmn;?/\\pm /g; s/&or;?/\\vee /g; s/&and;?/\\wedge /g; s/&ap;?/\\approx /g; s/&sube;?/\\subseteq /g; s/&sub;?/\\subset /g; s/&supe;?/\\supseteq /g; s/&sup;?/\\supset /g; s/&isin;?/\\in /g; s/&larr;?/\\leftarrow /g; s/&rarr;?([_^])/\\mathop\\rightarrow\\limits$1 /g; s/&rarr;?/\\rightarrow /g; s/&uarr;?/\\uparrow /g; s/&darr;?/\\downarrow /g; s/&harr;?/\\leftrightarrow /g; s/&lArr;?/\\Leftarrow /g; s/&rArr;?/\\Rightarrow /g; s/&uArr;?/\\Uparrow /g; s/&dArr;?/\\Downarrow /g; s/&exist;?/\\exists /g; s/&inf;?/\\infty /g; s/&?int;?/\\int\\limits /g; s/&?sum;?/\\sum\\limits /g; s/&?prod;?/\\prod\\limits /g; s/&pd;?/\\partial /g; s/&lcub;?/\\{/g; s/&rcub;?/\\}/g; s/<t>/\\hbox{/gi; s/<b>/\\bf /gi; s/<bt>/{\\bf\\hbox{/gi; s/<sub$R/_{/gi; s/<sup$R/\^{/gi; s/<box\s*size=["']?(\w+)["']?>/{\\def\\lft{$s{$1}}\\def\\rgt{$s{$1}}/gi; s/<box$R/{/gi; s/<text\s*>/\\hbox{/gi; s/([\(\[\|])\s*<left>/\\lft$1/gi; s/<right>/\\rgt /gi; s/<(atop|choose|over)>/\\\L$1 /gi; s/<of>/}\\of{/gi; s/<bar>/\\overline{/gi; s/<vec>/\\overrightarrow{/gi; s/<hat>/\\widehat{/gi; s/<tilde>/\\widetilde{/gi; s/<(sqrt|root|vec|dot|ddot|hat|tilde)>/\\\L$1\{/gi; while(/<above\s+sym\s*=\s*["']?equals["']?\s*>/i) { $beg=$`."\\overline{\\overline{"; $rest=$'; $rest=~s/<\/above>/}}/i; $_=$beg.$rest; } s/<above\s*>/\\overline{/gi; s/<above\s+sym\s*=\s*["']?(\w+)["']?\s*>/\\$a{$1}\{/gi; s/<below\s*>/\\underline{/gi; s/<below\s+sym\s*=\s*["']?(\w+)["']?\s*>/\\$b{$1}\{/gi; s/<\/(math|row|item|b)>//gi; s/<\/(box|t|sup|sub|sqrt|root|vec|bar|dot|ddot|hat|tilde|above|below|text|array)>/}/gi; s/<\/bt>/}}/gi; s/&lt;?/< /gi; s/&gt;?/>/gi; s/&(\w+);?/\\$1 /gi; s/<array$R/\\matrix{/gi; s/<row>\s*<item$R//i; s/<row>\s*<item$R/\\cr /gi; s/<item>/&/gi; s/<[^ ]$R//gi; s/\n*$//; $tex="\\batchmode\\magnification=$mag\\hsize=40cm\\nopagenumbers\n" ."\\def\\lft{\\left}\\def\\rgt{\\right}\n\\setbox0=\\hbox{\$$st$di".$_."\$}\n" ."\\immediate\\write0{$prog: \\the\\ht0: \\the\\dp0}\\box0\n\\end\n"; } sub Getopts { local($optlist)=@_; local(@args,$_,$opt,$opts,$rest,$olist,$plist,$found,@popts); local($errs)=0; local($[)=0; @args=split( /\|/, $optlist ); for $opt (@args) { if(substr($opt,-1,1) ne ':') {$olist.=$opt} else {$plist.=$opt} } @popts=split(/:/,$plist); while(@ARGV && ($_=$ARGV[0]) =~ /^-(.*)/) { $opt=$1; if($opt=~/^-/ && $optalias{"\L$'"}) {$opt=$optalias{"\L$'"}}; if($opt =~ /^[$olist]+$/) { while ($char=chop $opt) {eval "\$opt_$char=1"} shift(@ARGV); } else { $found=0; for $opts (@popts) { $rest=substr($opt,length($opts)); if(index($opt,$opts)==0) { $found=1; shift(@ARGV); if(length($rest)==0) { ++$errs unless @ARGV; $rest=shift(@ARGV); } eval "\$opt_$opts=\$rest"; } } if(!$found) { &dbg("Unknown option: $opt\n"); ++$errs; shift(@ARGV); } } } $errs==0; } sub openps { open(STDOUT,">$opt_o") || die "*** Error opening $opt_o for output\n"; } sub getalt { if($imgcmd eq "img") { $alt=""; $match=0; if($img=~/alt\s*=\s*"([^"]*)"/i) {$alt=$1; $match=1}; if(!$match && $img=~/alt\s*=\s*([\w\.-]+)/i) {$alt=$1; $match=1}; if(!$match) {$alt=")WB IA WB("}; $text="$alt )WB("; return; } if($imgcmd eq "hr") { $text=$img=~/align\s*=\s*["']?(left|center|right)/i?")$algn{lc $1} ":")2 "; $text.=$img=~/size\s*=\s*["']?$V/i?$1:.6; $wd=1; if($img=~/width\s*=\s*["']?$V(%?)/i) {$wd=$2?$1/100:-$1}; $text.=" $wd HR("; return; } if($imgcmd eq "fig") { $text=")BN("; } } sub xbmtops { $fc=1; $dp=1; ($xs,$ys)=$pic=~/^#define.* (\d+)[\w\W]*^#define.* (\d+)/; $nd=2*int(($xs+7)/8)*$ys; ($pic)=$pic=~/[^#].* char.*[\w\W]*{([\w\W]*)}/; $pic=~s/[ ,\n\r]*0x[ ,]*//g; $pic=~y/01246789bdef/f7bd91e62480/; $bm=unpack("H*", pack("h*",$pic)); } sub pmtops { pmtoraw($pm) if($pm=~/^P([1-3])/); $pm=~/^P([4-6])/; $maptype=$1; return if(!$maptype); $pm=$'; $bm=""; $nint=3; $dp=8; if($maptype==4) { $nint=2; $dp=1; } undef @num; $found=0; while($pm && $found<$nint) { if($pm=~/^\s*(\d+)/) {$num[$found]=$1}; if($num[$found]) { $found++; $pm=$'; } elsif($pm=~/^\s*#.*\n/) { $pm=$'; } else { return; } } ($b)=$pm=~/\s([\w\W]*)/; ($xs,$ys,$bits)=@num; return if($bits>255); $fc=1; if($maptype==6) { $fc=3; $nd=6*$xs*$ys; $bm=unpack("H*",$b); } else { $bm=unpack("H*",$b); if($maptype==4) { $nd=2*int(($xs+7)/8)*$ys; $bm=~y/0123456789abcdef/fedcba9876543210/; } else { $nd=2*$xs*$ys; } } } sub trans { $next = 13; $temp = ord substr($pic,10,1); if($temp & 0x80) {$next += 3*2**(($temp & 0x07) + 1)} else {return}; $byte = ord substr($pic,$next,1); while($byte != 0x3b && $next <= length $pic) { if($byte == 0x21) { if(ord substr($pic,$next+1,1) == 0xf9) { if(ord substr($pic,$next+3,1) & 0x01) { &dbg("Transparent\n") if($opt_d); $src{$URL}=$pic; $idx = 3*(ord substr($pic,$next+6,1))+13; substr($pic,$idx,3) = pack("H*",$red.$grn.$blu) if($idx<length $pic); } return; $next += 2; &skip; } else { $next += 2; &skip; } } elsif($byte == 0x2c) { $next += 10; $temp = ord substr($pic,$next-1,1); if($temp & 0x80) {$next += 3*2**(($temp & 0x07) + 1)}; $next++; &skip; } else {return} } } sub skip { $byte = ord substr($pic,$next,1); while($byte != 0) { $next += $byte + 1; $byte = ord substr($pic,$next,1); } $next++; $byte = ord substr($pic,$next,1); } sub run { &dbg("@_\n") if($opt_d); $pm=`@_`; } sub geturl { local($url)=@_; &dbg("Retrieving $url"); if($package{'libwww-perl'} || $package{'jfriedl'}) { warn "\n"; &gu(); if($code==401) { &prompt("\nDocument requires username and password\n\nUsername: ",$user); &prompt("Password: ",$pass); &gu($user,$pass); } $_[1]=$cont; } elsif(defined $geturl) { &dbg("..."); $_[1]=`$geturl '$url'`; if($?) { &dbg("\n*** Error opening $url\n"); return 0; } &dbg("done\n"); if($_[1]=~/\r?\n\r?\n/) { $_[1]=$'; $dhead=$`; ($code)=$dhead=~/HTTP\/\S+ +(\d+)/i; ($contyp)=$dhead=~/Content-type:\s+(.*)/i; } else { $code=500; } } $_[0]=$url; $code<300; } sub gu { if($package{'libwww-perl'}) { require LWP::UserAgent; $ua=new LWP::UserAgent; $ua->env_proxy(); if ($opt_k) { require HTTP::Cookies; $cookie_jar = HTTP::Cookies::Netscape->new(File => $opt_k, AutoSave => 1); $ua->cookie_jar($cookie_jar); } $req = HTTP::Request->new(GET => $url); $req->authorization_basic(@_) if(@_); $ua->agent($spoof) if($spoof); my $res = $ua->request($req); $code=$res->code; $contyp=$res->header('content-type'); $cont=$res->content; } else { require "www.pl"; @opts=@_?("authorization=$_[0]:$_[1]"):(); push(@opts,"quiet") if(!$opt_d); $www::useragent=$spoof if($spoof); ($status,$memo,%info)=&www::open_http_url(*FILE,$url,@opts); $code=$info{'CODE'}; ($contyp)=$info{'HEADER'}=~/Content-type:\s+(.*)/i; $cont=<FILE>; } } sub pictops { if($opt_g) { $fc=1; $pg1="pgm"; $pg2="|ppmtopgm"; } else { $fc=3; $pg1="ppm"; $pg2=""; } ($type)=$URL=~/([^\?]+)\??/; ($type)=$type=~/\.(\w+)$/; $bm=""; $ps=""; $pm=""; if($opt_U && $src{$URL} && !$cmd{$URL.$red.$grn.$blu}) { $pic=$src{$URL}; } elsif($URL=~m|://|) { &geturl($URL,$pic) || return; } else { $flag=0; if($opt_O) { $orig=$URL; unless($orig=~s/\.\w*$/.ps/) {$orig.=".ps"}; if(open(ORIG,"$orig")) { $pic=<ORIG>; close ORIG; if($pic=~/^%!/ && $pic=~/%%BoundingBox:/) { $flag=1; &dbg("Using $orig as original for $URL\n") if($opt_d); } } } if(!$flag) { if(open(PIC,"$URL")) { binmode PIC; $pic=<PIC>; close PIC; } else { &dbg("*** Error opening $URL\n"); return; } } } $pic=~s/^[\n\r]*//; &trans if($pic=~/^GIF/); if($pic=~/^P[1-6]/) { $pm=$pic; } else { open(SCRATCH,">$scr"); binmode(SCRATCH); print SCRATCH "$pic"; close SCRATCH; if($pic=~/^%!/ && $pic=~/%%BoundingBox: +$V +$V +$V +$V/) { $xs=$3-$1; $ys=$4-$2; $ps="save\n0 0 M\nIS IS scale\n/showpage {}D\n".(0-$1)." ".(0-$2)." translate\n"; for $i (split(/\n/,$pic)) { $ps.=$i."\n" if($i && $i!~/^%/); } $ps.="restore"; } elsif($type=~/.xbm$/i || $pic=~/^#define/) { &xbmtops; } elsif($package{'ImageMagick'}) { if($package{'PerlMagick'}) { $imobj=Image::Magick->new; $mess=$imobj->Read($scr); if($mess) { &dbg("$mess\n"); } else { $mess=$imobj->Write("$scr\.$pg1"); &dbg("$mess\n") if($mess); } undef $imobj; } else { # &run("convert $scr $pg1:-"); &run("convert $scr $scr\.$pg1"); } open(PNM,"$scr\.$pg1"); binmode PNM; $pm=<PNM>; close PNM; if(!$pm && $pic=~/^\377\330/ && $package{'djpeg'}) { &run("djpeg $scr$pg2"); } } elsif($pic=~/^\377\330/ && $package{'djpeg'}) { &run("djpeg $scr$pg2"); } elsif($package{'pbmplus'} || $package{'netpbm'}) { if($pic=~/^GIF/) { &run("$giftopm $scr"); } else { &run("anytopnm $scr"); } if($opt_g && $pm=~/^P6/) { open(SCRATCH,">$scr"); binmode(SCRATCH); print SCRATCH $pm; close SCRATCH; &run("ppmtopgm $scr"); } } } &pmtops if(!$bm); return if(!$bm); $bm=substr($bm,0,$nd); $pad=$nd-length($bm); if($pad) {$bm.="f" x $pad}; $bm=~s/(.{60})/$1\n/g; } sub math2sym { local($_)=@_; s/<math$R//gi; for $char (keys %symb) {s/&($char)(;|$|(?=\W))/\\$symb{$char}/g}; $stat=!/([&<][a-zA-Z]|[_^{])/; s/[a-zA-Z\s]*[a-zA-Z][a-zA-Z\s]*/)ES()I($&)ES()SY(/g; s/(\\200|\\201|\\202)/)RO($&)ES(/g; $sym=")SY($_)ES("; $stat; } sub varsub { for (@_) { s/\\\\/\000/g; s/\([^)]+\)/()$&join /g; s/(^|[^\\])\$(T|N|U|H|A)/$1)join $vars{$2} join(/g; s/(^|[^\\])\$D\{"(.*?)"\}/"$1".POSIX::strftime($+,@now)/eg if($posix); s/(^|[^\\])\$D/"$1".POSIX::strftime($datefmt,@now)/eg if($posix); # while(/(?=[^\\])\${([^}]+)}/) { while(/(?=[^\\])\$\[([^]]+)\]/) { if(!defined $metarc{lc $1}) { $metarc{lc $1}=$mn++; } $_="$`)join ME $metarc{lc $1} get join($'"; } s/\\\$/\$/g; s/\000/\\\\/g; s/\(\)join//g; s/\(\) ?(\([^)]*\)|\w+) ?join/ $1/g; } } sub follow { return 0 if(!$opt_W); $H=$lnk=~/\.html?(#|$)/i || $lnk=~m|.+//.+/[^/\.]*$|; $T=$rev && ($revtoc && $ndoc==1 || $ndoc>1 && $H); $L=$b1=~m|://| && $lnk=~m"^$b1(/|$)" || $b1!~m|://| && $lnk!~m|://|; $B=$B2 && $lnk=~/^$B2/ || !$B2 && $lnk!~m"(^\.\.|://)"; return $rlnk && ($H || $T) if($rel); return $L && ($H || $T) if($local); return $B && ($H || $T) if($below); return $H || $T if($rev); $H; } sub DSC { &dbg("Generating DSC PostScript\n") if($opt_d); %op=("moveto",2, "rmoveto",2, "lineto",2, "rlineto",2, "translate",2, "scale",2, "show",1, "awidthshow",6, "stroke",0, "save",0, "restore",0, "gsave",0, "grestore",0, "showpage",0, "newpath",0, "setlinewidth",1, "setlinejoin",1, "setgray",1, "closepath",0, "fill",0, "arc",5, "setrgbcolor",3, "rotate",1, "image",5, "colorimage",7); %sho=("moveto","M", "rmoveto","RM", "lineto","L", "rlineto","RL", "show","S", "showpage","N", "awidthshow","A"); $i=0; $po="/OU true D\n"; for (keys %op) { $cmd=$sho{$_}?$sho{$_}:$_; push(@val,$cmd); $in{$_}=$i++; $j=$op{$_}+1; $extra=""; if(/showpage/) {$extra="Bb{Xl Yl Xh Yh}if Pn "}; if(/image/) {$extra="K ";$j++}; $t=$op{$_}?"$op{$_} copy $extra$in{$_} $j array astore":"[$extra$in{$_}]"; $po.="/$_ {OU {$t ==} if $_}d\n"; } $po.="/pdfmark {$i] ==} D\n"; $in{"pdfmark"}=$i++; push(@val,"pdfmark"); $po.="/NF {OU{2 copy E $i 3 array astore ==}if ONF}d\n" ."/EX {[IS EC] ==} D\n/Cd {} D\n/DU {TU PM 1 eq and TP and{Pn ==}if}d\n" ."/BB {US Bb{dup Yl lt{dup /Yl E D}if dup Yh gt{/Yh E D}{pop}ie\n" ." dup Xl lt{dup /Xl E D}if dup Xh gt{/Xh E D}{pop}ie}\n" ." {/Yl E D /Yh Yl D /Xl E D /Xh Xl D /Bb t D}ie}D\n"; $in{"Nf"}=$i++; s|/(NF.*)|/O$1|; s|/BB .*|$po|; push(@val,"Nf"); if($psin) { ($ti)=/%%Title: (.*)/; if(m|/BM (\d+)|) { $nbit=$1; for $vec ("IT","WS") { /\/$vec \[(.*)\]/; @$vec=split(' ',$1); } /\nSB/; for (0..$nbit-1) { $'=~/\n\n/; push(@BM,$`); } } ($epsf)=/(\n\/P\d+_?\d* [\w\W]*)%Endpv/; while($epsf=~/\n\/(P\d+_?\d*) \{/g) { $pid=$1; $rest=$'; $temp=$'=~/\/P\d+_?\d* \{/?$`:$rest; ($eps{$pid})=$temp=~/([\w\W]*)} D/; } if(/\/DH {/) { $'=~/%EndDH/; $ph="/DH {$`"; } } $j=-1; for $i (0..$#IT) { $j++ if($IT[$i] == 0); push(@ix,$j); } $dfn="/F $opt_s D\n$ph"; for (keys %sho) { $dfn.="/$sho{$_} {$_} d\n"; } open(SCR,">$scr.ps"); print SCR "$_ quit\n"; close SCR; $cd{')]'}="Cd "; $io="($in{'image'}|$in{'colorimage'})"; $_=""; $temp=""; $pn=""; $start=1; $EPS="%%EndPageSetup"; $pp=0; $n=0; for $line (split(/\r?\n/,`$gs -q -dNODISPLAY $scr.ps -c quit`)) { if(!$pp) { $mv=""; $cx=""; $cy=""; } if($start && $line!~/ $in{"pdfmark"}\]$/) { $pdf=$temp; $temp=""; $start=0; } $pp=$line=~/^\[(\S+) (\S+) ($in{'moveto'}|$in{'rmoveto'}|$in{'Nf'})\]$/; S:{ if($pp && $3==$in{"Nf"}) { $fn="$1 $2 $val[$3]\n"; last S; } if($pp && $3==$in{"moveto"}) { $cx=$1; $cy=$2; $mv=sprintf("%.1f %.1f %s\n",$1,$2,$val[$3]); last S; } if($pp && $3==$in{"rmoveto"}) { if($mv) { $cx+=$1; $cy+=$2; $mv=sprintf("%.1f %.1f %s\n",$cx,$cy,$val[$in{"moveto"}]); } else { $temp.=sprintf("%.1f %.1f %s\n",$1,$2,$val[$3]) if($1||$2); } last S; } if($line=~s/^\[(.*)\((\S*)\) ($in{"showpage"})\]$/pgsave restore $val[$3]/) { $pbb=""; if($1) { ($llx,$lly,$urx,$ury)=split(/ /,$1); $llx=int($llx); $lly=int($lly); $urx=int($urx+1); $ury=int($ury+1); $pbb="%%PageBoundingBox: $llx $lly $urx $ury\n"; if(!defined($Llx) || $llx<$Llx) {$Llx=$llx}; if(!defined($Lly) || $lly<$Lly) {$Lly=$lly}; if(!defined($Urx) || $urx>$Urx) {$Urx=$urx}; if(!defined($Ury) || $ury>$Ury) {$Ury=$ury}; } $pn.="," if($pn && $2); $n++; @df=(); for(0..$#docfonts) { push(@df,$docfonts[$_]) if($uf{$_}==$n); } push(@df,"Symbol") if($uf{"-1"}==$n); $fu=""; $tmp=@df?"%%PageResources: font":""; &splitline(@df); $_.="%%Page: $pn$2 $n\n$fu$pbb%%BeginPageSetup\n/pgsave save D\n$temp$line\n"; $EPS="%%EndPageSetup"; $temp=""; $line=""; $fn=""; $mv=""; $pn=""; last S; } if($line=~/^\[([^(]*)(\(.*\)) ($in{"show"}|$in{"awidthshow"})\]$/) { if(length $2>2) { $line="$fn$1$2 $val[$3]"; if($fn=~/(\S+) Nf/ && $uf{$1}!=$n+1) { $uf{$1}=$n+1; $fnt=$1<0?"Symbol":$docfonts[$1]; $line="%%IncludeResource: font $fnt\n$line"; } $fn=""; $pp=0; } else { $pp=1; } last S; } if($line=~/^\[(\S+) (\S+) ($in{"scale"})\]$/) { $line=$1!=1||$2!=1?"$1 $2 $val[$3]\n$EPS":"$EPS"; $EPS=""; last S; } if($line=~/^\[(.*) (\d+) $io\]$/) { $li=$BM[$2]=~y/\n/\n/+2; $line="\/picstr $WS[$ix[$2]] string D\n$1\n" ."%%BeginData: $li Hex Lines\n$val[$3]\n$BM[$2]\n%%EndData"; last S; } if($line=~/^\((.*)\)$/) { $pn=$1; $line=""; last S; } last S if($line=~s/^\[([^\/].* )?(\d+)\]$/$1$val[$2]/); last S if($line=~s/(\)\])? (\/\w+) $in{"pdfmark"}\]$/$1 $cd{$1}$2 pdfmark/); last S if($line=~s/^\[(\S+) \((P\d+.*)\)\]$/\/IS $1 D\n$eps{$2}/); &dbg("$line\n"); } if(!$pp && $mv.$line) { $mv=~s/\.0//g; $temp.="$mv$line\n"; } } @nf=(); @sf=(); $fontdef=""; for(0..$#docfonts) { $ff=$ff{$docfonts[$_]}; if($ff && $uf{$_}>0) { push(@sf,$docfonts[$_]); $fontdef.="%%BeginResource: font $docfonts[$_]\n$cont{$ff}\n%%EndResource\n"; $cont{$ff}=""; } push(@nf,$docfonts[$_]) if(!$ff && $uf{$_}>0); } push(@nf,"Symbol") if($uf{"-1"}>0); $ti="@ARGV" unless($psin); $or=$opt_L?"Landscape":"Portrait"; $setup="%%BeginSetup\n"; $setup.="$dupl\n" if($dupl); $setup.="$fontdef" if($fontdef); $fu=""; $tmp=@nf?"%%DocumentNeededResources: font":""; &splitline(@nf); $tmp=@sf?"%%DocumentSuppliedResources: font":""; &splitline(@sf); s/\\(200|201|202)/\\$ssy{$1}/g; $dd="Clean7Bit"; $dd="Clean8Bit" if(($fontdef.$_)=~/[\200-\377]/); $dd="Binary" if(($fontdef.$_)=~/[\000-\010\013-\014\016-\036]/); $time=localtime; print <<EOT; %!PS-Adobe-3.0 %%Title: $title %%Creator: $version %%CreationDate: $time $fu%%DocumentData: $dd %%Orientation: $or %%BoundingBox: $Llx $Lly $Urx $Ury %%Pages: $n %%EndComments %%BeginProlog /d {bind def} bind def /D {def} d /ie {ifelse} d /E {exch} d /t true D /f false D $fl $cd $defs $mysymb/Nf {dup 0 ge{FL E get}{-1 eq{/Symbol}{/MySymbol}ie}ie findfont E scalefont setfont} D /IP {currentfile picstr readhexstring pop} D /WF $wf D $dfn%%EndProlog $setup$reenc$pdf%%EndSetup $_%%EOF EOT } sub splitline { for (@_) { if(length($tmp.$_)>78) { $fu.="$tmp\n"; $tmp="%%+ font"; } $tmp.=" $_"; } $fu.="$tmp\n" if($tmp); } sub ref { @pnum=(); /.*\s*$/; open(SCR,">$scr.ps"); print SCR "$`HN{==}forall $& quit\n"; close SCR; $pnum=`$gs -q -dNODISPLAY $scr.ps -c quit`; while($pnum=~/\([^)]*\)/g) {push(@pnum,$&)}; $pnum="@pnum"; &cut($pnum); s|/HN [^D]*D|/HN [$pnum] D|; } sub cut { $_[0]=~s/(.{70}[^ \n]*) ([^ ])/$1\n$2/g; } sub fin { if($opt_D) { &DSC; } else { print; } if($opt_d) { print DBG "\n"; close DBG; } unlink "$scr","$scr.ps","$scr.ppm","$scr.tex","$scr.dvi","$scr.log" if($scr); exit; } sub col2rgb { $rgb=$colour{"\L$_[0]"}?($colour{"\L$_[0]"}):$_[0]; @cvec=$rgb=~/($X$X)($X$X)($X$X)/?($1,$2,$3):(); @cvec?"[16#$1 16#$2 16#$3]":""; } sub inihyph { if($hyphenation_file{$lang}) { $hyfile=$hyphenation_file{$lang}; } else { &dbg("No hyphenation file for language '$lang'\n"); $lng=$lang; while($lng=~s/-?[^-]+$// && !$hyphenation_file{$lng}) {}; $hyfile=$hyphenation_file{$lng}; &dbg(" ..using $hyfile\n"); } if($init{$hyfile}) { $rep{$lang}=$refl{$hyfile}; return; } if(open(HYPH,$hyfile)) { &dbg("Reading hyphenation patterns from $hyfile\n") if($opt_d); <HYPH>=~/\\patterns{.*/; close HYPH; $def=$`; ($patterns=$')=~s/\^\^($X$X)/chr hex $1/eg; $upp{$lang}=''; $low{$lang}=''; while ($def=~/\\lccode(`\\?\^\^|")($X$X)=(`\\?\^\^|")($X$X)/g) { if($2 ne $4) { $uc=$2; $lc=$4; if($`=~/\n$/ || $`!~/%.*$/) { $upp{$lang}.=chr hex $uc; $low{$lang}.=chr hex $lc; } } } while ($def=~/\\let\\(\w+)=(\^\^|")($X$X)/g) { $key=$1; $value=chr hex $3; $tex{$key}=$value if($`=~/\n$/ || $`!~/%.*$/); } for $key (keys %tex) { $patterns=~s/\\$key */$tex{$key}/g; } if($lang=~/^de/) { %de=('"a',228, '"o',246, '"u',252, '\3', 223); $patterns=~s/\\c\{[^}]*\}//g; $patterns=~s/\\n\{([^}]*)\}/$1/g; $patterns=~s/("a|"o|"u|\\3)/chr $de{$1}/eg; $upp{"de"}=~s/\337//; $low{"de"}=~s/\377//; } if($lang=~/^is/ && !$upp{"is"}) { %is=("'a","\341", "'e","\351", "'i","\355", "'o","\363", "'u","\372", "'y","\375", '"x',"\346", '"o',"\366", "'d","\360", "`t","\376"); $isch=join("|",keys %is); $patterns=~s/($isch)/$is{$1}/g; $upp{"is"}="\301\311\315\323\332\335\306\326\336\320"; $low{"is"}="\341\351\355\363\372\375\346\366\376\360"; } if($lang=~/^fi/ && !$upp{"fi"}) { $upp{"fi"}="\304\326"; $low{"fi"}="\344\366"; } if($lang=~/^fr/ && !$upp{"fr"}) { $upp{"fr"}="\300\302\307\311\310\312\313\316\317\324\326\333\226"; $low{"fr"}="\340\342\347\351\350\352\353\356\357\364\366\373\225"; } if($lang=~/^es/ && !$upp{"es"}) { $upp{"es"}="\301\311\315\323\321\332\334"; $low{"es"}="\341\351\355\363\361\372\374"; } $patterns=~s/\{([\w\W]*?)\}/[$1]/g; $patterns=~/}/; $end=$`; if($def.$'=~/\\hyphenation\[.*/) { $'=~/]/; $hyext=$`; } ($patterns=$end)=~s/%.*//g; for $key (split('\s+',$patterns)) { $value=$key; $key=~s/\d//g; $value=~s/^([$ltrs.])/0$1/; $value=~s/[$ltrs](\d)/$1/g; $value=~s/[$ltrs.]/0/g; $patt{"$key,$lang"}=$value if($value=~/^\d+$/); } } else { &dbg("Cannot open hyphenation file: $hyfile\n"); } $hext=$hyphenation_extfile{$lang}; for(split('\s*:\s*',$hext)) { if(open(HEXT,$_)) { &dbg("Reading hyphenation extensions from $_\n") if($opt_d); $hyext.=<HEXT>; close HEXT; } else { &dbg("Cannot open hyphenation extension file: $_\n"); } } if($hyext) { for $key (keys %tex) { $hyext=~s/$key */$tex{$key}/g; } for $key (split('\s+',$hyext)) { $key=~s/\s+//g; $value="00$key\0"; $key=~s/-//g; $value=~s/[$ltrs]/0/g; $value=~s/0-/1/g; $hext{"$key,$lang"}=$value; } } $refl{$hyfile}=$lang; $rep{$lang}=$lang; $init{$hyfile}=1; } sub hyph { $word="\L$_[0]"; eval "\$word=~y/$upp{$rep{$lang}}/$low{$rep{$lang}}/" if($upp{$rep{$lang}}); $len=length($word); $h=$hext{"$word,$rep{$lang}"}; if($h) { @br=split(//,$h); } else { @br=(0) x ($len+3); for $i (0..$len) { for $j (0..$len-$i) { $str=substr(".$word.",$j,$i+2); $pstr=$patt{"$str,$rep{$lang}"}; if($pstr) { @patt=split(//,$pstr); for $k (0..$#patt) { $br[$k+$j]=$patt[$k] if($br[$k+$j]<$patt[$k]); } } } } } $hword=""; for $i (0..$len-1) { $hword.=substr($_[0],$i,1); if(($h || $i>$hyphenation{'start'}-2 && $i<$len-$hyphenation{'end'}) && $br[$i+2]%2==1) {$hword.=")HY("}; } $hword.=")YH(" if(length $word < length $hword); $hword; } sub setel { $el=$_[0]; eval "\%arr=\%$el"; &fs($el); push(@font,$fontid{"\L$font"}); push(@styl,$styl); push(@size,$arr{'font-size'}); push(@alig,$algn{$arr{'text-align'}}-1); push(@topm,$arr{'margin-top'}); push(@botm,$arr{'margin-bottom'}); push(@lftm,$arr{'margin-left'}); push(@rgtm,$arr{'margin-right'}); push(@colr,$col eq "[16#00 16#00 16#00]"?0:$col); $temp=$arr{'margin-top'}*$arr{'font-size'}; $mi=$temp if($temp>$mi); $temp=$arr{'margin-bottom'}*$arr{'font-size'}; $mi=$temp if($temp>$mi); } sub fs { $arr{'font-family'}='times' if($el ne 'p' && !$latin1 && !defined $arr{$_}); for ("font-family","font-size") { $arr{$_}=$body{$_} if(!defined $arr{$_}); } ($font=$arr{'font-family'})=~s/\W/-/g; if(!$font_names{"\L$font"}) {$font=$fal{$font}}; if(!$font_names{"\L$font"}) { &dbg("Unknown font: $arr{'font-family'}, using $deffnt{$_[0]}\n"); $font=$deffnt{$_[0]}; } if(!defined $fontid{"\L$font"}) { $fontid{"\L$font"}=$nfont++; @names=split(/\s+/,$font_names{"\L$font"}); for($#names+1..3) {push(@names,$names[0])}; @docfonts=(@docfonts,@names); } &getval($arr{"font-size"},2); for ('left','right','top','bottom') { $arr{"margin-$_"}=0 if(!defined $arr{"margin-$_"}); } for ($arr{"text-indent"},$arr{"margin-top"},$arr{"margin-bottom"}, $arr{"margin-left"},$arr{"margin-right"}) { &getval($_,0); } $styl=$arr{'font-style'}=~/^(i|o)/+2*($arr{'font-weight'}=~/^b/); $col=$arr{'color'}?&col2rgb($arr{'color'}):-1; } sub img { local($_,$red,$grn,$blu)=@_; local($beg,$end); ($red,$grn,$blu)=("FF","FF","FF") if(!$opt_U); while (/<(img|fig|hr|overlay|object)\s/i) { $imgcmd="\L$1"; $beg=$`; $'=~/>/; $img=" $`"; $end=$'; $img=~s/\n/ /g; if($imgcmd ne "object" || $img=~/data\s*=\s*['"]?([\w\/\.:~%-]+\.$IM)/i || $img=~/type\s*=\s*['"]?(image\/|application\/postscript)/i){ if($opt_T) { &getalt; } else { $al=0; $off=""; ($align)=$img=~/align\s*=\s*['"]?(\w*)/i; if($align=~/^middle$/i) {$al=1}; if($align=~/^top$/i) {$al=2}; if($imgcmd eq "overlay") { $al=4; $xoff=0; $yoff=0; if($img=~/\s*x\s*=\s*['"]?(\d+)/i) {$xoff=$1}; if($img=~/\s*y\s*=\s*['"]?(\d+)/i) {$yoff=$1}; $off="$xoff $yoff "; } $url=""; if($img=~/\s(src|data)\s*=\s*($S)/i) {($url)=$+=~/([^ \n]*)/}; &dbg("Image: $url\n") if($opt_d && $url); $URL=$url; unless($url=~m|://|) { $url=~s/^file://; if($url=~m|^/|) {$URL=$b1.$url} else {$URL=$b2.$url} } while($URL!~m|^\.\./| && $URL=~m|[^/]*/\.\./|) {$URL=$`.$'}; $URL=~s|/\./|/|g; $text=$src{$URL}?$cmd{$URL.$red.$grn.$blu}:$cmd{$URL}; if(!$text || $opt_U && $src{$URL} && !$cmd{$URL.$red.$grn.$blu}) { if(!$url || $failed{$url}) { &getalt; } else { &pictops; if($bm || $ps) { &dbg("Size: $xs*$ys\n") if($opt_d); $nimg++; push(@XS,$xs); push(@YS,$ys); if($bm) { $nm++; push(@DP,$dp); push(@BM,$bm); push(@WS,int(($xs-1)*$dp/8)+1); push(@FC,$fc); push(@IX,$nm); push(@IT,0); } if($ps) { $nps--; push(@IX,$nps); push(@IT,1); $nli=30000; $n=1; $npr=$ps=~s|(.*\n){$nli}|sprintf("$&} D\n/P$nimg\_%d {",$n++)|eg; if($npr) { $proc=" ("; for $i (0..$npr) { $proc.="P$nimg\_$i "; } $proc.=")"; $pv.="/P$nimg\_0 {$ps} D\n"; $eps{"P$nimg\_0"}=$ps; } else { $proc=" (P$nimg)"; $pv.="/P$nimg {$ps} D\n"; $eps{"P$nimg"}=$ps; } } $text="$proc $nimg IM("; $cmd{$URL}=$text if(!$cmd{$URL}); $cmd{$URL.$red.$grn.$blu}=$text if($src{$URL}); $proc=""; $end=$' if($imgcmd eq "object" && $end=~m|</object>|i); } else { &getalt; $failed{"$url"}=1; } } } elsif($imgcmd eq "object" && $end=~m|</object>|i) { $end=$'; } } if($cmd{$URL}) { $text=")".$off.$al.$text; if($imgcmd eq "fig") { $end=~m|</fig>|i; $fig=$`; $end=$'; $over=""; while($fig=~/(<overlay$R)/ig) {$over.=$1}; ($dum,$cap)=$fig=~m|<caption$R([\w\W]*)</caption>|i; ($dum,$cred)=$fig=~m|<credit$R([\w\W]*)</credit>|i; $text=")BN($text$over)BN($cap)BN($cred)BN("; } } } $_=$beg.$text.$end; } s|<[hH][rR]$R|)2 1 1 HR(|g; $_[0]=$_; } sub getval{ local($val,$unit)=$_[0]=~/$V\s*(\w*)/g; $val*=$cm{$unit} if($_[1]==1 && defined $cm{$unit}); $val*=$pt{$unit} if($_[1]==2 && defined $pt{$unit}); $_[0]=$val; } sub getconf { local($_)=@_; while(/\@import\s+(([\w.\/-]+)|"([^"]*)"|'([^']*)')\s*;/) { if(open(SS,$+) && !$read{$+}) { $conf=<SS>; $_=$`.$conf.$'; print DBG "***** $+:\n$conf" if($opt_d); close SS; $read{$+}=1; } else { &dbg($read{$+}?"Infinite \@import loop: $+\n":"Error opening: $+\n"); $_=$`.$'; } } @block=(); while(&getblk($_)){}; } sub getblk { local($_)=@_; local ($beg,$match,$end,$blk,$key,$val,$id,$temp); while(/^\s*\/\*/) { /\*\/|$/; $_=$'; } return 0 if !/\S/; /[\w,:.@\s-]+\{/; $_=$'; ($id=$&)=~s/^\s*|\s*\{//g; $id=lc $id; push(@block,"\L$id"); if($#block==1) { $valid{$id}=1 if(!$user); if($id eq "color") {$id="colour"}; if(!$valid{$id}) { &dbg("Error in configuration file: unknown block name '$id'\n"); } } $blk=""; W:while(/\s*(\/\*|[\w][\w-]*\s*:|[\w,:.\s-]+\{|\})\s*/) { $blk.=$1 if($1 ne "/*"); $beg=$`; $match=$1; $end=$'; S:{ if($match=~/\{$/) { $temp=$match.$end; $blk.=&getblk($temp); $_=$temp; last S; } if($match=~/:$/) { ($key=$`)=~s/\s*$//; # $end=~/([\w.\$-]+|"[^"]*"|'[^']*')\s*;?/; $end=~/("[^"]*"|'[^']*'|.*?(?= *(\/\*|;|}|$)))/m; $blk.=$`.$&; $_=$'; ($val=$1)=~s/^["']|["']$//g; $val=~s/'|\\/\\$&/g; $typ=1; $typ=2 if($val=~/^$V(cm|mm|in|pt|pc|em)$/); $typ=3 if($val=~/^$V$/); $typ=4 if($val=~/^-?\d+$/); $typ=5 if($val eq "0" || $val eq "1"); if($block[0] eq '@html2ps') { if($#block==0) { if(!$user) { $valid{$key}=1; $type{$key}=$typ if(!defined $type{$key}); } if($valid{$key}) { if($typ>=$type{$key}) { $key=~s/-/_/g; eval "\$$key='$val'" if($user || $val ne ''); # print DBG "\$$key='$val'\n" if($opt_d && $user); } elsif($user) { &dbg("Error in configuration file: bad value for $key: $val\n"); } } else { &dbg("Error in configuration file: unknown key '$key'\n"); } } if($#block==1) { if($id eq "option" && $optalias{$key}) {$key=$optalias{$key}}; if(!$user) { $valid{"$id,$key"}=1; $type{"$id,$key"}=$typ if(!defined $type{"$id,$key"}); } if($valid{"$id,$key"} || $extend{$id}) { if($typ>=$type{"$id,$key"} || $id eq "colour") { eval "\$$id\{'$key'}='$val'" if($user || $val ne ''); # print DBG "\$$id\{'$key'}='$val'\n" if($opt_d && $user); } elsif($user) { &dbg("Error in configuration file: bad value for $key: $val\n"); } } else { &dbg("Error in block '$id' in configuration file:" ." unknown key '$key'\n"); } } if($#block>1) { $temp="$block[$#block-1]_$key"; $valid{$temp}=1 if(!$user); $parblk=$block[$#block-1]; if($valid{$temp}) { eval "\$$parblk\_$key\{'$id'}='$val'"; # print DBG "\$$parblk\_$key\{'$id'}='$val'\n" if($opt_d && $user); } elsif($valid{$parblk}) { &dbg("Error in block '$parblk' in configuration file:" ." unknown key '$key'\n"); } } } else { for $i (split(',\s*',$id)) { $i=~s/@/AT_/; $i=~s/\./_/; $i=~s/ *:/__/; eval "\$$i\{'\L$key'}='\L$val'"; # print DBG "\$$i\{'\L$key'}='\L$val'\n" if($opt_d && $user); } } last S; } if($match eq "/*") { /\*\/|$/; $_=$'; last S; } last W; } } pop(@block); $_[0]=$end; $blk; } sub prompt { local($/)="\n"; &dbg($_[0]); chop($_[1]=<STDIN>); } sub dbg { print STDERR $_[0]; print DBG $_[0]; } sub hb { local($_)=@_; local($head,$body,$beg,$end,$match,$tag); #If neither </HEAD> nor <BODY> can be found, find the separation point (messy). if(!/<(?:body|\/head>\s*)/i || $`=~/<plaintext|<xmp|<listing|<!--/i) { $head=""; $int=""; S1: while(/<(\/?\w+|!--|!|\?)/) { S2:{ $beg=$`; $end=$'; $match=$&; $tag=$1; if($tag eq "!--") { $int.=$`; &getcom; $int.=$com; $_=$rest; last S2; } if($tag=~/[!?]/) { $end=~/>/; $int.="$beg$match$`>"; $_=$'; last S2; } $tag=~s|/||; last S1 if(!$head{"\L$tag"}); $end=~/$R/; $head.=$int.$beg.$match.$&; $int=""; $_=$'; } } $body=$int.$_; } else { $head= $`; $body=(lc $& eq '<body' && $&).$'; } $_[0]=$body; $_[1]=$head; } sub open { if($_[0]=~m|://|) { &geturl($_[0],$_[1]); } elsif(open(FILE,$_[0])) { $_[1]=<FILE>; close FILE; } else { 0; } } sub pagedef { for $margin ('left','right','top','bottom') { ($m)=$margin=~/(.)/; if(defined $margin{$margin}) { &dbg("'margin { margin-$margin:... }' is obsolete, use '\@page'\n"); $AT_page{"margin-$margin"}=$margin{$margin} if(!defined $AT_page{"margin-$margin"}); } for $page ('left','right') { ($p)=$page=~/(.)/; eval "\$m$m$p=\$AT_page\{'margin'} if(defined \$AT_page\{'margin'})"; eval "\$m$m$p=\$AT_page\{'margin-$margin'} if(defined \$AT_page\{'margin-$margin'})"; eval "\$m$m$p=\$AT_page__$page\{'margin'} if(defined \$AT_page__$page\{'margin'})"; eval "\$m$m$p=\$AT_page__$page\{'margin-$margin'} if(defined \$AT_page__$page\{'margin-$margin'})"; } } } sub pmtoraw { @pars=(); ($temp)=@_; for $i (0..3) { 1 while ($temp=~s/^\s*#.*//); next if($pars[0] eq 'P1' && $i == 3); $temp=~s/\s*(\S+)\s*//; $pars[$i]=$1; } $temp=~s/#.*//g; $pars[0]=~s/\d/$&+3/e; $_[0]="$pars[0]\n$pars[1] $pars[2]\n"; if($pars[0] eq 'P4') { $temp=~s/\s//g; $_[0].=pack("B*",$temp); } else { $_[0].="255\n"; while ($temp=~/\d+/g) { $_[0].=pack("C",int(255*$&/$pars[3]+.5)); } } }