'''
A script used to extract almost all constants from C header files (*.h).

(c) 2007-2008 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or 
 (at your option) any later version.

'''

import re, sys

clamav_h = open('/usr/include/clamav.h', 'rt')

reg_define = re.compile(
  r'^#define\s+(CL_)([A-Z0-9a-z_]+)\s+(.*)$'
)

if len(sys.argv)>1:
  sys.stdout = open(sys.argv[1], 'wt')

print """\
# This file is automatically generated by getconst.py.
CL_CLEAN = 0
"""
for line in clamav_h.readlines():
  # handle comments and trailing new lines
  line = line.strip().replace('/*', '#').replace('*/', '#')
  # search for #define line
  r = reg_define.search(line)
  if r:
    print "%s%s = %s" % r.groups()
    print "%s = %s" % (r.group(2), r.group(3))
