From 9895a8083305ecbf672cbe6e42c72aaee98f6ce2 Mon Sep 17 00:00:00 2001 From: adjoly Date: Mon, 11 Aug 2025 19:51:18 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=8F=97=EF=B8=8F=E3=80=8D=20wip:?= =?UTF-8?q?=20started=20the=20parsing=20of=20the=20args?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .clang-format | 5 +++++ .gitignore | 3 +++ includes/help.h | 9 +++++++++ includes/opt_parse.h | 11 +++++++++++ includes/ping.h | 1 + src/help.c | 15 +++++++++++++++ src/main.c | 23 ++++++++++++++++++++--- src/opt_parse.c | 33 +++++++++++++++++++++++++++++++++ 8 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 .clang-format create mode 100644 includes/help.h create mode 100644 includes/opt_parse.h create mode 100644 includes/ping.h create mode 100644 src/help.c create mode 100644 src/opt_parse.c diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..7a2deec --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +UseTab: Always +IndentWidth: 4 +TabWidth: 4 +AlignConsecutiveDeclarations: true +ConstructorInitializerIndentWidth: 4 diff --git a/.gitignore b/.gitignore index 6438daa..a8c366c 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,6 @@ Module.symvers Mkfile.old dkms.conf +# clangd shit +compile_commands.json +.cache diff --git a/includes/help.h b/includes/help.h new file mode 100644 index 0000000..28c0eee --- /dev/null +++ b/includes/help.h @@ -0,0 +1,9 @@ +#pragma once + +/** + * @brief Can be used to print the help message if no host (or addr) are + * provided + */ +void print_no_host(char *av); + +void print_help(void); diff --git a/includes/opt_parse.h b/includes/opt_parse.h new file mode 100644 index 0000000..43de3b0 --- /dev/null +++ b/includes/opt_parse.h @@ -0,0 +1,11 @@ +#pragma once + +typedef struct { + +} args_t; + +/** + * @brief Can be used to parse the command line options + * @param av The argv of the program + */ +int opt_parse(char **av, args_t *args); diff --git a/includes/ping.h b/includes/ping.h new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/includes/ping.h @@ -0,0 +1 @@ +#pragma once diff --git a/src/help.c b/src/help.c new file mode 100644 index 0000000..d027343 --- /dev/null +++ b/src/help.c @@ -0,0 +1,15 @@ +#include + +#include + +struct options { + char opt; + char *desc; +}; + +void print_help(void) {} + +void print_no_host(char *av) { + printf("%s: missing host operand\n", av); + printf("Try 'ping --help' or 'ping -?' for more information.\n"); +} diff --git a/src/main.c b/src/main.c index 3547b35..76494a0 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,22 @@ -#include +#include "sysexits.h" +#include +#include +#include -int main(void){ - printf("asdf asdfa"); +#include +#include + +int main(int ac, char **av) { + args_t args; + if (ac > 1) { + int ret = opt_parse(av, &args); + if (ret != EXIT_SUCCESS) + return ret; + else + return EXIT_SUCCESS; + } else { + print_no_host(*av); + return EX_USAGE; + } + return EXIT_SUCCESS; } diff --git a/src/opt_parse.c b/src/opt_parse.c new file mode 100644 index 0000000..ea88888 --- /dev/null +++ b/src/opt_parse.c @@ -0,0 +1,33 @@ +#include +#include +#include + +#include +#include +#include + +int opt_parse(char **av, args_t *args) { + char *exec_name = *av; + + (void)args; + while (*av != NULL) { + char *a = *av; + + if (*a == '-') { + printf("omg an opt\n"); + } else { + + } + av++; + } + + if (av) { + print_no_host(exec_name); + return EX_USAGE; + } + return EXIT_SUCCESS; +} + + +// 127.0.0.1 localhost : no error wtf EZ 42 parsing + ratio +// -v 127.0.0.1