src/bin/psql/command.c
backslashResult
HandleSlashCmds(PsqlScanState scan_state,
				ConditionalStack cstack,
				PQExpBuffer query_buf,
				PQExpBuffer previous_buf)
{
	backslashResult status;
	char	   *cmd;
	char	   *arg;

	Assert(scan_state != NULL);
	Assert(cstack != NULL);

	/* Parse off the command name */
	cmd = psql_scan_slash_command(scan_state);

	/* And try to execute it */
	status = exec_command(cmd, scan_state, cstack, query_buf, previous_buf);

	if (status == PSQL_CMD_UNKNOWN)
	{
		pg_log_error("invalid command \\%s", cmd);
		if (pset.cur_cmd_interactive)
			pg_log_info("Try \\? for help.");
		status = PSQL_CMD_ERROR;
	}

	if (status != PSQL_CMD_ERROR)
	{
		/*
		 * Eat any remaining arguments after a valid command.  We want to
		 * suppress evaluation of backticks in this situation, so transiently
		 * push an inactive conditional-stack entry.
		 */
		bool		active_branch = conditional_active(cstack);

		conditional_stack_push(cstack, IFSTATE_IGNORED);
		while ((arg = psql_scan_slash_option(scan_state,
											 OT_NORMAL, NULL, false)))
		{
			if (active_branch)
				pg_log_warning("\\%s: extra argument \"%s\" ignored", cmd, arg);
			free(arg);
		}
		conditional_stack_pop(cstack);
	}
	else
	{
		/* silently throw away rest of line after an erroneous command */
		while ((arg = psql_scan_slash_option(scan_state,
											 OT_WHOLE_LINE, NULL, false)))
			free(arg);
	}

	/* if there is a trailing \\, swallow it */
	psql_scan_slash_command_end(scan_state);

	free(cmd);

	/* some commands write to queryFout, so make sure output is sent */
	fflush(pset.queryFout);

	return status;
}
/*----------
 * HandleSlashCmds:
 *
 * Handles all the different commands that start with '\'.
 * Ordinarily called by MainLoop().
 *
 * scan_state is a lexer working state that is set to continue scanning
 * just after the '\'.  The lexer is advanced past the command and all
 * arguments on return.
 *
 * cstack is the current \if stack state.  This will be examined, and
 * possibly modified by conditional commands.
 *
 * query_buf contains the query-so-far, which may be modified by
 * execution of the backslash command (for example, \r clears it).
 *
 * previous_buf contains the query most recently sent to the server
 * (empty if none yet).  This should not be modified here, but some
 * commands copy its content into query_buf.
 *
 * query_buf and previous_buf will be NULL when executing a "-c"
 * command-line option.
 *
 * Returns a status code indicating what action is desired, see command.h.
 *----------
 */
Handles all the different commands that start with '\'.
Ordinarily called by MainLoop().

scan_state is a lexer working state that is set to continue scanning
just after the '\'.  The lexer is advanced past the command and all
arguments on return.

cstack is the current \if stack state.  This will be examined, and
possibly modified by conditional commands.

query_buf contains the query-so-far, which may be modified by
execution of the backslash command (for example, \r clears it).

previous_buf contains the query most recently sent to the server
(empty if none yet).  This should not be modified here, but some
commands copy its content into query_buf.

query_buf and previous_buf will be NULL when executing a "-c"
command-line option.

Returns a status code indicating what action is desired, see command.h.
Handles all the different commands that start with ' \ ' . Ordinarily called by MainLoop () . scan_state is a lexer working state that is set to continue scanning just after the ' \ ' . The lexer is advanced past the command and all arguments on return . cstack is the current \ if stack state . This will be examined and possibly modified by conditional commands . query_buf contains the query - so - far which may be modified by execution of the backslash command ( for example \ r clears it ) . previous_buf contains the query most recently sent to the server ( empty if none yet ) . This should not be modified here but some commands copy its content into query_buf . query_buf and previous_buf will be NULL when executing a " - c " command - line option . Returns a status code indicating what action is desired see command . h .
backslashResult
HandleSlashCmds(PsqlScanState scan_state,
				ConditionalStack cstack,
				PQExpBuffer query_buf,
				PQExpBuffer previous_buf)
{
	backslashResult status;
	char	   *cmd;
	char	   *arg;
	Assert(scan_state != NULL);
	Assert(cstack != NULL);
	cmd = psql_scan_slash_command(scan_state);
	status = exec_command(cmd, scan_state, cstack, query_buf, previous_buf);
	if (status == PSQL_CMD_UNKNOWN)
	{
		pg_log_error("invalid command \\%s", cmd);
		if (pset.cur_cmd_interactive)
			pg_log_info("Try \\? for help.");
		status = PSQL_CMD_ERROR;
	}
	if (status != PSQL_CMD_ERROR)
	{
		bool		active_branch = conditional_active(cstack);
		conditional_stack_push(cstack, IFSTATE_IGNORED);
		while ((arg = psql_scan_slash_option(scan_state,
											 OT_NORMAL, NULL, false)))
		{
			if (active_branch)
				pg_log_warning("\\%s: extra argument \"%s\" ignored", cmd, arg);
			free(arg);
		}
		conditional_stack_pop(cstack);
	}
	else
	{
		while ((arg = psql_scan_slash_option(scan_state,
											 OT_WHOLE_LINE, NULL, false)))
			free(arg);
	}
	psql_scan_slash_command_end(scan_state);
	free(cmd);
	fflush(pset.queryFout);
	return status;
}
backslashResult HandleSlashCmds ( PsqlScanState scan_state , ConditionalStack cstack , PQExpBuffer query_buf , PQExpBuffer previous_buf ) { backslashResult status ; char * cmd ; char * arg ; Assert ( scan_state != NULL ) ; Assert ( cstack != NULL ) ; cmd = psql_scan_slash_command ( scan_state ) ; status = exec_command ( cmd , scan_state , cstack , query_buf , previous_buf ) ; if ( status == PSQL_CMD_UNKNOWN ) { pg_log_error ( " \\ " , cmd ) ; if ( pset . cur_cmd_interactive ) pg_log_info ( " \\ " ) ; status = PSQL_CMD_ERROR ; } if ( status != PSQL_CMD_ERROR ) { bool active_branch = conditional_active ( cstack ) ; conditional_stack_push ( cstack , IFSTATE_IGNORED ) ; while ( ( arg = psql_scan_slash_option ( scan_state , OT_NORMAL , NULL , false ) ) ) { if ( active_branch ) pg_log_warning ( " \\ \" \" " , cmd , arg ) ; free ( arg ) ; } conditional_stack_pop ( cstack ) ; } else { while ( ( arg = psql_scan_slash_option ( scan_state , OT_WHOLE_LINE , NULL , false ) ) ) free ( arg ) ; } psql_scan_slash_command_end ( scan_state ) ; free ( cmd ) ; fflush ( pset . queryFout ) ; return status ; }
HandleSlashCmds:
 Handles all the different commands that start with '\'.
HandleSlashCmds : Handles all the different commands that start with ' \ ' .
/* Parse off the command name */ /* And try to execute it */ /*
		 * Eat any remaining arguments after a valid command.  We want to
		 * suppress evaluation of backticks in this situation, so transiently
		 * push an inactive conditional-stack entry.
		 */ /* silently throw away rest of line after an erroneous command */ /* if there is a trailing \\, swallow it */ /* some commands write to queryFout, so make sure output is sent */