#!/usr/bin/python # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. # # Use of this source code is governed by a BSD-style license # that can be found in the LICENSE file in the root of the source # tree. An additional intellectual property rights grant can be found # in the file PATENTS. All contributing project authors may # be found in the AUTHORS file in the root of the source tree. """WebRTC reformat script. This script is used to reformat WebRTC code from the old code style to Google C++ code style. This script does not indent code; use clang-reformat-chrome.py as described in go/webrtc/engineering/reformatting-gips---google. """ __author__ = 'mflodman@webrtc.org (Magnus Flodman)' import fnmatch import os import re import subprocess import sys def LowerWord(obj): """Helper for DeCamelCase.""" optional_last_letters = obj.group(3) or '' return obj.group(1) + '_' + obj.group(2).lower() + optional_last_letters def DeCamelCase(text): """De-camelize variable names.""" pattern = re.compile(r'(?<=[ _*\(\&\!])([a-z]+)(?' % sys.argv[0] sys.exit(1) for filename in args: f = open(filename) text = f.read() f.close() text = DeCamelCase(text) text = MoveUnderScore(text) text = PostfixToPrefixInForLoops(text) text = CPPComments(text) text = AddHeaderPath(text) text = AddWebrtcPrefixToOldSrcRelativePaths(text) text = SortIncludeHeaders(text, filename) # Remove the original file and re-create it with the reformatted content. SaveFile(filename, text) if filename.endswith('.h'): f = open(filename) text = f.read() f.close() text = FixIncludeGuards(text, filename) SaveFile(filename, text) print filename + ' done.' if __name__ == '__main__': main()