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