|
1 |
| -#! /usr/bin/perl |
| 1 | +#! /usr/bin/perl -w |
2 | 2 |
|
3 | 3 | #################################################################
|
4 | 4 | # create_help.pl -- converts SGML docs to internal psql help
|
5 | 5 | #
|
6 | 6 | # Copyright (c) 2000-2008, PostgreSQL Global Development Group
|
7 | 7 | #
|
8 |
| -# $PostgreSQL: pgsql/src/bin/psql/create_help.pl,v 1.17 2008/01/20 21:13:55tgl Exp $ |
| 8 | +# $PostgreSQL: pgsql/src/bin/psql/create_help.pl,v 1.18 2008/11/19 09:51:55petere Exp $ |
9 | 9 | #################################################################
|
10 | 10 |
|
11 | 11 | #
|
|
19 | 19 | # sure does matter to the rest of the source.
|
20 | 20 | #
|
21 | 21 |
|
22 |
| -$docdir =$ARGV[0] ||die"$0: missing required argument: docdir\n"; |
23 |
| -$outputfile =$ARGV[1] ||die"$0: missing required argument: output file\n"; |
| 22 | +use strict; |
24 | 23 |
|
| 24 | +my$docdir =$ARGV[0]ordie"$0: missing required argument: docdir\n"; |
| 25 | +my$outputfile =$ARGV[1]ordie"$0: missing required argument: output file\n"; |
| 26 | + |
| 27 | +my$outputfilebasename; |
25 | 28 | if ($outputfile =~m!.*/([^/]+)$!) {
|
26 | 29 | $outputfilebasename =$1;
|
27 | 30 | }
|
28 | 31 | else {
|
29 | 32 | $outputfilebasename =$outputfile;
|
30 | 33 | }
|
31 | 34 |
|
32 |
| -$define =$outputfilebasename; |
| 35 | +my$define =$outputfilebasename; |
33 | 36 | $define =~tr/a-z/A-Z/;
|
34 | 37 | $define =~s/\W/_/g;
|
35 | 38 |
|
36 | 39 | opendir(DIR,$docdir)
|
37 |
| -||die"$0: could not open documentation source dir '$docdir':$!\n"; |
| 40 | +ordie"$0: could not open documentation source dir '$docdir':$!\n"; |
38 | 41 | open(OUT,">$outputfile")
|
39 |
| -||die"$0: could not open output file '$outputfile':$!\n"; |
| 42 | +ordie"$0: could not open output file '$outputfile':$!\n"; |
40 | 43 |
|
41 | 44 | print OUT
|
42 | 45 | "/*
|
|
64 | 67 | static const struct _helpStruct QL_HELP[] = {
|
65 | 68 | ";
|
66 | 69 |
|
67 |
| -$count = 0; |
68 |
| -$maxlen = 0; |
| 70 | +my$maxlen = 0; |
| 71 | + |
| 72 | +my%entries; |
69 | 73 |
|
70 |
| -foreach$file (sortreaddir DIR) { |
71 |
| -local ($cmdname,$cmddesc,$cmdsynopsis); |
72 |
| -$file =~/\.sgml$/||next; |
| 74 | +foreachmy$file (sortreaddir DIR) { |
| 75 | +my (@cmdnames,$cmddesc,$cmdsynopsis); |
| 76 | +$file =~/\.sgml$/ornext; |
73 | 77 |
|
74 |
| -open(FILE,"$docdir/$file")||next; |
75 |
| -$filecontent =join('', <FILE>); |
| 78 | +open(FILE,"$docdir/$file")ornext; |
| 79 | +my$filecontent =join('', <FILE>); |
76 | 80 | close FILE;
|
77 | 81 |
|
78 | 82 | # Ignore files that are not for SQL language statements
|
79 | 83 | $filecontent =~m!<refmiscinfo>\s*SQL - Language Statements\s*</refmiscinfo>!i
|
80 |
| -||next; |
81 |
| - |
82 |
| -# Extract <refname>, <refpurpose>, and <synopsis> fields, taking the |
83 |
| -# first one if there are more than one. NOTE: we cannot just say |
84 |
| -# "<synopsis>(.*)</synopsis>", because that will match the first |
85 |
| -# occurrence of <synopsis> and the last one of </synopsis>! Under |
86 |
| -# Perl 5 we could use a non-greedy wildcard, .*?, to ensure we match |
87 |
| -# the first </synopsis>, but we want this script to run under Perl 4 |
88 |
| -# too, and Perl 4 hasn't got that feature. So, do it the hard way. |
89 |
| -# Also, use [\000-\377] where we want to match anything including |
90 |
| -# newline --- Perl 4 does not have Perl 5's /s modifier. |
91 |
| -$filecontent =~m!<refname>\s*([a-z ]*[a-z])\s*</refname>!i && ($cmdname =$1); |
92 |
| -if ($filecontent =~m!<refpurpose>\s*([\000-\377]+)$!i) { |
93 |
| -$tmp =$1;# everything after first <refpurpose> |
94 |
| -if ($tmp =~s!\s*</refpurpose>[\000-\377]*$!!i) { |
95 |
| -$cmddesc =$tmp; |
96 |
| -} |
97 |
| - } |
98 |
| -if ($filecontent =~m!<synopsis>\s*([\000-\377]+)$!i) { |
99 |
| -$tmp =$1;# everything after first <synopsis> |
100 |
| -if ($tmp =~s!\s*</synopsis>[\000-\377]*$!!i) { |
101 |
| -$cmdsynopsis =$tmp; |
102 |
| -} |
103 |
| - } |
| 84 | +ornext; |
| 85 | + |
| 86 | +# Collect multiple refnames |
| 87 | + LOOP: {$filecontent =~m!\G.*?<refname>\s*([a-z ]+?)\s*</refname>!cgisandpush@cmdnames,$1andredo LOOP; } |
| 88 | +$filecontent =~m!<refpurpose>\s*(.+?)\s*</refpurpose>!isand$cmddesc =$1; |
| 89 | +$filecontent =~m!<synopsis>\s*(.+?)\s*</synopsis>!isand$cmdsynopsis =$1; |
104 | 90 |
|
105 |
| -if ($cmdname &&$cmddesc &&$cmdsynopsis) { |
106 |
| -$cmdname =~s/\"/\\"/g; |
| 91 | +if (@cmdnames &&$cmddesc &&$cmdsynopsis) { |
| 92 | +s/\"/\\"/gforeach@cmdnames; |
107 | 93 |
|
108 | 94 | $cmddesc =~s/<[^>]+>//g;
|
109 | 95 | $cmddesc =~s/\s+//g;
|
|
113 | 99 | $cmdsynopsis =~s/\r?\n/\\n/g;
|
114 | 100 | $cmdsynopsis =~s/\"/\\"/g;
|
115 | 101 |
|
116 |
| -print OUT"{\"$cmdname\",\n N_(\"$cmddesc\"),\n N_(\"$cmdsynopsis\") },\n\n"; |
117 |
| - |
118 |
| -$count++; |
119 |
| -$maxlen = ($maxlen >=length$cmdname) ?$maxlen :length$cmdname; |
| 102 | +foreachmy$cmdname (@cmdnames) { |
| 103 | +$entries{$cmdname} = {cmddesc=>$cmddesc,cmdsynopsis=>$cmdsynopsis }; |
| 104 | +$maxlen = ($maxlen >=length$cmdname) ?$maxlen :length$cmdname; |
| 105 | +} |
120 | 106 | }
|
121 | 107 | else {
|
122 |
| -printSTDERR"$0: parsing file '$file' failed (N='$cmdname' D='$cmddesc')\n"; |
| 108 | +die"$0: parsing file '$file' failed (N='@cmdnames' D='$cmddesc')\n"; |
123 | 109 | }
|
124 | 110 | }
|
125 | 111 |
|
| 112 | +print OUT" {\"$_\",\n N_(\"".$entries{$_}{cmddesc}."\"),\n N_(\"".$entries{$_}{cmdsynopsis}."\") },\n\n"foreach (sortkeys%entries); |
| 113 | + |
126 | 114 | print OUT"
|
127 | 115 | { NULL, NULL, NULL } /* End of list marker */
|
128 | 116 | };
|
129 | 117 |
|
130 | 118 |
|
131 |
| -#define QL_HELP_COUNT$count/* number of help items */ |
| 119 | +#define QL_HELP_COUNT".scalar(keys%entries)."/* number of help items */ |
132 | 120 | #define QL_MAX_CMD_LEN$maxlen/* largest strlen(cmd) */
|
133 | 121 |
|
134 | 122 |
|
|