From 646274a0abeafe9f65ace6fc70da3235b82a75ab Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 9 Oct 2013 10:47:24 +0200 Subject: error fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/gpp.py | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/gpp.py b/src/gpp.py index b14e538..5828a7b 100644 --- a/src/gpp.py +++ b/src/gpp.py @@ -23,25 +23,7 @@ def pp(line): dollar = False quote = [] for c in line: - if len(quote) > 0: - if esc: - esc = False - elif dollar: - dollar = False - if c == '(': - quote.append(')') - elif c == '{': - quote.append('}') - elif c == quote[-1]: - quote[:] = quote[:-1] - elif (quote[-1] in ')}') and (c in '\'"`'): - quote.append(c) - elif (c == '\\') and (quote[-1] != "'"): - esc = True - elif c == '$': - dollar = True - rc += c - elif brackets > 0: + if brackets > 0: if esc: esc = False elif (c == ')') or (c == '}'): @@ -56,13 +38,31 @@ def pp(line): rc += c elif symb: symb = False - if c == symbol: + if (c == '(') or (c == '{'): + brackets += 1 + rc += '\'"$' + c + else: rc += c elif c == symbol: symb = True - elif (c == '(') or (c == '{'): - brackets += 1 - rc += '\'"$' + c + elif len(quote) > 0: + if esc: + esc = False + elif dollar: + dollar = False + if c == '(': + quote.append(')') + elif c == '{': + quote.append('}') + elif c == quote[-1]: + quote[:] = quote[:-1] + elif (quote[-1] in ')}') and (c in '\'"`'): + quote.append(c) + elif (c == '\\') and (quote[-1] != "'"): + esc = True + elif c == '$': + dollar = True + rc += c elif (c == '"') or (c == "'") or (c == '`'): quote.append(c) rc += c @@ -82,7 +82,7 @@ for lineno in range(len(data)): bashed.append(line) else: line = '\'%s\'' % line.replace('\'', '\'\\\'\'') - bashed.append('echo $\'\\e%i\\e\' %s' % (lineno, pp(line))) + bashed.append('echo $\'\\e%i\\e\'%s' % (lineno, pp(line))) bashed = '\n'.join(bashed).encode(encoding) bash = Popen(["bash"], stdin = PIPE, stdout = PIPE, stderr = sys.stderr) -- cgit v1.2.3-70-g09d2