diff options
Diffstat (limited to 'src/bin/psql/create_help.pl')
-rw-r--r-- | src/bin/psql/create_help.pl | 101 |
1 files changed, 83 insertions, 18 deletions
diff --git a/src/bin/psql/create_help.pl b/src/bin/psql/create_help.pl index 6aadda90b06..d56cc5bea6b 100644 --- a/src/bin/psql/create_help.pl +++ b/src/bin/psql/create_help.pl @@ -5,7 +5,7 @@ # # Copyright (c) 2000-2009, PostgreSQL Global Development Group # -# $PostgreSQL: pgsql/src/bin/psql/create_help.pl,v 1.19 2009/01/01 17:23:54 momjian Exp $ +# $PostgreSQL: pgsql/src/bin/psql/create_help.pl,v 1.20 2009/09/18 05:00:42 petere Exp $ ################################################################# # @@ -14,7 +14,7 @@ # enough that this worked, but this here is by no means an SGML # parser. # -# Call: perl create_help.pl docdir sql_help.h +# Call: perl create_help.pl docdir sql_help # The name of the header file doesn't matter to this script, but it # sure does matter to the rest of the source. # @@ -22,26 +22,29 @@ use strict; my $docdir = $ARGV[0] or die "$0: missing required argument: docdir\n"; -my $outputfile = $ARGV[1] or die "$0: missing required argument: output file\n"; +my $hfile = $ARGV[1] . '.h' or die "$0: missing required argument: output file\n"; +my $cfile = $ARGV[1] . '.c'; -my $outputfilebasename; -if ($outputfile =~ m!.*/([^/]+)$!) { - $outputfilebasename = $1; +my $hfilebasename; +if ($hfile =~ m!.*/([^/]+)$!) { + $hfilebasename = $1; } else { - $outputfilebasename = $outputfile; + $hfilebasename = $hfile; } -my $define = $outputfilebasename; +my $define = $hfilebasename; $define =~ tr/a-z/A-Z/; $define =~ s/\W/_/g; opendir(DIR, $docdir) or die "$0: could not open documentation source dir '$docdir': $!\n"; -open(OUT, ">$outputfile") - or die "$0: could not open output file '$outputfile': $!\n"; +open(HFILE, ">$hfile") + or die "$0: could not open output file '$hfile': $!\n"; +open(CFILE, ">$cfile") + or die "$0: could not open output file '$cfile': $!\n"; -print OUT +print HFILE "/* * *** Do not change this file by hand. It is automatically * *** generated from the DocBook documentation. @@ -56,15 +59,31 @@ print OUT #define N_(x) (x) /* gettext noop */ +#include \"postgres_fe.h\" +#include \"pqexpbuffer.h\" + struct _helpStruct { const char *cmd; /* the command name */ const char *help; /* the help associated with it */ - const char *syntax; /* the syntax associated with it */ + void (*syntaxfunc)(PQExpBuffer); /* function that prints the syntax associated with it */ + int nl_count; /* number of newlines in syntax (for pager) */ }; +"; + +print CFILE +"/* + * *** Do not change this file by hand. It is automatically + * *** generated from the DocBook documentation. + * + * generated by + * $^X $0 @ARGV + * + */ + +#include \"$hfile\" -static const struct _helpStruct QL_HELP[] = { "; my $maxlen = 0; @@ -95,12 +114,25 @@ foreach my $file (sort readdir DIR) { $cmddesc =~ s/\s+/ /g; $cmddesc =~ s/\"/\\"/g; - $cmdsynopsis =~ s/<[^>]+>//g; + my @params = (); + + my $nl_count = () = $cmdsynopsis =~ /\n/g; + + $cmdsynopsis =~ m!</>! and die "$0:$file: null end tag not supported in synopsis\n"; + $cmdsynopsis =~ s/%/%%/g; + + while ($cmdsynopsis =~ m!<(\w+)[^>]*>(.+?)</\1[^>]*>!) { + my $match = $2; + $match =~ s/<[^>]+>//g; + $match =~ s/%%/%/g; + push @params, $match; + $cmdsynopsis =~ s!<(\w+)[^>]*>.+?</\1[^>]*>!%s!; + } $cmdsynopsis =~ s/\r?\n/\\n/g; $cmdsynopsis =~ s/\"/\\"/g; foreach my $cmdname (@cmdnames) { - $entries{$cmdname} = { cmddesc => $cmddesc, cmdsynopsis => $cmdsynopsis }; + $entries{$cmdname} = { cmddesc => $cmddesc, cmdsynopsis => $cmdsynopsis, params => \@params, nl_count => $nl_count }; $maxlen = ($maxlen >= length $cmdname) ? $maxlen : length $cmdname; } } @@ -109,9 +141,41 @@ foreach my $file (sort readdir DIR) { } } -print OUT " { \"$_\",\n N_(\"".$entries{$_}{cmddesc}."\"),\n N_(\"".$entries{$_}{cmdsynopsis}."\") },\n\n" foreach (sort keys %entries); +foreach (sort keys %entries) { + my $prefix = "\t"x5 . ' '; + my $id = $_; + $id =~ s/ /_/g; + my $synopsis = "\"$entries{$_}{cmdsynopsis}\""; + $synopsis =~ s/\\n/\\n"\n$prefix"/g; + my @args = ("buf", + $synopsis, + map("_(\"$_\")", @{$entries{$_}{params}})); + print HFILE "extern void sql_help_$id(PQExpBuffer buf);\n"; + print CFILE "void +sql_help_$id(PQExpBuffer buf) +{ +\tappendPQExpBuffer(".join(",\n$prefix", @args)."); +} + +"; +} + +print HFILE " + +static const struct _helpStruct QL_HELP[] = { +"; +foreach (sort keys %entries) { + my $id = $_; + $id =~ s/ /_/g; + print HFILE " { \"$_\", + N_(\"$entries{$_}{cmddesc}\"), + sql_help_$id, + $entries{$_}{nl_count} }, + +"; +} -print OUT " +print HFILE " { NULL, NULL, NULL } /* End of list marker */ }; @@ -123,5 +187,6 @@ print OUT " #endif /* $define */ "; -close OUT; +close CFILE; +close HFILE; closedir DIR; |