diff options
Diffstat (limited to 'Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm')
-rw-r--r-- | Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm | 161 |
1 files changed, 88 insertions, 73 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm index fa6df78828f..cd6ec912c3b 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm @@ -1,4 +1,5 @@ package LatexIndent::LogFile; + # 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 3 of the License, or @@ -16,25 +17,29 @@ package LatexIndent::LogFile; # For all communication, please visit: https://github.com/cmhughes/latexindent.pl use strict; use warnings; -use FindBin; -use File::Basename; # to get the filename and directory path +use FindBin; +use File::Basename; # to get the filename and directory path use Exporter qw/import/; use LatexIndent::Switches qw/%switches/; use LatexIndent::Version qw/$versionNumber $versionDate/; our @EXPORT_OK = qw/process_switches $logger/; our $logger; -sub process_switches{ +sub process_switches { + # -v switch is just to show the version number - if($switches{version}) { - print $versionNumber,", ",$versionDate,"\n"; - if ($switches{vversion}) { + if ( $switches{version} ) { + print $versionNumber, ", ", $versionDate, "\n"; + if ( $switches{vversion} ) { print "$FindBin::Script lives here: $FindBin::RealBin/$FindBin::Script\n"; - if ( -e "$FindBin::RealBin/defaultSettings.yaml" ){ + if ( -e "$FindBin::RealBin/defaultSettings.yaml" ) { print "defaultSettings.yaml lives here $FindBin::RealBin/defaultSettings.yaml\n"; - } elsif ( -e "$FindBin::RealBin/../../texmf-dist/scripts/latexindent/defaultSettings.yaml" ){ - print "defaultSettings.yaml lives here $FindBin::RealBin/../../texmf-dist/scripts/latexindent/defaultSettings.yaml\n"; - } elsif ( -e "$FindBin::RealBin/LatexIndent/defaultSettings.yaml" ) { + } + elsif ( -e "$FindBin::RealBin/../../texmf-dist/scripts/latexindent/defaultSettings.yaml" ) { + print + "defaultSettings.yaml lives here $FindBin::RealBin/../../texmf-dist/scripts/latexindent/defaultSettings.yaml\n"; + } + elsif ( -e "$FindBin::RealBin/LatexIndent/defaultSettings.yaml" ) { print "defaultSettings.yaml lives here $FindBin::RealBin/LatexIndent/defaultSettings.yaml\n"; } print "project home: https://github.com/cmhughes/latexindent.pl\n"; @@ -42,8 +47,8 @@ sub process_switches{ exit(0); } - if(scalar(@ARGV) < 1 or $switches{showhelp}) { - print <<ENDQUOTE + if ( scalar(@ARGV) < 1 or $switches{showhelp} ) { + print <<ENDQUOTE latexindent.pl version $versionNumber, $versionDate usage: latexindent.pl [options] [file] -v, --version @@ -110,29 +115,30 @@ usage: latexindent.pl [options] [file] loads the Unicode::GCString module for the align-at-ampersand routine Note: this requires the Unicode::GCString module to be installed on your system ENDQUOTE - ; - exit(0); -} + ; + exit(0); + } # if we've made it this far, the processing of switches and logging begins - my $self = shift; - my @fileNames = @{$_[0]}; + my $self = shift; + my @fileNames = @{ $_[0] }; $logger = LatexIndent::Logger->new(); - + # cruft directory - ${$self}{cruftDirectory} = $switches{cruftDirectory}||(dirname ${$self}{fileName}); + ${$self}{cruftDirectory} = $switches{cruftDirectory} || ( dirname ${$self}{fileName} ); # if cruft directory does not exist - if(!(-d ${$self}{cruftDirectory})){ + if ( !( -d ${$self}{cruftDirectory} ) ) { $logger->fatal("*Could not find directory ${$self}{cruftDirectory}"); - $logger->fatal("Exiting, no indendation done."); + $logger->fatal("Exiting, no indendation done."); $self->output_logfile(); exit(6); } - my $logfileName = ($switches{cruftDirectory} ? ${$self}{cruftDirectory}."/" : '').($switches{logFileName}||"indent.log"); - + my $logfileName = ( $switches{cruftDirectory} ? ${$self}{cruftDirectory} . "/" : '' ) + . ( $switches{logFileName} || "indent.log" ); + # details of the script to log file $logger->info("*$FindBin::Script version $versionNumber, $versionDate, a script to indent .tex files"); $logger->info("$FindBin::Script lives here: $FindBin::RealBin/"); @@ -140,21 +146,24 @@ ENDQUOTE my $time = localtime(); $logger->info($time); - if (${$self}{fileName} ne "-"){ + if ( ${$self}{fileName} ne "-" ) { + # multiple filenames or not - if ( (scalar (@fileNames)) >1 ){ - $logger->info("Filenames:"); - foreach (@fileNames) { - $logger->info(" $_"); - } - $logger->info("total number of files: ".(scalar (@fileNames))); - } else { - $logger->info("Filename: ${$self}{fileName}"); + if ( ( scalar(@fileNames) ) > 1 ) { + $logger->info("Filenames:"); + foreach (@fileNames) { + $logger->info(" $_"); + } + $logger->info( "total number of files: " . ( scalar(@fileNames) ) ); + } + else { + $logger->info("Filename: ${$self}{fileName}"); } - } else { + } + else { $logger->info("Reading input from STDIN"); - if (-t STDIN) { - my $buttonText = ($FindBin::Script eq 'latexindent.exe') ? 'CTRL+Z followed by ENTER':'CTRL+D'; + if ( -t STDIN ) { + my $buttonText = ( $FindBin::Script eq 'latexindent.exe' ) ? 'CTRL+Z followed by ENTER' : 'CTRL+D'; print STDERR "Please enter text to be indented: (press $buttonText when finished)\n"; } } @@ -163,51 +172,56 @@ ENDQUOTE $logger->info("*Processing switches:"); # check on the trace mode switch (should be turned on if ttrace mode active) - $switches{trace} = $switches{ttrace} ? 1 : $switches{trace}; - + $switches{trace} = $switches{ttrace} ? 1 : $switches{trace}; + # output details of switches - $logger->info("-sl|--screenlog: log file will also be output to the screen") if($switches{screenlog}); - $logger->info("-t|--trace: Trace mode active (you have used either -t or --trace)") if($switches{trace} and !$switches{ttrace}); - $logger->info("-tt|--ttrace: TTrace mode active (you have used either -tt or --ttrace)") if($switches{ttrace}); - $logger->info("-s|--silent: Silent mode active (you have used either -s or --silent)") if($switches{silentMode}); - $logger->info("-d|--onlydefault: Only defaultSettings.yaml will be used (you have used either -d or --onlydefault)") if($switches{onlyDefault}); - $logger->info("-w|--overwrite: Overwrite mode active, will make a back up before overwriting") if($switches{overwrite}); - $logger->info("-wd|--overwriteIfDifferent: will overwrite ONLY if indented text is different") if($switches{overwriteIfDifferent}); - $logger->info("-l|--localSettings: Read localSettings YAML file") if($switches{readLocalSettings}); - $logger->info("-y|--yaml: YAML settings specified via command line") if($switches{yaml}); - $logger->info("-o|--outputfile: output to file") if($switches{outputToFile}); - $logger->info("-m|--modifylinebreaks: modify line breaks") if($switches{modifyLineBreaks}); - $logger->info("-g|--logfile: logfile name") if($switches{logFileName}); - $logger->info("-c|--cruft: cruft directory") if($switches{cruftDirectory}); - $logger->info("-r|--replacement: replacement mode") if($switches{replacement}); - $logger->info("-rr|--onlyreplacement: *only* replacement mode, no indentation") if($switches{onlyreplacement}); - $logger->info("-k|--check mode: will exit with 0 if document body unchanged, 1 if changed") if($switches{check}); - $logger->info("-kv|--check mode verbose: as in check mode, but outputs diff to screen") if($switches{checkverbose}); - $logger->info("-n|--lines mode: will only operate on specific lines $switches{lines}") if($switches{lines}); - $logger->info("--GCString switch active, loading Unicode::GCString module") if($switches{GCString}); + $logger->info("-sl|--screenlog: log file will also be output to the screen") if ( $switches{screenlog} ); + $logger->info("-t|--trace: Trace mode active (you have used either -t or --trace)") + if ( $switches{trace} and !$switches{ttrace} ); + $logger->info("-tt|--ttrace: TTrace mode active (you have used either -tt or --ttrace)") if ( $switches{ttrace} ); + $logger->info("-s|--silent: Silent mode active (you have used either -s or --silent)") if ( $switches{silentMode} ); + $logger->info("-d|--onlydefault: Only defaultSettings.yaml will be used (you have used either -d or --onlydefault)") + if ( $switches{onlyDefault} ); + $logger->info("-w|--overwrite: Overwrite mode active, will make a back up before overwriting") + if ( $switches{overwrite} ); + $logger->info("-wd|--overwriteIfDifferent: will overwrite ONLY if indented text is different") + if ( $switches{overwriteIfDifferent} ); + $logger->info("-l|--localSettings: Read localSettings YAML file") if ( $switches{readLocalSettings} ); + $logger->info("-y|--yaml: YAML settings specified via command line") if ( $switches{yaml} ); + $logger->info("-o|--outputfile: output to file") if ( $switches{outputToFile} ); + $logger->info("-m|--modifylinebreaks: modify line breaks") if ( $switches{modifyLineBreaks} ); + $logger->info("-g|--logfile: logfile name") if ( $switches{logFileName} ); + $logger->info("-c|--cruft: cruft directory") if ( $switches{cruftDirectory} ); + $logger->info("-r|--replacement: replacement mode") if ( $switches{replacement} ); + $logger->info("-rr|--onlyreplacement: *only* replacement mode, no indentation") if ( $switches{onlyreplacement} ); + $logger->info("-k|--check mode: will exit with 0 if document body unchanged, 1 if changed") if ( $switches{check} ); + $logger->info("-kv|--check mode verbose: as in check mode, but outputs diff to screen") + if ( $switches{checkverbose} ); + $logger->info("-n|--lines mode: will only operate on specific lines $switches{lines}") if ( $switches{lines} ); + $logger->info("--GCString switch active, loading Unicode::GCString module") if ( $switches{GCString} ); # check if overwrite and outputfile are active similtaneously - if($switches{overwrite} and $switches{outputToFile}){ + if ( $switches{overwrite} and $switches{outputToFile} ) { $logger->info("*Options check: -w and -o specified"); $logger->info("You have called latexindent.pl with both -o and -w"); $logger->info("The -o switch will take priority, and -w (overwrite) will be ignored"); - $switches{overwrite}=0; + $switches{overwrite} = 0; } # check if overwrite and outputfile are active similtaneously - if($switches{overwrite} and $switches{overwriteIfDifferent}){ + if ( $switches{overwrite} and $switches{overwriteIfDifferent} ) { $logger->info("*Options check: -w and -wd specified"); $logger->info("You have called latexindent.pl with both -w and -wd."); $logger->info("The -wd switch will take priority, and -w (overwrite) will be ignored"); - $switches{overwrite}=0; + $switches{overwrite} = 0; } # check if overwriteIfDifferent and outputfile are active similtaneously - if($switches{overwriteIfDifferent} and $switches{outputToFile}){ + if ( $switches{overwriteIfDifferent} and $switches{outputToFile} ) { $logger->info("*Options check: -wd and -o specified"); $logger->info("You have called latexindent.pl with both -o and -wd"); $logger->info("The -o switch will take priority, and -wd (overwriteIfDifferent) will be ignored"); - $switches{overwriteIfDifferent}=0; + $switches{overwriteIfDifferent} = 0; } # multiple files with the -o switch needs care @@ -218,32 +232,33 @@ ENDQUOTE # # would result in only the final file being written to myfile.tex # - # So, if -o switch does *not* match having a + symbol at the beginning, then + # So, if -o switch does *not* match having a + symbol at the beginning, then # we ignore it, and turn it off # - if ( (scalar @fileNames>1) and $switches{outputToFile} and ($switches{outputToFile} !~ m/^h*\+/) ){ + if ( ( scalar @fileNames > 1 ) and $switches{outputToFile} and ( $switches{outputToFile} !~ m/^h*\+/ ) ) { $logger->warn("*-o switch specified as single file, but multiple files given as input"); $logger->warn("ignoring your specification -o $switches{outputToFile}"); $logger->warn("perhaps you migh specify it using, for example, -o=++ or -o=+myoutput"); - $switches{outputToFile} =0; + $switches{outputToFile} = 0; } $logger->info("*Directory for backup files and $logfileName:"); $logger->info("${$self}{cruftDirectory}"); # output location of modules - if($FindBin::Script eq 'latexindent.pl' or ($FindBin::Script eq 'latexindent.exe' and $switches{trace} )) { - my @listOfModules = ('FindBin', 'YAML::Tiny', 'File::Copy', 'File::Basename', 'Getopt::Long','File::HomeDir'); - push(@listOfModules,'Unicode::GCString') if $switches{GCString}; + if ( $FindBin::Script eq 'latexindent.pl' or ( $FindBin::Script eq 'latexindent.exe' and $switches{trace} ) ) { + my @listOfModules + = ( 'FindBin', 'YAML::Tiny', 'File::Copy', 'File::Basename', 'Getopt::Long', 'File::HomeDir' ); + push( @listOfModules, 'Unicode::GCString' ) if $switches{GCString}; $logger->info("*Perl modules are being loaded from the following directories:"); foreach my $moduleName (@listOfModules) { - (my $file = $moduleName) =~ s|::|/|g; - $logger->info($INC{$file .'.pm'}); - } + ( my $file = $moduleName ) =~ s|::|/|g; + $logger->info( $INC{ $file . '.pm' } ); + } $logger->info("*LatexIndent perl modules are being loaded from, for example:"); - (my $file = 'LatexIndent::Document') =~ s|::|/|g; - $logger->info($INC{$file .'.pm'}); + ( my $file = 'LatexIndent::Document' ) =~ s|::|/|g; + $logger->info( $INC{ $file . '.pm' } ); } return; |