# should also support fragment in
'output-all': r"""
-@include %(fn)s-doc.texi
@tex
\catcode`\@=12
\input lilyponddefs
needed_filetypes.append('png')
if 'eps' in opts and not ('eps' in needed_filetypes):
needed_filetypes.append('eps')
- outname = os.path.join(g_outdir, basename)
+ pathbase = os.path.join (g_outdir, basename)
def f(base, ext1, ext2):
a = os.path.isfile(base + ext2)
if (os.path.isfile(base + ext1) and
not os.path.isfile(base + ext2):
return 1
todo = []
- if 'tex' in needed_filetypes and f(outname, '.ly', '.tex'):
+ if 'tex' in needed_filetypes and f(pathbase, '.ly', '.tex'):
todo.append('tex')
- if 'eps' in needed_filetypes and f(outname, '.tex', '.eps'):
+ if 'eps' in needed_filetypes and f(pathbase, '.tex', '.eps'):
todo.append('eps')
- if 'png' in needed_filetypes and f(outname, '.eps', '.png'):
+ if 'png' in needed_filetypes and f(pathbase, '.eps', '.png'):
todo.append('png')
newbody = ''
if 'verbatim' in opts:
else:
s = 'output-tex'
else: # format == 'texi'
- s = 'output-all'
- newbody = newbody + get_output(s) % {'fn': basename }
+ s = 'output-all'
+ newbody = newbody + get_output (s) % {'fn': basename }
return ('lilypond', newbody, opts, todo, basename)
def process_lilypond_blocks(outname, chunks):#ugh rename
error ('Error command exited with value %d\n' % st)
return st
-
-texidoc_re = re.compile (r'.*?\n\s*texidoc\s*=\s*"((([^"])|([^\\]\\"))*)".*', re.DOTALL)
-def extract_texidoc (lyfile):
- """
- Extract the ``texidoc'' entry from the lyfile.ly, and write it to
- lyfile-doc.texi.
-
- Maybe this should be output by `lilypond --header=texidoc' or so?
- """
- outfile = os.path.basename (os.path.splitext (lyfile)[0]) + "-doc.texi"
- sys.stderr.write ("Writing `%s'\n" % outfile)
- f = open (lyfile)
- s = f.read (-1)
-# doc = re.sub (r'(.|\n)*?\n\s*texidoc\s*=\s*"((([^"])|([^\\]\\"))*)"(.|\n)*', '\\2', s) + '\n'
- m = texidoc_re.match (s)
- doc = ''
- if m:
- doc = m.group (1) + '\n'
- f = open (outfile, 'w')
- f.write (doc)
- f.close ()
-
def compile_all_files (chunks):
eps = []
tex = []
incs = map (incl_opt, include_path)
lilyopts = string.join (incs, ' ' )
texfiles = string.join (tex, ' ')
- system ('lilypond %s %s' % (lilyopts, texfiles))
- for i in tex:
- extract_texidoc (i)
+ system ('lilypond --header=texidoc %s %s' % (lilyopts, texfiles))
for e in eps:
system(r"tex '\nonstopmode \input %s'" % e)
system(r"dvips -E -o %s %s" % (e + '.eps', e))
NO WARRANTY.
""")
+
+def check_texidoc (chunks):
+ n = []
+ for c in chunks:
+ if c[0] == 'lilypond':
+ (type, body, opts, todo, basename) = c;
+ pathbase = os.path.join (g_outdir, basename)
+ if os.path.isfile (pathbase + '.texidoc'):
+ body = '\n@include %s.texidoc' % basename + body
+ c = (type, body, opts, todo, basename)
+ n.append (c)
+ return n
+
+def fix_epswidth (chunks):
+ newchunks = []
+ for c in chunks:
+ if c[0] == 'lilypond' and 'eps' in c[2]:
+ body = re.sub (r"""\\lilypondepswidth{(.*?)}""", find_eps_dims, c[1])
+ newchunks.append(('lilypond', body, c[2], c[3], c[4]))
+ else:
+ newchunks.append (c)
+ return newchunks
+
+
def do_file(input_filename):
file_settings = {}
if outname:
#sys.exit()
scan_preamble(chunks)
chunks = process_lilypond_blocks(my_outname, chunks)
+
# Do It.
if __main__.g_run_lilypond:
compile_all_files (chunks)
- newchunks = []
- # finishing touch.
- for c in chunks:
- if c[0] == 'lilypond' and 'eps' in c[2]:
- body = re.sub (r"""\\lilypondepswidth{(.*?)}""", find_eps_dims, c[1])
- newchunks.append (('lilypond', body))
- else:
- newchunks.append (c)
- chunks = newchunks
+ chunks = fix_epswidth (chunks)
+
+ if __main__.format == 'texi':
+ chunks = check_texidoc (chunks)
+
x = 0
chunks = completize_preamble (chunks)
foutn = os.path.join(g_outdir, my_outname + '.' + format)