1*93be19b9SAndy Fiddaman#!@TOOLS_PYTHON@ 2cdf0c1d5Smjnelson# 3cdf0c1d5Smjnelson# CDDL HEADER START 4cdf0c1d5Smjnelson# 5cdf0c1d5Smjnelson# The contents of this file are subject to the terms of the 6cdf0c1d5Smjnelson# Common Development and Distribution License (the "License"). 7cdf0c1d5Smjnelson# You may not use this file except in compliance with the License. 8cdf0c1d5Smjnelson# 9cdf0c1d5Smjnelson# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10cdf0c1d5Smjnelson# or http://www.opensolaris.org/os/licensing. 11cdf0c1d5Smjnelson# See the License for the specific language governing permissions 12cdf0c1d5Smjnelson# and limitations under the License. 13cdf0c1d5Smjnelson# 14cdf0c1d5Smjnelson# When distributing Covered Code, include this CDDL HEADER in each 15cdf0c1d5Smjnelson# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16cdf0c1d5Smjnelson# If applicable, add the following below this CDDL HEADER, with the 17cdf0c1d5Smjnelson# fields enclosed by brackets "[]" replaced with your own identifying 18cdf0c1d5Smjnelson# information: Portions Copyright [yyyy] [name of copyright owner] 19cdf0c1d5Smjnelson# 20cdf0c1d5Smjnelson# CDDL HEADER END 21cdf0c1d5Smjnelson# 22cdf0c1d5Smjnelson 23cdf0c1d5Smjnelson# 2487ab3622SRichard Lowe# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 25*93be19b9SAndy Fiddaman# Copyright 2018 OmniOS Community Edition (OmniOSce) Association. 26cdf0c1d5Smjnelson# 27cdf0c1d5Smjnelson 28cdf0c1d5Smjnelson# 29cdf0c1d5Smjnelson# Check header files conform to ON standards. 30cdf0c1d5Smjnelson# 31cdf0c1d5Smjnelson 32*93be19b9SAndy Fiddamanimport sys, os, io, getopt 33cdf0c1d5Smjnelson 3487ab3622SRichard Lowesys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "lib", 3587ab3622SRichard Lowe "python%d.%d" % sys.version_info[:2])) 3687ab3622SRichard Lowe 3787ab3622SRichard Lowe# Allow running from the source tree, using the modules in the source tree 3887ab3622SRichard Lowesys.path.insert(2, os.path.join(os.path.dirname(__file__), '..')) 39cdf0c1d5Smjnelson 40cdf0c1d5Smjnelsonfrom onbld.Checks.HdrChk import hdrchk 41cdf0c1d5Smjnelson 42cdf0c1d5Smjnelsondef usage(): 43cdf0c1d5Smjnelson progname = os.path.split(sys.argv[0])[1] 44cdf0c1d5Smjnelson msg = ['Usage: %s [-a] file [file...]\n' % progname, 45cdf0c1d5Smjnelson ' -a\tApply (more lenient) application header rules\n'] 46cdf0c1d5Smjnelson sys.stderr.writelines(msg) 47cdf0c1d5Smjnelson 48cdf0c1d5Smjnelson 49cdf0c1d5Smjnelsontry: 50cdf0c1d5Smjnelson opts, args = getopt.getopt(sys.argv[1:], 'a') 51cdf0c1d5Smjnelsonexcept getopt.GetoptError: 52cdf0c1d5Smjnelson usage() 53cdf0c1d5Smjnelson sys.exit(2) 54cdf0c1d5Smjnelson 55cdf0c1d5Smjnelsonlenient = False 56cdf0c1d5Smjnelsonfor opt, arg in opts: 57cdf0c1d5Smjnelson if opt == '-a': 58cdf0c1d5Smjnelson lenient = True 59cdf0c1d5Smjnelson 60cdf0c1d5Smjnelsonret = 0 61cdf0c1d5Smjnelsonfor filename in args: 62cdf0c1d5Smjnelson try: 63*93be19b9SAndy Fiddaman with io.open(filename, encoding='utf-8', 64*93be19b9SAndy Fiddaman errors='replace') as fh: 65*93be19b9SAndy Fiddaman ret |= hdrchk(fh, lenient=lenient, output=sys.stderr) 66*93be19b9SAndy Fiddaman except IOError as e: 67cdf0c1d5Smjnelson sys.stderr.write("failed to open '%s': %s\n" % 68cdf0c1d5Smjnelson (e.filename, e.strerror)) 69cdf0c1d5Smjnelsonsys.exit(ret) 70