From 312dea1d673365656cf98d282fb2bce64289a11d Mon Sep 17 00:00:00 2001 From: Thomas Albers Date: Thu, 10 Aug 2023 10:37:52 +0200 Subject: Make param global --- zup.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'zup.c') diff --git a/zup.c b/zup.c index 8dffb17..844a693 100644 --- a/zup.c +++ b/zup.c @@ -95,7 +95,7 @@ parse_baud(const char *str) static int -parse_options(int argc, char *const argv[], struct param *param) +parse_options(int argc, char *const argv[]) { const char *sopts = "b:p:hHVRrv"; const struct option lopts[] = { @@ -116,30 +116,30 @@ parse_options(int argc, char *const argv[], struct param *param) while ((c = getopt_long(argc, argv, sopts, lopts, &i)) != -1) { switch (c) { case 'b': - if (!(param->baud = parse_baud(optarg))) { + if (!(param.baud = parse_baud(optarg))) { fprintf(stderr, "Error: Invalid baud rate '%s'\n", optarg); exit(EXIT_FAILURE); } break; case 'v': - param->verbose = 1; + param.verbose = 1; break; case 'p': - strncpy(param->port, optarg, LEN(param->port)); + strncpy(param.port, optarg, LEN(param.port)); break; case 'R': - param->repl = 1; + param.repl = 1; break; case 'H': - param->human_readable = 1; + param.human_readable = 1; break; case 'r': - param->human_readable = 0; + param.human_readable = 0; break; case 'V': @@ -210,7 +210,13 @@ hexdump(size_t start_address, size_t len, const uint8_t *buf) } } -int verbose = 0; +struct param param = { + .port = "/dev/ttyS1", + .baud = B9600, + .verbose = 0, + .human_readable = 0, + .repl = 0 +}; // TODO: Support stdin/stdout @@ -220,29 +226,19 @@ main(int argc, char *argv[]) int suc = EXIT_SUCCESS; // Init defaults - struct param param = { - .port = "/dev/ttyS1", - .baud = B9600, - .verbose = 0, - .human_readable = 0, - .repl = 0 - - }; - - int ind = parse_options(argc, argv, ¶m); - verbose = param.verbose; + int ind = parse_options(argc, argv); int fd = open_tty(param.port, param.baud); if (ind == argc || param.repl) { - repl(fd, ¶m); + repl(fd); } else { argc -= ind; argv = &argv[ind]; int err = 0; for (int i = 0; i < argc && !err; ++i) - err = run_line(fd, ¶m, argv[i], ":"); + err = run_line(fd, argv[i], ":"); if (err) suc = EXIT_FAILURE; -- cgit v1.2.3