[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 07/30: [preproc]: Migrate to modern getopt_long(3) usage.
From: |
G. Branden Robinson |
Subject: |
[groff] 07/30: [preproc]: Migrate to modern getopt_long(3) usage. |
Date: |
Sun, 22 Dec 2024 19:39:16 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit 531feba760f69244fa35ccd38c01b993a05ed6f2
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sat Dec 21 15:28:54 2024 -0600
[preproc]: Migrate to modern getopt_long(3) usage.
* src/preproc/eqn/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/soelim.cpp (main):
* src/preproc/tbl/main.cpp (main): Migrate to modern getopt_long(3)
usage. Drop `opterr` assignment; prefix the option string with ":"
instead. Handle return of `:`, emit an appropriate usage diagnostic,
and exit with status 2.
---
ChangeLog | 12 ++++++++++++
src/preproc/eqn/main.cpp | 9 +++++++--
src/preproc/html/pre-html.cpp | 9 +++++++--
src/preproc/pic/main.cpp | 9 +++++++--
src/preproc/preconv/preconv.cpp | 9 +++++++--
src/preproc/soelim/soelim.cpp | 9 +++++++--
src/preproc/tbl/main.cpp | 10 ++++++++--
7 files changed, 55 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a1f095e6b..2e2e95430 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-12-21 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * src/preproc/eqn/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/soelim.cpp (main):
+ * src/preproc/tbl/main.cpp (main): Migrate to modern
+ getopt_long(3) usage. Drop `opterr` assignment; prefix the
+ option string with ":" instead. Handle return of `:`, emit an
+ appropriate usage diagnostic, and exit with status 2.
+
2024-12-21 G. Branden Robinson <g.branden.robinson@gmail.com>
* src/devices/grolj4/lj4.cpp (main): Align missing command-line
diff --git a/src/preproc/eqn/main.cpp b/src/preproc/eqn/main.cpp
index 56ab03603..a6e0fa8d2 100644
--- a/src/preproc/eqn/main.cpp
+++ b/src/preproc/eqn/main.cpp
@@ -342,8 +342,7 @@ int main(int argc, char **argv)
{ "version", no_argument, 0, 'v' },
{ NULL, 0, 0, 0 }
};
- opterr = 0;
- while ((opt = getopt_long(argc, argv, "CNrRd:f:m:M:p:s:T:v",
+ while ((opt = getopt_long(argc, argv, ":CNrRd:f:m:M:p:s:T:v",
long_options, NULL)) != EOF)
switch (opt) {
case 'C':
@@ -434,6 +433,12 @@ int main(int argc, char **argv)
usage(stderr);
exit(2);
break;
+ case ':':
+ error("command-line option '%1' requires an argument",
+ char(optopt));
+ usage(stderr);
+ exit(2);
+ break;
default:
assert(0 == "unhandled getopt_long return value");
}
diff --git a/src/preproc/html/pre-html.cpp b/src/preproc/html/pre-html.cpp
index 7e7b36d59..9cb8dce05 100644
--- a/src/preproc/html/pre-html.cpp
+++ b/src/preproc/html/pre-html.cpp
@@ -1604,9 +1604,8 @@ static int scanArguments(int argc, char **argv)
{ "version", no_argument, 0, 'v' },
{ 0 /* nullptr */, 0, 0, 0 }
};
- opterr = 0;
while ((c = getopt_long(argc, argv,
- "+a:bCdD:eF:g:Ghi:I:j:k:lno:prs:S:vVx:y", long_options,
+ "+:a:bCdD:eF:g:Ghi:I:j:k:lno:prs:S:vVx:y", long_options,
0 /* nullptr */))
!= EOF)
switch(c) {
@@ -1707,6 +1706,12 @@ static int scanArguments(int argc, char **argv)
usage(stderr);
exit(2);
break;
+ case ':':
+ error("command-line option '%1' requires an argument",
+ char(optopt));
+ usage(stderr);
+ exit(2);
+ break;
default:
break;
}
diff --git a/src/preproc/pic/main.cpp b/src/preproc/pic/main.cpp
index 1fa94741c..4bb7d752d 100644
--- a/src/preproc/pic/main.cpp
+++ b/src/preproc/pic/main.cpp
@@ -573,8 +573,7 @@ int main(int argc, char **argv)
{ "version", no_argument, 0, 'v' },
{ NULL, 0, 0, 0 }
};
- opterr = 0;
- while ((opt = getopt_long(argc, argv, "T:CDSUtcvnxzpf", long_options,
+ while ((opt = getopt_long(argc, argv, ":T:CDSUtcvnxzpf", long_options,
NULL)) != EOF)
switch (opt) {
case 'C':
@@ -638,6 +637,12 @@ int main(int argc, char **argv)
usage(stderr);
exit(2);
break;
+ case ':':
+ error("command-line option '%1' requires an argument",
+ char(optopt));
+ usage(stderr);
+ exit(2);
+ break;
default:
assert(0 == "unhandled getopt_long return value");
}
diff --git a/src/preproc/preconv/preconv.cpp b/src/preproc/preconv/preconv.cpp
index 6a8ee6392..a5bf6905d 100644
--- a/src/preproc/preconv/preconv.cpp
+++ b/src/preproc/preconv/preconv.cpp
@@ -1271,9 +1271,8 @@ main(int argc, char **argv)
{ NULL, 0, 0, 0 }
};
// Parse the command-line options.
- opterr = 0;
while ((opt = getopt_long(argc, argv,
- "dD:e:hrv", long_options, NULL)) != EOF)
+ ":dD:e:hrv", long_options, NULL)) != EOF)
switch (opt) {
case 'v':
printf("GNU preconv (groff) version %s %s iconv support and %s"
@@ -1320,6 +1319,12 @@ main(int argc, char **argv)
usage(stderr);
exit(2);
break;
+ case ':':
+ error("command-line option '%1' requires an argument",
+ char(optopt));
+ usage(stderr);
+ exit(2);
+ break;
default:
assert(0 == "unhandled getopt_long return value");
}
diff --git a/src/preproc/soelim/soelim.cpp b/src/preproc/soelim/soelim.cpp
index 8cb601ba3..40848b2d4 100644
--- a/src/preproc/soelim/soelim.cpp
+++ b/src/preproc/soelim/soelim.cpp
@@ -76,8 +76,7 @@ int main(int argc, char **argv)
{ "version", no_argument, 0, 'v' },
{ NULL, 0, 0, 0 }
};
- opterr = 0;
- while ((opt = getopt_long(argc, argv, "CI:rtv", long_options, NULL))
+ while ((opt = getopt_long(argc, argv, ":CI:rtv", long_options, NULL))
!= EOF)
switch (opt) {
case 'v':
@@ -105,6 +104,12 @@ int main(int argc, char **argv)
usage(stderr);
exit(2);
break;
+ case ':':
+ error("command-line option '%1' requires an argument",
+ char(optopt));
+ usage(stderr);
+ exit(2);
+ break;
default:
assert(0 == "unhandled getopt_long return value");
}
diff --git a/src/preproc/tbl/main.cpp b/src/preproc/tbl/main.cpp
index da2d98f23..ba42be809 100644
--- a/src/preproc/tbl/main.cpp
+++ b/src/preproc/tbl/main.cpp
@@ -1660,8 +1660,7 @@ int main(int argc, char **argv)
{ "version", no_argument, 0, 'v' },
{ NULL, 0, 0, 0 }
};
- opterr = 0;
- while ((opt = getopt_long(argc, argv, "vC", long_options, NULL))
+ while ((opt = getopt_long(argc, argv, ":vC", long_options, NULL))
!= EOF)
switch (opt) {
case 'C':
@@ -1682,6 +1681,13 @@ int main(int argc, char **argv)
usage(stderr);
exit(2);
break;
+ // in case we ever accept options that take arguments
+ case ':':
+ error("command-line option '%1' requires an argument",
+ char(optopt));
+ usage(stderr);
+ exit(2);
+ break;
default:
assert(0 == "unhandled getopt_long return value");
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 07/30: [preproc]: Migrate to modern getopt_long(3) usage.,
G. Branden Robinson <=