Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc3a69c3

Browse files
committed
Attached is a patch that enhances the "\h" capability in psql. I often
find myself typing a command and then wanting to get the syntax for it.So I do a ctrl-a and add a \h: but psql does not recognize the command,because I have stuff attached to it (e.g. "alter table foobar"), so Ihave to scroll over and delete everything except the name of the commanditself. This patch gives \h three chances to match: if nothing matchesthe complete string (current behavior), it tries to match the first twowords (e.g. "ALTER TABLE"). If that fails, it tries to match the firstword (e.g. "DELETE").Greg Sabino Mullane
1 parent84d630e commitc3a69c3

File tree

1 file changed

+64
-38
lines changed

1 file changed

+64
-38
lines changed

‎src/bin/psql/help.c

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.102 2005/06/14 02:57:41 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.103 2005/07/06 03:14:48 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -305,52 +305,78 @@ helpSQL(const char *topic, unsigned short int pager)
305305
}
306306
else
307307
{
308-
inti;
308+
inti,j,x=0;
309309
boolhelp_found= false;
310310
FILE*output;
311-
size_tlen;
311+
size_tlen,wordlen;
312312
intnl_count=0;
313313
char*ch;
314314

315-
/* don't care about trailing spaces or semicolons */
315+
/* User gets two chances: exact match, then the first word */
316+
317+
/* First pass : strip trailing spaces and semicolons */
316318
len=strlen(topic);
317319
while (topic[len-1]==' '||topic[len-1]==';')
318-
len--;
319-
320-
/* Count newlines for pager */
321-
for (i=0;QL_HELP[i].cmd;i++)
322-
{
323-
if (pg_strncasecmp(topic,QL_HELP[i].cmd,len)==0||
324-
strcmp(topic,"*")==0)
325-
{
326-
nl_count+=5;
327-
for (ch=QL_HELP[i].syntax;*ch!='\0';ch++)
328-
if (*ch=='\n')
329-
nl_count++;
330-
/* If we have an exact match, exit. Fixes \h SELECT */
331-
if (pg_strcasecmp(topic,QL_HELP[i].cmd)==0)
332-
break;
333-
}
334-
}
335-
336-
output=PageOutput(nl_count,pager);
320+
len--;
337321

338-
for (i=0;QL_HELP[i].cmd;i++)
322+
for (x=1;x<=3;x++)/* Three chances to guess that word... */
339323
{
340-
if (pg_strncasecmp(topic,QL_HELP[i].cmd,len)==0||
341-
strcmp(topic,"*")==0)
342-
{
343-
help_found= true;
344-
fprintf(output,_("Command: %s\n"
345-
"Description: %s\n"
346-
"Syntax:\n%s\n\n"),
347-
QL_HELP[i].cmd,
348-
_(QL_HELP[i].help),
349-
_(QL_HELP[i].syntax));
350-
/* If we have an exact match, exit. Fixes \h SELECT */
351-
if (pg_strcasecmp(topic,QL_HELP[i].cmd)==0)
352-
break;
353-
}
324+
if (x>1)/* Nothing on first pass - try the opening words */
325+
{
326+
wordlen=j=1;
327+
while (topic[j]!=' '&&j++<len)
328+
wordlen++;
329+
if (x==2)
330+
{
331+
j++;
332+
while (topic[j]!=' '&&j++<=len)
333+
wordlen++;
334+
}
335+
if (wordlen >=len)/* Don't try again if the same word */
336+
{
337+
output=PageOutput(nl_count,pager);
338+
break;
339+
}
340+
len=wordlen;
341+
}
342+
343+
/* Count newlines for pager */
344+
for (i=0;QL_HELP[i].cmd;i++)
345+
{
346+
if (pg_strncasecmp(topic,QL_HELP[i].cmd,len)==0||
347+
strcmp(topic,"*")==0)
348+
{
349+
nl_count+=5;
350+
for (ch=QL_HELP[i].syntax;*ch!='\0';ch++)
351+
if (*ch=='\n')
352+
nl_count++;
353+
/* If we have an exact match, exit. Fixes \h SELECT */
354+
if (pg_strcasecmp(topic,QL_HELP[i].cmd)==0)
355+
break;
356+
}
357+
}
358+
359+
output=PageOutput(nl_count,pager);
360+
361+
for (i=0;QL_HELP[i].cmd;i++)
362+
{
363+
if (pg_strncasecmp(topic,QL_HELP[i].cmd,len)==0||
364+
strcmp(topic,"*")==0)
365+
{
366+
help_found= true;
367+
fprintf(output,_("Command: %s\n"
368+
"Description: %s\n"
369+
"Syntax:\n%s\n\n"),
370+
QL_HELP[i].cmd,
371+
_(QL_HELP[i].help),
372+
_(QL_HELP[i].syntax));
373+
/* If we have an exact match, exit. Fixes \h SELECT */
374+
if (pg_strcasecmp(topic,QL_HELP[i].cmd)==0)
375+
break;
376+
}
377+
}
378+
if (help_found)/* Don't keep trying if we got a match */
379+
break;
354380
}
355381

356382
if (!help_found)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp