3
#################################################################
4
# create_help.pl -- converts SGML docs to internal psql help
6
# Copyright (c) 2000-2005, PostgreSQL Global Development Group
8
# $PostgreSQL: pgsql/src/bin/psql/create_help.pl,v 1.13 2005-01-01 20:44:25 tgl Exp $
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.
22
$docdir = $ARGV[0] || die "$0: missing required argument: docdir\n";
23
$outputfile = $ARGV[1] || die "$0: missing required argument: output file\n";
25
if ($outputfile =~ m!.*/([^/]+)$!) {
26
$outputfilebasename = $1;
29
$outputfilebasename = $outputfile;
32
$define = $outputfilebasename;
33
$define =~ tr/a-z/A-Z/;
37
|| die "$0: could not open documentation source dir '$docdir': $!\n";
38
open(OUT, ">$outputfile")
39
|| die "$0: could not open output file '$outputfile': $!\n";
43
* *** Do not change this file by hand. It is automatically
44
* *** generated from the DocBook documentation.
54
#define N_(x) (x) /* gettext noop */
58
char *cmd; /* the command name */
59
char *help; /* the help associated with it */
60
char *syntax; /* the syntax associated with it */
64
static struct _helpStruct QL_HELP[] = {
69
foreach $file (sort readdir DIR) {
70
local ($cmdname, $cmddesc, $cmdsynopsis);
71
$file =~ /\.sgml$/ || next;
73
open(FILE, "$docdir/$file") || next;
74
$filecontent = join('', <FILE>);
77
# Ignore files that are not for SQL language statements
78
$filecontent =~ m!<refmiscinfo>\s*SQL - Language Statements\s*</refmiscinfo>!i
81
# Extract <refname>, <refpurpose>, and <synopsis> fields, taking the
82
# first one if there are more than one. NOTE: we cannot just say
83
# "<synopsis>(.*)</synopsis>", because that will match the first
84
# occurrence of <synopsis> and the last one of </synopsis>! Under
85
# Perl 5 we could use a non-greedy wildcard, .*?, to ensure we match
86
# the first </synopsis>, but we want this script to run under Perl 4
87
# too, and Perl 4 hasn't got that feature. So, do it the hard way.
88
# Also, use [\000-\377] where we want to match anything including
89
# newline --- Perl 4 does not have Perl 5's /s modifier.
90
$filecontent =~ m!<refname>\s*([a-z ]*[a-z])\s*</refname>!i && ($cmdname = $1);
91
if ($filecontent =~ m!<refpurpose>\s*([\000-\377]+)$!i) {
92
$tmp = $1; # everything after first <refpurpose>
93
if ($tmp =~ s!\s*</refpurpose>[\000-\377]*$!!i) {
97
if ($filecontent =~ m!<synopsis>\s*([\000-\377]+)$!i) {
98
$tmp = $1; # everything after first <synopsis>
99
if ($tmp =~ s!\s*</synopsis>[\000-\377]*$!!i) {
104
if ($cmdname && $cmddesc && $cmdsynopsis) {
105
$cmdname =~ s/\"/\\"/g;
107
$cmddesc =~ s/<[^>]+>//g;
108
$cmddesc =~ s/\s+/ /g;
109
$cmddesc =~ s/\"/\\"/g;
111
$cmdsynopsis =~ s/<[^>]+>//g;
112
$cmdsynopsis =~ s/\r?\n/\\n/g;
113
$cmdsynopsis =~ s/\"/\\"/g;
115
print OUT " { \"$cmdname\",\n N_(\"$cmddesc\"),\n N_(\"$cmdsynopsis\") },\n\n";
119
print STDERR "$0: parsing file '$file' failed (N='$cmdname' D='$cmddesc')\n";
124
{ NULL, NULL, NULL } /* End of list marker */
128
#define QL_HELP_COUNT $count