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/geniec.awk,v 1.4 2003/10/10 14:50:05 hbb Exp $
30121934Sharti#
31121934Sharti# Generate table for IE parsing.
32121934Sharti#
33121934Sharti# This function is called before the first line
34121934Sharti#
35121934Shartifunction begin() {
36121934Sharti	for(i = 0; i < 256; i++) {
37121934Sharti		for(j = 0; j < 4; j++) {
38121934Sharti			decl[i,j] = ""
39121934Sharti		}
40121934Sharti	}
41121934Sharti}
42121934Sharti
43121934Sharti#
44121934Sharti# This function is called after the last line.
45121934Sharti#
46121934Shartifunction end() {
47121934Sharti	print ""
48121934Sharti	print "const struct iedecl *uni_ietable[256][4] = {"
49121934Sharti	for(i = 0; i < 256; i++) {
50121934Sharti		printf "\t{"
51121934Sharti		for(j = 0; j < 4; j++) {
52121934Sharti			if(decl[i,j] == "") {
53121934Sharti				printf " NULL,"
54121934Sharti			} else {
55121934Sharti				printf " &%s,", decl[i,j]
56121934Sharti			}
57121934Sharti		}
58121934Sharti		printf " }, /* 0x%02x */\n", i
59121934Sharti	}
60121934Sharti	print "};"
61121934Sharti}
62121934Sharti
63121934Sharti#
64121934Sharti# This function is called just when the first information element was found
65121934Sharti#
66121934Shartifunction first_element() {
67121934Sharti	print "/* This file was created automatically"
68121934Sharti	print " * Source file: " id
69121934Sharti	print " */"
70121934Sharti	print ""
71121934Sharti}
72121934Sharti
73121934Sharti#
74121934Sharti# This is called, when the information element is defaulted (there is
75121934Sharti# only the name and the coding scheme
76121934Sharti#
77121934Shartifunction element_default() {
78121934Sharti	print ""
79121934Sharti	print "static const struct iedecl decl_" coding "_" ie " = {"
80121934Sharti	print "\tUNIFL_DEFAULT,"
81121934Sharti	print "\t0,"
82121934Sharti	print "\t(uni_print_f)NULL,"
83121934Sharti	print "\t(uni_check_f)NULL,"
84121934Sharti	print "\t(uni_encode_f)NULL,"
85121934Sharti	print "\t(uni_decode_f)NULL"
86121934Sharti	print "};"
87121934Sharti	decl[number,ncoding] = "decl_" coding "_" ie
88121934Sharti}
89121934Sharti
90121934Sharti#
91121934Sharti# This is found for a real, non-default IE
92121934Sharti#
93121934Shartifunction element() {
94121934Sharti	print ""
95121934Sharti	print "static void uni_ie_print_" coding "_" ie "(struct uni_ie_" ie " *, struct unicx *);"
96121934Sharti	print "static int uni_ie_check_" coding "_" ie "(struct uni_ie_" ie " *, struct unicx *);"
97121934Sharti	print "static int uni_ie_encode_" coding "_" ie "(struct uni_msg *, struct uni_ie_" ie " *, struct unicx *);"
98121934Sharti	print "static int uni_ie_decode_" coding "_" ie "(struct uni_ie_" ie " *, struct uni_msg *, u_int, struct unicx *);"
99121934Sharti	print ""
100121934Sharti	print "static struct iedecl decl_" coding "_" ie " = {"
101121934Sharti	if(access)	print "\tUNIFL_ACCESS,"
102121934Sharti	else		print "\t0,"
103121934Sharti	print "\t" len ","
104121934Sharti	print "\t(uni_print_f)uni_ie_print_" coding "_" ie ","
105121934Sharti	print "\t(uni_check_f)uni_ie_check_" coding "_" ie ","
106121934Sharti	print "\t(uni_encode_f)uni_ie_encode_" coding "_" ie ","
107121934Sharti	print "\t(uni_decode_f)uni_ie_decode_" coding "_" ie ""
108121934Sharti	print "};"
109121934Sharti	decl[number,ncoding] = "decl_" coding "_" ie
110121934Sharti}
111