parsemsg.awk revision 121934
1254721Semaste# 2254721Semaste# Copyright (c) 2001-2003 3254721Semaste# Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4254721Semaste# All rights reserved. 5254721Semaste# 6254721Semaste# Redistribution and use in source and binary forms, with or without 7254721Semaste# modification, are permitted provided that the following conditions 8254721Semaste# are met: 9254721Semaste# 1. Redistributions of source code must retain the above copyright 10254721Semaste# notice, this list of conditions and the following disclaimer. 11263363Semaste# 2. Redistributions in binary form must reproduce the above copyright 12254721Semaste# notice, this list of conditions and the following disclaimer in the 13254721Semaste# documentation and/or other materials provided with the distribution. 14254721Semaste# 15254721Semaste# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16254721Semaste# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17263363Semaste# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18263363Semaste# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19263363Semaste# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20263363Semaste# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21263363Semaste# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22254721Semaste# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23254721Semaste# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24254721Semaste# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25254721Semaste# SUCH DAMAGE. 26254721Semaste# 27254721Semaste# Author: Hartmut Brandt <harti@freebsd.org> 28254721Semaste# 29254721Semaste# $Begemot: libunimsg/atm/msg/parsemsg.awk,v 1.3 2003/09/19 11:58:15 hbb Exp $ 30254721Semaste# 31254721Semaste# Parse the message definition file 32254721Semaste# 33254721Semastematch($0, "Begemot:")!=0 { 34254721Semaste gsub("^[^$]*", "") 35254721Semaste gsub("[^$]*$", "") 36254721Semaste id = $0 37254721Semaste next 38254721Semaste} 39254721Semaste 40254721Semaste/^#/ { 41254721Semaste next 42254721Semaste} 43254721SemasteNF == 0 { 44254721Semaste next 45254721Semaste} 46254721SemasteBEGIN { 47254721Semaste state=0 48254721Semaste id = " * ???" 49254721Semaste mcnt=0 50254721Semaste begin() 51263363Semaste} 52263363SemasteEND { 53254721Semaste end() 54254721Semaste} 55254721Semaste 56254721Semastestate==0 && $1=="start" { 57254721Semaste if(NF < 3) error("bad number of fields in message start "$0) 58254721Semaste state = 1 59254721Semaste msg = $2 60254721Semaste code = parse_hex($3) 61254721Semaste messages[mcnt] = msg 62254721Semaste msgcond[mcnt] = $4 63254721Semaste msgrep = 0 64254721Semaste msgrepie = 0 65254721Semaste cnt = 0 66254721Semaste if(mcnt == 0) first_entry() 67254721Semaste start_message() 68254721Semaste next 69254721Semaste} 70254721Semaste 71254721Semastestate==1 && $1=="end" { 72254721Semaste state=0 73254721Semaste mcnt++ 74254721Semaste end_message() 75254721Semaste next 76254721Semaste} 77254721Semastestate==1 { 78254721Semaste iename[cnt]=$1 79254721Semaste if($2 == "") $2="-" 80254721Semaste if(match($2, "[A-Za-z][A-Za-z0-9_]*/R") == 1) { 81254721Semaste ienum[cnt]=substr($2, 1, length($2)-2) 82254721Semaste ierep[cnt]=1 83254721Semaste msgrepie=1 84254721Semaste } else { 85254721Semaste ierep[cnt]=0 86254721Semaste ienum[cnt]=$2 87254721Semaste } 88254721Semaste if(ienum[cnt] != "-") msgrep = 1 89254721Semaste if($3 == "" || $3 == "-") { 90254721Semaste $3 = "1" 91254721Semaste } else { 92254721Semaste gsub("[a-zA-Z][a-zA-Z0-9]*", "cx->&", $3) 93254721Semaste } 94254721Semaste iecond[cnt] = $3 95254721Semaste cnt++ 96254721Semaste next 97254721Semaste} 98254721Semaste 99254721Semaste{ 100254721Semaste error("bad line: "$0) 101254721Semaste} 102254721Semaste 103254721Semastefunction parse_hex(str, n) 104254721Semaste{ 105254721Semaste n = 0 106254721Semaste if(substr(str,1,2) != "0x") { 107254721Semaste error("bad hex number" str) 108254721Semaste } 109254721Semaste for(i = 3; i <= length(str); i++) { 110254721Semaste c = substr(str,i,1) 111254721Semaste if(match(c,"[0-9]") != 0) { 112254721Semaste n = 16 * n + c 113254721Semaste } else if(match(c,"[a-f]")) { 114254721Semaste if(c == "a") n = 16 * n + 10 115254721Semaste if(c == "b") n = 16 * n + 11 116254721Semaste if(c == "c") n = 16 * n + 12 117254721Semaste if(c == "d") n = 16 * n + 13 118254721Semaste if(c == "e") n = 16 * n + 14 119254721Semaste if(c == "f") n = 16 * n + 15 120254721Semaste } else if(match(c,"[A-F]")) { 121254721Semaste if(c == "A") n = 16 * n + 10 122254721Semaste if(c == "B") n = 16 * n + 11 123254721Semaste if(c == "C") n = 16 * n + 12 124254721Semaste if(c == "D") n = 16 * n + 13 125254721Semaste if(c == "E") n = 16 * n + 14 126263363Semaste if(c == "F") n = 16 * n + 15 127263363Semaste } else { 128263363Semaste error("bad hex digit '" c "'") 129263363Semaste } 130263363Semaste } 131263363Semaste return n 132263363Semaste} 133263363Semaste 134263363Semastefunction error(str) 135263363Semaste{ 136254721Semaste print "error:" str >"/dev/stderr" 137254721Semaste exit 1 138263363Semaste} 139263363Semaste