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 a1ca03df5511acbbf797af9d8f38bece2e98047f..605ac1573acf15229ff30fc6530f70a5e3c9a21e 100644 (file)
@@ -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 eae48d7c256d90c79e4cd93b1b36fa8bd0540e10..f163a83fd2d0469ca05875bf4c8277790bbaf645 100644 (file)
@@ -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 1c2d4a8bb93f03cdac3073af2f7107c646024b70..a9d7e453ab649810051b155242303b4d2d65476c 100644 (file)
@@ -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 cef4f26a68955ab413f5558cc073b96bd3a13a4a..9aec5fdb3b8ef9d09e23950ba8aed9942b10f16e 100644 (file)
@@ -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;
        }