-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-config-from-file.sh
executable file
·57 lines (50 loc) · 1.31 KB
/
make-config-from-file.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
#
# Convert a file into a #defined string using bourne shell and awk.
#
# Check if the awk interpreter is available.
awk -- '' </dev/null >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "This script depends on awk, which I cannot find" 1>&2
exit 1
fi
# Check that the SYMBOL name to use was specified.
if [ "$#" -lt 1 ]
then
echo "usage: $0 SYMBOL [file(s)]" 1>&2
exit 1
fi
# Extract the SYMBOL name from the command line.
SYMBOL=$1
shift
# Process each specified file, or standard input.
awk -v "SYMBOL=$SYMBOL" -- '
BEGIN {
printf("// This file is automatically generated - dont edit it\n");
printf("#include \"Config.hpp\"\n");
printf("class Config%s\n", SYMBOL);
printf("{\n");
printf("public:\n");
printf(" Config%s() { Config::instance().registerDefaultConfig(\"%s\", config); }\n", SYMBOL, SYMBOL);
printf(" static Config%s instance;\n", SYMBOL);
printf(" static const char *config;\n");
printf("};\n");
printf("Config%s Config%s::instance;\n", SYMBOL, SYMBOL);
printf("const char *Config%s::config =\n", SYMBOL);
last = "who-there";
seenFirst = 0;
}
// {
gsub("\"", "\\\"");
if (seenFirst != 0)
{
printf("\"%s\\n\"\\\n", last);
}
last = $0;
seenFirst = 1;
}
END {
printf("\"%s\\n\";\n", last);
}' "$@"
exit $?