Revision: 65191
http://sourceforge.net/p/brlcad/code/65191
Author: starseeker
Date: 2015-06-05 00:45:22 +0000 (Fri, 05 Jun 2015)
Log Message:
-----------
Collapse help columns in option description table
Modified Paths:
--------------
brlcad/trunk/include/bu/opt.h
brlcad/trunk/src/conv/gcv/gcv.cpp
brlcad/trunk/src/libbu/opt.c
brlcad/trunk/src/libbu/tests/opt.c
brlcad/trunk/src/util/dsp_add_opt.c
Modified: brlcad/trunk/include/bu/opt.h
===================================================================
--- brlcad/trunk/include/bu/opt.h 2015-06-04 22:53:20 UTC (rev 65190)
+++ brlcad/trunk/include/bu/opt.h 2015-06-05 00:45:22 UTC (rev 65191)
@@ -62,11 +62,10 @@
const char *shortopt;
const char *longopt;
bu_opt_arg_process_t arg_process;
- const char *shortopt_doc;
- const char *longopt_doc;
+ const char *arg_helpstr;
const char *help_string;
};
-#define BU_OPT_DESC_NULL {-1, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL}
+#define BU_OPT_DESC_NULL {-1, 0, 0, NULL, NULL, NULL, NULL, NULL}
/** Output format options for bu_opt documentation generation */
Modified: brlcad/trunk/src/conv/gcv/gcv.cpp
===================================================================
--- brlcad/trunk/src/conv/gcv/gcv.cpp 2015-06-04 22:53:20 UTC (rev 65190)
+++ brlcad/trunk/src/conv/gcv/gcv.cpp 2015-06-05 00:45:22 UTC (rev 65191)
@@ -34,8 +34,8 @@
/* Emulate a FASTGEN4 format option processor */
enum fg4_opt_enums { FG4_TOL, FG4_WARN_DEFAULT_NAMES };
struct bu_opt_desc fg4_opt_desc[3] = {
- {FG4_TOL, 1, 1, "t", "tol", NULL, "-t tol",
"--tol tol", "Dimensional tolerance." },
- {FG4_WARN_DEFAULT_NAMES, 0, 0, "w", "warn-default-names", NULL, "-w",
"--warn-default-names", "File format of input file." },
+ {FG4_TOL, 1, 1, "t", "tol", NULL, "tol",
"Dimensional tolerance." },
+ {FG4_WARN_DEFAULT_NAMES, 0, 0, "w", "warn-default-names", NULL, "",
"File format of input file." },
BU_OPT_DESC_NULL
};
@@ -60,8 +60,8 @@
/* Emulate a STL format option processor */
enum stl_opt_enums { STL_TOL, STL_UNITS };
struct bu_opt_desc stl_opt_desc[3] = {
- {STL_TOL, 1, 1, "t", "tol", NULL, "-t tol", "--tol tol",
"Dimensional tolerance." },
- {STL_UNITS, 1, 1, "u", "units", NULL, "-u unit", "--units unit", "Units
of input file." },
+ {STL_TOL, 1, 1, "t", "tol", NULL, "tol", "Dimensional tolerance." },
+ {STL_UNITS, 1, 1, "u", "units", NULL, "unit", "Units of input file." },
BU_OPT_DESC_NULL
};
@@ -272,14 +272,14 @@
#define gcv_help_str "Print help and exit. If a format is specified to
--help, print help specific to that format"
enum gcv_opt_enums { GCV_HELP, IN_FILE, OUT_FILE, IN_FORMAT, OUT_FORMAT,
IN_OPTS, OUT_OPTS, GCV_OPTS_MAX };
struct bu_opt_desc gcv_opt_desc[9] = {
- {GCV_HELP, 0, 1, "h", "help", NULL, "-h [format]",
"--help [format]", gcv_help_str},
- {GCV_HELP, 0, 1, "?", "", NULL, "-? [format]",
"", ""},
- {IN_FILE , 1, 1, "i", "input", &(file_stat), "-i file",
"--input file", "Input file." },
- {OUT_FILE, 1, 1, "o", "output", &(file_null), "-o file",
"--output file", "Output file." },
- {IN_FORMAT , 1, 1, "", "input-format", &(model_mime), "",
"--input-format format", "File format of input file." },
- {OUT_FORMAT , 1, 1, "", "output-format", &(model_mime), "",
"--output-format format", "File format of output file." },
- {IN_OPTS , 1, 1, "I", "input-only-opts", NULL, "-I
\"[opts]\"", "--input-only-opts \"[opts]\"", "Options to apply only while
processing input file. Quotes around the opts are always necessary, but
brackets are only necessary when supplying a single option without arguments
that would otherwise be interpreted as an argv entry by the shell, even with
quotes. Brackets will never hurt, and for robustness when scripting they
should always be used." },
- {OUT_OPTS, 1, 1, "O", "output-only-opts", NULL, "-O
\"[opts]\"", "--output-only-opts \"[opts]\"", "Options to apply only while
preparing output file. Quotes around the opts are always necessary, but
brackets are only necessary when supplying a single option without arguments
that would otherwise be interpreted as an argv entry by the shell, even with
quotes. Brackets will never hurt, and for robustness when scripting they
should always be used." },
+ {GCV_HELP, 0, 1, "h", "help", NULL, "format",
gcv_help_str},
+ {GCV_HELP, 0, 1, "?", "", NULL, "format", ""},
+ {IN_FILE , 1, 1, "i", "input", &(file_stat), "file",
"Input file." },
+ {OUT_FILE, 1, 1, "o", "output", &(file_null), "file",
"Output file." },
+ {IN_FORMAT , 1, 1, "", "input-format", &(model_mime), "format",
"File format of input file." },
+ {OUT_FORMAT , 1, 1, "", "output-format", &(model_mime), "format",
"File format of output file." },
+ {IN_OPTS , 1, 1, "I", "input-only-opts", NULL, "\"[opts]\"",
"Options to apply only while processing input file. Quotes around the opts are
always necessary, but brackets are only necessary when supplying a single
option without arguments that would otherwise be interpreted as an argv entry
by the shell, even with quotes. Brackets will never hurt, and for robustness
when scripting they should always be used." },
+ {OUT_OPTS, 1, 1, "O", "output-only-opts", NULL, "\"[opts]\"",
"Options to apply only while preparing output file. Quotes around the opts are
always necessary, but brackets are only necessary when supplying a single
option without arguments that would otherwise be interpreted as an argv entry
by the shell, even with quotes. Brackets will never hurt, and for robustness
when scripting they should always be used." },
BU_OPT_DESC_NULL
};
Modified: brlcad/trunk/src/libbu/opt.c
===================================================================
--- brlcad/trunk/src/libbu/opt.c 2015-06-04 22:53:20 UTC (rev 65190)
+++ brlcad/trunk/src/libbu/opt.c 2015-06-05 00:45:22 UTC (rev 65191)
@@ -238,14 +238,39 @@
while (j < opt_cnt) {
d = &(ds[j]);
if (d->index == curr->index) {
- int new_len = strlen(d->shortopt_doc);
- if (new_len > 0) {
+ if (d->shortopt && strlen(d->shortopt) > 0) {
+ struct bu_vls tmp_arg = BU_VLS_INIT_ZERO;
+ int new_len = strlen(d->arg_helpstr);
+ if (d->arg_cnt_min == 0 && d->arg_cnt_max != 0) {
+ if (new_len > 0) {
+ bu_vls_sprintf(&tmp_arg, "-%s [%s]",
d->shortopt, d->arg_helpstr);
+ new_len = new_len + 5;
+ } else {
+ bu_vls_sprintf(&tmp_arg, "-%s [opts]",
d->shortopt);
+ new_len = 9;
+ }
+ } else {
+ if (d->arg_cnt_min == 0 && d->arg_cnt_max == 0) {
+ bu_vls_sprintf(&tmp_arg, "-%s", d->shortopt);
+ new_len = 2;
+ }
+ if (d->arg_cnt_min > 0) {
+ if (new_len > 0) {
+ bu_vls_sprintf(&tmp_arg, "-%s %s",
d->shortopt, d->arg_helpstr);
+ new_len = new_len + 3;
+ } else {
+ bu_vls_sprintf(&tmp_arg, "-%s opts",
d->shortopt);
+ new_len = 7;
+ }
+ }
+ }
if ((int)bu_vls_strlen(&opts) + new_len + offset + 2 >
opt_cols + desc_cols) {
bu_vls_printf(&description, "%*s%s\n", offset, " ",
bu_vls_addr(&opts));
- bu_vls_sprintf(&opts, "%s, ", d->shortopt_doc);
+ bu_vls_sprintf(&opts, "%s, ",
bu_vls_addr(&tmp_arg));
} else {
- bu_vls_printf(&opts, "%s, ", d->shortopt_doc);
+ bu_vls_printf(&opts, "%s, ", bu_vls_addr(&tmp_arg));
}
+ bu_vls_free(&tmp_arg);
}
/* While we're at it, pick up the string. The last string
with
* a matching key wins, as long as its not empty */
@@ -259,14 +284,39 @@
while (j < opt_cnt) {
d = &(ds[j]);
if (d->index == curr->index) {
- int new_len = strlen(d->longopt_doc);
- if (new_len > 0) {
+ if (d->longopt && strlen(d->longopt) > 0) {
+ struct bu_vls tmp_arg = BU_VLS_INIT_ZERO;
+ int new_len = strlen(d->arg_helpstr);
+ if (d->arg_cnt_min == 0 && d->arg_cnt_max != 0) {
+ if (new_len > 0) {
+ bu_vls_sprintf(&tmp_arg, "--%s [%s]",
d->longopt, d->arg_helpstr);
+ new_len = new_len + strlen(d->longopt) + 5;
+ } else {
+ bu_vls_sprintf(&tmp_arg, "--%s [opts]",
d->longopt);
+ new_len = strlen(d->longopt) + 9;
+ }
+ } else {
+ if (d->arg_cnt_min == 0 && d->arg_cnt_max == 0) {
+ bu_vls_sprintf(&tmp_arg, "--%s", d->longopt);
+ new_len = strlen(d->longopt) + 2;
+ }
+ if (d->arg_cnt_min > 0) {
+ if (new_len > 0) {
+ bu_vls_sprintf(&tmp_arg, "--%s %s",
d->longopt, d->arg_helpstr);
+ new_len = strlen(d->longopt) + new_len + 3;
+ } else {
+ bu_vls_sprintf(&tmp_arg, "--%s opts",
d->longopt);
+ new_len = strlen(d->longopt) + 7;
+ }
+ }
+ }
if ((int)bu_vls_strlen(&opts) + new_len + offset + 2 >
opt_cols + desc_cols) {
bu_vls_printf(&description, "%*s%s\n", offset, " ",
bu_vls_addr(&opts));
- bu_vls_sprintf(&opts, "%s, ", d->longopt_doc);
+ bu_vls_sprintf(&opts, "%s, ",
bu_vls_addr(&tmp_arg));
} else {
- bu_vls_printf(&opts, "%s, ", d->longopt_doc);
+ bu_vls_printf(&opts, "%s, ", bu_vls_addr(&tmp_arg));
}
+ bu_vls_free(&tmp_arg);
}
}
j++;
Modified: brlcad/trunk/src/libbu/tests/opt.c
===================================================================
--- brlcad/trunk/src/libbu/tests/opt.c 2015-06-04 22:53:20 UTC (rev 65190)
+++ brlcad/trunk/src/libbu/tests/opt.c 2015-06-05 00:45:22 UTC (rev 65191)
@@ -126,16 +126,16 @@
enum d1_opt_ind {D1_HELP, D1_VERBOSITY};
struct bu_opt_desc d1[4] = {
- {D1_HELP, 0, 0, "h", "help", NULL, "-h",
"--help", help_str},
- {D1_HELP, 0, 0, "?", "", NULL, "-?", "", help_str},
- {D1_VERBOSITY, 0, 1, "v", "verbosity", &(d1_verbosity), "-v #",
"--verbosity #", "Set verbosity (range is 0 to 3)"},
+ {D1_HELP, 0, 0, "h", "help", NULL, "", help_str},
+ {D1_HELP, 0, 0, "?", "", NULL, "", help_str},
+ {D1_VERBOSITY, 0, 1, "v", "verbosity", &(d1_verbosity), "#", "Set
verbosity (range is 0 to 3)"},
BU_OPT_DESC_NULL
};
enum d2_opt_ind {D2_HELP, D2_COLOR};
struct bu_opt_desc d2[4] = {
- {D2_HELP, 0, 0, "h", "help", NULL, "-h", "--help", help_str},
- {D2_COLOR, 1, 3, "C", "color", &(d2_color), "-c r/g/b", "--color
r/g/b", "Set color"},
+ {D2_HELP, 0, 0, "h", "help", NULL, "", help_str},
+ {D2_COLOR, 1, 3, "C", "color", &(d2_color), "r/g/b", "Set color"},
BU_OPT_DESC_NULL
};
Modified: brlcad/trunk/src/util/dsp_add_opt.c
===================================================================
--- brlcad/trunk/src/util/dsp_add_opt.c 2015-06-04 22:53:20 UTC (rev 65190)
+++ brlcad/trunk/src/util/dsp_add_opt.c 2015-06-05 00:45:22 UTC (rev 65191)
@@ -45,8 +45,8 @@
enum dsp_add_enums {DSP_HELP};
struct bu_opt_desc dsp_opt_desc[3] = {
- {DSP_HELP, 0, 0, "h", "help", NULL, "-h", "--help", "Print help and exit"},
- {DSP_HELP, 0, 0, "?", "", NULL, "-?", "", ""},
+ {DSP_HELP, 0, 0, "h", "help", NULL, "", "Print help and exit"},
+ {DSP_HELP, 0, 0, "?", "", NULL, "", ""},
BU_OPT_DESC_NULL
};
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits