Merge "Build and package Layer Management service binaries." into tizen
[profile/ivi/layer-management.git] / scripts / check_single_statement_on_line.py
1 #!/usr/bin/python
2
3 ###########################################################################
4 #
5 # Copyright 2013 BMW Car IT GmbH
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #        http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 ###########################################################################
20
21 import sys, re, string
22 from common_modules.common import *
23
24 def check_single_statement_on_line(filename, file_contents, clean_file_contents, file_lines, clean_file_lines):
25     """
26     Checks if there are several statements on the same line
27
28     """
29     open_parantheses_count = 0
30
31     for i in range(len(file_lines)):
32         line = clean_file_lines[i]
33
34         open_parantheses_count += line.count("(") - line.count(")")
35
36         #check if there are several semicolons on the line and that is not in the middle of a for statement
37         if line.count(";") > 1 and open_parantheses_count == 0:
38             #check that there is NO right parentheses after semicolon
39             if line.rfind(";") > line.rfind(")"):
40                 log_warning(filename, i + 1, "several statements on same line", file_lines[i].strip(" "))
41
42 if __name__ == "__main__":
43     targets = sys.argv[1:]
44     targets = get_all_files(targets)
45
46     if len(targets) == 0:
47         print """
48 \t**** No input provided ****
49 \tTakes a list of files/directories as input and performs specific style checking on all files/directories.
50
51 \tGives warnings if a line contains several statements.
52 """
53         exit(0)
54
55     for t in targets:
56         if t[-2:] == ".h" or t[-4:] == ".cpp" or t[-2] == ".c":
57             file_contents, clean_file_contents, file_lines, clean_file_lines = read_file(t)
58             check_single_statement_on_line(t, file_contents, clean_file_contents, file_lines, clean_file_lines)