#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# Copyright 2008, 2010, Richard Lowe
#
# Check that header files conform to our standards
#
# Standards for all header files (lenient):
#
# 1) Begin with a comment containing a copyright message
#
# 2) Enclosed in a guard of the form:
#
# #ifndef GUARD
# #define GUARD
# #endif /* [!]GUARD */
#
# The preferred form is without the bang character, but either is
# acceptable.
#
# 3) Has a valid ident declaration
#
# Additional standards for system header files:
#
# 1) The file guard must take the form '_FILENAME_H[_]', where FILENAME
# matches the basename of the file. If it is installed in a
# subdirectory, it must be of the form _DIR_FILENAME_H. The form
# without the trailing underscore is preferred.
#
# 2) All #include directives must use the <> form.
#
# 3) If the header file contains anything besides comments and
# preprocessor directives, then it must be enclosed in a C++ guard of
# the form:
#
# #ifdef __cplusplus
# extern "C" {
# #endif
#
# #ifdef __cplusplus
# }
# #endif
#
if filename:
else:
continue
else:
# Recursively join continuation lines
return line
else:
return ''
#
# Optionally take a line to start skipping/processing with
#
while line:
# When lenient, allow C++ comments
continue
return line
#
# We explicitly exclude the form used in the
# CDDL header rather than attempting to craft
# a match for every possibly valid copyright
# notice
#
if is_copyright(line):
if is_copyright(line):
return line
else:
#
# Keyword strings (both expanded and literal) for the various SCMs
# Be certain to wrap each full expression in parens.
#
idents = [
# SCCS
r'((\%Z\%(\%M\%)\t\%I\%|\%W\%)\t\%E\% SMI)',
r'(@\(#\)(\w[-\.\w]+\.h)\t\d+\.\d+(\.\d+\.\d+)?\t\d\d/\d\d/\d\d SMI)',
]
guard = None
ret = 0
#
# Step 1:
#
# Headers must begin with a comment containing a copyright notice. We
# don't validate the contents of the copyright, only that it exists
#
if not hdr.has_copyright:
ret = 1
#
# Step 2:
#
# For application header files only, allow the ident string to appear
# before the header guard.
found_ident = 1
#
# Step 3: Header guards
#
if not match:
ret = 1
else:
if not lenient:
#
# If we aren't being lenient, validate the name of the
# guard
#
"suggested style (_FILEPATH_H_)", hdr)
ret = 1
ret = 1
if not line:
else:
#
# Step 4: ident string
#
# We allow both the keyword and extracted versions
#
ret = 1
else:
#
# Main processing loop
#
while line:
continue
if match:
#
# For system files, make sure #includes are of the form:
# '#include <file>'
#
ret = 1
line):
#
# Start of C++ header guard.
# Make sure it is of the form:
#
# #ifdef __cplusplus
# extern "C" {
# #endif
#
if line == 'extern "C" {':
if line != '#endif':
hdr)
ret = 1
else:
else:
continue
#
# End of C++ header guard. Make sure it is of the form:
#
# #ifdef __cplusplus
# }
# #endif
#
if line == '}':
if line != '#endif':
hdr)
ret = 1
else:
else:
continue
#
# Ending header guard
#
#
# Check for missing end clauses
#
ret = 1
if in_cplusplus:
ret = 1
if not found_endguard:
ret = 1
return ret