Skip to contentSkip to conversation

dev-tools: Add reformat-all.sh for code style unification

PATCH Superseded David Sommerseth 3 participants 6 messages Dec 14, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dev-tools: Add reformat-all.sh for code style unification

This script will run all files related to the currently checked out git branch through uncrustify using a standardized style configuration.

Due to a bug in uncrustify 0.63, it is needed to add a special treatment to one of the files at the moment. So this both pre- and post-patched before/after uncrustify is run. This is to simply to assure that all file processing will happen consistently each time.

Also added doc/doxygen/doc_key_generation.h to an ignore list, as it carries some specific Doxygen formatting we should be careful with. This file is anyhow not so critical and can be managed manually.

The src/compat/compat-lz4.[ch] files are also not touched, as they are based on upstream formatting. This makes it easier to update to a newer LZ4 version later on and even see what the differences are.

v2 - Include updated config from CodeStyle wiki page
Remove line lenght restriction for The Great Reformatting Update the script with improvements by krzee

---
 dev-tools/reformat-all.sh                          | 136 +++++++++++++++++++++
 .../after_include_openvpn-plugin.h.in.patch        |  13 ++
 .../before_include_openvpn-plugin.h.in.patch       |  13 ++
 dev-tools/special-files.lst                        |   4 +
 dev-tools/uncrustify.conf                          |  64 ++++++++++
 5 files changed, 230 insertions(+)
 create mode 100755 dev-tools/reformat-all.sh
 create mode 100644 dev-tools/reformat-patches/after_include_openvpn-plugin.h.in.patch
 create mode 100644 dev-tools/reformat-patches/before_include_openvpn-plugin.h.in.patch
 create mode 100644 dev-tools/special-files.lst
 create mode 100644 dev-tools/uncrustify.conf
dev-tools/reformat-all.sh new file +136 -0
new file mode 100755
index 0000000..11a6eca
@@ -0,0 +1,136 @@
+#!/bin/bash
+# reformat-all.sh - Reformat all git files in the checked out
+#                   git branch using uncrustify.
+#
+# Copyright (C) 2016 - David Sommerseth <[email protected]...>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+tstamp="$(date +%Y%m%d-%H%M%S)"
+files="$(pwd)/reformat-all_files-$tstamp.lst"
+log="$(pwd)/reformat-all_log-$tstamp.txt"
+
+srcroot="$(git rev-parse --show-toplevel)"
+cfg="$srcroot/dev-tools/uncrustify.conf"
+specialfiles="$srcroot/dev-tools/special-files.lst"
+
+export gitfiles=0
+export procfiles=0
+
+# Go to the root of the source tree
+pushd "$srcroot" > /dev/null
+
+{
+    echo -n "** Starting $0: "
+    date
+
+    # Find all C source/header files
+    git ls-files | grep -E ".*\.[ch](\.in$|$)" > "${files}.git"
+
+    # Manage files which needs special treatment
+    awk -F\# '{gsub("\n| ", "", $1); print $1}' "$specialfiles" > "${files}.sp"
+    while read srcfile
+    do
+        res=$(grep "$srcfile" "${files}.sp" 2>/dev/null)
+        if [ $? -ne 0 ]; then
+            # If grep didn't find the file among special files,
+            # process it normally
+            echo "$srcfile" >> "$files"
+        else
+            mode=$(echo "$res" | cut -d:  -f1)
+            case "$mode" in
+                E)
+                    echo "** INFO **  Excluding '$srcfile'"
+                    ;;
+                P)
+                    echo "** INFO **  Pre-patching '$srcfile'"
+                    patchfile="${srcroot}"/dev-tools/reformat-patches/before_$(echo "$srcfile" | tr "/" "_").patch
+                    if [ -r "$patchfile" ]; then
+                        git apply "$patchfile"
+                        if [ $? -ne 0 ]; then
+                            echo "** ERROR **  Failed to apply pre-patch file: $patchfile"
+                            exit 2
+                        fi
+                    else
+                        echo "** WARN ** Pre-patch file for $srcfile is missing: $patchfile"
+                    fi
+                    echo "$srcfile" >> "${files}.postpatch"
+                    echo "$srcfile" >> "$files"
+                    ;;
+                *)
+                    echo "** WARN ** Unknown mode '$mode' for file '$srcfile'"
+                    ;;
+            esac
+        fi
+    done < "${files}.git"
+    rm -f "${files}.git" "${files}.sp"
+
+    # Kick off uncrustify
+    echo "** INFO ** Running: uncrustify -c $cfg --no-backup -l C -p debug.uncr -F $files"
+    uncrustify -c "$cfg" --no-backup -l C -p debug.uncr -F "$files" 2>&1
+    res=$?
+    echo "** INFO ** Uncrustify completed"
+} | tee "${log}-1"  # Log needs to be closed here, to be processed in next block
+
+{
+    # Check the results
+    gitfiles=$(wc -l "$files" | cut -d\  -f1)
+    procfiles=$(grep "Parsing: " "${log}-1" | wc -l)
+    echo
+    echo "C source/header files checked into git: $gitfiles"
+    echo "Files processed by uncrustify:          $procfiles"
+    echo
+    # Post-Patch files modified after we uncrustify have adjusted them
+    if [ -r "${files}.postpatch" ]; then
+        while read srcfile;
+        do
+            patchfile="${srcroot}"/dev-tools/reformat-patches/after_$(echo "$srcfile" | tr "/" "_").patch
+            if [ -r "$patchfile" ]; then
+                echo "** INFO **  Post-patching '$srcfile'"
+                git apply "$patchfile"
+                if [ $? -ne 0 ]; then
+                    echo "** WARN ** Failed to apply $patchfile"
+                fi
+            else
+                echo "** WARN ** Post-patch file for $srcfile is missing: $patchfile"
+            fi
+        done < "${files}.postpatch"
+        rm -f "${files}.postpatch"
+    fi
+} | tee "${log}-2"
+
+cat "${log}-1" "${log}-2" > "$log"
+
+{
+    ec=1
+    if [ "$gitfiles" -eq "$procfiles" ]; then
+        echo "Reformatting completed successfully"
+        ec=0
+    else
+        last=$(tail -n1 "${log}-1")
+        echo
+        echo "** ERROR ** Reformating failed to process all files."
+        echo "            uncrustify exit code: $res"
+        echo "            Last log line: $last"
+        echo
+    fi
+    rm -f "${log}-1" "${log}-2"
+} | tee -a "$log"
+rm -f "${files}"
+
+popd > /dev/null
+
+exit $ec
dev-tools/reformat-patches/after_include_openvpn-plugin.h.in.patch new file +13 -0
new file mode 100644
index 0000000..4faa4d8
@@ -0,0 +1,13 @@
+diff --git a/include/openvpn-plugin.h.in b/include/openvpn-plugin.h.in
+index 05bffab..05b4b6a 100644
+--- a/include/openvpn-plugin.h.in
++++ b/include/openvpn-plugin.h.in
+@@ -169,7 +169,7 @@ typedef void *openvpn_plugin_handle_t;
+ /*
+  * We are compiling OpenVPN.
+  */
+-/* #define OPENVPN_PLUGIN_DEF        typedef */
++#define OPENVPN_PLUGIN_DEF        typedef
+ #define OPENVPN_PLUGIN_FUNC(name) (*name)
+ 
+ #else  /* ifdef OPENVPN_PLUGIN_H */
dev-tools/reformat-patches/before_include_openvpn-plugin.h.in.patch new file +13 -0
new file mode 100644
index 0000000..7c7249d
@@ -0,0 +1,13 @@
+diff --git a/include/openvpn-plugin.h.in b/include/openvpn-plugin.h.in
+index 34ad18b..f4c5472 100644
+--- a/include/openvpn-plugin.h.in
++++ b/include/openvpn-plugin.h.in
+@@ -169,7 +169,7 @@ typedef void *openvpn_plugin_handle_t;
+ /*
+  * We are compiling OpenVPN.
+  */
+-#define OPENVPN_PLUGIN_DEF        typedef
++// #define OPENVPN_PLUGIN_DEF        typedef
+ #define OPENVPN_PLUGIN_FUNC(name) (*name)
+ 
+ #else
dev-tools/special-files.lst new file +4 -0
new file mode 100644
index 0000000..f3f77ea
@@ -0,0 +1,4 @@
+E:doc/doxygen/doc_key_generation.h     # @verbatim section gets mistreated, exclude it
+E:src/compat/compat-lz4.c              # Preserve LZ4 upstream formatting
+E:src/compat/compat-lz4.h              # Preserve LZ4 upstream formatting
+P:include/openvpn-plugin.h.in          # uncrustify segfaults, patch it before+after
dev-tools/uncrustify.conf new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw

dev-tools/uncrustify.conf line 6

Quoted 9 lines · David Sommerseth

+++ b/dev-tools/uncrustify.conf

dev-tools/uncrustify.conf new file +6 -0
@@ -0,0 +1,64 @@
+# Use Allman-style
+indent_columns=4
+indent_braces=false
+indent_else_if=false
+indent_switch_case=4
+indent_label=1nl_if_brace=add

What happened there? Is it my mailer or a newline missing?

Selva

#2 lore raw
In reply to David Sommerseth

Hi,

Quoted 1 line · David Sommerseth

Due to a bug in uncrustify 0.63

Should be 0.64.

dev-tools/reformat-all.sh line 1

Quoted 7 lines
dev-tools/reformat-all.sh new file +1 -0
new file mode 100755
index 0000000..11a6eca
@@ -0,0 +1,136 @@
+#!/bin/bash

If you replace the pushd/popd with a subshell, /bin.sh suffices (sligtly more portable).

And, it's a good habit to start shell scripts with set -eu, to make sure you exit on failures, and don't use uninitialised variables.

Finally, git complains about whitespace errors:

Applying: dev-tools: Add reformat-all.sh for code style unification .git/rebase-apply/patch:173: trailing whitespace.

.git/rebase-apply/patch:192: trailing whitespace.

warning: 2 lines add whitespace errors.

Other than these details (and what Selva mailed), the patch looks good.

-Steffan

#3 lore raw

PATCH v3 1/1 dev-tools: Add reformat-all.sh for code style unification

In reply to David Sommerseth

This script will run all files related to the currently checked out git branch through uncrustify using a standardized style configuration.

Due to a bug in uncrustify 0.64, it is needed to add a special treatment to one of the files at the moment. So this both pre- and post-patched before/after uncrustify is run. This is to simply to assure that all file processing will happen consistently each time.

Also added doc/doxygen/doc_key_generation.h to an ignore list, as it carries some specific Doxygen formatting we should be careful with. This file is anyhow not so critical and can be managed manually.

The src/compat/compat-lz4.[ch] files are also not touched, as they are based on upstream formatting. This makes it easier to update to a newer LZ4 version later on and even see what the differences are.

v2 - Include updated config from CodeStyle wiki page
Remove line lenght restriction for The Great Reformatting Update the script with improvements by krzee

v3 - Update with a fixed config from the CodeStyle wiki page
Corrected a typo in the commit message (0.63->0.64) Minor changes to the reformat script (no pushd/popd, some new lines moved around)

---
 dev-tools/reformat-all.sh                          | 136 +++++++++++++++++++++
 .../after_include_openvpn-plugin.h.in.patch        |  13 ++
 .../before_include_openvpn-plugin.h.in.patch       |  13 ++
 dev-tools/special-files.lst                        |   4 +
 dev-tools/uncrustify.conf                          |  65 ++++++++++
 5 files changed, 231 insertions(+)
 create mode 100755 dev-tools/reformat-all.sh
 create mode 100644 dev-tools/reformat-patches/after_include_openvpn-plugin.h.in.patch
 create mode 100644 dev-tools/reformat-patches/before_include_openvpn-plugin.h.in.patch
 create mode 100644 dev-tools/special-files.lst
 create mode 100644 dev-tools/uncrustify.conf
dev-tools/reformat-all.sh new file +136 -0
new file mode 100755
index 0000000..ac5cf6f
@@ -0,0 +1,136 @@
+#!/bin/bash
+# reformat-all.sh - Reformat all git files in the checked out
+#                   git branch using uncrustify.
+#
+# Copyright (C) 2016 - David Sommerseth <[email protected]...>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+tstamp="$(date +%Y%m%d-%H%M%S)"
+files="$(pwd)/reformat-all_files-$tstamp.lst"
+log="$(pwd)/reformat-all_log-$tstamp.txt"
+
+srcroot="$(git rev-parse --show-toplevel)"
+cfg="$srcroot/dev-tools/uncrustify.conf"
+specialfiles="$srcroot/dev-tools/special-files.lst"
+
+export gitfiles=0
+export procfiles=0
+
+# Go to the root of the source tree
+cd "$srcroot"
+
+{
+    echo -n "** Starting $0: "
+    date
+
+    # Find all C source/header files
+    git ls-files | grep -E ".*\.[ch](\.in$|$)" > "${files}.git"
+
+    # Manage files which needs special treatment
+    awk -F\# '{gsub("\n| ", "", $1); print $1}' "$specialfiles" > "${files}.sp"
+    while read srcfile
+    do
+        res=$(grep "$srcfile" "${files}.sp" 2>/dev/null)
+        if [ $? -ne 0 ]; then
+            # If grep didn't find the file among special files,
+            # process it normally
+            echo "$srcfile" >> "$files"
+        else
+            mode=$(echo "$res" | cut -d:  -f1)
+            case "$mode" in
+                E)
+                    echo "** INFO **  Excluding '$srcfile'"
+                    ;;
+                P)
+                    echo "** INFO **  Pre-patching '$srcfile'"
+                    patchfile="${srcroot}"/dev-tools/reformat-patches/before_$(echo "$srcfile" | tr "/" "_").patch
+                    if [ -r "$patchfile" ]; then
+                        git apply "$patchfile"
+                        if [ $? -ne 0 ]; then
+                            echo "** ERROR **  Failed to apply pre-patch file: $patchfile"
+                            exit 2
+                        fi
+                    else
+                        echo "** WARN ** Pre-patch file for $srcfile is missing: $patchfile"
+                    fi
+                    echo "$srcfile" >> "${files}.postpatch"
+                    echo "$srcfile" >> "$files"
+                    ;;
+                *)
+                    echo "** WARN ** Unknown mode '$mode' for file '$srcfile'"
+                    ;;
+            esac
+        fi
+    done < "${files}.git"
+    rm -f "${files}.git" "${files}.sp"
+
+    # Kick off uncrustify
+    echo
+    echo "** INFO ** Running: uncrustify -c $cfg --no-backup -l C -p debug.uncr -F $files"
+    uncrustify -c "$cfg" --no-backup -l C -p debug.uncr -F "$files" 2>&1
+    res=$?
+    echo "** INFO ** Uncrustify completed (exit code $res)"
+} | tee "${log}-1"  # Log needs to be closed here, to be processed in next block
+
+{
+    # Check the results
+    gitfiles=$(wc -l "$files" | cut -d\  -f1)
+    procfiles=$(grep "Parsing: " "${log}-1" | wc -l)
+    echo
+    echo "C source/header files checked into git: $gitfiles"
+    echo "Files processed by uncrustify:          $procfiles"
+    echo
+
+    # Post-Patch files modified after we uncrustify have adjusted them
+    if [ -r "${files}.postpatch" ]; then
+        while read srcfile;
+        do
+            patchfile="${srcroot}"/dev-tools/reformat-patches/after_$(echo "$srcfile" | tr "/" "_").patch
+            if [ -r "$patchfile" ]; then
+                echo "** INFO **  Post-patching '$srcfile'"
+                git apply "$patchfile"
+                if [ $? -ne 0 ]; then
+                    echo "** WARN ** Failed to apply $patchfile"
+                fi
+            else
+                echo "** WARN ** Post-patch file for $srcfile is missing: $patchfile"
+            fi
+        done < "${files}.postpatch"
+        rm -f "${files}.postpatch"
+    fi
+} | tee "${log}-2" # Log needs to be closed here, to be processed in next block
+
+cat "${log}-1" "${log}-2" > "$log"
+
+{
+    ec=1
+    echo
+    if [ "$gitfiles" -eq "$procfiles" ]; then
+        echo "Reformatting completed successfully"
+        ec=0
+    else
+        last=$(tail -n1 "${log}-1")
+        echo "** ERROR ** Reformating failed to process all files."
+        echo "            uncrustify exit code: $res"
+        echo "            Last log line: $last"
+        echo
+    fi
+    rm -f "${log}-1" "${log}-2"
+} | tee -a "$log"
+rm -f "${files}"
+
+exit $ec
dev-tools/reformat-patches/after_include_openvpn-plugin.h.in.patch new file +13 -0
new file mode 100644
index 0000000..4faa4d8
@@ -0,0 +1,13 @@
+diff --git a/include/openvpn-plugin.h.in b/include/openvpn-plugin.h.in
+index 05bffab..05b4b6a 100644
+--- a/include/openvpn-plugin.h.in
++++ b/include/openvpn-plugin.h.in
+@@ -169,7 +169,7 @@ typedef void *openvpn_plugin_handle_t;
+ /*
+  * We are compiling OpenVPN.
+  */
+-/* #define OPENVPN_PLUGIN_DEF        typedef */
++#define OPENVPN_PLUGIN_DEF        typedef
+ #define OPENVPN_PLUGIN_FUNC(name) (*name)
+ 
+ #else  /* ifdef OPENVPN_PLUGIN_H */
dev-tools/reformat-patches/before_include_openvpn-plugin.h.in.patch new file +13 -0
new file mode 100644
index 0000000..7c7249d
@@ -0,0 +1,13 @@
+diff --git a/include/openvpn-plugin.h.in b/include/openvpn-plugin.h.in
+index 34ad18b..f4c5472 100644
+--- a/include/openvpn-plugin.h.in
++++ b/include/openvpn-plugin.h.in
+@@ -169,7 +169,7 @@ typedef void *openvpn_plugin_handle_t;
+ /*
+  * We are compiling OpenVPN.
+  */
+-#define OPENVPN_PLUGIN_DEF        typedef
++// #define OPENVPN_PLUGIN_DEF        typedef
+ #define OPENVPN_PLUGIN_FUNC(name) (*name)
+ 
+ #else
dev-tools/special-files.lst new file +4 -0
new file mode 100644
index 0000000..f3f77ea
@@ -0,0 +1,4 @@
+E:doc/doxygen/doc_key_generation.h     # @verbatim section gets mistreated, exclude it
+E:src/compat/compat-lz4.c              # Preserve LZ4 upstream formatting
+E:src/compat/compat-lz4.h              # Preserve LZ4 upstream formatting
+P:include/openvpn-plugin.h.in          # uncrustify segfaults, patch it before+after
dev-tools/uncrustify.conf new file +65 -0

65 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#4 lore raw

Hi,

Quoted 46 lines · David Sommerseth

This script will run all files related to the currently checked out git branch through uncrustify using a standardized style configuration.

Due to a bug in uncrustify 0.64, it is needed to add a special treatment to one of the files at the moment. So this both pre- and post-patched before/after uncrustify is run. This is to simply to assure that all file processing will happen consistently each time.

Also added doc/doxygen/doc_key_generation.h to an ignore list, as it carries some specific Doxygen formatting we should be careful with. This file is anyhow not so critical and can be managed manually.

The src/compat/compat-lz4.[ch] files are also not touched, as they are based on upstream formatting. This makes it easier to update to a newer LZ4 version later on and even see what the differences are.

v2 - Include updated config from CodeStyle wiki page
Remove line lenght restriction for The Great Reformatting Update the script with improvements by krzee

v3 - Update with a fixed config from the CodeStyle wiki page
Corrected a typo in the commit message (0.63->0.64) Minor changes to the reformat script (no pushd/popd, some new lines moved around)

---
 dev-tools/reformat-all.sh                          | 136 +++++++++++++++++++++
 .../after_include_openvpn-plugin.h.in.patch        |  13 ++
 .../before_include_openvpn-plugin.h.in.patch       |  13 ++
 dev-tools/special-files.lst                        |   4 +
 dev-tools/uncrustify.conf                          |  65 ++++++++++
 5 files changed, 231 insertions(+)
 create mode 100755 dev-tools/reformat-all.sh
 create mode 100644 dev-tools/reformat-patches/after_include_openvpn-plugin.h.in.patch
 create mode 100644 dev-tools/reformat-patches/before_include_openvpn-plugin.h.in.patch
 create mode 100644 dev-tools/special-files.lst
 create mode 100644 dev-tools/uncrustify.conf
dev-tools/reformat-all.sh new file +0 -0
new file mode 100755
index 0000000..ac5cf6f

dev-tools/reformat-all.sh line 1

Quoted 1 line
dev-tools/reformat-all.sh new file +1 -0
@@ -0,0 +1,136 @@
+#!/bin/bash

Just tested, works fine when using /bin/sh too (on Ubuntu, so dash).

Quoted 245 lines
dev-tools/reformat-all.sh new file +135 -0
+# reformat-all.sh - Reformat all git files in the checked out
+#                   git branch using uncrustify.
+#
+# Copyright (C) 2016 - David Sommerseth <[email protected]...>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+tstamp="$(date +%Y%m%d-%H%M%S)"
+files="$(pwd)/reformat-all_files-$tstamp.lst"
+log="$(pwd)/reformat-all_log-$tstamp.txt"
+
+srcroot="$(git rev-parse --show-toplevel)"
+cfg="$srcroot/dev-tools/uncrustify.conf"
+specialfiles="$srcroot/dev-tools/special-files.lst"
+
+export gitfiles=0
+export procfiles=0
+
+# Go to the root of the source tree
+cd "$srcroot"
+
+{
+    echo -n "** Starting $0: "
+    date
+
+    # Find all C source/header files
+    git ls-files | grep -E ".*\.[ch](\.in$|$)" > "${files}.git"
+
+    # Manage files which needs special treatment
+    awk -F\# '{gsub("\n| ", "", $1); print $1}' "$specialfiles" > "${files}.sp"
+    while read srcfile
+    do
+        res=$(grep "$srcfile" "${files}.sp" 2>/dev/null)
+        if [ $? -ne 0 ]; then
+            # If grep didn't find the file among special files,
+            # process it normally
+            echo "$srcfile" >> "$files"
+        else
+            mode=$(echo "$res" | cut -d:  -f1)
+            case "$mode" in
+                E)
+                    echo "** INFO **  Excluding '$srcfile'"
+                    ;;
+                P)
+                    echo "** INFO **  Pre-patching '$srcfile'"
+                    patchfile="${srcroot}"/dev-tools/reformat-patches/before_$(echo "$srcfile" | tr "/" "_").patch
+                    if [ -r "$patchfile" ]; then
+                        git apply "$patchfile"
+                        if [ $? -ne 0 ]; then
+                            echo "** ERROR **  Failed to apply pre-patch file: $patchfile"
+                            exit 2
+                        fi
+                    else
+                        echo "** WARN ** Pre-patch file for $srcfile is missing: $patchfile"
+                    fi
+                    echo "$srcfile" >> "${files}.postpatch"
+                    echo "$srcfile" >> "$files"
+                    ;;
+                *)
+                    echo "** WARN ** Unknown mode '$mode' for file '$srcfile'"
+                    ;;
+            esac
+        fi
+    done < "${files}.git"
+    rm -f "${files}.git" "${files}.sp"
+
+    # Kick off uncrustify
+    echo
+    echo "** INFO ** Running: uncrustify -c $cfg --no-backup -l C -p debug.uncr -F $files"
+    uncrustify -c "$cfg" --no-backup -l C -p debug.uncr -F "$files" 2>&1
+    res=$?
+    echo "** INFO ** Uncrustify completed (exit code $res)"
+} | tee "${log}-1"  # Log needs to be closed here, to be processed in next block
+
+{
+    # Check the results
+    gitfiles=$(wc -l "$files" | cut -d\  -f1)
+    procfiles=$(grep "Parsing: " "${log}-1" | wc -l)
+    echo
+    echo "C source/header files checked into git: $gitfiles"
+    echo "Files processed by uncrustify:          $procfiles"
+    echo
+
+    # Post-Patch files modified after we uncrustify have adjusted them
+    if [ -r "${files}.postpatch" ]; then
+        while read srcfile;
+        do
+            patchfile="${srcroot}"/dev-tools/reformat-patches/after_$(echo "$srcfile" | tr "/" "_").patch
+            if [ -r "$patchfile" ]; then
+                echo "** INFO **  Post-patching '$srcfile'"
+                git apply "$patchfile"
+                if [ $? -ne 0 ]; then
+                    echo "** WARN ** Failed to apply $patchfile"
+                fi
+            else
+                echo "** WARN ** Post-patch file for $srcfile is missing: $patchfile"
+            fi
+        done < "${files}.postpatch"
+        rm -f "${files}.postpatch"
+    fi
+} | tee "${log}-2" # Log needs to be closed here, to be processed in next block
+
+cat "${log}-1" "${log}-2" > "$log"
+
+{
+    ec=1
+    echo
+    if [ "$gitfiles" -eq "$procfiles" ]; then
+        echo "Reformatting completed successfully"
+        ec=0
+    else
+        last=$(tail -n1 "${log}-1")
+        echo "** ERROR ** Reformating failed to process all files."
+        echo "            uncrustify exit code: $res"
+        echo "            Last log line: $last"
+        echo
+    fi
+    rm -f "${log}-1" "${log}-2"
+} | tee -a "$log"
+rm -f "${files}"
+
+exit $ec
dev-tools/reformat-patches/after_include_openvpn-plugin.h.in.patch new file +13 -0
new file mode 100644
index 0000000..4faa4d8
@@ -0,0 +1,13 @@
+diff --git a/include/openvpn-plugin.h.in b/include/openvpn-plugin.h.in
+index 05bffab..05b4b6a 100644
+--- a/include/openvpn-plugin.h.in
++++ b/include/openvpn-plugin.h.in
+@@ -169,7 +169,7 @@ typedef void *openvpn_plugin_handle_t;
+ /*
+  * We are compiling OpenVPN.
+  */
+-/* #define OPENVPN_PLUGIN_DEF        typedef */
++#define OPENVPN_PLUGIN_DEF        typedef
+ #define OPENVPN_PLUGIN_FUNC(name) (*name)
+ 
+ #else  /* ifdef OPENVPN_PLUGIN_H */
dev-tools/reformat-patches/before_include_openvpn-plugin.h.in.patch new file +13 -0
new file mode 100644
index 0000000..7c7249d
@@ -0,0 +1,13 @@
+diff --git a/include/openvpn-plugin.h.in b/include/openvpn-plugin.h.in
+index 34ad18b..f4c5472 100644
+--- a/include/openvpn-plugin.h.in
++++ b/include/openvpn-plugin.h.in
+@@ -169,7 +169,7 @@ typedef void *openvpn_plugin_handle_t;
+ /*
+  * We are compiling OpenVPN.
+  */
+-#define OPENVPN_PLUGIN_DEF        typedef
++// #define OPENVPN_PLUGIN_DEF        typedef
+ #define OPENVPN_PLUGIN_FUNC(name) (*name)
+ 
+ #else
dev-tools/special-files.lst new file +4 -0
new file mode 100644
index 0000000..f3f77ea
@@ -0,0 +1,4 @@
+E:doc/doxygen/doc_key_generation.h     # @verbatim section gets mistreated, exclude it
+E:src/compat/compat-lz4.c              # Preserve LZ4 upstream formatting
+E:src/compat/compat-lz4.h              # Preserve LZ4 upstream formatting
+P:include/openvpn-plugin.h.in          # uncrustify segfaults, patch it before+after
dev-tools/uncrustify.conf new file +55 -0
new file mode 100644
index 0000000..95e0b2a
@@ -0,0 +1,65 @@
+# Use Allman-style
+indent_columns=4
+indent_braces=false
+indent_else_if=false
+indent_switch_case=4
+indent_label=1
+nl_if_brace=add
+nl_brace_else=add
+nl_elseif_brace=add
+nl_else_brace=add
+nl_else_if=remove
+sp_func_proto_paren=Remove
+sp_func_def_paren=Remove
+sp_func_call_paren=Remove
+sp_sizeof_paren=Remove
+
+# No tabs, spaces only
+indent_with_tabs=0
+align_with_tabs=false
+cmt_convert_tab_to_spaces=true
+
+# Do not put spaces between the # and preprocessor statements
+pp_space=remove
+
+# Various whitespace fiddling
+sp_assign=add
+sp_before_sparen=add
+sp_inside_sparen=remove
+sp_cond_colon=add
+sp_cond_question=add
+sp_bool=add
+sp_else_brace=add
+sp_brace_else=add
+pos_arith=Lead
+pos_bool=Lead
+nl_func_type_name=add
+nl_before_case=true
+nl_assign_leave_one_liners=true
+nl_enum_leave_one_liners=true
+nl_brace_fparen=add
+nl_max=4
+nl_after_func_proto=2
+
+# Always use scoping braces for conditionals
+mod_full_brace_if=add
+mod_full_brace_if_chain=false
+
+# Annotate #else and #endif statements
+mod_add_long_ifdef_endif_comment=20
+mod_add_long_ifdef_else_comment=5
+
+# Misc cleanup
+mod_remove_extra_semicolon=true
+
+# Use C-style comments (/* .. */)

dev-tools/uncrustify.conf line 65

Quoted 10 lines
dev-tools/uncrustify.conf new file +10 -0
+cmt_c_nl_end=true
+cmt_star_cont=true
+cmt_cpp_to_c=true
+
+# Use "char **a"-style pointer stars/dereferences
+sp_before_ptr_star=Add
+sp_between_ptr_star=Remove
+sp_after_ptr_star=Remove
+sp_before_byref=Add
+sp_after_byref=Remove

Otherwise everything looks good now. If you change the /bin/bash to /bin/sh when committing, ACK.

-Steffan

#5 lore raw
In reply to David Sommerseth

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Did a quick change at commit time, changing from bash to sh

Your patch has been applied to the master branch.

commit 2417d55c4945d491e528dd0e4cf24047da5ceae9

Author: David Sommerseth
Date:   Wed Dec 14 22:05:00 2016 +0100
     dev-tools: Add reformat-all.sh for code style unification

     Signed-off-by: David Sommerseth <[email protected]...>
     Acked-by: Steffan Karger <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://www.mail-archive.com/search?l=mid&[email protected]...

- --
kind regards,

David Sommerseth

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBAgAGBQJYUbmjAAoJEIbPlEyWcf3yKokP/2ODlMt5zj+8BD4nNPup/SNN 5h236L8Rm9VE13lYZxPECYGmTQNML94qAnxcew0T/KCAeRKtprUbR4FlfEwWaC+E eH38inXz6Gcho8BqUuq4dRHspR+A15NQkRS5Vpa7RTGJKQRUFLbFAWb1Jqacl+Gk 7qGE9CypkncYMT5OsdZ13q4o5bgy2yO6b3wKVt2Ah7tkUzcqmswIglk4Fb44Zo48 ZraTaXNtxtImLkrcqrwI/7YFlPuTMbBtg/wAQ3fUNMfnLorGMdD6I9L1vlVwWv56 RPJIBcK0lDKJk0+m2YDWDvP7bYTZ+kOw5Arkv2sp2/0Rp5Cr8O4XtVFMz1ZTntmW s99/ZG9RO5Ln4DWeoz6cpHfTXcZrI3ltkG8q+gDbTFfocQsnW4LPLmUYhkB0lHlv UgdNhBqzvuYWUjoh7Jr423qjNaUAkcpNrFt7kW7VI4gpsYO1bzt87zUKqMrqfE/s cJIgHkJT6INjvOJiAxqMPbJLpUejoRCzZifNqwNg/X9d1czJF1z/K7NZ4bmNQuPN Z4fZbEMW88GrljcQfm4qLFwrsOKo/RWL+2AJS3JcXN3YFc8pCBs73i7iSWYQKt05 Xl1CSWV93aUo+rEyJnP436iVPb4GGfjgLkfJU4QYFvDzT1TdvigDmPOG+u011cyd LVG0zfLepzQmHSoEnCsF
=dwj/
-----END PGP SIGNATURE-----