Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "Corey Huinker" <corey(dot)huinker(at)gmail(dot)com>
Cc: "Fabien COELHO" <coelho(at)cri(dot)ensmp(dot)fr>,"Erik Rijkers" <er(at)xs4all(dot)nl>,"Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>,"Jim Nasby" <Jim(dot)Nasby(at)bluetreble(dot)com>,"PostgreSQL" <pgsql-hackers(at)postgresql(dot)org>,pgsql-hackers-owner(at)postgresql(dot)org
Subject: Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
Date: 2017-02-04 11:37:24
Message-ID: ac097a44-f9f4-4e80-ba6b-996f0e42c8d8@manitou-mail.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Corey Huinker wrote:

[about Ctrl-C]

> That does seem to be the consensus desired behavior. I'm just not sure
> where to handle that. The var "cancel_pressed" shows up in a lot of places.
> Advice?

Probably you don't need to care about cancel_pressed, and
the /if stack could be unwound at the point the SIGINT
handler longjumps to, in mainloop.c:

/* got here with longjmp */

/* reset parsing state */
psql_scan_finish(scan_state);
psql_scan_reset(scan_state);
resetPQExpBuffer(query_buf);
resetPQExpBuffer(history_buf);
count_eof = 0;
slashCmdStatus = PSQL_CMD_UNKNOWN;
prompt_status = PROMPT_READY;
pset.stmt_lineno = 1;
cancel_pressed = false;

The check I was suggesting on whether Ctrl+C has been pressed
on an empty line seems harder to implement, because get_interactive()
just calls readline() or fgets(), which block to return when a whole
line is ready. AFAICS psql can't know what was the edit-in-progress
when these functions are interrupted by a signal instead of
returning normally.
But I don't think this check is essential, it could be left to another patch.

Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2017-02-04 12:01:32 Re: Provide list of subscriptions and publications in psql's completion
Previous Message Tomasz Ostrowski 2017-02-04 10:49:32 pg_restore foreign keys NOT VALID, or [assume] VALID; VALIDATE CONSTRAINT CONCURRENTLY