-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #458 from CFD-GO/feature/format
Adding clang-format configuration and script
- Loading branch information
Showing
10 changed files
with
168 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,4 @@ p | |
/*.txt | ||
.idea/* | ||
*.ipynb_checkpoint* | ||
tools/.format/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
|
||
#ifndef REGION_H | ||
#include <stdio.h> | ||
#include "cross.h" | ||
class lbRegion { | ||
public: | ||
int dx,dy,dz; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#include <vector> | ||
#include <set> | ||
#include <math.h> | ||
#include "types.h" | ||
|
||
typedef int gr_addr_t; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
#include "pugixml.hpp" | ||
extern pugi::xml_document xml_def; | ||
int xml_def_init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
BasedOnStyle: Google | ||
ColumnLimit: 160 | ||
IndentWidth: 4 | ||
AllowShortBlocksOnASingleLine: Always | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: InlineOnly | ||
AllowShortIfStatementsOnASingleLine: Always | ||
DerivePointerAlignment: false | ||
PointerAlignment: Left | ||
BinPackArguments: false | ||
BinPackParameters: false | ||
ReflowComments: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#!/bin/bash | ||
|
||
set -o pipefail | ||
|
||
PP=$(dirname $0) | ||
FORMATFILE="$PP/.clang-format" | ||
PRINTSKIP=true | ||
|
||
function format { | ||
clang-format --style=file:$FORMATFILE \ | ||
| sed -E 's/for[[:blank:]]*[(]([[:alpha:]_]*[[:blank:]]|)[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*=[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*;[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*([<=]*)[[:blank:]]*([[:alnum:]_]+)[[:blank:]]*;[[:blank:]]*([[:alnum:]_]+)[+][+][[:blank:]]*\)/for (\1\2=\3; \4\5\6; \7++)/g' \ | ||
| sed -E 's| ([*/]) |\1|g' | ||
} | ||
|
||
function formatRT { | ||
R -s -e 'rtemplate::RTtokenize()' | format | R -s -e 'rtemplate::RTtokenize(inv=TRUE)' | ||
} | ||
|
||
function format_sel { | ||
if [[ -z "$1" || "$1" =~ \.[rR][tT]$ ]] | ||
then | ||
echo formatRT | ||
else | ||
echo format | ||
fi | ||
} | ||
|
||
function format_to { | ||
F="$(format_sel "$1")" | ||
if test -z "$1" || test -z "$2" | ||
then | ||
echo "Something went wrong in format_to" | ||
exit 5 | ||
fi | ||
mkdir -p $PP/.format | ||
NAMESUM=$(echo "$1 $2" | sha256sum | cut -c 1-30) | ||
SUMFILE="$PP/.format/$NAMESUM" | ||
if test -f "$SUMFILE" | ||
then | ||
if sha256sum --status --check "$SUMFILE" | ||
then | ||
$PRINTSKIP && echo "Skipping $1" | ||
return 0 | ||
fi | ||
fi | ||
if [[ "$1" == "$2" ]] | ||
then | ||
echo "Running $F on $1" | ||
else | ||
echo "Running $F on $1 -> $2" | ||
fi | ||
cat "$1" | $F >tmp | ||
mv tmp "$2" | ||
sha256sum "$1" "$2" "$FORMATFILE" >"$SUMFILE" | ||
} | ||
|
||
OUTFILE="" | ||
OUTSAME=false | ||
while test -n "$1" | ||
do | ||
case "$1" in | ||
--help) | ||
echo "" | ||
echo "$0 [--all] [-o output] [-x] [files]" | ||
echo "" | ||
echo " -o (--output) OUTPUT : put the formated output in OUTPUT" | ||
echo " -x (--overwrite) : put the formated output in the same file" | ||
echo " --all [FROM_DIR] [TO_DIR] : format all source files in DIR" | ||
echo "" | ||
exit 0; | ||
;; | ||
-o|--output) | ||
shift | ||
OUTFILE="$1" | ||
;; | ||
-x|--overwrite) | ||
OUTSAME=true | ||
;; | ||
-a|--all) | ||
shift | ||
FROM_DIR="src" | ||
if ! test -z "$1" | ||
then | ||
if ! test -d "$1" | ||
then | ||
echo "$1: not a directory" | ||
exit 3 | ||
fi | ||
FROM_DIR="$1" | ||
shift | ||
fi | ||
TO_DIR="$FROM_DIR" | ||
if ! test -z "$1" | ||
then | ||
if ! test -d "$1" | ||
then | ||
echo "$1: not a directory" | ||
exit 3 | ||
fi | ||
TO_DIR="$1" | ||
shift | ||
fi | ||
if test "$FROM_DIR" == "$TO_DIR" && ! $OUTSAME | ||
then | ||
echo "Trying to format all file into the same directory. If you want to overwrite say '-x'" | ||
exit 4 | ||
fi | ||
PRINTSKIP=false | ||
find "$FROM_DIR" | grep -E '[.](cpp|h|hpp)([.]Rt|)$' | while read i | ||
do | ||
if test "$FROM_DIR" == "$TO_DIR" | ||
then | ||
j="$i" | ||
else | ||
j="$TO_DIR/${i#$FROM_DIR}" | ||
fi | ||
format_to "$i" "$j" | ||
done | ||
;; | ||
-p|--pipe) | ||
formatRT | ||
;; | ||
-*) | ||
echo "Uknown option $1" | ||
exit 1; | ||
;; | ||
*) | ||
INFILE="$1" | ||
if $OUTSAME && test -z "$OUTFILE" | ||
then | ||
OUTFILE="$INFILE" | ||
fi | ||
if test -z $OUTFILE | ||
then | ||
cat "$INFILE" | $(format_sel "$INFILE") | ||
else | ||
format_to "$INFILE" "$OUTFILE" | ||
OUTFILE="" | ||
fi | ||
esac | ||
shift | ||
done | ||
|
||
exit 0 |