S
S.Badel
Guest
here is the script i promised some time ago, to generate tips file from
finder data.
i always forgot to send it,
hope it'll serve someone.
stéphane
------------------------------------------------------------------------------------------
#!/usr/bin/perl
##################################################################
## File : iltips ##
## Author : S.Badel ##
## Date : Apr 1, 2005 ##
##--------------------------------------------------------------##
## Purpose : Generates nedit tips file from finder data ##
## ##
##--------------------------------------------------------------##
## Notes : ##
## ##
##--------------------------------------------------------------##
## Future improvements : ##
## ##
##################################################################
use Carp;
use Getopt::Long;
use File::stat;
use Text::Balanced qw (
extract_delimited
extract_bracketed
extract_quotelike
extract_codeblock
extract_variable
extract_tagged
extract_multiple
gen_delimited_pat
gen_extract_tagged
);
package main;
our( $BIN,$VERSION);
$BIN="iltips";
$VERSION="1.0";
##################################################################
## main() ##
##################################################################
# display version
print STDERR "\n". Version() . "\n\n";
# parse options
my $help='';
my $version='';
my @options = (
'h|help' => \$help,
'v|version' => \$version
);
my %helpData = (
args => {
'<file>' => 'name of finder file to process',
'[<file> ...]' => undef,
},
options => {
'-h, --help' => 'displays this help screen',
'-v, --version' => 'prints the script version string'
}
);
GetOptions( @options );
# check options
if( $help == 1 )
{
DisplayHelp();
exit 0;
}
if( $version == 1 )
{
exit 0;
}
#
# main code starts here
#
die "Missing argument." if $#ARGV<0;
# print calltip file header
print "* comment *\n".
"File generated by iltips tool, from the file(s) : \n " .
join("\n ", @ARGV) . "\n".
"\n";
print "* language *\n".
"SKILL\n".
"\n";
my $file = shift @ARGV;
while( $file )
{
# read file
open( FILE, "<$file" ) or do { print STDERR "Cannot open $file.\n";
next; };
my @lines = <FILE>;
close( FILE );
my $data = join( "", @lines ) . "\n";
# print progress indication
print STDERR " processing file $file...\n";
# print comment indicating file name
print "* comment *\n".
"File $file\n".
"\n";
# strip leading comments and empty lines
$data =~ s/(^\s*(;.*)?\n)*\(/(/m;
# start processing
($match, $data, $skipped) = extract_bracketed( $data, '(")' );
while ( $match )
{
# extract section name, function definition and help text, removing
quotes
($name, $match) = extract_delimited( $match, '"', '\(' ); $name =
substr( $name, 1, length($name)-2 );
($def, $match) = extract_delimited( $match, '"', '[\s\n]*' ); $def =
substr( $def, 1, length($def)-2 );
($text, $match) = extract_delimited( $match, '"', '[\s\n]*' ); $text
= substr( $text, 1, length($text)-2 );
# break lines longer than 80 chars
$text =~ s/(.{80,}?)\W\s*/\1\n/mg;
# strip white lines
$text =~ s/^\s*\n//mg;
# print result
print "$name\n$def\n$text\n\n" if $name and $def and $text;
# strip leading comments and empty lines
$data =~ s/(^\s*(;.*)?\n)*\(/(/m;
# extract next definition
($match, $data, $skipped) = extract_bracketed( $data, '(")' );
}
# catch error
if( $data =~ m/[^\s\n]/m )
{
# print STDERR "\nError parsing file $file:\n" . substr( $data, 0,
1000 ) . "\n\n";
print STDERR "\nError parsing file $file:\n" . $data . "\n\n";
}
# process next file
$file = shift ARGV;
}
# exit
exit 0;
#-----------------------------------------------------------------
# Version() - returns the version string of the program
#-----------------------------------------------------------------
sub Version
{
return "$BIN v$VERSION";
}
#-----------------------------------------------------------------
# DisplayHelp() - returns the help message
#-----------------------------------------------------------------
sub DisplayHelp
{
my $x;
print "USAGE : $BIN [options] ";
foreach $x( keys %{$helpData{args}} ) { print "$x "; }
print "\n";
print "WHERE :\n";
foreach $x( keys %{$helpData{args}} ) { print "
$x\t$helpData{args}{$x}\n" if defined($helpData{args}{$x}) }
print "OPTIONS:\n";
foreach $x( keys %{$helpData{options}} ) { print "
$x\t$helpData{options}{$x}\n" if defined($helpData{options}{$x}) }
print "\n";
}
finder data.
i always forgot to send it,
hope it'll serve someone.
stéphane
------------------------------------------------------------------------------------------
#!/usr/bin/perl
##################################################################
## File : iltips ##
## Author : S.Badel ##
## Date : Apr 1, 2005 ##
##--------------------------------------------------------------##
## Purpose : Generates nedit tips file from finder data ##
## ##
##--------------------------------------------------------------##
## Notes : ##
## ##
##--------------------------------------------------------------##
## Future improvements : ##
## ##
##################################################################
use Carp;
use Getopt::Long;
use File::stat;
use Text::Balanced qw (
extract_delimited
extract_bracketed
extract_quotelike
extract_codeblock
extract_variable
extract_tagged
extract_multiple
gen_delimited_pat
gen_extract_tagged
);
package main;
our( $BIN,$VERSION);
$BIN="iltips";
$VERSION="1.0";
##################################################################
## main() ##
##################################################################
# display version
print STDERR "\n". Version() . "\n\n";
# parse options
my $help='';
my $version='';
my @options = (
'h|help' => \$help,
'v|version' => \$version
);
my %helpData = (
args => {
'<file>' => 'name of finder file to process',
'[<file> ...]' => undef,
},
options => {
'-h, --help' => 'displays this help screen',
'-v, --version' => 'prints the script version string'
}
);
GetOptions( @options );
# check options
if( $help == 1 )
{
DisplayHelp();
exit 0;
}
if( $version == 1 )
{
exit 0;
}
#
# main code starts here
#
die "Missing argument." if $#ARGV<0;
# print calltip file header
print "* comment *\n".
"File generated by iltips tool, from the file(s) : \n " .
join("\n ", @ARGV) . "\n".
"\n";
print "* language *\n".
"SKILL\n".
"\n";
my $file = shift @ARGV;
while( $file )
{
# read file
open( FILE, "<$file" ) or do { print STDERR "Cannot open $file.\n";
next; };
my @lines = <FILE>;
close( FILE );
my $data = join( "", @lines ) . "\n";
# print progress indication
print STDERR " processing file $file...\n";
# print comment indicating file name
print "* comment *\n".
"File $file\n".
"\n";
# strip leading comments and empty lines
$data =~ s/(^\s*(;.*)?\n)*\(/(/m;
# start processing
($match, $data, $skipped) = extract_bracketed( $data, '(")' );
while ( $match )
{
# extract section name, function definition and help text, removing
quotes
($name, $match) = extract_delimited( $match, '"', '\(' ); $name =
substr( $name, 1, length($name)-2 );
($def, $match) = extract_delimited( $match, '"', '[\s\n]*' ); $def =
substr( $def, 1, length($def)-2 );
($text, $match) = extract_delimited( $match, '"', '[\s\n]*' ); $text
= substr( $text, 1, length($text)-2 );
# break lines longer than 80 chars
$text =~ s/(.{80,}?)\W\s*/\1\n/mg;
# strip white lines
$text =~ s/^\s*\n//mg;
# print result
print "$name\n$def\n$text\n\n" if $name and $def and $text;
# strip leading comments and empty lines
$data =~ s/(^\s*(;.*)?\n)*\(/(/m;
# extract next definition
($match, $data, $skipped) = extract_bracketed( $data, '(")' );
}
# catch error
if( $data =~ m/[^\s\n]/m )
{
# print STDERR "\nError parsing file $file:\n" . substr( $data, 0,
1000 ) . "\n\n";
print STDERR "\nError parsing file $file:\n" . $data . "\n\n";
}
# process next file
$file = shift ARGV;
}
# exit
exit 0;
#-----------------------------------------------------------------
# Version() - returns the version string of the program
#-----------------------------------------------------------------
sub Version
{
return "$BIN v$VERSION";
}
#-----------------------------------------------------------------
# DisplayHelp() - returns the help message
#-----------------------------------------------------------------
sub DisplayHelp
{
my $x;
print "USAGE : $BIN [options] ";
foreach $x( keys %{$helpData{args}} ) { print "$x "; }
print "\n";
print "WHERE :\n";
foreach $x( keys %{$helpData{args}} ) { print "
$x\t$helpData{args}{$x}\n" if defined($helpData{args}{$x}) }
print "OPTIONS:\n";
foreach $x( keys %{$helpData{options}} ) { print "
$x\t$helpData{options}{$x}\n" if defined($helpData{options}{$x}) }
print "\n";
}