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

Function parse_args

dpdk/examples/pipeline/main.c:41–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39};
40
41static int
42parse_args(int argc, char **argv)
43{
44 char *app_name = argv[0];
45 struct option lgopts[] = {
46 { NULL, 0, 0, 0 }
47 };
48 int opt, option_index;
49 int h_present, p_present, s_present, n_args, i;
50
51 /* Skip EAL input args */
52 n_args = argc;
53 for (i = 0; i < n_args; i++)
54 if (strcmp(argv[i], "--") == 0) {
55 argc -= i;
56 argv += i;
57 break;
58 }
59
60 if (i == n_args)
61 return 0;
62
63 /* Parse args */
64 h_present = 0;
65 p_present = 0;
66 s_present = 0;
67
68 while ((opt = getopt_long(argc, argv, "h:p:s:", lgopts, &option_index))
69 != EOF)
70 switch (opt) {
71 case 'h':
72 if (h_present) {
73 printf("Error: Multiple -h arguments\n");
74 return -1;
75 }
76 h_present = 1;
77
78 if (!strlen(optarg)) {
79 printf("Error: Argument for -h not provided\n");
80 return -1;
81 }
82
83 app.conn.addr = strdup(optarg);
84 if (app.conn.addr == NULL) {
85 printf("Error: Not enough memory\n");
86 return -1;
87 }
88 break;
89
90 case 'p':
91 if (p_present) {
92 printf("Error: Multiple -p arguments\n");
93 return -1;
94 }
95 p_present = 1;
96
97 if (!strlen(optarg)) {
98 printf("Error: Argument for -p not provided\n");

Callers 1

mainFunction · 0.70

Calls 4

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

Tested by

no test coverage detected