remove experimental tags from all symbol definitions
[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 <getopt.h>
6 #include <unistd.h>
7 #include <string.h>
8
9 #include <rte_eal.h>
10 #include <rte_option.h>
11
12 #include "eal_private.h"
13 #include "eal_internal_cfg.h" /* Necessary for eal_options.h */
14 #include "eal_options.h"
15
16 TAILQ_HEAD(rte_option_list, rte_option);
17
18 struct rte_option_list rte_option_list =
19         TAILQ_HEAD_INITIALIZER(rte_option_list);
20
21 int
22 rte_option_parse(const char *opt)
23 {
24         struct rte_option *option;
25
26         if (strlen(opt) <= 2 ||
27             strncmp(opt, "--", 2))
28                 return -1;
29
30         /* Check if the option is registered */
31         TAILQ_FOREACH(option, &rte_option_list, next) {
32                 if (strcmp(&opt[2], option->name) == 0) {
33                         option->enabled = 1;
34                         return 0;
35                 }
36         }
37
38         return -1;
39 }
40
41 int
42 rte_option_register(struct rte_option *opt)
43 {
44         struct rte_option *option;
45         const struct option *gopt;
46
47         gopt = &eal_long_options[0];
48         while (gopt->name != NULL) {
49                 if (strcmp(gopt->name, opt->name) == 0) {
50                         RTE_LOG(ERR, EAL, "Option %s is already a common EAL option.\n",
51                                         opt->name);
52                         return -1;
53                 }
54                 gopt++;
55         }
56
57         TAILQ_FOREACH(option, &rte_option_list, next) {
58                 if (strcmp(opt->name, option->name) == 0) {
59                         RTE_LOG(ERR, EAL, "Option %s has already been registered.\n",
60                                         opt->name);
61                         return -1;
62                 }
63         }
64
65         TAILQ_INSERT_HEAD(&rte_option_list, opt, next);
66         return 0;
67 }
68
69 void
70 rte_option_init(void)
71 {
72         struct rte_option *option;
73
74         TAILQ_FOREACH(option, &rte_option_list, next) {
75                 if (option->enabled)
76                         option->cb();
77         }
78 }
79
80 void
81 rte_option_usage(void)
82 {
83         struct rte_option *option;
84         int opt_count = 0;
85
86         TAILQ_FOREACH(option, &rte_option_list, next)
87                 opt_count += 1;
88         if (opt_count == 0)
89                 return;
90
91         printf("EAL dynamic options:\n");
92         TAILQ_FOREACH(option, &rte_option_list, next)
93                 printf("  --%-*s %s\n", 17, option->name, option->usage);
94         printf("\n");
95 }