1121934Sharti#
2121934Sharti# Copyright (c) 2001-2003
3121934Sharti# Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4121934Sharti# 	All rights reserved.
5121934Sharti#
6121934Sharti# Redistribution and use in source and binary forms, with or without
7121934Sharti# modification, are permitted provided that the following conditions
8121934Sharti# are met:
9121934Sharti# 1. Redistributions of source code must retain the above copyright
10121934Sharti#    notice, this list of conditions and the following disclaimer.
11121934Sharti# 2. Redistributions in binary form must reproduce the above copyright
12121934Sharti#    notice, this list of conditions and the following disclaimer in the
13121934Sharti#    documentation and/or other materials provided with the distribution.
14121934Sharti#
15121934Sharti# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16121934Sharti# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17121934Sharti# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18121934Sharti# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19121934Sharti# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20121934Sharti# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21121934Sharti# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22121934Sharti# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23121934Sharti# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24121934Sharti# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25121934Sharti# SUCH DAMAGE.
26121934Sharti#
27121934Sharti# Author: Hartmut Brandt <harti@freebsd.org>
28121934Sharti#
29131826Sharti# $Begemot: libunimsg/netnatm/msg/parsemsg.awk,v 1.3 2003/09/19 11:58:15 hbb Exp $
30121934Sharti#
31121934Sharti# Parse the message definition file
32121934Sharti#
33121934Shartimatch($0, "Begemot:")!=0 {
34121934Sharti	gsub("^[^$]*", "")
35121934Sharti	gsub("[^$]*$", "")
36121934Sharti	id = $0
37121934Sharti	next
38121934Sharti}
39121934Sharti
40121934Sharti/^#/ {
41121934Sharti	next
42121934Sharti}
43121934ShartiNF == 0 {
44121934Sharti	next
45121934Sharti}
46121934ShartiBEGIN {
47121934Sharti	state=0
48121934Sharti	id = " * ???"
49121934Sharti	mcnt=0
50121934Sharti	begin()
51121934Sharti}
52121934ShartiEND {
53121934Sharti	end()
54121934Sharti}
55121934Sharti
56121934Shartistate==0 && $1=="start" {
57121934Sharti	if(NF < 3) error("bad number of fields in message start "$0)
58121934Sharti	state = 1
59121934Sharti	msg = $2
60121934Sharti	code = parse_hex($3)
61121934Sharti	messages[mcnt] = msg
62121934Sharti	msgcond[mcnt] = $4
63121934Sharti	msgrep = 0
64121934Sharti	msgrepie = 0
65121934Sharti	cnt = 0
66121934Sharti	if(mcnt == 0) first_entry()
67121934Sharti	start_message()
68121934Sharti	next
69121934Sharti}
70121934Sharti
71121934Shartistate==1 && $1=="end" {
72121934Sharti	state=0
73121934Sharti	mcnt++
74121934Sharti	end_message()
75121934Sharti	next
76121934Sharti}
77121934Shartistate==1 {
78121934Sharti	iename[cnt]=$1
79121934Sharti	if($2 == "") $2="-"
80121934Sharti	if(match($2, "[A-Za-z][A-Za-z0-9_]*/R") == 1) {
81121934Sharti		ienum[cnt]=substr($2, 1, length($2)-2)
82121934Sharti		ierep[cnt]=1
83121934Sharti		msgrepie=1
84121934Sharti	} else {
85121934Sharti		ierep[cnt]=0
86121934Sharti		ienum[cnt]=$2
87121934Sharti	}
88121934Sharti	if(ienum[cnt] != "-") msgrep = 1
89121934Sharti	if($3 == "" || $3 == "-") {
90121934Sharti		$3 = "1"
91121934Sharti	} else {
92121934Sharti		gsub("[a-zA-Z][a-zA-Z0-9]*", "cx->&", $3)
93121934Sharti	}
94121934Sharti	iecond[cnt] = $3
95121934Sharti	cnt++
96121934Sharti	next
97121934Sharti}
98121934Sharti
99121934Sharti{
100121934Sharti	error("bad line: "$0)
101121934Sharti}
102121934Sharti
103121934Shartifunction parse_hex(str,		n)
104121934Sharti{
105121934Sharti	n = 0
106121934Sharti	if(substr(str,1,2) != "0x") {
107121934Sharti		error("bad hex number" str)
108121934Sharti	}
109121934Sharti	for(i = 3; i <= length(str); i++) {
110121934Sharti		c = substr(str,i,1)
111121934Sharti		if(match(c,"[0-9]") != 0) {
112121934Sharti			n = 16 * n + c
113121934Sharti		} else if(match(c,"[a-f]")) {
114121934Sharti			if(c == "a") n = 16 * n + 10
115121934Sharti			if(c == "b") n = 16 * n + 11
116121934Sharti			if(c == "c") n = 16 * n + 12
117121934Sharti			if(c == "d") n = 16 * n + 13
118121934Sharti			if(c == "e") n = 16 * n + 14
119121934Sharti			if(c == "f") n = 16 * n + 15
120121934Sharti		} else if(match(c,"[A-F]")) {
121121934Sharti			if(c == "A") n = 16 * n + 10
122121934Sharti			if(c == "B") n = 16 * n + 11
123121934Sharti			if(c == "C") n = 16 * n + 12
124121934Sharti			if(c == "D") n = 16 * n + 13
125121934Sharti			if(c == "E") n = 16 * n + 14
126121934Sharti			if(c == "F") n = 16 * n + 15
127121934Sharti		} else {
128121934Sharti			error("bad hex digit '" c "'")
129121934Sharti		}
130121934Sharti	}
131121934Sharti	return n
132121934Sharti}
133121934Sharti
134121934Shartifunction error(str)
135121934Sharti{
136121934Sharti	print "error:" str >"/dev/stderr"
137121934Sharti	exit 1
138121934Sharti}
139