* \prompt -- prompt and set variable */
| 2096 | * \prompt -- prompt and set variable |
| 2097 | */ |
| 2098 | static backslashResult |
| 2099 | exec_command_prompt(PsqlScanState scan_state, bool active_branch, |
| 2100 | const char *cmd) |
| 2101 | { |
| 2102 | bool success = true; |
| 2103 | |
| 2104 | if (active_branch) |
| 2105 | { |
| 2106 | char *opt, |
| 2107 | *prompt_text = NULL; |
| 2108 | char *arg1, |
| 2109 | *arg2; |
| 2110 | |
| 2111 | arg1 = psql_scan_slash_option(scan_state, OT_NORMAL, NULL, false); |
| 2112 | arg2 = psql_scan_slash_option(scan_state, OT_NORMAL, NULL, false); |
| 2113 | |
| 2114 | if (!arg1) |
| 2115 | { |
| 2116 | pg_log_error("\\%s: missing required argument", cmd); |
| 2117 | success = false; |
| 2118 | } |
| 2119 | else |
| 2120 | { |
| 2121 | char *result; |
| 2122 | |
| 2123 | if (arg2) |
| 2124 | { |
| 2125 | prompt_text = arg1; |
| 2126 | opt = arg2; |
| 2127 | } |
| 2128 | else |
| 2129 | opt = arg1; |
| 2130 | |
| 2131 | if (!pset.inputfile) |
| 2132 | { |
| 2133 | result = simple_prompt(prompt_text, true); |
| 2134 | } |
| 2135 | else |
| 2136 | { |
| 2137 | if (prompt_text) |
| 2138 | { |
| 2139 | fputs(prompt_text, stdout); |
| 2140 | fflush(stdout); |
| 2141 | } |
| 2142 | result = gets_fromFile(stdin); |
| 2143 | if (!result) |
| 2144 | { |
| 2145 | pg_log_error("\\%s: could not read value for variable", |
| 2146 | cmd); |
| 2147 | success = false; |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | if (result && |
| 2152 | !SetVariable(pset.vars, opt, result)) |
| 2153 | success = false; |
| 2154 | |
| 2155 | if (result) |
no test coverage detected