3 # genheader.py -- do headers (like these)
5 # source file of the GNU LilyPond music typesetter
7 # (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
20 self.commentify = None
24 my_options = My_options()
28 return pwd.getpwuid(os.getuid())[4]
30 def c_commentify(str):
31 return '/* ' + regsub.gsub('^',' ', str) + '\n */';
33 def sh_commentify(str):
34 return regsub.gsub('^', '# ', str)
36 def tex_commentify(str):
37 return regsub.gsub('^', '% ', str)
41 if regex.search('flower', cwd) <> -1:
42 PROJECT = "the Flower Library"
43 elif regex.search('mf$', cwd) <> -1:
44 PROJECT = "the Feta (defintively not an abbreviation for Font-En-Tja) music font"
46 PROJECT = "the GNU LilyPond music typesetter"
49 def head_str(filename):
50 if my_options.add_hdr_def:
58 mailaddres = '<%s>' % os.environ['MAILADDRESS']
61 headstr = '\n%s -- %s\n\nsource file of %s\n\n(c) %d %s %s\n' \
62 %(filename, what, project_str(),
63 time.localtime (time.time ())[0], name(), mailaddres)
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;
80 sys.stdout.write ("Usage: genheader [options] FILENAME\n"
81 + "Generate file with header FILENAME\n\n"
83 + " -h, --header generate header\n"
84 + " --help print this help\n"
85 + " -p, --package=DIR specify package\n"
91 (options, files) = getopt.getopt(sys.argv[1:], 'tcshp:', ['class', 'package=', 'help'])
97 my_options.commentify = c_commentify
99 my_options.commentify = tex_commentify
101 my_options.commentify = sh_commentify
102 elif o == '-h' or o == '--header':
103 my_options.add_hdr_def = 1
105 my_options.classname = a
109 # FIXME: should create xxx.cc and include/xxx.hh, with implement/declare Xxx
111 if my_options.classname:
115 s = my_options.commentify(head_str(nm))
116 if my_options.add_hdr_def:
117 s = s + c_include(nm)
121 def extension(ext,nm):
123 return regex.search(ext, nm) <> -1
126 return extension('hh',nm) or extension('cc',nm) \
127 or extension('icc', nm) or extension('tcc',nm)
129 def select_commentification(nm):
132 elif extension('py',nm) or extension('pl',nm) or extension('sh',nm):
134 elif extension('mf',nm) or extension('tex',nm) or extension('ly',nm):
135 return tex_commentify
137 sys.stderr.write ('unknown extension for file %s\n' % nm)
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)