2 # Copyright (c) 2016 Comcast Cable Communications Management, LLC.
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:
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # Filter for .c files to make various preprocessor tricks Doxygenish
23 sys.stderr.write("Usage: %s <filename>\n" % (sys.argv[0]))
27 # Search for CLIB_PAD_FROM_TO(...); and replace with padding
28 # #define CLIB_PAD_FROM_TO(from,to) u8 pad_##from[(to) - (from)]
31 r"(?P<m>CLIB_PAD_FROM_TO)\s*[(](?P<from>[^,]+)," r"\s*(?P<to>[^)]+)[)]"
33 r"/** Padding. */ u8 pad_\g<from>[(\g<to>) - (\g<from>)]",
38 filename = sys.argv[1]
40 if filename[0 : len(cwd)] == cwd:
41 filename = filename[len(cwd) :]
42 if filename[0] == "/":
43 filename = filename[1:]
45 with open(filename) as fd:
50 str = line[:-1] # filter \n
52 # Look for search/replace patterns
53 for p in replace_patterns:
54 str = p[0].sub(p[1], str)
56 sys.stdout.write(str + "\n")