1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
10 #include "rte_eth_softnic_internals.h"
13 #ifndef CMD_MAX_TOKENS
14 #define CMD_MAX_TOKENS 256
17 #define MSG_OUT_OF_MEMORY "Not enough memory.\n"
18 #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n"
19 #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n"
20 #define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n"
21 #define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n"
22 #define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n"
23 #define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n"
24 #define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n"
25 #define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n"
26 #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n"
27 #define MSG_CMD_FAIL "Command \"%s\" failed.\n"
32 if ((strlen(in) && index("!#%;", in[0])) ||
33 (strncmp(in, "//", 2) == 0) ||
34 (strncmp(in, "--", 2) == 0))
41 softnic_cli_process(char *in, char *out, size_t out_size, void *arg __rte_unused)
43 char *tokens[CMD_MAX_TOKENS];
44 uint32_t n_tokens = RTE_DIM(tokens);
50 status = softnic_parse_tokenize_string(in, tokens, &n_tokens);
52 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
59 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
63 softnic_cli_script_process(struct pmd_internals *softnic,
64 const char *file_name,
65 size_t msg_in_len_max,
66 size_t msg_out_len_max)
68 char *msg_in = NULL, *msg_out = NULL;
71 /* Check input arguments */
72 if (file_name == NULL ||
73 strlen(file_name) == 0 ||
74 msg_in_len_max == 0 ||
78 msg_in = malloc(msg_in_len_max + 1);
79 msg_out = malloc(msg_out_len_max + 1);
88 f = fopen(file_name, "r");
97 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
100 printf("%s", msg_in);
103 softnic_cli_process(msg_in,
109 printf("%s", msg_out);