From d04a039bd01d7c72a94a34152821b00f5a121c5c Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Fri, 19 Aug 2016 11:14:56 -0400 Subject: [PATCH] Added comments --- process.pl | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/process.pl b/process.pl index 301dcab..545c4d8 100755 --- a/process.pl +++ b/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() { + # 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"; }