aboutsummaryrefslogtreecommitdiff
path: root/utils/add_include_guard.sh
blob: 7ca10db593635e60435870e126c6247d58fb54f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/sh

if [ -z "$1" ]; then
	echo "Usage: $0 [file]"
	exit 1
fi

guard="$(echo "$1" | sed 's/^\.\///' | tr 'a-z/.' 'A-Z__')"

new_file="$1.adding_include_guard"
printf '#ifndef %s\n#define %s\n\n' "$guard" "$guard" > "$new_file"
cat "$1" >> "$new_file"
printf '\n#endif /* %s */\n' "$guard" >> "$new_file"

mv "$new_file" "$1"

Generated with cgit - Back to sebastiano.tronto.net