diff options
author | Mattias Andrée <maandree@operamail.com> | 2013-10-06 12:34:30 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2013-10-06 12:34:30 +0200 |
commit | 5a4f6f9d83eb12b1e53cbab3a82381263c4a3e09 (patch) | |
tree | 7b58a1d13feb9bf5e2f03d42250471f6988a8eb3 /src/gpp.py | |
parent | add readme (diff) | |
download | gpp-5a4f6f9d83eb12b1e53cbab3a82381263c4a3e09.tar.gz gpp-5a4f6f9d83eb12b1e53cbab3a82381263c4a3e09.tar.bz2 gpp-5a4f6f9d83eb12b1e53cbab3a82381263c4a3e09.tar.xz |
beginning of gpp
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/gpp.py')
-rw-r--r-- | src/gpp.py | 44 |
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))) + |