Skip to content

Commit 8f656e4

Browse files
committed
training: Fix dubious parsing of command line
- Don't support --helpshort as an undocumented alias for --help - Don't allow any number of leading '-' characters. The preferred form uses --OPTION, and for compatibility reasons the new code still supports -OPTION. Update also related documentation comments. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 4b468e1 commit 8f656e4

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

training/commandlineflags.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,14 @@ void ParseCommandLineFlags(const char* usage,
170170
break;
171171
}
172172
// Position current_arg after startings hyphens. We treat a sequence of
173-
// consecutive hyphens of any length identically.
174-
while (*current_arg == '-') {
173+
// one or two consecutive hyphens identically.
174+
++current_arg;
175+
if (current_arg[0] == '-') {
175176
++current_arg;
176177
}
177178
// If this is asking for usage, print the help message and abort.
178-
if (!strcmp(current_arg, "help") ||
179-
!strcmp(current_arg, "helpshort")) {
180-
printf("USAGE: %s\n", usage);
179+
if (!strcmp(current_arg, "help")) {
180+
printf("Usage:\n %s [OPTION ...]\n\n", usage);
181181
PrintCommandLineFlags();
182182
exit(0);
183183
}

training/commandlineflags.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
namespace tesseract {
6868

6969
// Parse commandline flags and values. Prints the usage string and exits on
70-
// input of --help or --helpshort.
70+
// input of --help or --version.
7171
//
7272
// If remove_flags is true, the argv pointer is advanced so that (*argv)[1]
7373
// points to the first non-flag argument, (*argv)[0] points to the same string

0 commit comments

Comments
 (0)