3 #################################################################
4 # create_help.pl -- converts SGML docs to internal psql help
6 # Copyright (c) 2000-2009, PostgreSQL Global Development Group
9 #################################################################
12 # This script automatically generates the help on SQL in psql from
13 # the SGML docs. So far the format of the docs was consistent
14 # enough that this worked, but this here is by no means an SGML
17 # Call: perl create_help.pl docdir sql_help.h
18 # The name of the header file doesn't matter to this script, but it
19 # sure does matter to the rest of the source.
24 my $docdir = $ARGV[0] or die "$0: missing required argument: docdir\n";
25 my $outputfile = $ARGV[1] or die "$0: missing required argument: output file\n";
27 my $outputfilebasename;
28 if ($outputfile =~ m!.*/([^/]+)$!) {
29 $outputfilebasename = $1;
32 $outputfilebasename = $outputfile;
35 my $define = $outputfilebasename;
36 $define =~ tr/a-z/A-Z/;
40 or die "$0: could not open documentation source dir '$docdir': $!\n";
41 open(OUT
, ">$outputfile")
42 or die "$0: could not open output file '$outputfile': $!\n";
46 * *** Do not change this file by hand. It is automatically
47 * *** generated from the DocBook documentation.
57 #define N_(x) (x) /* gettext noop */
61 const char *cmd; /* the command name */
62 const char *help; /* the help associated with it */
63 const char *syntax; /* the syntax associated with it */
67 static const struct _helpStruct QL_HELP[] = {
74 foreach my $file (sort readdir DIR
) {
75 my (@cmdnames, $cmddesc, $cmdsynopsis);
76 $file =~ /\.sgml$/ or next;
78 open(FILE
, "$docdir/$file") or next;
79 my $filecontent = join('', <FILE
>);
82 # Ignore files that are not for SQL language statements
83 $filecontent =~ m!<refmiscinfo>\s*SQL - Language Statements\s*</refmiscinfo>!i
86 # Collect multiple refnames
87 LOOP
: { $filecontent =~ m!\G.*?<refname>\s*([a-z ]+?)\s*</refname>!cgis and push @cmdnames, $1 and redo LOOP
; }
88 $filecontent =~ m!<refpurpose>\s*(.+?)\s*</refpurpose>!is and $cmddesc = $1;
89 $filecontent =~ m!<synopsis>\s*(.+?)\s*</synopsis>!is and $cmdsynopsis = $1;
91 if (@cmdnames && $cmddesc && $cmdsynopsis) {
92 s/\"/\\"/g foreach @cmdnames;
94 $cmddesc =~ s/<[^>]+>//g;
95 $cmddesc =~ s/\s+/ /g;
96 $cmddesc =~ s/\"/\\"/g;
98 $cmdsynopsis =~ s/<[^>]+>//g;
99 $cmdsynopsis =~ s/\r?\n/\\n/g;
100 $cmdsynopsis =~ s/\"/\\"/g;
102 foreach my $cmdname (@cmdnames) {
103 $entries{$cmdname} = { cmddesc
=> $cmddesc, cmdsynopsis
=> $cmdsynopsis };
104 $maxlen = ($maxlen >= length $cmdname) ?
$maxlen : length $cmdname;
108 die "$0: parsing file '$file' failed (N='@cmdnames' D='$cmddesc')\n";
112 print OUT
" { \"$_\",\n N_(\"".$entries{$_}{cmddesc
}."\"),\n N_(\"".$entries{$_}{cmdsynopsis
}."\") },\n\n" foreach (sort keys %entries);
115 { NULL, NULL, NULL } /* End of list marker */
119 #define QL_HELP_COUNT ".scalar(keys %entries)." /* number of help items */
120 #define QL_MAX_CMD_LEN $maxlen /* largest strlen(cmd) */