aboutsummaryrefslogtreecommitdiff
path: root/misc/make_nn.bash
diff options
context:
space:
mode:
Diffstat (limited to 'misc/make_nn.bash')
-rwxr-xr-xmisc/make_nn.bash94
1 files changed, 94 insertions, 0 deletions
diff --git a/misc/make_nn.bash b/misc/make_nn.bash
new file mode 100755
index 000000000..e994fc4d8
--- /dev/null
+++ b/misc/make_nn.bash
@@ -0,0 +1,94 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et tw=0 :
+
+echo -n "/* vim"
+echo ": set ro : */"
+echo
+echo "/* ******************************************************** */"
+echo "/* THIS IS A GENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY */"
+echo "/* ******************************************************** */"
+
+what_to_make=${1}
+shift
+
+include_cc() {
+ if [[ "${what_to_make}" == "--source" ]] ; then
+ echo
+ cat
+ echo
+ fi
+}
+
+include_hh() {
+ if [[ "${what_to_make}" == "--header" ]] ; then
+ echo
+ cat
+ echo
+ fi
+}
+
+use_namespace() {
+ if [[ "${what_to_make}" == "--source" ]] ; then
+ echo "using namespace $1;"
+ fi
+}
+
+if ! source ${1} ; then
+ echo "source ${1} failed" 1>&2
+ exit 7
+fi
+
+set | grep '^make_nn_.*() $' | sort -r | \
+while read name ; do
+ name=${name##make_nn_}
+ name=${name%% *}
+
+ if [[ "${what_to_make}" == "--header" ]] ; then
+ namespace() {
+ a=${1//::/ }
+ echo
+ for ns in ${a}; do
+ echo "${indent}namespace ${ns}"
+ echo "${indent}{"
+ indent+=" "
+ done
+
+ echo "${indent}template <typename>"
+ echo "${indent}struct ${name};"
+ }
+
+ name() {
+ class=$1
+ echo
+ echo "${indent}template<>"
+ echo "${indent}struct ${name}<${class}>"
+ echo "${indent}{"
+ echo "${indent} static const char * name;"
+ echo "${indent}};"
+ }
+
+ make_nn_${name}
+
+ while [[ -n ${indent} ]]; do
+ indent=${indent/ }
+ echo "${indent}}"
+ done
+
+ elif [[ "${what_to_make}" == "--source" ]] ; then
+ namespace() {
+ ns="${1}::"
+ }
+
+ name() {
+ class=$1
+ class_name=${2:-$1}
+ echo "const char * ${ns}${name}<${class}>::name = \"${class_name}\";"
+ }
+
+ echo
+ make_nn_${name}
+ else
+ echo "bad argument (expected --header or --source)" 1>&2
+ exit 1
+ fi
+done