1# 2# Copyright (c) 2001-2003 3# Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 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. 14# 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 25# SUCH DAMAGE. 26# 27# Author: Hartmut Brandt <harti@freebsd.org> 28# 29# $Begemot: libunimsg/netnatm/msg/parseie.awk,v 1.3 2003/09/19 11:58:15 hbb Exp $ 30# 31# Parse the IE definition file 32# 33match($0, "Begemot:")!=0 { 34 gsub("^[^$]*", "") 35 gsub("[^$]*$", "") 36 id = $0 37 next 38} 39 40/^#/ { 41 next 42} 43NF == 0 { 44 next 45} 46 47BEGIN { 48 iecnt = 0 49 id = " * ???" 50 begin() 51} 52 53END { 54 end() 55} 56 57# 58# Syntax is: 59# element <name> <code> <coding> [<maxlen> [<options>*]] 60# 61$1=="element" { 62 if(iecnt == 0) first_element() 63 if(NF < 4) { 64 error("Bad number of args: " $0) 65 } 66 ie = $2 67 file = $2 68 number = parse_hex($3) 69 coding = $4 70 if(coding == "itu") { 71 ncoding = 0 72 } else if(coding == "net") { 73 ncoding = 3 74 } else { 75 error("bad coding " coding) 76 } 77 if(NF == 4) { 78 element_default() 79 file="" 80 } else { 81 len = $5 82 parse_options() 83 element() 84 } 85 ies[iecnt] = ie 86 codings[iecnt] = coding 87 files[iecnt] = file 88 iecnt++ 89 next 90} 91 92{ 93 error("Bad line: " $0) 94} 95 96function parse_options() { 97 access = 0 98 cond = "" 99 for(i = 6; i <= NF; i++) { 100 if($i == "access") { 101 access = 1 102 } else if($i == "-") { 103 } else if(index($i, "file=") == 1) { 104 file=substr($i, 6) 105 } else { 106 if(cond != "") { 107 error("Too many conditions: "$0) 108 } 109 cond = $i 110 } 111 } 112} 113 114function parse_hex(str, n) 115{ 116 n = 0 117 if(substr(str,1,2) != "0x") { 118 error("bad hex number" str) 119 } 120 for(i = 3; i <= length(str); i++) { 121 c = substr(str,i,1) 122 if(match(c,"[0-9]") != 0) { 123 n = 16 * n + c 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 138 } else { 139 error("bad hex digit '" c "'") 140 } 141 } 142 return n 143} 144 145# function error(str) 146# { 147# print "error:" str >"/dev/stderr" 148# exit 1 149# } 150 151