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