From 5a4f6f9d83eb12b1e53cbab3a82381263c4a3e09 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 6 Oct 2013 12:34:30 +0200 Subject: beginning of gpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/gpp.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/gpp.py (limited to 'src') 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))) + -- cgit v1.2.3-70-g09d2