|
5 | 5 | #
|
6 | 6 | # Copyright 2000 by PostgreSQL Global Development Group
|
7 | 7 | #
|
8 |
| -# $Header: /cvsroot/pgsql/src/bin/psql/create_help.pl,v 1.5 2000/03/01 21:09:58 petere Exp $ |
| 8 | +# $Header: /cvsroot/pgsql/src/bin/psql/create_help.pl,v 1.6 2000/04/16 18:07:22 tgl Exp $ |
9 | 9 | #################################################################
|
10 | 10 |
|
11 | 11 | #
|
|
14 | 14 | # enough that this worked, but this here is by no means an SGML
|
15 | 15 | # parser.
|
16 | 16 | #
|
17 |
| -# Call: perl create_help.pl sql_help.h |
| 17 | +# Call: perl create_help.pldocdirsql_help.h |
18 | 18 | # The name of the header file doesn't matter to this script, but it
|
19 | 19 | # sure does matter to the rest of the source.
|
20 | 20 | #
|
21 | 21 |
|
22 |
| -$docdir ="./../../../doc/src/sgml/ref"; |
23 |
| -$outputfile =$ARGV[0]ordie"$0: missing required argument\n"; |
| 22 | +$docdir =$ARGV[0] ||die"$0: missing required argument: docdir\n"; |
| 23 | +$outputfile =$ARGV[1] ||die"$0: missing required argument: output file\n"; |
24 | 24 |
|
25 | 25 | $define =$outputfile;
|
26 | 26 | $define =~tr/a-z/A-Z/;
|
27 | 27 | $define =~s/\W/_/g;
|
28 | 28 |
|
29 |
| -opendir DIR,$docdirordie"$0: could not open documentation sources:$!\n"; |
30 |
| -open OUT,">$outputfile"ordie"$0: could not open output file '$outputfile':$!\n"; |
| 29 | +opendir(DIR,$docdir) |
| 30 | + ||die"$0: could not open documentation source dir '$docdir':$!\n"; |
| 31 | +open(OUT,">$outputfile") |
| 32 | + ||die"$0: could not open output file '$outputfile':$!\n"; |
31 | 33 |
|
32 | 34 | print OUT
|
33 | 35 | "/*
|
|
57 | 59 | $count = 0;
|
58 | 60 |
|
59 | 61 | foreach$file (sortreaddir DIR) {
|
60 |
| -my ($cmdname,$cmddesc,$cmdsynopsis); |
| 62 | +local ($cmdname,$cmddesc,$cmdsynopsis); |
61 | 63 | $file =~/\.sgml$/ ||next;
|
62 | 64 |
|
63 |
| -openFILE,"$docdir/$file"ornext; |
| 65 | +open(FILE,"$docdir/$file") ||next; |
64 | 66 | $filecontent =join('', <FILE>);
|
65 | 67 | close FILE;
|
66 | 68 |
|
| 69 | +# Ignore files that are not for SQL language statements |
67 | 70 | $filecontent =~m!<refmiscinfo>\s*SQL - Language Statements\s*</refmiscinfo>!i
|
68 |
| -ornext; |
69 |
| - |
70 |
| -$filecontent =~m!<refname>\s*([a-z ]+?)\s*</refname>!i && ($cmdname =$1); |
71 |
| -$filecontent =~m!<refpurpose>\s*(.+?)\s*</refpurpose>!i && ($cmddesc =$1); |
72 |
| - |
73 |
| -$filecontent =~m!<synopsis>\s*(.+?)\s*</synopsis>!is && ($cmdsynopsis =$1); |
| 71 | +||next; |
| 72 | + |
| 73 | +# Extract <refname>, <refpurpose>, and <synopsis> fields, taking the |
| 74 | +# first one if there are more than one. NOTE: we cannot just say |
| 75 | +# "<synopsis>(.*)</synopsis>", because that will match the first |
| 76 | +# occurrence of <synopsis> and the last one of </synopsis>! Under |
| 77 | +# Perl 5 we could use a non-greedy wildcard, .*?, to ensure we match |
| 78 | +# the first </synopsis>, but we want this script to run under Perl 4 |
| 79 | +# too, and Perl 4 hasn't got that feature. So, do it the hard way. |
| 80 | +# Also, use [\000-\377] where we want to match anything including |
| 81 | +# newline --- Perl 4 does not have Perl 5's /s modifier. |
| 82 | +$filecontent =~m!<refname>\s*([a-z ]*[a-z])\s*</refname>!i && ($cmdname =$1); |
| 83 | +if ($filecontent =~m!<refpurpose>\s*([\000-\377]+)$!i) { |
| 84 | +$tmp =$1;# everything after first <refpurpose> |
| 85 | +if ($tmp =~s!\s*</refpurpose>[\000-\377]*$!!i) { |
| 86 | +$cmddesc =$tmp; |
| 87 | +} |
| 88 | + } |
| 89 | +if ($filecontent =~m!<synopsis>\s*([\000-\377]+)$!i) { |
| 90 | +$tmp =$1;# everything after first <synopsis> |
| 91 | +if ($tmp =~s!\s*</synopsis>[\000-\377]*$!!i) { |
| 92 | +$cmdsynopsis =$tmp; |
| 93 | +} |
| 94 | + } |
74 | 95 |
|
75 | 96 | if ($cmdname &&$cmddesc &&$cmdsynopsis) {
|
76 | 97 | $cmdname =~s/\"/\\"/g;
|
77 | 98 |
|
78 |
| -$cmddesc =~s/<\/?.+?>//sg; |
79 |
| -$cmddesc =~s/\n//g; |
| 99 | +$cmddesc =~s/<[^>]+>//g; |
| 100 | +$cmddesc =~s/\s+//g; |
80 | 101 | $cmddesc =~s/\"/\\"/g;
|
81 | 102 |
|
82 |
| -$cmdsynopsis =~s/<\/?.+?>//sg; |
| 103 | +$cmdsynopsis =~s/<[^>]+>//g; |
83 | 104 | $cmdsynopsis =~s/\n/\\n/g;
|
84 | 105 | $cmdsynopsis =~s/\"/\\"/g;
|
85 | 106 |
|
|