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>
20 self.commentify = None
24 my_options = My_options()
28 return os.environ['USERNAME']
30 # field 4 of passwd is also used for finger info (phone no., office etc)
31 # return pwd.getpwuid(os.getuid())[4]
33 def c_commentify(str):
34 return '/* ' + regsub.gsub('^',' ', str) + '\n */';
36 def sh_commentify(str):
37 return regsub.gsub('^', '# ', str)
39 def tex_commentify(str):
40 return regsub.gsub('^', '% ', str)
44 if regex.search('flower', cwd) <> -1:
45 PROJECT = "the Flower Library"
46 elif regex.search('mf$', cwd) <> -1:
47 PROJECT = "the Feta (defintively not an abbreviation for Font-En-Tja) music font"
49 PROJECT = "the GNU LilyPond music typesetter"
52 def head_str(filename):
53 if my_options.add_hdr_def:
61 mailaddres = '<%s>' % os.environ['MAILADDRESS']
64 headstr = '\n%s -- %s\n\nsource file of %s\n\n(c) %d %s %s\n' \
65 %(filename, what, project_str(),
66 time.localtime (time.time ())[0], name(), mailaddres)
70 def c_include(filename):
72 trans = string.maketrans( string.lowercase + '-.', string.uppercase + '__')
73 startdef = string.translate(filename, trans)
76 headstr = "\n\n#ifndef %s\n#define %s\n" % (startdef, startdef)
77 terminatestr = "#endif /* %s */\n" % (startdef);
79 return headstr+ '\n\n'+ terminatestr;
83 sys.stdout.write ("Usage: genheader [options] FILENAME\n"
84 + "Generate file with header FILENAME\n\n"
86 + " -h, --header generate header\n"
87 + " --help print this help\n"
88 + " -p, --package=DIR specify package\n"
94 (options, files) = getopt.getopt(sys.argv[1:], 'tcshp:', ['class', 'package=', 'help'])
100 my_options.commentify = c_commentify
102 my_options.commentify = tex_commentify
104 my_options.commentify = sh_commentify
105 elif o == '-h' or o == '--header':
106 my_options.add_hdr_def = 1
108 my_options.classname = a
112 # FIXME: should create xxx.cc and include/xxx.hh, with implement/declare Xxx
114 if my_options.classname:
118 s = my_options.commentify(head_str(nm))
119 if my_options.add_hdr_def:
120 s = s + c_include(nm)
124 def extension(ext,nm):
126 return regex.search(ext, nm) <> -1
129 return extension('hh',nm) or extension('cc',nm) \
130 or extension('icc', nm) or extension('tcc',nm)
132 def select_commentification(nm):
135 elif extension('py',nm) or extension('pl',nm) or extension('sh',nm):
137 elif extension('mf',nm) or extension('tex',nm) or extension('ly',nm):
138 return tex_commentify
140 sys.stderr.write ('unknown extension for file %s\n' % nm)
144 if extension('hh', nm) or extension('icc', nm) or extension('tcc', nm):
145 my_options.add_hdr_def = 1
146 if my_options.commentify == None:
147 my_options.commentify = select_commentification(nm)