From 97d2f1383df1f9be95827a3d564245a8bcf87b11 Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Thu, 30 Apr 2026 11:03:33 +0200 Subject: [PATCH] feat(ssl): X-macro driven algo list and dynamic usage --- libft_ssl | 2 +- src/cli/parse.c | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/libft_ssl b/libft_ssl index f21811b..35c32a9 160000 --- a/libft_ssl +++ b/libft_ssl @@ -1 +1 @@ -Subproject commit f21811b66f4f5d29ada3a53bd91763cac3f6d87f +Subproject commit 35c32a9c323046f2e8d2c0380c3e512ee5a88dd4 diff --git a/src/cli/parse.c b/src/cli/parse.c index cb90c80..7c92d3f 100644 --- a/src/cli/parse.c +++ b/src/cli/parse.c @@ -11,14 +11,16 @@ /* Forward declarations */ static void init_config(struct ssl_config *config); +static void print_usage(const char *prog); static const struct digest_algo *find_algo(const char *name); static enum cli_code parse_subcommand(int argc, char **argv, int first_arg, struct ssl_config *config); /* ------------------- */ static const struct digest_algo * const s_algos[] = { - &g_md5, - &g_sha256, +#define DIGEST_ALGO(lower, ds, bs) &g_##lower, +#include +#undef DIGEST_ALGO NULL }; @@ -43,16 +45,14 @@ parse_subcommand(int argc, char **argv, int first_arg, if (first_arg >= argc) { fprintf(stderr, "%s: missing command\n", argv[0]); - fprintf(stderr, "usage: %s {md5|sha256} [-pqr] [-s string] [file...]\n", - argv[0]); + print_usage(argv[0]); return CLI_ERROR; } config->algo = find_algo(argv[first_arg]); if (NULL == config->algo) { fprintf(stderr, "%s: unknown command -- '%s'\n", argv[0], argv[first_arg]); - fprintf(stderr, "usage: %s {md5|sha256} [-pqr] [-s string] [file...]\n", - argv[0]); + print_usage(argv[0]); return CLI_ERROR; } config->files = argv + first_arg + 1; @@ -73,6 +73,21 @@ find_algo(const char *name) return NULL; } +static void +print_usage(const char *prog) +{ + size_t i; + + fprintf(stderr, "usage: %s {", prog); + for (i = 0; NULL != s_algos[i]; i++) + { + if (0 != i) + fprintf(stderr, "|"); + fprintf(stderr, "%s", s_algos[i]->name); + } + fprintf(stderr, "} [-pqr] [-s string] [file...]\n"); +} + static void init_config(struct ssl_config *config) {