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# JStyle, wrap the jstyle tool in a pythonic API 31*cdf0c1d5Smjnelson# 32*cdf0c1d5Smjnelson 33*cdf0c1d5Smjnelsonimport sys 34*cdf0c1d5Smjnelsonfrom onbld.Checks.ProcessCheck import processcheck 35*cdf0c1d5Smjnelson 36*cdf0c1d5Smjnelson 37*cdf0c1d5Smjnelsondef jstyle(fh, filename=None, output=sys.stderr, **opts): 38*cdf0c1d5Smjnelson opttrans = {'check_continuation': '-c', 39*cdf0c1d5Smjnelson 'heuristic': '-h', 40*cdf0c1d5Smjnelson 'picky': '-p', 41*cdf0c1d5Smjnelson 'ignore_hdr_comment': '-C', 42*cdf0c1d5Smjnelson 'verbose': '-v', 43*cdf0c1d5Smjnelson 'tabs': '-t'} 44*cdf0c1d5Smjnelson 45*cdf0c1d5Smjnelson for x in filter(lambda x: x not in opttrans, opts): 46*cdf0c1d5Smjnelson raise TypeError('jstyle() got an unexpected keyword ' 47*cdf0c1d5Smjnelson 'argument %s' % x) 48*cdf0c1d5Smjnelson 49*cdf0c1d5Smjnelson options = [opttrans[x] for x in opts if opts[x]] 50*cdf0c1d5Smjnelson 51*cdf0c1d5Smjnelson if not filename: 52*cdf0c1d5Smjnelson filename = fh.name 53*cdf0c1d5Smjnelson 54*cdf0c1d5Smjnelson ret, tmpfile = processcheck('jstyle', options, fh, output) 55*cdf0c1d5Smjnelson 56*cdf0c1d5Smjnelson if tmpfile: 57*cdf0c1d5Smjnelson for line in tmpfile: 58*cdf0c1d5Smjnelson line = line.replace('<stdin>', filename) 59*cdf0c1d5Smjnelson output.write(line) 60*cdf0c1d5Smjnelson 61*cdf0c1d5Smjnelson tmpfile.close() 62*cdf0c1d5Smjnelson 63*cdf0c1d5Smjnelson return ret 64