From 1fba1a2e5acdf590d44bbbd8e6a20518ff903e18 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Tue, 16 Jul 2013 14:17:18 +0100 Subject: Avoid depending on hash order in gdoc. Previously, gdoc had a hash of regexp replacements for each output format, and applied the replacements in the order that "keys" returned for the hash. However, not all orders are safe -- and now that Perl 5.18 randomises hash order per-process, it only worked sometimes! For example, this order is OK: 'is a #gnutls_session_t structure.' '\@([A-Za-z0-9_]+)\s*' -> 'is a #gnutls_session_t structure.' '\%([A-Za-z0-9_]+)' -> 'is a #gnutls_session_t structure.' '\#([A-Za-z0-9_]+)' -> 'is a @code{gnutls_session_t} structure.' '([A-Za-z0-9_]+\(\))' -> 'is a @code{gnutls_session_t} structure.' This one, however, winds up producing invalid texinfo: 'is a #gnutls_session_t structure.' '\%([A-Za-z0-9_]+)' -> 'is a #gnutls_session_t structure.' '([A-Za-z0-9_]+\(\))' -> 'is a #gnutls_session_t structure.' '\#([A-Za-z0-9_]+)' -> 'is a @code{gnutls_session_t} structure.' '\@([A-Za-z0-9_]+)\s*' -> 'is a @code{code} {gnutls_session_t} structure.' This patch turns the hash into a list, so the replacements will always be done in the intended order. Signed-off-by: Adam Sampson --- doc/scripts/gdoc | 72 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/doc/scripts/gdoc b/doc/scripts/gdoc index 953cd574aa..dbe2efe30a 100755 --- a/doc/scripts/gdoc +++ b/doc/scripts/gdoc @@ -9,6 +9,8 @@ eval '(exit $?0)' && eval 'exec perl "$0" ${1+"$@"}' ## Copyright (c) 2001, 2002 Nikos Mavrogiannopoulos ## added -tex ## Copyright (c) 1998 Michael Zucchi +## Copyright (c) 2013 Adam Sampson +## made highlighting not depend on hash order, for Perl 5.18 # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -145,46 +147,46 @@ $type_env = "(\\\$[A-Za-z0-9_]+)"; # One for each output format # these work fairly well -%highlights_html = ( $type_constant, '"$1"', - $type_func, '"$1"', - $type_struct, '"$1"', - $type_param, '" $1 "' ); +@highlights_html = ( [$type_constant, '"$1"'], + [$type_func, '"$1"'], + [$type_struct, '"$1"'], + [$type_param, '" $1 "'] ); $blankline_html = "

"; -%highlights_texinfo = ( $type_param, '" \@code{$1} "', - $type_constant, '"\@code{$1} "', - $type_func, '"\@code{$1} "', - $type_struct, '"\@code{$1} "', +@highlights_texinfo = ( [$type_param, '" \@code{$1} "'], + [$type_constant, '"\@code{$1} "'], + [$type_func, '"\@code{$1} "'], + [$type_struct, '"\@code{$1} "'], ); $blankline_texinfo = ""; -%highlights_tex = ( $type_param, '" {\\\bf $1} "', - $type_constant, '"{\\\it $1}"', - $type_func, '"{\\\bf $1}"', - $type_struct, '"{\\\it $1}"', +@highlights_tex = ( [$type_param, '" {\\\bf $1} "'], + [$type_constant, '"{\\\it $1}"'], + [$type_func, '"{\\\bf $1}"'], + [$type_struct, '"{\\\it $1}"'], ); $blankline_tex = "\\\\"; # sgml, docbook format -%highlights_sgml = ( $type_constant, '"$1"', - $type_func, '"$1"', - $type_struct, '"$1"', - $type_env, '"$1"', - $type_param, '" $1 "' ); +@highlights_sgml = ( [$type_constant, '"$1"'], + [$type_func, '"$1"'], + [$type_struct, '"$1"'], + [$type_env, '"$1"'], + [$type_param, '" $1 "'] ); $blankline_sgml = "\n"; # these are pretty rough -%highlights_man = ( $type_constant, '"\\\fB$1\\\fP"', - $type_func, '"\\\fB$1\\\fP"', - $type_struct, '"\\\fB$1\\\fP"', - $type_param, '" \\\fI$1\\\fP "' ); +@highlights_man = ( [$type_constant, '"\\\fB$1\\\fP"'], + [$type_func, '"\\\fB$1\\\fP"'], + [$type_struct, '"\\\fB$1\\\fP"'], + [$type_param, '" \\\fI$1\\\fP "'] ); $blankline_man = ""; # text-mode -%highlights_text = ( $type_constant, '"$1"', - $type_func, '"$1"', - $type_struct, '"$1"', - $type_param, '"$1 "' ); +@highlights_text = ( [$type_constant, '"$1"'], + [$type_func, '"$1"'], + [$type_struct, '"$1"'], + [$type_param, '"$1 "'] ); $blankline_text = ""; my $lineprefix = ""; @@ -205,7 +207,7 @@ if ($#ARGV==-1) { $verbose = 0; $output_mode = "man"; -%highlights = %highlights_man; +@highlights = @highlights_man; $blankline = $blankline_man; $modulename = "API Documentation"; $sourceversion = strftime "%Y-%m-%d", localtime; @@ -214,27 +216,27 @@ while ($ARGV[0] =~ m/^-(.*)/) { $cmd = shift @ARGV; if ($cmd eq "-html") { $output_mode = "html"; - %highlights = %highlights_html; + @highlights = @highlights_html; $blankline = $blankline_html; } elsif ($cmd eq "-man") { $output_mode = "man"; - %highlights = %highlights_man; + @highlights = @highlights_man; $blankline = $blankline_man; } elsif ($cmd eq "-tex") { $output_mode = "tex"; - %highlights = %highlights_tex; + @highlights = @highlights_tex; $blankline = $blankline_tex; } elsif ($cmd eq "-texinfo") { $output_mode = "texinfo"; - %highlights = %highlights_texinfo; + @highlights = @highlights_texinfo; $blankline = $blankline_texinfo; } elsif ($cmd eq "-text") { $output_mode = "text"; - %highlights = %highlights_text; + @highlights = @highlights_text; $blankline = $blankline_text; } elsif ($cmd eq "-docbook") { $output_mode = "sgml"; - %highlights = %highlights_sgml; + @highlights = @highlights_sgml; $blankline = $blankline_sgml; } elsif ($cmd eq "-listfunc") { $output_mode = "listfunc"; @@ -308,9 +310,9 @@ sub just_highlight { my $line; my $ret = ""; - foreach $pattern (keys %highlights) { - #print "scanning pattern $pattern ($highlights{$pattern})\n"; - my $replace = $highlights{$pattern}; + foreach $highlight (@highlights) { + my ($pattern, $replace) = @$highlight; + #print "scanning pattern $pattern ($replace)\n"; $contents =~ s/$pattern/$replace/gees; } foreach $line (split "\n", $contents) { -- cgit v1.2.1