white = re.compile(r'^\s+')
cppcomment = re.compile(r'\/\/.*$')
+nonident = re.compile(r'[^a-zA-Z0-9_]')
headerdirect = []
cppdirect = []
pass
def GuardName(self, name):
- name = '_'.join(name.split('.'))
- name = '_'.join(name.split('/'))
- guard = '_' + name.upper() + '_'
-
- return guard
+ # Use the complete provided path to the input file, with all
+ # non-identifier characters replaced with underscores, to
+ # reduce the chance of a collision between guard macros.
+ return '_' + nonident.sub('_', name).upper() + '_'
def HeaderPreamble(self, name):
guard = self.GuardName(name)
'#define %s\n\n' ) % (
name, guard, guard)
- # insert stdint.h - let's hope everyone has it
- pre += (
- '#include <event-config.h>\n'
- '#ifdef _EVENT_HAVE_STDINT_H\n'
- '#include <stdint.h>\n'
- '#endif\n' )
-
for statement in headerdirect:
pre += '%s\n' % statement
if headerdirect:
pre += '\n'
- pre += '#include <event2/rpc.h>'
+ pre += (
+ '#include <event2/util.h> /* for ev_uint*_t */\n'
+ '#include <event2/rpc.h>\n'
+ )
return pre
global _VERSION
header_file = '.'.join(name.split('.')[:-1]) + '.gen.h'
+ slash = header_file.rfind('/')
+ if slash != -1:
+ header_file = header_file[slash+1:]
pre = ( '/*\n'
' * Automatically generated from %s\n'
' * by %s/%s. DO NOT EDIT THIS FILE.\n'
' */\n\n' ) % (name, _NAME, _VERSION)
- pre += ( '#include <sys/types.h>\n'
- '#include <sys/time.h>\n'
- '#include <stdlib.h>\n'
+ pre += ( '#include <stdlib.h>\n'
'#include <string.h>\n'
'#include <assert.h>\n'
'#include <event2/event.h>\n'