From ed8c31339705242b672e10132a741368ec387ccd Mon Sep 17 00:00:00 2001 From: tadam Date: Fri, 1 Jan 2010 19:58:17 +0000 Subject: [PATCH] Convert over to use GetOpt::Long and introduce -f and -h. --follow-read|-f : Follow files found via "Read". --help|-h : Print help message. No longer allow fvwm-convert-2.6 to follow Read files automatically -- force this via -f instead. In the case of -f not given, still print out files found on the command line to make the user aware there's additional files that will need processing. --- bin/ChangeLog | 15 +++++++++++++++ bin/fvwm-convert-2.6.1.in | 21 ++++++++++++++++++--- bin/fvwm-convert-2.6.in | 40 ++++++++++++++++++++++++++++------------ 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/bin/ChangeLog b/bin/ChangeLog index 113914ba1..f7d983184 100644 --- a/bin/ChangeLog +++ b/bin/ChangeLog @@ -1,5 +1,20 @@ 2010-01-01 Thomas Adam * fvwm-convert-2.6.in: + * fvwm-convert-2.6.1.in: + Convert over to use GetOpt::Long and introduce -f and -h. + + --follow-read|-f : Follow files found via "Read". + --help|-h : Print help message. + + No longer allow fvwm-convert-2.6 to follow Read files automatically -- + force this via -f instead. + + In the case of -f not given, still print out files found on the command + line to make the user aware there's additional files that will need + processing. + +2010-01-01 Thomas Adam + * fvwm-convert-2.6.in: Fix command-line parsing, and allow for destination file to be honoured -- stupid logic bug on my part. diff --git a/bin/fvwm-convert-2.6.1.in b/bin/fvwm-convert-2.6.1.in index ada346e4d..fdd8d5637 100644 --- a/bin/fvwm-convert-2.6.1.in +++ b/bin/fvwm-convert-2.6.1.in @@ -4,8 +4,18 @@ fvwm-convert-2.6 \- convert fvwm 2.4.x configuration file to fvwm 2.6 style .SH SYNOPSIS .B fvwm-convert-2.6 +.RI [ --follow-read | -f ] +.RI [ --help | -h ] .RI source .RI [ dest ] +.SH OPTIONS +The following options are supported: +.IP "\fB\-\-help\fR | \fB\-h\fR" +Prints a usage message to the screen. +.IP "\fB\-\-follow\-read\fR | \fB\-f\fR" +Follows files found along with the +.B Read +command. .SH DESCRIPTION .B fvwm-convert-2.6 converts an fvwm 2.4.x configuration file into a fvwm 2.6 @@ -75,10 +85,15 @@ redundant when StartFunction is read at both of these times. attempts to convert this. .TP 4 .B Read -Any files +If +.B -f +or +.B --follow-read +is given, any files .B fvwm-convert-2.6 -can detect and open will be converted automatically, else a warning is -printed to STDERR. +can detect and open will be converted automatically, else a list of files +that could would have been followed are printed to the screen. + .TP 4 .SH BUGS diff --git a/bin/fvwm-convert-2.6.in b/bin/fvwm-convert-2.6.in index aa5cade7a..f4ff86a6d 100644 --- a/bin/fvwm-convert-2.6.in +++ b/bin/fvwm-convert-2.6.in @@ -21,6 +21,7 @@ use strict; use Cwd; +use Getopt::Long; # Global array for all our converted lines. my @converted_lines = (); @@ -32,6 +33,10 @@ my %converted_funcs = (); # Global for additional files... my @additional_files = (); +# GetOpts +my $follow_read = ''; +my $process_read = 0; + # Convert conditional command syntax correctly. sub __convert_conditionals { @@ -54,6 +59,8 @@ sub process_files { my( $s, $d ) = @$f; + warn "Following: Read $s...\n" if $process_read; + if( (!defined $d or $d eq '') and ! -e "$s.converted" ) { @@ -399,42 +406,32 @@ sub dispatch_line if( $line =~ /^style/i ) { - print "Converting style lines...\n"; convert_styles($line); } elsif( $line =~ /^\s*\*fvwmtheme:??/i ) { - print "Converting FvwmTheme lines...\n"; convert_fvwmtheme($line); } elsif( $line =~ /^\s*modulepath\s*/i ) { - print "Shooting the user for ever having changed ModulePath...\n"; handle_modulepath( $line ); } elsif( $line =~ /^\s*windowshadesteps.*/i ) { convert_windowshadesteps($line); } elsif( $line =~ /^\s*module(?:synchronous)?.*?fvwmtheme$/i ) { convert_fvwmtheme($line); } elsif( $line =~ /^\s*edgeresistance\s*\d+\s*\d+/i ) { - print "Converting EdgeResistance lines...\n"; convert_edge_resistance($line); } elsif( $line =~ /^\s*key|mouse/i ) { - print "Converting key/mouse bindings...\n"; convert_key_mouse_bindings($line); } elsif( $line =~ /^\s*snap(?:attraction|grid)/i ) { - print "Converting SnapAttraction...\n"; convert_snapattraction( $line ); } elsif( $line =~ /^\s*addtofunc\s+initfunction/i ) { - print "Converting InitFunction...\n"; convert_initfunc( $line ); } elsif( $line =~ /^\s*addtofunc\s+startfunction.*/i ) { - print "Converting StartFunction ...\n"; convert_startfunc( $line ); } elsif( $line =~ /^\s*addtofunc\s+restartfunction/i ) { - print "Converting RestartFunction...\n"; convert_restartfunc( $line ); } elsif( $line =~ /^\s*addtofunc\s+\w+.*/i ) { check_func_definition( $line ); } elsif( $line =~ /^\s*\+\s*\"??[ichmd]{1}\s*\"??\s+.*/i ) { handle_continuation( $line ); } elsif( $line =~ /^\s*read\s*[\/\w]+/i ) { - print "Following Read Command( $line ) ...\n"; handle_read_file( $line ); } else { # Could be a comment, or a continuation, or simply something we @@ -449,12 +446,31 @@ sub dispatch_line sub usage { - print "fvwm-convert-2.6 source-file destination-file\n"; + print "fvwm-convert-2.6 [-f] [-h] source-file destination-file\n"; exit; } +GetOptions( + "help|h" => \&usage, + "follow-read|f" => \$follow_read, +) || usage(); + +# But we still require @ARGV to be populated with our filenames. usage() unless( @ARGV > 0 and @ARGV <=2 ); my @files = [@ARGV]; process_files( \@files ); -process_files( \@additional_files ) if scalar @additional_files; + +if( @additional_files && !$follow_read ) +{ + print "The following files were detected, but not processed:\n\n", + join("\n", @$_ ) for @additional_files,; + print "\n"; +} + +# Only do this is we've been asked. +if( @additional_files && $follow_read ) +{ + $process_read = 1; + process_files( \@additional_files ); +} -- 2.11.4.GIT