nat: use correct data types for memory sizes
[vpp.git] / doxygen / filter_h.py
1 #!/usr/bin/env python3
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 .c files to make various preprocessor tricks Doxygenish
17
18 import os
19 import re
20 import sys
21
22 if len(sys.argv) < 2:
23     sys.stderr.write("Usage: %s <filename>\n" % (sys.argv[0]))
24     sys.exit(1)
25
26 replace_patterns = [
27     # Search for CLIB_PAD_FROM_TO(...); and replace with padding
28     # #define CLIB_PAD_FROM_TO(from,to) u8 pad_##from[(to) - (from)]
29     (re.compile(r"(?P<m>CLIB_PAD_FROM_TO)\s*[(](?P<from>[^,]+),"
30                 r"\s*(?P<to>[^)]+)[)]"),
31      r"/** Padding. */ u8 pad_\g<from>[(\g<to>) - (\g<from>)]"),
32
33 ]
34
35
36 filename = sys.argv[1]
37 cwd = os.getcwd()
38 if filename[0:len(cwd)] == cwd:
39     filename = filename[len(cwd):]
40     if filename[0] == "/":
41         filename = filename[1:]
42
43 with open(filename) as fd:
44     line_num = 0
45
46     for line in fd:
47         line_num += 1
48         str = line[:-1]  # filter \n
49
50         # Look for search/replace patterns
51         for p in replace_patterns:
52             str = p[0].sub(p[1], str)
53
54         sys.stdout.write(str+"\n")
55
56 # All done