# # # patch "option.cc" # from [4196e8cd69e0338d7d99da072e8daa94cb1a6731] # to [176ac8e0ae5dc6bd71d515bd51710f795f9de4cd] # # patch "option.hh" # from [7b18a9e8807a29cd59fd8a9e727f89e82a694366] # to [0f9cf0b04b3c675f23dbdbf0a0b3d1a59565edc5] # # patch "options.cc" # from [b0531b13b04640f7f8cbbade6dc72451f461b20b] # to [e89af04e97c53b86bbfff144e567a6bfd7535357] # # patch "options.hh" # from [45ee02558ec8b1b5220f6d02dbbcc66965f07e48] # to [c3d069fcf7845b6e8cf8a2819d73e98c69aaee8b] # # patch "options_list.hh" # from [62ca74d018e89677fff23a364bbc161d2cb153c3] # to [3f798d9ddb7d778a6590afda9c371856feed5bcb] # ============================================================ --- option.cc 4196e8cd69e0338d7d99da072e8daa94cb1a6731 +++ option.cc 176ac8e0ae5dc6bd71d515bd51710f795f9de4cd @@ -1,3 +1,5 @@ +// Copyright 2006 Timothy Brownawell +// This is made available under the GNU GPL v2 or later. #include "base.hh" #include "file_io.hh" ============================================================ --- option.hh 7b18a9e8807a29cd59fd8a9e727f89e82a694366 +++ option.hh 0f9cf0b04b3c675f23dbdbf0a0b3d1a59565edc5 @@ -1,6 +1,18 @@ +// Copyright 2006 Timothy Brownawell +// This is made available under the GNU GPL v2 or later. + #ifndef __OPTION_HH__ #define __OPTION_HH__ +/* + * Infrastructure for parsing options. + * + * This can be used on its own with concrete_option_set::operator()(), or + * used with something like options.{cc,hh} and option_set. The former is + * very simple to do, while the latter should allow slightly better code + * structure for more involved uses. + */ + #include #include #include ============================================================ --- options.cc b0531b13b04640f7f8cbbade6dc72451f461b20b +++ options.cc e89af04e97c53b86bbfff144e567a6bfd7535357 @@ -1,3 +1,5 @@ +// Copyright 2006 Timothy Brownawell +// This is made available under the GNU GPL v2 or later. #include "base.hh" #include ============================================================ --- options.hh 45ee02558ec8b1b5220f6d02dbbcc66965f07e48 +++ options.hh c3d069fcf7845b6e8cf8a2819d73e98c69aaee8b @@ -1,6 +1,16 @@ +// Copyright 2006 Timothy Brownawell +// This is made available under the GNU GPL v2 or later. + #ifndef __OPTIONS_HH__ #define __OPTIONS_HH__ +/* + * This defines 'struct options', which includes the variables and options + * defined in options_list.hh as members. Options and optsets are available + * statically as options::opts::, and option variables are available + * as options::. + */ + #include #include "option.hh" ============================================================ --- options_list.hh 62ca74d018e89677fff23a364bbc161d2cb153c3 +++ options_list.hh 3f798d9ddb7d778a6590afda9c371856feed5bcb @@ -1,7 +1,54 @@ -#define OPT(name, string, type, default_, description) \ +// Copyright 2006 Timothy Brownawell +// This is made available under the GNU GPL v2 or later. + +/* + * This is a list of all options that monotone can take, what variables + * they get put into, and how they get there. There are 4 important macros + * available here (and only here): + * + * OPTSET(name) + * Defines a set of related options, which can easily be allowed for + * a particular command or reset together. It is named + * 'options::opts::name'. + * + * OPTSET_REL(parent, child) + * Declare a relationship between to optsets, so that if the parent + * is reset or allowed for a command the child will also be. + * + * OPTVAR(optset, type, name, default) + * Defines a variable 'type options::name' which is initialized to + * 'type (default)' and belongs to the named optset. When the optset + * is reset, this variable will be reset to 'type (default)'. + * + * OPTION(optset, name, hasarg, optstring, description) + * Declare an option named 'options::opts::name', which belongs to the + * given optset. 'optstring' can look like "foo", in which case it is + * specified as "--foo", or it can look like "foo,f", in which case it + * is specified as either "--foo" or "-f". The description is a + * translatable help text. 'hasarg' is a bool indicating whether this + * option takes an argument. + * + * Some expansions of this macro expect a function body, which looks + * like 'void (std::string const & arg)'. This is the 'setter' function + * for this option, and is called when the option is parsed. If the + * option was declared to not take an argument, 'arg' is empty. + * Otherwise, it is the given argument. In any case this function + * should set the option variables for this option and throw a + * 'bad_arg_internal' if this fails. The variables that are set must be + * part of the same optset as the option, or they won't get reset + * properly. When the function body is needed, 'option_bodies' will + * be defined. + */ + +// This is a shortcut for an option which has its own variable and optset. +// It will take an argument unless 'type' is 'bool'. +#define OPT(name, string, type, default_, description) \ OPTVAR(name, type, name, default_) \ OPTION(name, name, has_arg(), string, description) +// This is the same, except that the option and variable belong to the +// 'globals' optset. These are global options, not specific to a particular +// command. #define GOPT(name, string, type, default_, description) \ OPTVAR(globals, type, name, default_) \ OPTION(globals, name, has_arg(), string, description)