214 #ifndef OPTIONPARSER_H_
215 #define OPTIONPARSER_H_
223 #pragma intrinsic(_BitScanReverse)
224 struct MSC_Builtin_CLZ
226 static int builtin_clz(
unsigned x)
229 _BitScanReverse(&index, x);
233 #define __builtin_clz(x) MSC_Builtin_CLZ::builtin_clz(x)
528 return desc == 0 ? 0 : desc->
type;
537 return desc == 0 ? -1 : desc->
index;
554 int c = (desc == 0 ? 0 : 1);
574 return isTagged(prev_);
587 return isTagged(next_);
666 return isLast() ? 0 : next_;
698 new_last->next_ = tag(f);
699 f->prev_ = tag(new_last);
720 return desc ?
this : 0;
741 return desc ?
this : 0;
749 desc(0), name(0), arg(0), namelen(0)
765 init(desc_, name_, arg_);
797 void init(
const Descriptor* desc_,
const char* name_,
const char* arg_)
810 while (name[namelen] != 0 && name[namelen] !=
'=')
816 return (
Option*) ((
unsigned long long) ptr | 1);
821 return (
Option*) ((
unsigned long long) ptr & ~1ull);
824 static bool isTagged(
Option* ptr)
826 return ((
unsigned long long) ptr & 1);
888 fprintf(stderr,
"ERROR: %s", msg1);
890 fprintf(stderr,
"%s", msg2);
912 if (msg)
printError(
"Option '", option,
"' requires an argument\n");
956 buffer_max(1), options_max(1)
969 Stats(
bool gnu,
const Descriptor usage[],
int argc,
const char** argv,
int min_abbr_len = 0,
970 bool single_minus_longopt =
false) :
971 buffer_max(1), options_max(1)
973 add(gnu, usage, argc, argv, min_abbr_len, single_minus_longopt);
977 Stats(
bool gnu,
const Descriptor usage[],
int argc,
char** argv,
int min_abbr_len = 0,
978 bool single_minus_longopt =
false) :
979 buffer_max(1), options_max(1)
981 add(gnu, usage, argc, (
const char**) argv, min_abbr_len, single_minus_longopt);
986 bool single_minus_longopt =
false) :
987 buffer_max(1), options_max(1)
989 add(
false, usage, argc, argv, min_abbr_len, single_minus_longopt);
994 bool single_minus_longopt =
false) :
995 buffer_max(1), options_max(1)
997 add(
false, usage, argc, (
const char**) argv, min_abbr_len, single_minus_longopt);
1009 void add(
bool gnu,
const Descriptor usage[],
int argc,
const char** argv,
int min_abbr_len = 0,
1010 bool single_minus_longopt =
false);
1013 void add(
bool gnu,
const Descriptor usage[],
int argc,
char** argv,
int min_abbr_len = 0,
1014 bool single_minus_longopt =
false)
1016 add(gnu, usage, argc, (
const char**) argv, min_abbr_len, single_minus_longopt);
1020 void add(
const Descriptor usage[],
int argc,
const char** argv,
int min_abbr_len = 0,
1021 bool single_minus_longopt =
false)
1023 add(
false, usage, argc, argv, min_abbr_len, single_minus_longopt);
1028 bool single_minus_longopt =
false)
1030 add(
false, usage, argc, (
const char**) argv, min_abbr_len, single_minus_longopt);
1033 class CountOptionsAction;
1060 const char** nonop_args;
1068 op_count(0), nonop_count(0), nonop_args(0), err(false)
1077 int min_abbr_len = 0,
bool single_minus_longopt =
false,
int bufmax = -1) :
1078 op_count(0), nonop_count(0), nonop_args(0), err(false)
1080 parse(gnu, usage, argc, argv, options, buffer, min_abbr_len, single_minus_longopt, bufmax);
1085 int min_abbr_len = 0,
bool single_minus_longopt =
false,
int bufmax = -1) :
1086 op_count(0), nonop_count(0), nonop_args(0), err(false)
1088 parse(gnu, usage, argc, (
const char**) argv, options, buffer, min_abbr_len, single_minus_longopt, bufmax);
1093 bool single_minus_longopt =
false,
int bufmax = -1) :
1094 op_count(0), nonop_count(0), nonop_args(0), err(false)
1096 parse(
false, usage, argc, argv, options, buffer, min_abbr_len, single_minus_longopt, bufmax);
1101 bool single_minus_longopt =
false,
int bufmax = -1) :
1102 op_count(0), nonop_count(0), nonop_args(0), err(false)
1104 parse(
false, usage, argc, (
const char**) argv, options, buffer, min_abbr_len, single_minus_longopt, bufmax);
1164 int min_abbr_len = 0,
bool single_minus_longopt =
false,
int bufmax = -1);
1168 int min_abbr_len = 0,
bool single_minus_longopt =
false,
int bufmax = -1)
1170 parse(gnu, usage, argc, (
const char**) argv, options, buffer, min_abbr_len, single_minus_longopt, bufmax);
1175 int min_abbr_len = 0,
bool single_minus_longopt =
false,
int bufmax = -1)
1177 parse(
false, usage, argc, argv, options, buffer, min_abbr_len, single_minus_longopt, bufmax);
1182 bool single_minus_longopt =
false,
int bufmax = -1)
1184 parse(
false, usage, argc, (
const char**) argv, options, buffer, min_abbr_len, single_minus_longopt, bufmax);
1274 static bool workhorse(
bool gnu,
const Descriptor usage[],
int numargs,
const char** args,
Action& action,
1275 bool single_minus_longopt,
bool print_errors,
int min_abbr_len);
1291 static bool streq(
const char* st1,
const char* st2)
1294 if (*st1++ != *st2++)
1296 return (*st2 == 0 || *st2 ==
'=');
1323 static bool streqabbr(
const char* st1,
const char* st2,
long long min)
1325 const char* st1start = st1;
1326 while (*st1 != 0 && (*st1 == *st2))
1332 return (*st1 == 0 || (min > 0 && (st1 - st1start) >= min)) && (*st2 == 0 || *st2 ==
'=');
1341 static bool instr(
char ch,
const char* st)
1343 while (*st != 0 && *st != ch)
1353 static void shift(
const char** args,
int count)
1355 for (
int i = 0; i > -count; --i)
1357 const char* temp = args[i];
1358 args[i] = args[i - 1];
1407 unsigned* buffer_max;
1414 buffer_max(buffer_max_)
1420 if (*buffer_max == 0x7fffffff)
1447 parser(parser_), options(options_), buffer(buffer_), bufmax(bufmax_)
1451 while ((bufmax < 0 || bufidx < bufmax) && buffer[bufidx])
1455 parser.op_count = bufidx;
1460 if (bufmax < 0 || parser.op_count < bufmax)
1462 if (parser.op_count == 0x7fffffff)
1465 buffer[parser.op_count] = option;
1466 int idx = buffer[parser.op_count].
desc->
index;
1468 options[idx].
append(buffer[parser.op_count]);
1470 options[idx] = buffer[parser.op_count];
1483 parser.nonop_count = numargs;
1484 parser.nonop_args = args;
1492 Option buffer[],
int min_abbr_len,
bool single_minus_longopt,
int bufmax)
1495 err = !workhorse(gnu, usage, argc, argv, action, single_minus_longopt,
true, min_abbr_len);
1499 bool single_minus_longopt)
1503 while (usage[i].shortopt != 0)
1512 Parser::workhorse(gnu, usage, argc, argv, action, single_minus_longopt,
false, min_abbr_len);
1515 inline bool Parser::workhorse(
bool gnu,
const Descriptor usage[],
int numargs,
const char** args, Action& action,
1516 bool single_minus_longopt,
bool print_errors,
int min_abbr_len)
1524 while (numargs != 0 && *args != 0)
1526 const char* param = *args;
1530 if (param[0] !=
'-' || param[1] == 0)
1545 if (param[1] ==
'-' && param[2] == 0)
1547 shift(args, nonops);
1554 bool handle_short_options;
1555 const char* longopt_name;
1556 if (param[1] ==
'-')
1558 handle_short_options =
false;
1559 longopt_name = param + 2;
1563 handle_short_options =
true;
1564 longopt_name = param + 1;
1567 bool try_single_minus_longopt = single_minus_longopt;
1568 bool have_more_args = (numargs > 1 || numargs < 0);
1577 if (handle_short_options ==
false || try_single_minus_longopt)
1580 while (usage[idx].longopt != 0 && !streq(usage[idx].longopt, longopt_name))
1583 if (usage[idx].longopt == 0 && min_abbr_len > 0)
1586 while (usage[i1].longopt != 0 && !streqabbr(usage[i1].longopt, longopt_name, min_abbr_len))
1588 if (usage[i1].longopt != 0)
1591 while (usage[i2].longopt != 0 && !streqabbr(usage[i2].longopt, longopt_name, min_abbr_len))
1594 if (usage[i2].longopt == 0)
1600 if (usage[idx].longopt != 0)
1601 handle_short_options =
false;
1603 try_single_minus_longopt =
false;
1605 optarg = longopt_name;
1606 while (*optarg != 0 && *optarg !=
'=')
1612 optarg = (have_more_args ? args[1] : 0);
1616 if (handle_short_options)
1622 while (usage[idx].shortopt != 0 && !instr(*param, usage[idx].shortopt))
1626 optarg = (have_more_args ? args[1] : 0);
1632 const Descriptor* descriptor = &usage[idx];
1634 if (descriptor->shortopt == 0)
1638 while (usage[idx].shortopt != 0 && (usage[idx].shortopt[0] != 0 || usage[idx].longopt[0] != 0))
1640 descriptor = (usage[idx].
shortopt == 0 ? 0 : &usage[idx]);
1643 if (descriptor != 0)
1645 Option option(descriptor, param, optarg);
1646 switch (descriptor->check_arg(option, print_errors))
1652 if (optarg != 0 && have_more_args && optarg == args[1])
1654 shift(args, nonops);
1661 handle_short_options =
false;
1670 if (!action.perform(option))
1674 }
while (handle_short_options);
1676 shift(args, nonops);
1683 if (numargs > 0 && *args == 0)
1689 while (args[numargs] != 0)
1693 return action.finished(numargs + nonops, args - nonops);
1721 template<
typename Function>
1728 (*write)(str, size);
1742 template<
typename OStream>
1749 ostream.write(str, size);
1763 template<
typename Temporary>
1770 userstream.write(str, size);
1785 template<
typename Syscall>
1793 (*write)(
fd, str, size);
1806 template<
typename Function,
typename Stream>
1814 (*fwrite)(str, size, 1,
stream);
1818 fwrite(w), stream(s)
1829 i1 = (i1 >= i2 ? i1 : i2);
1855 for (
int i = 0; i <
indent; ++i)
1884 return ((0x1100 <= ch && ch <= 0x115F) || (0x2329 <= ch && ch <= 0x232A) || (0x2E80 <= ch && ch <= 0xA4C6)
1885 || (0xA960 <= ch && ch <= 0xA97C) || (0xAC00 <= ch && ch <= 0xD7FB) || (0xF900 <= ch && ch <= 0xFAFF)
1886 || (0xFE10 <= ch && ch <= 0xFE6B) || (0xFF01 <= ch && ch <= 0xFF60) || (0xFFE0 <= ch && ch <= 0xFFE6)
1887 || (0x1B000 <= ch));
1930 const char* rowstart;
1935 int max_line_in_block;
1937 int target_line_in_block;
1938 bool hit_target_line;
1944 void update_length()
1947 for (len = 0; ptr[len] != 0 && ptr[len] !=
'\v' && ptr[len] !=
'\t' && ptr[len] !=
'\n'; ++len)
1950 unsigned ch = (
unsigned char) ptr[len];
1955 unsigned mask = (unsigned) -1 >> __builtin_clz(ch ^ 0xff);
1957 while (((
unsigned char) ptr[len + 1] ^ 0x80) <= 0x3F)
1959 ch = (ch << 6) ^ (
unsigned char) ptr[len + 1] ^ 0x80;
1972 tablestart(usage), rowdesc(0), rowstart(0), ptr(0), col(-1), len(0), max_line_in_block(0), line_in_block(0),
1973 target_line_in_block(0), hit_target_line(true)
1988 while (tablestart->
help != 0 && tablestart->
shortopt != 0)
1993 while (tablestart->
help == 0 && tablestart->
shortopt != 0)
1997 return rowstart != 0;
2005 rowdesc = tablestart;
2006 rowstart = tablestart->
help;
2020 return rowstart != 0;
2023 while (*ptr != 0 && *ptr !=
'\n')
2028 if ((rowdesc + 1)->help == 0)
2032 rowstart = rowdesc->
help;
2052 max_line_in_block = 0;
2054 target_line_in_block = 0;
2055 hit_target_line =
true;
2083 upmax(max_line_in_block, ++line_in_block);
2087 if (!hit_target_line)
2090 hit_target_line =
true;
2094 hit_target_line =
false;
2101 if (!hit_target_line)
2104 hit_target_line =
true;
2108 if (++target_line_in_block > max_line_in_block)
2114 hit_target_line =
false;
2124 if (line_in_block == target_line_in_block)
2127 hit_target_line =
true;
2148 return target_line_in_block;
2203 static const int bufmask = 15;
2207 int lenbuf[bufmask + 1];
2211 const char* datbuf[bufmask + 1];
2233 bool wrote_something;
2237 return ((tail + 1) & bufmask) == head;
2242 return tail == head;
2245 void buf_store(
const char* data,
int len)
2248 datbuf[head] = data;
2249 head = (head + 1) & bufmask;
2255 tail = (tail + 1) & bufmask;
2262 void output(
IStringWriter& write,
const char* data,
int len)
2265 write_one_line(write);
2267 buf_store(data, len);
2275 if (wrote_something)
2285 write(datbuf[tail], lenbuf[tail]);
2288 wrote_something =
true;
2303 wrote_something =
false;
2304 while (!buf_empty())
2305 write_one_line(write);
2329 wrote_something =
false;
2335 output(write, data, len);
2342 while (maxi < len && utf8width < width)
2345 unsigned ch = (
unsigned char) data[maxi];
2350 unsigned mask = (unsigned) -1 >> __builtin_clz(ch ^ 0xff);
2352 while ((maxi + charbytes < len) &&
2353 (((
unsigned char) data[maxi + charbytes] ^ 0x80) <= 0x3F))
2355 ch = (ch << 6) ^ (
unsigned char) data[maxi + charbytes] ^ 0x80;
2361 if (utf8width + 2 > width)
2375 output(write, data, len);
2381 for (i = maxi; i >= 0; --i)
2387 output(write, data, i);
2393 output(write, data, maxi);
2400 if (!wrote_something)
2401 write_one_line(write);
2411 x(x1), width(x2 - x1), head(0), tail(bufmask)
2424 int last_column_min_percent = 50,
int last_column_own_line_max_percent = 75)
2432 int last_column_min_width = ((width * last_column_min_percent) + 50) / 100;
2433 int last_column_own_line_max_width = ((width * last_column_own_line_max_percent) + 50) / 100;
2434 if (last_column_own_line_max_width == 0)
2435 last_column_own_line_max_width = 1;
2443 const int maxcolumns = 8;
2444 int col_width[maxcolumns];
2447 int overlong_column_threshold = 10000;
2451 for (
int i = 0; i < maxcolumns; ++i)
2459 if (part.
column() < maxcolumns)
2485 overlong_column_threshold = 0;
2486 for (
int i = 0; i < lastcolumn; ++i)
2488 leftwidth += col_width[i];
2489 upmax(overlong_column_threshold, col_width[i]);
2492 }
while (leftwidth > width);
2496 int tabstop[maxcolumns];
2498 for (
int i = 1; i < maxcolumns; ++i)
2499 tabstop[i] = tabstop[i - 1] + col_width[i - 1];
2501 int rightwidth = width - tabstop[lastcolumn];
2502 bool print_last_column_on_own_line =
false;
2503 if (rightwidth < last_column_min_width && rightwidth < col_width[lastcolumn])
2505 print_last_column_on_own_line =
true;
2506 rightwidth = last_column_own_line_max_width;
2517 if (lastcolumn == 0)
2518 print_last_column_on_own_line =
false;
2520 LineWrapper lastColumnLineWrapper(width - rightwidth, width);
2532 if (part.
column() > lastcolumn)
2544 if ((part.
column() < lastcolumn)
2557 LineWrapper& lineWrapper = (part.
column() == 0) ? interjectionLineWrapper : lastColumnLineWrapper;
2559 if (!print_last_column_on_own_line)
2564 if (print_last_column_on_own_line)
2569 if (part.
column() == lastcolumn)
2573 indent(write, _, width - rightwidth);
2580 lastColumnLineWrapper.
flush(write);
2581 interjectionLineWrapper.
flush(write);
2786 template<
typename OStream>
2788 int last_column_own_line_max_percent = 75)
2794 template<
typename Function>
2796 int last_column_own_line_max_percent = 75)
2802 template<
typename Temporary>
2804 int last_column_own_line_max_percent = 75)
2810 template<
typename Syscall>
2812 int last_column_own_line_max_percent = 75)
2818 template<
typename Function,
typename Stream>
2819 void printUsage(Function* prn, Stream* stream,
const Descriptor usage[],
int width = 80,
int last_column_min_percent =
2821 int last_column_own_line_max_percent = 75)
static ArgStatus Required(const Option &option, bool msg)
Definition: optionparser.h:908
Definition: optionparser.h:1432
const unsigned index
Index of this option's linked list in the array filled in by the parser.
Definition: optionparser.h:329
Stream * stream
Definition: optionparser.h:1810
The argument is acceptable for the option.
Definition: optionparser.h:249
int screenLength()
Returns the width in screen columns of the part pointed to by data(). Takes multi-byte UTF-8 sequence...
Definition: optionparser.h:2163
virtual void operator()(const char *str, int size)
Writes the given number of chars beginning at the given pointer somewhere.
Definition: optionparser.h:1791
Option * nextwrap()
Returns a pointer to the next element of the linked list with wrap-around from last() to first()...
Definition: optionparser.h:677
Parser()
Creates a new Parser.
Definition: optionparser.h:1067
OStream & ostream
Definition: optionparser.h:1745
LineWrapper(int x1, int x2)
Constructs a LineWrapper that wraps its output to fit into screen columns x1 (incl.) to x2 (excl.).
Definition: optionparser.h:2410
void parse(bool gnu, const Descriptor usage[], int argc, char **argv, Option options[], Option buffer[], int min_abbr_len=0, bool single_minus_longopt=false, int bufmax=-1)
parse() with non-const argv.
Definition: optionparser.h:1167
Parser(bool gnu, const Descriptor usage[], int argc, char **argv, Option options[], Option buffer[], int min_abbr_len=0, bool single_minus_longopt=false, int bufmax=-1)
Parser(...) with non-const argv.
Definition: optionparser.h:1084
const Descriptor * desc
Pointer to this Option's Descriptor.
Definition: optionparser.h:458
unsigned options_max
Number of elements needed for an options[] array to be used for parsing the same argument vectors tha...
Definition: optionparser.h:950
OStreamWriter(OStream &o)
Definition: optionparser.h:1752
bool next()
Moves iteration to the next part (if any). Has to be called once after each call to nextRow() to move...
Definition: optionparser.h:2065
Definition: optionparser.h:1743
const char * nonOption(int i)
Returns nonOptions()[i] (without checking if i is in range!).
Definition: optionparser.h:1239
void add(bool gnu, const Descriptor usage[], int argc, char **argv, int min_abbr_len=0, bool single_minus_longopt=false)
add() with non-const argv.
Definition: optionparser.h:1013
Definition: optionparser.h:1405
bool perform(Option &option)
Called by Parser::workhorse() for each Option that has been successfully parsed (including unknown op...
Definition: optionparser.h:1458
bool finished(int numargs, const char **args)
Called by Parser::workhorse() after finishing the parse.
Definition: optionparser.h:1476
void restartTable()
Reset iteration to the beginning of the current table.
Definition: optionparser.h:2003
bool isLast() const
Returns true iff this is the last element of the linked list.
Definition: optionparser.h:585
The option does not take an argument.
Definition: optionparser.h:247
Definition: optionparser.h:1807
int length()
Returns the length of the part pointed to by data() in raw chars (not UTF-8 characters).
Definition: optionparser.h:2154
int type() const
Returns Descriptor::type of this Option's Descriptor, or 0 if this Option is invalid (unused)...
Definition: optionparser.h:526
void add(const Descriptor usage[], int argc, char **argv, int min_abbr_len=0, bool single_minus_longopt=false)
POSIX add() (gnu==false) with non-const argv.
Definition: optionparser.h:1027
Syscall * write
Definition: optionparser.h:1788
The argument is not acceptable but that's non-fatal because the option's argument is optional...
Definition: optionparser.h:251
const char *const longopt
The long option name (without the leading – ).
Definition: optionparser.h:386
Parser(const Descriptor usage[], int argc, const char **argv, Option options[], Option buffer[], int min_abbr_len=0, bool single_minus_longopt=false, int bufmax=-1)
POSIX Parser(...) (gnu==false).
Definition: optionparser.h:1092
ArgStatus(* CheckArg)(const Option &option, bool msg)
Signature of functions that check if an argument is valid for a certain type of option.
Definition: optionparser.h:284
virtual void operator()(const char *str, int size)
Writes the given number of chars beginning at the given pointer somewhere.
Definition: optionparser.h:1812
Stats()
Creates a Stats object with counts set to 1 (for the sentinel element).
Definition: optionparser.h:955
TemporaryWriter(const Temporary &u)
Definition: optionparser.h:1773
FunctionWriter(Function *w)
Definition: optionparser.h:1731
int optionsCount()
Returns the number of valid Option objects in buffer[].
Definition: optionparser.h:1196
virtual void operator()(const char *, int)
Writes the given number of chars beginning at the given pointer somewhere.
Definition: optionparser.h:1711
A parsed option from the command line together with its argument if it has one.
Definition: optionparser.h:435
bool isFirst() const
Returns true iff this is the first element of the linked list.
Definition: optionparser.h:572
int line()
Returns the index (counting from 0) of the line within the current column this part belongs to...
Definition: optionparser.h:2146
Definition: optionparser.h:1722
const int type
Used to distinguish between options with the same index. See index for details.
Definition: optionparser.h:338
Option * first()
Returns a pointer to the first element of the linked list.
Definition: optionparser.h:601
Parser(bool gnu, const Descriptor usage[], int argc, const char **argv, Option options[], Option buffer[], int min_abbr_len=0, bool single_minus_longopt=false, int bufmax=-1)
Creates a new Parser and immediately parses the given argument vector.
Definition: optionparser.h:1076
int nonOptionsCount()
Returns the number of non-option arguments that remained at the end of the most recent parse() that a...
Definition: optionparser.h:1215
Option()
Creates a new Option that is a one-element linked list and has NULL desc, name, arg and namelen...
Definition: optionparser.h:748
virtual void operator()(const char *str, int size)
Writes the given number of chars beginning at the given pointer somewhere.
Definition: optionparser.h:1726
The namespace of The Lean Mean C++ Option Parser.
Definition: optionparser.h:218
static ArgStatus None(const Option &, bool)
For options that don't take an argument: Returns ARG_NONE.
Definition: optionparser.h:894
virtual bool perform(Option &)
Called by Parser::workhorse() for each Option that has been successfully parsed (including unknown op...
Definition: optionparser.h:1379
void operator=(const Option &orig)
Makes *this a copy of orig except for the linked list pointers.
Definition: optionparser.h:773
const char *const shortopt
Each char in this string will be accepted as a short option character.
Definition: optionparser.h:351
void append(Option *new_last)
Makes new_last the new last() by chaining it into the list after last().
Definition: optionparser.h:692
const char ** nonOptions()
Returns a pointer to an array of non-option arguments (only valid if nonOptionsCount() >0 )...
Definition: optionparser.h:1231
void parse(bool gnu, const Descriptor usage[], int argc, const char **argv, Option options[], Option buffer[], int min_abbr_len=0, bool single_minus_longopt=false, int bufmax=-1)
Parses the given argument vector.
Definition: optionparser.h:1491
Checks argument vectors for validity and parses them into data structures that are easier to work wit...
Definition: optionparser.h:1056
Option * last()
Returns a pointer to the last element of the linked list.
Definition: optionparser.h:625
static void printUsage(IStringWriter &write, const Descriptor usage[], int width=80, int last_column_min_percent=50, int last_column_own_line_max_percent=75)
Definition: optionparser.h:2423
static void printError(const char *msg1, const option::Option &opt, const char *msg2)
Definition: optionparser.h:886
const char * name
The name of the option as used on the command line.
Definition: optionparser.h:474
static bool isWideChar(unsigned ch)
Returns true if ch is the unicode code point of a wide character.
Definition: optionparser.h:1879
int count()
Returns the number of times this Option (or others with the same Descriptor::index) occurs in the arg...
Definition: optionparser.h:552
StoreOptionAction(Parser &parser_, Option options_[], Option buffer_[], int bufmax_)
Number of slots in buffer. -1 means "large enough".
Definition: optionparser.h:1446
Stats(const Descriptor usage[], int argc, const char **argv, int min_abbr_len=0, bool single_minus_longopt=false)
POSIX Stats(...) (gnu==false).
Definition: optionparser.h:985
int column()
Returns the index (counting from 0) of the column in which the part pointed to by data() is located...
Definition: optionparser.h:2137
ArgStatus
Possible results when checking if an argument is valid for a certain option.
Definition: optionparser.h:244
SyscallWriter(Syscall *w, int f)
Definition: optionparser.h:1796
Option(const Descriptor *desc_, const char *name_, const char *arg_)
Creates a new Option that is a one-element linked list and has the given values for desc...
Definition: optionparser.h:763
const Temporary & userstream
Definition: optionparser.h:1766
CountOptionsAction(unsigned *buffer_max_)
Definition: optionparser.h:1413
static ArgStatus Optional(const Option &option, bool)
Returns ARG_OK if the argument is attached and ARG_IGNORE otherwise.
Definition: optionparser.h:900
Stats(bool gnu, const Descriptor usage[], int argc, char **argv, int min_abbr_len=0, bool single_minus_longopt=false)
Stats(...) with non-const argv.
Definition: optionparser.h:977
Option * prevwrap()
Returns a pointer to the previous element of the linked list with wrap-around from first() to last()...
Definition: optionparser.h:651
static void indent(IStringWriter &write, int &x, int want_x)
Definition: optionparser.h:1843
LinePartIterator(const Descriptor usage[])
Creates an iterator for usage.
Definition: optionparser.h:1971
void restartRow()
Reset iteration to the beginning of the current row.
Definition: optionparser.h:2046
void parse(const Descriptor usage[], int argc, char **argv, Option options[], Option buffer[], int min_abbr_len=0, bool single_minus_longopt=false, int bufmax=-1)
POSIX parse() (gnu==false) with non-const argv.
Definition: optionparser.h:1181
Definition: optionparser.h:1764
Definition: optionparser.h:1700
void add(bool gnu, const Descriptor usage[], int argc, const char **argv, int min_abbr_len=0, bool single_minus_longopt=false)
Updates this Stats object for the given usage and argument vector. You may pass 0 for argc and/or arg...
Definition: optionparser.h:1498
Stats(bool gnu, const Descriptor usage[], int argc, const char **argv, int min_abbr_len=0, bool single_minus_longopt=false)
Creates a new Stats object and immediately updates it for the given usage and argument vector...
Definition: optionparser.h:969
StreamWriter(Function *w, Stream *s)
Definition: optionparser.h:1817
virtual bool finished(int numargs, const char **args)
Called by Parser::workhorse() after finishing the parse.
Definition: optionparser.h:1392
Definition: optionparser.h:1369
The argument is not acceptable and that's fatal.
Definition: optionparser.h:253
Definition: optionparser.h:1786
const char * arg
Pointer to this Option's argument (if any).
Definition: optionparser.h:482
int index() const
Returns Descriptor::index of this Option's Descriptor, or -1 if this Option is invalid (unused)...
Definition: optionparser.h:535
const CheckArg check_arg
For each option that matches shortopt or longopt this function will be called to check a potential ar...
Definition: optionparser.h:398
Stats(const Descriptor usage[], int argc, char **argv, int min_abbr_len=0, bool single_minus_longopt=false)
POSIX Stats(...) (gnu==false) with non-const argv.
Definition: optionparser.h:993
void process(IStringWriter &write, const char *data, int len)
Process, wrap and output the next piece of data.
Definition: optionparser.h:2327
Parser(const Descriptor usage[], int argc, char **argv, Option options[], Option buffer[], int min_abbr_len=0, bool single_minus_longopt=false, int bufmax=-1)
POSIX Parser(...) (gnu==false) with non-const argv.
Definition: optionparser.h:1100
Option * next()
Returns a pointer to the next element of the linked list or NULL if called on last().
Definition: optionparser.h:664
Function * write
Definition: optionparser.h:1724
void printUsage(OStream &prn, const Descriptor usage[], int width=80, int last_column_min_percent=50, int last_column_own_line_max_percent=75)
Outputs a nicely formatted usage string with support for multi-column formatting and line-wrapping...
Definition: optionparser.h:2787
bool perform(Option &)
Called by Parser::workhorse() for each Option that has been successfully parsed (including unknown op...
Definition: optionparser.h:1418
Determines the minimum lengths of the buffer and options arrays used for Parser.
Definition: optionparser.h:926
bool nextTable()
Moves iteration to the next table (if any). Has to be called once on a new LinePartIterator to move t...
Definition: optionparser.h:1982
unsigned buffer_max
Number of elements needed for a buffer[] array to be used for parsing the same argument vectors that ...
Definition: optionparser.h:937
bool nextRow()
Moves iteration to the next row (if any). Has to be called once after each call to nextTable() to mov...
Definition: optionparser.h:2015
const char * help
The usage text associated with the options in this Descriptor.
Definition: optionparser.h:415
Definition: optionparser.h:2201
Functions for checking the validity of option arguments.
Definition: optionparser.h:884
Option * prev()
Returns a pointer to the previous element of the linked list or NULL if called on first()...
Definition: optionparser.h:638
const char * data()
Returns the current part of the iteration.
Definition: optionparser.h:2171
void parse(const Descriptor usage[], int argc, const char **argv, Option options[], Option buffer[], int min_abbr_len=0, bool single_minus_longopt=false, int bufmax=-1)
POSIX parse() (gnu==false).
Definition: optionparser.h:1174
static void upmax(int &i1, int i2)
Definition: optionparser.h:1827
Option(const Option &orig)
Makes *this a copy of orig except for the linked list pointers.
Definition: optionparser.h:783
Definition: optionparser.h:1706
int namelen
The length of the option name.
Definition: optionparser.h:503
Definition: optionparser.h:1926
int fd
Definition: optionparser.h:1789
Function * fwrite
Definition: optionparser.h:1809
void add(const Descriptor usage[], int argc, const char **argv, int min_abbr_len=0, bool single_minus_longopt=false)
POSIX add() (gnu==false).
Definition: optionparser.h:1020
virtual void operator()(const char *str, int size)
Writes the given number of chars beginning at the given pointer somewhere.
Definition: optionparser.h:1747
bool error()
Returns true if an unrecoverable error occurred while parsing options.
Definition: optionparser.h:1259
void flush(IStringWriter &write)
Writes out all remaining data from the LineWrapper using write. Unlike process() this method indents ...
Definition: optionparser.h:2297
Describes an option, its help text (usage) and how it should be parsed.
Definition: optionparser.h:308
virtual void operator()(const char *str, int size)
Writes the given number of chars beginning at the given pointer somewhere.
Definition: optionparser.h:1768