aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpp.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-10-11 10:08:36 +0200
committerMattias Andrée <maandree@operamail.com>2013-10-11 10:08:36 +0200
commitff502665a3b2ce1b4485d1fdb837c62770c20086 (patch)
tree2c6ff5e401b943974409c61585e472857424f418 /src/gpp.py
parentparse command line (diff)
downloadgpp-ff502665a3b2ce1b4485d1fdb837c62770c20086.tar.gz
gpp-ff502665a3b2ce1b4485d1fdb837c62770c20086.tar.bz2
gpp-ff502665a3b2ce1b4485d1fdb837c62770c20086.tar.xz
add iteration parameter (not used yet)
Diffstat (limited to 'src/gpp.py')
-rw-r--r--src/gpp.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/gpp.py b/src/gpp.py
index 827720a..9a0e086 100644
--- a/src/gpp.py
+++ b/src/gpp.py
@@ -5,16 +5,18 @@ from subprocess import Popen, PIPE
symbol = '@'
encoding = 'utf-8'
+iterations = 1
input_file = '/dev/stdin'
output_file = '/dev/stdout'
for i in range(1, len(sys.argv)):
arg = sys.argv[i]
i += 1
- if arg in ('-s', '--symbol'): symbol = sys.argv[i]
- elif arg in ('-e', '--encoding'): encoding = sys.argv[i]
- elif arg in ('-i', '--input'): input_file = sys.argv[i]
- elif arg in ('-o', '--output'): output_file = sys.argv[i]
+ if arg in ('-s', '--symbol'): symbol = sys.argv[i]
+ elif arg in ('-e', '--encoding'): encoding = sys.argv[i]
+ else arg in ('-n', '--iterations') iterations = int(sys.argv[i])
+ elif arg in ('-i', '--input'): input_file = sys.argv[i]
+ elif arg in ('-o', '--output'): output_file = sys.argv[i]
elif arg in ('-f', '--file'):
input_file = sys.argv[i]
output_file = sys.argv[i]
@@ -25,6 +27,15 @@ for i in range(1, len(sys.argv)):
if input_file == '-': input_file = '/dev/stdin'
if output_file == '-': output_file = '/dev/stdout'
+if iterations < 1:
+ if input_file != output_file:
+ data = None
+ with open(input_file, 'rb') as file:
+ data = file.read()
+ with open(write_file, 'wb') as file:
+ file.write(data)
+ sys.exit(0)
+
data = None
with open(input_file, 'rb') as file:
data = file.read().decode(encoding, 'error').split('\n')