#!/local/bin/perl5 ############################################################################## # $Id: glossar.pl,v 1.1 2010/09/07 14:20:14 unrz59 Exp $ ############################################################################## # Glossar / Acronymanzeige # Anzeige von HTML-Acronym-Tags aus vorheriger Indizierung ueber search_acronyms.pl # Copyright (C) 2004 Wolfgang Wiese # # glossar.pl ist freie Software; Sie dürfen sie unter den Bedingungen der # GNU Lesser General Public License, wie von der Free Software Foundation # veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß # Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version. # # glossar.pl wird in der Hoffnung weiterverbreitet, daß sie nützlich # sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie # der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details # finden Sie in der GNU Lesser General Public License. # # Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit # dieser Bibliothek/diesem Programm erhalten haben; falls nicht, schreiben Sie # an die Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307, USA. # # Das Regionale Rechenzentrum Erlangen (http://www.rrze.uni-erlangen.de) # erhebt keinen urheberechtlichen Anspruch auf das von # Wolfgang Wiese # geschrieben Programm. ############################################################################## # Last Modified on: $Date: 2010/09/07 14:20:14 $ # By: $Author: unrz59 $ # Version: $Revision: 1.1 $ ############################################################################# use strict; use lib './'; my $GLOSSAR_FILE = "glossar.txt"; # In dieser Datei befindet sich die Glossardatei. Diese wird erstellt vom Skript # search_acronyms.pl welches per cron automatisch gestartet werden soll. my %glossar = LadeGlossar($GLOSSAR_FILE); my $ALPHALIST = 'aäbcdefghijklmnoöpqrstuüvwxyz0123456789'; my $ALPHALIST_OHNEZAHLEN = 'aäbcdefghijklmnoöpqrstuüvwxyz'; my $SHOWPAGES = 1; my $NACHOBENSTRING = "

\"nachNach oben

"; print "Status: 200\n"; print "Content-type: text/html\n\n"; my $output = ZeigeGlossar(\%glossar); print $output; exit; ############################################################################## # Subroutinen ############################################################################## sub ZeigeGlossar { my $hashref = shift; if (not $hashref) { return "Es konnten keine Einträge gefunden werden."; } my %hash = %{$hashref}; my $key; my $firstchar; my $zahlenfound; my %ahash; foreach $key (keys %hash) { $firstchar = substr($key,0,1); if ($firstchar =~ /^[0-9]/i) { $zahlenfound =1; } push(@{$ahash{$firstchar}}, "$key\t$hash{$key}{'acronym'}"); } if (not $zahlenfound) { $ALPHALIST = $ALPHALIST_OHNEZAHLEN; } my $len = length($ALPHALIST); my $this; my $pos; my $key; my $i; my $hthis; my $res; my $pagenavi; my $usetitle; my $l; my @liste; my ($lang,$title,$file,$seitentitel) ; while($pos < $len) { $this = substr($ALPHALIST,$pos,1); $hthis = uc($this); if ($ahash{$this}) { $pagenavi .= "\t
  • $hthis
  • \n"; $res .= "

    $hthis

    \n"; $res .= "\n"; $res .= $NACHOBENSTRING; } else { $pagenavi .= "\t
  • $hthis
  • \n"; } $pos++; } $pagenavi = "

     

    \n"; $res = "
    $res
    \n"; return " $pagenavi\n$res\n"; } ############################################################################## sub LadeGlossar { my $file = shift; if (not $file) { return; } my @inhalt = LoadFile($file); if (not @inhalt) { return; } my $i; my ($acronym,$title); my $num; my %result; my ($lang,$file,$seitentitel); my $acro; my $lastacro; my $l; my $found; my ($dlang,$dtitle,$dfile,$dseitentitel); for ($i=0; $i<=$#inhalt; $i++) { if ($inhalt[$i] =~ /^Glossar/i) { $inhalt[$i] =~ s/^Glossar\s+//gi; ($acronym, $title) = split(/\t/,$inhalt[$i],2); $acro = $acronym; $acronym =~ s/&/ und /gi; $acronym =~ s/ä/ä/gi; $acronym =~ s/ü/ü/gi; $acronym =~ s/ö/ö/gi; $acronym =~ s/ß/ss/gi; # $acronym =~ s/[^$ALPHALIST]+//gi; $acronym = lc($acronym); if (($lastacro) && ($acronym ne $lastacro)) { $result{$lastacro}{'num'} = $num-1; $lastacro = $acronym; } elsif (not $lastacro) { $lastacro = $acronym; } $result{$acronym}{'title'} = $title; $result{$acronym}{'acronym'} = $acro; $num =1; } elsif (($inhalt[$i] =~ /^\s*#/i) && ($acronym)) { $inhalt[$i] =~ s/^\s*#\t+//gi; $found =0; ($lang,$title,$file,$seitentitel) = split(/\t/,$inhalt[$i],4); for ($l=1; $l<=$num; $l++) { ($dlang,$dtitle,$dfile,$dseitentitel) = split(/\t/,$result{$acronym}{$l},4); if ($dfile eq $file) { $found =1; } } if (not $found) { $result{$acronym}{$num} = "$lang\t$title\t$file\t$seitentitel"; $result{$acronym}{'lang'} = $lang; $num++; } } } return %result; } ############################################################################## sub LoadFile { my $file = shift; if (not $file) { return; } my @res; open(f1,"<$file"); while() { chomp($_); push(@res, $_); } close f1; return @res; } ############################################################################## # EOF ##############################################################################