4 # genheader.py -- do headers (like these)
6 # source file of the GNU LilyPond music typesetter
8 # (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
24 lilypath
= os
.environ
['LILYPOND_SOURCEDIR'] + '/'
26 print 'Please set LILYPOND_SOURCEDIR to the toplevel source, eg LILYPOND_SOURCEDIR=/home/foobar/lilypond-1.2.3/'
29 lilypath
= lilypath
+ '/bin/'
30 sys
.path
.append(lilypath
)
32 from lilypython
import *
36 self
.commentify
= None
40 my_options
= My_options()
44 return pwd
.getpwuid(posix
.getuid())[4]
46 def c_commentify(str):
47 return '/* ' + regsub
.gsub('^',' ', str) + '\n */';
49 def sh_commentify(str):
50 return regsub
.gsub('^', '# ', str)
52 def tex_commentify(str):
53 return regsub
.gsub('^', '% ', str)
57 if regex
.search('flower', cwd
) <> -1:
58 PROJECT
= "the Flower Library"
59 elif regex
.search('mf$', cwd
) <> -1:
60 PROJECT
= "the Feta (defintively not an abbreviation for Font-En-Tja) music font"
62 PROJECT
= "the GNU LilyPond music typesetter"
65 def head_str(filename
):
66 if my_options
.add_hdr_def
:
72 headstr
= '\n%s -- %s\n\nsource file of %s\n\n(c) %d %s <%s>\n' \
73 %(filename
, what
, project_str(), time
.localtime (time
.time ())[0], name(), mailaddress())
77 def c_include(filename
):
79 trans
= string
.maketrans( string
.lowercase
+ '-.', string
.uppercase
+ '__')
80 startdef
= string
.translate(filename
, trans
)
83 headstr
= "\n\n#ifndef %s\n#define %s\n" % (startdef
, startdef
)
84 terminatestr
= "#endif /* %s */\n" % (startdef
);
86 return headstr
+ '\n\n'+ terminatestr
;
92 (options
, files
) = getopt
.getopt(sys
.argv
[1:], 'tcsh', ['class'])
98 my_options
.commentify
= c_commentify
100 my_options
.commentify
= tex_commentify
102 my_options
.commentify
= sh_commentify
104 my_options
.add_hdr_def
= 1
106 my_options
.classname
= a
111 # FIXME: should create xxx.cc and include/xxx.hh, with implement/declare Xxx
113 if my_options
.classname
:
117 s
= my_options
.commentify(head_str(nm
))
118 if my_options
.add_hdr_def
:
119 s
= s
+ c_include(nm
)
123 def extension(ext
,nm
):
125 return regex
.search(ext
, nm
) <> -1
128 return extension('hh',nm
) or extension('cc',nm
) \
129 or extension('icc', nm
) or extension('tcc',nm
)
130 def select_commentification(nm
):
133 elif extension('py',nm
) or extension('pl',nm
) or extension('sh',nm
):
135 elif extension('mf',nm
) or extension('tex',nm
) or extension('ly',nm
):
136 return tex_commentify
141 if extension('hh', nm
) or extension('icc', nm
) or extension('tcc', nm
):
142 my_options
.add_hdr_def
= 1
143 if my_options
.commentify
== None:
144 my_options
.commentify
= select_commentification(nm
)