src/bin/psql/command.c
static backslashResult
process_command_g_options(char *first_option, PsqlScanState scan_state,
						  bool active_branch, const char *cmd)
{
	bool		success = true;
	bool		found_r_paren = false;

	do
	{
		char	   *option;
		size_t		optlen;

		/* If not first time through, collect a new option */
		if (first_option)
			option = first_option;
		else
		{
			option = psql_scan_slash_option(scan_state,
											OT_NORMAL, NULL, false);
			if (!option)
			{
				if (active_branch)
				{
					pg_log_error("\\%s: missing right parenthesis", cmd);
					success = false;
				}
				break;
			}
		}

		/* Check for terminating right paren, and remove it from string */
		optlen = strlen(option);
		if (optlen > 0 && option[optlen - 1] == ')')
		{
			option[--optlen] = '\0';
			found_r_paren = true;
		}

		/* If there was anything besides parentheses, parse/execute it */
		if (optlen > 0)
		{
			/* We can have either "name" or "name=value" */
			char	   *valptr = strchr(option, '=');

			if (valptr)
				*valptr++ = '\0';
			if (active_branch)
			{
				/* save settings if not done already, then apply option */
				if (pset.gsavepopt == NULL)
					pset.gsavepopt = savePsetInfo(&pset.popt);
				success &= do_pset(option, valptr, &pset.popt, true);
			}
		}

		/* Clean up after this option.  We should not free first_option. */
		if (first_option)
			first_option = NULL;
		else
			free(option);
	} while (!found_r_paren);

	/* If we failed after already changing some options, undo side-effects */
	if (!success && active_branch && pset.gsavepopt)
	{
		restorePsetInfo(&pset.popt, pset.gsavepopt);
		pset.gsavepopt = NULL;
	}

	return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR;
}
/*
 * Process parenthesized pset options for \g
 *
 * Note: okay to modify first_option, but not to free it; caller does that
 */
Process parenthesized pset options for \g
Note: okay to modify first_option, but not to free it; caller does that
Process parenthesized pset options for \ g Note : okay to modify first_option but not to free it ; caller does that
static backslashResult
process_command_g_options(char *first_option, PsqlScanState scan_state,
						  bool active_branch, const char *cmd)
{
	bool		success = true;
	bool		found_r_paren = false;
	do
	{
		char	   *option;
		size_t		optlen;
		if (first_option)
			option = first_option;
		else
		{
			option = psql_scan_slash_option(scan_state,
											OT_NORMAL, NULL, false);
			if (!option)
			{
				if (active_branch)
				{
					pg_log_error("\\%s: missing right parenthesis", cmd);
					success = false;
				}
				break;
			}
		}
		optlen = strlen(option);
		if (optlen > 0 && option[optlen - 1] == ')')
		{
			option[--optlen] = '\0';
			found_r_paren = true;
		}
		if (optlen > 0)
		{
			char	   *valptr = strchr(option, '=');
			if (valptr)
				*valptr++ = '\0';
			if (active_branch)
			{
				if (pset.gsavepopt == NULL)
					pset.gsavepopt = savePsetInfo(&pset.popt);
				success &= do_pset(option, valptr, &pset.popt, true);
			}
		}
		if (first_option)
			first_option = NULL;
		else
			free(option);
	} while (!found_r_paren);
	if (!success && active_branch && pset.gsavepopt)
	{
		restorePsetInfo(&pset.popt, pset.gsavepopt);
		pset.gsavepopt = NULL;
	}
	return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR;
}
static backslashResult process_command_g_options ( char * first_option , PsqlScanState scan_state , bool active_branch , const char * cmd ) { bool success = true ; bool found_r_paren = false ; do { char * option ; size_t optlen ; if ( first_option ) option = first_option ; else { option = psql_scan_slash_option ( scan_state , OT_NORMAL , NULL , false ) ; if ( ! option ) { if ( active_branch ) { pg_log_error ( " \\ " , cmd ) ; success = false ; } break ; } } optlen = strlen ( option ) ; if ( optlen > 0 && option [ optlen - 1 ] == ' ' ) { option [ -- optlen ] = ' \0 ' ; found_r_paren = true ; } if ( optlen > 0 ) { char * valptr = strchr ( option , ' ' ) ; if ( valptr ) * valptr ++ = ' \0 ' ; if ( active_branch ) { if ( pset . gsavepopt == NULL ) pset . gsavepopt = savePsetInfo ( & pset . popt ) ; success &= do_pset ( option , valptr , & pset . popt , true ) ; } } if ( first_option ) first_option = NULL ; else free ( option ) ; } while ( ! found_r_paren ) ; if ( ! success && active_branch && pset . gsavepopt ) { restorePsetInfo ( & pset . popt , pset . gsavepopt ) ; pset . gsavepopt = NULL ; } return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR ; }
Process parenthesized pset options for \g
 Note: okay to modify first_option, but not to free it; caller does that
Process parenthesized pset options for \ g Note : okay to modify first_option but not to free it ; caller does that
/* If not first time through, collect a new option */ /* Check for terminating right paren, and remove it from string */ /* If there was anything besides parentheses, parse/execute it */ /* We can have either "name" or "name=value" */ /* save settings if not done already, then apply option */ /* Clean up after this option.  We should not free first_option. */ /* If we failed after already changing some options, undo side-effects */