Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8b4da40

Browse files
committed
Change this script to Perl 5 style. Add support for multiple refnames.
Sort the output by command name. This previously only worked by sourcefile name, which doesn't always match the command name exactly. And itcertainly won't work for multiple refnames.
1 parent89ad92a commit8b4da40

File tree

1 file changed

+34
-46
lines changed

1 file changed

+34
-46
lines changed

‎src/bin/psql/create_help.pl

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#! /usr/bin/perl
1+
#! /usr/bin/perl -w
22

33
#################################################################
44
# create_help.pl -- converts SGML docs to internal psql help
55
#
66
# Copyright (c) 2000-2008, PostgreSQL Global Development Group
77
#
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 $
99
#################################################################
1010

1111
#
@@ -19,24 +19,27 @@
1919
# sure does matter to the rest of the source.
2020
#
2121

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;
2423

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;
2528
if ($outputfile =~m!.*/([^/]+)$!) {
2629
$outputfilebasename =$1;
2730
}
2831
else {
2932
$outputfilebasename =$outputfile;
3033
}
3134

32-
$define =$outputfilebasename;
35+
my$define =$outputfilebasename;
3336
$define =~tr/a-z/A-Z/;
3437
$define =~s/\W/_/g;
3538

3639
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";
3841
open(OUT,">$outputfile")
39-
||die"$0: could not open output file '$outputfile':$!\n";
42+
ordie"$0: could not open output file '$outputfile':$!\n";
4043

4144
print OUT
4245
"/*
@@ -64,46 +67,29 @@
6467
static const struct _helpStruct QL_HELP[] = {
6568
";
6669

67-
$count = 0;
68-
$maxlen = 0;
70+
my$maxlen = 0;
71+
72+
my%entries;
6973

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;
7377

74-
open(FILE,"$docdir/$file")||next;
75-
$filecontent =join('', <FILE>);
78+
open(FILE,"$docdir/$file")ornext;
79+
my$filecontent =join('', <FILE>);
7680
close FILE;
7781

7882
# Ignore files that are not for SQL language statements
7983
$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;
10490

105-
if ($cmdname &&$cmddesc &&$cmdsynopsis) {
106-
$cmdname =~s/\"/\\"/g;
91+
if (@cmdnames &&$cmddesc &&$cmdsynopsis) {
92+
s/\"/\\"/gforeach@cmdnames;
10793

10894
$cmddesc =~s/<[^>]+>//g;
10995
$cmddesc =~s/\s+//g;
@@ -113,22 +99,24 @@
11399
$cmdsynopsis =~s/\r?\n/\\n/g;
114100
$cmdsynopsis =~s/\"/\\"/g;
115101

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+
}
120106
}
121107
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";
123109
}
124110
}
125111

112+
print OUT" {\"$_\",\n N_(\"".$entries{$_}{cmddesc}."\"),\n N_(\"".$entries{$_}{cmdsynopsis}."\") },\n\n"foreach (sortkeys%entries);
113+
126114
print OUT"
127115
{ NULL, NULL, NULL } /* End of list marker */
128116
};
129117
130118
131-
#define QL_HELP_COUNT$count/* number of help items */
119+
#define QL_HELP_COUNT".scalar(keys%entries)."/* number of help items */
132120
#define QL_MAX_CMD_LEN$maxlen/* largest strlen(cmd) */
133121
134122

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp