1# $OpenBSD: symbols.awk,v 1.4 2024/05/08 06:54:43 tb Exp $
2
3# Copyright (c) 2018,2020,2023 Theo Buehler <tb@openbsd.org>
4#
5# Permission to use, copy, modify, and distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17# usage: awk -f symbols.awk < Symbols.list > symbols.c
18
19BEGIN {
20	printf("#include <stdio.h>\n\n")
21
22	printf("#include <openssl/dtls1.h>\n")
23	printf("#include <openssl/ssl.h>\n")
24	printf("#include <openssl/tls1.h>\n\n")
25
26	printf("#include <openssl/srtp.h>\n\n")		# depends on ssl.h
27}
28
29{
30	symbols[$0] = $0
31
32	# Undefine aliases, so we don't accidentally leave them in Symbols.list.
33	printf("#ifdef %s\n#undef %s\n#endif\n", $0, $0)
34}
35
36END {
37	printf("\nint\nmain(void)\n{\n")
38	printf("\tsize_t i;\n");
39
40	printf("\tstruct {\n")
41	printf("\t\tconst char *const name;\n")
42	printf("\t\tconst void *addr;\n")
43	printf("\t} symbols[] = {\n")
44
45	for (symbol in symbols) {
46		printf("\t\t{\n")
47		printf("\t\t\t.name = \"%s\",\n", symbol)
48		printf("\t\t\t.addr = &%s,\n", symbol)
49		printf("\t\t},\n")
50	}
51
52	printf("\t\};\n\n")
53
54	printf("\tfor (i = 0; i < sizeof(symbols) / sizeof(symbols[0]); i++)\n")
55	printf("\t\tfprintf(stderr, \"%%s: %%p\\n\", symbols[i].name, symbols[i].addr);\n")
56	printf("\n\tprintf(\"OK\\n\");\n")
57	printf("\n\treturn 0;\n}\n")
58}
59