Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ea46ddc

Browse files
committed
Tweak create_help.pl so it will work under either perl 4.* or perl 5.*.
Remove knowledge of path to documentation source directory from perl script, instead have Makefile pass it to script.
1 parent aae70b2 commit ea46ddc

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

src/bin/psql/Makefile.in

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
#
88
#
99
# IDENTIFICATION
10-
# $Header: /cvsroot/pgsql/src/bin/psql/Attic/Makefile.in,v 1.22 2000/04/14 23:43:44 petere Exp $
10+
# $Header: /cvsroot/pgsql/src/bin/psql/Attic/Makefile.in,v 1.23 2000/04/16 18:07:22 tgl Exp $
1111
#
1212
#-------------------------------------------------------------------------
1313

1414
SRCDIR= ../..
15-
include ../../Makefile.global
15+
include $(SRCDIR)/Makefile.global
1616

17-
CFLAGS:= -I$(LIBPQDIR) $(CFLAGS)
17+
DOCDIR= $(SRCDIR)/../doc/src/sgml/ref
18+
19+
CFLAGS+= -I$(LIBPQDIR)
1820

1921
#
2022
# And where libpq goes, so goes the authentication stuff...
@@ -61,8 +63,8 @@ psql: $(OBJS) $(LIBPQDIR)/libpq.a
6163
help.o: sql_help.h
6264

6365
ifneq ($(strip $(PERL)),)
64-
sql_help.h: $(wildcard $(SRCDIR)/../doc/src/sgml/ref/*.sgml) create_help.pl
65-
$(PERL) create_help.pl sql_help.h
66+
sql_help.h: $(wildcard $(DOCDIR)/*.sgml) create_help.pl
67+
$(PERL) create_help.pl $(DOCDIR) sql_help.h
6668
else
6769
sql_help.h:
6870
@echo "*** Perl is needed to build psql help."

src/bin/psql/create_help.pl

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
# Copyright 2000 by PostgreSQL Global Development Group
77
#
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 $
99
#################################################################
1010

1111
#
@@ -14,20 +14,22 @@
1414
# enough that this worked, but this here is by no means an SGML
1515
# parser.
1616
#
17-
# Call: perl create_help.pl sql_help.h
17+
# Call: perl create_help.pl docdir sql_help.h
1818
# The name of the header file doesn't matter to this script, but it
1919
# sure does matter to the rest of the source.
2020
#
2121

22-
$docdir = "./../../../doc/src/sgml/ref";
23-
$outputfile = $ARGV[0] or die "$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";
2424

2525
$define = $outputfile;
2626
$define =~ tr/a-z/A-Z/;
2727
$define =~ s/\W/_/g;
2828

29-
opendir DIR, $docdir or die "$0: could not open documentation sources: $!\n";
30-
open OUT, ">$outputfile" or die "$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";
3133

3234
print OUT
3335
"/*
@@ -57,29 +59,48 @@
5759
$count = 0;
5860

5961
foreach $file (sort readdir DIR) {
60-
my ($cmdname, $cmddesc, $cmdsynopsis);
62+
local ($cmdname, $cmddesc, $cmdsynopsis);
6163
$file =~ /\.sgml$/ || next;
6264

63-
open FILE, "$docdir/$file" or next;
65+
open(FILE, "$docdir/$file") || next;
6466
$filecontent = join('', <FILE>);
6567
close FILE;
6668

69+
# Ignore files that are not for SQL language statements
6770
$filecontent =~ m!<refmiscinfo>\s*SQL - Language Statements\s*</refmiscinfo>!i
68-
or next;
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+
}
7495

7596
if ($cmdname && $cmddesc && $cmdsynopsis) {
7697
$cmdname =~ s/\"/\\"/g;
7798

78-
$cmddesc =~ s/<\/?.+?>//sg;
79-
$cmddesc =~ s/\n/ /g;
99+
$cmddesc =~ s/<[^>]+>//g;
100+
$cmddesc =~ s/\s+/ /g;
80101
$cmddesc =~ s/\"/\\"/g;
81102

82-
$cmdsynopsis =~ s/<\/?.+?>//sg;
103+
$cmdsynopsis =~ s/<[^>]+>//g;
83104
$cmdsynopsis =~ s/\n/\\n/g;
84105
$cmdsynopsis =~ s/\"/\\"/g;
85106

0 commit comments

Comments
 (0)