#!/usr/bin/perl # # sci2htm.pl reads a scilab function definition file (*.sci) and creates a # standard help file for the functions based on the initial comments # following the function header. # # Torbjørn Pettersen October 2003. (Torbjorn.Pettersen@broadpark.no) # $Id: sci2htm.pl,v 1.5 2003/11/02 08:46:09 top Exp $ # # 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 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); $mon=$mon+1;$year=$year+1900; unless (@ARGV[0]) { print "sci2htm.pl: Generates help files for each function defined \n\tin a Scilab *.sci file, based on the initial comment \n\tlines following the function definition.\n\tUsage: sci2htm.pl \n"; exit(0); }; print "Creating helpfiles from functions defined in @ARGV[0]\n"; $input=@ARGV[0]; $FILEOPEN=0; $FIRSTLINEREAD=0; # test while (<>) { if (/^\s*function/) { if ($FILEOPEN) { print "\t...oops missed end of last function.\n"; print OUT '\n\n'; close(OUT); $FILEOPEN = 0; $FIRSTLINEREAD=0; } # Prepare a new helpfile for the new function. if (/=/) { # If function lhs=fname(rhs) ($foo,$file)=split(/=/); # Get hold of the ($file,$foo)=split(/\(/,$file); # name of the new function. } elsif (/function\s*(\b\w*\b)/) { # Else assume function fname(rhs) $file=$1; } $fcall = $_; # remember the function call $outfile = "$file.htm"; open(OUT,">$outfile") || die "Unable to create $outfile: $!\n"; $FILEOPEN = 1; # Flag to indicate that we have an open file. print "\t Creating helpfile $outfile\n"; print OUT "\n"; print OUT "$file\n\n"; print OUT "
Scilab Function
\n\n"; } elsif (($FILEOPEN) && (m"^\s*//")) { # If still an initial comment s/^\s*\/\///; # Strip of leading // if ($FIRSTLINEREAD==0) { print OUT "

$file - $_

\n\n"; print OUT "

Calling Sequence

\n\n"; print OUT "
\n\t $fcall\n
\n\n\n"; $FIRSTLINEREAD=1; } elsif ($FIRSTLINEREAD==1) { print OUT "

Parameters

\n\n"; print OUT "

Description

"; $DESCRIPTION = 1; } elsif (/^\s*Examples/i) { # Insert Examples header... print OUT "\n"; print OUT "

Examples

"; print OUT "
";    
	    $EXAMPLES = 1;
	} elsif (/^\s*$/) {
	    print OUT "

\n"; }else { print OUT; } } else { # Start of code - time to finish the helpfile. unless ($DESCRIPTION) { print OUT "

\n"; print OUT "

Description

"; print OUT "
";
	    print OUT "PLACE ANY DESCRIPTION HERE OR DELETE ENTRY!\n"
	}
	unless ($EXAMPLES) {
	    print OUT "
\n"; print OUT "

Examples

"; print OUT "
";
	    print OUT "PLACE ANY EXAMPLES HERE OR DELETE ENTRY!\n"
	}
	print OUT "\n
\n\n"; close(OUT); # close it $FILEOPEN = 0; $FIRSTLINEREAD=0; $DESCRIPTION=0; $EXAMPLES=0; } }