diff options
author | Karl Berry <karl@freefriends.org> | 2017-06-25 21:50:47 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-06-25 21:50:47 +0000 |
commit | a3d3b206eb2e58da4e00d07576e32c5bd9acbf69 (patch) | |
tree | 313d64a4fdbe9c168e5e210aedfd13312e6a1f44 /Master/texmf-dist/scripts/latexindent | |
parent | 00305c9e9703b6a03efb295fc20c04be6a65d447 (diff) |
latexindent (25jun17)
git-svn-id: svn://tug.org/texlive/trunk@44695 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/latexindent')
6 files changed, 118 insertions, 8 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileExtension.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileExtension.pm index 131c5c011eb..c2f6d0fcf3f 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/FileExtension.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/FileExtension.pm @@ -22,6 +22,7 @@ use open ':std', ':encoding(UTF-8)'; use File::Basename; # to get the filename and directory path use Exporter qw/import/; use LatexIndent::GetYamlSettings qw/%masterSettings/; +use LatexIndent::Switches qw/%switches/; our @EXPORT_OK = qw/file_extension_check/; sub file_extension_check{ @@ -37,7 +38,8 @@ sub file_extension_check{ my @fileExtensions = sort { $fileExtensionPreference{$a} <=> $fileExtensionPreference{$b} } keys(%fileExtensionPreference); # get the base file name, allowing for different extensions (possibly no extension) - my ($dir, $name, $ext) = fileparse($fileName, @fileExtensions); + my ($name, $dir, $ext) = fileparse($fileName, @fileExtensions); + ${$self}{baseName} = $name; # check to make sure given file type is supported if( -e $fileName and !$ext ){ @@ -90,6 +92,51 @@ sub file_extension_check{ # store the file extension ${$self}{fileExtension} = $ext; + # check to see if -o switch is active + if($switches{outputToFile}){ + + $self->logger("Output file check",'heading'); + + # the -o file name might begin with a + symbol + if($switches{outputToFile} =~ m/^\+(.*)/ and $1 ne "+"){ + $self->logger("-o switch called with + symbol at the beginning: $switches{outputToFile}"); + $switches{outputToFile} = ${$self}{baseName}.$1; + $self->logger("output file is now: $switches{outputToFile}"); + } + + my $strippedFileExtension = ${$self}{fileExtension}; + $strippedFileExtension =~ s/\.//; + + # grab the name, directory, and extension of the output file + my ($name, $dir, $ext) = fileparse($switches{outputToFile}, $strippedFileExtension); + + # if there is no extension, then add the extension from the file to be operated upon + if(!$ext){ + $self->logger("-o switch called with file name without extension: $switches{outputToFile}"); + $switches{outputToFile} = $name.($name=~m/\.\z/ ? q() : ".").$strippedFileExtension; + $self->logger("Updated to $switches{outputToFile} as the file extension of the input file is $strippedFileExtension"); + } + + # the -o file name might end with ++ in which case we wish to search for existence, + # and then increment accordingly + $name =~ s/\.$//; + if($name =~ m/\+\+$/){ + $self->logger("-o switch called with file name ending with ++: $switches{outputToFile}"); + $name =~ s/\+\+$//; + $name = ${$self}{baseName} if ($name eq ""); + my $outputFileCounter = 0; + my $fileName = $name.$outputFileCounter.".".$strippedFileExtension; + $self->logger("will search for exisitence and increment counter, starting with $fileName"); + while( -e $fileName ){ + $self->logger("$fileName exists, incrementing counter"); + $outputFileCounter++; + $fileName = $name.$outputFileCounter.".".$strippedFileExtension; + } + $self->logger("$fileName does not exist, and will be the output file"); + $switches{outputToFile} = $fileName; + } + } + # read the file into the Document body my @lines; open(MAINFILE, $fileName) or die "Could not open input file, $fileName"; diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm index e4b5f12c54d..0d51d5837db 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/GetYamlSettings.pm @@ -35,7 +35,6 @@ our %previouslyFoundSettings; sub readSettings{ my $self = shift; - $defaultSettings = YAML::Tiny->new; $defaultSettings = YAML::Tiny->read( "$FindBin::RealBin/defaultSettings.yaml" ); $self->logger("YAML settings read",'heading'); $self->logger("Reading defaultSettings.yaml from $FindBin::RealBin/defaultSettings.yaml"); @@ -104,11 +103,34 @@ sub readSettings{ # get information about LOCAL settings, assuming that $readLocalSettings exists my $directoryName = dirname (${$self}{fileName}); + my @localSettings; + + # local settings can be called with a + symbol, for example + # -l=+myfile.yaml + # -l "+ myfile.yaml" + # -l=myfile.yaml+ + # which translates to, respectively + # -l=localSettings.yaml,myfile.yaml + # -l=myfile.yaml,localSettings.yaml + # Note: the following is *not allowed*: + # -l+myfile.yaml + # and + # -l + myfile.yaml + # will *only* load localSettings.yaml, and myfile.yaml will be ignored + if($switches{readLocalSettings} =~ m/\+/){ + $self->logger("+ found in call for -l switch: will add localSettings.yaml"); + + # + can be either at the beginning or the end, which determines if where the comma should go + my $commaAtBeginning = ($switches{readLocalSettings} =~ m/^\h*\+/ ? q() : ","); + my $commaAtEnd = ($switches{readLocalSettings} =~ m/^\h*\+/ ? "," : q()); + $switches{readLocalSettings} =~ s/\h*\+\h*/$commaAtBeginning."localSettings.yaml".$commaAtEnd/e; + $self->logger("New value of -l switch: $switches{readLocalSettings}"); + } + # local settings can be separated by , # e.g # -l = myyaml1.yaml,myyaml2.yaml # and in which case, we need to read them all - my @localSettings; if($switches{readLocalSettings} =~ m/,/){ $self->logger("Multiple localSettings found, separated by commas:",'heading'); @localSettings = split(/,/,$switches{readLocalSettings}); @@ -118,6 +140,13 @@ sub readSettings{ # add local settings to the paths, if appropriate foreach (@localSettings) { + # check for an extension (.yaml) + my ($dir, $name, $ext) = fileparse($_, "yaml"); + + # if no extension is found, append the current localSetting with .yaml + $_ = $_.($_=~m/\.\z/ ? q() : ".")."yaml" if(!$ext); + + # check for existence and non-emptiness if ( (-e "$directoryName/$_") and !(-z "$directoryName/$_")) { $self->logger("Adding $directoryName/$_ to YAML read paths"); push(@absPaths,"$directoryName/$_"); diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm index 336ec34c7ad..fb7cb37ed00 100644 --- a/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/LogFile.pm @@ -18,6 +18,7 @@ use strict; use warnings; use LatexIndent::GetYamlSettings qw/%masterSettings/; use LatexIndent::Switches qw/%switches/; +use LatexIndent::Version qw/$versionNumber $versionDate/; use FindBin; use File::Basename; # to get the filename and directory path use Exporter qw/import/; @@ -41,17 +42,25 @@ sub processSwitches{ my $self = shift; # details of the script to log file - $self->logger("$FindBin::Script version 3.2, a script to indent .tex files",'heading'); + $self->logger("$FindBin::Script version $versionNumber, $versionDate, a script to indent .tex files",'heading'); $self->logger("$FindBin::Script lives here: $FindBin::RealBin/"); # time the script is used my $time = localtime(); $self->logger("$time"); + # -v switch is just to show the version number + if($switches{version}) { + print $versionNumber,", ",$versionDate,"\n"; + exit(2); + } + if(scalar(@ARGV) < 1 or $switches{showhelp}) { print <<ENDQUOTE -latexindent.pl version 3.2 +latexindent.pl version $versionNumber, $versionDate usage: latexindent.pl [options] [file][.tex|.sty|.cls|.bib|...] + -v, --version + displays the version number and date of release -h, --help help (see the documentation for detailed instructions and examples) -o, --outputfile @@ -72,7 +81,7 @@ usage: latexindent.pl [options] [file][.tex|.sty|.cls|.bib|...] latexindent.pl -l=some.yaml,another.yaml myfile.tex -d, --onlydefault ONLY use defaultSettings.yaml, ignore ALL (yaml) user files - -g, --logfile + -g, --logfile=<name of log file> used to specify the name of logfile (default is indent.log) -c, --cruft=<cruft directory> used to specify the location of backup files and indent.log diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm new file mode 100644 index 00000000000..1ebfb27171e --- /dev/null +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Version.pm @@ -0,0 +1,24 @@ +package LatexIndent::Version; +# 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 +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# See http://www.gnu.org/licenses/. +# +# Chris Hughes, 2017 +# +# For all communication, please visit: https://github.com/cmhughes/latexindent.pl +use strict; +use warnings; +use Exporter qw/import/; +our @EXPORT_OK = qw/$versionNumber $versionDate/; + +our $versionNumber = '3.2.1'; +our $versionDate = '2017-06-25'; +1 diff --git a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml index 916efb46dd3..d29c887f2da 100755 --- a/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml +++ b/Master/texmf-dist/scripts/latexindent/defaultSettings.yaml @@ -1,4 +1,4 @@ -# defaultSettings.yaml for latexindent.pl, version 3.2, 2017-06-19 +# defaultSettings.yaml for latexindent.pl, version 3.2.1, 2017-06-25 # a script that aims to # beautify .tex, .sty, .cls files # diff --git a/Master/texmf-dist/scripts/latexindent/latexindent.pl b/Master/texmf-dist/scripts/latexindent/latexindent.pl index 107d4fab865..e4fc3ea64f6 100755 --- a/Master/texmf-dist/scripts/latexindent/latexindent.pl +++ b/Master/texmf-dist/scripts/latexindent/latexindent.pl @@ -1,5 +1,5 @@ #!/usr/bin/env perl -# latexindent.pl, version 3.2, 2017-06-19 +# latexindent.pl, version 3.2.1, 2017-06-25 # # 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 @@ -30,6 +30,7 @@ use LatexIndent::Document; my %switches = (readLocalSettings=>0); GetOptions ( + "version|v"=>\$switches{version}, "silent|s"=>\$switches{silentMode}, "trace|t"=>\$switches{trace}, "ttrace|tt"=>\$switches{ttrace}, |