gbranden pushed a commit to branch master
in repository groff.
commit ff65f930ead64f98bb86b7c5ea232f0d162300a1
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Dec 6 07:44:54 2025 -0600
Handle unrecognized long option arguments better.
* src/devices/grodvi/dvi.cpp (main):
* src/devices/grohtml/post-html.cpp (main):
* src/devices/grolbp/lbp.cpp (main):
* src/devices/grolj4/lj4.cpp (main):
* src/devices/grops/ps.cpp (main):
* src/devices/grotty/tty.cpp (main):
* src/preproc/eqn/main.cpp (main):
* src/preproc/grn/main.cpp (main):
* src/preproc/html/pre-html.cpp (main):
* src/preproc/pic/main.cpp (main):
* src/preproc/preconv/main.cpp (main):
* src/preproc/soelim/main.cpp (main):
* src/preproc/tbl/main.cpp (main):
* src/roff/groff/groff.cpp (main):
* src/roff/troff/input.cpp (main):
* src/utils/hpftodit/hpftodit.cpp (main):
* src/utils/indxbib/indxbib.cpp (main):
* src/utils/lkbib/lkbib.cpp (main):
* src/utils/lookbib/lookbib.cpp (main):
* src/utils/pfbtops/pfbtops.c (main):
* src/utils/tfmtodit/tfmtodit.cpp (main):
* src/utils/xtotroff/xtotroff.c (main): When given an unrecognized long
option, report what it was.
Fixes regression during 1.24 development cycle:
$ ~/groff-1.23.0/bin/groff --bogus 2>&1 | head -n 1
.../groff-1.23.0/bin/groff: unrecognized option '--bogus'
$ ~/groff-HEAD/bin/groff --bogus 2>&1 | head -n 1
.../groff-HEAD/bin/groff: error: unrecognized command-line option ''
$ ./build/test-groff --bogus 2>&1 | head -n 1
.../src/GIT/groff/build/groff: error: unrecognized command-line option
'--bogus'
and similarly for the other programs.
---
ChangeLog | 28 ++++++++++++++++++++++++++++
src/devices/grodvi/dvi.cpp | 6 +++++-
src/devices/grohtml/post-html.cpp | 6 +++++-
src/devices/grolbp/lbp.cpp | 6 +++++-
src/devices/grolj4/lj4.cpp | 6 +++++-
src/devices/grops/ps.cpp | 6 +++++-
src/devices/grotty/tty.cpp | 6 +++++-
src/preproc/eqn/main.cpp | 6 +++++-
src/preproc/grn/main.cpp | 2 +-
src/preproc/html/pre-html.cpp | 6 +++++-
src/preproc/pic/main.cpp | 6 +++++-
src/preproc/preconv/preconv.cpp | 6 +++++-
src/preproc/soelim/soelim.cpp | 6 +++++-
src/preproc/tbl/main.cpp | 6 +++++-
src/roff/groff/groff.cpp | 6 +++++-
src/roff/troff/input.cpp | 6 +++++-
src/utils/hpftodit/hpftodit.cpp | 6 +++++-
src/utils/indxbib/indxbib.cpp | 6 +++++-
src/utils/lkbib/lkbib.cpp | 6 +++++-
src/utils/lookbib/lookbib.cpp | 6 +++++-
src/utils/pfbtops/pfbtops.c | 8 ++++++--
src/utils/tfmtodit/tfmtodit.cpp | 6 +++++-
src/utils/xtotroff/xtotroff.c | 8 ++++++--
23 files changed, 136 insertions(+), 24 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 99271dc7d..92ba02f87 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,31 @@
+2025-12-06 G. Branden Robinson <[email protected]>
+
+ Handle unrecognized long option arguments better.
+
+ * src/devices/grodvi/dvi.cpp (main):
+ * src/devices/grohtml/post-html.cpp (main):
+ * src/devices/grolbp/lbp.cpp (main):
+ * src/devices/grolj4/lj4.cpp (main):
+ * src/devices/grops/ps.cpp (main):
+ * src/devices/grotty/tty.cpp (main):
+ * src/preproc/eqn/main.cpp (main):
+ * src/preproc/grn/main.cpp (main):
+ * src/preproc/html/pre-html.cpp (main):
+ * src/preproc/pic/main.cpp (main):
+ * src/preproc/preconv/main.cpp (main):
+ * src/preproc/soelim/main.cpp (main):
+ * src/preproc/tbl/main.cpp (main):
+ * src/roff/groff/groff.cpp (main):
+ * src/roff/troff/input.cpp (main):
+ * src/utils/hpftodit/hpftodit.cpp (main):
+ * src/utils/indxbib/indxbib.cpp (main):
+ * src/utils/lkbib/lkbib.cpp (main):
+ * src/utils/lookbib/lookbib.cpp (main):
+ * src/utils/pfbtops/pfbtops.c (main):
+ * src/utils/tfmtodit/tfmtodit.cpp (main):
+ * src/utils/xtotroff/xtotroff.c (main): When given an
+ unrecognized long option, report what it was.
+
2025-12-05 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp (token::description): Improve
diff --git a/src/devices/grodvi/dvi.cpp b/src/devices/grodvi/dvi.cpp
index 4d46da10a..5cb97ac52 100644
--- a/src/devices/grodvi/dvi.cpp
+++ b/src/devices/grodvi/dvi.cpp
@@ -983,7 +983,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/devices/grohtml/post-html.cpp
b/src/devices/grohtml/post-html.cpp
index 26d5d2591..f41531c54 100644
--- a/src/devices/grohtml/post-html.cpp
+++ b/src/devices/grohtml/post-html.cpp
@@ -5971,7 +5971,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/devices/grolbp/lbp.cpp b/src/devices/grolbp/lbp.cpp
index 22fcab587..41516967d 100644
--- a/src/devices/grolbp/lbp.cpp
+++ b/src/devices/grolbp/lbp.cpp
@@ -735,7 +735,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/devices/grolj4/lj4.cpp b/src/devices/grolj4/lj4.cpp
index 44362c826..a3d9274aa 100644
--- a/src/devices/grolj4/lj4.cpp
+++ b/src/devices/grolj4/lj4.cpp
@@ -708,7 +708,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/devices/grops/ps.cpp b/src/devices/grops/ps.cpp
index 35f416b99..e7e48e3a1 100644
--- a/src/devices/grops/ps.cpp
+++ b/src/devices/grops/ps.cpp
@@ -1930,7 +1930,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/devices/grotty/tty.cpp b/src/devices/grotty/tty.cpp
index 472da6d06..b4ed628a9 100644
--- a/src/devices/grotty/tty.cpp
+++ b/src/devices/grotty/tty.cpp
@@ -1054,7 +1054,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/preproc/eqn/main.cpp b/src/preproc/eqn/main.cpp
index 48af52439..a471a2a93 100644
--- a/src/preproc/eqn/main.cpp
+++ b/src/preproc/eqn/main.cpp
@@ -428,7 +428,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/preproc/grn/main.cpp b/src/preproc/grn/main.cpp
index 93fb6cd7b..18c0cc0bd 100644
--- a/src/preproc/grn/main.cpp
+++ b/src/preproc/grn/main.cpp
@@ -372,7 +372,7 @@ main(int argc,
}
// fallthrough
default:
- error("unrecognized command-line option '%1'", c);
+ error("unrecognized command-line option '%1'", *argv);
usage(stderr);
exit(2);
}
diff --git a/src/preproc/html/pre-html.cpp b/src/preproc/html/pre-html.cpp
index ff15a950f..dd6dd2341 100644
--- a/src/preproc/html/pre-html.cpp
+++ b/src/preproc/html/pre-html.cpp
@@ -1714,7 +1714,11 @@ static int scanArguments(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/preproc/pic/main.cpp b/src/preproc/pic/main.cpp
index aabe2fd60..1be102998 100644
--- a/src/preproc/pic/main.cpp
+++ b/src/preproc/pic/main.cpp
@@ -625,7 +625,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/preproc/preconv/preconv.cpp b/src/preproc/preconv/preconv.cpp
index 08431d0da..a7c860e6d 100644
--- a/src/preproc/preconv/preconv.cpp
+++ b/src/preproc/preconv/preconv.cpp
@@ -1321,7 +1321,11 @@ main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/preproc/soelim/soelim.cpp b/src/preproc/soelim/soelim.cpp
index acc7aa0f9..513054bf3 100644
--- a/src/preproc/soelim/soelim.cpp
+++ b/src/preproc/soelim/soelim.cpp
@@ -102,7 +102,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/preproc/tbl/main.cpp b/src/preproc/tbl/main.cpp
index 355aa1789..546b38788 100644
--- a/src/preproc/tbl/main.cpp
+++ b/src/preproc/tbl/main.cpp
@@ -1687,7 +1687,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/roff/groff/groff.cpp b/src/roff/groff/groff.cpp
index dc41c0b4b..fabacd597 100644
--- a/src/roff/groff/groff.cpp
+++ b/src/roff/groff/groff.cpp
@@ -378,7 +378,11 @@ int main(int argc, char **argv)
need_postdriver = false;
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
xexit(2);
break;
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 95a42fe34..83e9d76fe 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -9843,7 +9843,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr, argv[0]);
exit(2);
break; // never reached
diff --git a/src/utils/hpftodit/hpftodit.cpp b/src/utils/hpftodit/hpftodit.cpp
index 35986ee92..2c83331ff 100644
--- a/src/utils/hpftodit/hpftodit.cpp
+++ b/src/utils/hpftodit/hpftodit.cpp
@@ -330,7 +330,11 @@ main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage();
break;
case ':':
diff --git a/src/utils/indxbib/indxbib.cpp b/src/utils/indxbib/indxbib.cpp
index be3570cc7..968be4eaa 100644
--- a/src/utils/indxbib/indxbib.cpp
+++ b/src/utils/indxbib/indxbib.cpp
@@ -194,7 +194,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/utils/lkbib/lkbib.cpp b/src/utils/lkbib/lkbib.cpp
index a69a57250..fd041bb69 100644
--- a/src/utils/lkbib/lkbib.cpp
+++ b/src/utils/lkbib/lkbib.cpp
@@ -108,7 +108,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/utils/lookbib/lookbib.cpp b/src/utils/lookbib/lookbib.cpp
index 6e2be5002..95bed5517 100644
--- a/src/utils/lookbib/lookbib.cpp
+++ b/src/utils/lookbib/lookbib.cpp
@@ -110,7 +110,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/utils/pfbtops/pfbtops.c b/src/utils/pfbtops/pfbtops.c
index 9010eb210..8d15d173d 100644
--- a/src/utils/pfbtops/pfbtops.c
+++ b/src/utils/pfbtops/pfbtops.c
@@ -197,8 +197,12 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- fprintf(stderr, "%s: error: unrecognized command-line option"
- " '%c'\n", program_name, (char) optopt);
+ if (optopt != 0)
+ fprintf(stderr, "%s: error: unrecognized command-line option"
+ " '%c'\n", program_name, (char) optopt);
+ else
+ fprintf(stderr, "unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
break;
diff --git a/src/utils/tfmtodit/tfmtodit.cpp b/src/utils/tfmtodit/tfmtodit.cpp
index ec6fb89ed..192cd345b 100644
--- a/src/utils/tfmtodit/tfmtodit.cpp
+++ b/src/utils/tfmtodit/tfmtodit.cpp
@@ -736,7 +736,11 @@ int main(int argc, char **argv)
exit(EXIT_SUCCESS);
break;
case '?':
- error("unrecognized command-line option '%1'", char(optopt));
+ if (optopt != 0)
+ error("unrecognized command-line option '%1'", char(optopt));
+ else
+ error("unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
exit(2);
case ':':
diff --git a/src/utils/xtotroff/xtotroff.c b/src/utils/xtotroff/xtotroff.c
index ee5ccb501..b7da9c5e3 100644
--- a/src/utils/xtotroff/xtotroff.c
+++ b/src/utils/xtotroff/xtotroff.c
@@ -317,8 +317,12 @@ int main(int argc, char **argv)
xtotroff_exit(EXIT_SUCCESS);
break;
case '?':
- fprintf(stderr, "%s: unrecognized command-line option '%c'\n",
- program_name, (char) optopt);
+ if (optopt != 0)
+ fprintf(stderr, "%s: error: unrecognized command-line option"
+ " '%c'\n", program_name, (char) optopt);
+ else
+ fprintf(stderr, "unrecognized command-line option '%1'",
+ argv[(optind - 1)]);
usage(stderr);
xtotroff_exit(2);
break;
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit