From ab273d8948d88df7269358973f8151513b00a40f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 13 Feb 2017 08:46:05 +0100 Subject: Fix -n and escaped symbols MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/gpp.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/gpp.py') diff --git a/src/gpp.py b/src/gpp.py index ce35380..7d537fe 100755 --- a/src/gpp.py +++ b/src/gpp.py @@ -3,7 +3,7 @@ copyright = ''' gpp – Bash-based general-purpose preprocessor -Copyright © 2013, 2014, 2015 Mattias Andrée (maandree@member.fsf.org) +Copyright © 2013, 2014, 2015, 2017 Mattias Andrée (maandree@member.fsf.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -93,7 +93,7 @@ if iterations < 1: data = None with open(input_file, 'rb') as file: data = file.read() - with open(write_file, 'wb') as file: + with open(output_file, 'wb') as file: file.write(data) file.flush() sys.exit(0) @@ -178,6 +178,11 @@ def pp(line): elif c == ord('\\'): esc = True rc.append(c) + elif line[i - 1 : i + symlen - 1] == symbol: + if symb: + rc += symbol + symb = not symb + i += symlen - 1 elif symb: symb = False if c in (ord('('), ord('{')): @@ -192,9 +197,6 @@ def pp(line): rc.append(ord('\\')) rc.append(c) rc.append(c) - elif line[i - 1 : i + symlen - 1] == symbol: - symb = True - i += symlen - 1 elif c == ord('\''): rc.append(c) rc.append(ord('\\')) -- cgit v1.2.3-70-g09d2