diff options
| author | Mattias Andrée <maandree@operamail.com> | 2014-10-31 23:31:45 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2014-10-31 23:31:45 +0100 |
| commit | c5860aa2d8176f134d3599af6f9f98ffa37bec40 (patch) | |
| tree | 6afeffcae7bedce6c6d5fad157dd0d6440d9975b /src | |
| parent | bump year (diff) | |
| download | splashtool-c5860aa2d8176f134d3599af6f9f98ffa37bec40.tar.gz splashtool-c5860aa2d8176f134d3599af6f9f98ffa37bec40.tar.bz2 splashtool-c5860aa2d8176f134d3599af6f9f98ffa37bec40.tar.xz | |
replace a python file with a sed+awk sequence
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
| -rwxr-xr-x | src/splashtool | 15 | ||||
| -rwxr-xr-x | src/trim.py | 35 |
2 files changed, 24 insertions, 26 deletions
diff --git a/src/splashtool b/src/splashtool index 6c96aee..95f8975 100755 --- a/src/splashtool +++ b/src/splashtool @@ -18,11 +18,22 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. - in="$(realpath "$1")" out="$(realpath "$2")" d="$(dirname "$(realpath "$0")")" +# Remove all information we do not need. +trim () +{ + sed -e 's/\t/ /g' | sed -e '/^[ \t]*\(#\|$\)/d' -e 's/ #.*$//' -e 's/^ *//' -e 's/ *$//' | + awk ' BEGIN { text = 0; } + { t=tolower($1); + if (t=="text") text+=1; + if (t=="timeout" || t=="menu" || t=="font" || text==1) print $LINE; + if (t=="endtext") text+=1; + }' +} + cd "$(dirname "$1")" -cat "$in" | "$d"/trim.py | "$d"/parse.py | java -cp "$d" Assemble "$out" "$3" +trim < "$in" | "$d"/parse.py | java -cp "$d" Assemble "$out" "$3" diff --git a/src/trim.py b/src/trim.py index c623f74..72a1b3f 100755 --- a/src/trim.py +++ b/src/trim.py @@ -24,32 +24,19 @@ firsttext = True while True: try: - line = input().replace('\t', ' ') + line = input() lower = line.lower() - if line.replace(' ', '').startswith('#') or (len(line.replace(' ', '')) == 0): - continue - else: - if ' # ' in line: - line = line[:line.find(' # ')] - lower = lower[:lower.find(' # ')] - while line.startswith(' '): - line = line[1:] - lower = lower[1:] - while line.endswith(' '): - line = line[:-1] - lower = lower[:-1] - - if lower.startswith('text '): - text = True - if firsttext: - print(line) - elif lower == 'endtext': - text = False - if firsttext: - print(line) - firsttext = False - elif (text and firsttext) or (lower.split(' ')[0] in ('timeout', 'menu', 'font')): + if lower.startswith('text '): + text = True + if firsttext: print(line) + elif lower == 'endtext': + text = False + if firsttext: + print(line) + firsttext = False + elif (text and firsttext) or (lower.split(' ')[0] in ('timeout', 'menu', 'font')): + print(line) except: break |
