aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/Makefile.am3
-rwxr-xr-xmisc/make_se.bash132
2 files changed, 134 insertions, 1 deletions
diff --git a/misc/Makefile.am b/misc/Makefile.am
index 5da8fdaa0..b4fad58c9 100644
--- a/misc/Makefile.am
+++ b/misc/Makefile.am
@@ -1,6 +1,7 @@
CLEANFILES = *~
MAINTAINERCLEANFILES = Makefile.in svn-version-filter-data.bash
-EXTRA_DIST = generated-file.txt svn-version-filter.bash svn-version-filter-data.bash.in do_m4.bash make_sr.bash
+EXTRA_DIST = generated-file.txt svn-version-filter.bash svn-version-filter-data.bash.in \
+ do_m4.bash make_sr.bash make_se.bash
built-sources : $(BUILT_SOURCES)
for s in $(SUBDIRS) ; do $(MAKE) -C $$s built-sources || exit 1 ; done
diff --git a/misc/make_se.bash b/misc/make_se.bash
new file mode 100755
index 000000000..753e9856f
--- /dev/null
+++ b/misc/make_se.bash
@@ -0,0 +1,132 @@
+#!/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 "/* ******************************************************** */"
+echo
+
+what_to_make=${1}
+shift
+
+for src in ${@} ; do
+ if ! source ${src} ; then
+ echo "source ${src} failed" 1>&2
+ exit 7
+ fi
+done
+
+set | grep '^make_enum_.*() $' | sort -r | \
+while read a ; do
+ a=${a##make_enum_}
+ a=${a%% *}
+
+ want_keys=( )
+ want_key_descriptions=( )
+ want_prefix_key=
+ want_namespace=paludis
+
+ key()
+ {
+ want_keys=( "${want_keys[@]}" "$1" )
+ want_key_descriptions=( "${want_key_descriptions[@]}" "$2" )
+ }
+
+ prefix()
+ {
+ want_prefix_key=$1
+ }
+
+ namespace()
+ {
+ want_namespace=$1
+ }
+
+ doxygen_comment()
+ {
+ :
+ }
+
+ make_enum_${a}
+ if [[ -z "${want_prefix_key}" ]] ; then
+ echo "no prefix key set for ${a}" 1>&2
+ exit 1
+ fi
+
+ key()
+ {
+ :
+ }
+
+ prefix()
+ {
+ :
+ }
+
+ namespace()
+ {
+ :
+ }
+
+ if [[ "${what_to_make}" == "--header" ]] ; then
+
+ doxygen_comment()
+ {
+ cat
+ }
+
+ make_enum_${a}
+
+ echo "enum ${a}"
+ echo "{"
+
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo " ${want_keys[${k}]}, ///< ${want_key_descriptions[${k}]}"
+ done
+
+ echo " last_${want_prefix_key}"
+
+ echo "};"
+
+ echo
+ echo "std::ostream &"
+ echo "operator<< (std::ostream &, const $a &);"
+ echo
+
+ elif [[ "${what_to_make}" == "--source" ]] ; then
+
+ echo "std::ostream &"
+ echo "${want_namespace}::operator<< (std::ostream & o, const ${a} & s)"
+ echo "{"
+ echo " do"
+ echo " {"
+ echo " switch (s)"
+ echo " {"
+
+ for (( k = 0 ; k < ${#want_keys[@]} ; k++ )) ; do
+ echo " case ${want_keys[${k}]}:"
+ echo " o << \"${want_keys[${k}]#${want_prefix_key}_}\";";
+ echo " continue;"
+ echo
+ done
+
+ echo " case last_${want_prefix_key}:"
+ echo " ;"
+ echo " }"
+ echo " throw InternalError(PALUDIS_HERE, \"Bad ${a} value '\" + paludis::stringify("
+ echo " static_cast<int>(s)));"
+ echo " } while (false);"
+ echo
+ echo " return o;"
+ echo "}"
+ echo
+
+ else
+ echo "bad argument (expected --header or --source)" 1>&2
+ exit 1
+ fi
+done
+