Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d235d9b

Browse files
committed
Reset parenthesis level counter upon \r.
1 parent 2442e79 commit d235d9b

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

src/bin/psql/command.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.70 2002/03/19 02:32:21 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.71 2002/03/27 19:16:13 petere Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -52,7 +52,8 @@
5252
static backslashResult exec_command(const char *cmd,
5353
const char *options_string,
5454
const char **continue_parse,
55-
PQExpBuffer query_buf);
55+
PQExpBuffer query_buf,
56+
volatile int *paren_level);
5657

5758
/* different ways for scan_option to handle parameter words */
5859
enum option_type
@@ -94,7 +95,8 @@ static bool do_shell(const char *command);
9495
backslashResult
9596
HandleSlashCmds(const char *line,
9697
PQExpBuffer query_buf,
97-
const char **end_of_cmd)
98+
const char **end_of_cmd,
99+
volatile int *paren_level)
98100
{
99101
backslashResult status = CMD_SKIP_LINE;
100102
char *my_line;
@@ -132,7 +134,7 @@ HandleSlashCmds(const char *line,
132134
my_line[blank_loc] = '\0';
133135
}
134136

135-
status = exec_command(my_line, options_string, &continue_parse, query_buf);
137+
status = exec_command(my_line, options_string, &continue_parse, query_buf, paren_level);
136138

137139
if (status == CMD_UNKNOWN)
138140
{
@@ -147,7 +149,7 @@ HandleSlashCmds(const char *line,
147149
new_cmd[1] = '\0';
148150

149151
/* use line for options, because my_line was clobbered above */
150-
status = exec_command(new_cmd, line + 1, &continue_parse, query_buf);
152+
status = exec_command(new_cmd, line + 1, &continue_parse, query_buf, paren_level);
151153

152154
/*
153155
* continue_parse must be relative to my_line for calculation
@@ -192,7 +194,8 @@ static backslashResult
192194
exec_command(const char *cmd,
193195
const char *options_string,
194196
const char **continue_parse,
195-
PQExpBuffer query_buf)
197+
PQExpBuffer query_buf,
198+
volatile int *paren_level)
196199
{
197200
bool success = true; /* indicate here if the command ran ok or
198201
* failed */
@@ -636,6 +639,8 @@ exec_command(const char *cmd,
636639
else if (strcmp(cmd, "r") == 0 || strcmp(cmd, "reset") == 0)
637640
{
638641
resetPQExpBuffer(query_buf);
642+
if (paren_level)
643+
*paren_level = 0;
639644
if (!quiet)
640645
puts(gettext("Query buffer reset (cleared)."));
641646
}

src/bin/psql/command.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/command.h,v 1.13 2001/11/05 17:46:30 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.h,v 1.14 2002/03/27 19:16:13 petere Exp $
77
*/
88
#ifndef COMMAND_H
99
#define COMMAND_H
@@ -28,7 +28,8 @@ typedef enum _backslashResult
2828

2929
backslashResult HandleSlashCmds(const char *line,
3030
PQExpBuffer query_buf,
31-
const char **end_of_cmd);
31+
const char **end_of_cmd,
32+
volatile int *paren_level);
3233

3334
int
3435
process_file(char *filename);

src/bin/psql/mainloop.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.46 2002/02/18 05:57:41 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.47 2002/03/27 19:16:13 petere Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "mainloop.h"
@@ -465,7 +465,8 @@ MainLoop(FILE *source)
465465
/* handle backslash command */
466466
slashCmdStatus = HandleSlashCmds(&line[i],
467467
query_buf->len > 0 ? query_buf : previous_buf,
468-
&end_of_cmd);
468+
&end_of_cmd,
469+
&paren_level);
469470

470471
success = slashCmdStatus != CMD_ERROR;
471472

src/bin/psql/startup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.54 2001/11/05 17:46:31 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.55 2002/03/27 19:16:13 petere Exp $
77
*/
88
#include "postgres_fe.h"
99

@@ -256,7 +256,7 @@ main(int argc, char *argv[])
256256

257257
if ((value = GetVariable(pset.vars, "ECHO")) && strcmp(value, "all") == 0)
258258
puts(options.action_string);
259-
successResult = HandleSlashCmds(options.action_string, NULL, NULL) != CMD_ERROR
259+
successResult = HandleSlashCmds(options.action_string, NULL, NULL, NULL) != CMD_ERROR
260260
? EXIT_SUCCESS : EXIT_FAILURE;
261261
}
262262

0 commit comments

Comments
 (0)