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>
25 self.commentify = None
29 my_options = My_options()
32 return os.environ['MAILADDRESS']
35 return pwd.getpwuid(posix.getuid())[4]
37 def c_commentify(str):
38 return '/* ' + regsub.gsub('^',' ', str) + '\n */';
40 def sh_commentify(str):
41 return regsub.gsub('^', '# ', str)
43 def tex_commentify(str):
44 return regsub.gsub('^', '% ', str)
48 if regex.search('flower', cwd) <> -1:
49 PROJECT = "the Flower Library"
50 elif regex.search('mf$', cwd) <> -1:
51 PROJECT = "the Feta (defintively not an abbreviation for Font-En-Tja) music font"
53 PROJECT = "the GNU LilyPond music typesetter"
56 def head_str(filename):
57 if my_options.add_hdr_def:
63 headstr = '\n%s -- %s\n\nsource file of %s\n\n(c) %d %s <%s>\n' \
64 %(filename, what, project_str(), time.localtime (time.time ())[0], name(), mail())
68 def c_include(filename):
70 trans = string.maketrans( string.lowercase + '-.', string.uppercase + '__')
71 startdef = string.translate(filename, trans)
74 headstr = "\n\n#ifndef %s\n#define %s\n" % (startdef, startdef)
75 terminatestr = "#endif /* %s */\n" % (startdef);
77 return headstr+ '\n\n'+ terminatestr;
83 (options, files) = getopt.getopt(sys.argv[1:], 'tcsh', ['class'])
89 my_options.commentify = c_commentify
91 my_options.commentify = tex_commentify
93 my_options.commentify = sh_commentify
95 my_options.add_hdr_def = 1
97 my_options.classname = a
102 # FIXME: should create xxx.cc and include/xxx.hh, with implement/declare Xxx
104 if my_options.classname:
108 s = my_options.commentify(head_str(nm))
109 if my_options.add_hdr_def:
110 s = s + c_include(nm)
114 def extension(ext,nm):
116 return regex.search(ext, nm) <> -1
119 return extension('hh',nm) or extension('cc',nm) \
120 or extension('icc', nm) or extension('tcc',nm)
121 def select_commentification(nm):
124 elif extension('py',nm) or extension('pl',nm) or extension('sh',nm):
126 elif extension('mf',nm) or extension('tex',nm) or extension('ly',nm):
127 return tex_commentify
132 if extension('hh', nm) or extension('icc', nm) or extension('tcc', nm):
133 my_options.add_hdr_def = 1
134 if my_options.commentify == None:
135 my_options.commentify = select_commentification(nm)