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

Function parse_args

dpdk/examples/vm_power_manager/guest_cli/main.c:36–175  ·  view source on GitHub ↗

Parse the argument given in the command line of the application */

Source from the content-addressed store, hash-verified

34
35/* Parse the argument given in the command line of the application */
36static int
37parse_args(int argc, char **argv)
38{
39 int opt, ret;
40 char **argvopt;
41 int option_index;
42 char *prgname = argv[0];
43 const struct option lgopts[] = {
44 { "vm-name", required_argument, 0, 'n'},
45 { "busy-hours", required_argument, 0, 'b'},
46 { "quiet-hours", required_argument, 0, 'q'},
47 { "port-list", required_argument, 0, 'p'},
48 { "vcpu-list", required_argument, 0, 'l'},
49 { "policy", required_argument, 0, 'o'},
50 {NULL, 0, 0, 0}
51 };
52 struct rte_power_channel_packet *policy;
53 unsigned short int hours[MAX_HOURS];
54 unsigned short int cores[RTE_POWER_MAX_VCPU_PER_VM];
55 unsigned short int ports[RTE_POWER_MAX_VCPU_PER_VM];
56 int i, cnt, idx;
57
58 policy = get_policy();
59 ret = set_policy_defaults(policy);
60 if (ret != 0) {
61 printf("Failed to set policy defaults\n");
62 return -1;
63 }
64
65 argvopt = argv;
66
67 while ((opt = getopt_long(argc, argvopt, "n:b:q:p:",
68 lgopts, &option_index)) != EOF) {
69
70 switch (opt) {
71 /* portmask */
72 case 'n':
73 strlcpy(policy->vm_name, optarg,
74 RTE_POWER_VM_MAX_NAME_SZ);
75 printf("Setting VM Name to [%s]\n", policy->vm_name);
76 break;
77 case 'b':
78 case 'q':
79 //printf("***Processing set using [%s]\n", optarg);
80 cnt = parse_set(optarg, hours, MAX_HOURS);
81 if (cnt < 0) {
82 printf("Invalid value passed to quiet/busy hours - [%s]\n",
83 optarg);
84 break;
85 }
86 idx = 0;
87 for (i = 0; i < MAX_HOURS; i++) {
88 if (hours[i]) {
89 if (opt == 'b') {
90 printf("***Busy Hour %d\n", i);
91 policy->timer_policy.busy_hours
92 [idx++] = i;
93 } else {

Callers 1

mainFunction · 0.70

Calls 8

get_policyFunction · 0.85
set_policy_defaultsFunction · 0.85
getopt_longFunction · 0.85
strcmpFunction · 0.85
parse_setFunction · 0.70
set_policy_macFunction · 0.70
printfFunction · 0.50
strlcpyFunction · 0.50

Tested by

no test coverage detected