#!/usr/bin/env python # TODO special-case BN_MASK import sys import os #import re #r_define = re.compile(r"#[ ]*define[ ]*([A-Za-z_][A-Za-z_0-9]*)[ ]*") items = {} for line in sys.stdin.xreadlines(): parts = line.split(":", 1) if len(parts) < 2: continue header, definition = parts header = os.path.basename(header) definition = definition.strip() if definition.startswith("#"): definition = definition[1:].strip() else: continue if definition.startswith("define"): definition = definition[len("define"):].strip() else: continue if definition.endswith("\\"): # we don't support multiline macros continue i = definition.find(" ") j = definition.find("\t") if i != -1: if j != -1: i = min(i, j) else: i = i else: i = j if i == -1: # no value continue name = definition[:i] svalue = definition[i:].strip() items[name] = svalue v = items.items() v.sort() for name, svalue in v: if name.find("(") != -1: # macro with arguments continue if name == "OPENSSL_EXTERN" or \ name.startswith("BIO_TYPE_DGRAM_SCTP") or \ name.startswith("BIO_CTRL_DGRAM_SCTP") or \ name.startswith("SSL") or \ name.startswith("TLS") or \ name.startswith("DTLS1_") or \ name.startswith("COMP_") or \ name.endswith("_LONG_LOG2") or \ (name.endswith("_LONG") and name.count("_") == 1) or \ (name.endswith("_LONG64") and name.count("_") == 1) or \ (name.endswith("_INT") and name.count("_") == 1) or \ name == "BN_ULLONG" or \ name == "MD4_LONG" or \ name == "EXT_END" or \ name.startswith("OPENSSL_UNISTD_IO") or \ name.startswith("OPENSSL_DECLARE_") or \ name == "OPENSSL_EXPORT" or \ name == "OPENSSL_IMPORT" or \ name == "OPENSSL_GLOBAL" or \ name == "MY_UI_FLAG1" or \ name.endswith("_method") or \ name == "EVP_RC2_KEY_SIZE" or \ name == "EVP_RC4_KEY_SIZE" or \ name == "EVP_BLOWFISH_KEY_SIZE" or \ name == "EVP_CAST5_KEY_SIZE" or \ name == "EVP_RC5_32_12_16_KEY_SIZE" or \ name == "EVP_rc5_32_12_16_cfb" or \ name == "ENGINESDIR" or \ name == "CERT" or \ name == "RC4_CHUNK" or \ name == "M_PKCS12_cert_bag_type" or \ name == "EVP_idea_cfb" or \ name == "M_PKCS12_crl_bag_type" or \ False: continue # TODO add a type-check that it actually IS int (gcc-specific). if name.startswith("SN_") or name.startswith("LN_"): t = "s" tcast = "" else: t = "ld" tcast = "(long)" print("#ifdef %s" % (name, )) print("\tprintf(\"%s\t%s\t%%%s\\n\", %s %s);" % (header, name, t, tcast, name)) print("#endif")