aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--COPYING4
-rw-r--r--Makefile2
-rw-r--r--README2
-rw-r--r--dist/archlinux/stable/PKGBUILD2
-rw-r--r--info/gpp.texinfo8
-rwxr-xr-xsrc/gpp.py80
-rw-r--r--tests/complex7
-rw-r--r--tests/quoted2
-rw-r--r--tests/quoted-brackets3
-rw-r--r--tests/unquoted2
10 files changed, 52 insertions, 60 deletions
diff --git a/COPYING b/COPYING
index ab19927..63a681e 100644
--- a/COPYING
+++ b/COPYING
@@ -1,6 +1,6 @@
-gpp – Bash based general purpose preprocessor
+gpp – Bash-based general-purpose preprocessor
-Copyright © 2013, 2014 Mattias Andrée (maandree@member.fsf.org)
+Copyright © 2013, 2014, 2015 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
diff --git a/Makefile b/Makefile
index 6a8162a..6dab478 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
-VERSION = 1.2
+VERSION = 1.3
PREFIX = /usr
DATA = /share
diff --git a/README b/README
index 6a3b981..61fbd1d 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
General Perprocessor
-Bash based preprocessor for anything.
+Bash-based preprocessor for anything.
diff --git a/dist/archlinux/stable/PKGBUILD b/dist/archlinux/stable/PKGBUILD
index eb5813f..e5e7319 100644
--- a/dist/archlinux/stable/PKGBUILD
+++ b/dist/archlinux/stable/PKGBUILD
@@ -3,7 +3,7 @@
pkgname=general-preprocessor
pkgver=1.3
pkgrel=1
-pkgdesc="Bash based preprocessor for anything"
+pkgdesc="Bash-based preprocessor for anything"
url="https://github.com/maandree/gpp"
arch=(any)
license=(GPL3)
diff --git a/info/gpp.texinfo b/info/gpp.texinfo
index 2698230..e39156b 100644
--- a/info/gpp.texinfo
+++ b/info/gpp.texinfo
@@ -12,12 +12,12 @@
@dircategory Development
@direntry
-* ?{GPP}: (?{GPP}). Bash based preprocessor for anything
+* ?{GPP}: (?{GPP}). Bash-based preprocessor for anything
@end direntry
@copying
-Copyright @copyright{} 2013 Mattias Andrée
+Copyright @copyright{} 2013, 2015 Mattias Andrée
@quotation
Permission is granted to copy, distribute and/or modify this document
@@ -31,13 +31,13 @@ Texts. A copy of the license is included in the section entitled
@ifnottex
@node Top
-@top gpp -- Bash based preprocessor for anything
+@top gpp -- Bash-based preprocessor for anything
@insertcopying
@end ifnottex
@titlepage
@title gpp
-@subtitle Bash based preprocessor for anything
+@subtitle Bash-based preprocessor for anything
@author by Mattias Andrée (maandree)
@page
diff --git a/src/gpp.py b/src/gpp.py
index 7d3f4f0..fb240fe 100755
--- a/src/gpp.py
+++ b/src/gpp.py
@@ -1,9 +1,9 @@
#!@{SHEBANG}
# -*- coding: utf-8 -*-
-'''
-gpp – Bash based general purpose preprocessor
+copyright = '''
+gpp – Bash-based general-purpose preprocessor
-Copyright © 2013, 2014 Mattias Andrée (maandree@member.fsf.org)
+Copyright © 2013, 2014, 2015 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
@@ -76,22 +76,7 @@ for i in range(1, len(args)):
print('gpp ' + VERSION)
sys.exit(0)
elif arg in ('-c', '--copying'):
- print('gpp -- Bash based general purpose preprocessor')
- print('')
- print('Copyright (C) 2013, 2014 Mattias Andrée (maandree@member.fsf.org)')
- print('')
- print('This program is free software: you can redistribute it and/or modify')
- print('it under the terms of the GNU General Public License as published by')
- print('the Free Software Foundation, either version 3 of the License, or')
- print('(at your option) any later version.')
- print('')
- print('This program is distributed in the hope that it will be useful,')
- print('but WITHOUT ANY WARRANTY; without even the implied warranty of')
- print('MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the')
- print('GNU General Public License for more details.')
- print('')
- print('You should have received a copy of the GNU General Public License')
- print('along with this program. If not, see <http://www.gnu.org/licenses/>.')
+ print(copyright[1:-1])
sys.exit(0)
else:
continue
@@ -157,27 +142,45 @@ def pp(line):
quote = []
n = len(line)
i = 0
+ rc.append(ord('\''))
while i < n:
c = line[i]
i += 1
if brackets > 0:
if esc:
esc = False
- elif (c in (ord(')'), ord('}'))):
+ elif len(quote) > 0:
+ if dollar:
+ dollar = False
+ if c == ord('('):
+ quote.append(ord(')'))
+ elif c == ord('{'):
+ quote.append(ord('}'))
+ elif c == quote[-1]:
+ quote[:] = quote[:-1]
+ elif (quote[-1] in (ord(')'), ord('}'))) and (c in (ord('"'), ord('\''), ord('`'))):
+ quote.append(c)
+ elif (c == ord('\\')) and (quote[-1] != ord('\'')):
+ esc = True
+ elif c == ord('$'):
+ dollar = True
+ elif c in (ord('"'), ord('\''), ord('`')):
+ quote.append(c)
+ elif c in (ord(')'), ord('}')):
brackets -= 1
if brackets == 0:
rc.append(c)
rc.append(ord('"'))
rc.append(ord('\''))
continue
- elif (c in (ord('('), ord('{'))):
+ elif c in (ord('('), ord('{')):
brackets += 1
elif c == ord('\\'):
esc = True
rc.append(c)
elif symb:
symb = False
- if (c in (ord('('), ord('{'))):
+ if c in (ord('('), ord('{')):
brackets += 1
rc.append(ord('\''))
rc.append(ord('"'))
@@ -186,29 +189,14 @@ def pp(line):
elif line[i - 1 : i + symlen - 1] == symbol:
symb = True
i += symlen - 1
- elif len(quote) > 0:
- if esc:
- esc = False
- elif dollar:
- dollar = False
- if c == ord('('):
- quote.append(ord(')'))
- elif c == ord('{'):
- quote.append(ord('}'))
- elif c == quote[-1]:
- quote[:] = quote[:-1]
- elif (quote[-1] in (ord(')'), ord('}'))) and (c in (ord('"'), ord('\''), ord('`'))):
- quote.append(c)
- elif (c == ord('\\')) and (quote[-1] != ord('\'')):
- esc = True
- elif c == ord('$'):
- dollar = True
+ elif c == ord('\''):
+ rc.append(c)
+ rc.append(ord('\\'))
rc.append(c)
- elif c in (ord('"'), ord('\''), ord('`')):
- quote.append(c)
rc.append(c)
else:
rc.append(c)
+ rc.append(ord('\''))
return rc
for _ in range(iterations):
@@ -223,16 +211,6 @@ for _ in range(iterations):
elif entered:
bashed.append(line)
else:
- buf = []
- for c in line:
- if c == ord('\''):
- buf.append(c)
- buf.append(ord('\\'))
- buf.append(c)
- buf.append(c)
- else:
- buf.append(c)
- line = [ord('\'')] + buf + [ord('\'')]
buf = bytelist(('echo $\'\\e%i\\e\'' % lineno).encode())
bashed.append(buf + pp(line))
diff --git a/tests/complex b/tests/complex
new file mode 100644
index 0000000..2f6af5b
--- /dev/null
+++ b/tests/complex
@@ -0,0 +1,7 @@
+@<set -v # the last line should not appear, unless you have a $()$() command
+@>
+@>h=H
+
+'@{h}ello @(echo `echo 'W'`"o$(echo $(echo r))"'ld!')'
+@('$()$()')
+
diff --git a/tests/quoted b/tests/quoted
new file mode 100644
index 0000000..469b5d8
--- /dev/null
+++ b/tests/quoted
@@ -0,0 +1,2 @@
+@>set -v
+'ello @(echo 'world')!!!
diff --git a/tests/quoted-brackets b/tests/quoted-brackets
new file mode 100644
index 0000000..5b170d8
--- /dev/null
+++ b/tests/quoted-brackets
@@ -0,0 +1,3 @@
+@>set -v
+'ello @(echo 'wo(rld')!!!
+'ello @(echo 'wo)rld')!!!
diff --git a/tests/unquoted b/tests/unquoted
new file mode 100644
index 0000000..ac3742e
--- /dev/null
+++ b/tests/unquoted
@@ -0,0 +1,2 @@
+@>set -v
+'ello @(echo world)!!!