3 ##########################################################################
4 # Convert kernel-doc style comments to Doxygen comments.
5 ##########################################################################
7 # This script reads a C source file from stdin, and writes
8 # to stdout. Normal usage:
10 # $ mv file.c file.c.gtkdoc
11 # $ kerneldoc2doxygen.pl <file.c.gtkdoc >file.c
13 # Or to do the same thing with multiple files:
14 # $ perl -i.gtkdoc kerneldoc2doxygen.pl *.c *.h
16 # This script may also be suitable for use as a Doxygen input filter,
17 # but that has not been tested.
19 # Back up your source files before using this script!!
21 ##########################################################################
22 # Copyright (C) 2003 Jonathan Foster <jon@jon-foster.co.uk>
23 # Copyright (C) 2005 Jouni Malinen <j@w1.fi>
24 # (modified for kerneldoc format used in wpa_supplicant)
26 # This program is free software; you can redistribute it and/or modify
27 # it under the terms of the GNU General Public License version 2 as
28 # published by the Free Software Foundation.
30 # This program is distributed in the hope that it will be useful,
31 # but WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 # GNU General Public License for more details.
35 # You should have received a copy of the GNU General Public License
36 # along with this program; if not, write to the Free Software
37 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 # or look at http://www.gnu.org/licenses/gpl.html
39 ##########################################################################
42 ##########################################################################
44 # This function converts a single comment from gtk-doc to Doxygen format.
45 # The parameter does not include the opening or closing lines
46 # (i.e. given a comment like this:
48 # " * FunctionName:\n"
49 # " * @foo: This describes the foo parameter\n"
50 # " * @bar: This describes the bar parameter\n"
51 # " * @Returns: This describes the return value\n"
53 # " * This describes the function.\n"
56 # " * FunctionName:\n"
57 # " * @foo: This describes the foo parameter\n"
58 # " * @bar: This describes the bar parameter\n"
59 # " * @Returns: This describes the return value\n"
61 # " * This describes the function.\n"
63 # " * This describes the function.\n"
65 # " * @param foo This describes the foo parameter\n"
66 # " * @param bar This describes the bar parameter\n"
67 # " * @return This describes the return value\n"
73 # " * func: foo" --> "\brief foo\n"
74 # " * struct bar: foo" --> "\brief foo\n"
75 # If this fails, not a kernel-doc comment ==> return unmodified.
76 ($t =~ s/^[\t ]*\*[\t ]*(struct )?([^ \t\n]*) - ([^\n]*)/\\brief $3\n/s)
79 # " * Returns: foo" --> "\return foo"
80 $t =~ s/\n[\t ]*\*[\t ]*Returns:/\n\\return/sig;
82 # " * @foo: bar" --> "\param foo bar"
83 # Handle two common typos: No ":", or "," instead of ":".
84 $t =~ s/\n[\t ]*\*[\t ]*\@([^ :,]*)[:,]?[\t ]*/\n\\param $1 /sg;
89 ##########################################################################
92 # Read entire stdin into memory - one multi-line string.
93 $_ = do { local $/; <> };
95 s{^/\*\n \*}{/\*\* \\file\n\\brief};
96 s{ \* Copyright}{\\par Copyright\nCopyright};
98 # Fix any comments like "/*************" so they don't match.
100 s{/\*\*\*}{/\* \*}gs;
102 # The main comment-detection code.
104 ( # $1 = Open comment
106 (?
!\
*) # Do not match /*** (redundant due to fixup above).
107 [\t ]*\n?
# If 1st line is whitespace, match the lot (including the newline).
109 (.*?
) # $2 = Body of comment (multi-line)
110 ( # $3 = Close comment
111 ( # If possible, match the whitespace before the close-comment
112 (?
<=\n) # This part only matches after a newline
113 [\t ]* # Eat whitespace
119 $1 . fixcomment
($2) . $3
121 # ^^^^ Modes: g - Global, match all occurances.
122 # e - Evaluate the replacement as an expression.
123 # s - Single-line - allows the pattern to match across newlines.
124 # x - eXtended pattern, ignore embedded whitespace
125 # and allow comments.
127 # Write results to stdout