- global format
- if format == '':
- html = re.search ('(?i)<[dh]tml', str[:200])
- latex = re.search (r'''\\document''', str[:200])
- texi = re.search ('@node|@setfilename', str[:200])
-
- f = ''
- g = None
-
- if html and not latex and not texi:
- f = 'html'
- elif latex and not html and not texi:
- f = 'latex'
- elif texi and not html and not latex:
- f = 'texi'
- else:
- error ("can't determine format, please specify")
- format = f
-
- global paperguru
- if paperguru == None:
- if format == 'html':
- g = HtmlPaper ()
- elif format == 'latex':
- g = LatexPaper ()
- elif format == 'texi':
- g = TexiPaper ()
-
- paperguru = g
-
-
-def read_doc_file (filename):
- '''Read the input file, find verbatim chunks and do \input and \include
- '''
- (str, path) = find_file (filename)
- determine_format (str)
-
- chunks = [('input', str)]
-
- # we have to check for verbatim before doing include,
- # because we don't want to include files that are mentioned
- # inside a verbatim environment
- chunks = chop_chunks (chunks, 'verbatim', make_verbatim)
-
- chunks = chop_chunks (chunks, 'verb', make_verb)
- chunks = chop_chunks (chunks, 'multiline-comment', do_ignore)
- #ugh fix input
- chunks = chop_chunks (chunks, 'include', do_include_file, 1)
- chunks = chop_chunks (chunks, 'input', do_input_file, 1)
- return chunks
-
-
-taken_file_names = {}
-
-def unique_file_name (body):
- return 'lily-' + `abs (hash (body))`
-
-def schedule_lilypond_block (chunk):
- '''Take the body and options from CHUNK, figure out how the
- real .ly should look. The .ly is written, and scheduled in
- TODO.
-
- Return: a single chunk.
-
- The chunk pertaining to the lilypond output
- has the format (TYPE_STR, MAIN_STR, OPTIONS, TODO, BASE),
- where TODO has format [basename, extension, extension, ... ]
- '''
-
- (type, body, opts) = chunk
- assert type == 'lilypond'
- file_body = compose_full_body (body, opts)
- ## Hmm, we should hash only lilypond source, and skip the
- ## %options are ...
- ## comment line
- basename = unique_file_name (file_body)
- for o in opts:
- m = re.search ('filename="(.*?)"', o)
- if m:
- basename = m.group (1)
- if not taken_file_names.has_key (basename):
- taken_file_names[basename] = 0
- else:
- taken_file_names[basename] = taken_file_names[basename] + 1
- basename = basename + "-t%i" % taken_file_names[basename]
- update_file (file_body, os.path.join (g_outdir, basename) + '.ly')
- needed_filetypes = ['tex']
-
- if format == 'html' or g_make_html:
- needed_filetypes.append ('eps')
- needed_filetypes.append ('png')
- if 'eps' in opts and not ('eps' in needed_filetypes):
- needed_filetypes.append ('eps')
-
- pathbase = os.path.join (g_outdir, basename)
- def must_rebuild (base, ext1, ext2):
-
- f2 = base + ext2
- f1 = base + ext1
- fp2 = base + '-page1' + ext2
-
- isfile2 = os.path.isfile (f2)
-
- if not isfile2 and os.path.isfile (fp2):
- f2 = fp2
- isfile2 = os.path.isfile (fp2)
-
- if (os.path.isfile (f2) and isfile2 and
- os.stat (f1)[stat.ST_MTIME] >
- os.stat (f2)[stat.ST_MTIME]) or \
- not isfile2:
-
- return 1
-
- todo = []
- if 'tex' in needed_filetypes and must_rebuild (pathbase, '.ly', '.tex'):
- todo.append ('tex')
- if 'eps' in needed_filetypes and must_rebuild (pathbase, '.tex', '.eps'):
- todo.append ('eps')
- if 'png' in needed_filetypes and must_rebuild (pathbase, '.eps', '.png'):
- todo.append ('png')
-
- return ('lilypond', body, opts, todo, basename)
-
-def format_lilypond_block (chunk):
- """