#!/usr/bin/perl -s =head1 gramatica PROJ -> PROJ* HV* synopsis? ALBUM? HV -> mp* ALBUM? biografia? som? ALBUM -> fotos? img* dir.html : img -> JPG | GIF JPG: Tn.jpg Sm.jpg .eps mp: ?id !{id}.bi.html !{id}.monobloco.html !cat =cut use mp; use XML::DT; use agod; $ENV{MP_ROOT}="/home/mp/new_site/MuseuDaPessoa"; $http_root = '/mpessoa/MuseuDaPessoa/'; $treedir = shift; if ($meta) { $mpdir = $meta; } elsif ($nometa) { $mpdir = $nometa; } else { $mpdir = $ENV{MP_ROOT} || '/home/jj/MuseuPessoa/MP'; } $MFI="MP_file_index"; %G= ( PROJ => { RHS =>{ PROJ => "*", HV => "*", ALBUM => "?", sinopse => "?", }, "index.html" => sub{ my ($des,$ori,%rhs)=@_; open(F,">$des") or die("can't create $des"); # Incluir sinopses if ($rhs{sinopse}) { for (@{$rhs{sinopse}}) { my $a = att($_,".html"); open O, "<$a" or die("Cannot open file $a: $!"); while($t = ) { print F $t; } close O; } } else { my $attr = att("$ori/sinopse.xml",".nome"); open NOME, ">$attr"; $ori =~ m{/([^/]+)/?$}; print NOME $1; close NOME; print F "

$1

"; } print F "
"; # Imprimir subprojectos, se os houver if (@{$rhs{PROJ}}) { print F "

Subprojectos

"; } # Imprimir historias, se as houver if (@{$rhs{HV}}) { print F "

Histórias

"; } close(F); }, "cat" => sub{ my ($des,$ori,%rhs)=@_; my @l = (@{$rhs{PROJ}},@{$rhs{HV}}); open(F,">$des") or die("can't create $des"); for (@l) { my $a = att($_,"cat"); print F `cat $a`; } print F "
"; close(F); } }, HV => { RHS =>{ mp => "*", biografia => "?", ALBUM => "?", SOM => "?", }, 'biog' => sub{ my ($des, $ori, %rhs) = @_; my $b = undef; if ($rhs{mp}) { for (@{$rhs{mp}}) { dt($_,('-inputenc'=>'ISO-8859-1', '-outputenc'=>'ISO-8859-1', 'biografia' => sub{$b = $c;}, )); last if $b; } } if ($b) { open B, ">$des"; print B $b; close B; } }, "nome" => sub{ my ($des,$ori,%rhs)=@_; my $att = att($ori,"cat"); my $dep = `cat $att|grep -i depoente`; $dep =~ />\s*([^<]+)\s* ([^<]+)([^<]+)$des" or die("..."); print F "$dep ",(($data!~/^\s*$/)?"- $data":""),(($profissao!~/^\s*$/)?"- $profissao":""); close F; }, "cat" => sub{ my ($des,$ori,%rhs)=@_; my @l = (@{$rhs{mp}}); open(F,">$des") or die("can't create $des"); for (@l) { my $a = att($_,"!cat"); print F `cat $a`; } close(F); }, "index.html" => sub{ my ($des,$ori,%rhs)=@_; open(F,">$des") or die("can't create $des"); print F "

Entrevistas

\n"; for (sort @{$rhs{mp}}) { my $id = $mpindex{$_}{id}; my $a = attr($_,"!$id.bi.html"); print F "
  • $_\n"; } for (@{$rhs{ALBUM}}) { my $a = attr2($_,"dir.html",$mpdir,$http_root); print F "

  • $_"; } close(F); } }, ALBUM => { RHS => { GIF => '*', JPG => '*', fotos => '?' }, 'dir.html' => sub { my ($des,$ori,%rhs)=@_; my @l = (@{$rhs{GIF}},@{$rhs{JPG}}); open(F,">$des") or die("can't create $des"); for (@l) { printf F "\n", attr($_,"Sm.jpg"), attr($_,"Tn.jpg"); } close F; } }, mp => { '=i' => sub{ my($b)=@_; $mpindex{$b}{id}; }, '!cat' => sub { my ($destino,$origem)=@_; open(F,">$destino") or die("cant create $destino"); print F mp::hv2xmlcatalog($origem,$ts{i}); close F; }, '!{i}.bi.html' => sub { my ($a,$b)=@_; my $d; if ($a =~ m{(.*)/(.*?)$}) { $d=$1; } mp::hv2html($b,$d,$ts{i}); }, '!{i}.ps' => sub { my ($a,$b)=@_; system("hv2smallbook -q -nodest -single '$b'; mv '$b.ps' '$a'") } }, biografia => {}, fotos => { 'album.html' => sub { my ($a,$b)=@_; open(F,">$a") or die("cant create $a"); print F mp::fotos2html($b,$a); close F; } }, sinopse => { '.html' => sub { my ($a,$b) = @_; mp::sinopsis($b,$a); }, '.nome' => sub { my ($dest,$source) = @_; open D, ">$dest" or die(""); print D mp::sinpsis_project($source); close D; }, }, JPG => { '.eps' => sub{ my($a,$b) = @_; system("jjpeg2ps '$b' '$a' "); }, 'Sm.jpg' => sub{ my($a,$b) = @_; system("convert -geometry '640x640>' '$b' '$a'"); }, 'Tn.jpg' => sub{ my($a,$b) = @_; system("convert -geometry '150x150>' '$b' '$a'"); }, }, GIF => { '.eps' => sub{ my($a,$b) = @_; system("convert '$b' '$a'"); }, 'Sm.jpg' => sub{ my($a,$b) = @_; system("convert -geometry '640x640>' '$b' '$a'"); }, 'Tn.jpg' => sub{ my($a,$b) = @_; system("convert -geometry '150x150>' '$b' '$a'"); }, }, GESTAO =>{}, MPFileIndex =>{}, 'error' => sub { my ($t,$f)=@_; print "\n\nERROR: unknown type $t ($f)\n"; }, ); agvalidate($treedir, \%G, \&typeof) if $val; agdec($treedir, \%G, \&typeof) unless $val; # agdec: RootDir: Str x # Gram: (STR -> (STR -> func)) x # typeof # Fullname: Str ---> Tipo: Str sub typeof{ my $f=shift; my $tipo="UNDEF"; my $raz=""; if (-d $f) { my @hv = ((<$f/[Ee]ntrevista*>) , (<$f/[Dd]epoim*>), (<$f/[Hh]istori*>)); my @pro = ((<$f/Projec*>),(<$f/*/entrevista*>)); if (-e "$f/META" or -e "$f/_META") { $tipo = `grep 'tipo' '$f'/*META`; if ($tipo =~ m{(.*?)} ) { $tipo=$1; $raz="meta"; } else { $tipo="META WITH NO TYPE??"; } } elsif (@hv) { $tipo = 'HV'; $raz=join(":",@hv); } elsif (@pro) { $tipo = "PROJ"; $raz=join(":",@pro); } elsif ($f =~ /[Pp]roject\w*$/ ) { $tipo = 'PROJ';$raz="pelo nome"; } elsif ($f =~ /\/[fF]oto\w*$/ ) { $tipo = 'ALBUM';$raz="pelo nome"; } elsif ($f =~ /\/contact\w*$/ ) { $tipo = 'GESTAO';$raz="pelo nome"; } else { $tipo = 'DIR??'; } # print("\n$f\n $tipo (porque... $raz)\n"); } else { if ($f =~ /jpg$/) { $tipo="JPG"; } elsif ($f =~ /gif$/) { $tipo="GIF"; } elsif ($f =~ /html?$/) { $tipo="HTML"; } elsif ($f =~ /mp3$/) { $tipo="SOM"; } elsif ($f =~ /doc$/) { $tipo="WORD"; } elsif ($f =~ /$MFI$/) { $tipo="MPFileIndex"; } elsif ($f =~ /xml$/) { $tipo=`grep '<[a-zA-Z]' '$f' | head -1 `; if ($tipo =~m{^.*?<(\w+)} ) { $tipo = $1; } else { $tipo="????"; } } elsif ($f =~ /META$/) { $tipo="META"; } else { $tipo="FILE??"; } } $tipo; } sub index_import_init{ my $path=shift; my %ind=(); if (-f $path) { open(F, $path ); while () { if (/(.+):(.+):(.*):(.*)/) { $ind{$2}{id} = $1; $ind{$2}{tipo} = $3; $ind{$2}{perm} = $4; } elsif (/(.+):(.+):(.+)/) { $ind{$2}{$3} = $1; } } close F; } else { $ind{__LAST__}={}; } %ind; } __END__