| 207 | */ |
| 208 | |
| 209 | backslashResult |
| 210 | HandleSlashCmds(PsqlScanState scan_state, |
| 211 | ConditionalStack cstack, |
| 212 | PQExpBuffer query_buf, |
| 213 | PQExpBuffer previous_buf) |
| 214 | { |
| 215 | backslashResult status; |
| 216 | char *cmd; |
| 217 | char *arg; |
| 218 | |
| 219 | Assert(scan_state != NULL); |
| 220 | Assert(cstack != NULL); |
| 221 | |
| 222 | /* Parse off the command name */ |
| 223 | cmd = psql_scan_slash_command(scan_state); |
| 224 | |
| 225 | /* And try to execute it */ |
| 226 | status = exec_command(cmd, scan_state, cstack, query_buf, previous_buf); |
| 227 | |
| 228 | if (status == PSQL_CMD_UNKNOWN) |
| 229 | { |
| 230 | pg_log_error("invalid command \\%s", cmd); |
| 231 | if (pset.cur_cmd_interactive) |
| 232 | pg_log_info("Try \\? for help."); |
| 233 | status = PSQL_CMD_ERROR; |
| 234 | } |
| 235 | |
| 236 | if (status != PSQL_CMD_ERROR) |
| 237 | { |
| 238 | /* |
| 239 | * Eat any remaining arguments after a valid command. We want to |
| 240 | * suppress evaluation of backticks in this situation, so transiently |
| 241 | * push an inactive conditional-stack entry. |
| 242 | */ |
| 243 | bool active_branch = conditional_active(cstack); |
| 244 | |
| 245 | conditional_stack_push(cstack, IFSTATE_IGNORED); |
| 246 | while ((arg = psql_scan_slash_option(scan_state, |
| 247 | OT_NORMAL, NULL, false))) |
| 248 | { |
| 249 | if (active_branch) |
| 250 | pg_log_warning("\\%s: extra argument \"%s\" ignored", cmd, arg); |
| 251 | free(arg); |
| 252 | } |
| 253 | conditional_stack_pop(cstack); |
| 254 | } |
| 255 | else |
| 256 | { |
| 257 | /* silently throw away rest of line after an erroneous command */ |
| 258 | while ((arg = psql_scan_slash_option(scan_state, |
| 259 | OT_WHOLE_LINE, NULL, false))) |
| 260 | free(arg); |
| 261 | } |
| 262 | |
| 263 | /* if there is a trailing \\, swallow it */ |
| 264 | psql_scan_slash_command_end(scan_state); |
| 265 | |
| 266 | free(cmd); |
no test coverage detected