From: Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk> To: linux-doc@vger.kernel.org Cc: Randy Dunlap <rdunlap@infradead.org>, Daniel Vetter <daniel.vetter@ffwll.ch>, Laurent Pinchart <laurent.pinchart@ideasonboard.com>, Jonathan Corbet <corbet@lwn.net>, Herbert Xu <herbert@gondor.apana.org.au>, Stephan Mueller <smueller@chronox.de>, Michal Marek <mmarek@suse.cz>, linux-kernel@vger.kernel.org, intel-gfx <intel-gfx@lists.freedesktop.org>, dri-devel <dri-devel@lists.freedesktop.org>, Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk> Subject: [PATCH 2/4] scripts/kernel-doc: Replacing highlights hash by an array Date: Thu, 23 Jul 2015 15:16:25 -0300 [thread overview] Message-ID: <1437675387-25719-3-git-send-email-danilo.cesar@collabora.co.uk> (raw) In-Reply-To: <1437675387-25719-1-git-send-email-danilo.cesar@collabora.co.uk> The "highlight" code is very sensible to the order of the hash keys, but the order of the keys cannot be predicted on Perl. It generates faulty DocBook entries like: - @<function>device_for_each_child</function> We should use an array for that job, so we can guarantee that the order of the regex execution on dohighlight won't change. Signed-off-by: Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Stephan Mueller <smueller@chronox.de> Cc: Michal Marek <mmarek@suse.cz> Cc: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org Cc: intel-gfx <intel-gfx@lists.freedesktop.org> Cc: dri-devel <dri-devel@lists.freedesktop.org> --- scripts/kernel-doc | 104 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 44 deletions(-) diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 9922e66..a38a69a 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -182,59 +182,73 @@ my $type_env = '(\$\w+)'; # One for each output format # these work fairly well -my %highlights_html = ( $type_constant, "<i>\$1</i>", - $type_func, "<b>\$1</b>", - $type_struct_xml, "<i>\$1</i>", - $type_env, "<b><i>\$1</i></b>", - $type_param, "<tt><b>\$1</b></tt>" ); +my @highlights_html = ( + [$type_constant, "<i>\$1</i>"], + [$type_func, "<b>\$1</b>"], + [$type_struct_xml, "<i>\$1</i>"], + [$type_env, "<b><i>\$1</i></b>"], + [$type_param, "<tt><b>\$1</b></tt>"] + ); my $local_lt = "\\\\\\\\lt:"; my $local_gt = "\\\\\\\\gt:"; my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" # html version 5 -my %highlights_html5 = ( $type_constant, "<span class=\"const\">\$1</span>", - $type_func, "<span class=\"func\">\$1</span>", - $type_struct_xml, "<span class=\"struct\">\$1</span>", - $type_env, "<span class=\"env\">\$1</span>", - $type_param, "<span class=\"param\">\$1</span>" ); +my @highlights_html5 = ( + [$type_constant, "<span class=\"const\">\$1</span>"], + [$type_func, "<span class=\"func\">\$1</span>"], + [$type_struct_xml, "<span class=\"struct\">\$1</span>"], + [$type_env, "<span class=\"env\">\$1</span>"], + [$type_param, "<span class=\"param\">\$1</span>]"] + ); my $blankline_html5 = $local_lt . "br /" . $local_gt; # XML, docbook format -my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>", - $type_constant, "<constant>\$1</constant>", - $type_func, "<function>\$1</function>", - $type_struct_xml, "<structname>\$1</structname>", - $type_env, "<envar>\$1</envar>", - $type_param, "<parameter>\$1</parameter>" ); +my @highlights_xml = ( + ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], + [$type_constant, "<constant>\$1</constant>"], + [$type_struct_xml, "<structname>\$1</structname>"], + [$type_param, "<parameter>\$1</parameter>"], + [$type_func, "<function>\$1</function>"], + [$type_env, "<envar>\$1</envar>"] + ); my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; # gnome, docbook format -my %highlights_gnome = ( $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>" ); +my @highlights_gnome = ( + [$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>" ] + ); my $blankline_gnome = "</para><para>\n"; # these are pretty rough -my %highlights_man = ( $type_constant, "\$1", - $type_func, "\\\\fB\$1\\\\fP", - $type_struct, "\\\\fI\$1\\\\fP", - $type_param, "\\\\fI\$1\\\\fP" ); +my @highlights_man = ( + [$type_constant, "\$1"], + [$type_func, "\\\\fB\$1\\\\fP"], + [$type_struct, "\\\\fI\$1\\\\fP"], + [$type_param, "\\\\fI\$1\\\\fP"] + ); my $blankline_man = ""; # text-mode -my %highlights_text = ( $type_constant, "\$1", - $type_func, "\$1", - $type_struct, "\$1", - $type_param, "\$1" ); +my @highlights_text = ( + [$type_constant, "\$1"], + [$type_func, "\$1"], + [$type_struct, "\$1"], + [$type_param, "\$1"] + ); my $blankline_text = ""; # list mode -my %highlights_list = ( $type_constant, "\$1", - $type_func, "\$1", - $type_struct, "\$1", - $type_param, "\$1" ); +my @highlights_list = ( + [$type_constant, "\$1"], + [$type_func, "\$1"], + [$type_struct, "\$1"], + [$type_param, "\$1"] + ); my $blankline_list = ""; # read arguments @@ -249,7 +263,7 @@ my $verbose = 0; my $output_mode = "man"; my $output_preformatted = 0; my $no_doc_sections = 0; -my %highlights = %highlights_man; +my @highlights = @highlights_man; my $blankline = $blankline_man; my $modulename = "Kernel API"; my $function_only = 0; @@ -328,31 +342,31 @@ while ($ARGV[0] =~ m/^-(.*)/) { my $cmd = shift @ARGV; if ($cmd eq "-html") { $output_mode = "html"; - %highlights = %highlights_html; + @highlights = @highlights_html; $blankline = $blankline_html; } elsif ($cmd eq "-html5") { $output_mode = "html5"; - %highlights = %highlights_html5; + @highlights = @highlights_html5; $blankline = $blankline_html5; } elsif ($cmd eq "-man") { $output_mode = "man"; - %highlights = %highlights_man; + @highlights = @highlights_man; $blankline = $blankline_man; } elsif ($cmd eq "-text") { $output_mode = "text"; - %highlights = %highlights_text; + @highlights = @highlights_text; $blankline = $blankline_text; } elsif ($cmd eq "-docbook") { $output_mode = "xml"; - %highlights = %highlights_xml; + @highlights = @highlights_xml; $blankline = $blankline_xml; } elsif ($cmd eq "-list") { $output_mode = "list"; - %highlights = %highlights_list; + @highlights = @highlights_list; $blankline = $blankline_list; } elsif ($cmd eq "-gnome") { $output_mode = "gnome"; - %highlights = %highlights_gnome; + @highlights = @highlights_gnome; $blankline = $blankline_gnome; } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document $modulename = shift @ARGV; @@ -2587,9 +2601,11 @@ $kernelversion = get_kernel_version(); # generate a sequence of code that will splice in highlighting information # using the s// operator. -foreach my $pattern (keys %highlights) { -# print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n"; - $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n"; +foreach my $k (keys @highlights) { + my $pattern = $highlights[$k][0]; + my $result = $highlights[$k][1]; +# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; + $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; } # Read the file that maps relative names to absolute names for -- 2.1.4
WARNING: multiple messages have this Message-ID (diff)
From: Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk> To: linux-doc@vger.kernel.org Cc: Michal Marek <mmarek@suse.cz>, Herbert Xu <herbert@gondor.apana.org.au>, Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk>, Jonathan Corbet <corbet@lwn.net>, Stephan Mueller <smueller@chronox.de>, Daniel Vetter <daniel.vetter@ffwll.ch>, intel-gfx <intel-gfx@lists.freedesktop.org>, Randy Dunlap <rdunlap@infradead.org>, linux-kernel@vger.kernel.org, dri-devel <dri-devel@lists.freedesktop.org>, Laurent Pinchart <laurent.pinchart@ideasonboard.com> Subject: [PATCH 2/4] scripts/kernel-doc: Replacing highlights hash by an array Date: Thu, 23 Jul 2015 15:16:25 -0300 [thread overview] Message-ID: <1437675387-25719-3-git-send-email-danilo.cesar@collabora.co.uk> (raw) In-Reply-To: <1437675387-25719-1-git-send-email-danilo.cesar@collabora.co.uk> The "highlight" code is very sensible to the order of the hash keys, but the order of the keys cannot be predicted on Perl. It generates faulty DocBook entries like: - @<function>device_for_each_child</function> We should use an array for that job, so we can guarantee that the order of the regex execution on dohighlight won't change. Signed-off-by: Danilo Cesar Lemes de Paula <danilo.cesar@collabora.co.uk> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Stephan Mueller <smueller@chronox.de> Cc: Michal Marek <mmarek@suse.cz> Cc: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org Cc: intel-gfx <intel-gfx@lists.freedesktop.org> Cc: dri-devel <dri-devel@lists.freedesktop.org> --- scripts/kernel-doc | 104 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 44 deletions(-) diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 9922e66..a38a69a 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -182,59 +182,73 @@ my $type_env = '(\$\w+)'; # One for each output format # these work fairly well -my %highlights_html = ( $type_constant, "<i>\$1</i>", - $type_func, "<b>\$1</b>", - $type_struct_xml, "<i>\$1</i>", - $type_env, "<b><i>\$1</i></b>", - $type_param, "<tt><b>\$1</b></tt>" ); +my @highlights_html = ( + [$type_constant, "<i>\$1</i>"], + [$type_func, "<b>\$1</b>"], + [$type_struct_xml, "<i>\$1</i>"], + [$type_env, "<b><i>\$1</i></b>"], + [$type_param, "<tt><b>\$1</b></tt>"] + ); my $local_lt = "\\\\\\\\lt:"; my $local_gt = "\\\\\\\\gt:"; my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" # html version 5 -my %highlights_html5 = ( $type_constant, "<span class=\"const\">\$1</span>", - $type_func, "<span class=\"func\">\$1</span>", - $type_struct_xml, "<span class=\"struct\">\$1</span>", - $type_env, "<span class=\"env\">\$1</span>", - $type_param, "<span class=\"param\">\$1</span>" ); +my @highlights_html5 = ( + [$type_constant, "<span class=\"const\">\$1</span>"], + [$type_func, "<span class=\"func\">\$1</span>"], + [$type_struct_xml, "<span class=\"struct\">\$1</span>"], + [$type_env, "<span class=\"env\">\$1</span>"], + [$type_param, "<span class=\"param\">\$1</span>]"] + ); my $blankline_html5 = $local_lt . "br /" . $local_gt; # XML, docbook format -my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>", - $type_constant, "<constant>\$1</constant>", - $type_func, "<function>\$1</function>", - $type_struct_xml, "<structname>\$1</structname>", - $type_env, "<envar>\$1</envar>", - $type_param, "<parameter>\$1</parameter>" ); +my @highlights_xml = ( + ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], + [$type_constant, "<constant>\$1</constant>"], + [$type_struct_xml, "<structname>\$1</structname>"], + [$type_param, "<parameter>\$1</parameter>"], + [$type_func, "<function>\$1</function>"], + [$type_env, "<envar>\$1</envar>"] + ); my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; # gnome, docbook format -my %highlights_gnome = ( $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>" ); +my @highlights_gnome = ( + [$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>" ] + ); my $blankline_gnome = "</para><para>\n"; # these are pretty rough -my %highlights_man = ( $type_constant, "\$1", - $type_func, "\\\\fB\$1\\\\fP", - $type_struct, "\\\\fI\$1\\\\fP", - $type_param, "\\\\fI\$1\\\\fP" ); +my @highlights_man = ( + [$type_constant, "\$1"], + [$type_func, "\\\\fB\$1\\\\fP"], + [$type_struct, "\\\\fI\$1\\\\fP"], + [$type_param, "\\\\fI\$1\\\\fP"] + ); my $blankline_man = ""; # text-mode -my %highlights_text = ( $type_constant, "\$1", - $type_func, "\$1", - $type_struct, "\$1", - $type_param, "\$1" ); +my @highlights_text = ( + [$type_constant, "\$1"], + [$type_func, "\$1"], + [$type_struct, "\$1"], + [$type_param, "\$1"] + ); my $blankline_text = ""; # list mode -my %highlights_list = ( $type_constant, "\$1", - $type_func, "\$1", - $type_struct, "\$1", - $type_param, "\$1" ); +my @highlights_list = ( + [$type_constant, "\$1"], + [$type_func, "\$1"], + [$type_struct, "\$1"], + [$type_param, "\$1"] + ); my $blankline_list = ""; # read arguments @@ -249,7 +263,7 @@ my $verbose = 0; my $output_mode = "man"; my $output_preformatted = 0; my $no_doc_sections = 0; -my %highlights = %highlights_man; +my @highlights = @highlights_man; my $blankline = $blankline_man; my $modulename = "Kernel API"; my $function_only = 0; @@ -328,31 +342,31 @@ while ($ARGV[0] =~ m/^-(.*)/) { my $cmd = shift @ARGV; if ($cmd eq "-html") { $output_mode = "html"; - %highlights = %highlights_html; + @highlights = @highlights_html; $blankline = $blankline_html; } elsif ($cmd eq "-html5") { $output_mode = "html5"; - %highlights = %highlights_html5; + @highlights = @highlights_html5; $blankline = $blankline_html5; } elsif ($cmd eq "-man") { $output_mode = "man"; - %highlights = %highlights_man; + @highlights = @highlights_man; $blankline = $blankline_man; } elsif ($cmd eq "-text") { $output_mode = "text"; - %highlights = %highlights_text; + @highlights = @highlights_text; $blankline = $blankline_text; } elsif ($cmd eq "-docbook") { $output_mode = "xml"; - %highlights = %highlights_xml; + @highlights = @highlights_xml; $blankline = $blankline_xml; } elsif ($cmd eq "-list") { $output_mode = "list"; - %highlights = %highlights_list; + @highlights = @highlights_list; $blankline = $blankline_list; } elsif ($cmd eq "-gnome") { $output_mode = "gnome"; - %highlights = %highlights_gnome; + @highlights = @highlights_gnome; $blankline = $blankline_gnome; } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document $modulename = shift @ARGV; @@ -2587,9 +2601,11 @@ $kernelversion = get_kernel_version(); # generate a sequence of code that will splice in highlighting information # using the s// operator. -foreach my $pattern (keys %highlights) { -# print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n"; - $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n"; +foreach my $k (keys @highlights) { + my $pattern = $highlights[$k][0]; + my $result = $highlights[$k][1]; +# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; + $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; } # Read the file that maps relative names to absolute names for -- 2.1.4 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2015-07-23 18:18 UTC|newest] Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-07-23 18:16 [PATCH 0/4] Add support for Hyperlinks and Markup on kernel-doc Danilo Cesar Lemes de Paula 2015-07-23 18:16 ` [PATCH 1/4] scripts/kernel-doc: Adding cross-reference links to html documentation Danilo Cesar Lemes de Paula 2015-07-23 18:16 ` Danilo Cesar Lemes de Paula [this message] 2015-07-23 18:16 ` [PATCH 2/4] scripts/kernel-doc: Replacing highlights hash by an array Danilo Cesar Lemes de Paula 2015-07-23 18:16 ` [PATCH 3/4] scripts/kernel-doc: Adding infrastructure for markdown support Danilo Cesar Lemes de Paula 2015-07-23 18:16 ` Danilo Cesar Lemes de Paula 2015-07-23 18:16 ` [PATCH 4/4] drm/doc: Convert to markdown Danilo Cesar Lemes de Paula 2015-07-23 18:16 ` Danilo Cesar Lemes de Paula 2015-07-23 20:29 ` [PATCH 0/4] Add support for Hyperlinks and Markup on kernel-doc Jonathan Corbet 2015-08-13 23:09 ` Danilo Cesar Lemes de Paula 2015-08-13 23:20 ` Jonathan Corbet 2015-08-14 17:26 ` Danilo Cesar Lemes de Paula 2015-08-14 17:26 ` Danilo Cesar Lemes de Paula 2015-07-25 10:20 ` Stephan Mueller 2015-07-28 19:12 ` Danilo Cesar Lemes de Paula 2015-07-28 19:45 ` [PATCH v2 " Danilo Cesar Lemes de Paula 2015-07-28 19:45 ` [PATCH v2 1/4] scripts/kernel-doc: Adding cross-reference links to html documentation Danilo Cesar Lemes de Paula 2015-08-17 4:10 ` Jonathan Corbet 2015-08-17 4:10 ` Jonathan Corbet 2015-08-17 13:06 ` Danilo Cesar Lemes de Paula 2015-07-28 19:45 ` [PATCH v2 2/4] scripts/kernel-doc: Replacing highlights hash by an array Danilo Cesar Lemes de Paula 2015-07-28 19:45 ` Danilo Cesar Lemes de Paula 2015-11-17 10:40 ` Mauro Carvalho Chehab 2015-11-17 10:40 ` Mauro Carvalho Chehab 2015-11-17 14:44 ` Jonathan Corbet 2015-11-17 15:29 ` Mauro Carvalho Chehab 2015-11-17 15:48 ` Danilo Cesar Lemes de Paula 2015-11-17 15:48 ` Danilo Cesar Lemes de Paula 2015-11-18 0:21 ` Jonathan Corbet 2015-11-18 9:14 ` Mauro Carvalho Chehab 2015-11-18 9:14 ` Mauro Carvalho Chehab 2015-07-28 19:45 ` [PATCH v2 3/4] scripts/kernel-doc: Adding infrastructure for markdown support Danilo Cesar Lemes de Paula 2015-07-28 19:45 ` Danilo Cesar Lemes de Paula 2015-07-28 19:45 ` [PATCH v2 4/4] drm/doc: Convert to markdown Danilo Cesar Lemes de Paula 2015-07-28 19:45 ` Danilo Cesar Lemes de Paula
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1437675387-25719-3-git-send-email-danilo.cesar@collabora.co.uk \ --to=danilo.cesar@collabora.co.uk \ --cc=corbet@lwn.net \ --cc=daniel.vetter@ffwll.ch \ --cc=dri-devel@lists.freedesktop.org \ --cc=herbert@gondor.apana.org.au \ --cc=intel-gfx@lists.freedesktop.org \ --cc=laurent.pinchart@ideasonboard.com \ --cc=linux-doc@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=mmarek@suse.cz \ --cc=rdunlap@infradead.org \ --cc=smueller@chronox.de \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.