diff options
Diffstat (limited to 'src/bin/psql')
-rw-r--r-- | src/bin/psql/Makefile.in | 3 | ||||
-rw-r--r-- | src/bin/psql/command.c | 47 | ||||
-rw-r--r-- | src/bin/psql/copy.c | 28 | ||||
-rw-r--r-- | src/bin/psql/mainloop.c | 8 |
4 files changed, 50 insertions, 36 deletions
diff --git a/src/bin/psql/Makefile.in b/src/bin/psql/Makefile.in index 6221d4cb89c..da8e2860963 100644 --- a/src/bin/psql/Makefile.in +++ b/src/bin/psql/Makefile.in @@ -7,7 +7,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/psql/Attic/Makefile.in,v 1.21 2000/03/08 01:58:22 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/psql/Attic/Makefile.in,v 1.22 2000/04/14 23:43:44 petere Exp $ # #------------------------------------------------------------------------- @@ -65,6 +65,7 @@ sql_help.h: $(wildcard $(SRCDIR)/../doc/src/sgml/ref/*.sgml) create_help.pl $(PERL) create_help.pl sql_help.h else sql_help.h: + @echo "*** Perl is needed to build psql help." endif .PHONY: submake diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index bc95e205065..ca4099d53eb 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.28 2000/04/12 17:16:22 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.29 2000/04/14 23:43:44 petere Exp $ */ #include "postgres.h" #include "command.h" @@ -51,7 +51,7 @@ static backslashResult exec_command(const char *cmd, enum option_type { - OT_NORMAL, OT_SQLID + OT_NORMAL, OT_SQLID, OT_FILEPIPE }; static char *scan_option(char **string, enum option_type type, char *quote); static char *unescape(const unsigned char *source, size_t len); @@ -105,7 +105,7 @@ HandleSlashCmds(const char *line, * * Also look for a backslash, so stuff like \p\g works. */ - blank_loc = strcspn(my_line, " \t\\"); + blank_loc = strcspn(my_line, " \t\n\r\\"); if (my_line[blank_loc] == '\\') { @@ -408,7 +408,7 @@ exec_command(const char *cmd, /* \g means send query */ else if (strcmp(cmd, "g") == 0) { - char *fname = scan_option(&string, OT_NORMAL, NULL); + char *fname = scan_option(&string, OT_FILEPIPE, NULL); if (!fname) pset.gfname = NULL; @@ -421,7 +421,7 @@ exec_command(const char *cmd, /* help */ else if (strcmp(cmd, "h") == 0 || strcmp(cmd, "help") == 0) { - helpSQL(options_string ? &options_string[strspn(options_string, " \t")] : NULL); + helpSQL(options_string ? &options_string[strspn(options_string, " \t\n\r")] : NULL); /* set pointer to end of line */ if (string) string += strlen(string); @@ -518,7 +518,7 @@ exec_command(const char *cmd, /* \o -- set query output */ else if (strcmp(cmd, "o") == 0 || strcmp(cmd, "out") == 0) { - char *fname = scan_option(&string, OT_NORMAL, NULL); + char *fname = scan_option(&string, OT_FILEPIPE, NULL); success = setQFout(fname); free(fname); @@ -676,7 +676,7 @@ exec_command(const char *cmd, } else { - fname = scan_option(&string, OT_NORMAL, NULL); + fname = scan_option(&string, OT_FILEPIPE, NULL); if (!fname) { @@ -806,7 +806,7 @@ scan_option(char **string, enum option_type type, char *quote) options_string = *string; /* skip leading whitespace */ - pos += strspn(options_string + pos, " \t"); + pos += strspn(options_string + pos, " \t\n\r"); switch (options_string[pos]) { @@ -845,17 +845,11 @@ scan_option(char **string, enum option_type type, char *quote) exit(EXIT_FAILURE); } - if (type == OT_NORMAL) - { - strncpy(return_val, &options_string[pos], jj - pos + 1); - return_val[jj - pos + 1] = '\0'; - } - /* * If this is expected to be an SQL identifier like option * then we strip out the double quotes */ - else if (type == OT_SQLID) + if (type == OT_SQLID) { unsigned int k, cc; @@ -877,6 +871,12 @@ scan_option(char **string, enum option_type type, char *quote) return_val[cc] = '\0'; } + else + { + strncpy(return_val, &options_string[pos], jj - pos + 1); + return_val[jj - pos + 1] = '\0'; + } + *string = options_string + jj + 1; if (quote) *quote = '"'; @@ -1010,7 +1010,7 @@ scan_option(char **string, enum option_type type, char *quote) const char *value; char save_char; - token_end = strcspn(&options_string[pos + 1], " \t"); + token_end = strcspn(&options_string[pos + 1], " \t\n\r"); save_char = options_string[pos + token_end + 1]; options_string[pos + token_end + 1] = '\0'; value = GetVariable(pset.vars, options_string + pos + 1); @@ -1031,6 +1031,19 @@ scan_option(char **string, enum option_type type, char *quote) break; /* + * | could be the beginning of a pipe + * if so, take rest of line as command + */ + case '|': + if (type == OT_FILEPIPE) + { + *string += strlen(options_string + pos); + return xstrdup(options_string + pos); + break; + } + /* fallthrough for other option types */ + + /* * A normal word */ default: @@ -1038,7 +1051,7 @@ scan_option(char **string, enum option_type type, char *quote) size_t token_end; char *cp; - token_end = strcspn(&options_string[pos], " \t"); + token_end = strcspn(&options_string[pos], " \t\n\r"); return_val = malloc(token_end + 1); if (!return_val) { diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 7e08a1d6b16..7b38d26a639 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.13 2000/04/12 17:16:22 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.14 2000/04/14 23:43:44 petere Exp $ */ #include "postgres.h" #include "copy.h" @@ -82,7 +82,7 @@ parse_slash_copy(const char *args) exit(EXIT_FAILURE); } - token = strtokx(line, " \t", "\"", '\\', "e, NULL, pset.encoding); + token = strtokx(line, " \t\n\r", "\"", '\\', "e, NULL, pset.encoding); if (!token) error = true; else @@ -92,7 +92,7 @@ parse_slash_copy(const char *args) if (!quote && strcasecmp(token, "binary") == 0) { result->binary = true; - token = strtokx(NULL, " \t", "\"", '\\', "e, NULL, pset.encoding); + token = strtokx(NULL, " \t\n\r", "\"", '\\', "e, NULL, pset.encoding); if (!token) error = true; } @@ -107,14 +107,14 @@ parse_slash_copy(const char *args) if (!error) { - token = strtokx(NULL, " \t", NULL, '\\', NULL, NULL, pset.encoding); + token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding); if (!token) error = true; else { if (strcasecmp(token, "with") == 0) { - token = strtokx(NULL, " \t", NULL, '\\', NULL, NULL, pset.encoding); + token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding); if (!token || strcasecmp(token, "oids") != 0) error = true; else @@ -122,7 +122,7 @@ parse_slash_copy(const char *args) if (!error) { - token = strtokx(NULL, " \t", NULL, '\\', NULL, NULL, pset.encoding); + token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding); if (!token) error = true; } @@ -139,7 +139,7 @@ parse_slash_copy(const char *args) if (!error) { - token = strtokx(NULL, " \t", "'", '\\', "e, NULL, pset.encoding); + token = strtokx(NULL, " \t\n\r", "'", '\\', "e, NULL, pset.encoding); if (!token) error = true; else if (!quote && (strcasecmp(token, "stdin") == 0 || strcasecmp(token, "stdout") == 0)) @@ -150,21 +150,21 @@ parse_slash_copy(const char *args) if (!error) { - token = strtokx(NULL, " \t", NULL, '\\', NULL, NULL, pset.encoding); + token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding); if (token) { if (strcasecmp(token, "using") == 0) { - token = strtokx(NULL, " \t", NULL, '\\', NULL, NULL, pset.encoding); + token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding); if (!token || strcasecmp(token, "delimiters") != 0) error = true; else { - token = strtokx(NULL, " \t", "'", '\\', NULL, NULL, pset.encoding); + token = strtokx(NULL, " \t\n\r", "'", '\\', NULL, NULL, pset.encoding); if (token) { result->delim = xstrdup(token); - token = strtokx(NULL, " \t", NULL, '\\', NULL, NULL, pset.encoding); + token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding); } else error = true; @@ -175,17 +175,17 @@ parse_slash_copy(const char *args) { if (strcasecmp(token, "with") == 0) { - token = strtokx(NULL, " \t", NULL, '\\', NULL, NULL, pset.encoding); + token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding); if (!token || strcasecmp(token, "null") != 0) error = true; else { - token = strtokx(NULL, " \t", NULL, '\\', NULL, NULL, pset.encoding); + token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding); if (!token || strcasecmp(token, "as") != 0) error = true; else { - token = strtokx(NULL, " \t", "'", '\\', NULL, NULL, pset.encoding); + token = strtokx(NULL, " \t\n\r", "'", '\\', NULL, NULL, pset.encoding); if (token) result->null = xstrdup(token); } diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c index a6f9d90c842..3e746a037f5 100644 --- a/src/bin/psql/mainloop.c +++ b/src/bin/psql/mainloop.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.28 2000/04/12 17:16:22 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.29 2000/04/14 23:43:44 petere Exp $ */ #include "postgres.h" #include "mainloop.h" @@ -397,7 +397,7 @@ MainLoop(FILE *source) { line[i] = '\0'; /* is there anything else on the line? */ - if (line[query_start + strspn(line + query_start, " \t")] != '\0') + if (line[query_start + strspn(line + query_start, " \t\n\r")] != '\0') { /* @@ -441,7 +441,7 @@ MainLoop(FILE *source) line[i - prevlen] = '\0'; /* overwrites backslash */ /* is there anything else on the line for the command? */ - if (line[query_start + strspn(line + query_start, " \t")] != '\0') + if (line[query_start + strspn(line + query_start, " \t\n\r")] != '\0') { /* @@ -499,7 +499,7 @@ MainLoop(FILE *source) /* Put the rest of the line in the query buffer. */ - if (line[query_start + strspn(line + query_start, " \t\n")] != '\0') + if (line[query_start + strspn(line + query_start, " \t\n\r")] != '\0') { if (query_buf->len > 0) appendPQExpBufferChar(query_buf, '\n'); |