def warranty ():
identify (sys.stdout)
sys.stdout.write ('\n')
- sys.stdout.write (_ ('Copyright (c) %s by' % ' 1998--2003'))
+ sys.stdout.write (_ ("Copyright (c) %s by") % '1998--2004')
sys.stdout.write ('\n')
map (lambda x: sys.stdout.write (' %s\n' % x), __main__.copyright)
sys.stdout.write ('\n')
sys.stderr.write (s)
def warning (s):
- sys.stderr.write (__main__.program_name + ": " + _ ("warning: ") + s + '\n')
+ sys.stderr.write (__main__.program_name + ": " + _ ("warning: %s") % s + '\n')
def error (s):
- sys.stderr.write (__main__.program_name + ": " + _ ("error: ") + s + '\n')
+ sys.stderr.write (__main__.program_name + ": " + _ ("error: %s") % s + '\n')
def exit (i):
if __main__.verbose_p:
return __main__.temp_dir
def command_name (cmd):
- return re.match ('^[ \t]*([^ \t]*)', cmd).group (1)
+
+ # deal with "((latex ) >& 1 ) .." too
+ cmd = re.match ("([\(\)]*)([^ ]*)", cmd).group(2)
+ return os.path.split (cmd)[1]
def error_log (name):
- name = re.sub('[/:]','x',name)
+ name = re.sub('[^a-z]','x', name)
return tempfile.mktemp ('%s.errorlog' % name)
def read_pipe (cmd, mode = 'r'):
+
+
redirect = ''
error_log_file = ''
if __main__.verbose_p:
progress (_ ("Opening pipe `%s\'") % cmd)
+ else:
error_log_file = error_log (command_name (cmd))
redirect = ' 2>%s' % error_log_file
if status:
error (_ ("`%s\' failed (%d)") % (cmd, exit_status))
+
if not __main__.verbose_p:
- error (_ ("The error log is as follows:"))
- sys.stderr.write (open (error_log (command_name (cmd)).read ()))
+ contents = open (error_log_file).read ()
+ if contents:
+ error (_ ("The error log is as follows:"))
+ sys.stderr.write (contents)
+
+ # Ugh. code dup
+ if error_log_file:
+ os.unlink (error_log_file)
+
exit (status)
if __main__.verbose_p:
Exit status of CMD '''
name = command_name (cmd)
-
+ error_log_file = ''
+
if __main__.verbose_p:
progress_p = 1
progress (_ ("Invoking `%s\'") % cmd)
redirect = ''
if not progress_p:
- redirect = ' 1>/dev/null 2>' + error_log (name)
+ error_log_file = error_log (name)
+ redirect = ' 1>/dev/null 2>' + error_log_file
elif __main__.pseudo_filter_p:
redirect = ' 1>/dev/null'
-
+
status = os.system (cmd + redirect)
signal = 0x0f & status
exit_status = status >> 8
warning (msg + ' ' + _ ("(ignored)"))
else:
error (msg)
- if not progress_p:
+ if not progress_p and error_log_file:
error (_ ("The error log is as follows:"))
- sys.stderr.write (open (error_log (name)).read ())
+ sys.stderr.write (open (error_log_file).read ())
+ if error_log_file:
+ os.unlink (error_log_file)
exit (status)
+ if error_log_file:
+ os.unlink (error_log_file)
progress ('\n')
return status
for (k,v) in os.environ.items ():
sys.stderr.write ("%s=\"%s\"\n" % (k, v))
+BOUNDING_BOX_RE = '^%%BoundingBox: (-?[0-9]+) (-?[0-9]+) (-?[0-9]+) (-?[0-9]+)'
def get_bbox (filename):
bbox = filename + '.bbox'
## -sOutputFile does not work with bbox?
(filename, bbox)
system (cmd, progress_p = 1)
box = open (bbox).read ()
- m = re.match ('^%%BoundingBox: ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)',
- box)
+ m = re.match (BOUNDING_BOX_RE, box)
gr = []
if m:
gr = map (string.atoi, m.groups ())
output_file = re.sub (r'\.e?ps', '.png', ps_name)
- margin = 0
+
+ # need to have margin, otherwise edges of letters will
+ # be cropped off.
+
+ margin = 3
fo = open (trans_ps, 'w')
fo.write ('%d %d translate\n' % (-bbox[0] + margin,
-bbox[1] + margin))
map (os.unlink, rms)
else:
output_file = re.sub (r'\.e?ps', '-page%d.png', ps_name)
+
rmfile = base + '.png'
if os.path.isfile (rmfile):
os.unlink (rmfile)
cmd = r'''gs -s -sDEVICE=pnggray -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q -sOutputFile=%s -dNOPAUSE -r%d %s -c quit''' % (output_file,
resolution, ps_name)
-
+
status = system (cmd)
signal = 0xf & status
exit_status = status >> 8