src/bin/psql/command.c
static backslashResult
exec_command_watch(PsqlScanState scan_state, bool active_branch,
				   PQExpBuffer query_buf, PQExpBuffer previous_buf)
{
	bool		success = true;

	if (active_branch)
	{
		char	   *opt = psql_scan_slash_option(scan_state,
												 OT_NORMAL, NULL, true);
		double		sleep = 2;

		/* Convert optional sleep-length argument */
		if (opt)
		{
			sleep = strtod(opt, NULL);
			if (sleep <= 0)
				sleep = 1;
			free(opt);
		}

		/* If query_buf is empty, recall and execute previous query */
		(void) copy_previous_query(query_buf, previous_buf);

		success = do_watch(query_buf, sleep);

		/* Reset the query buffer as though for \r */
		resetPQExpBuffer(query_buf);
		psql_scan_reset(scan_state);
	}
	else
		ignore_slash_options(scan_state);

	return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR;
}
/*
 * \watch -- execute a query every N seconds
 */
\watch -- execute a query every N seconds
\ watch -- execute a query every N seconds
static backslashResult
exec_command_watch(PsqlScanState scan_state, bool active_branch,
				   PQExpBuffer query_buf, PQExpBuffer previous_buf)
{
	bool		success = true;
	if (active_branch)
	{
		char	   *opt = psql_scan_slash_option(scan_state,
												 OT_NORMAL, NULL, true);
		double		sleep = 2;
		if (opt)
		{
			sleep = strtod(opt, NULL);
			if (sleep <= 0)
				sleep = 1;
			free(opt);
		}
		(void) copy_previous_query(query_buf, previous_buf);
		success = do_watch(query_buf, sleep);
		resetPQExpBuffer(query_buf);
		psql_scan_reset(scan_state);
	}
	else
		ignore_slash_options(scan_state);
	return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR;
}
static backslashResult exec_command_watch ( PsqlScanState scan_state , bool active_branch , PQExpBuffer query_buf , PQExpBuffer previous_buf ) { bool success = true ; if ( active_branch ) { char * opt = psql_scan_slash_option ( scan_state , OT_NORMAL , NULL , true ) ; double sleep = 2 ; if ( opt ) { sleep = strtod ( opt , NULL ) ; if ( sleep <= 0 ) sleep = 1 ; free ( opt ) ; } ( void ) copy_previous_query ( query_buf , previous_buf ) ; success = do_watch ( query_buf , sleep ) ; resetPQExpBuffer ( query_buf ) ; psql_scan_reset ( scan_state ) ; } else ignore_slash_options ( scan_state ) ; return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR ; }
\watch -- execute a query every N seconds
\ watch -- execute a query every N seconds
/* Convert optional sleep-length argument */ /* If query_buf is empty, recall and execute previous query */ /* Reset the query buffer as though for \r */