#!/usr/bin/perl # todo # titles in cftp and explaning the ': in ibidem # this is the time stamp for the update $updata="Last update: ".`date --utc --rfc-822`; # this is the version string for the packaged version $pakvers=`date --utc +%Y.%m.%d`; chomp $updata; chomp $pakvers; # format for tidy # this is a fully indented and neat format $format='-i -w 9999'; # this is a compact format - not good for Netscape #$format='-o -w 9999'; # cleanup---------------------------------------------------------------------------------------------- # cleaning up garbage files `rm -f *~ index.html f-*.html framed.html table-index.html *.tgz *.bak tcpip-slides/*~`; # backing up files `cp -R * ../backups/miscnotes`; # -d parameter means we only want to clean files exit if($ARGV[0] eq '-d'); # tidying all files------------------------------------------------------------------------------------ print "Tidying phase 1\n"; `tidy -m $format *.html *.htm &> /dev/null`; # -t parameter means basic clean up and reformatting exit if($ARGV[0] eq '-t'); # ChangeLog processing # first we clean up ownership entries open FIN,"/tmp/ChangeLog"; while() { chomp; if(/^(\d\d\d\d-\d\d-\d\d)\s+<.+>$/) { $_=$1; } print FOUT "$_\n"; } close FIN; close FOUT; `mv /tmp/ChangeLog ChangeLog`; $clue="datechanges\n"; $ldate=""; open FIN,") { # we must select: date lines, entry start lines, entry continuation lines, formatting lines next if(/^\s*---/); if(/^(\d\d\d\d-\d\d-\d\d)/) { if($1 ne $ldate) { $cl.=$clue; $cl.="\n$1
    "; $clue="\n
\n"; $ldate=$1; next; } } if(/^\s+\*(.*)/) { $cl.="\n
  • $1"; next; } $cl.=" $1" if(/^\s+([^*].*)/); } $cl.=$clue; $cl=qq(\n\n$cl
    \n\n); close FIN; # intro.html processing-------------------------------------------------------------------------------- # fill in the version numbers in intro.html # update the changelog open FIN,"intro.html"; open FOUT,">/tmp/intro.html"; $incl=0; while() { if(//) { $incl=0; print FOUT $cl; next; } elsif(//) { $incl=1; next; } elsif($incl) { print "Skipped: $_"; next; } elsif(/(.*?)(.*?)(.*)/) { $p1=$1; $comm=$4; $p3=$3; $comm =~ s/=/-/g; $comm=`$comm`; chomp($comm); print "Match!\n"; $_="$p1$comm$p3"; } elsif(/note="archive"/) { s!.*?!LNB-$pakvers.tgz!; } elsif(/note="bigarchive"/) { s!.*?!LNB-big-$pakvers.tgz!; } print FOUT; } close(FIN); close(FOUT); `mv /tmp/intro.html intro.html`; # find the main files: the ones without dashes in the name and ending in html-------------------------- @mainfiles=(grep(!/-/,`ls *.html`)); chomp @mainfiles; $mainfiles=join " ",@mainfiles; # collect menu info ----------------------------------------------------------------------------------- @a=`grep '"menuin"' $mainfiles`; foreach $v (@a) { # extracting filename and title ($file,$title)= $v =~ /(.*?):(.*)/; # cleaning up title $title =~ s/<.*?>//g; $title =~ s/^\s+//g; $title =~ s/\s+$//g; $ref= $title; $ref =~ tr/A-Z/a-z/; $ref =~ tr/A-Za-z0-9/_/cs; # each record in @menu contains the title, the filename and the reference used as destination push @menu,$title.'%'.$file.'%'.$ref; # this accumulates the titles to use as keyword in the meta tags $keywords{$_}=1 foreach(split " ",$title); # the %titulos hash contains the titles keyed by the file names $titulos{$file}.=" / $title"; } # we sort the menu by title, case insensitive @menu=sort {uc($a) cmp uc($b)} @menu; foreach(keys %keywords) { push @remove,$_ if(length($_)<3); push @remove,$_ if(/^&/); } delete $keywords{$_} foreach(@remove); $keywords=qq(\n\n\n); # now we process each file $tabix="tab000"; foreach $file (@mainfiles) { chomp $file; print "Processing [$file]\n"; open FIN,"<$file"; open FOUT,">$file.tmp"; $inhead=0; while() { $inhead=1 if(m///g; } s{\s+$}{}; s{]+? note="tabix">}{}g; if(/]*?summary="(.*?)"[^>]*>/) { $tabix++; if(length($1)==0) { print "Table index problem in file $file\n"; exit 100; } print FOUT ""; push @tabs,$1."!".$file."#".$tabix; print FOUT; } elsif(/note="indexin"/) { # this is where we put the menu, the whole line is replaced $ins=''; foreach $r (@menu) { ($title,$page,$ref)=split /%/,$r; if($page eq $file) { $ins.="$title "; } else { $ins.="$title "; } } # table index entry $ins.="Index "; # slides $ins.="TCP/IP slides "; $ins.="\n"; print FOUT $ins; } elsif( m{} ) { # replacing the old title print FOUT "<title>Linux notebook$titulos{$file}\n"; } elsif( m/class="time"/ ) { # updating the time stamp s!class="time">.*?$updata(.*?)//g; $r =~ s/^\s+//g; $r =~ s/\s+$//g; $r=(grep(/^$r%/,@menu))[0]; ($title,$page,$ref)=split /%/,$r; $curtitle=$title; s{class="menuin">.*?$title/) { ($lk,$top)= m{(.*)}; push @tops,"$title§$top§$file#$lk"; print FOUT; } elsif (m//) { ($src,$alt,$link)= m{(.+?)}; push @imgs,"$title§$alt§$file#$link"; print FOUT; } else { chomp; s/\s+$//; print FOUT "$_\n"; } } close FIN; close FOUT; `mv $file.tmp $file`; } # creating table index foreach (@tabs) { ($area,$title,$file)=split /!/; $tu=$title; $tu =~ s/\(|\)|\:|\.//g; $taba{$area}.="$tu§
    $title
    §"; $taci{$area}++; } foreach (@tops) { ($area,$title,$file)=split /§/; $tu=$title; $tu =~ s/<.+?>//g; $tu =~ s/\(|\)|\:|\.//g; $topba{$area}.="$tu§
    $title
    §"; $topci{$area}++; } foreach (@imgs) { ($area,$title,$file)=split /§/; $tu=$title; $tu =~ s/<.+?>//g; $tu =~ s/\(|\)|\:|\.//g; $tipba{$area}.="$tu§
    $title
    §"; $tipci{$area}++; } open FOUT,">table-index.html"; print FOUT qq(Linux notebook/Index$keywords
    ); foreach $r (@menu) { ($title,$page,$ref)=split /%/,$r; print FOUT "$title "; } print FOUT '
    '; # ------------------ the index of topics ---------------------- print FOUT '

    Index of topics

    '; # calculating total number of lines $nlin=0; $nlin+=$topci{$_}+1 foreach (keys(%topci)); $lic=0; print FOUT "
    "; foreach (sort {uc($a) cmp uc($b)} keys(%topba)) { %roro=split /§/,$topba{$_}; $topba{$_}=(); foreach $uiui (sort {uc($a) cmp uc($b)} keys %roro) { $topba{$_}.=$roro{$uiui}; } print FOUT "
    $_
    $topba{$_}"; $lic+=$topci{$_}+1; if($lic>$nlin/3) { print FOUT "
    "; $lic=0; } } print FOUT "
    "; # ------------------ the index of tables ---------------------- print FOUT '

    Index of tables

    '; # calculating total number of lines $nlin=0; $nlin+=$taci{$_}+1 foreach (keys(%taci)); $lic=0; print FOUT "
    "; foreach (sort {uc($a) cmp uc($b)} keys(%taba)) { %roro=split /§/,$taba{$_}; $taba{$_}=(); foreach $uiui (sort {uc($a) cmp uc($b)} keys %roro) { $taba{$_}.=$roro{$uiui}; } print FOUT "
    $_
    $taba{$_}"; $lic+=$taci{$_}+1; if($lic>$nlin/3) { print FOUT "
    "; $lic=0; } } print FOUT "
    "; # ------------------ the index of images -------------------- print FOUT '

    Index of images

    '; # calculating total number of lines $nlin=0; $nlin+=$tipci{$_}+1 foreach (keys(%tipci)); $lic=0; print FOUT "
    "; foreach (sort {uc($a) cmp uc($b)} keys(%tipba)) { %roro=split /§/,$tipba{$_}; $tipba{$_}=(); foreach $uiui (sort {uc($a) cmp uc($b)} keys %roro) { $tipba{$_}.=$roro{$uiui}; } print FOUT "
    $_
    $tipba{$_}"; $lic+=$tipci{$_}+1; if($lic>$nlin/3) { print FOUT "
    "; $lic=0; } } print FOUT "
    "; print FOUT ""; close FOUT; # cleaning up files print "Tidying phase 2\n"; `tidy -m -i -w 9999 *.html &> /dev/null`; # linking do index.html ($title,$page,$ref)=split /%/,$menu[0]; `ln -s intro.html index.html`; print "Packing\n"; $truque=time(); `mv tcpip-slides ../tcpip-slides.$truque`; `tar czvf LNB-$pakvers.tgz *`; `mv ../tcpip-slides.$truque tcpip-slides`; $archivesize=int((-s "LNB-$pakvers.tgz")/1024+0.5); `mv LNB-$pakvers.tgz ../LNB-$pakvers.tgz.$truque`; `tar czvf LNB-big-$pakvers.tgz *`; $bigarchivesize=int((-s "LNB-big-$pakvers.tgz")/1024+0.5); `mv ../LNB-$pakvers.tgz.$truque LNB-$pakvers.tgz`; # linking versioned archives `ln -s LNB-$pakvers.tgz LNB-current.tgz`; `ln -s LNB-big-$pakvers.tgz LNB-current-big.tgz`; # repatching intro with archive sizes open FIN,"intro.html"; open FOUT,">/tmp/intro.html"; while() { s[.*?][$archivesize kB]g; s[.*?][$bigarchivesize kB]g; print FOUT; } close FIN; close FOUT; `mv /tmp/intro.html intro.html`; if($ARGV[0] eq '-u') { print "Uploading...\n"; `scp LNB-big-$pakvers.tgz beer:/tmp`; print "Upload complete.\n"; }