diff options
-rw-r--r-- | src/gpp.py | 48 |
1 files changed, 24 insertions, 24 deletions
@@ -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) |