summaryrefslogtreecommitdiff
path: root/squeeze.py
blob: ce56a86ecda4fb912882178b10b14a5640b5f206 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import re
import sys

output = ''

while True:
  line = sys.stdin.readline()
  if not line: break
  if line[0] == '#':
    if output:
      print output
      output = ''
    print line.strip()
  else:
    x = re.findall('\w+|\W',line)
    for u in x:
      if not u.isspace():
        if len(output) + len(u) > 140:
          print output
	  output = ''
        if (re.match('\w',output[-1:]) and re.match('\w',u[:1])) or (output[-1:] == '=' and u[:1] == '-'):
          if len(output) + 1 + len(u) > 140:
	    print output
	    output = ''
	  else:
            output += ' '
        output += u

print output