| 592 | } |
| 593 | |
| 594 | static void LeCaR_parse_params(cache_t *cache, |
| 595 | const char *cache_specific_params) { |
| 596 | LeCaR_params_t *params = (LeCaR_params_t *)cache->eviction_params; |
| 597 | char *params_str = strdup(cache_specific_params); |
| 598 | char *old_params_str = params_str; |
| 599 | char *end; |
| 600 | |
| 601 | while (params_str != NULL && params_str[0] != '\0') { |
| 602 | /* different parameters are separated by comma, |
| 603 | * key and value are separated by = */ |
| 604 | char *key = strsep((char **)¶ms_str, "="); |
| 605 | char *value = strsep((char **)¶ms_str, ","); |
| 606 | |
| 607 | // skip the white space |
| 608 | while (params_str != NULL && *params_str == ' ') { |
| 609 | params_str++; |
| 610 | } |
| 611 | |
| 612 | if (strcasecmp(key, "update-weight") == 0) { |
| 613 | if ((int)strtol(value, &end, 0) == 1) |
| 614 | params->update_weight = true; |
| 615 | else |
| 616 | params->update_weight = false; |
| 617 | if (strlen(end) > 2) { |
| 618 | ERROR("param parsing error, find string \"%s\" after number\n", end); |
| 619 | } |
| 620 | } else if (strcasecmp(key, "lru-weight") == 0) { |
| 621 | params->w_lru = (double)strtod(value, &end); |
| 622 | } else if (strcasecmp(key, "print") == 0) { |
| 623 | printf("current parameters: %s\n", LeCaR_current_params(cache, params)); |
| 624 | exit(0); |
| 625 | } else { |
| 626 | ERROR("%s does not have parameter %s\n", cache->cache_name, key); |
| 627 | exit(1); |
| 628 | } |
| 629 | } |
| 630 | free(old_params_str); |
| 631 | } |
| 632 | |
| 633 | // *********************************************************************** |
| 634 | // **** **** |
no test coverage detected