* Process parenthesized pset options for \g * * Note: okay to modify first_option, but not to free it; caller does that */
| 1408 | * Note: okay to modify first_option, but not to free it; caller does that |
| 1409 | */ |
| 1410 | static backslashResult |
| 1411 | process_command_g_options(char *first_option, PsqlScanState scan_state, |
| 1412 | bool active_branch, const char *cmd) |
| 1413 | { |
| 1414 | bool success = true; |
| 1415 | bool found_r_paren = false; |
| 1416 | |
| 1417 | do |
| 1418 | { |
| 1419 | char *option; |
| 1420 | size_t optlen; |
| 1421 | |
| 1422 | /* If not first time through, collect a new option */ |
| 1423 | if (first_option) |
| 1424 | option = first_option; |
| 1425 | else |
| 1426 | { |
| 1427 | option = psql_scan_slash_option(scan_state, |
| 1428 | OT_NORMAL, NULL, false); |
| 1429 | if (!option) |
| 1430 | { |
| 1431 | if (active_branch) |
| 1432 | { |
| 1433 | pg_log_error("\\%s: missing right parenthesis", cmd); |
| 1434 | success = false; |
| 1435 | } |
| 1436 | break; |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | /* Check for terminating right paren, and remove it from string */ |
| 1441 | optlen = strlen(option); |
| 1442 | if (optlen > 0 && option[optlen - 1] == ')') |
| 1443 | { |
| 1444 | option[--optlen] = '\0'; |
| 1445 | found_r_paren = true; |
| 1446 | } |
| 1447 | |
| 1448 | /* If there was anything besides parentheses, parse/execute it */ |
| 1449 | if (optlen > 0) |
| 1450 | { |
| 1451 | /* We can have either "name" or "name=value" */ |
| 1452 | char *valptr = strchr(option, '='); |
| 1453 | |
| 1454 | if (valptr) |
| 1455 | *valptr++ = '\0'; |
| 1456 | if (active_branch) |
| 1457 | { |
| 1458 | /* save settings if not done already, then apply option */ |
| 1459 | if (pset.gsavepopt == NULL) |
| 1460 | pset.gsavepopt = savePsetInfo(&pset.popt); |
| 1461 | success &= do_pset(option, valptr, &pset.popt, true); |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | /* Clean up after this option. We should not free first_option. */ |
| 1466 | if (first_option) |
| 1467 | first_option = NULL; |
no test coverage detected