xref: /onnv-gate/usr/src/lib/libshell/common/scripts/shlint.sh (revision 12068:08a39a083754)
18462SApril.Chin@Sun.COM#!/usr/bin/ksh93
28462SApril.Chin@Sun.COM
38462SApril.Chin@Sun.COM#
48462SApril.Chin@Sun.COM# CDDL HEADER START
58462SApril.Chin@Sun.COM#
68462SApril.Chin@Sun.COM# The contents of this file are subject to the terms of the
78462SApril.Chin@Sun.COM# Common Development and Distribution License (the "License").
88462SApril.Chin@Sun.COM# You may not use this file except in compliance with the License.
98462SApril.Chin@Sun.COM#
108462SApril.Chin@Sun.COM# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
118462SApril.Chin@Sun.COM# or http://www.opensolaris.org/os/licensing.
128462SApril.Chin@Sun.COM# See the License for the specific language governing permissions
138462SApril.Chin@Sun.COM# and limitations under the License.
148462SApril.Chin@Sun.COM#
158462SApril.Chin@Sun.COM# When distributing Covered Code, include this CDDL HEADER in each
168462SApril.Chin@Sun.COM# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
178462SApril.Chin@Sun.COM# If applicable, add the following below this CDDL HEADER, with the
188462SApril.Chin@Sun.COM# fields enclosed by brackets "[]" replaced with your own identifying
198462SApril.Chin@Sun.COM# information: Portions Copyright [yyyy] [name of copyright owner]
208462SApril.Chin@Sun.COM#
218462SApril.Chin@Sun.COM# CDDL HEADER END
228462SApril.Chin@Sun.COM#
238462SApril.Chin@Sun.COM
248462SApril.Chin@Sun.COM#
25*12068SRoger.Faulkner@Oracle.COM# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
268462SApril.Chin@Sun.COM#
278462SApril.Chin@Sun.COM
288462SApril.Chin@Sun.COM#
298462SApril.Chin@Sun.COM# shlint - a simple lint wrapper around "shcomp"
308462SApril.Chin@Sun.COM#
318462SApril.Chin@Sun.COM
328462SApril.Chin@Sun.COM# Solaris needs /usr/xpg6/bin:/usr/xpg4/bin because the tools in /usr/bin are not POSIX-conformant
338462SApril.Chin@Sun.COMexport PATH=/usr/xpg6/bin:/usr/xpg4/bin:/bin:/usr/bin
348462SApril.Chin@Sun.COM
358462SApril.Chin@Sun.COM# Make sure all math stuff runs in the "C" locale to avoid problems
368462SApril.Chin@Sun.COM# with alternative # radix point representations (e.g. ',' instead of
378462SApril.Chin@Sun.COM# '.' in de_DE.*-locales). This needs to be set _before_ any
388462SApril.Chin@Sun.COM# floating-point constants are defined in this script).
398462SApril.Chin@Sun.COMif [[ "${LC_ALL}" != "" ]] ; then
408462SApril.Chin@Sun.COM    export \
418462SApril.Chin@Sun.COM        LC_MONETARY="${LC_ALL}" \
428462SApril.Chin@Sun.COM        LC_MESSAGES="${LC_ALL}" \
438462SApril.Chin@Sun.COM        LC_COLLATE="${LC_ALL}" \
448462SApril.Chin@Sun.COM        LC_CTYPE="${LC_ALL}"
458462SApril.Chin@Sun.COM        unset LC_ALL
468462SApril.Chin@Sun.COMfi
478462SApril.Chin@Sun.COMexport LC_NUMERIC=C
488462SApril.Chin@Sun.COM
498462SApril.Chin@Sun.COMfunction fatal_error
508462SApril.Chin@Sun.COM{
518462SApril.Chin@Sun.COM	print -u2 "${progname}: $*"
528462SApril.Chin@Sun.COM	exit 1
538462SApril.Chin@Sun.COM}
548462SApril.Chin@Sun.COM
558462SApril.Chin@Sun.COMfunction usage
568462SApril.Chin@Sun.COM{
578462SApril.Chin@Sun.COM	OPTIND=0
588462SApril.Chin@Sun.COM	getopts -a "${progname}" "${shlint_usage}" OPT '-?'
598462SApril.Chin@Sun.COM	exit 2
608462SApril.Chin@Sun.COM}
618462SApril.Chin@Sun.COM
628462SApril.Chin@Sun.COM# program start
638462SApril.Chin@Sun.COMbuiltin basename
648462SApril.Chin@Sun.COM
658462SApril.Chin@Sun.COMtypeset progname="${ basename "${0}" ; }"
668462SApril.Chin@Sun.COM
678462SApril.Chin@Sun.COMtypeset -r shlint_usage=$'+
6810898Sroland.mainz@nrubsig.org[-?\n@(#)\$Id: shlint (Roland Mainz) 2009-03-15 \$\n]
698462SApril.Chin@Sun.COM[-author?Roland Mainz <roland.mainz@sun.com>]
708462SApril.Chin@Sun.COM[-author?Roland Mainz <roland.mainz@nrubsig.org>]
718462SApril.Chin@Sun.COM[+NAME?shlint - lint for POSIX shell scripts]
728462SApril.Chin@Sun.COM[+DESCRIPTION?\bshlint\b is a lint for POSIX shell scripts.]
738462SApril.Chin@Sun.COM[+SEE ALSO?\bshcomp\b(1), \bksh93\b(1)]
748462SApril.Chin@Sun.COM'
758462SApril.Chin@Sun.COM
768462SApril.Chin@Sun.COMwhile getopts -a "${progname}" "${shlint_usage}" OPT ; do
778462SApril.Chin@Sun.COM#	printmsg "## OPT=|${OPT}|, OPTARG=|${OPTARG}|"
788462SApril.Chin@Sun.COM	case ${OPT} in
798462SApril.Chin@Sun.COM		*)    usage ;;
808462SApril.Chin@Sun.COM	esac
818462SApril.Chin@Sun.COMdone
828462SApril.Chin@Sun.COMshift $((OPTIND-1))
838462SApril.Chin@Sun.COM
8410898Sroland.mainz@nrubsig.org(( $# > 0 )) || usage
8510898Sroland.mainz@nrubsig.org
868462SApril.Chin@Sun.COMfile="$1"
878462SApril.Chin@Sun.COM[[ ! -f "$file" ]] && fatal_error $"File ${file} not found."
888462SApril.Chin@Sun.COM[[ ! -r "$file" ]] && fatal_error $"File ${file} not readable."
898462SApril.Chin@Sun.COM
9010898Sroland.mainz@nrubsig.orgx="$( /usr/bin/shcomp -n "${file}" /dev/null 2>&1 1>/dev/null  )"
918462SApril.Chin@Sun.COM
9210898Sroland.mainz@nrubsig.orgprintf "%s\n" "$x"
938462SApril.Chin@Sun.COM
948462SApril.Chin@Sun.COM[[ "$x" != "" ]] && exit 1 || exit 0
958462SApril.Chin@Sun.COM# EOF.
96