aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpp.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/gpp.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/gpp.py b/src/gpp.py
new file mode 100644
index 0000000..7771398
--- /dev/null
+++ b/src/gpp.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python3
+
+import sys
+
+symbol = '@'
+encoding = 'utf-8'
+input_file = '/dev/stdin'
+output_file = '/dev/stdout'
+
+data = None
+with open(input_file, 'rb') as file:
+ data = file.read().decode(encoding, 'error').split('\n')
+
+entered = False
+bashed = []
+
+def pp(line):
+ rc = ''
+ symb = False
+ for c in line:
+ if symb:
+ symb = False
+ if c == symbol:
+ rc += c
+ elif c == symbol:
+ symb = True
+ else:
+ rc += c
+ return rc
+
+for lineno in range(len(data)):
+ line = data[lineno]
+ if line.startswith(symbol + '<'):
+ bashed.append(line[2:])
+ entered = True
+ elif line.startswith(symbol + '>'):
+ bashed.append(line[2:])
+ entered = False
+ elif entered:
+ bashed.append(line)
+ else:
+ line = '\'%s\'' % line.replace('\'', '\'\\\'\'')
+ bashed.append('echo %i %s' % (lineno, pp(line)))
+