diff options
author | Tristan Riehs <tristan.riehs@bordeaux-inp.fr> | 2024-06-20 01:08:43 +0900 |
---|---|---|
committer | Tristan Riehs <tristan.riehs@bordeaux-inp.fr> | 2024-06-20 01:08:43 +0900 |
commit | 830f3750bcffd0a6dff998a1ac227333932cfec0 (patch) | |
tree | af5dceae55454fac22e9c050b7ffff7bd2e68da6 /src | |
parent | 0fe90e921af56fd758d64bd123fd9c7a0ebba374 (diff) |
Handle the new interface option
Diffstat (limited to 'src')
-rw-r--r-- | src/calculer.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/calculer.c b/src/calculer.c index 3ea19ad..34e2fa6 100644 --- a/src/calculer.c +++ b/src/calculer.c @@ -26,6 +26,7 @@ #include <unistd.h> #include "_readline.h" +#include "disp.h" static int lower = 0; static int upper = 100; @@ -115,11 +116,30 @@ print_version(void) printf("%s\n", VERSION); } +void +set_disp_name(char **dest, char const *optarg) +{ + if (strcmp(optarg, "cli") == 0) + { + *dest = DISP_CLI; + } + else if (strcmp(optarg, "gui") == 0) + { + *dest = DISP_RAY; + } + else + { + fprintf(stderr, "calculer: invalid interface \"%s\"\n", optarg); + print_usage(stderr); + exit(1); + } +} + int main(int argc, char *argv[]) { char *logpath = "./calculer.log"; - + char *disp_name = DISP_RAY; srand(time(NULL)); /* Store the prefix "YYYY-MM-DD" in LOGBUF. */ @@ -129,7 +149,7 @@ main(int argc, char *argv[]) assert(bytes_written); int opt; - while ((opt = getopt(argc, argv, ":Vhl:m:M:")) != -1) + while ((opt = getopt(argc, argv, ":Vhl:m:M:i:")) != -1) { switch (opt) { @@ -148,6 +168,9 @@ main(int argc, char *argv[]) case 'M': upper = atoi(optarg); break; + case 'i': + set_disp_name(&disp_name, optarg); + break; case ':': fprintf(stderr, "calculer: option %d requires an argument\n", |