commit 72781f4fb731184263cca9cf52dca23a7ce72fe9
parent b009d1b81e1ed073de76b11d6b47ed8fcdc4ca0d
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Sun, 20 Dec 2020 23:32:54 -0800
Simplify main() by reusing cgoto() instead of getopt(3)
Diffstat:
M | main.c | | | 30 | +++++------------------------- |
1 file changed, 5 insertions(+), 25 deletions(-)
diff --git a/main.c b/main.c
@@ -578,36 +578,16 @@ gawk(int depth, const char *tmpdir, const char *host, const char *path, const ch
int
main(int argc, char *argv[])
{
- char *host = "localhost";
- char *path = "/";
- char *port = "70";
- char temp[64];
- int ch;
+ char temp[] = "/tmp/gawk-XXXXXXXXXXX";
int status;
- while ((ch = getopt(argc, argv, "d:h:p:")) != -1) {
- switch (ch) {
- case 'd':
- path = optarg;
- break;
- case 'h':
- host = optarg;
- break;
- case 'p':
- port = optarg;
- break;
- default:
- fprintf(stderr, "usage: %s [-d path] [-h host] [-p port]\n",
- getprogname());
- return 1;
- }
- }
-
- strcpy(temp, "/tmp/gawk-XXXXXXXXXXX");
if (mkdtemp(temp) == NULL)
err(1, "mkdtemp '%s'", temp);
- status = gawk(0, temp, host, path, port);
+ status = cgoto(argc - 1, (const char **)argv + 1, 0, temp, "localhost", "/", "70");
+ if (status)
+ fprintf(stderr, "usage: %s [path] | [host] [path] [port]\n",
+ getprogname());
if (rmdir(temp) == -1)
err(1, "rmdir '%s'", temp);