xref: /titanic_52/usr/src/cmd/ast/libshell/common/scripts/shlint.sh (revision 906afcb89d0412cc073b95c2d701a804a8cdb62c)
1*906afcb8SAndy Fiddaman#!/usr/bin/ksh93
2*906afcb8SAndy Fiddaman
3*906afcb8SAndy Fiddaman#
4*906afcb8SAndy Fiddaman# CDDL HEADER START
5*906afcb8SAndy Fiddaman#
6*906afcb8SAndy Fiddaman# The contents of this file are subject to the terms of the
7*906afcb8SAndy Fiddaman# Common Development and Distribution License (the "License").
8*906afcb8SAndy Fiddaman# You may not use this file except in compliance with the License.
9*906afcb8SAndy Fiddaman#
10*906afcb8SAndy Fiddaman# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*906afcb8SAndy Fiddaman# or http://www.opensolaris.org/os/licensing.
12*906afcb8SAndy Fiddaman# See the License for the specific language governing permissions
13*906afcb8SAndy Fiddaman# and limitations under the License.
14*906afcb8SAndy Fiddaman#
15*906afcb8SAndy Fiddaman# When distributing Covered Code, include this CDDL HEADER in each
16*906afcb8SAndy Fiddaman# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*906afcb8SAndy Fiddaman# If applicable, add the following below this CDDL HEADER, with the
18*906afcb8SAndy Fiddaman# fields enclosed by brackets "[]" replaced with your own identifying
19*906afcb8SAndy Fiddaman# information: Portions Copyright [yyyy] [name of copyright owner]
20*906afcb8SAndy Fiddaman#
21*906afcb8SAndy Fiddaman# CDDL HEADER END
22*906afcb8SAndy Fiddaman#
23*906afcb8SAndy Fiddaman
24*906afcb8SAndy Fiddaman#
25*906afcb8SAndy Fiddaman# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
26*906afcb8SAndy Fiddaman#
27*906afcb8SAndy Fiddaman
28*906afcb8SAndy Fiddaman#
29*906afcb8SAndy Fiddaman# shlint - a simple lint wrapper around "shcomp"
30*906afcb8SAndy Fiddaman#
31*906afcb8SAndy Fiddaman
32*906afcb8SAndy Fiddaman# Solaris needs /usr/xpg6/bin:/usr/xpg4/bin because the tools in /usr/bin are not POSIX-conformant
33*906afcb8SAndy Fiddamanexport PATH=/usr/xpg6/bin:/usr/xpg4/bin:/bin:/usr/bin
34*906afcb8SAndy Fiddaman
35*906afcb8SAndy Fiddaman# Make sure all math stuff runs in the "C" locale to avoid problems
36*906afcb8SAndy Fiddaman# with alternative # radix point representations (e.g. ',' instead of
37*906afcb8SAndy Fiddaman# '.' in de_DE.*-locales). This needs to be set _before_ any
38*906afcb8SAndy Fiddaman# floating-point constants are defined in this script).
39*906afcb8SAndy Fiddamanif [[ "${LC_ALL}" != "" ]] ; then
40*906afcb8SAndy Fiddaman    export \
41*906afcb8SAndy Fiddaman        LC_MONETARY="${LC_ALL}" \
42*906afcb8SAndy Fiddaman        LC_MESSAGES="${LC_ALL}" \
43*906afcb8SAndy Fiddaman        LC_COLLATE="${LC_ALL}" \
44*906afcb8SAndy Fiddaman        LC_CTYPE="${LC_ALL}"
45*906afcb8SAndy Fiddaman        unset LC_ALL
46*906afcb8SAndy Fiddamanfi
47*906afcb8SAndy Fiddamanexport LC_NUMERIC=C
48*906afcb8SAndy Fiddaman
49*906afcb8SAndy Fiddamanfunction fatal_error
50*906afcb8SAndy Fiddaman{
51*906afcb8SAndy Fiddaman	print -u2 "${progname}: $*"
52*906afcb8SAndy Fiddaman	exit 1
53*906afcb8SAndy Fiddaman}
54*906afcb8SAndy Fiddaman
55*906afcb8SAndy Fiddamanfunction usage
56*906afcb8SAndy Fiddaman{
57*906afcb8SAndy Fiddaman	OPTIND=0
58*906afcb8SAndy Fiddaman	getopts -a "${progname}" "${shlint_usage}" OPT '-?'
59*906afcb8SAndy Fiddaman	exit 2
60*906afcb8SAndy Fiddaman}
61*906afcb8SAndy Fiddaman
62*906afcb8SAndy Fiddaman# program start
63*906afcb8SAndy Fiddamanbuiltin basename
64*906afcb8SAndy Fiddaman
65*906afcb8SAndy Fiddamantypeset progname="${ basename "${0}" ; }"
66*906afcb8SAndy Fiddaman
67*906afcb8SAndy Fiddamantypeset -r shlint_usage=$'+
68*906afcb8SAndy Fiddaman[-?\n@(#)\$Id: shlint (Roland Mainz) 2009-03-15 \$\n]
69*906afcb8SAndy Fiddaman[-author?Roland Mainz <roland.mainz@sun.com>]
70*906afcb8SAndy Fiddaman[-author?Roland Mainz <roland.mainz@nrubsig.org>]
71*906afcb8SAndy Fiddaman[+NAME?shlint - lint for POSIX shell scripts]
72*906afcb8SAndy Fiddaman[+DESCRIPTION?\bshlint\b is a lint for POSIX shell scripts.]
73*906afcb8SAndy Fiddaman[+SEE ALSO?\bshcomp\b(1), \bksh93\b(1)]
74*906afcb8SAndy Fiddaman'
75*906afcb8SAndy Fiddaman
76*906afcb8SAndy Fiddamanwhile getopts -a "${progname}" "${shlint_usage}" OPT ; do
77*906afcb8SAndy Fiddaman#	printmsg "## OPT=|${OPT}|, OPTARG=|${OPTARG}|"
78*906afcb8SAndy Fiddaman	case ${OPT} in
79*906afcb8SAndy Fiddaman		*)    usage ;;
80*906afcb8SAndy Fiddaman	esac
81*906afcb8SAndy Fiddamandone
82*906afcb8SAndy Fiddamanshift $((OPTIND-1))
83*906afcb8SAndy Fiddaman
84*906afcb8SAndy Fiddaman(( $# > 0 )) || usage
85*906afcb8SAndy Fiddaman
86*906afcb8SAndy Fiddamanfile="$1"
87*906afcb8SAndy Fiddaman[[ ! -f "$file" ]] && fatal_error $"File ${file} not found."
88*906afcb8SAndy Fiddaman[[ ! -r "$file" ]] && fatal_error $"File ${file} not readable."
89*906afcb8SAndy Fiddaman
90*906afcb8SAndy Fiddamanx="$( /usr/bin/shcomp -n "${file}" /dev/null 2>&1 1>/dev/null  )"
91*906afcb8SAndy Fiddaman
92*906afcb8SAndy Fiddamanprintf "%s\n" "$x"
93*906afcb8SAndy Fiddaman
94*906afcb8SAndy Fiddaman[[ "$x" != "" ]] && exit 1 || exit 0
95*906afcb8SAndy Fiddaman# EOF.
96