Commit 22c40033 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

[media] docs-rst: parse-headers.pl: use the C domain for cross-references

Instead of keep using the normal reference, move to the C
domain ones. Using C domains everywhere will allow
cross-references between kAPI and uAPI docs.
Acked-by: default avatarJonathan Corbet <corbet@lwn.net>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent bcec7c21
...@@ -57,7 +57,7 @@ while (<IN>) { ...@@ -57,7 +57,7 @@ while (<IN>) {
$n =~ tr/A-Z/a-z/; $n =~ tr/A-Z/a-z/;
$n =~ tr/_/-/; $n =~ tr/_/-/;
$enum_symbols{$s} = $n; $enum_symbols{$s} = "\\ :ref:`$s <$n>`\\ ";
$is_enum = 0 if ($is_enum && m/\}/); $is_enum = 0 if ($is_enum && m/\}/);
next; next;
...@@ -69,7 +69,7 @@ while (<IN>) { ...@@ -69,7 +69,7 @@ while (<IN>) {
my $n = $1; my $n = $1;
$n =~ tr/A-Z/a-z/; $n =~ tr/A-Z/a-z/;
$ioctls{$s} = $n; $ioctls{$s} = "\\ :ref:`$s <$n>`\\ ";
next; next;
} }
...@@ -79,17 +79,15 @@ while (<IN>) { ...@@ -79,17 +79,15 @@ while (<IN>) {
$n =~ tr/A-Z/a-z/; $n =~ tr/A-Z/a-z/;
$n =~ tr/_/-/; $n =~ tr/_/-/;
$defines{$s} = $n; $defines{$s} = "\\ :ref:`$s <$n>`\\ ";
next; next;
} }
if ($ln =~ m/^\s*typedef\s+.*\s+([_\w][\w\d_]+);/) { if ($ln =~ m/^\s*typedef\s+([_\w][\w\d_]+)\s+(.*)\s+([_\w][\w\d_]+);/) {
my $s = $1; my $s = $2;
my $n = $1; my $n = $3;
$n =~ tr/A-Z/a-z/;
$n =~ tr/_/-/;
$typedefs{$s} = $n; $typedefs{$n} = "\\ :c:type:`$n <$s>`\\ ";
next; next;
} }
if ($ln =~ m/^\s*enum\s+([_\w][\w\d_]+)\s+\{/ if ($ln =~ m/^\s*enum\s+([_\w][\w\d_]+)\s+\{/
...@@ -97,11 +95,8 @@ while (<IN>) { ...@@ -97,11 +95,8 @@ while (<IN>) {
|| $ln =~ m/^\s*typedef\s*enum\s+([_\w][\w\d_]+)\s+\{/ || $ln =~ m/^\s*typedef\s*enum\s+([_\w][\w\d_]+)\s+\{/
|| $ln =~ m/^\s*typedef\s*enum\s+([_\w][\w\d_]+)$/) { || $ln =~ m/^\s*typedef\s*enum\s+([_\w][\w\d_]+)$/) {
my $s = $1; my $s = $1;
my $n = $1;
$n =~ tr/A-Z/a-z/;
$n =~ tr/_/-/;
$enums{$s} = $n; $enums{$s} = "enum :c:type:`$s`\\ ";
$is_enum = $1; $is_enum = $1;
next; next;
...@@ -112,11 +107,8 @@ while (<IN>) { ...@@ -112,11 +107,8 @@ while (<IN>) {
|| $ln =~ m/^\s*typedef\s*struct\s+([[_\w][\w\d_]+)$/ || $ln =~ m/^\s*typedef\s*struct\s+([[_\w][\w\d_]+)$/
) { ) {
my $s = $1; my $s = $1;
my $n = $1;
$n =~ tr/A-Z/a-z/;
$n =~ tr/_/-/;
$structs{$s} = $n; $structs{$s} = "struct :c:type:`$s`\\ ";
next; next;
} }
} }
...@@ -129,12 +121,9 @@ close IN; ...@@ -129,12 +121,9 @@ close IN;
my @matches = ($data =~ m/typedef\s+struct\s+\S+?\s*\{[^\}]+\}\s*(\S+)\s*\;/g, my @matches = ($data =~ m/typedef\s+struct\s+\S+?\s*\{[^\}]+\}\s*(\S+)\s*\;/g,
$data =~ m/typedef\s+enum\s+\S+?\s*\{[^\}]+\}\s*(\S+)\s*\;/g,); $data =~ m/typedef\s+enum\s+\S+?\s*\{[^\}]+\}\s*(\S+)\s*\;/g,);
foreach my $m (@matches) { foreach my $m (@matches) {
my $s = $m; my $s = $m;
my $n = $m;
$n =~ tr/A-Z/a-z/;
$n =~ tr/_/-/;
$typedefs{$s} = $n; $typedefs{$s} = "\\ :c:type:`$s`\\ ";
next; next;
} }
...@@ -142,6 +131,15 @@ foreach my $m (@matches) { ...@@ -142,6 +131,15 @@ foreach my $m (@matches) {
# Handle exceptions, if any # Handle exceptions, if any
# #
my %def_reftype = (
"ioctl" => ":ref",
"define" => ":ref",
"symbol" => ":ref",
"typedef" => ":c:type",
"enum" => ":c:type",
"struct" => ":c:type",
);
if ($file_exceptions) { if ($file_exceptions) {
open IN, $file_exceptions or die "Can't read $file_exceptions"; open IN, $file_exceptions or die "Can't read $file_exceptions";
while (<IN>) { while (<IN>) {
...@@ -175,29 +173,49 @@ if ($file_exceptions) { ...@@ -175,29 +173,49 @@ if ($file_exceptions) {
} }
# Parsers to replace a symbol # Parsers to replace a symbol
my ($type, $old, $new, $reftype);
if (m/^replace\s+ioctl\s+(\S+)\s+(\S+)/) { if (m/^replace\s+(\S+)\s+(\S+)\s+(\S+)/) {
$ioctls{$1} = $2 if (exists($ioctls{$1})); $type = $1;
$old = $2;
$new = $3;
} else {
die "Can't parse $file_exceptions: $_";
}
if ($new =~ m/^\:c\:(data|func|macro|type)\:\`(.+)\`/) {
$reftype = ":c:$1";
$new = $2;
} elsif ($new =~ m/\:ref\:\`(.+)\`/) {
$reftype = ":ref";
$new = $1;
} else {
$reftype = $def_reftype{$type};
}
$new = "$reftype:`$old <$new>`";
if ($type eq "ioctl") {
$ioctls{$old} = $new if (exists($ioctls{$old}));
next; next;
} }
if (m/^replace\s+define\s+(\S+)\s+(\S+)/) { if ($type eq "define") {
$defines{$1} = $2 if (exists($defines{$1})); $defines{$old} = $new if (exists($defines{$old}));
next; next;
} }
if (m/^replace\s+typedef\s+(\S+)\s+(\S+)/) { if ($type eq "symbol") {
$typedefs{$1} = $2 if (exists($typedefs{$1})); $enum_symbols{$old} = $new if (exists($enum_symbols{$old}));
next; next;
} }
if (m/^replace\s+enum\s+(\S+)\s+(\S+)/) { if ($type eq "typedef") {
$enums{$1} = $2 if (exists($enums{$1})); $typedefs{$old} = $new if (exists($typedefs{$old}));
next; next;
} }
if (m/^replace\s+symbol\s+(\S+)\s+(\S+)/) { if ($type eq "enum") {
$enum_symbols{$1} = $2 if (exists($enum_symbols{$1})); $enums{$old} = $new if (exists($enums{$old}));
next; next;
} }
if (m/^replace\s+struct\s+(\S+)\s+(\S+)/) { if ($type eq "struct") {
$structs{$1} = $2 if (exists($structs{$1})); $structs{$old} = $new if (exists($structs{$old}));
next; next;
} }
...@@ -238,9 +256,7 @@ my $start_delim = "[ \n\t\(\=\*\@]"; ...@@ -238,9 +256,7 @@ my $start_delim = "[ \n\t\(\=\*\@]";
my $end_delim = "(\\s|,|\\\\=|\\\\:|\\;|\\\)|\\}|\\{)"; my $end_delim = "(\\s|,|\\\\=|\\\\:|\\;|\\\)|\\}|\\{)";
foreach my $r (keys %ioctls) { foreach my $r (keys %ioctls) {
my $n = $ioctls{$r}; my $s = $ioctls{$r};
my $s = "\\ :ref:`$r <$n>`\\ ";
$r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g;
...@@ -250,9 +266,7 @@ foreach my $r (keys %ioctls) { ...@@ -250,9 +266,7 @@ foreach my $r (keys %ioctls) {
} }
foreach my $r (keys %defines) { foreach my $r (keys %defines) {
my $n = $defines{$r}; my $s = $defines{$r};
my $s = "\\ :ref:`$r <$n>`\\ ";
$r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g;
...@@ -262,9 +276,7 @@ foreach my $r (keys %defines) { ...@@ -262,9 +276,7 @@ foreach my $r (keys %defines) {
} }
foreach my $r (keys %enum_symbols) { foreach my $r (keys %enum_symbols) {
my $n = $enum_symbols{$r}; my $s = $enum_symbols{$r};
my $s = "\\ :ref:`$r <$n>`\\ ";
$r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g;
...@@ -274,9 +286,7 @@ foreach my $r (keys %enum_symbols) { ...@@ -274,9 +286,7 @@ foreach my $r (keys %enum_symbols) {
} }
foreach my $r (keys %enums) { foreach my $r (keys %enums) {
my $n = $enums{$r}; my $s = $enums{$r};
my $s = "\\ :ref:`enum $r <$n>`\\ ";
$r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g;
...@@ -286,9 +296,7 @@ foreach my $r (keys %enums) { ...@@ -286,9 +296,7 @@ foreach my $r (keys %enums) {
} }
foreach my $r (keys %structs) { foreach my $r (keys %structs) {
my $n = $structs{$r}; my $s = $structs{$r};
my $s = "\\ :ref:`struct $r <$n>`\\ ";
$r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g;
...@@ -298,18 +306,15 @@ foreach my $r (keys %structs) { ...@@ -298,18 +306,15 @@ foreach my $r (keys %structs) {
} }
foreach my $r (keys %typedefs) { foreach my $r (keys %typedefs) {
my $n = $typedefs{$r}; my $s = $typedefs{$r};
my $s = "\\ :ref:`$r <$n>`\\ ";
$r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g;
print "$r -> $s\n" if ($debug); print "$r -> $s\n" if ($debug);
$data =~ s/($start_delim)($r)$end_delim/$1$s$3/g; $data =~ s/($start_delim)($r)$end_delim/$1$s$3/g;
} }
$data =~ s/\\ \n/\n/g; $data =~ s/\\ ([\n\s])/\1/g;
# #
# Generate output file # Generate output file
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment