MCPcopy Create free account
hub / github.com/F-Stack/f-stack / app_args_parse

Function app_args_parse

dpdk/app/graph/main.c:56–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56static int
57app_args_parse(int argc, char **argv)
58{
59 struct option lgopts[] = {
60 {"help", 0, 0, 'H'},
61 {"enable-graph-stats", 0, 0, 'g'},
62 };
63 int h_present, p_present, s_present, n_args, i;
64 char *app_name = argv[0];
65 int opt, option_index;
66
67 /* Skip EAL input args */
68 n_args = argc;
69 for (i = 0; i < n_args; i++)
70 if (strcmp(argv[i], "--") == 0) {
71 argc -= i;
72 argv += i;
73 break;
74 }
75
76 if (i == n_args)
77 return 0;
78
79 /* Parse args */
80 h_present = 0;
81 p_present = 0;
82 s_present = 0;
83
84 while ((opt = getopt_long(argc, argv, "h:p:s:", lgopts, &option_index)) != EOF) {
85 switch (opt) {
86 case 'h':
87 if (h_present) {
88 printf("Error: Multiple -h arguments\n");
89 return -1;
90 }
91 h_present = 1;
92
93 if (!strlen(optarg)) {
94 printf("Error: Argument for -h not provided\n");
95 return -1;
96 }
97
98 app.conn.addr = strdup(optarg);
99 if (app.conn.addr == NULL) {
100 printf("Error: Not enough memory\n");
101 return -1;
102 }
103 break;
104
105 case 'p':
106 if (p_present) {
107 printf("Error: Multiple -p arguments\n");
108 return -1;
109 }
110 p_present = 1;
111
112 if (!strlen(optarg)) {
113 printf("Error: Argument for -p not provided\n");

Callers 1

mainFunction · 0.85

Calls 5

strcmpFunction · 0.85
getopt_longFunction · 0.85
strdupFunction · 0.85
strtoulFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected