dtinfogen: don't override PATH
[oweals/cde.git] / cde / programs / dtinfo / dtinfogen / infolib / etc / dtinfogen
1 #!/bin/sh
2
3 ###############################################################################
4 #
5 # $XConsortium: dtinfogen /main/10 1996/09/06 14:24:23 cde-hal $
6 # $Version$
7 # $XConsortium: dtinfogen /main/10 1996/09/06 14:24:23 cde-hal $ 
8 #
9 # Copyright (c) 1994 HaL Computer Systems, Inc.  All rights reserved.
10 # UNPUBLISHED -- rights reserved under the Copyright Laws of the United
11 # States.  Use of a copyright notice is precautionary only and does not
12 # imply publication or disclosure.
13 #
14 # This software contains confidential information and trade secrets of HaL
15 # Computer Systems, Inc.  Use, disclosure, or reproduction is prohibited
16 # without the prior express written permission of HaL Computer Systems, Inc.
17 #
18 #                         RESTRICTED RIGHTS LEGEND
19 # Use, duplication, or disclosure by the Government is subject to
20 # restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
21 # Technical Data and Computer Software clause at DFARS 252.227-7013.
22 #                        HaL Computer Systems, Inc.
23 #                  1315 Dell Avenue, Campbell, CA  95008               $
24 #
25 ###############################################################################
26
27 ###############################################################################
28 #
29 #       Set up shell traps
30 #
31 ###############################################################################
32
33 RETCODE=0
34
35 trap '\
36         RETCODE=${RETCODE:-$?}          ;\
37         exit $RETCODE \
38 ' 0 1 2 3 4 5 6 7 8 10 12 15
39
40 ###############################################################################
41 #
42 #       Environment variables that this shell script sets/changes:
43 #
44 ###############################################################################
45
46 export  ARCH DTINFO_HOME OTK_NAME
47
48
49 ###############################################################################
50 #
51 #       Functions:
52 #               err_f            - reports an error message and exits
53 #               msg_f            - reports messages
54 #               mybasename_f     - returns a basename using expr in BASE
55 #               mydirname_f      - returns a path using expr in HEAD
56 #                                       user's font path
57 #               warn_f           - reports a warning message
58 #
59 ###############################################################################
60
61 ###############################################################################
62
63
64 err_f () {
65
66 msg_f "${OTK_NAME:-$0}: *** ERROR - $@"
67 exit 3
68
69 }
70
71 ###############################################################################
72
73 msg_f () {
74
75 echo "
76 $@ 
77 " 1>&2
78
79 }
80
81 ###############################################################################
82
83 mybasename_f() {
84
85 if [ -z "$1" ] ; then
86         err_f "mybasename_f() passed an empty argument."
87 fi
88
89 BASE=`expr \
90         $1 : '.*/\([^/][^/]*\)$' \| \
91         $1 : '\([^/][^/]*\)$' \| \
92         "\/"`
93
94 if [ "$BASE" = "\/" ] ; then
95         warn_f "mybasename_f() passed a path [$1]."
96         BASE=""
97 fi
98
99 }
100
101 ###############################################################################
102
103 mydirname_f() {
104
105 if [ -z "$1" ] ; then
106         err_f "mydirname_f() passed an empty path."
107 fi
108
109 HEAD=`expr \
110         $1 : '\(.*[^/]\)//*[^/]*$' \| \
111         $1 : '\(/\)[^/]*$' \| \
112         .`
113
114 if [ "$HEAD" = "$1" ] ; then
115         HEAD="."
116 elif [ -z "$HEAD" ] ; then
117         HEAD="/"
118 fi
119
120 }
121
122 ###############################################################################
123
124 warn_f () {
125
126 msg_f "${OTK_NAME:-$0}: *** WARNING - $@"
127
128 }
129
130 ###############################################################################
131
132 ###############################################################################
133 #
134 #       Initialize some useful variables
135 #
136 ###############################################################################
137
138        CMD=$0
139 DTINFO_HOME=${DTINFO_HOME:-""}
140
141 ARGUMENT=""
142 while [ $# -gt 0 ] ; do
143         if [ -n "`echo $1 | egrep ' '`" ] ; then
144                 ARGUMENT="$ARGUMENT \"$1\""
145         else
146                 ARGUMENT="$ARGUMENT $1"
147         fi
148         shift
149 done
150
151     THISPLACE=`pwd`
152   mydirname_f $CMD
153          HERE=`(cd $HEAD ; pwd)`
154  mybasename_f $CMD
155      OTK_NAME=$BASE
156
157 ###############################################################################
158 #
159 #       Determine the OS running to see if the binary will run at all,
160 #       also provide a mechanism to choose the correct binary for a
161 #       particular architecture automagically.
162 #
163 ###############################################################################
164
165           OS=`uname -sr`
166 LINKTESTFLAG="-h"
167 case "$OS" in
168
169         AIX*)
170                 ARCH=aix
171                 LINKTESTFLAG="-L"
172         ;;
173
174         HP-UX*)
175                 ARCH=hpux
176         ;;
177  
178         IRIX*)
179                 ARCH=irix
180                 LINKTESTFLAG="-l"
181         ;;
182  
183         SunOS\ 4.1*)
184                 ARCH=sunos
185         ;;
186
187         SunOS\ 5*)
188                 case "`uname -m`" in
189  
190                         hal*) 
191                                 ARCH=halos
192                         ;;
193  
194                         i86*)
195                                 ARCH=solaris-386
196                         ;;
197  
198                         sun4*) 
199                                 ARCH=solaris
200                         ;;
201                 esac
202         ;;
203
204         *4.2MP)
205                 ARCH=mips
206         ;;
207
208         Linux*)
209                 case "`uname -i`" in
210
211                         i386*)
212                                 ARCH=i386
213                         ;;
214
215                         x86_64*)
216                                 ARCH=amd64
217                         ;;
218
219                         *)
220                                 ARCH=unknown
221                         ;;
222                 esac
223         ;;
224
225         FreeBSD*)
226                 case "`uname -m`" in
227
228                         i386*)
229                                 ARCH=i386
230                         ;;
231
232                         amd64*)
233                                 ARCH=amd64
234                         ;;
235
236                         *)
237                                 ARCH=unknown
238                         ;;
239                 esac
240         ;;
241
242         OpenBSD*)
243                 case "`uname -m`" in
244
245                         i386*)
246                                 ARCH=i386
247                         ;;
248
249                         amd64*)
250                                 ARCH=amd64
251                         ;;
252
253                         powerpc*)
254                                 ARCH=powerpc
255                         ;;
256
257                         *)
258                                 ARCH=unknown
259                         ;;
260                 esac
261         ;;
262
263         NetBSD*)
264                 case "`uname -m`" in
265
266                         i386*)
267                                 ARCH=i386
268                         ;;
269
270                         amd64*)
271                                 ARCH=amd64
272                         ;;
273
274                         *)
275                                 ARCH=unknown
276                         ;;
277                 esac
278         ;;
279
280         *)
281                 err_f "Does not run under [$OS]"
282         ;;
283 esac
284
285         
286 ###############################################################################
287 #
288 #       Find the toolkit's real home.
289 #
290 ###############################################################################
291
292 if [ $LINKTESTFLAG $CMD -a -z "$DTINFO_HOME" ] ; then
293         cd $HERE
294         while [ $LINKTESTFLAG $OTK_NAME ] ; do
295                 OLD=$CMD
296                 CMD=`ls -l $OTK_NAME | sed -e 's/.*->[ ]*//g'`
297                 mydirname_f $CMD
298                 cd $HEAD
299                 mybasename_f $CMD
300                 OTK_NAME=$BASE
301                 HEAD=`pwd`
302                  CMD=$HEAD/$OTK_NAME
303         done
304         mydirname_f $HEAD
305
306 elif [ -z "$DTINFO_HOME" ] ; then
307
308         #######################################################################
309         #
310         #       An explicit path has been given, but the environment variable
311         #       is not set.
312         #
313         #######################################################################
314
315         if [ "$HERE" = "." ] ; then
316                 HERE=`pwd`
317         elif [ `expr $HERE : '.*\.\..*'` -gt 0 ] ; then
318                 cd $HERE
319                 HERE=`pwd`
320         fi
321         mydirname_f $HERE
322
323 else
324
325         if [ -d $DTINFO_HOME ] ; then
326         
327                 cd $DTINFO_HOME
328                 DTINFO_HOME=`pwd`
329
330         else
331
332                 err_f "The DtInfo ToolKit does not appear to be installed
333 correctly in [$DTINFO_HOME].  Set the environment variable, 
334 DTINFO_HOME, to the directory where the DtInfo ToolKit is installed, 
335 or use a fully qualified path when invoking [otk]."
336
337         fi
338
339 fi
340
341 ###############################################################################
342 #
343 #       Look in a default place if DTINFO_HOME not set.
344 #       Set path to default information library
345 #       Add DTINFO_BIN to path
346 #
347 ###############################################################################
348
349 DTINFO_HOME=${DTINFO_HOME:-$HEAD}
350  DTINFO_BIN=${DTINFO_BIN:-$DTINFO_HOME/bin}
351 # the infolib/etc dir contains most library and bin type files
352  DTINFO_LIB=${DTINFO_LIB:-$DTINFO_HOME/infolib/etc}
353       PATH=${DTINFO_BIN}:${DTINFO_LIB}:${PATH}
354
355 if [ ! -d $DTINFO_LIB ] ; then
356
357         err_f "The $ARCH binaries were not installed in
358                $DTINFO_BIN"
359
360 fi
361
362 ###############################################################################
363 #
364 #       Create the command line and invoke the DtInfo build tools
365 #
366 ###############################################################################
367
368 cd $THISPLACE
369 eval $DTINFO_LIB/dtinfogen_worker $ARGUMENT
370 RETCODE=$?
371
372 exit $RETCODE