From f136aac49b09ab9746c236d2cce93d220800724f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 24 Oct 2013 21:49:04 +0200 Subject: add option: -u twice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- info/gpp.texinfo | 12 +++++++++++- src/gpp.py | 11 ++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/info/gpp.texinfo b/info/gpp.texinfo index 20049f4..133afc5 100644 --- a/info/gpp.texinfo +++ b/info/gpp.texinfo @@ -118,10 +118,20 @@ Number of iterations to run the preprocessing in. (Default: 1) @item -u @itemx --unshebang -Bland out the shebang line. Notice that the line is not removed, +Blank out the shebang line. Notice that the line is not removed, it is just cleared. You can use a shebang line make gpp preprocess the file when executed. +If @option{--unshebang} is used twice, the second line in the +file will be moved up to the top of the file and the initial +shebang line will be removed. A blank line will be inserted +after the new top line will be added to keep the line numbers +in the output file as near as possible to the line numbers +in the input file. The intension of this option is that you +can have two shebang lines, one on the first line for preprocessing +when the file is executed, and one shebang line on the second +line for output file. + @item -i @itemx --input Set the input file. (Default: /dev/stdin) diff --git a/src/gpp.py b/src/gpp.py index 6881d98..5200b2a 100755 --- a/src/gpp.py +++ b/src/gpp.py @@ -29,7 +29,7 @@ encoding = 'utf-8' iterations = 1 input_file = '/dev/stdin' output_file = '/dev/stdout' -unshebang = False +unshebang = 0 args = sys.argv @@ -46,7 +46,7 @@ for i in range(1, len(args)): if arg in ('-s', '--symbol'): symbol = sys.argv[i] elif arg in ('-e', '--encoding'): encoding = sys.argv[i] elif arg in ('-n', '--iterations'): iterations = int(sys.argv[i]) - elif arg in ('-u', '--unshebang'): unshebang = True; continue + elif arg in ('-u', '--unshebang'): unshebang += 1; continue elif arg in ('-i', '--input'): input_file = sys.argv[i] elif arg in ('-o', '--output'): output_file = sys.argv[i] elif arg in ('-f', '--file'): @@ -100,10 +100,15 @@ data = None with open(input_file, 'rb') as file: data = file.read().decode(encoding, 'error').split('\n') -if unshebang: +if unshebang == 1: if data[0][:2] == '#!': data[0] = '' +if unshebang >= 2: + if data[0][:2] == '#!': + data[0] = data[1] + data[1] = '' + def pp(line): rc = '' symb = False -- cgit v1.2.3-70-g09d2