Added comments
This commit is contained in:
parent
5e02c12a82
commit
d04a039bd0
21
process.pl
21
process.pl
@ -5,35 +5,52 @@ use warnings;
|
||||
use File::Compare;
|
||||
use File::Basename;
|
||||
no warnings 'once';
|
||||
|
||||
# For every argument (file)
|
||||
foreach my $file (@ARGV) {
|
||||
# If it exists
|
||||
if (-e $file) {
|
||||
# Load the autoformatted data into $data
|
||||
my $data = process_file($file);
|
||||
open(MYOUTPUTFILE, "+>$file.bak") or die "Error opening output file $!";
|
||||
# Write the data to $file.bak
|
||||
#TODO: This could be done with no .bak
|
||||
print MYOUTPUTFILE $data;
|
||||
close(MYOUTPUTFILE);
|
||||
if (compare($file, "$file.bak") != 0) {
|
||||
# If there were changes, then tell the user
|
||||
print "Processed $file\n";
|
||||
}
|
||||
# Replace the original file with this file
|
||||
# Delete it
|
||||
unlink $file;
|
||||
# Overwrite the old one
|
||||
rename "$file.bak", $file;
|
||||
}
|
||||
|
||||
}
|
||||
# Creates the automatically formatted file
|
||||
sub process_file {
|
||||
my($filename) = "$_[0]";
|
||||
open(MYINPUTFILE, "<$filename") or die "x $!";
|
||||
# The formatted file
|
||||
my($data) = "";
|
||||
# Loop through every line in the file
|
||||
while(<MYINPUTFILE>) {
|
||||
# Get rid of trailing whitespace
|
||||
s/\s*$//;
|
||||
my($line) = $_;
|
||||
# If it is not a whitespace only line, append it to $data
|
||||
if($line !~ /^\s*$/) {
|
||||
$data = $data . "$line\n";
|
||||
}
|
||||
}
|
||||
close(MYINPUTFILE);
|
||||
# Get rid of final newline
|
||||
chomp($data);
|
||||
if ($data !~ /^\s*\/\*\*/) {
|
||||
# Get the basename of the file, this prevents making the block comment say:
|
||||
# @file src/folders/code.c
|
||||
# And instead uses
|
||||
# @file code.c
|
||||
my $basename = basename($filename);
|
||||
$data = "/**\n * \@file $basename\n * \@author Austen Adler (agadler)\n * TODO: Description\n */\n$data";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user