Source:Doc: Difference between revisions

From FAIWiki
Jump to navigation Jump to search
(upload version 0.0.2)
 
m (add description of page)
Line 1: Line 1:
Source file of <tt>hooks</tt> for making documentation during intallation. You store this code to
<tt>$FAI/hooks/finish.DOC</tt> file.
<pre>
<pre>
#!/usr/bin/perl
#!/usr/bin/perl

Revision as of 01:42, 4 December 2005

Source file of hooks for making documentation during intallation. You store this code to $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 script with execute rights!";
        }
}

exit 0;