#
#
# patch "builtpython.sh"
# from [f6751550dd0706450b55908b9bb10896c9401a2f]
# to [c1d18a362622ec209ea6818957a5778d5374de45]
#
# patch "enscriptlangs.py"
# from [de603c91038f329cce1cca8a30ea161b2271e2f6]
# to [95c443cac402a883b7f523a46faba66d2c79caaf]
#
# patch "file.psp"
# from [154e97fe58ebbe211c7bec8fee580d25b8b150ab]
# to [26e32a4f1b347134e2d1fa0fdfdc7ff6461a4732]
#
# patch "utility.py"
# from [fb51955563d64e628e0e67e4acca1a1abc4cd989]
# to [c1f6a1ef480d6270c208d9b74a6dcbe1b8be7a06]
#
============================================================
--- builtpython.sh f6751550dd0706450b55908b9bb10896c9401a2f
+++ builtpython.sh c1d18a362622ec209ea6818957a5778d5374de45
@@ -1,11 +1,11 @@
#!/bin/sh
# generate the list of enscript formatting options
LANGS=enscriptlangs.py
echo -n 'enscript_langs = [' > "$LANGS"
for i in `enscript --help-highlight | grep Name | awk {'print $2'}`; do
- echo -n "'$i', " > "$LANGS"
-done; echo ']' > "$LANGS"
+ echo -n "'$i', " >> "$LANGS"
+done; echo ']' >> "$LANGS"
# generate the help file data
AUTHORS=authors.py
============================================================
--- enscriptlangs.py de603c91038f329cce1cca8a30ea161b2271e2f6
+++ enscriptlangs.py 95c443cac402a883b7f523a46faba66d2c79caaf
@@ -1 +1 @@
-]
+enscript_langs = ['ada', 'asm', 'awk', 'bash', 'changelog', 'cpp', 'csh', 'c', 'delphi', 'diffs', 'diff', 'diffu', 'dylan', 'eiffel', 'elisp', 'erlang', 'forth', 'fortran_pp', 'fortran', 'haskell', 'html', 'icon', 'idl', 'inf', 'javascript', 'java', 'ksh', 'lua', 'm4', 'mail', 'makefile', 'matlab', 'nroff', 'oberon2', 'objc', 'outline', 'oz', 'pascal', 'perl', 'postscript', 'pyrex', 'python', 'rfc', 'scheme', 'sh', 'skill', 'Smalltalk', 'sml', 'sql', 'states', 'synopsys', 'tcl', 'tcsh', 'tex', 'vba', 'verilog', 'vhdl', 'vrml', 'wmlscript', 'zsh', ]
============================================================
--- file.psp 154e97fe58ebbe211c7bec8fee580d25b8b150ab
+++ file.psp 26e32a4f1b347134e2d1fa0fdfdc7ff6461a4732
@@ -11,6 +11,7 @@
import os
from enscriptlangs import enscript_langs
from html import get_icon, TableWriter
+from utility import run_command
# file.psp ; provide information about a file
# if possible, display it (with syntax highlighting, etc.)
@@ -100,21 +101,33 @@
if display_as_image:
req.write('''')
+ def stop_code():
+ req.write('')
+ def text():
+ start_code()
+ req.write(hq(contents))
+ stop_code()
+ def enscript():
+ command = config.enscript_path + ' -o - --color -w html'
command += ' --highlight=%s' % (pipes.quote(filter))
- p_in, p_out = os.popen2(command)
- p_in.write(contents)
- p_in.close()
- in_contents = False
- for line in p_out:
- if line.startswith('
'):
- in_contents = True
- req.write('')
- elif in_contents:
- req.write(line)
- if line.startswith(''): in_contents = False
+ req.write("%s
" % command)
+ result = run_command(command, to_child=contents)
+ if result['exitcode'] != 0:
+ raise Exception('Error running enscript.')
+ in_contents = False
+ for line in result['fromchild'].split('\n'):
+ if line.startswith(''):
+ in_contents = True
+ start_code()
+ elif line.startswith(''):
+ in_contents = False
+ stop_code()
+ elif in_contents:
+ req.write(line + '\r\n')
+ if filter == "text": text()
+ else: enscript()
else:
req.write('''This file seems to binary and not suitable for display in the browser. You must %s the file and use a suitable viewer.
''' % (link("download", [matching_file_id, path], "download")))
req.write('''''')
============================================================
--- utility.py fb51955563d64e628e0e67e4acca1a1abc4cd989
+++ utility.py c1f6a1ef480d6270c208d9b74a6dcbe1b8be7a06
@@ -8,7 +8,7 @@
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NDELAY)
-def run_command(command, timeout=None):
+def run_command(command, timeout=None, to_child=None):
"returns a tuple of (was_timeout, exit_code, data_read)"
p = popen2.Popen3(command, capturestderr=True)
set_nonblocking(p.fromchild)
@@ -16,6 +16,9 @@
fromchild_read = ""
childerr_read = ""
was_timeout = False
+ if to_child != None:
+ p.tochild.write(to_child)
+ p.tochild.close()
while 1:
ro, rw, re = select.select([p.fromchild], [], [p.childerr], timeout)
if not ro and not rw and not re:
@@ -37,7 +40,6 @@
try: childerr_read += p.childerr.read()
except IOError: pass
p.fromchild.close()
- p.tochild.close()
# if there wasn't a timeout, the program should have exited; in which case we should wait() for it
# otherwise, it might be hung, so the parent should wait for it.
# (wrap in a try: except: just in case some other thread happens to wait() and grab ours; god wrapping