aboutsummaryrefslogtreecommitdiffstats
path: root/format-code
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-04-09 17:54:27 +0200
committerJay Berkenbilt <ejb@ql.org>2022-04-09 17:56:30 +0200
commitece6b6feb4ea82d82985c4820f1e88724d1b1aa8 (patch)
tree3d2a78b82eb05eb4fc6266518d60bedc7fcd9d79 /format-code
parent554a870b81c977c21303ef4eae4e5c4bf1b96e89 (diff)
downloadqpdf-ece6b6feb4ea82d82985c4820f1e88724d1b1aa8.tar.zst
Add format-code script
Diffstat (limited to 'format-code')
-rwxr-xr-xformat-code35
1 files changed, 35 insertions, 0 deletions
diff --git a/format-code b/format-code
new file mode 100755
index 00000000..5ec5275d
--- /dev/null
+++ b/format-code
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+# Formatting rules are in .clang-format.
+
+# To protect a block of code from automatic formatting, enclose in
+# comments such as
+#
+# // clang-format off
+# ...
+# // clang-format on
+
+# Sometimes, a comment of the form `// line-break` may appear in the
+# code to prevent clang-format from removing an intentional line
+# break.
+
+# For emacs users, the file `.dir-locals.el` configures cc-mode for an
+# indentation style that is close to but not exactly like what
+# clang-format produces. clang-format is authoritative.
+
+# Please see "Code Formatting" in the manual for additional notes.
+
+cd $(dirname $0)
+for i in $(find . -name 'build*' -prune -o '(' \
+ -name '*.hh' -o -name '*.h' -o -name '*.cc' -o -name '*.c' \
+ ')' -print); do
+ if clang-format < $i >| $i.new; then
+ if diff -q $i $i.new >/dev/null 2>/dev/null; then
+ echo "okay: $i"
+ rm $i.new
+ else
+ echo "updated: $i"
+ mv $i.new $i
+ fi
+ fi
+done