symbols.awk revision 1.1.1.1
1# $OpenBSD: symbols.awk,v 1.1.1.1 2023/07/15 19:29:44 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 <openssl/dtls1.h>\n") 21 printf("#include <openssl/ssl.h>\n") 22 printf("#include <openssl/ssl2.h>\n") 23 printf("#include <openssl/ssl23.h>\n") 24 printf("#include <openssl/ssl3.h>\n") 25 printf("#include <openssl/tls1.h>\n\n") 26 27 printf("#include <openssl/srtp.h>\n\n") # depends on ssl.h 28} 29 30/^SSL_version_str$/ { 31 printf("extern const char *%s;\n", $0) 32} 33 34{ 35 symbols[$0] = $0 36 37 # Undefine aliases, so we don't accidentally leave them in Symbols.list. 38 printf("#ifdef %s\n#undef %s\n#endif\n", $0, $0) 39} 40 41END { 42 printf("\nint\nmain(void)\n{\n") 43 printf("\tsize_t i;\n"); 44 45 printf("\tstruct {\n") 46 printf("\t\tconst char *const name;\n") 47 printf("\t\tconst void *addr;\n") 48 printf("\t} symbols[] = {\n") 49 50 for (symbol in symbols) { 51 printf("\t\t{\n") 52 printf("\t\t\t.name = \"%s\",\n", symbol) 53 printf("\t\t\t.addr = &%s,\n", symbol) 54 printf("\t\t},\n") 55 } 56 57 printf("\t\};\n\n") 58 59 printf("\tfor (i = 0; i < sizeof(symbols) / sizeof(symbols[0]); i++)\n") 60 printf("\t\tfprintf(stderr, \"%%s: %%p\\n\", symbols[i].name, symbols[i].addr);\n") 61 printf("\n\tprintf(\"OK\\n\");\n") 62 printf("\n\treturn 0;\n}\n") 63} 64