From a4cc3ad3504d634e379369862c9f9fd8eed379f3 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 16 May 2024 01:43:09 -0400 Subject: Add Jindrich Kubec's tools. --- jindroush/switches.pl | 322 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 322 insertions(+) create mode 100644 jindroush/switches.pl (limited to 'jindroush/switches.pl') diff --git a/jindroush/switches.pl b/jindroush/switches.pl new file mode 100644 index 0000000..71f78be --- /dev/null +++ b/jindroush/switches.pl @@ -0,0 +1,322 @@ +$infile = "switches.def"; +$outfile = "switches.cpp"; + +if ( @ARGV ) +{ + $infile = shift @ARGV; +} + +if ( @ARGV ) +{ + $outfile = shift @ARGV; +} + +############################################################################ +## Script for generating switches.cpp +## +############################################################################ + +open INFILE, $infile or die; +@inf = ; +close INFILE; + +unshift @inf, "="; +unshift @inf, "=bRet = SWFN_HELP( USAGE );"; +unshift @inf, "this help"; +unshift @inf, "help, ?"; + +push @out, < $longest ); +} + +$longest += 2 + 9; +foreach $line ( @help ) +{ + my ( $switch, $desc, $par ) = split( /\|/, $line, 3 ); + + my $len = length( $switch ) + length( $par ); + + my $l = "printf( \"-$switch"; + + if ( $par ) + { + $l .= " $par"; + } + + $l .= ' ' x ( $longest - length( $l ) ); + + $l .= " -$desc\\n\" );\n"; + + push @helpf, $l; + +} + +unshift @out, @helpf; + +unshift @out, <$outfile"; + +print OUTFILE "//THIS IS A GENERATED FILE. DO NOT EDIT!!!\n"; +print OUTFILE "//EDIT $infile INSTEAD!\n\n"; + +$indent = 0; + +$bigline = join( '', @out ); +@out = split( /\n/, $bigline ); + +foreach $line ( @out ) +{ + $indent-- if ( $line =~ /}/ ); + + print OUTFILE "\t" x $indent, $line, "\n"; + + $indent++ if ( $line =~ /{/ ); + +} + +close OUTFILE; + +sub switch() +{ + my $switch_desc = ""; + + my $switches_names = shift @inf; + my $switches_desc = shift @inf; + + chomp $switches_desc; + + my @switches = split( /,/, $switches_names ); + + foreach $switch ( @switches ) + { + $switch =~ s/\s+$//; + $switch =~ s/^\s+//; + + if ( defined ( $SWITCHES{ $switch } ) ) + { + die "Duplicate switch $switch"; + } + + $SWITCHES{ $switch } = 1; + + } + + $switches_count = @switches; + + $switch_desc = $switches[ 0 ] . "|" . $switches_desc . "|"; + + push @out, "if ("; + + my @asc; + + foreach $switch (@switches ) + { + push @asc, "!strcmp( m_szSwitch, \"$switch\" )"; + } + + push @out, join( " || ", @asc ); + + push @out, ")"; + + push @out, "\n{\n"; + + my @switch_pars = (); + + for(;;) + { + my $par_desc = shift @inf; + + my ( $par, $code ) = split( /=/, $par_desc, 2 ); + + $par =~ s/\s+$//; + $par =~ s/^\s+//; + + $code =~ s/\s+$//; + $code =~ s/^\s+//; + + last if ( !$par && !$code ); + + if ( $code =~ /(SWFN_\w+)/ ) + { + $CODE_INCLUDE{ $1 } = 1; + } + + if ( $par ) + { + push @switch_pars, $par; + } + + push @out, $code . "\n"; + } + + push @out, "continue;\n"; + + $switch_desc .= join( ' ', @switch_pars ); + + push @help, $switch_desc; + + push @out, "}\n"; + +} -- cgit v1.2.3