3fbc13a6a71ea32ee1008cca31c8016c9ca52675
[dpdk.git] / lib / librte_eal / common / rte_option.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation.
3  */
4
5 #include <unistd.h>
6 #include <string.h>
7
8 #include <rte_eal.h>
9 #include <rte_option.h>
10
11 #include "eal_private.h"
12
13 TAILQ_HEAD(rte_option_list, rte_option);
14
15 struct rte_option_list rte_option_list =
16         TAILQ_HEAD_INITIALIZER(rte_option_list);
17
18 static struct rte_option *option;
19
20 int
21 rte_option_parse(const char *opt)
22 {
23         if (strlen(opt) <= 2 ||
24             strncmp(opt, "--", 2))
25                 return -1;
26
27         /* Check if the option is registered */
28         TAILQ_FOREACH(option, &rte_option_list, next) {
29                 if (strcmp(&opt[2], option->opt_str) == 0) {
30                         option->enabled = 1;
31                         return 0;
32                 }
33         }
34
35         return -1;
36 }
37
38 void __rte_experimental
39 rte_option_register(struct rte_option *opt)
40 {
41         TAILQ_FOREACH(option, &rte_option_list, next) {
42                 if (strcmp(opt->opt_str, option->opt_str) == 0) {
43                         RTE_LOG(INFO, EAL, "Option %s has already been registered.\n",
44                                         opt->opt_str);
45                         return;
46                 }
47         }
48
49         TAILQ_INSERT_HEAD(&rte_option_list, opt, next);
50 }
51
52 void
53 rte_option_init(void)
54 {
55         TAILQ_FOREACH(option, &rte_option_list, next) {
56                 if (option->enabled)
57                         option->cb();
58         }
59 }