Reset parenthesis level counter upon \r.
authorPeter Eisentraut <peter_e@gmx.net>
Wed, 27 Mar 2002 19:16:13 +0000 (19:16 +0000)
committerPeter Eisentraut <peter_e@gmx.net>
Wed, 27 Mar 2002 19:16:13 +0000 (19:16 +0000)
src/bin/psql/command.c
src/bin/psql/command.h
src/bin/psql/mainloop.c
src/bin/psql/startup.c

index 97f58dc3f616ebd020653b47c3d61b794b32b9f4..a0d4a5ca1a4f41b5c15396f20eb1fbceb2a5da78 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.70 2002/03/19 02:32:21 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.71 2002/03/27 19:16:13 petere Exp $
  */
 #include "postgres_fe.h"
 #include "command.h"
@@ -52,7 +52,8 @@
 static backslashResult exec_command(const char *cmd,
                         const char *options_string,
                         const char **continue_parse,
-                        PQExpBuffer query_buf);
+                        PQExpBuffer query_buf,
+                        volatile int *paren_level);
 
 /* different ways for scan_option to handle parameter words */
 enum option_type
@@ -94,7 +95,8 @@ static bool do_shell(const char *command);
 backslashResult
 HandleSlashCmds(const char *line,
                                PQExpBuffer query_buf,
-                               const char **end_of_cmd)
+                               const char **end_of_cmd,
+                               volatile int *paren_level)
 {
        backslashResult status = CMD_SKIP_LINE;
        char       *my_line;
@@ -132,7 +134,7 @@ HandleSlashCmds(const char *line,
                my_line[blank_loc] = '\0';
        }
 
-       status = exec_command(my_line, options_string, &continue_parse, query_buf);
+       status = exec_command(my_line, options_string, &continue_parse, query_buf, paren_level);
 
        if (status == CMD_UNKNOWN)
        {
@@ -147,7 +149,7 @@ HandleSlashCmds(const char *line,
                new_cmd[1] = '\0';
 
                /* use line for options, because my_line was clobbered above */
-               status = exec_command(new_cmd, line + 1, &continue_parse, query_buf);
+               status = exec_command(new_cmd, line + 1, &continue_parse, query_buf, paren_level);
 
                /*
                 * continue_parse must be relative to my_line for calculation
@@ -192,7 +194,8 @@ static backslashResult
 exec_command(const char *cmd,
                         const char *options_string,
                         const char **continue_parse,
-                        PQExpBuffer query_buf)
+                        PQExpBuffer query_buf,
+                        volatile int *paren_level)
 {
        bool            success = true; /* indicate here if the command ran ok or
                                                                 * failed */
@@ -636,6 +639,8 @@ exec_command(const char *cmd,
        else if (strcmp(cmd, "r") == 0 || strcmp(cmd, "reset") == 0)
        {
                resetPQExpBuffer(query_buf);
+               if (paren_level)
+                       *paren_level = 0;
                if (!quiet)
                        puts(gettext("Query buffer reset (cleared)."));
        }
index b026cf4f8a50f5539d9ddf3eff8674b670d72105..f74be3a851094d885bffc0bcc4354f4a2d7cbb3c 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/command.h,v 1.13 2001/11/05 17:46:30 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/command.h,v 1.14 2002/03/27 19:16:13 petere Exp $
  */
 #ifndef COMMAND_H
 #define COMMAND_H
@@ -28,7 +28,8 @@ typedef enum _backslashResult
 
 backslashResult HandleSlashCmds(const char *line,
                                PQExpBuffer query_buf,
-                               const char **end_of_cmd);
+                               const char **end_of_cmd,
+                               volatile int *paren_level);
 
 int
                        process_file(char *filename);
index 954b5752741a0b9579fb3e128159711c44ce7707..06ca83a7fe19e58f7e0d1c0c5280f0ae15ad47bc 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.46 2002/02/18 05:57:41 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.47 2002/03/27 19:16:13 petere Exp $
  */
 #include "postgres_fe.h"
 #include "mainloop.h"
@@ -465,7 +465,8 @@ MainLoop(FILE *source)
                                /* handle backslash command */
                                slashCmdStatus = HandleSlashCmds(&line[i],
                                                   query_buf->len > 0 ? query_buf : previous_buf,
-                                                                                                &end_of_cmd);
+                                                                                                &end_of_cmd,
+                                                                                                &paren_level);
 
                                success = slashCmdStatus != CMD_ERROR;
 
index 9e4185de3be51fe93c4450d7239ed53333a49db2..3a7b7a0f93661a1a12f07a3d3f24e57c5dc54e5e 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.54 2001/11/05 17:46:31 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.55 2002/03/27 19:16:13 petere Exp $
  */
 #include "postgres_fe.h"
 
@@ -256,7 +256,7 @@ main(int argc, char *argv[])
 
                if ((value = GetVariable(pset.vars, "ECHO")) && strcmp(value, "all") == 0)
                        puts(options.action_string);
-               successResult = HandleSlashCmds(options.action_string, NULL, NULL) != CMD_ERROR
+               successResult = HandleSlashCmds(options.action_string, NULL, NULL, NULL) != CMD_ERROR
                        ? EXIT_SUCCESS : EXIT_FAILURE;
        }