eal: rename option name field
[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 int
19 rte_option_parse(const char *opt)
20 {
21         struct rte_option *option;
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->name) == 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         struct rte_option *option;
42
43         TAILQ_FOREACH(option, &rte_option_list, next) {
44                 if (strcmp(opt->name, option->name) == 0) {
45                         RTE_LOG(INFO, EAL, "Option %s has already been registered.\n",
46                                         opt->name);
47                         return;
48                 }
49         }
50
51         TAILQ_INSERT_HEAD(&rte_option_list, opt, next);
52 }
53
54 void
55 rte_option_init(void)
56 {
57         struct rte_option *option;
58
59         TAILQ_FOREACH(option, &rte_option_list, next) {
60                 if (option->enabled)
61                         option->cb();
62         }
63 }
64
65 void
66 rte_option_usage(void)
67 {
68         struct rte_option *option;
69         int opt_count = 0;
70
71         TAILQ_FOREACH(option, &rte_option_list, next)
72                 opt_count += 1;
73         if (opt_count == 0)
74                 return;
75
76         printf("EAL dynamic options:\n");
77         TAILQ_FOREACH(option, &rte_option_list, next)
78                 printf("  --%-*s %s\n", 17, option->name, option->usage);
79         printf("\n");
80 }