Use POSIX macros for linux
[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(__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 #if defined (_AIX)
176 XCOMM ##########################################################################
177 XCOMM
178 XCOMM  Setup keyboard mapping for local display if required
179 XCOMM
180 XCOMM ##########################################################################
181
182 #if 0
183 /*
184  * The keyboard mapping method depends upon how the session is started:
185  *
186  * - from dtlogin with a local X server
187  *   
188  *   This is generally the case for the console. Since the keyboard is
189  *   on the login server, the keyboard mapping will be done in Xsetup
190  *   and the language will be determined via querybkd. 
191  *
192  * - from dtlogin with a remote X server
193  *
194  *   The is generally the case for X stations. Since the keyboard is not
195  *   on the login server, we cannot query for the language. The keyboard
196  *   language will thus be provided in the KBD_MAP table setup by the
197  *   sysadmin and the keyboard mapping will be done in Xsetup. 
198  *
199  * - using 'xinit /usr/dt/bin/Xsession' from an HFT/LFT
200  *   
201  *   Since the keyboard is local, the keyboard mapping will be done in 
202  *   Xsession and the language will be determined via querykbd.
203  *   
204  * - starting Xsession from an x_st_mgr provided aixterm on an X station
205  *   
206  *   The X station manager sets up the keyboard mapping in this case, so
207  *   no work is required.
208  */
209 #endif
210
211 SetKeyboardMap()
212 {
213   HASH $1 = language name
214
215 #if defined (AIXV4)
216 #  define cpp_KBDALTFILE "$KBD_LIST $XMODDIR/${1}@alt/keyboard"
217 #else
218 #  define cpp_KBDALTFILE "$KBD_LIST $XMODDIR/$1/keyboard.alt"
219 #endif
220
221   KBD_LIST=""
222   KBD_LIST="$KBD_LIST $IMKEYMAPPATH/$1/keyboard"
223   if [ "$IMKEYMAPPATH" = "/usr/lib/nls/im.alt" ]; then
224     KBD_LIST=cpp_KBDALTFILE
225   fi
226   KBD_LIST="$KBD_LIST $XMODDIR/$1/keyboard"
227
228   for i in $KBD_LIST; do
229     if [ -r $i ]; then
230 #ifdef cpp_Xsession
231       Log "starting xmodmap $i"
232 #endif
233       $XDIR/xmodmap $i
234       return 0
235     fi
236   done
237
238   return 1
239 }
240
241 #ifdef cpp_Xsession
242   if [ "${pexec##*/}" != "dtlogin" -a -z "$XSTATION" ]; then
243     HASH
244     HASH If Xsession started by dtlogin, it is assumed that the keyboard mapping
245     HASH was set up in Xsetup. If Xsession not started by dtlogin, but XSTATION
246     HASH set, it is assumed that the keyboard mapping was set up by x_st_mgr.
247     HASH
248 #endif
249     
250 #if defined (AIXV4)
251 # define cpp_CNAME "C"
252 #else
253 # define cpp_CNAME "C.hft"
254 #endif
255
256 #ifdef cpp_Xsetup
257     HASH
258     HASH Determine keyboard language
259     HASH
260     KBD_LANG=""
261     if [ "$DTXSERVERLOCATION" = "local" ]; then
262       HASH
263       HASH Local display so query for keyboard map
264       HASH
265       KBD_LANG=`/usr/lpp/X11/bin/querykbd`
266     else
267       HASH
268       HASH Non-local display so use KEY_MAP list
269       HASH
270       let i=0
271       while true; do
272         [ -z "${KBD_MAP[i]}" ] && break
273         if [ "$DISPLAY" = "${KBD_MAP[i]%% *}" ]; then
274           KBD_LANG=${KBD_MAP[i]##* }
275           break
276         fi
277         let i=$i+1
278       done
279     fi
280 #endif
281 #ifdef cpp_Xsession
282     KBD_LANG=`/usr/lpp/X11/bin/querykbd`
283 #endif
284
285     HASH
286     HASH Set up keyboard mapping
287     HASH 
288     KBD=""
289     XMODDIR=/usr/lpp/X11/defaults/xmodmap
290
291     if [ ! -z "$KBD_LANG" ]; then
292       if [ "$KBD_LANG" != "NULL" -a "$KBD_LANG" != cpp_CNAME ]; then
293         SetKeyboardMap $KBD_LANG
294         if [ $? != 0 ]; then
295           SetKeyboardMap $LANG
296         fi
297       else
298         SetKeyboardMap $LANG
299       fi
300     fi
301     
302 #ifdef cpp_Xsession
303   fi
304 #endif
305 #endif
306
307 #if defined(__linux__)
308 #ifdef cpp_Xsetup
309     if [ "$DTXSERVERLOCATION" != "remote" ]; then
310       fontpath=
311       FONTLIB=/usr/share/fonts/X11
312       for i in misc 75dpi 100dpi Speedo Type1 PJE
313       do
314          if [ -f $FONTLIB/$i/fonts.dir ];  then
315              if [ ! -z "$fontpath" ]; then
316                 fontpath=$fontpath,$FONTLIB/$i/
317              else
318                 fontpath=$FONTLIB/$i/
319              fi
320          fi
321       done
322
323       if [ ! -z "$fontpath" ]; then
324         $XDIR/xset fp+ $fontpath
325       fi
326     fi
327 #endif
328 #endif
329
330 #if defined(CSRG_BASED)
331 #ifdef cpp_Xsetup
332     if [ "$DTXSERVERLOCATION" != "remote" ]; then
333       fontpath=
334 #if defined(__FreeBSD__)
335       FONTLIB=/usr/local/lib/X11/fonts
336 #elif defined(__OpenBSD__)
337       FONTLIB=/usr/X11R6/lib/X11/fonts
338 #elif defined(__NetBSD__)
339       FONTLIB=/usr/X11R7/lib/X11/fonts
340 #endif
341       for i in misc 75dpi 100dpi Speedo Type1 PJE
342       do
343          if [ -f $FONTLIB/$i/fonts.dir ];  then
344              if [ ! -z "$fontpath" ]; then
345                 fontpath=$fontpath,$FONTLIB/$i/
346              else
347                 fontpath=$FONTLIB/$i/
348              fi
349          fi
350       done
351
352       if [ ! -z "$fontpath" ]; then
353         $XDIR/xset fp+ $fontpath
354       fi
355     fi
356 #endif
357 #endif
358