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 self.commentify = None
28 my_options = My_options()
31 return os.environ['MAILADDRESS']
34 return pwd.getpwuid(posix.getuid())[4]
36 def c_commentify(str):
37 return '/* ' + regsub.gsub('^',' ', str) + '\n */';
39 def sh_commentify(str):
40 return regsub.gsub('^', '# ', str)
42 def tex_commentify(str):
43 return regsub.gsub('^', '% ', str)
47 if regex.search('flower', cwd) <> -1:
48 PROJECT = "the Flower Library"
49 elif regex.search('mf$', cwd) <> -1:
50 PROJECT = "the Feta (defintively not an abbreviation for Font-En-Tja) music font"
52 PROJECT = "the GNU LilyPond music typesetter"
55 def head_str(filename):
56 if my_options.add_hdr_def:
62 headstr = '\n%s -- %s\n\nsource file of %s\n\n(c) 1997 %s <%s>\n' \
63 %(filename, what, project_str(), name(), mail())
67 def c_include(filename):
69 trans = string.maketrans( string.lowercase + '-.', string.uppercase + '__')
70 startdef = string.translate(filename, trans)
73 headstr = "\n\n#ifndef %s\n#define %s\n" % (startdef, startdef)
74 terminatestr = "#endif /* %s */\n" % (startdef);
76 return headstr+ '\n\n'+ terminatestr;
82 (options, files) = getopt.getopt(sys.argv[1:], 'tcsh', ['class'])
88 my_options.commentify = c_commentify
90 my_options.commentify = tex_commentify
92 my_options.commentify = sh_commentify
94 my_options.add_hdr_def = 1
96 my_options.classname = a
101 # FIXME: should create xxx.cc and include/xxx.hh, with implement/declare Xxx
103 if my_options.classname:
107 s = my_options.commentify(head_str(nm))
108 if my_options.add_hdr_def:
109 s = s + c_include(nm)
113 def extension(ext,nm):
115 return regex.search(ext, nm) <> -1
118 return extension('hh',nm) or extension('cc',nm) \
119 or extension('icc', nm) or extension('tcc',nm)
120 def select_commentification(nm):
123 elif extension('py',nm) or extension('pl',nm) or extension('sh',nm):
125 elif extension('mf',nm) or extension('tex',nm) or extension('ly',nm):
126 return tex_commentify
131 if extension('hh', nm) or extension('icc', nm) or extension('tcc', nm):
132 my_options.add_hdr_def = 1
133 if my_options.commentify == None:
134 my_options.commentify = select_commentification(nm)