Created version 1, will autoformat, strip blank lines and trailing whitespace
This commit is contained in:
parent
f3f660da21
commit
6150318600
27
autoformat.sh
Executable file
27
autoformat.sh
Executable file
@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/zsh
|
||||||
|
# Format all c files
|
||||||
|
GLOB=( **/*.c )
|
||||||
|
# Astyle options:
|
||||||
|
# --mode=c : c formatting
|
||||||
|
# -xc : Brace attached to class names
|
||||||
|
# --style=stroustrup : stroustrup style (similar to 1tbs)
|
||||||
|
# -j : Always add brackets (even on one line if statements)
|
||||||
|
# -s2 : Three spaces
|
||||||
|
# -xG : Indent modifiers
|
||||||
|
# -S : Indent switches
|
||||||
|
# -K : Indent cases
|
||||||
|
# -N : Indent namespaces
|
||||||
|
# -xn : Attach bracket to namespace
|
||||||
|
# -xl : Attach inlines
|
||||||
|
# -n : Don't make a backup
|
||||||
|
# -p : Pad operators
|
||||||
|
# -H : Pad header (space after if, for, while)
|
||||||
|
OPTS=( --mode=c -xc --style=stroustrup -j -s2 -xG -S -K -N -xn -xl -n -p -H )
|
||||||
|
# Process the c files by adding the comment and removing newlines
|
||||||
|
perl "${0:h}/process.pl" $GLOB
|
||||||
|
# Colorize output if you can
|
||||||
|
if which colout>/dev/null; then
|
||||||
|
astyle $OPTS $GLOB|\grep -P '^(?!Unchanged)'|colout '(Formatted)' green||true
|
||||||
|
else
|
||||||
|
astyle $OPTS $GLOB|\grep -P '^(?!Unchanged)'||true
|
||||||
|
fi
|
41
process.pl
Executable file
41
process.pl
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/perl
|
||||||
|
use strict;
|
||||||
|
use autodie;
|
||||||
|
use warnings;
|
||||||
|
use File::Compare;
|
||||||
|
use File::Basename;
|
||||||
|
no warnings 'once';
|
||||||
|
|
||||||
|
foreach my $file (@ARGV) {
|
||||||
|
if (-e $file) {
|
||||||
|
my $data = process_file($file);
|
||||||
|
open(MYOUTPUTFILE, "+>$file.bak") or die "Error opening output file $!";
|
||||||
|
print MYOUTPUTFILE $data;
|
||||||
|
close(MYOUTPUTFILE);
|
||||||
|
if (compare($file, "$file.bak") != 0) {
|
||||||
|
print "Processed $file\n";
|
||||||
|
}
|
||||||
|
unlink $file;
|
||||||
|
rename "$file.bak", $file;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
sub process_file {
|
||||||
|
my($filename) = "$_[0]";
|
||||||
|
open(MYINPUTFILE, "<$filename") or die "x $!";
|
||||||
|
my($data) = "";
|
||||||
|
while(<MYINPUTFILE>) {
|
||||||
|
s/\s*$//;
|
||||||
|
my($line) = $_;
|
||||||
|
if($line !~ /^\s*$/) {
|
||||||
|
$data = $data . "$line\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(MYINPUTFILE);
|
||||||
|
chomp($data);
|
||||||
|
if ($data !~ /^\s*\/\*\*/) {
|
||||||
|
my $basename = basename($filename);
|
||||||
|
$data = "/**\n * \@file $basename\n * \@author Austen Adler (agadler)\n * TODO: Description\n */\n$data";
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user