forked from se-sic/cppstats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove_multiple_macros.py
executable file
·72 lines (55 loc) · 1.42 KB
/
move_multiple_macros.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
65
66
67
68
69
70
71
#!/usr/bin/python
# -*- coding: utf-8 -*-
# this script is made for changing macros that span over
# multiple lines (examples see below) to one line for
# better parsing
# e.g.:
# #define FillGroup1 \
# "mov r11,r2 \n\t" \
# "mov r10,r2 \n\t" \ ...
#
# effects all kind of macros #defines, conditionals, ...
__author__ = "Jörg Liebig"
__date__ = "$Date:$"
__version__ = "$Rev:$"
import os, sys
# translates macros (s.o. or usage)
def translate(infile, outfile):
fdin = open(infile)
fdout = open(outfile, 'w')
curline = ''
for line in fdin:
line = line.strip()
# macro found
if len(curline):
# multi-line macro
if line.endswith('\\'):
curline += line[:-1]
else:
curline += line
fdout.write(curline+'\n')
curline = ''
continue
# found a new macro
if (line.startswith('#') and line.endswith('\\')):
curline += line[:-1]
continue
# normal line
fdout.write(line+'\n')
# closeup
fdin.close()
fdout.close()
# usage
def usage():
print('usage: ' + sys.argv[0] + ' <infile> <outfile>')
print('')
print('Translates multiple macros in the source-code of the infile')
print('to a oneliner-macro in the outfile.')
##################################################
if __name__ == '__main__':
if (len(sys.argv) < 3):
usage()
sys.exit(-1)
infile = os.path.abspath(sys.argv[1])
outfile = os.path.abspath(sys.argv[2])
translate(infile, outfile)