#!perl ################################################################# # create_help.pl -- converts SGML docs to internal psql help # # Copyright 2000-2001 by PostgreSQL Global Development Group # # $Header: /cvsroot/pgsql/src/bin/psql/create_help.pl,v 1.7 2000/06/27 00:31:41 petere Exp $ ################################################################# # # This script automatically generates the help on SQL in psql from # the SGML docs. So far the format of the docs was consistent # enough that this worked, but this here is by no means an SGML # parser. # # Call: perl create_help.pl docdir sql_help.h # The name of the header file doesn't matter to this script, but it # sure does matter to the rest of the source. # 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"; ## Create a name for use in the #define at the top of the generated file my $define = uc $outputfile; $define =~ s!.*/(.+)!$1!; $define =~ s/\W/_/; 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"; print OUT <<"FILE_HEADER"; /* * *** Do not change this file by hand. It is automatically * *** generated from the DocBook documentation. * * generated by * $^X $0 @ARGV * */ #ifndef $define #define $define struct _helpStruct { char *cmd; /* the command name */ char *help; /* the help associated with it */ char *syntax; /* the syntax associated with it */ }; static struct _helpStruct QL_HELP[] = { FILE_HEADER my $count=0; ## Total files successfully processed my $filecontent; my ($cmdname, $cmddesc, $cmdsynopsis); for my $file (sort readdir DIR) { next unless $file =~ /\.sgml$/; unless (open(SGMLFILE, "$docdir/$file")) { warn "Could not open $docdir/$file: $!\n"; next; } { local $/; $filecontent = ; } close SGMLFILE; # Ignore files that are not for SQL language statements next unless $filecontent =~ m!\s*SQL - Language Statements\s*!i; # Extract , , and fields, taking the # first one if there are more than one. $cmdname = $cmddesc = $cmdsynopsis = ""; $cmdname = $1 if $filecontent =~ m!\s*([a-z ]*[a-z])\s*!is; $cmddesc = $1 if $filecontent =~ m!\s*(.+?)\s*!is; $cmdsynopsis = $1 if $filecontent =~ m!\s*(.+?)\s*!is; if (!length $cmdname or !length $cmddesc or !length $cmdsynopsis) { warn "$0: parsing file '$file' failed ". "(N='$cmdname' D='$cmddesc' S='$cmdsynopsis')\n"; next; } $cmdname =~ s!"!\\"!g; $cmddesc =~ s!<[^>]+>!!g; $cmddesc =~ s!\s+! !gs; $cmddesc =~ s!"!\\"!g; $cmdsynopsis =~ s!<[^>]+>!!g; $cmdsynopsis =~ s!\n!\\n!g; $cmdsynopsis =~ s!"!\\"!g; print OUT qq! { "$cmdname",\n "$cmddesc",\n "$cmdsynopsis" },\n\n!; $count++; } ## end of each file in the directory closedir DIR; print OUT <<"FILE_FOOTER"; { NULL, NULL, NULL } /* End of list marker */ }; #define QL_HELP_COUNT $count #endif /* $define */ FILE_FOOTER close OUT;