From f0f56055d87e51f7ab974cd7812de72ce1cd9100 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 24 Mar 2013 01:38:37 +0000 Subject: Initial docgen changes to generate manpages for Heretic, Hexen, Strife. Subversion-branch: /branches/v2-branch Subversion-revision: 2568 --- man/Makefile.am | 72 +++++++++++++++++++++++++++++++++++++++++++++++++-------- man/docgen | 59 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 105 insertions(+), 26 deletions(-) (limited to 'man') diff --git a/man/Makefile.am b/man/Makefile.am index 618c0bde..1be69258 100644 --- a/man/Makefile.am +++ b/man/Makefile.am @@ -5,22 +5,76 @@ docdir=$(prefix)/share/doc/@PACKAGE@ if HAVE_PYTHON -man_MANS=chocolate-doom.6 \ - chocolate-server.6 \ - chocolate-setup.6 \ - default.cfg.5 \ - $(PACKAGE).cfg.5 +man_MANS=chocolate-server.6 \ + chocolate-setup.6 \ + chocolate-doom.6 \ + default.cfg.5 \ + chocolate-doom.cfg.5 \ + chocolate-heretic.6 \ + heretic.cfg.5 \ + chocolate-heretic.cfg.5 \ + chocolate-hexen.6 \ + hexen.cfg.5 \ + chocolate-hexen.cfg.5 \ + chocolate-strife.6 \ + strife.cfg.5 \ + chocolate-strife.cfg.5 nodist_doc_DATA=INSTALL + + chocolate-doom.6: ../src $(MANPAGE_GEN_FILES) - ./docgen -m manpage.template ../src > $@ + ./docgen -g doom -m manpage.template ../src ../src/doom > $@ default.cfg.5: ../src default.cfg.template - ./docgen -m default.cfg.template -c default.cfg ../src > $@ + ./docgen -g doom -m default.cfg.template \ + -c default ../src/m_config.c > $@ + +chocolate-doom.cfg.5: ../src extra.cfg.template + ./docgen -g doom -m extra.cfg.template \ + -c extended ../src/m_config.c > $@ + + + +chocolate-heretic.6: ../src $(MANPAGE_GEN_FILES) + ./docgen -g heretic -m manpage.template ../src ../src/heretic > $@ + +heretic.cfg.5: ../src default.cfg.template + ./docgen -g heretic -m default.cfg.template \ + -c default ../src/m_config.c > $@ + +chocolate-heretic.cfg.5: ../src extra.cfg.template + ./docgen -g heretic -m extra.cfg.template \ + -c extended ../src/m_config.c > $@ + + + +chocolate-hexen.6: ../src $(MANPAGE_GEN_FILES) + ./docgen -g hexen -m manpage.template ../src ../src/hexen > $@ + +hexen.cfg.5: ../src default.cfg.template + ./docgen -g hexen -m default.cfg.template \ + -c default ../src/m_config.c > $@ + +chocolate-hexen.cfg.5: ../src extra.cfg.template + ./docgen -g hexen -m extra.cfg.template \ + -c extended ../src/m_config.c > $@ + + + +chocolate-strife.6: ../src $(MANPAGE_GEN_FILES) + ./docgen -g strife -m manpage.template ../src ../src/strife > $@ + +strife.cfg.5: ../src default.cfg.template + ./docgen -g strife -m default.cfg.template \ + -c default ../src/m_config.c > $@ + +chocolate-strife.cfg.5: ../src extra.cfg.template + ./docgen -g strife -m extra.cfg.template \ + -c extended ../src/m_config.c > $@ + -$(PACKAGE).cfg.5: ../src extra.cfg.template - ./docgen -m extra.cfg.template -c $(PACKAGE).cfg ../src > $@ INSTALL: INSTALL.template ./simplecpp -DPRECOMPILED < INSTALL.template > $@ diff --git a/man/docgen b/man/docgen index 3016dc5a..219895a2 100755 --- a/man/docgen +++ b/man/docgen @@ -19,7 +19,7 @@ # # For configuration file values: # -# //! @begin_config_file myconfig.cfg +# //! @begin_config_file myconfig # # //! # // Description of the configuration file value. @@ -160,6 +160,7 @@ class Parameter: self.platform = None self.category = None self.vanilla_option = False + self.games = None def should_show(self): return not self.vanilla_option or show_vanilla_options @@ -184,12 +185,21 @@ class Parameter: self.category = data elif option_type == "vanilla": self.vanilla_option = True + elif option_type == "game": + self.games = re.split(r'\s+', data.strip()) else: raise "Unknown option type '%s'" % option_type else: self.text += text + " " + def _games_only_text(self, pattern="(%s only)"): + if not match_game and self.games: + games_list = ", ".join(map(str.capitalize, self.games)) + return " " + (pattern % games_list) + else: + return "" + def manpage_output(self): result = self.name @@ -205,7 +215,7 @@ class Parameter: escaped = re.sub('\\\\', '\\\\\\\\', self.text) - result += escaped + "\n" + result += escaped + self._games_only_text() + "\n" return result @@ -221,6 +231,7 @@ class Parameter: if self.platform: result += "'''(%s only)'''" % self.platform + result += self._games_only_text("'''(%s only)'''") return result @@ -243,6 +254,8 @@ class Parameter: if self.platform: description += " (%s only)" % self.platform + description += self._games_only_text() + # Build the complete text for the argument # Split the description into words and add a word at a time @@ -291,18 +304,25 @@ def add_wiki_links(text): def add_parameter(param, line, config_file): + # If we're only targeting a particular game, check this is one of + # the ones we're targeting. + + if match_game and param.games and match_game not in param.games: + return + # Is this documenting a command line parameter? - match = re.search('M_CheckParm(WithArgs)?\s*\(\s*"(.*?)"', line) + match = re.search('(M_CheckParm(WithArgs)|M_ParmExists)?\s*\(\s*"(.*?)"', + line) if match: - param.name = match.group(2) + param.name = match.group(3) categories[param.category].add_param(param) return # Documenting a configuration file variable? - match = re.search('CONFIG_VARIABLE_\S+\s*\(\s*(\S+?),', line) + match = re.search('CONFIG_VARIABLE_\S+\s*\(\s*(\S+?)\),', line) if match: param.name = match.group(1) @@ -357,9 +377,9 @@ def process_file(file): if match: # Beginning a configuration file - filename = match.group(1) - current_config_file = ConfigFile(filename) - config_files[filename] = current_config_file + tagname = match.group(1) + current_config_file = ConfigFile(tagname) + config_files[tagname] = current_config_file else: # Start of a normal comment param = Parameter() @@ -367,18 +387,18 @@ def process_file(file): finally: f.close() -def process_files(dir): +def process_files(path): # Process all C source files. - if os.path.isdir(dir): - files = glob.glob(dir + "/*.c") + if os.path.isdir(path): + files = glob.glob(path + "/*.c") for file in files: process_file(file) else: # Special case to allow a single file to be specified as a target - process_file(dir) + process_file(path) def print_template(template_file, content): f = open(template_file) @@ -416,22 +436,25 @@ def plaintext_output(targets, template_file): print_template(template_file, content) def usage(): - print("Usage: %s [-V] [-c filename ]( -m | -w | -p ) " \ + print("Usage: %s [-V] [-c tag] [-g game] ( -m | -w | -p ) ..." \ % sys.argv[0]) print(" -c : Provide documentation for the specified configuration file") + print(" (matches the given tag name in the source file)") print(" -m : Manpage output") print(" -w : Wikitext output") print(" -p : Plaintext output") print(" -V : Don't show Vanilla Doom options") + print(" -g : Only document options for specified game.") sys.exit(0) # Parse command line -opts, args = getopt.getopt(sys.argv[1:], "m:wp:c:V") +opts, args = getopt.getopt(sys.argv[1:], "m:wp:c:g:V") output_function = None template = None doc_config_file = None +match_game = None for opt in opts: if opt[0] == "-m": @@ -446,14 +469,16 @@ for opt in opts: show_vanilla_options = False elif opt[0] == "-c": doc_config_file = opt[1] + elif opt[0] == "-g": + match_game = opt[1] -if output_function == None or len(args) != 1: +if output_function == None or len(args) < 1: usage() else: - # Process specified files - process_files(args[0]) + for path in args: + process_files(path) # Build a list of things to document -- cgit v1.2.3