xref: /openbsd/sbin/isakmpd/genconstants.sh (revision 898184e3)
1#	$OpenBSD: genconstants.sh,v 1.12 2004/04/15 18:39:25 deraadt Exp $
2#	$EOM: genconstants.sh,v 1.6 1999/04/02 01:15:53 niklas Exp $
3
4#
5# Copyright (c) 1998, 1999, 2001 Niklas Hallqvist.  All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27
28#
29# This code was written under funding by Ericsson Radio Systems.
30#
31
32base=`basename $1`
33upcased_name=`echo $base |tr a-z A-Z`
34
35awk=${AWK:-awk}
36
37locase_function='function locase (str) {
38  cmd = "echo " str " |tr A-Z a-z"
39  cmd | getline retval;
40  close (cmd);
41  return retval;
42}'
43
44$awk "
45$locase_function
46"'
47BEGIN {
48  print "/* DO NOT EDIT-- this file is automatically generated.  */\n"
49  print "#ifndef _'$upcased_name'_H_"
50  print "#define _'$upcased_name'_H_\n"
51  print "#include \"sysdep.h\"\n"
52  print "#include \"constants.h\"\n"
53}
54
55/^[#.]/ {
56  next
57}
58
59/^[^ 	]/ {
60  prefix = $1
61  printf ("extern struct constant_map %s_cst[];\n\n", locase(prefix));
62  next
63}
64
65/^[ 	]/ && $1 {
66  printf ("#define %s_%s %s\n", prefix, $1, $2)
67  next
68}
69
70{
71    print
72}
73
74END {
75  printf ("\n")
76  print "#endif /* _'$upcased_name'_H_ */"
77}
78' <$1.cst >$base.h
79
80$awk "
81$locase_function
82"'
83BEGIN {
84  print "/* DO NOT EDIT-- this file is automatically generated.  */\n"
85  print "#include \"sysdep.h\"\n"
86  print "#include \"constants.h\""
87  print "#include \"'$base'.h\"\n"
88}
89
90/^#/ {
91  next
92}
93
94/^\./ {
95  print "	{ 0, 0 }\n};\n"
96  next
97}
98
99/^[^ 	]/ {
100  prefix = $1
101  printf ("struct constant_map %s_cst[] = {\n", locase(prefix))
102  next
103}
104
105/^[ 	]/ && $1 {
106  printf ("	{ %s_%s, \"%s\", %s },\n", prefix, $1, $1,
107    ($3 && substr($3,1,1) != "#") ? $3 : 0)
108  next
109}
110
111{
112  print
113}
114' <$1.cst >$base.c
115