3 # genheader.py -- do headers (like these)
5 # source file of the GNU LilyPond music typesetter
7 # (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
19 self
.commentify
= None
23 my_options
= My_options()
27 return os
.environ
['USERNAME']
29 # field 4 of passwd is also used for finger info (phone no., office etc)
30 # return pwd.getpwuid(os.getuid())[4]
32 def c_commentify(str):
33 return '/* ' + re
.sub('^',' ', str) + '\n */';
35 def sh_commentify(str):
36 return re
.sub('^', '# ', str)
38 def tex_commentify(str):
39 return re
.sub('^', '% ', str)
43 if re
.search('flower', cwd
):
44 PROJECT
= "the Flower Library"
45 elif re
.search('mf$', cwd
):
46 PROJECT
= "the Feta (defintively not an abbreviation for Font-En-Tja) music font"
48 PROJECT
= "the GNU LilyPond music typesetter"
51 def head_str(filename
):
52 if my_options
.add_hdr_def
:
60 mailaddres
= '<%s>' % os
.environ
['MAILADDRESS']
63 headstr
= '\n%s -- %s\n\nsource file of %s\n\n(c) %d %s %s\n' \
64 %(filename
, what
, project_str(),
65 time
.localtime (time
.time ())[0], name(), mailaddres
)
69 def c_include(filename
):
71 trans
= string
.maketrans( string
.lowercase
+ '-.', string
.uppercase
+ '__')
72 startdef
= string
.translate(filename
, trans
)
75 headstr
= "\n\n#ifndef %s\n#define %s\n" % (startdef
, startdef
)
76 terminatestr
= "#endif /* %s */\n" % (startdef
);
78 return headstr
+ '\n\n'+ terminatestr
;
81 def icc_include (filename
):
83 trans
= string
.maketrans( string
.lowercase
+ '-.', string
.uppercase
+ '__')
84 startdef
= string
.translate(filename
, trans
)
87 headstr
= "\n\n#ifndef %s\n#define %s\n" % (startdef
, startdef
)
88 headstr
= headstr
+ r
"""
91 #define LOCAL_INLINE_DEF
94 terminatestr
= "#endif /* %s */\n" % (startdef
);
97 #ifdef LOCAL_INLINE_DEF
98 #undef LOCAL_INLINE_DEF
102 return headstr
+ '\n\n'+ terminatestr
;
107 sys
.stdout
.write ("Usage: genheader [options] FILENAME\n"
108 + "Generate file with header FILENAME\n\n"
110 + " -h, --header generate header\n"
111 + " --help print this help\n"
112 + " -p, --package=DIR specify package\n"
118 (options
, files
) = getopt
.getopt(sys
.argv
[1:], 'tcshp:', ['class', 'package=', 'help'])
124 my_options
.commentify
= c_commentify
126 my_options
.commentify
= tex_commentify
128 my_options
.commentify
= sh_commentify
129 elif o
== '-h' or o
== '--header':
130 my_options
.add_hdr_def
= 1
132 my_options
.classname
= a
136 # FIXME: should create xxx.cc and include/xxx.hh, with implement/declare Xxx
138 if my_options
.classname
:
142 s
= my_options
.commentify(head_str(nm
))
143 if my_options
.add_hdr_def
:
144 s
= s
+ c_include(nm
)
148 def extension(ext
,nm
):
150 return re
.search(ext
, nm
) <> None
153 return extension('hh',nm
) or extension('cc',nm
) \
154 or extension('icc', nm
) or extension('tcc',nm
)
156 def select_commentification(nm
):
159 elif extension('py',nm
) or extension('pl',nm
) or extension('sh',nm
):
161 elif extension('mf',nm
) or extension('tex',nm
) or extension('ly',nm
):
162 return tex_commentify
164 sys
.stderr
.write ('unknown extension for file %s\n' % nm
)
168 if extension('hh', nm
) or extension('icc', nm
) or extension('tcc', nm
):
169 my_options
.add_hdr_def
= 1
170 if my_options
.commentify
== None:
171 my_options
.commentify
= select_commentification(nm
)