fix previous commit, formatting

This commit is contained in:
John
2023-10-01 14:29:11 +02:00
parent 22b6f02752
commit acc6eddbba
5 changed files with 22 additions and 16 deletions
+1
View File
@@ -5,6 +5,7 @@ AM_CXXFLAGS = -I$(top_srcdir)/src \
noinst_LIBRARIES = libutils.a
libutils_a_SOURCES = \
arg.h arg.cpp \
log.h log.cpp \
tcpsocket.h tcpsocket.cpp \
thread.h thread.cpp \
+11 -7
View File
@@ -48,7 +48,8 @@ void calcCounts(const argDef *argDefs, int &count, int &shortCharsCount, int &sh
}
}
void buildOpts(const argDef *argDefs, int &count, int &shortCharsCount, int &shortOptsCount, struct option *longOpts, char *shortChars, int *shortIndexes, char *shortOpts, int argDefIdx) {
void buildOpts(const argDef *argDefs, int &count, int &shortCharsCount, int &shortOptsCount,
struct option *longOpts, char *shortChars, int *shortIndexes, char *shortOpts, int argDefIdx) {
struct option *opt = longOpts+count;
for (const argDef *arg = argDefs; arg && arg->help; arg++, argDefIdx++) {
if (!arg->name) {
@@ -108,15 +109,19 @@ int argParse(const argParseOpt *parseOpt, int argc, char **argv, int *argIndex)
shortOpts[shortOptsCount++] = '+'; // posix mode to stop at first non-option
shortOpts[shortOptsCount++] = ':'; // return ':' for missing option
if (!(parseOpt->flags & af_noHelp)) {
buildOpts(helpArgDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars, shortIndexes, shortOpts, 0xff00);
buildOpts(helpArgDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars,
shortIndexes, shortOpts, 0xff00);
}
if (!(parseOpt->flags & af_noVersion)) {
buildOpts(versionArgDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars, shortIndexes, shortOpts, 0xff01);
buildOpts(versionArgDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars,
shortIndexes, shortOpts, 0xff01);
}
buildOpts(parseOpt->argDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars, shortIndexes, shortOpts, 0);
buildOpts(parseOpt->argDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars,
shortIndexes, shortOpts, 0);
int children = 0;
for (const argParseChildOpt *child = parseOpt->childOpts; child && child->argDefs; child++) {
buildOpts(child->argDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars, shortIndexes, shortOpts, 0x100*(++children));
buildOpts(child->argDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars,
shortIndexes, shortOpts, 0x100*(++children));
}
optind = 1; // setting to 0 does not work
int c = 0, longIdx = -1, ret = 0;
@@ -320,8 +325,7 @@ void argHelp(const argParseOpt *parseOpt) {
}
printf("Usage: %s [OPTION...] %s\n",
parseOpt->name,
parseOpt->positional ? parseOpt->positional : ""
);
parseOpt->positional ? parseOpt->positional : "");
wrap(parseOpt->help, 0, 0);
printArgs(parseOpt->argDefs, indent);
for (const argParseChildOpt *child = parseOpt->childOpts; child && child->argDefs; child++) {
+3 -3
View File
@@ -16,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIB_UTILS_ARGS_H_
#define LIB_UTILS_ARGS_H_
#ifndef LIB_UTILS_ARG_H_
#define LIB_UTILS_ARG_H_
namespace ebusd {
@@ -94,4 +94,4 @@ void argHelp(const argParseOpt *parseOpt);
} // namespace ebusd
#endif // LIB_UTILS_ARGS_H_
#endif // LIB_UTILS_ARG_H_