aboutsummaryrefslogtreecommitdiff
path: root/utils/add_include_guard.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xutils/add_include_guard.sh15
1 files changed, 15 insertions, 0 deletions
diff --git a/utils/add_include_guard.sh b/utils/add_include_guard.sh
new file mode 100755
index 0000000..7ca10db
--- /dev/null
+++ b/utils/add_include_guard.sh
@@ -0,0 +1,15 @@
1#!/bin/sh
2
3if [ -z "$1" ]; then
4 echo "Usage: $0 [file]"
5 exit 1
6fi
7
8guard="$(echo "$1" | sed 's/^\.\///' | tr 'a-z/.' 'A-Z__')"
9
10new_file="$1.adding_include_guard"
11printf '#ifndef %s\n#define %s\n\n' "$guard" "$guard" > "$new_file"
12cat "$1" >> "$new_file"
13printf '\n#endif /* %s */\n' "$guard" >> "$new_file"
14
15mv "$new_file" "$1"

Generated with cgit - Back to sebastiano.tronto.net