Index: tab-complete.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/tab-complete.c,v retrieving revision 1.141 diff -c -r1.141 tab-complete.c *** tab-complete.c 18 Nov 2005 16:31:11 -0000 1.141 --- tab-complete.c 5 Dec 2005 04:14:43 -0000 *************** *** 476,481 **** --- 476,483 ---- static char *previous_word(int point, int skip); + static int find_open_parenthesis(int end); + #if 0 static char *quote_file_name(char *text, int match_type, char *quote_pointer); static char *dequote_file_name(char *text, char quote_char); *************** *** 1016,1022 **** */ else if (pg_strcasecmp(prev4_wd, "INDEX") == 0 && pg_strcasecmp(prev2_wd, "ON") == 0) ! COMPLETE_WITH_ATTR(prev_wd); /* same if you put in USING */ else if (pg_strcasecmp(prev4_wd, "ON") == 0 && pg_strcasecmp(prev2_wd, "USING") == 0) --- 1018,1040 ---- */ else if (pg_strcasecmp(prev4_wd, "INDEX") == 0 && pg_strcasecmp(prev2_wd, "ON") == 0) ! { ! if (find_open_parenthesis(end)) ! { ! COMPLETE_WITH_ATTR(prev_wd); ! } ! else ! { ! COMPLETE_WITH_CONST("("); ! } ! } ! else if (pg_strcasecmp(prev5_wd, "INDEX") == 0 && ! pg_strcasecmp(prev3_wd, "ON") == 0 && ! pg_strcasecmp(prev_wd, "(") == 0) ! { ! COMPLETE_WITH_ATTR(prev2_wd); ! } ! /* same if you put in USING */ else if (pg_strcasecmp(prev4_wd, "ON") == 0 && pg_strcasecmp(prev2_wd, "USING") == 0) *************** *** 1222,1233 **** pg_strcasecmp(prev3_wd, "AGGREGATE") == 0 && prev_wd[strlen(prev_wd) - 1] == ')')) { ! static const char *const list_DROPCR[] = ! {"CASCADE", "RESTRICT", NULL}; ! ! COMPLETE_WITH_LIST(list_DROPCR); } /* EXPLAIN */ /* --- 1240,1282 ---- pg_strcasecmp(prev3_wd, "AGGREGATE") == 0 && prev_wd[strlen(prev_wd) - 1] == ')')) { ! ! if ((pg_strcasecmp(prev3_wd, "DROP") == 0) && (pg_strcasecmp(prev2_wd, "FUNCTION") == 0)) ! { ! if (find_open_parenthesis(end)) ! { ! static const char func_args_query[] = "select pg_catalog.oidvectortypes(proargtypes)||')' from pg_proc where proname='%s'"; ! char *tmp_buf = malloc(strlen(func_args_query) + strlen(prev_wd)); ! sprintf(tmp_buf, func_args_query, prev_wd); ! COMPLETE_WITH_QUERY(tmp_buf); ! free(tmp_buf); ! } ! else ! { ! COMPLETE_WITH_CONST("("); ! } ! } ! else ! { ! static const char *const list_DROPCR[] = ! {"CASCADE", "RESTRICT", NULL}; ! ! COMPLETE_WITH_LIST(list_DROPCR); ! } ! } ! else if (pg_strcasecmp(prev4_wd, "DROP") == 0 && ! pg_strcasecmp(prev3_wd, "FUNCTION") == 0 && ! pg_strcasecmp(prev_wd, "(") == 0 ) ! { ! static const char func_args_query[] = "select pg_catalog.oidvectortypes(proargtypes)||')' from pg_proc where proname='%s'"; ! char *tmp_buf = malloc(strlen(func_args_query) + strlen(prev2_wd)); ! sprintf(tmp_buf, func_args_query, prev2_wd); ! COMPLETE_WITH_QUERY(tmp_buf); ! free(tmp_buf); } + + /* EXPLAIN */ /* *************** *** 2247,2253 **** --- 2296,2324 ---- return s; } + /* Find the parenthesis after the last word */ + + + static int find_open_parenthesis(int end) + { + int i = end-1; + + while((rl_line_buffer[i]!=' ')&&(i>=0)) + { + if (rl_line_buffer[i]=='(') return 1; + i--; + } + while((rl_line_buffer[i]==' ')&&(i>=0)) + { + i--; + } + if (rl_line_buffer[i]=='(') + { + return 1; + } + return 0; + } #if 0