aboutsummaryrefslogtreecommitdiffstats
path: root/hostapd/doc/kerneldoc2doxygen.pl
blob: d46f7bd0786810d4b7d5bb21176e494a307cebf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/perl -w
#
##########################################################################
# Convert kernel-doc style comments to Doxygen comments.
##########################################################################
#
# This script reads a C source file from stdin, and writes
# to stdout.  Normal usage:
#
# $ mv file.c file.c.gtkdoc
# $ kerneldoc2doxygen.pl <file.c.gtkdoc >file.c
#
# Or to do the same thing with multiple files:
# $ perl -i.gtkdoc kerneldoc2doxygen.pl *.c *.h
#
# This script may also be suitable for use as a Doxygen input filter,
# but that has not been tested.
#
# Back up your source files before using this script!!
#
##########################################################################
# Copyright (C) 2003 Jonathan Foster <jon@jon-foster.co.uk>
# Copyright (C) 2005 Jouni Malinen <jkmaline@cc.hut.fi>
# (modified for kerneldoc format used in wpa_supplicant)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# or look at http://www.gnu.org/licenses/gpl.html
##########################################################################


##########################################################################
#
# This function converts a single comment from gtk-doc to Doxygen format.
# The parameter does not include the opening or closing lines
# (i.e. given a comment like this:
#    "/**\n"
#    " * FunctionName:\n"
#    " * @foo: This describes the foo parameter\n"
#    " * @bar: This describes the bar parameter\n"
#    " * @Returns: This describes the return value\n"
#    " *\n"
#    " * This describes the function.\n"
#    " */\n"
# This function gets:
#    " * FunctionName:\n"
#    " * @foo: This describes the foo parameter\n"
#    " * @bar: This describes the bar parameter\n"
#    " * @Returns: This describes the return value\n"
#    " *\n"
#    " * This describes the function.\n"
# And it returns:
#    " * This describes the function.\n"
#    " *\n"
#    " * @param foo This describes the foo parameter\n"
#    " * @param bar This describes the bar parameter\n"
#    " * @return This describes the return value\n"
# )
#
sub fixcomment {
    $t = $_[0];

    # " * func: foo" --> "\brief foo\n"
    # " * struct bar: foo" --> "\brief foo\n"
    # If this fails, not a kernel-doc comment ==> return unmodified.
    ($t =~ s/^[\t ]*\*[\t ]*(struct )?([^ \t\n]*) - ([^\n]*)/\\brief $3\n/s)
      or return $t;

    # " * Returns: foo" --> "\return foo"
    $t =~ s/\n[\t ]*\*[\t ]*Returns:/\n\\return/sig;

    # " * @foo: bar" --> "\param foo bar"
    # Handle two common typos: No ":", or "," instead of ":".
    $t =~ s/\n[\t ]*\*[\t ]*\@([^ :,]*)[:,]?[\t ]*/\n\\param $1 /sg;

    return $t;
}

##########################################################################
# Start of main code

# Read entire stdin into memory - one multi-line string.
$_ = do { local $/; <> };

s{^/\*\n \*}{/\*\* \\file\n\\brief};
s{ \* Copyright}{\\par Copyright\nCopyright};

# Fix any comments like "/*************" so they don't match.
# "/***" ===> "/* *"
s{/\*\*\*}{/\* \*}gs;

# The main comment-detection code.
s{
    (               # $1 = Open comment
        /\*\*       # Open comment
        (?!\*)      # Do not match /*** (redundant due to fixup above).
        [\t ]*\n?   # If 1st line is whitespace, match the lot (including the newline).
    )
    (.*?)           # $2 = Body of comment (multi-line)
    (               # $3 = Close comment
        (           # If possible, match the whitespace before the close-comment
            (?<=\n) # This part only matches after a newline
            [\t ]*  # Eat whitespace
        )?
        \*/         # Close comment
    )
 }
 {
    $1 . fixcomment($2) . $3
 }gesx;
# ^^^^ Modes: g - Global, match all occurances.
#             e - Evaluate the replacement as an expression.
#             s - Single-line - allows the pattern to match across newlines.
#             x - eXtended pattern, ignore embedded whitespace
#                 and allow comments.

# Write results to stdout
print $_;