1
- import re
2
- with open ('..\\ flagdefs.cpp' ,'r' ) as f :
3
- data = f .read ()
4
- #\n\s*\"([^"]+)\"
5
- out = []
6
- for identifier ,name in re .findall (r'^static Flag ([a-z0-9_]+) = Flag\(\n\s*\"([^"]+)\"' ,data ,re .DOTALL | re .MULTILINE ):
7
- out .append ((name ,identifier ))
8
-
9
- out .sort ()
10
-
11
- print 'class Flag far *PRIDE_FLAGS[]={'
12
- for name ,identifier in out :
13
- print '\t &{},' .format (identifier )
14
- print '\t NULL\n };\n '
1
+ import re , os , glob
2
+
3
+
4
+ prideflags = []
5
+ for filepath in glob .glob (os .path .join ('..' ,'*.cpp' )):
6
+ with open (filepath ,'r' ) as f :
7
+ data = f .read ()
8
+ seenfile = False
9
+ for identifier ,name in re .findall (r'^(?:static )?Flag ([a-z0-9_]+) = Flag\(\n\s*\"([^"]+)\"' ,data ,re .DOTALL | re .MULTILINE ):
10
+ if not seenfile :
11
+ seenfile = True
12
+ print '{}:' .format (filepath )
13
+
14
+ print ' * Found "{}"' .format (name )
15
+ prideflags .append ((name ,identifier ))
16
+
17
+ prideflags .sort ()
18
+
19
+ with open (os .path .join ('..' ,'flagordr.h' ),'w' ) as f :
20
+ print >> f ,'// Generated by py\\ sort_flags.py'
21
+ print >> f ,'class Flag far *PRIDE_FLAGS[]={'
22
+ for name , identifier in prideflags :
23
+ print >> f ,'\t &{},' .format (identifier )
24
+ print >> f ,'\t NULL\n };\n '
0 commit comments