Source:Doc
Jump to navigation
Jump to search
Source code of the hooks script for making documentation during intallation. Store this code in $FAI/hooks/finish.DOC file.
#!/usr/bin/perl # BEGIN LICENCE BLOCK # # Copyright (C) 2004 Michal Svamberg <svamberg@civ.zcu.cz> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. # # END LICENCE BLOCK # Version: 0.0.2 # Changes to 0.0.2 # - add support for postprocessing skripts # (you can run $docdir/P[0-9][0-9]* scripts now) # use strict; # --- START: config options --- my $docdir="$ENV{FAI}/doc"; my @classes= split /\n/, $ENV{classes}; my $tmpfile="/tmp/doc.$$"; my $outfile="$ENV{LOGDIR}/doc.tex"; # file in logdir is stored as log automaticly my $comment_start = '%'; # begin string of comment: <!--, #, //, /*, \begin{comment}, ... my $comment_end = ''; # end string of comment: -->, */, \end{comment}, ... my $debug = 0; # --- END: config options --- # ---------------------------------------------------- create_doc_from_file --- sub create_doc_from_file { my $file = shift; my $text; print "add file: $file\n" if $debug; if (-x $file ) { $text .= "$comment_start ### BEGIN: $file (exec) ### $comment_end\n"; $text .= `$file`; $text .= "$comment_start ### END: $file (exec) ### $comment_end\n"; } else { $text .= "$comment_start ### BEGIN: $file (read) ### $comment_end\n"; $text .= `cat $file`; $text .= "$comment_start ### END: $file (read) ### $comment_end\n"; } return $text; } # ---------------------------------------------------- create_doc_for_class --- sub create_doc_by_class { my $class = shift; my $dir = shift || $docdir; my $text; if (-e "$dir/$class") { if (-d "$dir/$class") { # create doc through directory foreach (<$dir/$class/*>) { $text .= create_doc_from_file($_); } } else { # one file in root of doc directory $text .= create_doc_from_file("$dir/$class"); } } return $text; } # -------------------------------------------------------- create_doc_in_dir --- sub create_doc_in_dir { my $dir = shift; my $text; print ">>> create_doc_in_dir: $dir\n" if $debug; # init dir foreach (<$dir/S[0-9][0-9]*>) { $text .= create_doc_from_file($_); } # through classes foreach (@classes) { $text .= create_doc_by_class($_, $dir); } # close documentation in dir foreach (<$dir/K[0-9][0-9]*>) { $text .= create_doc_from_file($_); } print "<<< create_doc_in_dir: $dir\n" if $debug; return $text; } # ============================================================================= my $doc_class; my $doc_script; open DOC, ">$tmpfile" or die "Cannot open tmp file '$tmpfile': $!"; # header of document and first documentations (S[0-9][0-9]* files) - header foreach (<$docdir/S[0-9][0-9]*>) { $doc_script = create_doc_from_file($_); print DOC $doc_script; } # documentation by sections foreach (<$docdir/[0-9][0-9]*>) { if (-d $_) { $doc_script = create_doc_in_dir($_); print DOC $doc_script; } } # documentations for classes foreach (@classes) { $doc_class = create_doc_by_class($_); print DOC $doc_class; } # last doc and foot of document (K[0-9][0-9]* files) - footer foreach (<$docdir/K[0-9][0-9]*>) { $doc_script = create_doc_from_file($_); print DOC $doc_script; } close DOC; `cp $tmpfile $outfile`; # Post production scripts my $file; foreach (<$docdir/P[0-9][0-9]*>) { $file = $_; if (-x $file ) { print "Run `$file` post production script.\n" if $debug; `$file`; } else { warn "Post production file '$file' must be a script with execute rights!"; } } exit 0;