xref: /illumos-gate/usr/src/tools/onbld/Checks/WsCheck.py (revision d1855c8182d5cf1cd290336767a7c8e7537c13a2)
1#! /usr/bin/python
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright 2018 Gordon Ross <gordon.w.ross@gmail.com>
15#
16
17#
18# Check file for whitespace issues
19# (space tab, trailing space)
20#
21
22
23import time, re, sys
24
25stMsg = 'space tab sequences'
26twsMsg = 'has trailing spaces'
27
28def err(stream, fname, lineno, msg):
29	stream.write("%s:%d: %s\n" % (fname, lineno, msg))
30
31def wscheck(fh, output=sys.stderr):
32	lineno = 1
33	ret = 0
34
35	fname = fh.name
36
37	for line in fh:
38		if re.search(r' \t', line):
39			err(output, fname, lineno, stMsg);
40			ret = 1
41		if re.search(r'[ \t]$', line):
42			err(output, fname, lineno, twsMsg);
43			ret = 1
44		lineno += 1
45
46	return ret
47