xref: /titanic_52/usr/src/tools/scripts/flg.flp.sh (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate#! /bin/ksh -p
2*7c478bd9Sstevel@tonic-gate#
3*7c478bd9Sstevel@tonic-gate# CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate#
5*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate# with the License.
9*7c478bd9Sstevel@tonic-gate#
10*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate# and limitations under the License.
14*7c478bd9Sstevel@tonic-gate#
15*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate#
21*7c478bd9Sstevel@tonic-gate# CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate#
23*7c478bd9Sstevel@tonic-gate#
24*7c478bd9Sstevel@tonic-gate# Copyright 1991, 2002-2003 Sun Microsystems, Inc.  All rights reserved.
25*7c478bd9Sstevel@tonic-gate# Use is subject to license terms.
26*7c478bd9Sstevel@tonic-gate#
27*7c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate#
29*7c478bd9Sstevel@tonic-gate# Generates the list of source files that would get brought over with the
30*7c478bd9Sstevel@tonic-gate# specified subtree as a result of inc.flg and req.flg files.  If no subtree
31*7c478bd9Sstevel@tonic-gate# is named, then the current directory is assumed.
32*7c478bd9Sstevel@tonic-gate#
33*7c478bd9Sstevel@tonic-gate# Based loosely on ON's version of Teamware's def.dir.flp.
34*7c478bd9Sstevel@tonic-gate#
35*7c478bd9Sstevel@tonic-gate
36*7c478bd9Sstevel@tonic-gatePATH=/usr/bin export PATH
37*7c478bd9Sstevel@tonic-gatePROG=`basename $0`
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gate#
40*7c478bd9Sstevel@tonic-gate# The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
41*7c478bd9Sstevel@tonic-gate# under certain circumstances, which will screw up consumers of incflg()
42*7c478bd9Sstevel@tonic-gate# (and perhaps other things as well); unset it.
43*7c478bd9Sstevel@tonic-gate#
44*7c478bd9Sstevel@tonic-gateunset CDPATH
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gate#
47*7c478bd9Sstevel@tonic-gate# Print the usage message and exit with an error.
48*7c478bd9Sstevel@tonic-gate#
49*7c478bd9Sstevel@tonic-gateusage()
50*7c478bd9Sstevel@tonic-gate{
51*7c478bd9Sstevel@tonic-gate	echo "usage: $PROG [-r] [<dir>]" > /dev/stderr
52*7c478bd9Sstevel@tonic-gate	exit 1
53*7c478bd9Sstevel@tonic-gate}
54*7c478bd9Sstevel@tonic-gate
55*7c478bd9Sstevel@tonic-gate#
56*7c478bd9Sstevel@tonic-gate# Print the provided failure message and exit with an error.
57*7c478bd9Sstevel@tonic-gate#
58*7c478bd9Sstevel@tonic-gatefail()
59*7c478bd9Sstevel@tonic-gate{
60*7c478bd9Sstevel@tonic-gate	echo $PROG: $@ > /dev/stderr
61*7c478bd9Sstevel@tonic-gate	exit 1
62*7c478bd9Sstevel@tonic-gate}
63*7c478bd9Sstevel@tonic-gate
64*7c478bd9Sstevel@tonic-gate#
65*7c478bd9Sstevel@tonic-gate# Find the files matching the pattern specified by the first argument in the
66*7c478bd9Sstevel@tonic-gate# directories named by the remaining arguments.  Unlike def.dir.flp, print
67*7c478bd9Sstevel@tonic-gate# the name of the source file since we want to make a list of source files,
68*7c478bd9Sstevel@tonic-gate# not SCCS files.
69*7c478bd9Sstevel@tonic-gate#
70*7c478bd9Sstevel@tonic-gatefind_files()
71*7c478bd9Sstevel@tonic-gate{
72*7c478bd9Sstevel@tonic-gate   	pat=$1
73*7c478bd9Sstevel@tonic-gate   	shift
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate	for dir; do
76*7c478bd9Sstevel@tonic-gate		if [ -d $CODEMGR_WS/$dir ]; then
77*7c478bd9Sstevel@tonic-gate			cd $CODEMGR_WS
78*7c478bd9Sstevel@tonic-gate    			find $dir -name "$pat" | sed -n s:/SCCS/s.:/:p | prpath
79*7c478bd9Sstevel@tonic-gate 			cd - > /dev/null
80*7c478bd9Sstevel@tonic-gate		fi
81*7c478bd9Sstevel@tonic-gate	done
82*7c478bd9Sstevel@tonic-gate}
83*7c478bd9Sstevel@tonic-gate
84*7c478bd9Sstevel@tonic-gate#
85*7c478bd9Sstevel@tonic-gate# Echo the filename if it exists in the workspace.
86*7c478bd9Sstevel@tonic-gate#
87*7c478bd9Sstevel@tonic-gateecho_file()
88*7c478bd9Sstevel@tonic-gate{
89*7c478bd9Sstevel@tonic-gate	[ -f $CODEMGR_WS/$1 ] && echo $1 | prpath
90*7c478bd9Sstevel@tonic-gate}
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gate#
93*7c478bd9Sstevel@tonic-gate# Source the named script, specified as either a full path or a path relative
94*7c478bd9Sstevel@tonic-gate# to $CODEMGR_WS.  Although def.dir.flp allows for situations in which the
95*7c478bd9Sstevel@tonic-gate# script is actually executed (rather than sourced), this feature has never
96*7c478bd9Sstevel@tonic-gate# been used in ON, since it precludes use of echo_file() and find_files().
97*7c478bd9Sstevel@tonic-gate#
98*7c478bd9Sstevel@tonic-gateexec_file()
99*7c478bd9Sstevel@tonic-gate{
100*7c478bd9Sstevel@tonic-gate	if [ "${1##/}" = "$1" ]; then
101*7c478bd9Sstevel@tonic-gate		. $CODEMGR_WS/$1
102*7c478bd9Sstevel@tonic-gate	else
103*7c478bd9Sstevel@tonic-gate		. $1
104*7c478bd9Sstevel@tonic-gate	fi
105*7c478bd9Sstevel@tonic-gate}
106*7c478bd9Sstevel@tonic-gate
107*7c478bd9Sstevel@tonic-gate#
108*7c478bd9Sstevel@tonic-gate# Iterate up through all directories below the named directory, and
109*7c478bd9Sstevel@tonic-gate# execute any inc.flg's that may exist.
110*7c478bd9Sstevel@tonic-gate#
111*7c478bd9Sstevel@tonic-gateincflg()
112*7c478bd9Sstevel@tonic-gate{
113*7c478bd9Sstevel@tonic-gate	cd $1
114*7c478bd9Sstevel@tonic-gate	for i in * .*; 	do
115*7c478bd9Sstevel@tonic-gate    		case $i in
116*7c478bd9Sstevel@tonic-gate		'*'|.|..)
117*7c478bd9Sstevel@tonic-gate			;;
118*7c478bd9Sstevel@tonic-gate		inc.flg)
119*7c478bd9Sstevel@tonic-gate			exec_file $1/$i
120*7c478bd9Sstevel@tonic-gate			;;
121*7c478bd9Sstevel@tonic-gate		*)
122*7c478bd9Sstevel@tonic-gate			if [ -d $i -a ! -h $i ]; then
123*7c478bd9Sstevel@tonic-gate				incflg $1/$i
124*7c478bd9Sstevel@tonic-gate				cd $1
125*7c478bd9Sstevel@tonic-gate			fi
126*7c478bd9Sstevel@tonic-gate			;;
127*7c478bd9Sstevel@tonic-gate		esac
128*7c478bd9Sstevel@tonic-gate	done
129*7c478bd9Sstevel@tonic-gate}
130*7c478bd9Sstevel@tonic-gate
131*7c478bd9Sstevel@tonic-gate#
132*7c478bd9Sstevel@tonic-gate# Convert the absolute pathnames named on input to relative pathnames (if
133*7c478bd9Sstevel@tonic-gate# necessary) and print them.
134*7c478bd9Sstevel@tonic-gate#
135*7c478bd9Sstevel@tonic-gateprpath()
136*7c478bd9Sstevel@tonic-gate{
137*7c478bd9Sstevel@tonic-gate	reltree=${CURTREE##$CODEMGR_WS/}
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate	while read srcfile; do
140*7c478bd9Sstevel@tonic-gate		if [ "$RELPATHS" != y ]; then
141*7c478bd9Sstevel@tonic-gate			echo $srcfile
142*7c478bd9Sstevel@tonic-gate			continue
143*7c478bd9Sstevel@tonic-gate		fi
144*7c478bd9Sstevel@tonic-gate
145*7c478bd9Sstevel@tonic-gate		dots=
146*7c478bd9Sstevel@tonic-gate		tree=$reltree
147*7c478bd9Sstevel@tonic-gate		while [ "${srcfile##$tree}" = "$srcfile" ]; do
148*7c478bd9Sstevel@tonic-gate			dots=../$dots
149*7c478bd9Sstevel@tonic-gate			tree=`dirname $tree`
150*7c478bd9Sstevel@tonic-gate		done
151*7c478bd9Sstevel@tonic-gate		echo ${dots}${srcfile##$tree/}
152*7c478bd9Sstevel@tonic-gate	done
153*7c478bd9Sstevel@tonic-gate}
154*7c478bd9Sstevel@tonic-gate
155*7c478bd9Sstevel@tonic-gate[ -z "$CODEMGR_WS" ] && fail "No active workspace; run \"ws <workspace_name>\""
156*7c478bd9Sstevel@tonic-gate
157*7c478bd9Sstevel@tonic-gatewhile getopts r flag; do
158*7c478bd9Sstevel@tonic-gate	case $flag in
159*7c478bd9Sstevel@tonic-gate	r)
160*7c478bd9Sstevel@tonic-gate		RELPATHS=y
161*7c478bd9Sstevel@tonic-gate		;;
162*7c478bd9Sstevel@tonic-gate	\?)
163*7c478bd9Sstevel@tonic-gate		usage
164*7c478bd9Sstevel@tonic-gate		;;
165*7c478bd9Sstevel@tonic-gate	esac
166*7c478bd9Sstevel@tonic-gatedone
167*7c478bd9Sstevel@tonic-gate
168*7c478bd9Sstevel@tonic-gateshift $((OPTIND - 1))
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate[ $# -gt 1 ] && usage
171*7c478bd9Sstevel@tonic-gate
172*7c478bd9Sstevel@tonic-gateCURTREE=`/bin/pwd`
173*7c478bd9Sstevel@tonic-gate
174*7c478bd9Sstevel@tonic-gate#
175*7c478bd9Sstevel@tonic-gate# Determine the subtree being examined.
176*7c478bd9Sstevel@tonic-gate#
177*7c478bd9Sstevel@tonic-gateif [ $# -eq 0 ]; then
178*7c478bd9Sstevel@tonic-gate	SUBTREE=$CURTREE
179*7c478bd9Sstevel@tonic-gateelif [ -d $1 ]; then
180*7c478bd9Sstevel@tonic-gate	SUBTREE=$1
181*7c478bd9Sstevel@tonic-gateelif [ -d $CODEMGR_WS/$1 ]; then
182*7c478bd9Sstevel@tonic-gate	SUBTREE=$CODEMGR_WS/$1
183*7c478bd9Sstevel@tonic-gateelse
184*7c478bd9Sstevel@tonic-gate	fail "neither \$CODEMGR_WS/$1 nor $1 exists as a directory"
185*7c478bd9Sstevel@tonic-gatefi
186*7c478bd9Sstevel@tonic-gate
187*7c478bd9Sstevel@tonic-gate#
188*7c478bd9Sstevel@tonic-gate# Get the canonical path to the subtree.
189*7c478bd9Sstevel@tonic-gate#
190*7c478bd9Sstevel@tonic-gatecd $SUBTREE
191*7c478bd9Sstevel@tonic-gateSUBTREE=`/bin/pwd`
192*7c478bd9Sstevel@tonic-gate
193*7c478bd9Sstevel@tonic-gate#
194*7c478bd9Sstevel@tonic-gate# Get the canonical path to the current directory.
195*7c478bd9Sstevel@tonic-gate#
196*7c478bd9Sstevel@tonic-gatecd $CURTREE
197*7c478bd9Sstevel@tonic-gateCURTREE=`/bin/pwd`
198*7c478bd9Sstevel@tonic-gate
199*7c478bd9Sstevel@tonic-gate#
200*7c478bd9Sstevel@tonic-gate# Get the canonical path to the workspace.
201*7c478bd9Sstevel@tonic-gate#
202*7c478bd9Sstevel@tonic-gatecd $CODEMGR_WS
203*7c478bd9Sstevel@tonic-gateCODEMGR_WS=`/bin/pwd`
204*7c478bd9Sstevel@tonic-gate
205*7c478bd9Sstevel@tonic-gateif [ "${SUBTREE##$CODEMGR_WS}" = "$SUBTREE" ]; then
206*7c478bd9Sstevel@tonic-gate	fail "$SUBTREE is not a subtree of \$CODEMGR_WS"
207*7c478bd9Sstevel@tonic-gatefi
208*7c478bd9Sstevel@tonic-gate
209*7c478bd9Sstevel@tonic-gateif [ "${CURTREE##$CODEMGR_WS}" = "$CURTREE" ]; then
210*7c478bd9Sstevel@tonic-gate	fail "$CURTREE is not a subtree of \$CODEMGR_WS"
211*7c478bd9Sstevel@tonic-gatefi
212*7c478bd9Sstevel@tonic-gate
213*7c478bd9Sstevel@tonic-gate#
214*7c478bd9Sstevel@tonic-gate# Find and execute all inc.flg's below our subtree.
215*7c478bd9Sstevel@tonic-gate#
216*7c478bd9Sstevel@tonic-gateincflg $SUBTREE
217*7c478bd9Sstevel@tonic-gate
218*7c478bd9Sstevel@tonic-gate#
219*7c478bd9Sstevel@tonic-gate# Find and execute all req.flg's at or above our subtree.
220*7c478bd9Sstevel@tonic-gate#
221*7c478bd9Sstevel@tonic-gateTREE=$SUBTREE
222*7c478bd9Sstevel@tonic-gatewhile [ $TREE != $CODEMGR_WS ]; do
223*7c478bd9Sstevel@tonic-gate	[ -f $TREE/req.flg ] && exec_file $TREE/req.flg
224*7c478bd9Sstevel@tonic-gate	TREE=`dirname $TREE`
225*7c478bd9Sstevel@tonic-gatedone
226*7c478bd9Sstevel@tonic-gate
227*7c478bd9Sstevel@tonic-gateexit 0
228