aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-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')