Lines Matching +full:in +full:- +full:line

12 # notice appear in all copies and that both that copyright notice and
13 # this permission notice appear in supporting documentation, and that
14 # the name of M.I.T. not be used in advertising or publicity pertaining
17 # your software as modified software and not distribute it in such a
24 # violations in a single file. Checked violations include:
26 # Line is too long
30 # Preprocessor statements in function bodies
32 # Space before paren in function call, or no space after if/for/while
34 # Space after cast operator, or no space before * in cast operator
35 # Line broken before binary operator
39 # Lack of braces around 2+ line flow control body
40 # Incorrect indentation as determined by emacs c-mode (if possible)
44 # Anything outside of a function body except line length/whitespace
45 # Anything non-syntactic (proper cleanup flow control, naming, etc.)
46 # UTF-8 violations
48 # Inner-scope variable declarations
49 # Over- or under-parenthesization
67 if 'c-basic-offset: 4; indent-tabs-mode: nil' not in lines[0]:
71 cstyle_el = os.path.join(util_dir, 'krb5-c-style.el')
72 reindent_el = os.path.join(util_dir, 'krb5-batch-reindent.el')
76 args = ['emacs', '-q', '-batch', '-l', cstyle_el, '-l', reindent_el,
92 def check_length(line, ln): argument
93 if len(line) > 79 and not line.startswith(' * Copyright'):
97 def check_tabs(line, ln, allow_tabs, seen_tab): argument
99 if '\t' in line:
100 warn(ln, 'Tab character in file which does not allow tabs')
102 if ' \t' in line:
104 if ' ' in line and seen_tab:
105 warn(ln, '8+ spaces in file which uses tabs')
108 def check_trailing_whitespace(line, ln): argument
109 if line and line[-1] in ' \t':
116 warn(ln, 'Multi-line comment begins after code')
117 for line in lines[1:]:
119 if len(line) <= align or line[align] != '*':
120 warn(ln, 'Comment line does not have * aligned with top')
121 elif line[:align].lstrip() != '':
122 warn(ln, 'Garbage before * in comment line')
123 if not lines[-1].rstrip().endswith('*/'):
124 warn(ln, 'Code after end of multi-line comment')
125 if len(lines) > 2 and (lines[0].strip() not in ('/*', '/**') or
126 lines[-1].strip() != '*/'):
130 def check_preprocessor(line, ln): argument
131 if line.startswith('#'):
132 warn(ln, 'Preprocessor statement in function body')
135 def check_braces(line, ln): argument
136 # Strip out one-line initializer expressions.
137 line = re.sub(r'=\s*{.*}', '', line)
138 if line.lstrip().startswith('{') and not line.startswith('{'):
139 warn(ln, 'Un-cuddled open brace')
140 if re.search(r'{\s*\S', line):
141 warn(ln, 'Code on line after open brace')
142 if re.search(r'\S.*}', line):
143 warn(ln, 'Code on line before close brace')
148 def check_space_before_paren(line, ln): argument
149 for m in re.finditer(r'([\w]+)(\s*)\(', line):
151 if ident in ('void', 'char', 'int', 'long', 'unsigned'):
153 elif ident in ('if', 'for', 'while', 'switch'):
158 warn(ln, 'Space before parenthesis in function call')
160 if re.search(r' \)', line):
164 def check_parenthesized_return(line, ln): argument
165 if re.search(r'return\s*\(.*\);', line):
169 def check_cast(line, ln): argument
181 for m in re.finditer(r'\(([^(]+)\)(\s*)[a-zA-Z_(]', line):
186 warn(ln, 'No space before * in cast operator')
189 def check_binary_operator(line, ln): argument
190 binop = r'(\+|-|\*|/|%|\^|==|=|!=|<=|<|>=|>|&&|&|\|\||\|)'
191 if re.match(r'\s*' + binop + r'\s', line):
192 warn(ln - 1, 'Line broken before binary operator')
193 for m in re.finditer(r'(\s|\w)' + binop + r'(\s|\w)', line):
199 elif op not in ('-', '*', '&') and not after.isspace():
203 def check_assignment_in_conditional(line, ln): argument
204 # Check specifically for if statements; we allow assignments in
206 if re.search(r'if\s*\(+\w+\s*=[^=]', line):
207 warn(ln, 'Assignment in if conditional')
210 def indent(line): argument
211 return len(re.match(r'\s*', line).group(0).expandtabs())
214 def check_unbraced_flow_body(line, ln, lines): argument
215 if re.match(r'\s*do$', line):
219 m = re.match(r'\s*(})?\s*else(\s*if\s*\(.*\))?\s*({)?\s*$', line)
223 if (re.match(r'\s*(if|else if|for|while)\s*\(.*\)$', line) or
224 re.match(r'\s*else$', line)):
225 base = indent(line)
226 # Look at the next two lines (ln is 1-based so lines[ln] is next).
231 def check_bad_string_fn(line, ln): argument
233 if re.search(r'\W(strcpy|strcat|sprintf|\w*scanf)\W', line):
237 def check_indentation(line, indented_lines, ln): argument
241 if ln - 1 >= len(indented_lines):
244 if line.strip() == '':
245 warn(ln, 'Trailing blank line')
248 if line != indented_lines[ln - 1].rstrip('\r\n'):
256 allow_tabs = 'indent-tabs-mode: nil' not in lines[0]
263 for line in lines:
265 line = line.rstrip('\r\n')
266 seen_tab = seen_tab or ('\t' in line)
268 # Check line structure issues before altering the line.
269 check_indentation(line, indented_lines, ln)
270 check_length(line, ln)
271 check_tabs(line, ln, allow_tabs, seen_tab)
272 check_trailing_whitespace(line, ln)
274 # Strip out single-line comments the contents of string literals.
276 line = re.sub(r'/\*.*?\*/', '', line)
277 line = re.sub(r'"(\\.|[^"])*"', '""', line)
279 # Parse out and check multi-line comments. (Ignore code on
280 # the first or last line; check_comment will warn about it.)
281 if comment or '/*' in line:
282 comment.append(line)
283 if '*/' in line:
284 check_comment(comment, ln - len(comment) + 1)
289 if '//' in line:
291 line = re.sub(r'//.*/', '', line)
293 if line.startswith('{'):
295 elif line.startswith('}'):
299 check_preprocessor(line, ln)
300 check_braces(line, ln)
301 check_space_before_paren(line, ln)
302 check_parenthesized_return(line, ln)
303 check_cast(line, ln)
304 check_binary_operator(line, ln)
305 check_assignment_in_conditional(line, ln)
306 check_unbraced_flow_body(line, ln, lines)
307 check_bad_string_fn(line, ln)
309 if lines[-1] == '':
310 warn(ln, 'Blank line at end of file')
320 sys.stderr.write('Usage: cstyle-file [filename]\n')