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