xref: /onnv-gate/usr/src/tools/scripts/hdrchk.py (revision 12216:5167f302c8cf)
111838SLiane.Praza@Sun.COM#!/usr/bin/python2.4
27078Smjnelson#
37078Smjnelson# CDDL HEADER START
47078Smjnelson#
57078Smjnelson# The contents of this file are subject to the terms of the
67078Smjnelson# Common Development and Distribution License (the "License").
77078Smjnelson# You may not use this file except in compliance with the License.
87078Smjnelson#
97078Smjnelson# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107078Smjnelson# or http://www.opensolaris.org/os/licensing.
117078Smjnelson# See the License for the specific language governing permissions
127078Smjnelson# and limitations under the License.
137078Smjnelson#
147078Smjnelson# When distributing Covered Code, include this CDDL HEADER in each
157078Smjnelson# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167078Smjnelson# If applicable, add the following below this CDDL HEADER, with the
177078Smjnelson# fields enclosed by brackets "[]" replaced with your own identifying
187078Smjnelson# information: Portions Copyright [yyyy] [name of copyright owner]
197078Smjnelson#
207078Smjnelson# CDDL HEADER END
217078Smjnelson#
227078Smjnelson
237078Smjnelson#
24*12216Srichlowe@richlowe.net# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
257078Smjnelson#
267078Smjnelson
277078Smjnelson#
287078Smjnelson# Check header files conform to ON standards.
297078Smjnelson#
307078Smjnelson
317078Smjnelsonimport sys, os, getopt
327078Smjnelson
33*12216Srichlowe@richlowe.netsys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "lib",
34*12216Srichlowe@richlowe.net                                "python%d.%d" % sys.version_info[:2]))
35*12216Srichlowe@richlowe.net
36*12216Srichlowe@richlowe.net# Allow running from the source tree, using the modules in the source tree
37*12216Srichlowe@richlowe.netsys.path.insert(2, os.path.join(os.path.dirname(__file__), '..'))
387078Smjnelson
397078Smjnelsonfrom onbld.Checks.HdrChk import hdrchk
407078Smjnelson
417078Smjnelsondef usage():
427078Smjnelson	progname = os.path.split(sys.argv[0])[1]
437078Smjnelson	msg =  ['Usage: %s [-a] file [file...]\n' % progname,
447078Smjnelson		'  -a\tApply (more lenient) application header rules\n']
457078Smjnelson	sys.stderr.writelines(msg)
467078Smjnelson
477078Smjnelson
487078Smjnelsontry:
497078Smjnelson	opts, args = getopt.getopt(sys.argv[1:], 'a')
507078Smjnelsonexcept getopt.GetoptError:
517078Smjnelson	usage()
5211300Srichlowe@richlowe.net	sys.exit(2)
537078Smjnelson
547078Smjnelsonlenient = False
557078Smjnelsonfor opt, arg in opts:
567078Smjnelson	if opt == '-a':
577078Smjnelson		lenient = True
587078Smjnelson
597078Smjnelsonret = 0
607078Smjnelsonfor filename in args:
617078Smjnelson	try:
627078Smjnelson		fh = open(filename, 'r')
637078Smjnelson	except IOError, e:
647078Smjnelson		sys.stderr.write("failed to open '%s': %s\n" %
657078Smjnelson				 (e.filename, e.strerror))
667078Smjnelson	else:
677078Smjnelson		ret |= hdrchk(fh, lenient=lenient, output=sys.stderr)
687078Smjnelson		fh.close()
697078Smjnelsonsys.exit(ret)
70