diff options
Diffstat (limited to 'misc/make_se.bash')
-rwxr-xr-x | misc/make_se.bash | 132 |
1 files changed, 132 insertions, 0 deletions
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 + |