#!/usr/bin/perl -s -I . use mp; use XML::DT; our $individuo; my %htits = ( hv => "História de vida", infancia => "Infância", familia => "Família", casa => "Casa", lazer => "Lazer", quotidiano => "Quotidiano", pessoas => "Pessoas", costumes => "Costumes", filosofiadevida => "Filosofia de Vida", casamento => "Casamento", namoro => "Namoro", identificacao => "Identificação", educacao => "Educação", oficio => "Ofício", religiao => "Religião", pprofissional => "Percurso Profissional", percursoprofissional => "Percurso Profissional", ascendencia => "Ascendência", sonhos => "Sonhos", descendencia => "Descendência", antepassados => "Antepassados"); $individuo = shift; my $f2 = "$ARGV[0].pdf"; $f = "_hv_$$"; hv2latex( {output => $f, tit => $individuo}, @ARGV); system ("psmallbook -ag -o=$f2 $f.tex "); $remove = "_hv_$$.*"; system( "rm $remove" ) unless $dontrm; sub hv2latex{ my ($opt,@h)=@_; my %opt = ( size => "agbook", tit => "Histórias de vida", autor => "Museu da Pessoa", compact => "normal", tipo => "article", projecto => "", %$opt ); my $f= $opt{output} || $h[0]; $f =~ s/\.xml$/.tex/ or $f .= '.tex'; my ($dirhist, $history); my %handler=( '-outputenc'=> 'ISO-8859-1', '-inputenc'=> 'ISO-8859-1', '-default' => sub{ print STDERR "UNKNOWN TAG: $q\n"; $c}, '-pcdata' => sub{$c =~ s/â\x80¦/.../g;$c =~ s/\&/\\&/g; $c }, 'resposta' => sub{"\n\n \\noindent $c\n\n"}, 'pergunta' => sub{"\\mbox{}\\\\[-3mm] {\\bf $c}\n\n"}, 'audio' => sub{"\\marginpar{{\\scriptsize $v{t1}}}"}, 'data' => sub{$data="$c";""}, 'hh' => sub{"{\\small \\textbf{História da história} - $c } \n\n"}, 'ref' => sub{"\\textbf{$c}\\index{$v{tipo} - $c}\n"}, 'rel' => sub{"\n\n\\noindent {\\small $c}\n"}, 'biografia'=> sub{push(@destaque,$c); ""}, 'meta' => sub{ $meta = ((@meta) ? "\n\n" . join('\\\\',@meta)."\n\n" :""). $c; ""; }, 'p' => sub{"\n\n$c\n\n"}, 'br' => sub{"\n\n"}, 'h' => sub{ if(inctxt("mp")){ $titulogeral= $titulo = $v{tit}; $titulo .= " - $v{_escritor}" if $v{_escritor}; mkchap($opt{compact});} else{ my $tipo=$v{tipo} || $v{t}; my $tt = $v{tit}; $tt =~ s/"(.*?)"/\\emph{$1}/g; $tt =~ s/'(.*?)'/\\emph{$1}/g; (_geracao() == 2 ? "\\subsection{" : "\\subsubsection{") . ($v{tit} ?"$tt}\n{\\scriptsize $v{data} $v{onde} $v{tipo}}\n\n" : ucfirst($tipo) . "}\n{\\scriptsize $v{data} $v{onde}}\n\n"). $c}}, 'projecto' => sub{$proj=$c;push(@meta, "\\textbf{$c}"); "" }, 'nascimento' => sub{push(@meta, "\\textbf{Nascido em} $c $v{onde} $v{data}"); "" }, 'evento' => sub{ "\\subsection{$v{tit} ($v{data})}\n $c"}, 'versao' => sub{"\n\n\\noindent $c\n\n"}, 'versos' => sub{$c =~ s/\n/\\\\/g; "{\\begin{verse}$c\\end{verse}}\n"}, 'destaque' => sub{push(@destaque,"...$c...") unless $opt{nodest}; ($v{tipo})? "" : $c}, 'foto' => sub{ my $foto; if(-e "$dirhist/fotos/__$v{href}.eps") {$foto = "$dirhist/fotos/__$v{href}.eps";} elsif(-e "$v{href}.eps"){$foto = "$v{href}.eps";} elsif(-e "fotos/$v{href}.eps"){$foto = "fotos/$v{href}.eps";} elsif(-e "$v{href}.jpg"){system("jpeg2ps $v{href}.jpg > $v{href}.eps"); $foto = "$v{href}.eps";} else {$foto = "NAO ENTCONTREI $dirhist/fotos/\\_\\_$v{href}.eps"} if(defined $v{scale}){ $v{scale} /= 100 if $v{scale} > 2 ; "\n\n\\img{$foto}{$v{scale}}\n\n$c\n\n", } else { "\n\n\\bigimg{$foto}\n\n$c\n\n"}}, 'profissao'=> sub{$pro="$c";""}, 'autor' => sub{ $v{tipo}="$v{role}$v{papel}$v{tipo}"; delete $v{role}; delete $v{papel}; if ($v{tipo} eq "vida" || $v{tipo} eq "vida de" || $v{role} eq "vida de" || $v{tipo} eq "depoente" || $v{tipo} eq "Depoente" || $v{tipo} eq "vida" ) {$titulogeral= $titulo=$c;} $dtatributes[_pai($hist)]{_escritor}=$c if $v{tipo} eq "escritor"; $v{tipo}="Escrito por" if $v{tipo} eq "escritor"; push(@meta,"\\textbf{$v{tipo}} - $c");""}, 'hv' => sub{ mkchap($opt{compact})} , 'mp' => sub{$c}, 'casamento' => sub{"\\subsection{$htits{$q}} $c";}, 'identificacao' => sub{"\\subsection{$htits{$q}} $c";}, 'antepassados' => sub{"\\subsection{$htits{$q}} $c";}, 'quotidiano' => sub{"\\subsection{$htits{$q}} $c";}, 'ascendencia' => sub{"\\subsection{$htits{$q}} $c";}, 'descendencia' => sub{"\\subsection{$htits{$q}} $c";}, 'oficio' => sub{"\\subsection{$htits{$q}} $c";}, 'educacao' => sub{"\\subsection{$htits{$q}} $c";}, 'namoro' => sub{"\\subsection{$htits{$q}} $c";}, 'infancia' => sub{"\\subsection{$htits{$q}} $c";}, 'sonhos' => sub{"\\subsection{$htits{$q}} $c";}, 'casa' => sub{"\\subsection{$htits{$q}} $c";}, 'lazer' => sub{"\\subsection{$htits{$q}} $c";}, 'pessoas' => sub{"\\subsection{$htits{$q}} $c";}, 'religiao' => sub{"\\subsection{$htits{$q}} $c";}, 'familia' => sub{"\\subsection{$htits{$q}} $c";}, 'pprofissional' => sub{"\\subsection{$htits{$q}} $c";}, 'filosofiavida' => sub{"\\subsection{$htits{$q}} $c";}, 'costumes' => sub{"\\subsection{$htits{$q}} $c";}, 'percursoprofissional' => sub{"\\subsection{$htits{$q}} $c";}, 'episodio' => sub{ $titulo = normaliza($v{titulo} || "Episódio"); "\\subsection{$titulo} $c"; }, '-end' => sub{ $c } ); if($opt{justsection}){ unless ( ($dirhist = $h[0]) =~ s#(.*)/(.*)#$1# ) { $dirhist=".";} my $text = dt($h[0],%handler); return($text) } elsif($opt{single}) { open(F,">$f") or die; unless ( ($dirhist = $h[0]) =~ s#(.*)/(.*)#$1# ) { $dirhist=".";} my $text = "\\newpage\n". dt($h[0],%handler); print F textofinal($titulogeral, $opt{autor}, $opt{size}, $proj||$opt{projecto}, $opt{pre}, $opt{tipo} ); print F $text; print F "\\newpage \\mbox{}\\vfill $opt{end} " if defined $opt{end}; print F "\n \\end{document}\n"; close F; } else{ open(F,">$f") or die; print F (textofinal($opt{tit}, $opt{autor}, $opt{size}, $opt{projecto}, $opt{pre}, $opt{tipo}, )); for(@h){ my $historia = $_; $historia =~ s/\.xml$//; unless ( ($dirhist = $historia) =~ s#(.*)/(.*)#$1# ) { $dirhist=".";} print F "\\newpage\n\\section{$individuo}\n", ((dt($_,%handler))); } print F "\\newpage \\mbox{}\\vfill $opt{end} " if defined $opt{end}; print F "\n \\end{document}\n"; close F; } } sub textofinal { my $t = shift; my $a = shift; my $size= shift; my $projecto = shift; my $pre = shift; my $page = shift; my $pts = (($size =~ s/s$//)? ",10pt":""); $projecto = "\\\\\\begin{large}$projecto\\end{large}" if $projecto; my $aftertitle = $page eq "article" ? '\vfill':'\newpage'; my $docclass = $page eq "book" ? 'book':'article'; my $textofinal = <<"."; \\documentclass[twoside,portuges$pts]{$docclass} \\usepackage[portuges]{babel} \\usepackage{$size} \\usepackage{graphicx} \\usepackage[latin1]{inputenc} \\usepackage{t1enc} \\usepackage{fancyhdr} \\pagestyle{fancy} %\\renewcommand{\\sectionmark}[1]{\\markright{ \\thesection.\\ #1}} %\\fancyhead[RO]{\\nouppercase{\\rightmark}} %\\fancyhead[LE]{\\nouppercase{\\leftmark}} %\\fancyhead[RE,LO]{} \\fancyfoot{} %\\renewcommand{\\chaptermark}[1]{\\markboth{#1}{}} %\\renewcommand{\\sectionmark}[1]{\\markright{\\thesection\\ #1}} \\renewcommand{\\sectionmark}[1]{\\markboth{\\thesection}{\\thesection}} \\lhead[\\fancyplain{}{\\bfseries\\thepage}]{\\fancyplain{}{\\bfseries\\rightmark}} \\rhead[\\fancyplain{}{\\bfseries\\rightmark}]{\\fancyplain{}{\\bfseries\\thepage}} \\makeindex \\begin{document} \\title{$t} \\author{$a$projecto} \\maketitle $aftertitle {\\small \\tableofcontents } . $textofinal . ($pre? "\\newpage \\mbox{} \\vfill { \\it $pre} \\vfill \\mbox{} " : "") } sub normaliza { my $f = shift; for ($f) { s/"//g; } return $f; } sub _geracao{ scalar grep {/^($hist)$/} @dtcontext ; }