Skip to content

Commit

Permalink
update r950
Browse files Browse the repository at this point in the history
  • Loading branch information
srz-zumix committed Oct 26, 2015
1 parent 7b258a1 commit 22ebe5d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
11 changes: 11 additions & 0 deletions tools/python/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Makefile

.PHONY: sample clean
TOOLS=eval_line.py

sample: $(TOOLS) Makefile
python eval_line.py '#define PP_INC_$${line} $${line+1}' -r 255 -s 1 -o pp_inc.h --encoding utf-8-sig

clean:
rm -rf pp_inc.h
26 changes: 15 additions & 11 deletions tools/python/eval_line.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/usr/bin/env python
#
# eval_line.py
#
# Copyright (C) 2014, Takazumi Shirayanagi
# Copyright (C) 2014-2015, Takazumi Shirayanagi
# This software is released under the new BSD License,
# see LICENSE
#

import sys
import argparse
import re
import codecs

from argparse import ArgumentParser

Expand All @@ -31,7 +33,6 @@ def parse_command_line():
'-r'
, '--repeat'
, action=EvalIntAction
, dest = 'repeat'
, nargs=1
, help = 'Set eval repeat count.'
, default = 1
Expand All @@ -40,28 +41,28 @@ def parse_command_line():
'-s'
, '--start'
, action=EvalIntAction
, dest = 'start'
, nargs=1
, help = 'Set eval repeat start no.'
, default = 0
)
parser.add_argument(
'-o'
, '--output'
, dest = 'output'
, help = 'output file path.'
, default = None
)
parser.add_argument(
'--encoding'
, help = 'output file encoding.'
, default = None
)
parser.add_argument(
'expression'
, metavar='EXP'
, help = 'eval expressions'
, nargs='+'
)
if len(sys.argv) <= 1:
parser.error('invalid number arguments')

options = parser.parse_args(sys.argv)
options = parser.parse_args()
return options

def eval_line(r, define, line):
Expand All @@ -77,16 +78,19 @@ def eval_line(r, define, line):
def main():
re_eval = re.compile(r'\${([^}]+)}')
options = parse_command_line()
define = options.expression[1]
for a in options.expression[2:]:
define = options.expression[0]
for a in options.expression[1:]:
define += ' ' + a

output = options.output
if output == None:
for line in range(options.repeat):
print eval_line(re_eval, define, line+options.start)
else:
file = open(output, 'w')
if options.encoding:
file = codecs.open(output, 'w', options.encoding)
else:
file = open(output, 'w')
for line in range(options.repeat):
file.write( eval_line(re_eval, define, line+options.start) )
file.write( '\n' )
Expand Down

0 comments on commit 22ebe5d

Please sign in to comment.