0cb6ac27918ff7cc6d029fd53c434873a38a8cc8
[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         OSF1*)
186                 ARCH=osf1
187                 LINKTESTFLAG="-L"
188         ;;
189  
190         SunOS\ 4.1*)
191                 ARCH=sunos
192         ;;
193
194         SunOS\ 5*)
195                 case "`uname -m`" in
196  
197                         hal*) 
198                                 ARCH=halos
199                         ;;
200  
201                         i86*)
202                                 ARCH=solaris-386
203                         ;;
204  
205                         sun4*) 
206                                 ARCH=solaris
207                         ;;
208                 esac
209         ;;
210
211         UNIX_System_V\ 4.2*)
212                 # Based on DS/90 server...
213                 case "`uname -m`" in
214                         DS/90*)
215                                 ARCH=uxpds
216                         ;;
217                 esac
218         ;;
219
220         *4.2MP)
221                 ARCH=mips
222         ;;
223
224         Linux*)
225                 case "`uname -i`" in
226
227                         i386*)
228                                 ARCH=i386
229                         ;;
230
231                         x86_64*)
232                                 ARCH=amd64
233                         ;;
234
235                         *)
236                                 ARCH=unknown
237                         ;;
238                 esac
239         ;;
240
241         FreeBSD*)
242                 case "`uname -m`" in
243
244                         i386*)
245                                 ARCH=i386
246                         ;;
247
248                         amd64*)
249                                 ARCH=amd64
250                         ;;
251
252                         *)
253                                 ARCH=unknown
254                         ;;
255                 esac
256         ;;
257
258         OpenBSD*)
259                 case "`uname -m`" in
260
261                         i386*)
262                                 ARCH=i386
263                         ;;
264
265                         amd64*)
266                                 ARCH=amd64
267                         ;;
268
269                         powerpc*)
270                                 ARCH=powerpc
271                         ;;
272
273                         *)
274                                 ARCH=unknown
275                         ;;
276                 esac
277         ;;
278
279         NetBSD*)
280                 case "`uname -m`" in
281
282                         i386*)
283                                 ARCH=i386
284                         ;;
285
286                         amd64*)
287                                 ARCH=amd64
288                         ;;
289
290                         *)
291                                 ARCH=unknown
292                         ;;
293                 esac
294         ;;
295
296         *)
297                 err_f "Does not run under [$OS]"
298         ;;
299 esac
300
301         
302 ###############################################################################
303 #
304 #       Find the toolkit's real home.
305 #
306 ###############################################################################
307
308 if [ $LINKTESTFLAG $CMD -a -z "$DTINFO_HOME" ] ; then
309         cd $HERE
310         while [ $LINKTESTFLAG $OTK_NAME ] ; do
311                 OLD=$CMD
312                 CMD=`ls -l $OTK_NAME | sed -e 's/.*->[ ]*//g'`
313                 mydirname_f $CMD
314                 cd $HEAD
315                 mybasename_f $CMD
316                 OTK_NAME=$BASE
317                 HEAD=`pwd`
318                  CMD=$HEAD/$OTK_NAME
319         done
320         mydirname_f $HEAD
321
322 elif [ -z "$DTINFO_HOME" ] ; then
323
324         #######################################################################
325         #
326         #       An explicit path has been given, but the environment variable
327         #       is not set.
328         #
329         #######################################################################
330
331         if [ "$HERE" = "." ] ; then
332                 HERE=`pwd`
333         elif [ `expr $HERE : '.*\.\..*'` -gt 0 ] ; then
334                 cd $HERE
335                 HERE=`pwd`
336         fi
337         mydirname_f $HERE
338
339 else
340
341         if [ -d $DTINFO_HOME ] ; then
342         
343                 cd $DTINFO_HOME
344                 DTINFO_HOME=`pwd`
345
346         else
347
348                 err_f "The DtInfo ToolKit does not appear to be installed
349 correctly in [$DTINFO_HOME].  Set the environment variable, 
350 DTINFO_HOME, to the directory where the DtInfo ToolKit is installed, 
351 or use a fully qualified path when invoking [otk]."
352
353         fi
354
355 fi
356
357 ###############################################################################
358 #
359 #       Look in a default place if DTINFO_HOME not set.
360 #       Set path to default information library
361 #       Add DTINFO_BIN to path
362 #
363 ###############################################################################
364
365 DTINFO_HOME=${DTINFO_HOME:-$HEAD}
366  DTINFO_BIN=${DTINFO_BIN:-$DTINFO_HOME/bin}
367 # the infolib/etc dir contains most library and bin type files
368  DTINFO_LIB=${DTINFO_LIB:-$DTINFO_HOME/infolib/etc}
369       PATH=${DTINFO_BIN}:${DTINFO_LIB}:${PATH}
370
371 if [ ! -d $DTINFO_LIB ] ; then
372
373         err_f "The $ARCH binaries were not installed in
374                $DTINFO_BIN"
375
376 fi
377
378 PATH=${PATH}:${USERPATH}
379
380 ###############################################################################
381 #
382 #       Create the command line and invoke the DtInfo build tools
383 #
384 ###############################################################################
385
386 cd $THISPLACE
387 eval $DTINFO_LIB/dtinfogen_worker $ARGUMENT
388 RETCODE=$?
389
390 exit $RETCODE