3 # Usage: manisort [-q] [-o outfile] [filename]
5 # Without 'filename', looks for MANIFEST in the current dir.
6 # With '-o outfile', writes the sorted MANIFEST to the specified file.
7 # Prints the result of the sort to stderr. '-q' silences this.
8 # The exit code for the script is the sort result status
9 # (i.e., 0 means already sorted properly, 1 means not properly sorted)
15 # Get command line options
17 require "./Porting/manifest_lib.pl";
21 GetOptions ('output=s' => \$outfile,
22 'check' => \$check_only,
25 my $file = (@ARGV) ? shift : 'MANIFEST';
27 # Read in the MANIFEST file
28 open(my $IN, '<', $file)
29 or die("Can't read '$file': $!");
31 close($IN) or die($!);
34 my %seen= ( '' => 1 ); # filter out blank lines
35 my @sorted = grep { !$seen{$_}++ }
36 sort_manifest(@manifest)
39 # Check if the file is sorted or not
41 for (my $ii = 0; $ii < $#manifest; $ii++) {
42 next if ($manifest[$ii] eq $sorted[$ii]);
43 $exit_code = 1; # Not sorted
48 if (defined($outfile)) {
49 open(my $OUT, '>', $outfile)
50 or die("Can't open output file '$outfile': $!");
52 print($OUT join("\n", @sorted), "\n");
53 close($OUT) or die($!);
56 # Report on sort results
57 printf(STDERR "'$file' is%s sorted properly\n",
58 (($exit_code) ? ' NOT' : '')) if (! $quiet);
60 # Exit with the sort results status