1#!/bin/sh 2 3cut_defines () 4{ 5 cut -b9- | cut -f1 | cut -d' ' -f1 6} 7 8list_commands () 9{ 10 egrep -h 'define.+CM_' "$@" | cut_defines 11} 12 13list_events () 14{ 15 # list and remove deprecations 16 egrep -h 'define.+EV_' "$@" | cut_defines | \ 17 grep -v 'EV_CALL_PROGRESS\|EV_FAX_MESSAGE_CONFIRMATION' 18} 19 20make_enumeration_one_by_one () 21{ 22 while read line 23 do 24 local size=$[50 - $(expr length "${line}")] 25 26 echo -n " K_${line}" 27 28 for ((i=0;i<size;i++)) 29 do 30 echo -n " " 31 done 32 33 echo "= ${line}," 34 done 35} 36 37make_enumeration () 38{ 39 local name="$1"; shift 40 local func="$1"; shift 41 42 echo " typedef enum" 43 echo " {" 44 "${func}" "$@" | make_enumeration_one_by_one 45 echo " }" 46 echo " ${name};" 47} 48 49make_switch_case_one_by_one () 50{ 51 while read line 52 do 53 local size=$[50 - $(expr length "${line}")] 54 55 echo -n " case K_${line}:" 56 57 for ((i=0;i<size;i++)) 58 do 59 echo -n " " 60 done 61 62 echo "return \"${line}\";" 63 done 64} 65 66make_switch_case () 67{ 68 local type="$1"; shift 69 local name="$1"; shift 70 local func="$1"; shift 71 72 echo "std::string VerboseTraits::${name}Name(const ${type} value)" 73 echo "{" 74 echo " switch(value)" 75 echo " {" 76 "${func}" "$@" | make_switch_case_one_by_one 77 echo " }" 78 echo " return STG(FMT(\"${name}=%d\") % ((int)value));" 79 echo "}" 80} 81 82make_license () 83{ 84 echo '/*' 85 echo ' KHOMP generic endpoint/channel library.' 86 echo ' Copyright (C) 2007-2010 Khomp Ind. & Com.' 87 echo '' 88 echo ' The contents of this file are subject to the Mozilla Public License Version 1.1' 89 echo ' (the "License"); you may not use this file except in compliance with the' 90 echo ' License. You may obtain a copy of the License at http://www.mozilla.org/MPL/' 91 echo '' 92 echo ' Software distributed under the License is distributed on an "AS IS" basis,' 93 echo ' WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for' 94 echo ' the specific language governing rights and limitations under the License.' 95 echo '' 96 echo ' Alternatively, the contents of this file may be used under the terms of the' 97 echo ' "GNU Lesser General Public License 2.1" license (the “LGPL" License), in which' 98 echo ' case the provisions of "LGPL License" are applicable instead of those above.' 99 echo '' 100 echo ' If you wish to allow use of your version of this file only under the terms of' 101 echo ' the LGPL License and not to allow others to use your version of this file under' 102 echo ' the MPL, indicate your decision by deleting the provisions above and replace them' 103 echo ' with the notice and other provisions required by the LGPL License. If you do not' 104 echo ' delete the provisions above, a recipient may use your version of this file under' 105 echo ' either the MPL or the LGPL License.' 106 echo '' 107 echo ' The LGPL header follows below:' 108 echo '' 109 echo ' This library is free software; you can redistribute it and/or' 110 echo ' modify it under the terms of the GNU Lesser General Public' 111 echo ' License as published by the Free Software Foundation; either' 112 echo ' version 2.1 of the License, or (at your option) any later version.' 113 echo '' 114 echo ' This library is distributed in the hope that it will be useful,' 115 echo ' but WITHOUT ANY WARRANTY; without even the implied warranty of' 116 echo ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU' 117 echo ' Lesser General Public License for more details.' 118 echo '' 119 echo ' You should have received a copy of the GNU Lesser General Public License' 120 echo ' along with this library; if not, write to the Free Software Foundation, Inc.,' 121 echo ' 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA' 122 echo '' 123 echo '*/' 124 125 echo "/* ****************************************************************************** */" 126 echo "/* ******************* AUTO GENERATED FILE - DO NOT EDIT! *********************** */" 127 echo "/* ****************************************************************************** */" 128 echo 129} 130 131make_header () 132{ 133 make_license 134 135 echo "#ifndef _VERBOSE_TRAITS_H_" 136 echo "#define _VERBOSE_TRAITS_H_" 137 echo 138 echo "#include <string>" 139 echo 140 echo "#include <format.hpp>" 141 echo 142 echo "#include <k3l.h>" 143 echo 144 echo "struct VerboseTraits" 145 echo "{" 146 make_enumeration "Command" list_commands "$@" || return 1 147 echo 148 make_enumeration "Event" list_events "$@" || return 1 149 echo 150 echo " static std::string eventName(const Event);" 151 echo " static std::string commandName(const Command);" 152 echo "};" 153 echo 154 echo "#endif /* _VERBOSE_TRAITS_H_ */" 155} 156 157make_source () 158{ 159 make_license 160 161 echo "#include <verbose_traits.hpp>" 162 echo 163 164 make_switch_case "Event" "event" list_events "$@" || return 1 165 echo 166 make_switch_case "Command" "command" list_commands "$@" || return 1 167} 168 169make_run () 170{ 171 local destdir="$1"; shift 172 173 if [ ! -d "${destdir}" ] 174 then 175 echo "ERROR: First argument is not a directory!" 176 return 1 177 fi 178 179 make_header "$@" > "${destdir}/verbose_traits.hpp" 180 make_source "$@" > "${destdir}/verbose_traits.cpp" 181} 182 183make_run "$@" 184