X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fvm_power_manager%2Fparse.c;h=8a8dcf05fec107905edd9b38a200b07631e9d2cc;hb=95f648ff9eedc11f9c888f2cc331aadb95cb9b47;hp=8231533b6029157407fcb4c96e1991a33ad8ca93;hpb=8831678b51c791cc7332cf49a37f98e1167673fc;p=dpdk.git diff --git a/examples/vm_power_manager/parse.c b/examples/vm_power_manager/parse.c index 8231533b60..8a8dcf05fe 100644 --- a/examples/vm_power_manager/parse.c +++ b/examples/vm_power_manager/parse.c @@ -60,7 +60,7 @@ parse_set(const char *input, uint16_t set[], unsigned int num) min = idx; else /* avoid continuous '-' */ return -1; - } else if ((*end == ',') || (*end == '\0')) { + } else if ((*end == ',') || (*end == ':') || (*end == '\0')) { max = idx; if (min == num) @@ -75,7 +75,45 @@ parse_set(const char *input, uint16_t set[], unsigned int num) return -1; str = end + 1; - } while (*end != '\0'); + } while ((*end != '\0') && (*end != ':')); + + return str - input; +} + +int +parse_branch_ratio(const char *input, float *branch_ratio) +{ + const char *str = input; + char *end = NULL; + + while (isblank(*str)) + str++; + + if (*str == '\0') + return -1; + + /* Go straight to the ':' separator if present */ + while ((*str != '\0') && (*str != ':')) + str++; + + /* Branch ratio not specified in args so leave it at default setting */ + if (*str == '\0') + return 0; + + /* Confirm ':' separator present */ + if (*str != ':') + return -1; + + str++; + errno = 0; + *branch_ratio = strtof(str, &end); + if (errno || end == NULL) + return -1; + + if (*end != '\0') + return -1; + + str = end + 1; return str - input; }