2 # Copyright (c) 2001-2003
3 # Fraunhofer Institute for Open Communication Systems (FhG Fokus).
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 # Author: Hartmut Brandt <harti@freebsd.org>
29 # $Begemot: libunimsg/netnatm/msg/parseie.awk,v 1.3 2003/09/19 11:58:15 hbb Exp $
31 # Parse the IE definition file
33 match($0, "Begemot:")!=0 {
59 # element <name> <code> <coding> [<maxlen> [<options>*]]
62 if(iecnt == 0) first_element()
64 error("Bad number of args: " $0)
68 number = parse_hex($3)
72 } else if(coding == "net") {
75 error("bad coding " coding)
86 codings[iecnt] = coding
93 error("Bad line: " $0)
96 function parse_options() {
99 for(i = 6; i <= NF; i++) {
102 } else if($i == "-") {
103 } else if(index($i, "file=") == 1) {
107 error("Too many conditions: "$0)
114 function parse_hex(str, n)
117 if(substr(str,1,2) != "0x") {
118 error("bad hex number" str)
120 for(i = 3; i <= length(str); i++) {
122 if(match(c,"[0-9]") != 0) {
124 } else if(match(c,"[a-f]")) {
125 if(c == "a") n = 16 * n + 10
126 if(c == "b") n = 16 * n + 11
127 if(c == "c") n = 16 * n + 12
128 if(c == "d") n = 16 * n + 13
129 if(c == "e") n = 16 * n + 14
130 if(c == "f") n = 16 * n + 15
131 } else if(match(c,"[A-F]")) {
132 if(c == "A") n = 16 * n + 10
133 if(c == "B") n = 16 * n + 11
134 if(c == "C") n = 16 * n + 12
135 if(c == "D") n = 16 * n + 13
136 if(c == "E") n = 16 * n + 14
137 if(c == "F") n = 16 * n + 15
139 error("bad hex digit '" c "'")
145 # function error(str)
147 # print "error:" str >"/dev/stderr"