-''' % (name, title, title)
-
- def name2line (n):
- # UGR
- if string.find (n, '+') >= 0:
- s = "@lilypondfile{%s}" % n
- else:
- s = "@lilypondfile[printfilename]{%s}" % n
- return s
-
- s = s + string.join (map (lambda x: name2line (x), files), "\n")
- s = s + '\n@bye\n'
- f = "%s/%s.tely" % (dir, name)
- sys.stderr.write ("%s: writing %s..." % (program_name, f))
- h = open (f, "w")
- h.write (s)
- h.close ()
- sys.stderr.write ('\n')
-
+
+%s
+
+@bye
+''' % include_snippets
+
+for opt in options:
+ o = opt[0]
+ a = opt[1]
+ if o == '-h' or o == '--help':
+ help ()
+ elif o == '-n' or o == '--name':
+ name = a
+ elif o == '-t' or o == '--title':
+ title = a
+ elif o == '-f' or o == '--fragment-options':
+ fragment_options = a
+ elif o == '--template':
+ template = open (a, 'r').read ()
+ else:
+ raise Exception ('unknown option: ' + o)
+
+def name2line (n):
+ s = r"""
+@ifhtml
+@html
+<a name="%s"></a>
+@end html
+@end ifhtml
+
+@lilypondfile[%s]{%s}
+""" % (os.path.basename (n), fragment_options, n)
+ return s
+
+if files:
+ dir = os.path.dirname (name) or "."
+# don't strip .tely extension, input/lsr uses .itely
+ name = os.path.basename (name)
+ template = template % vars ()
+
+ files.sort ()
+ s = "\n".join (map (name2line, files))
+ s = template.replace (include_snippets, s, 1)
+ f = "%s/%s" % (dir, name)
+ sys.stderr.write ("%s: writing %s..." % (program_name, f))
+ h = open (f, "w")
+ h.write (s)
+ h.close ()
+ sys.stderr.write ('\n')
+else:
+ # not Unix philosophy, but hey, at least we notice when
+ # we don't distribute any .ly files.
+ sys.stderr.write ("No files specified. Doing nothing")