5 ## Copyright (C) 2015 Intel Corporation ##
7 ## This software falls under the GNU General Public License. ##
8 ## Please read the COPYING file for more information ##
11 # This software reads a XML file and a list of valid interal
12 # references to replace Docbook tags with links.
14 # The list of "valid internal references" must be one-per-line in the following format:
19 # The software walks over the XML file looking for xml tags representing possible references
20 # to the Document. Each reference will be cross checked against the "Valid Internal Reference" list. If
21 # the referece is found it replaces its content by a <link> tag.
24 # kernel-doc-xml-ref -db filename
25 # xml filename > outputfile
32 #Holds the database filename
41 "<function>(.*?)</function>",
42 "\"<function>\" . convert_function(\$1, \$line) . \"</function>\"",
43 "<structname>(.*?)</structname>",
44 "\"<structname>\" . convert_struct(\$1) . \"</structname>\"",
45 "<funcdef>(.*?)<function>(.*?)</function></funcdef>",
46 "\"<funcdef>\" . convert_param(\$1) . \"<function>\$2</function></funcdef>\"",
47 "<paramdef>(.*?)<parameter>(.*?)</parameter></paramdef>",
48 "\"<paramdef>\" . convert_param(\$1) . \"<parameter>\$2</parameter></paramdef>\"");
50 while($ARGV[0] =~ m/^-(.*)/) {
51 my $cmd = shift @ARGV;
53 $databasefile = shift @ARGV
58 $inputfile = shift @ARGV;
61 open (my $handle, '<', $databasefile) or die "Cannot open $databasefile";
62 chomp(my @lines = <$handle>);
72 foreach my $pattern (keys %highlights) {
73 $dohighlight .= "\$line =~ s:$pattern:$highlights{$pattern}:eg;\n";
76 open(FILE
, $inputfile) or die("Could not open $inputfile") or die ("Cannot open $inputfile");
77 foreach my $line (<FILE
>) {
86 $str =~ s/^\s+|\s+$//g;
90 sub has_key_defined
($_)
92 if ( grep( /^$_[0]$/, @database)) {
98 # Gets a <function> content and add it a hyperlink if possible.
99 sub convert_function
($_)
108 $key =~ s/[^A-Za-z0-9]/-/g;
109 $key = "API-" . $key;
111 # We shouldn't add links to <funcdef> prototype
112 if (!has_key_defined
($key) || $line =~ m/\s+<funcdef/i) {
118 if ($arg =~ /(.*?)( ?)$/) {
122 return "<link linkend=\"$key\">$head</link>$tail";
125 # Converting a struct text to link
126 sub convert_struct
($_)
130 $key =~ s/(struct )?(\w)/$2/g;
131 $key =~ s/[^A-Za-z0-9]/-/g;
132 $key = "API-struct-" . $key;
134 if (!has_key_defined
($key)) {
138 my ($head, $tail) = split_pointer
($arg);
139 return "<link linkend=\"$key\">$head</link>$tail";
142 # Identify "object *" elements
143 sub split_pointer
($_)
146 if ($arg =~ /(.*?)( ?\* ?)/) {
152 sub convert_param
($_)
155 my $keyname = convert_key_name
($type);
157 if (!has_key_defined
($keyname)) {
161 my ($head, $tail) = split_pointer
($type);
162 return "<link linkend=\"$keyname\">$head</link>$tail";
166 # DocBook links are in the API-<TYPE>-<STRUCT-NAME> format
167 # This method gets an element and returns a valid DocBook reference for it.
168 sub convert_key_name
($_)
170 #Pattern $2 is optional and might be uninitialized
171 no warnings
'uninitialized';
174 $str =~ s/(const|static)? ?(struct)? ?([a-zA-Z0-9_]+) ?(\*|&)?/$2 $3/g ;
177 $str =~ s/^\s+|\s+$//g;
180 $str =~ s/[^A-Za-z0-9]/-/g;
182 return "API-" . $str;
186 print "Usage: $0 -db database filename\n";
187 print " xml source file(s) > outputfile\n";
195 print STDERR
"$errors errors\n";