diff options
author | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2016-08-31 05:44:21 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2016-09-09 08:20:27 -0400 |
commit | 22c4003364437b4a3ddd36bd19b2080f1a20d372 (patch) | |
tree | 97a633d417d1300f80aa8ea98c59c6c1ae38850c | |
parent | bcec7c218d5aeb170d18c49a33f9bd36ddf9ee37 (diff) |
[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: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
-rwxr-xr-x | Documentation/sphinx/parse-headers.pl | 113 |
1 files changed, 59 insertions, 54 deletions
diff --git a/Documentation/sphinx/parse-headers.pl b/Documentation/sphinx/parse-headers.pl index 531c710fc73f..db0186a7618f 100755 --- a/Documentation/sphinx/parse-headers.pl +++ b/Documentation/sphinx/parse-headers.pl | |||
@@ -57,7 +57,7 @@ while (<IN>) { | |||
57 | $n =~ tr/A-Z/a-z/; | 57 | $n =~ tr/A-Z/a-z/; |
58 | $n =~ tr/_/-/; | 58 | $n =~ tr/_/-/; |
59 | 59 | ||
60 | $enum_symbols{$s} = $n; | 60 | $enum_symbols{$s} = "\\ :ref:`$s <$n>`\\ "; |
61 | 61 | ||
62 | $is_enum = 0 if ($is_enum && m/\}/); | 62 | $is_enum = 0 if ($is_enum && m/\}/); |
63 | next; | 63 | next; |
@@ -69,7 +69,7 @@ while (<IN>) { | |||
69 | my $n = $1; | 69 | my $n = $1; |
70 | $n =~ tr/A-Z/a-z/; | 70 | $n =~ tr/A-Z/a-z/; |
71 | 71 | ||
72 | $ioctls{$s} = $n; | 72 | $ioctls{$s} = "\\ :ref:`$s <$n>`\\ "; |
73 | next; | 73 | next; |
74 | } | 74 | } |
75 | 75 | ||
@@ -79,17 +79,15 @@ while (<IN>) { | |||
79 | $n =~ tr/A-Z/a-z/; | 79 | $n =~ tr/A-Z/a-z/; |
80 | $n =~ tr/_/-/; | 80 | $n =~ tr/_/-/; |
81 | 81 | ||
82 | $defines{$s} = $n; | 82 | $defines{$s} = "\\ :ref:`$s <$n>`\\ "; |
83 | next; | 83 | next; |
84 | } | 84 | } |
85 | 85 | ||
86 | if ($ln =~ m/^\s*typedef\s+.*\s+([_\w][\w\d_]+);/) { | 86 | if ($ln =~ m/^\s*typedef\s+([_\w][\w\d_]+)\s+(.*)\s+([_\w][\w\d_]+);/) { |
87 | my $s = $1; | 87 | my $s = $2; |
88 | my $n = $1; | 88 | my $n = $3; |
89 | $n =~ tr/A-Z/a-z/; | ||
90 | $n =~ tr/_/-/; | ||
91 | 89 | ||
92 | $typedefs{$s} = $n; | 90 | $typedefs{$n} = "\\ :c:type:`$n <$s>`\\ "; |
93 | next; | 91 | next; |
94 | } | 92 | } |
95 | if ($ln =~ m/^\s*enum\s+([_\w][\w\d_]+)\s+\{/ | 93 | if ($ln =~ m/^\s*enum\s+([_\w][\w\d_]+)\s+\{/ |
@@ -97,11 +95,8 @@ while (<IN>) { | |||
97 | || $ln =~ m/^\s*typedef\s*enum\s+([_\w][\w\d_]+)\s+\{/ | 95 | || $ln =~ m/^\s*typedef\s*enum\s+([_\w][\w\d_]+)\s+\{/ |
98 | || $ln =~ m/^\s*typedef\s*enum\s+([_\w][\w\d_]+)$/) { | 96 | || $ln =~ m/^\s*typedef\s*enum\s+([_\w][\w\d_]+)$/) { |
99 | my $s = $1; | 97 | my $s = $1; |
100 | my $n = $1; | ||
101 | $n =~ tr/A-Z/a-z/; | ||
102 | $n =~ tr/_/-/; | ||
103 | 98 | ||
104 | $enums{$s} = $n; | 99 | $enums{$s} = "enum :c:type:`$s`\\ "; |
105 | 100 | ||
106 | $is_enum = $1; | 101 | $is_enum = $1; |
107 | next; | 102 | next; |
@@ -112,11 +107,8 @@ while (<IN>) { | |||
112 | || $ln =~ m/^\s*typedef\s*struct\s+([[_\w][\w\d_]+)$/ | 107 | || $ln =~ m/^\s*typedef\s*struct\s+([[_\w][\w\d_]+)$/ |
113 | ) { | 108 | ) { |
114 | my $s = $1; | 109 | my $s = $1; |
115 | my $n = $1; | ||
116 | $n =~ tr/A-Z/a-z/; | ||
117 | $n =~ tr/_/-/; | ||
118 | 110 | ||
119 | $structs{$s} = $n; | 111 | $structs{$s} = "struct :c:type:`$s`\\ "; |
120 | next; | 112 | next; |
121 | } | 113 | } |
122 | } | 114 | } |
@@ -129,12 +121,9 @@ close IN; | |||
129 | my @matches = ($data =~ m/typedef\s+struct\s+\S+?\s*\{[^\}]+\}\s*(\S+)\s*\;/g, | 121 | my @matches = ($data =~ m/typedef\s+struct\s+\S+?\s*\{[^\}]+\}\s*(\S+)\s*\;/g, |
130 | $data =~ m/typedef\s+enum\s+\S+?\s*\{[^\}]+\}\s*(\S+)\s*\;/g,); | 122 | $data =~ m/typedef\s+enum\s+\S+?\s*\{[^\}]+\}\s*(\S+)\s*\;/g,); |
131 | foreach my $m (@matches) { | 123 | foreach my $m (@matches) { |
132 | my $s = $m; | 124 | my $s = $m; |
133 | my $n = $m; | ||
134 | $n =~ tr/A-Z/a-z/; | ||
135 | $n =~ tr/_/-/; | ||
136 | 125 | ||
137 | $typedefs{$s} = $n; | 126 | $typedefs{$s} = "\\ :c:type:`$s`\\ "; |
138 | next; | 127 | next; |
139 | } | 128 | } |
140 | 129 | ||
@@ -142,6 +131,15 @@ foreach my $m (@matches) { | |||
142 | # Handle exceptions, if any | 131 | # Handle exceptions, if any |
143 | # | 132 | # |
144 | 133 | ||
134 | my %def_reftype = ( | ||
135 | "ioctl" => ":ref", | ||
136 | "define" => ":ref", | ||
137 | "symbol" => ":ref", | ||
138 | "typedef" => ":c:type", | ||
139 | "enum" => ":c:type", | ||
140 | "struct" => ":c:type", | ||
141 | ); | ||
142 | |||
145 | if ($file_exceptions) { | 143 | if ($file_exceptions) { |
146 | open IN, $file_exceptions or die "Can't read $file_exceptions"; | 144 | open IN, $file_exceptions or die "Can't read $file_exceptions"; |
147 | while (<IN>) { | 145 | while (<IN>) { |
@@ -175,29 +173,49 @@ if ($file_exceptions) { | |||
175 | } | 173 | } |
176 | 174 | ||
177 | # Parsers to replace a symbol | 175 | # Parsers to replace a symbol |
176 | my ($type, $old, $new, $reftype); | ||
178 | 177 | ||
179 | if (m/^replace\s+ioctl\s+(\S+)\s+(\S+)/) { | 178 | if (m/^replace\s+(\S+)\s+(\S+)\s+(\S+)/) { |
180 | $ioctls{$1} = $2 if (exists($ioctls{$1})); | 179 | $type = $1; |
180 | $old = $2; | ||
181 | $new = $3; | ||
182 | } else { | ||
183 | die "Can't parse $file_exceptions: $_"; | ||
184 | } | ||
185 | |||
186 | if ($new =~ m/^\:c\:(data|func|macro|type)\:\`(.+)\`/) { | ||
187 | $reftype = ":c:$1"; | ||
188 | $new = $2; | ||
189 | } elsif ($new =~ m/\:ref\:\`(.+)\`/) { | ||
190 | $reftype = ":ref"; | ||
191 | $new = $1; | ||
192 | } else { | ||
193 | $reftype = $def_reftype{$type}; | ||
194 | } | ||
195 | $new = "$reftype:`$old <$new>`"; | ||
196 | |||
197 | if ($type eq "ioctl") { | ||
198 | $ioctls{$old} = $new if (exists($ioctls{$old})); | ||
181 | next; | 199 | next; |
182 | } | 200 | } |
183 | if (m/^replace\s+define\s+(\S+)\s+(\S+)/) { | 201 | if ($type eq "define") { |
184 | $defines{$1} = $2 if (exists($defines{$1})); | 202 | $defines{$old} = $new if (exists($defines{$old})); |
185 | next; | 203 | next; |
186 | } | 204 | } |
187 | if (m/^replace\s+typedef\s+(\S+)\s+(\S+)/) { | 205 | if ($type eq "symbol") { |
188 | $typedefs{$1} = $2 if (exists($typedefs{$1})); | 206 | $enum_symbols{$old} = $new if (exists($enum_symbols{$old})); |
189 | next; | 207 | next; |
190 | } | 208 | } |
191 | if (m/^replace\s+enum\s+(\S+)\s+(\S+)/) { | 209 | if ($type eq "typedef") { |
192 | $enums{$1} = $2 if (exists($enums{$1})); | 210 | $typedefs{$old} = $new if (exists($typedefs{$old})); |
193 | next; | 211 | next; |
194 | } | 212 | } |
195 | if (m/^replace\s+symbol\s+(\S+)\s+(\S+)/) { | 213 | if ($type eq "enum") { |
196 | $enum_symbols{$1} = $2 if (exists($enum_symbols{$1})); | 214 | $enums{$old} = $new if (exists($enums{$old})); |
197 | next; | 215 | next; |
198 | } | 216 | } |
199 | if (m/^replace\s+struct\s+(\S+)\s+(\S+)/) { | 217 | if ($type eq "struct") { |
200 | $structs{$1} = $2 if (exists($structs{$1})); | 218 | $structs{$old} = $new if (exists($structs{$old})); |
201 | next; | 219 | next; |
202 | } | 220 | } |
203 | 221 | ||
@@ -238,9 +256,7 @@ my $start_delim = "[ \n\t\(\=\*\@]"; | |||
238 | my $end_delim = "(\\s|,|\\\\=|\\\\:|\\;|\\\)|\\}|\\{)"; | 256 | my $end_delim = "(\\s|,|\\\\=|\\\\:|\\;|\\\)|\\}|\\{)"; |
239 | 257 | ||
240 | foreach my $r (keys %ioctls) { | 258 | foreach my $r (keys %ioctls) { |
241 | my $n = $ioctls{$r}; | 259 | my $s = $ioctls{$r}; |
242 | |||
243 | my $s = "\\ :ref:`$r <$n>`\\ "; | ||
244 | 260 | ||
245 | $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; | 261 | $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; |
246 | 262 | ||
@@ -250,9 +266,7 @@ foreach my $r (keys %ioctls) { | |||
250 | } | 266 | } |
251 | 267 | ||
252 | foreach my $r (keys %defines) { | 268 | foreach my $r (keys %defines) { |
253 | my $n = $defines{$r}; | 269 | my $s = $defines{$r}; |
254 | |||
255 | my $s = "\\ :ref:`$r <$n>`\\ "; | ||
256 | 270 | ||
257 | $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; | 271 | $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; |
258 | 272 | ||
@@ -262,9 +276,7 @@ foreach my $r (keys %defines) { | |||
262 | } | 276 | } |
263 | 277 | ||
264 | foreach my $r (keys %enum_symbols) { | 278 | foreach my $r (keys %enum_symbols) { |
265 | my $n = $enum_symbols{$r}; | 279 | my $s = $enum_symbols{$r}; |
266 | |||
267 | my $s = "\\ :ref:`$r <$n>`\\ "; | ||
268 | 280 | ||
269 | $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; | 281 | $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; |
270 | 282 | ||
@@ -274,9 +286,7 @@ foreach my $r (keys %enum_symbols) { | |||
274 | } | 286 | } |
275 | 287 | ||
276 | foreach my $r (keys %enums) { | 288 | foreach my $r (keys %enums) { |
277 | my $n = $enums{$r}; | 289 | my $s = $enums{$r}; |
278 | |||
279 | my $s = "\\ :ref:`enum $r <$n>`\\ "; | ||
280 | 290 | ||
281 | $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; | 291 | $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; |
282 | 292 | ||
@@ -286,9 +296,7 @@ foreach my $r (keys %enums) { | |||
286 | } | 296 | } |
287 | 297 | ||
288 | foreach my $r (keys %structs) { | 298 | foreach my $r (keys %structs) { |
289 | my $n = $structs{$r}; | 299 | my $s = $structs{$r}; |
290 | |||
291 | my $s = "\\ :ref:`struct $r <$n>`\\ "; | ||
292 | 300 | ||
293 | $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; | 301 | $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; |
294 | 302 | ||
@@ -298,18 +306,15 @@ foreach my $r (keys %structs) { | |||
298 | } | 306 | } |
299 | 307 | ||
300 | foreach my $r (keys %typedefs) { | 308 | foreach my $r (keys %typedefs) { |
301 | my $n = $typedefs{$r}; | 309 | my $s = $typedefs{$r}; |
302 | |||
303 | my $s = "\\ :ref:`$r <$n>`\\ "; | ||
304 | 310 | ||
305 | $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; | 311 | $r =~ s,([\_\`\*\<\>\&\\\\:\/]),\\\\$1,g; |
306 | 312 | ||
307 | print "$r -> $s\n" if ($debug); | 313 | print "$r -> $s\n" if ($debug); |
308 | |||
309 | $data =~ s/($start_delim)($r)$end_delim/$1$s$3/g; | 314 | $data =~ s/($start_delim)($r)$end_delim/$1$s$3/g; |
310 | } | 315 | } |
311 | 316 | ||
312 | $data =~ s/\\ \n/\n/g; | 317 | $data =~ s/\\ ([\n\s])/\1/g; |
313 | 318 | ||
314 | # | 319 | # |
315 | # Generate output file | 320 | # Generate output file |