xref: /openbsd/sbin/isakmpd/genconstants.sh (revision 76d0caae)
1#	$OpenBSD: genconstants.sh,v 1.13 2014/01/22 03:09:31 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 \"constants.h\"\n"
52}
53
54/^[#.]/ {
55  next
56}
57
58/^[^ 	]/ {
59  prefix = $1
60  printf ("extern struct constant_map %s_cst[];\n\n", locase(prefix));
61  next
62}
63
64/^[ 	]/ && $1 {
65  printf ("#define %s_%s %s\n", prefix, $1, $2)
66  next
67}
68
69{
70    print
71}
72
73END {
74  printf ("\n")
75  print "#endif /* _'$upcased_name'_H_ */"
76}
77' <$1.cst >$base.h
78
79$awk "
80$locase_function
81"'
82BEGIN {
83  print "/* DO NOT EDIT-- this file is automatically generated.  */\n"
84  print "#include \"constants.h\""
85  print "#include \"'$base'.h\"\n"
86}
87
88/^#/ {
89  next
90}
91
92/^\./ {
93  print "	{ 0, 0 }\n};\n"
94  next
95}
96
97/^[^ 	]/ {
98  prefix = $1
99  printf ("struct constant_map %s_cst[] = {\n", locase(prefix))
100  next
101}
102
103/^[ 	]/ && $1 {
104  printf ("	{ %s_%s, \"%s\", %s },\n", prefix, $1, $1,
105    ($3 && substr($3,1,1) != "#") ? $3 : 0)
106  next
107}
108
109{
110  print
111}
112' <$1.cst >$base.c
113