fix: interactive
This commit is contained in:
parent
95c902703e
commit
80e34d8158
1 changed files with 7 additions and 18 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <cli.h>
|
||||
#include <libft_ssl.h>
|
||||
|
|
@ -23,28 +24,17 @@ static void print_available(void);
|
|||
enum cli_code
|
||||
run_interactive(void)
|
||||
{
|
||||
char buf[INTERACTIVE_BUFSIZ];
|
||||
char *sep;
|
||||
char buf[INTERACTIVE_BUFSIZ];
|
||||
const struct digest_algo *algo;
|
||||
struct ssl_config config;
|
||||
struct ssl_config config;
|
||||
|
||||
while (fgets(buf, (int)sizeof(buf), stdin))
|
||||
{
|
||||
buf[strcspn(buf, "\n")] = '\0';
|
||||
if (buf[0] == '\0')
|
||||
continue;
|
||||
sep = buf;
|
||||
while (*sep && *sep != ' ' && *sep != '\t')
|
||||
sep++;
|
||||
if (*sep)
|
||||
{
|
||||
*sep = '\0';
|
||||
sep++;
|
||||
while (*sep == ' ' || *sep == '\t')
|
||||
sep++;
|
||||
}
|
||||
algo = find_algo(buf);
|
||||
if (!algo)
|
||||
if (NULL == algo)
|
||||
{
|
||||
fprintf(stderr, "ft_ssl: unknown command -- '%s'\n", buf);
|
||||
print_available();
|
||||
|
|
@ -52,7 +42,6 @@ run_interactive(void)
|
|||
}
|
||||
memset(&config, 0, sizeof(config));
|
||||
config.algo = algo;
|
||||
config.string = (*sep != '\0') ? sep : NULL;
|
||||
ssl_run(&config);
|
||||
}
|
||||
return CLI_EXIT_SUCCESS;
|
||||
|
|
@ -63,9 +52,9 @@ find_algo(const char *name)
|
|||
{
|
||||
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 NULL;
|
||||
|
|
@ -77,7 +66,7 @@ print_available(void)
|
|||
size_t i;
|
||||
|
||||
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, "\n");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue