13224b86eSHartmut Brandt# 23224b86eSHartmut Brandt# Copyright (c) 2001-2003 33224b86eSHartmut Brandt# Fraunhofer Institute for Open Communication Systems (FhG Fokus). 43224b86eSHartmut Brandt# All rights reserved. 53224b86eSHartmut Brandt# 63224b86eSHartmut Brandt# Redistribution and use in source and binary forms, with or without 73224b86eSHartmut Brandt# modification, are permitted provided that the following conditions 83224b86eSHartmut Brandt# are met: 93224b86eSHartmut Brandt# 1. Redistributions of source code must retain the above copyright 103224b86eSHartmut Brandt# notice, this list of conditions and the following disclaimer. 113224b86eSHartmut Brandt# 2. Redistributions in binary form must reproduce the above copyright 123224b86eSHartmut Brandt# notice, this list of conditions and the following disclaimer in the 133224b86eSHartmut Brandt# documentation and/or other materials provided with the distribution. 143224b86eSHartmut Brandt# 153224b86eSHartmut Brandt# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 163224b86eSHartmut Brandt# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 173224b86eSHartmut Brandt# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 183224b86eSHartmut Brandt# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 193224b86eSHartmut Brandt# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 203224b86eSHartmut Brandt# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 213224b86eSHartmut Brandt# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 223224b86eSHartmut Brandt# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 233224b86eSHartmut Brandt# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 243224b86eSHartmut Brandt# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 253224b86eSHartmut Brandt# SUCH DAMAGE. 263224b86eSHartmut Brandt# 273224b86eSHartmut Brandt# Author: Hartmut Brandt <[email protected]> 283224b86eSHartmut Brandt# 29*8339b150SHartmut Brandt# $Begemot: libunimsg/netnatm/msg/parsemsg.awk,v 1.3 2003/09/19 11:58:15 hbb Exp $ 303224b86eSHartmut Brandt# 313224b86eSHartmut Brandt# Parse the message definition file 323224b86eSHartmut Brandt# 333224b86eSHartmut Brandtmatch($0, "Begemot:")!=0 { 343224b86eSHartmut Brandt gsub("^[^$]*", "") 353224b86eSHartmut Brandt gsub("[^$]*$", "") 363224b86eSHartmut Brandt id = $0 373224b86eSHartmut Brandt next 383224b86eSHartmut Brandt} 393224b86eSHartmut Brandt 403224b86eSHartmut Brandt/^#/ { 413224b86eSHartmut Brandt next 423224b86eSHartmut Brandt} 433224b86eSHartmut BrandtNF == 0 { 443224b86eSHartmut Brandt next 453224b86eSHartmut Brandt} 463224b86eSHartmut BrandtBEGIN { 473224b86eSHartmut Brandt state=0 483224b86eSHartmut Brandt id = " * ???" 493224b86eSHartmut Brandt mcnt=0 503224b86eSHartmut Brandt begin() 513224b86eSHartmut Brandt} 523224b86eSHartmut BrandtEND { 533224b86eSHartmut Brandt end() 543224b86eSHartmut Brandt} 553224b86eSHartmut Brandt 563224b86eSHartmut Brandtstate==0 && $1=="start" { 573224b86eSHartmut Brandt if(NF < 3) error("bad number of fields in message start "$0) 583224b86eSHartmut Brandt state = 1 593224b86eSHartmut Brandt msg = $2 603224b86eSHartmut Brandt code = parse_hex($3) 613224b86eSHartmut Brandt messages[mcnt] = msg 623224b86eSHartmut Brandt msgcond[mcnt] = $4 633224b86eSHartmut Brandt msgrep = 0 643224b86eSHartmut Brandt msgrepie = 0 653224b86eSHartmut Brandt cnt = 0 663224b86eSHartmut Brandt if(mcnt == 0) first_entry() 673224b86eSHartmut Brandt start_message() 683224b86eSHartmut Brandt next 693224b86eSHartmut Brandt} 703224b86eSHartmut Brandt 713224b86eSHartmut Brandtstate==1 && $1=="end" { 723224b86eSHartmut Brandt state=0 733224b86eSHartmut Brandt mcnt++ 743224b86eSHartmut Brandt end_message() 753224b86eSHartmut Brandt next 763224b86eSHartmut Brandt} 773224b86eSHartmut Brandtstate==1 { 783224b86eSHartmut Brandt iename[cnt]=$1 793224b86eSHartmut Brandt if($2 == "") $2="-" 803224b86eSHartmut Brandt if(match($2, "[A-Za-z][A-Za-z0-9_]*/R") == 1) { 813224b86eSHartmut Brandt ienum[cnt]=substr($2, 1, length($2)-2) 823224b86eSHartmut Brandt ierep[cnt]=1 833224b86eSHartmut Brandt msgrepie=1 843224b86eSHartmut Brandt } else { 853224b86eSHartmut Brandt ierep[cnt]=0 863224b86eSHartmut Brandt ienum[cnt]=$2 873224b86eSHartmut Brandt } 883224b86eSHartmut Brandt if(ienum[cnt] != "-") msgrep = 1 893224b86eSHartmut Brandt if($3 == "" || $3 == "-") { 903224b86eSHartmut Brandt $3 = "1" 913224b86eSHartmut Brandt } else { 923224b86eSHartmut Brandt gsub("[a-zA-Z][a-zA-Z0-9]*", "cx->&", $3) 933224b86eSHartmut Brandt } 943224b86eSHartmut Brandt iecond[cnt] = $3 953224b86eSHartmut Brandt cnt++ 963224b86eSHartmut Brandt next 973224b86eSHartmut Brandt} 983224b86eSHartmut Brandt 993224b86eSHartmut Brandt{ 1003224b86eSHartmut Brandt error("bad line: "$0) 1013224b86eSHartmut Brandt} 1023224b86eSHartmut Brandt 1033224b86eSHartmut Brandtfunction parse_hex(str, n) 1043224b86eSHartmut Brandt{ 1053224b86eSHartmut Brandt n = 0 1063224b86eSHartmut Brandt if(substr(str,1,2) != "0x") { 1073224b86eSHartmut Brandt error("bad hex number" str) 1083224b86eSHartmut Brandt } 1093224b86eSHartmut Brandt for(i = 3; i <= length(str); i++) { 1103224b86eSHartmut Brandt c = substr(str,i,1) 1113224b86eSHartmut Brandt if(match(c,"[0-9]") != 0) { 1123224b86eSHartmut Brandt n = 16 * n + c 1133224b86eSHartmut Brandt } else if(match(c,"[a-f]")) { 1143224b86eSHartmut Brandt if(c == "a") n = 16 * n + 10 1153224b86eSHartmut Brandt if(c == "b") n = 16 * n + 11 1163224b86eSHartmut Brandt if(c == "c") n = 16 * n + 12 1173224b86eSHartmut Brandt if(c == "d") n = 16 * n + 13 1183224b86eSHartmut Brandt if(c == "e") n = 16 * n + 14 1193224b86eSHartmut Brandt if(c == "f") n = 16 * n + 15 1203224b86eSHartmut Brandt } else if(match(c,"[A-F]")) { 1213224b86eSHartmut Brandt if(c == "A") n = 16 * n + 10 1223224b86eSHartmut Brandt if(c == "B") n = 16 * n + 11 1233224b86eSHartmut Brandt if(c == "C") n = 16 * n + 12 1243224b86eSHartmut Brandt if(c == "D") n = 16 * n + 13 1253224b86eSHartmut Brandt if(c == "E") n = 16 * n + 14 1263224b86eSHartmut Brandt if(c == "F") n = 16 * n + 15 1273224b86eSHartmut Brandt } else { 1283224b86eSHartmut Brandt error("bad hex digit '" c "'") 1293224b86eSHartmut Brandt } 1303224b86eSHartmut Brandt } 1313224b86eSHartmut Brandt return n 1323224b86eSHartmut Brandt} 1333224b86eSHartmut Brandt 1343224b86eSHartmut Brandtfunction error(str) 1353224b86eSHartmut Brandt{ 1363224b86eSHartmut Brandt print "error:" str >"/dev/stderr" 1373224b86eSHartmut Brandt exit 1 1383224b86eSHartmut Brandt} 139