filter_api.py revision 440cde68
1#!/usr/bin/env python
2# Copyright (c) 2016 Comcast Cable Communications Management, LLC.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at:
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Filter for vpe.api to make it Doxygenish.
17
18import sys, re
19
20if len(sys.argv) < 2:
21    sys.stderr.write("Usage: %s <filename>\n" % (sys.argv[0]))
22    sys.exit(1)
23
24patterns = [
25    # Search for "define" blocks and treat them as structs
26    ( re.compile(r"^.*(manual_.[^\s]+\s+)?define\s+(?P<name>[^\s]+)"), r"typedef struct vl_api_\g<name>_t"),
27
28    # For every "brief" statement at the start of a comment block, add an
29    # xref with whatever is on the same line. This gives us an index page
30    # with all the API methods in one place.
31    # XXX Commented out for now; works but duplicates the brief text in the
32    # struct documentation
33    #( re.compile(r"/\*\*\s*(?P<b>[\\@]brief)\s+(?P<c>.+)(\*/)$"), r'/** @xrefitem api "" "VPP API" \g<c> \g<b> \g<c>'),  # capture inline comment close
34    #( re.compile(r"/\*\*\s*(?P<b>[\\@]brief)\s+(?P<c>.+)$"), r'/** @xrefitem api "" "VPP API" \g<c> \g<b> \g<c>'),
35
36    # Since structs don't have params, replace @param with @tparam
37    ( re.compile("[\\@]param\\b"), "@tparam"),
38]
39
40with open(sys.argv[1]) as fd:
41    for line in fd:
42        str = line[:-1] # strip \n
43        for p in patterns:
44            str = p[0].sub(p[1], str)
45        sys.stdout.write(str+"\n")
46