FreeBSD: Don't set MANPATH, use OS configuration
[oweals/cde.git] / cde / programs / dtlogin / config / _common.ksh.src
1 #if 0
2 /*
3  *  _common.ksh.src
4  *
5  *  Common Desktop Environment (CDE)
6  *
7  *  Common code for dtlogin config scripts
8  *
9  * (c) Copyright 1996 Digital Equipment Corporation.
10  * (c) Copyright 1993,1994,1996 Hewlett-Packard Company.
11  * (c) Copyright 1993,1994,1996 International Business Machines Corp.
12  * (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
13  * (c) Copyright 1993,1994,1996 Novell, Inc. 
14  * (c) Copyright 1996 FUJITSU LIMITED.
15  * (c) Copyright 1996 Hitachi.
16  * (c) Copyright 1997, The Open Group.
17  *
18  * $TOG: _common.ksh.src /main/12 1998/05/13 17:48:34 rafi $
19  */
20 #endif
21 #define HASH #
22
23 #if 0
24 /*
25  * Note: this file is included by Xsession.src and Xsetup.src. If
26  * Xsession is being built, cpp_Xsession will be defined. If Xsetup
27  * is being built, cpp_Xsetup will be defined.
28  */
29 #endif
30
31 #ifdef cpp_Xsession
32   HASH
33   HASH Determine Xsession parent
34   HASH
35 #if defined (__osf__)
36   pexec=$(LC_TIME=C ps -p $PPID | awk 'NR==2 {print $5}')
37 #elif defined(USL) && (OSMAJORVERSION > 1)
38   pexec=$(LC_TIME=C ps -p $PPID | awk 'NR==2 {print $6}')
39 #elif defined(linux) || defined(CSRG_BASED) && !defined(__FreeBSD__)
40   pexec=$(LC_TIME=C /bin/ps -p $PPID 2>/dev/null | awk 'NR==2 {print $4}')
41 #elif defined(__FreeBSD__)
42   pexec=$(LC_TIME=C /bin/ps -o comm= -p $PPID 2>/dev/null)
43 #else
44   pexec=$(LC_TIME=C /usr/bin/ps -p $PPID | awk 'NR==2 {print $4}')
45 #endif
46   Log "Xsession started by $pexec"
47 #endif
48
49 XCOMM ##########################################################################
50 XCOMM  
51 XCOMM Append desktop font aliases to font path
52 XCOMM
53 XCOMM ##########################################################################
54
55 #if defined(sun)
56 ADDFONTPATH() {
57         HASH Combine lines together to make arguments for the xset command
58         FP=`awk '
59         BEGIN { fp="fp+ " }
60         /^[     ]*$/ { fp=" +fp " ; continue }
61         { printf("%s%s", fp, $0) ; fp="," } ' $1`
62         if [ -n "$FP" ]; then
63 #ifdef cpp_Xsession
64                 Log "setting auxiliary font path..."
65 #endif
66                 eval "xset $FP"
67         fi
68 }
69 #endif /* sun */
70
71 #ifdef cpp_Xsession
72   if [ "${pexec##*/}" != "dtlogin" ]; then
73     HASH
74     HASH If Xsession launched by dtlogin, it is assumed that the desktop
75     HASH font path has already been added by Xsetup, so no need to add it here.
76     HASH 
77 #endif
78 #if defined (sun)
79
80     if [ -r $OPENWINHOME/lib/locale/${LANG-C}/OWfontpath ]; then
81       ADDFONTPATH $OPENWINHOME/lib/locale/${LANG-C}/OWfontpath
82     fi
83
84     HASH
85     HASH Switch Sun's Alt and Meta mod mappings to work with Motif
86     HASH
87     if $XDIR/xmodmap | /bin/grep mod4 | /bin/grep Alt > /dev/null 2>/dev/null
88     then
89         $XDIR/xmodmap -e "clear Mod1" \
90                 -e "clear Mod4" \
91                 -e "add Mod1 = Alt_L" \
92                 -e "add Mod1 = Alt_R" \
93                 -e "add Mod4 = Meta_L" \
94                 -e "add Mod4 = Meta_R"
95     fi
96
97 #endif /* sun */
98     HASH
99     HASH Append desktop font paths. Note: these directories should be
100     HASH accessable by the X server. The file precedence is:
101     HASH
102     HASH   CDE_CONFIGURATION_TOP/config/xfonts/$LANG
103     HASH   CDE_INSTALLATION_TOP/config/xfonts/$LANG
104     HASH   CDE_CONFIGURATION_TOP/config/xfonts/C
105     HASH   CDE_INSTALLATION_TOP/config/xfonts/C
106     HASH
107 #ifdef cpp_Xsession
108     Log "setting font path..."
109 #endif
110 #if defined (_AIX)
111     if [ "$DTXSERVERLOCATION" != "remote" -a -z "$XSTATION" ]; then
112 #else
113     if [ "$DTXSERVERLOCATION" != "remote" ]; then
114 #endif
115       HASH
116       HASH Since X server is local, optimize by checking local desktop
117       HASH font directories and making one call to xset.
118       HASH
119
120       if [ "${LANG-C}" != "C" ]; then
121         if [ -f CDE_CONFIGURATION_TOP/config/xfonts/$LANG/fonts.dir ]; then
122           fontpath=CDE_CONFIGURATION_TOP/config/xfonts/$LANG
123         fi
124
125         if [ -f CDE_INSTALLATION_TOP/config/xfonts/$LANG/fonts.dir ]; then
126           if [ -z "$fontpath" ]; then
127             fontpath=CDE_INSTALLATION_TOP/config/xfonts/$LANG
128           else
129             fontpath=$fontpath,CDE_INSTALLATION_TOP/config/xfonts/$LANG
130           fi
131         fi
132       fi
133
134       if [ -f CDE_CONFIGURATION_TOP/config/xfonts/C/fonts.dir ]; then
135           if [ -z "$fontpath" ]; then
136             fontpath=CDE_CONFIGURATION_TOP/config/xfonts/C
137           else
138             fontpath=$fontpath,CDE_CONFIGURATION_TOP/config/xfonts/C
139           fi
140       fi
141
142       if [ -f CDE_INSTALLATION_TOP/config/xfonts/C/fonts.dir ]; then
143         if [ -z "$fontpath" ]; then
144           fontpath=CDE_INSTALLATION_TOP/config/xfonts/C
145         else
146           fontpath=$fontpath,CDE_INSTALLATION_TOP/config/xfonts/C
147         fi
148       fi
149
150
151       if [ ! -z "$fontpath" ]; then
152         $XDIR/xset fp+ $fontpath
153       fi
154
155     else
156       HASH
157       HASH Since X server not local, we don't know if the desktop font
158       HASH directories exist on the X server machine, so we have to
159       HASH set them one at a time.
160       HASH
161
162       if [ "${LANG-C}" != "C" ]; then 
163         $XDIR/xset fp+ CDE_CONFIGURATION_TOP/config/xfonts/$LANG 1>/dev/null
164
165         $XDIR/xset fp+ CDE_INSTALLATION_TOP/config/xfonts/$LANG 1>/dev/null
166       fi
167
168       $XDIR/xset fp+ CDE_CONFIGURATION_TOP/config/xfonts/C 1>/dev/null
169
170       $XDIR/xset fp+ CDE_INSTALLATION_TOP/config/xfonts/C 1>/dev/null
171
172     fi
173 #ifdef cpp_Xsession
174   fi 
175 #endif
176
177
178 #if defined (__osf__)
179 #ifdef cpp_Xsetup
180
181     if [ "$DTXSERVERLOCATION" != "remote" ]; then
182       HASH
183       HASH We can only modify the font path or the keymap if the X server is
184       HASH local.
185       HASH
186       HASH Since X server is local, optimize by checking local desktop
187       HASH font directories and making one call to xset.
188       HASH
189       HASH
190       HASH
191       HASH check if the system has a Low or High Resolution Monitor
192       HASH   -  High Resolution (1280 x 1024) uses 100 dpi fonts.
193       HASH   -  Medium Resolution (1024 x 864 ) uses 75 dpi fonts.
194       HASH   -  Low Resolution (1024 x 768 or lower) uses 75 dpi fonts.
195       HASH This will only switch to 75dpi fonts if there is a low or medium
196       HASH resolution monitor found.  
197       HASH
198       HASH
199       fd=""
200       prefplist=""
201       appfplist=""
202       setfont="No"
203       FONTLIB="/usr/lib/X11/fonts"
204       I18N="/usr/i18n/lib/X11/fonts/decwin"
205       pixwidth=`/usr/sbin/sizer -gr | awk -Fx ' { print $1 } ' `
206       if [ ${pixwidth} -lt 1280 ] 
207       then
208          nat_res="75dpi"
209          alt_res="100dpi"
210       else
211          nat_res="100dpi"
212          alt_res="75dpi"
213       fi
214
215       HASH
216       HASH Add scalable fonts to the font path, based on 
217       HASH screen resolution
218       HASH
219       if [ ${pixwidth} -lt 1024 ] 
220       then
221           HASH
222           HASH Prepend fontpaths
223           HASH
224           prefplist="${FONTLIB}/Speedo ${FONTLIB}/Type1 ${FONTLIB}/Type1Adobe"
225       else
226           HASH
227           HASH Append fontpaths 
228           HASH
229           appfplist="${FONTLIB}/Type1Adobe"
230       fi
231
232       HASH
233       HASH Append fontpaths
234       HASH add optional extra fonts
235       HASH
236       cde_configuration_top=CDE_CONFIGURATION_TOP
237       cde_installation_top=CDE_INSTALLATION_TOP
238       appfplist="${appfplist} ${FONTLIB}/user/${nat_res} ${FONTLIB}/user/misc"
239       if [ "${LANG-C}" != "C" ]; then
240         appfplist="${appfplist} $cde_configuration_top/config/xfonts/$LANG/$nat_res"
241         appfplist="${appfplist} $cde_configuration_top/config/xfonts/$LANG/$alt_res"
242       fi
243       appfplist="${appfplist} $cde_configuration_top/config/xfonts/C"
244       appfplist="${appfplist} $cde_configuration_top/config/xfonts/C/$nat_res"
245       appfplist="${appfplist} $cde_configuration_top/config/xfonts/C/$alt_res"
246       if [ "${LANG-C}" != "C" ]; then
247         appfplist="${appfplist} $cde_installation_top/config/xfonts/$LANG/$nat_res"
248         appfplist="${appfplist} $cde_installation_top/config/xfonts/$LANG/$alt_res"
249       fi
250       appfplist="${appfplist} $cde_installation_top/config/xfonts/C"
251       appfplist="${appfplist} $cde_installation_top/config/xfonts/C/$nat_res"
252       appfplist="${appfplist} $cde_installation_top/config/xfonts/C/$alt_res"
253
254       HASH
255       HASH Prepend fontpaths
256       HASH add i18n fonts if they exist
257       HASH
258       prefplist="${I18N}/${nat_res} ${I18N}/${alt_res} ${prefplist}"
259
260       HASH
261       HASH Prepend to fontpath
262       HASH
263       for i in ${prefplist} 
264       do 
265          if [ -f ${i}/fonts.dir ]
266          then 
267              if [ $fd ] 
268              then
269                 fd="${fd},${i}/" 
270              else
271                 fd="${i}/"
272                 setfont="Yes" 
273              fi
274          fi 
275       done
276
277       if [ ${setfont} = Yes ]
278       then
279          $XDIR/xset +fp ${fd}
280          if [ $? -ne 0 ] 
281          then
282             HASH
283             HASH set the old slow way.....
284             HASH
285             for i in ${prefplist}
286             do
287               if [ -f ${i}/fonts.dir ]
288               then
289                   $XDIR/xset +fp ${i}
290               fi
291             done
292          fi
293          HASH
294          HASH End of the setting the old slow way.........
295          HASH
296          fd=""
297          setfont='No'
298       fi  
299
300       HASH
301       HASH Append to fontpath
302       HASH
303       for i in ${appfplist}
304       do
305          if [ -f ${i}/fonts.dir ]
306          then
307              if [ $fd ]
308              then
309                 fd="${fd},${i}/"
310              else
311                 fd="${i}/"
312                 setfont="Yes"
313              fi
314          fi
315       done
316
317       if [ ${setfont} = Yes ]
318       then
319          $XDIR/xset fp+ ${fd}
320          if [ $? -ne 0 ] 
321          then
322             HASH
323             HASH set the old slow way.....
324             HASH
325             for i in ${appfplist}
326             do
327               if [ -f ${i}/fonts.dir ]
328               then
329                   $XDIR/xset fp+ ${i}
330               fi
331             done
332          fi
333          HASH
334          HASH End of the setting the old slow way.........
335          HASH
336       fi
337
338
339     fi
340 #endif
341 #endif
342
343 #if defined (_AIX)
344 XCOMM ##########################################################################
345 XCOMM
346 XCOMM  Setup keyboard mapping for local display if required
347 XCOMM
348 XCOMM ##########################################################################
349
350 #if 0
351 /*
352  * The keyboard mapping method depends upon how the session is started:
353  *
354  * - from dtlogin with a local X server
355  *   
356  *   This is generally the case for the console. Since the keyboard is
357  *   on the login server, the keyboard mapping will be done in Xsetup
358  *   and the language will be determined via querybkd. 
359  *
360  * - from dtlogin with a remote X server
361  *
362  *   The is generally the case for X stations. Since the keyboard is not
363  *   on the login server, we cannot query for the language. The keyboard
364  *   language will thus be provided in the KBD_MAP table setup by the
365  *   sysadmin and the keyboard mapping will be done in Xsetup. 
366  *
367  * - using 'xinit /usr/dt/bin/Xsession' from an HFT/LFT
368  *   
369  *   Since the keyboard is local, the keyboard mapping will be done in 
370  *   Xsession and the language will be determined via querykbd.
371  *   
372  * - starting Xsession from an x_st_mgr provided aixterm on an X station
373  *   
374  *   The X station manager sets up the keyboard mapping in this case, so
375  *   no work is required.
376  */
377 #endif
378
379 SetKeyboardMap()
380 {
381   HASH $1 = language name
382
383 #if defined (AIXV4)
384 #  define cpp_KBDALTFILE "$KBD_LIST $XMODDIR/${1}@alt/keyboard"
385 #else
386 #  define cpp_KBDALTFILE "$KBD_LIST $XMODDIR/$1/keyboard.alt"
387 #endif
388
389   KBD_LIST=""
390   KBD_LIST="$KBD_LIST $IMKEYMAPPATH/$1/keyboard"
391   if [ "$IMKEYMAPPATH" = "/usr/lib/nls/im.alt" ]; then
392     KBD_LIST=cpp_KBDALTFILE
393   fi
394   KBD_LIST="$KBD_LIST $XMODDIR/$1/keyboard"
395
396   for i in $KBD_LIST; do
397     if [ -r $i ]; then
398 #ifdef cpp_Xsession
399       Log "starting xmodmap $i"
400 #endif
401       $XDIR/xmodmap $i
402       return 0
403     fi
404   done
405
406   return 1
407 }
408
409 #ifdef cpp_Xsession
410   if [ "${pexec##*/}" != "dtlogin" -a -z "$XSTATION" ]; then
411     HASH
412     HASH If Xsession started by dtlogin, it is assumed that the keyboard mapping
413     HASH was set up in Xsetup. If Xsession not started by dtlogin, but XSTATION
414     HASH set, it is assumed that the keyboard mapping was set up by x_st_mgr.
415     HASH
416 #endif
417     
418 #if defined (AIXV4)
419 # define cpp_CNAME "C"
420 #else
421 # define cpp_CNAME "C.hft"
422 #endif
423
424 #ifdef cpp_Xsetup
425     HASH
426     HASH Determine keyboard language
427     HASH
428     KBD_LANG=""
429     if [ "$DTXSERVERLOCATION" = "local" ]; then
430       HASH
431       HASH Local display so query for keyboard map
432       HASH
433       KBD_LANG=`/usr/lpp/X11/bin/querykbd`
434     else
435       HASH
436       HASH Non-local display so use KEY_MAP list
437       HASH
438       let i=0
439       while true; do
440         [ -z "${KBD_MAP[i]}" ] && break
441         if [ "$DISPLAY" = "${KBD_MAP[i]%% *}" ]; then
442           KBD_LANG=${KBD_MAP[i]##* }
443           break
444         fi
445         let i=$i+1
446       done
447     fi
448 #endif
449 #ifdef cpp_Xsession
450     KBD_LANG=`/usr/lpp/X11/bin/querykbd`
451 #endif
452
453     HASH
454     HASH Set up keyboard mapping
455     HASH 
456     KBD=""
457     XMODDIR=/usr/lpp/X11/defaults/xmodmap
458
459     if [ ! -z "$KBD_LANG" ]; then
460       if [ "$KBD_LANG" != "NULL" -a "$KBD_LANG" != cpp_CNAME ]; then
461         SetKeyboardMap $KBD_LANG
462         if [ $? != 0 ]; then
463           SetKeyboardMap $LANG
464         fi
465       else
466         SetKeyboardMap $LANG
467       fi
468     fi
469     
470 #ifdef cpp_Xsession
471   fi
472 #endif
473 #endif
474
475 #if defined(linux)
476 #ifdef cpp_Xsetup
477     if [ "$DTXSERVERLOCATION" != "remote" ]; then
478       fontpath=
479       FONTLIB=/usr/share/fonts/X11
480       for i in misc 75dpi 100dpi Speedo Type1 PJE
481       do
482          if [ -f $FONTLIB/$i/fonts.dir ];  then
483              if [ ! -z "$fontpath" ]; then
484                 fontpath=$fontpath,$FONTLIB/$i/
485              else
486                 fontpath=$FONTLIB/$i/
487              fi
488          fi
489       done
490
491       if [ ! -z "$fontpath" ]; then
492         $XDIR/xset fp+ $fontpath
493       fi
494     fi
495 #endif
496 #endif
497
498 #if defined(CSRG_BASED)
499 #ifdef cpp_Xsetup
500     if [ "$DTXSERVERLOCATION" != "remote" ]; then
501       fontpath=
502       FONTLIB=/usr/local/lib/X11/fonts
503       for i in misc 75dpi 100dpi Speedo Type1 PJE
504       do
505          if [ -f $FONTLIB/$i/fonts.dir ];  then
506              if [ ! -z "$fontpath" ]; then
507                 fontpath=$fontpath,$FONTLIB/$i/
508              else
509                 fontpath=$FONTLIB/$i/
510              fi
511          fi
512       done
513
514       if [ ! -z "$fontpath" ]; then
515         $XDIR/xset fp+ $fontpath
516       fi
517     fi
518 #endif
519 #endif
520