-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmkevents.py
executable file
·64 lines (50 loc) · 1.16 KB
/
mkevents.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python2
import sys
sys.path.append('stats/')
from hdata import Events
assert len(sys.argv) == 2, sys.argv
if sys.argv[1] == 'h':
print """/*
harris - a strategy game
Copyright (C) 2012-2013 Edward Cree
licensed under GPLv3+ - see top of harris.c for details
events: maps event names to ids
*/
#ifndef HAVE_EVENTS_H
#define HAVE_EVENTS_H
"""
for i,e in enumerate(Events):
print "#define EVENT_%s %d" % (e['id'], i)
print "#define NEVENTS %d" % len(Events)
print
print "extern const char *event_names[%d];" % len(Events)
print
print "int find_event(const char *name);"
print
print "#endif /* HAVE_EVENTS_H */"
else:
assert sys.argv[1] == 'c', sys.argv
print """/*
harris - a strategy game
Copyright (C) 2012-2013 Edward Cree
licensed under GPLv3+ - see top of harris.c for details
events: maps event names to ids
*/
#include "events.h"
#include <string.h>
"""
print "const char *event_names[%d]={" % len(Events)
for e in Events:
print '\t"%s",' % e['id']
print "};"
print """
int find_event(const char *name)
{
int i;
for(i=0;i<NEVENTS;i++)
if(!strcmp(name, event_names[i]))
break;
if(i<NEVENTS)
return i;
return -1;
}"""