summaryrefslogtreecommitdiff
path: root/zup.c
diff options
context:
space:
mode:
authorThomas Albers <thomas@thomaslabs.org>2023-08-10 10:37:52 +0200
committerThomas Albers <thomas@thomaslabs.org>2023-08-10 10:37:52 +0200
commit312dea1d673365656cf98d282fb2bce64289a11d (patch)
tree6ae5f5e118dcb70275181ffecd3541560cc1bdd2 /zup.c
parentd75ccbc5e113a09aa3b25f4c61e5b674bc51bed7 (diff)
Make param global
Diffstat (limited to 'zup.c')
-rw-r--r--zup.c38
1 files changed, 17 insertions, 21 deletions
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, &param);
- verbose = param.verbose;
+ int ind = parse_options(argc, argv);
int fd = open_tty(param.port, param.baud);
if (ind == argc || param.repl) {
- repl(fd, &param);
+ repl(fd);
} else {
argc -= ind;
argv = &argv[ind];
int err = 0;
for (int i = 0; i < argc && !err; ++i)
- err = run_line(fd, &param, argv[i], ":");
+ err = run_line(fd, argv[i], ":");
if (err)
suc = EXIT_FAILURE;