1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
#!/usr/bin/env perl
# /=====================================================================\ #
# | makemanifest | #
# | automagically re-generate the manifest file | #
# |=====================================================================| #
# | support tools for LaTeXML: | #
# | Public domain software, produced as part of work done by the | #
# | United States Government & not subject to copyright in the US. | #
# |---------------------------------------------------------------------| #
# | Bruce Miller <bruce.miller@nist.gov> #_# | #
# | http://dlmf.nist.gov/LaTeXML/ (o o) | #
# \=========================================================ooo==U==ooo=/ #
use strict;
use warnings;
use String::Util 'trim';
use File::Path qw(make_path);
use File::Copy qw(move);
use File::Basename;
use File::Find::Rule;
use Getopt::Long qw(:config no_ignore_case);
use Algorithm::Diff;
use Pod::Usage;
# read command line options
my $identity = 'makemanifest';
my ($diff, $quiet, $save, $help) = ();
GetOptions("diff" => \$diff,
"save" => \$save,
"quiet" => \$quiet,
"help" => \$help,
) or pod2usage(-message => $identity, -exitval => 1, -verbose => 0, -output => \*STDERR);
pod2usage(-message => $identity, -exitval => 1, -verbose => 2, -output => \*STDOUT) if $help;
#======================================================================
# Main Program Logic
#======================================================================
# switch to the root directory for all the finds
chdir make_path(basename($0), '..');
# Create an object to find all the files
my $finder = File::Find::Rule->file();
# read .gitignore
open my $gitignore, '<', '.gitignore';
chomp(my @gitignoreLines = <$gitignore>);
close $gitignore;
# add all lines from there to the ignored files
foreach my $line (@gitignoreLines) {
$line = trim($line);
$finder = $finder->not_name($line) unless ((length($line) == 0) || (substr($line, 0, 1) eq '#')); }
# Build the new MANIFEST
my $manifest = build_manifest();
# show the diff if --diff was given
if ($diff) {
# get the old and new manifests
open my $infile, '<', 'MANIFEST';
chomp(my @oldmanifest = <$infile>);
close $infile;
# get the new manifest
my @newmanifest = split("\n", $manifest);
push(@newmanifest, '');
# and make a diff
my $diff = Algorithm::Diff->new(\@oldmanifest, \@newmanifest);
while ($diff->Next()) {
next if $diff->Same();
my $sep = '';
if (!$diff->Items(2)) {
printf "%d,%dd%d\n", $diff->Get(qw( Min1 Max1 Max2 )); }
elsif (!$diff->Items(1)) {
printf "%da%d,%d\n", $diff->Get(qw( Max1 Min2 Max2 )); }
else {
$sep = "---\n";
printf "%d,%dc%d,%d\n", $diff->Get(qw( Min1 Max1 Min2 Max2 )); }
print "< $_\n" for $diff->Items(1);
print $sep;
print "> $_\n" for $diff->Items(2); }
print("\n"); }
# unless --quiet is set, print the new manifest to STDOUT
elsif (!$quiet) {
print($manifest); }
# if told to do so, write the new file
if ($save) {
# Make a Backup of the old MANIFEST
move("MANIFEST", "MANIFEST.bak");
# write the new one into it
open my $outfile, '>', 'MANIFEST';
print $outfile $manifest;
close $outfile;
# hey, we did it
print STDERR "Wrote new MANIFEST\n"; }
#======================================================================
# Function to list all the files in a given directory
#======================================================================
sub list_files {
my ($dir) = @_;
my $str = '';
my @files = $finder->in($dir);
foreach my $file (sort @files) { $str .= "$file\n"; }
return $str; }
#======================================================================
# Main function to build the manifest file
# Returns the contents as a string
#======================================================================
sub build_manifest {
# build the string
my $str = <<'HERE';
#==================================================
# Base
#==================================================
Changes
Makefile.PL
MANIFEST This list of files
MANIFEST.SKIP
README.pod
INSTALL
INSTALL.SKIP
LICENSE
manual.pdf
#==================================================
# Executables
#==================================================
HERE
$str .= list_files("bin");
$str .= <<'HERE';
#==================================================
# Master Modules
#==================================================
lib/LaTeXML.pm
lib/LaTeXML/Version.in
lib/LaTeXML/Global.pm
#==================================================
# Core Modules
#==================================================
lib/LaTeXML/Core.pm
lib/LaTeXML/Core/State.pm
lib/LaTeXML/Core/Mouth.pm
lib/LaTeXML/Core/Mouth/file.pm
lib/LaTeXML/Core/Mouth/http.pm
lib/LaTeXML/Core/Mouth/https.pm
lib/LaTeXML/Core/Mouth/Binding.pm
lib/LaTeXML/Core/Gullet.pm
lib/LaTeXML/Core/Stomach.pm
lib/LaTeXML/Core/Document.pm
lib/LaTeXML/Core/Rewrite.pm
lib/LaTeXML/Core/Token.pm
lib/LaTeXML/Core/Tokens.pm
lib/LaTeXML/Core/Box.pm
lib/LaTeXML/Core/Comment.pm
lib/LaTeXML/Core/List.pm
lib/LaTeXML/Core/Whatsit.pm
lib/LaTeXML/Core/Definition.pm
lib/LaTeXML/Core/Definition/Expandable.pm
lib/LaTeXML/Core/Definition/Conditional.pm
lib/LaTeXML/Core/Definition/Primitive.pm
lib/LaTeXML/Core/Definition/Register.pm
lib/LaTeXML/Core/Definition/CharDef.pm
lib/LaTeXML/Core/Definition/Constructor.pm
lib/LaTeXML/Core/Definition/Constructor/Compiler.pm
lib/LaTeXML/Core/Parameter.pm
lib/LaTeXML/Core/Parameters.pm
lib/LaTeXML/Core/Alignment.pm
lib/LaTeXML/Core/Alignment/Template.pm
lib/LaTeXML/Core/Array.pm
lib/LaTeXML/Core/KeyVal.pm
lib/LaTeXML/Core/KeyVals.pm
lib/LaTeXML/Core/MuDimension.pm
lib/LaTeXML/Core/MuGlue.pm
lib/LaTeXML/Core/Pair.pm
lib/LaTeXML/Core/PairList.pm
# ....
lib/LaTeXML/MathGrammar
lib/LaTeXML/MathParser.pm
#==================================================
# Preprocessing Modules
#==================================================
HERE
$str .= list_files("lib/LaTeXML/Pre");
$str .= <<'HERE';
#==================================================
# Postprocessing Modules
#==================================================
lib/LaTeXML/Post.pm
HERE
$str .= list_files("lib/LaTeXML/Post");
$str .= <<'HERE';
lib/LaTeXML/LaTeXML.catalog
#==================================================
# Common Modules
#==================================================
HERE
$str .= list_files("lib/LaTeXML/Common");
$str .= <<'HERE';
#==================================================
# Utility Modules
#==================================================
HERE
$str .= list_files("lib/LaTeXML/Util");
$str .= <<'HERE';
#==================================================
# Document Model
#==================================================
HERE
$str .= list_files("lib/LaTeXML/resources/RelaxNG");
$str .= list_files("lib/LaTeXML/resources/DTD");
$str .= <<'HERE';
#==================================================
# XSLT & CSS Support
#==================================================
HERE
$str .= list_files("lib/LaTeXML/resources/XSLT");
$str .= list_files("lib/LaTeXML/resources/CSS");
$str .= list_files("lib/LaTeXML/resources/javascript");
$str .= list_files("lib/LaTeXML/resources/Profiles");
$str .= <<'HERE';
#==================================================
# Supported Packages
#==================================================
lib/LaTeXML/Package.pm
HERE
$str .= list_files("lib/LaTeXML/Package");
$str .= <<'HERE';
#==================================================
# TeX packages
#==================================================
HERE
$str .= list_files("lib/LaTeXML/texmf");
$str .= <<'HERE';
#==================================================
# Test Suite.
#==================================================
HERE
$str .= list_files("t");
$str .= "\n";
return $str; }
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
__END__
=head1 NAME
C<makemanifest> I<options>
=head1 SYNOPSIS
A tool to automagically regenerate the MANIFEST file for LaTeXML.
By default, this tool prints the new MANIFEST file to STDOUT.
Options:
--diff Instead of saving the new manifest file only produce a diff.
--quiet Be quiet, and do not print the new MANIFEST to STDOUT.
--save Store the newly generate MANIFEST file in the LaTeXML root
directory. Makes a copy of the old MANIFEST file and stores
it under MANIFEST.bak.
--help Show this help message
=cut
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|