Commit 54a92060 authored by Arne Koehn's avatar Arne Koehn

[incr-helper] allow lookahead in tagoutput

parent 4c0e2ee8
#! /usr/bin/env python
import sys
import getopt
opts,args = getopt.getopt(sys.argv[1:],[],["lookahead="])
lookahead = 0
for k,v in opts:
if k == "--lookahead":
lookahead=int(v)
# we use this buffer for storin
sentence = []
while True:
lastsentence = sentence # we need to keep track of the last
# sentence. If the new input is empty, we
# need to print the rest of the
# sentence. lastsentence is holding that
# information.
sentence = []
x = "NEWLINE"
y = ""
while x.strip() != "":
y = x
x = sys.stdin.readline()
sentence.append(x)
sentence.pop() # remove the empty line
if x == "":
if lookahead: # finish the last sentence
for i in lastsentence[(-1*lookahead):]:
print i,
exit() # eof reached
if y == "NEWLINE": # end of sentence -> two newlines, print one
if lookahead:
for i in lastsentence[(-1*lookahead):]:
print i,
print
else:
print y, # y has \n already, don't print a second one
if lookahead:
try:
print sentence[(-1*(lookahead+1))],
except IndexError:
pass # too early for output( second word, lookahead=2 or similar)
#print "DEBUG: too early for output"
else:
print y, # y has \n already, don't print a second one
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment