1*cdf0c1d5Smjnelson#
2*cdf0c1d5Smjnelson# CDDL HEADER START
3*cdf0c1d5Smjnelson#
4*cdf0c1d5Smjnelson# The contents of this file are subject to the terms of the
5*cdf0c1d5Smjnelson# Common Development and Distribution License (the "License").
6*cdf0c1d5Smjnelson# You may not use this file except in compliance with the License.
7*cdf0c1d5Smjnelson#
8*cdf0c1d5Smjnelson# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*cdf0c1d5Smjnelson# or http://www.opensolaris.org/os/licensing.
10*cdf0c1d5Smjnelson# See the License for the specific language governing permissions
11*cdf0c1d5Smjnelson# and limitations under the License.
12*cdf0c1d5Smjnelson#
13*cdf0c1d5Smjnelson# When distributing Covered Code, include this CDDL HEADER in each
14*cdf0c1d5Smjnelson# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*cdf0c1d5Smjnelson# If applicable, add the following below this CDDL HEADER, with the
16*cdf0c1d5Smjnelson# fields enclosed by brackets "[]" replaced with your own identifying
17*cdf0c1d5Smjnelson# information: Portions Copyright [yyyy] [name of copyright owner]
18*cdf0c1d5Smjnelson#
19*cdf0c1d5Smjnelson# CDDL HEADER END
20*cdf0c1d5Smjnelson#
21*cdf0c1d5Smjnelson
22*cdf0c1d5Smjnelson#
23*cdf0c1d5Smjnelson# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*cdf0c1d5Smjnelson# Use is subject to license terms.
25*cdf0c1d5Smjnelson#
26*cdf0c1d5Smjnelson# ident	"%Z%%M%	%I%	%E% SMI"
27*cdf0c1d5Smjnelson#
28*cdf0c1d5Smjnelson
29*cdf0c1d5Smjnelson#
30*cdf0c1d5Smjnelson# CStyle, wrap the cstyle tool in a pythonic API
31*cdf0c1d5Smjnelson#
32*cdf0c1d5Smjnelson
33*cdf0c1d5Smjnelsonimport sys
34*cdf0c1d5Smjnelsonfrom onbld.Checks.ProcessCheck import processcheck
35*cdf0c1d5Smjnelson
36*cdf0c1d5Smjnelsondef cstyle(fh, filename=None, output=sys.stderr, **opts):
37*cdf0c1d5Smjnelson	opttrans = {'check_continuation': '-c',
38*cdf0c1d5Smjnelson		    'heuristic': '-h',
39*cdf0c1d5Smjnelson		    'picky': '-p',
40*cdf0c1d5Smjnelson		    'verbose': '-v',
41*cdf0c1d5Smjnelson		    'ignore_hdr_comment': '-C',
42*cdf0c1d5Smjnelson		    'check_posix_types': '-P',
43*cdf0c1d5Smjnelson		    'doxygen_comments': '-o doxygen',
44*cdf0c1d5Smjnelson		    'splint_comments': '-o splint'}
45*cdf0c1d5Smjnelson
46*cdf0c1d5Smjnelson	for x in filter(lambda x: x not in opttrans, opts):
47*cdf0c1d5Smjnelson		raise TypeError('cstyle() got an unexpected keyword '
48*cdf0c1d5Smjnelson				'argument %s' % x)
49*cdf0c1d5Smjnelson
50*cdf0c1d5Smjnelson	options = [opttrans[x] for x in opts if opts[x]]
51*cdf0c1d5Smjnelson
52*cdf0c1d5Smjnelson	if not filename:
53*cdf0c1d5Smjnelson		filename = fh.name
54*cdf0c1d5Smjnelson
55*cdf0c1d5Smjnelson	ret, tmpfile = processcheck('cstyle', options, fh, output)
56*cdf0c1d5Smjnelson
57*cdf0c1d5Smjnelson	if tmpfile:
58*cdf0c1d5Smjnelson		for line in tmpfile:
59*cdf0c1d5Smjnelson			line = line.replace('<stdin>', filename)
60*cdf0c1d5Smjnelson			output.write(line)
61*cdf0c1d5Smjnelson
62*cdf0c1d5Smjnelson		tmpfile.close()
63*cdf0c1d5Smjnelson	return ret
64