src/bin/psql/command.c
static backslashResult
exec_command_g(PsqlScanState scan_state, bool active_branch, const char *cmd)
{
	backslashResult status = PSQL_CMD_SKIP_LINE;
	char	   *fname;

	/*
	 * Because the option processing for this is fairly complicated, we do it
	 * and then decide whether the branch is active.
	 */
	fname = psql_scan_slash_option(scan_state,
								   OT_FILEPIPE, NULL, false);

	if (fname && fname[0] == '(')
	{
		/* Consume pset options through trailing ')' ... */
		status = process_command_g_options(fname + 1, scan_state,
										   active_branch, cmd);
		free(fname);
		/* ... and again attempt to scan the filename. */
		fname = psql_scan_slash_option(scan_state,
									   OT_FILEPIPE, NULL, false);
	}

	if (status == PSQL_CMD_SKIP_LINE && active_branch)
	{
		if (!fname)
			pset.gfname = NULL;
		else
		{
			expand_tilde(&fname);
			pset.gfname = pg_strdup(fname);
		}
		if (strcmp(cmd, "gx") == 0)
		{
			/* save settings if not done already, then force expanded=on */
			if (pset.gsavepopt == NULL)
				pset.gsavepopt = savePsetInfo(&pset.popt);
			pset.popt.topt.expanded = 1;
		}
		status = PSQL_CMD_SEND;
	}

	free(fname);

	return status;
}
/*
 * \g  [(pset-option[=pset-value] ...)] [filename/shell-command]
 * \gx [(pset-option[=pset-value] ...)] [filename/shell-command]
 *
 * Send the current query.  If pset options are specified, they are made
 * active just for this query.  If a filename or pipe command is given,
 * the query output goes there.  \gx implicitly sets "expanded=on" along
 * with any other pset options that are specified.
 */


Send the current query.  If pset options are specified, they are made
active just for this query.  If a filename or pipe command is given,
the query output goes there.  \gx implicitly sets "expanded=on" along
with any other pset options that are specified.
Send the current query . If pset options are specified they are made active just for this query . If a filename or pipe command is given the query output goes there . \ gx implicitly sets " expanded = on " along with any other pset options that are specified .
static backslashResult
exec_command_g(PsqlScanState scan_state, bool active_branch, const char *cmd)
{
	backslashResult status = PSQL_CMD_SKIP_LINE;
	char	   *fname;
	fname = psql_scan_slash_option(scan_state,
								   OT_FILEPIPE, NULL, false);
	if (fname && fname[0] == '(')
	{
		status = process_command_g_options(fname + 1, scan_state,
										   active_branch, cmd);
		free(fname);
		fname = psql_scan_slash_option(scan_state,
									   OT_FILEPIPE, NULL, false);
	}
	if (status == PSQL_CMD_SKIP_LINE && active_branch)
	{
		if (!fname)
			pset.gfname = NULL;
		else
		{
			expand_tilde(&fname);
			pset.gfname = pg_strdup(fname);
		}
		if (strcmp(cmd, "gx") == 0)
		{
			if (pset.gsavepopt == NULL)
				pset.gsavepopt = savePsetInfo(&pset.popt);
			pset.popt.topt.expanded = 1;
		}
		status = PSQL_CMD_SEND;
	}
	free(fname);
	return status;
}
static backslashResult exec_command_g ( PsqlScanState scan_state , bool active_branch , const char * cmd ) { backslashResult status = PSQL_CMD_SKIP_LINE ; char * fname ; fname = psql_scan_slash_option ( scan_state , OT_FILEPIPE , NULL , false ) ; if ( fname && fname [ 0 ] == ' ' ) { status = process_command_g_options ( fname + 1 , scan_state , active_branch , cmd ) ; free ( fname ) ; fname = psql_scan_slash_option ( scan_state , OT_FILEPIPE , NULL , false ) ; } if ( status == PSQL_CMD_SKIP_LINE && active_branch ) { if ( ! fname ) pset . gfname = NULL ; else { expand_tilde ( & fname ) ; pset . gfname = pg_strdup ( fname ) ; } if ( strcmp ( cmd , " " ) == 0 ) { if ( pset . gsavepopt == NULL ) pset . gsavepopt = savePsetInfo ( & pset . popt ) ; pset . popt . topt . expanded = 1 ; } status = PSQL_CMD_SEND ; } free ( fname ) ; return status ; }
\g  [(pset-option[=pset-value] ...)] [filename/shell-command]
 \gx [(pset-option[=pset-value] ...)] [filename/shell-command]
\ g [ ( pset - option [ = pset - value ] ... ) ] [ filename / shell - command ] \ gx [ ( pset - option [ = pset - value ] ... ) ] [ filename / shell - command ]
/*
	 * Because the option processing for this is fairly complicated, we do it
	 * and then decide whether the branch is active.
	 */ /* Consume pset options through trailing ')' ... */ /* ... and again attempt to scan the filename. */ /* save settings if not done already, then force expanded=on */