fix: interactive

This commit is contained in:
lohhiiccc 2026-05-11 18:45:09 +02:00
parent 95c902703e
commit 80e34d8158

View file

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include <cli.h> #include <cli.h>
#include <libft_ssl.h> #include <libft_ssl.h>
@ -23,28 +24,17 @@ static void print_available(void);
enum cli_code enum cli_code
run_interactive(void) run_interactive(void)
{ {
char buf[INTERACTIVE_BUFSIZ]; char buf[INTERACTIVE_BUFSIZ];
char *sep;
const struct digest_algo *algo; const struct digest_algo *algo;
struct ssl_config config; struct ssl_config config;
while (fgets(buf, (int)sizeof(buf), stdin)) while (fgets(buf, (int)sizeof(buf), stdin))
{ {
buf[strcspn(buf, "\n")] = '\0'; buf[strcspn(buf, "\n")] = '\0';
if (buf[0] == '\0') if (buf[0] == '\0')
continue; continue;
sep = buf;
while (*sep && *sep != ' ' && *sep != '\t')
sep++;
if (*sep)
{
*sep = '\0';
sep++;
while (*sep == ' ' || *sep == '\t')
sep++;
}
algo = find_algo(buf); algo = find_algo(buf);
if (!algo) if (NULL == algo)
{ {
fprintf(stderr, "ft_ssl: unknown command -- '%s'\n", buf); fprintf(stderr, "ft_ssl: unknown command -- '%s'\n", buf);
print_available(); print_available();
@ -52,7 +42,6 @@ run_interactive(void)
} }
memset(&config, 0, sizeof(config)); memset(&config, 0, sizeof(config));
config.algo = algo; config.algo = algo;
config.string = (*sep != '\0') ? sep : NULL;
ssl_run(&config); ssl_run(&config);
} }
return CLI_EXIT_SUCCESS; return CLI_EXIT_SUCCESS;
@ -63,9 +52,9 @@ find_algo(const char *name)
{ {
size_t i; size_t i;
for (i = 0; s_algos[i]; i++) for (i = 0; s_algos[i]; ++i)
{ {
if (strcmp(s_algos[i]->name, name) == 0) if (0 == strcmp(s_algos[i]->name, name))
return s_algos[i]; return s_algos[i];
} }
return NULL; return NULL;
@ -77,7 +66,7 @@ print_available(void)
size_t i; size_t i;
fprintf(stderr, "available commands:"); fprintf(stderr, "available commands:");
for (i = 0; s_algos[i]; i++) for (i = 0; s_algos[i]; ++i)
fprintf(stderr, " %s", s_algos[i]->name); fprintf(stderr, " %s", s_algos[i]->name);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }