Try to convert variable to a value; return false on failure */
| 1492 | |
| 1493 | /* Try to convert variable to a value; return false on failure */ |
| 1494 | static bool |
| 1495 | makeVariableValue(Variable *var) |
| 1496 | { |
| 1497 | size_t slen; |
| 1498 | |
| 1499 | if (var->value.type != PGBT_NO_VALUE) |
| 1500 | return true; /* no work */ |
| 1501 | |
| 1502 | slen = strlen(var->svalue); |
| 1503 | |
| 1504 | if (slen == 0) |
| 1505 | /* what should it do on ""? */ |
| 1506 | return false; |
| 1507 | |
| 1508 | if (pg_strcasecmp(var->svalue, "null") == 0) |
| 1509 | { |
| 1510 | setNullValue(&var->value); |
| 1511 | } |
| 1512 | |
| 1513 | /* |
| 1514 | * accept prefixes such as y, ye, n, no... but not for "o". 0/1 are |
| 1515 | * recognized later as an int, which is converted to bool if needed. |
| 1516 | */ |
| 1517 | else if (pg_strncasecmp(var->svalue, "true", slen) == 0 || |
| 1518 | pg_strncasecmp(var->svalue, "yes", slen) == 0 || |
| 1519 | pg_strcasecmp(var->svalue, "on") == 0) |
| 1520 | { |
| 1521 | setBoolValue(&var->value, true); |
| 1522 | } |
| 1523 | else if (pg_strncasecmp(var->svalue, "false", slen) == 0 || |
| 1524 | pg_strncasecmp(var->svalue, "no", slen) == 0 || |
| 1525 | pg_strcasecmp(var->svalue, "off") == 0 || |
| 1526 | pg_strcasecmp(var->svalue, "of") == 0) |
| 1527 | { |
| 1528 | setBoolValue(&var->value, false); |
| 1529 | } |
| 1530 | else if (is_an_int(var->svalue)) |
| 1531 | { |
| 1532 | /* if it looks like an int, it must be an int without overflow */ |
| 1533 | int64 iv; |
| 1534 | |
| 1535 | if (!strtoint64(var->svalue, false, &iv)) |
| 1536 | return false; |
| 1537 | |
| 1538 | setIntValue(&var->value, iv); |
| 1539 | } |
| 1540 | else /* type should be double */ |
| 1541 | { |
| 1542 | double dv; |
| 1543 | |
| 1544 | if (!strtodouble(var->svalue, true, &dv)) |
| 1545 | { |
| 1546 | pg_log_error("malformed variable \"%s\" value: \"%s\"", |
| 1547 | var->name, var->svalue); |
| 1548 | return false; |
| 1549 | } |
| 1550 | setDoubleValue(&var->value, dv); |
| 1551 | } |
no test coverage detected