diff options
author | Adam Sampson <ats@offog.org> | 2013-07-16 14:17:18 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2013-07-17 21:38:49 +0200 |
commit | bef38b98c0536d81c0e4b2e78a9182e1df1d451c (patch) | |
tree | 74e819723504b4a54f3af85963703992f92b1035 /doc/scripts | |
parent | 65d19ef39b03d23b171d5546e062e7c846264aa4 (diff) | |
download | gnutls-bef38b98c0536d81c0e4b2e78a9182e1df1d451c.tar.gz |
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 <ats@offog.org>
Diffstat (limited to 'doc/scripts')
-rwxr-xr-x | doc/scripts/gdoc | 72 |
1 files 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, '"<i>$1</i>"', - $type_func, '"<b>$1</b>"', - $type_struct, '"<i>$1</i>"', - $type_param, '" <tt><b>$1</b></tt> "' ); +@highlights_html = ( [$type_constant, '"<i>$1</i>"'], + [$type_func, '"<b>$1</b>"'], + [$type_struct, '"<i>$1</i>"'], + [$type_param, '" <tt><b>$1</b></tt> "'] ); $blankline_html = "<p>"; -%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, '"<replaceable class=\"option\">$1</replaceable>"', - $type_func, '"<function>$1</function>"', - $type_struct, '"<structname>$1</structname>"', - $type_env, '"<envar>$1</envar>"', - $type_param, '" <parameter>$1</parameter> "' ); +@highlights_sgml = ( [$type_constant, '"<replaceable class=\"option\">$1</replaceable>"'], + [$type_func, '"<function>$1</function>"'], + [$type_struct, '"<structname>$1</structname>"'], + [$type_env, '"<envar>$1</envar>"'], + [$type_param, '" <parameter>$1</parameter> "'] ); $blankline_sgml = "</para><para>\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) { |