]>
git.immae.eu Git - perso/Immae/Projets/Scripts/Public.git/blob - gen_html_documents
2 # The MIT License (MIT)
4 # Copyright (c) 2011-2015 Ismaël Bouya http://www.normalesup.org/~bouya/
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 sub parse_config_file
{
28 my ($config_line, $Name, $Value, $Config);
29 (my $File, $Config) = @_;
30 if (!open (CONFIG
, "$File")) {
31 print "ERROR: Config file not found : $File";
39 $config_line =~ s/^\s*//;
40 $config_line =~ s/\s*$//;
41 if ( ($config_line !~ /^#/) && ($config_line ne "") ){
43 $$Config{$Name} =~ s/\\$//;
44 $$Config{$Name} .= $config_line;
46 ($Name, $Value) = split (/\s*=\s*/, $config_line);
47 $Value =~ s/^~/$ENV{"HOME"}/;
48 $$Config{$Name} = $Value;
50 $multiline = ($$Config{$Name} =~ /\\$/);
57 &parse_config_file
($ENV{"HOME"}."/.gen_html_documents.rc", \
%Config);
59 my $entete = $Config{"entete"};
60 my $avant = $Config{"avant"};
61 my $milieu = $Config{"milieu"};
62 my $apres = $Config{"apres"};
63 my $html = $Config{"html"};
65 my @ignore = split (/\s*,\s*/, $Config{"ignore"});
66 my @ext = split (/\s*,\s*/, $Config{"ext"});
68 my $documents = $Config{"documents"};
69 my $droot = $Config{"dossier_web"};
71 $Config{"dossiers"} =~ s/^"//;
72 $Config{"dossiers"} =~ s/"$//;
73 my %dossiers = split (/"?\s*,\s*"?/, $Config{"dossiers"});
75 my ($dossier,$description);
79 while(($dossier,$description) = each(%dossiers)) {
80 opendir(DIR
, $documents.$dossier) || warn $documents.$dossier." coulnd't be opened\n";
81 my @content = grep {$_ !~ /^\.\.?$/} readdir(DIR
);
82 my @sorted = sort { lc($a) cmp lc($b) } @content;
85 print F
"<h3>".$description."</h3>\n";
87 foreach my $subpath (grep { -d
$documents.$dossier.'/'.$_} @sorted) {
88 subparse
($dossier,$subpath,4);
90 foreach my $file (grep { -f
$documents.$dossier.'/'.$_} @sorted) {
91 my($filename, $directories, $suffix) = fileparse
($file,qr/\.[^\.]*/);
92 next if(!in_array
(\
@ext,lc($suffix)));
94 print F
"<li><a href='".$droot.$dossier.'/'.$file."'>".$filename."</a></li>\n";
104 opendir(DIR
, $documents.$path."/".$dossier);
105 my @content = grep {$_ !~ /^\.\.?$/} readdir(DIR
);
106 my @sorted = sort { lc($a) cmp lc($b) } @content;
109 return if(in_array
(\
@ignore,$dossier));
110 my $dossierspace = $dossier;
111 $dossierspace =~ tr/_/ /;
112 print F
"<li>".$dossierspace."\n";
114 foreach my $subpath (grep { -d
$documents.$path."/".$dossier.'/'.$_} @sorted) {
115 subparse
($path."/".$dossier,$subpath,$rang+1);
117 foreach my $file (grep { -f
$documents.$path."/".$dossier.'/'.$_} @sorted) {
118 my($filename, $directories, $suffix) = fileparse
($file,qr/\.[^\.]*/);
119 next if(!in_array
(\
@ext,lc($suffix)));
120 $filename =~ tr/_/ /;
121 print F
"<li><a href='".$droot.$path.'/'.$dossier.'/'.$file."'>".$filename."</a></li>\n";
123 print F
"</ul></li>\n";
127 my ($arr,$search_for) = @_;
128 my %items = map {$_ => 1} @$arr; # create a hash out of the array values
129 return (exists($items{$search_for}))?1:0;
134 exec "cat $entete $avant $milieu $apres 1> $html" or die "$!\n";
135 exec "chmod -R go=rX,u=rwX $documents"