SKILL tips for n-edit

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";
}
 
Apart from line wraps and the quotes, i remember there were some '<'
characters also in the finder files, as in nl<yoursimulator>YadiYada
function names.
The <> seem to be properly handled, because the tokens are enclosed in quotes.
I've had problems with USR2 (i think it was USR2), related to errors in the finder
files (such as missing closing parenthesis), but only a few, I corrected by hand.

I already found a "bug" since i posted, however... it doesn't remove white lines from the
function definitions. If there happens to be one, it breaks the calltip.
The fix is easy though - copy the regexp that removes white lines from $text and apply it to
$def.

stéphane
 
Stephane,

this is indeed much cleaner than my shell script. Since you rewrote
the whole thing, it is a nice gesture to post this.

Apart from line wraps and the quotes, i remember there were some '<'
characters also in the finder files, as in nl<yoursimulator>YadiYada
function names.

S.Badel wrote:
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";
}
 
S.Badel wrote:
here is the script i promised some time ago, to generate tips file
from
SKILL finder data.
Thanks for helping all of us.
In my book, this earns you a free SKILL Quick Reference!

The SKILL Finder ASCII database is used by, of course, the SKILL Finder
GUI (which is part of product 900 SKILL Development Environment) and
for the CIW SKILL "help" command (sans the GUI), e.g.,
CIW: help(funcName1 [funcName2...])

In addition, that same SKILL Finder database is used for the hand-held
SKILL Quick Reference document, which is almost on its twelfth
printing, thanks to the resoundingly positive appraisals by Customers
(which keeps it going as Cadence learns what Customers like to have in
their hands and on their desks).

The eleventh printing (Cadence orange) contains FIVE kinds of
functions:
- CDBA functions that work on both CDB and OA databases (one)
- CDBA functions that work differently in CDB or OA databases (two,
three)
- CDBA functions that work only in CDB or OA dabases (four, five)

The twelfth printing (in progress) contains THREE kinds of functions:
- CDBA functions that work only in OA (one)
- CDBA functions that work both in CDB and OA (two)
- CDBA functions that work differently in OA than in CDB (three)

Send me your snail mail address if you like and I'd be glad to mail you
an SQR or two (use my company address ... do not use this yahoo address
as it's just a spam trap which gets thousands of spams a day).

John Gianni
"Nothing said by me on the USENET is company sanctioned nor reviewed!"
 

Welcome to EDABoard.com

Sponsor

Back
Top