2014-08-07 7:10 GMT+02:00 Fujii Masao <masao.fu...@gmail.com>:

> On Thu, Aug 7, 2014 at 6:26 AM, Pavel Stehule <pavel.steh...@gmail.com>
> wrote:
> > Hello
> >
> > updated version patch in attachment
>
> Thanks! But ISTM you forgot to attached the patch.
>

grr .. I am sorry


>
> >> +    /* all psql known variables are included in list by default */
> >> +    for (known_varname = known_varnames; *known_varname;
> known_varname++)
> >> +        varnames[nvars++] = pg_strdup(*known_varname);
> >>
> >> Don't we need to append both prefix and suffix to even known variables?
> >
> >
> > ??? I am not sure if I understand well - probably system "read only"
> > variables as DBNAME, USER, VERSION should not be there
>
> I had that question because complete_from_variables() is also called by the
> tab-completion of "\echo :" and it shows half-baked variables list. So
> I thought probably we need to change complete_from_variables() more to
> fix the problem.
>

I understand now.

I fixed it.

I have a question.\echo probably should not to show empty known variable.

data for autocomplete for \echo should be same as result of "\set"



>
> >> +    else if (strcmp(prev2_wd, "\\set") == 0)
> >> +    {
> >> +        if (strcmp(prev_wd, "AUTOCOMMIT") == 0)
> >>
> >> ISTM that some psql variables like IGNOREEOF are not there. Why not?
> >
> >
> > yes, there are not complete for DBNAME, ENCODING, FETCH_COUNT,
> HISTCONTROL,
> > HISTFILE, HISTSIZE, HOST, IGNOREEOFF, PROMPT*,USER,  VERSION
> >
> > There are more reasons:
> >
> > * paremeter is not a enum (string, number or both): FETCH_COUNT, PROMPT,
> > HISTSIZE, ..
> >
> > * variable is pseudo read only  - change has not any effect: DBNAME,
> > ENCODING, VERSION
>
> So HISTCONTROL should be there because it doesn't have such reasons at all?
>
>
yes

Pavel


> Regards,
>
> --
> Fujii Masao
>
commit bacfdc0e03219265aeee34b78f7ec9d272d49f72
Author: Pavel Stehule <pavel.steh...@gooddata.com>
Date:   Wed Aug 6 23:05:42 2014 +0200

    warnings and typo fixed

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 24e60b7..b94ed63 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3608,6 +3608,79 @@ psql_completion(const char *text, int start, int end)
 	{
 		matches = complete_from_variables(text, "", "");
 	}
+	else if (strcmp(prev2_wd, "\\set") == 0)
+	{
+		if (strcmp(prev_wd, "AUTOCOMMIT") == 0)
+		{
+			static const char *const my_list[] =
+			{"on", "off", "interactive", NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, "COMP_KEYWORD_CASE") == 0)
+		{
+			static const char *const my_list[] =
+			{"lower", "upper", "preserve-lower", "preserve-upper", NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, "ECHO") == 0)
+		{
+			static const char *const my_list[] =
+			{"none", "errors", "queries", "all", NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, "ECHO_HIDDEN") == 0)
+		{
+			static const char *const my_list[] =
+			{"noexec", "off", "on", NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, "ON_ERROR_ROLLBACK") == 0)
+		{
+			static const char *const my_list[] =
+			{"on", "off", "interactive", NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, "ON_ERROR_STOP") == 0)
+		{
+			static const char *const my_list[] =
+			{"on", "off", NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, "QUIET") == 0)
+		{
+			static const char *const my_list[] =
+			{"on", "off", NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, "SINGLELINE") == 0)
+		{
+			static const char *const my_list[] =
+			{"on", "off", NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, "SINGLESTEP") == 0)
+		{
+			static const char *const my_list[] =
+			{"on", "off", NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+		else if (strcmp(prev_wd, "VERBOSITY") == 0)
+		{
+			static const char *const my_list[] =
+			{"default", "verbose", "terse", NULL};
+
+			COMPLETE_WITH_LIST_CS(my_list);
+		}
+	}
 	else if (strcmp(prev_wd, "\\sf") == 0 || strcmp(prev_wd, "\\sf+") == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
 	else if (strcmp(prev_wd, "\\cd") == 0 ||
@@ -4062,28 +4135,61 @@ complete_from_variables(const char *text, const char *prefix, const char *suffix
 {
 	char	  **matches;
 	char	  **varnames;
+	static const char **known_varname;
 	int			nvars = 0;
 	int			maxvars = 100;
 	int			i;
 	struct _variable *ptr;
 
+	static const char *known_varnames[] = {
+		"AUTOCOMMIT", "COMP_KEYWORD_CASE", "DBNAME", "ECHO", "ECHO_HIDDEN", "ENCODING",
+		"FETCH_COUNT", "HISTCONTROL", "HISTFILE", "HISTSIZE", "HOST", "IGNOREEOFF",
+		"LASTOID", "ON_ERROR_ROLLBACK", "ON_ERROR_STOP", "PORT", "PROMPT1", "PROMPT2",
+		"PROMPT3", "QUIET", "SINGLELINE", "SINGLESTEP", "USER", "VERBOSITY",
+		NULL
+	};
+
 	varnames = (char **) pg_malloc((maxvars + 1) * sizeof(char *));
 
+	/* all psql known variables are included in list by default */
+	for (known_varname = known_varnames; *known_varname; known_varname++)
+		varnames[nvars++] = psprintf("%s%s%s", prefix, *known_varname, suffix);
+
 	for (ptr = pset.vars->next; ptr; ptr = ptr->next)
 	{
-		if (nvars >= maxvars)
+		char *varname;
+		bool is_known_varname = false;
+
+		varname = psprintf("%s%s%s", prefix, ptr->name, suffix);
+
+		/* is it known varname? */
+		for (known_varname = known_varnames; *known_varname; known_varname++)
 		{
-			maxvars *= 2;
-			varnames = (char **) realloc(varnames,
-										 (maxvars + 1) * sizeof(char *));
-			if (!varnames)
+			if (strcmp(*known_varname, varname) == 0)
 			{
-				psql_error("out of memory\n");
-				exit(EXIT_FAILURE);
+				free(varname);
+				is_known_varname = true;
+				break;
 			}
 		}
 
-		varnames[nvars++] = psprintf("%s%s%s", prefix, ptr->name, suffix);
+		/* append only unknown varnames, known varnames are in list already */
+		if (!is_known_varname)
+		{
+			if (nvars >= maxvars)
+			{
+				maxvars *= 2;
+				varnames = (char **) realloc(varnames,
+										 (maxvars + 1) * sizeof(char *));
+				if (!varnames)
+				{
+					psql_error("out of memory\n");
+					exit(EXIT_FAILURE);
+				}
+			}
+
+			varnames[nvars++] = psprintf("%s%s%s", prefix, ptr->name, suffix);
+		}
 	}
 
 	varnames[nvars] = NULL;
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to