Next Previous Contents

3. Preparing your environment

Before we start customizing various parts of the system functionality, we have to set up a couple basic things. Most of tools described below assume that there are Cyrillic fonts available and a user is able to input Cyrillic characters. To make it true we have to configure the environment to provide both fonts and input facility for Cyrillic.

There are effectively two interface models supported by Linux. One is the text mode, and the other one is the graphic mode, provided by the X Window System. Both require different setup, which will be described below.

3.1 Text mode setup

Generally, the text mode setup is the easiest way to show and input Cyrillic characters. There is one significant complication, however: the text mode fonts and keyboard layout manipulations depend on terminal driver implementation. Therefore, there is no portable way to achieve the goal across different systems.

Right now, I describe the way to deal with the Linux console driver. Thus, if you have another system, don't expect it to work for you. Instead, consult your terminal driver manual. Nevertheless, send me any information you find, so I'll be able to include it in further versions of this document.

Linux Console

The Linux console driver is quite a flexible piece of software. It is capable of changing fonts as well as keyboard layouts. To achieve it, you'll need the kbd package. Both RedHat and Slackware install kbd as part of a system.

The kbd package contains keyboard control utilities as well as a big collection of fonts and keyboard layouts.

Cyrillic setup with kbd usually involves two things:

  1. Screen font setup. This is performed by the setfont program. The fonts files are located in /usr/lib/kbd/consolefonts. NOTE: Never run the setfont program under X because it will hang your system. This is because it works with low-level video card calls which X doesn't like.
  2. Load the appropriate keyboard layout with the loadkeys program.

NOTE: In RedHat 3.0.3, /usr/bin/loadkeys has too restrictive access permissions, namely 700 (rwx------). There are no reasons for that, since everyone may compile his own copy and execute it (the appropriate system calls are not root-only). Thus, just ask your sysadmin to set more reasonable permissions for it (for example, 755).

The following is an excerpt from my cyrload script, which sets up the Cyrillic mode for Linux console:

if [ notset.$DISPLAY != notset. ]; then
    echo "`basename $0`:  cannot run under X"
    exit
fi

loadkeys /usr/lib/kbd/keytables/ru.map
setfont /usr/lib/kbd/consolefonts/Cyr_a8x16
mapscrn /usr/lib/kbd/consoletrans/koi2alt
echo -ne "\033(K"              # the magic sequence
echo "Use the right Ctrl key to switch the mode..."

Let me explain it a bit. You load the appropriate keyboard mapping. Then you load a font corresponding to the Alt codeset. Then, in order to be able to display text in KOI8-R correctly, you load a screen translation table. What it does is a translation of some characters from the upper half of the codeset to the Alt encoding. The word 'some' is crucial here - not all characters get translated, therefore some of them, like IBM pseudographic characters get unmodified to the screen and display correctly, since they are compatible with the Alt codeset, as opposed to KOI8-R. To ensure this, run mc and pretend you are back to MS-DOS 3.3...

Finally, the magic sequence is important but I have no idea what on the Earth it does. I stole/borrowed/learned it from German HOWTO back in 1994, when it was like the only national language oriented HOWTO. If you have any idea about this magic sequence, please tell me.

Finally, for those purists, who don't wont to give the Alt codeset a chance, I'm attaching yet another version of the script above, using native KOI8-R fonts.

if [ notset.$DISPLAY != notset. ]; then
    echo "`basename $0`:  cannot run under X"
    exit
fi

loadkeys /usr/lib/kbd/keytables/ru.map
setfont /usr/lib/kbd/consolefonts/koi-8x16
echo "Use the right Ctrl key to switch the mode..."

However, don't expect nice borders in your text mode-based windowing applications.

Now you probably want to test it. Do the appropriate bash or tcsh setup, rerun it, then press the right Control key and make sure you are getting the cyrillic characters right. The 'q' key must produce russian "short i" character, 'w' generates "ts", etc.

If you've screwed something up, the very best thing to do is to reset to the original (that is, US) settings. Execute the following commands:

loadkeys /usr/lib/kbd/keytables/defkeymap.map
setfont /usr/lib/kbd/consolefonts/default8x16

NOTE: unfortunately enough, the console driver is not able to preserve it's state (at least easily enough), while running the X Window System. Therefore, after you leave the X (or switch from it to a console), you have to reload the console russian font.

FreeBSD Console

I am not using FreeBSD so I couldn't test the following information. All data in this section should be treated as just pointers to begin with. The FreeBSD project homepage may have some information on the subject. Another good source is the relcom.fido.ru.unix newsgroup. Also, check the resources listed in section resources .

Anyway, this is what Ilya K. Orehov suggests to do in order to make FreeBSD console speak Russian:

  1. In /etc/sysconfig add:
    
    keymap=ru.koi8-r
    keyrate=fast
    # NOTE: '^[' below is a single control character
    keychange="61 ^[[K"
    cursor=destructive
    scrnmap=koi8-r2cp866
    font8x16=cp866b-8x16
    font8x14=cp866-8x14
    font8x8=cp866-8x8
    
  2. In /etc/csh.login:
    setenv ENABLE_STARTUP_LOCALE
    setenv LANG ru_SU.KOI8-R
    setenv LESSCHARSET latin1
    
  3. Make analogous changes in /etc/profile

3.2 The X Window System

Like the console mode, the X environment also requires some setup. This involves setting up the input mode and the X fonts. Both are being discussed below.

The X fonts.

First of all, you have to obtain the fonts having the Cyrillic glyphs at the appropriate positions.

If you are using the most recent X (or XFree86) distribution, chances are, that you already have such fonts. In the late 1995, the X Window System incorporated a set of Cyrillic fonts, created by Cronyx. Ask your system administrator, or, if you are the one, check your system, namely:

  1. Run 'xlsfonts | grep koi8'. If there are fonts listed, your X server is already aware about the fonts.
  2. Otherwise, run
    find -name crox\*.pcf\*
    
    to find the location of the Cyrillic fonts in the system. You'll have to enable those fonts to the X server, as I explain below.

If you haven't found such fonts installed, you'll have to do it yourself.

There is some ambiguity with the fonts. XFree86 docs claim that the russian fonts collection included in the distribution is developed by Cronyx. Nevertheless, you may find another set of Cronyx Cyrillic fonts on the net (eg. on ftp.kiae.su), known as the xrus package (don't confuse it with the xrus program, which is used to setup a Cyrillic keyboard layout. Hopefully, tha letter one was renamed to xruskb recently). Xrus has fewer fonts than the collection in Xfree86 (38 vs 68), but the latter one didn't go along with my Netscape setup - it gave me some really huge font in the menubar. The xrus package doesn't have this problem.

I would suggest you to download and try both of them. Pick up the one which you'll like more. Also, I'm going to creat RPM packages soon for both collections and download them to ftp.redhat.com.

There are also older stuff, for example the vakufonts package, created by Serge Vakulenko, which was the base for the one in the X distribution. There are also a number of others. The important point is that the fonts' names in the old collection were not strictly conforming to the standard. The latter is fine in general, but sometimes it may cause various weird errors. For example, I had a bad experience with Maple V for Linux, which crashed mysteriously with the vakufonts package, but ran smoothly with the "standard" ones.

So, let's start with the fonts:

  1. Download the appropriate fonts collection. The package for XFree86 may be found at any FTP site, containing the X distribution, for example, directly from the XFree86 FTP site. The xrus package may be found on ftp.kiae.su
  2. Now when you have the fonts, you create some directory for them. It is generally a bad idea to put new fonts to the already existing font directory. So, place them, to, say, /usr/lib/X11/fonts/cyrillic for a system-wide setup, or just create a private directory for personal use.
  3. If the new fonts are in BDF format (*.bdf files), you have to compile them. For each font do:
    bdftopcf -o <font>.pcf <font>.bdf
    
    If your server supports compressed fonts, do it, using the compress program:
    compress *.pcf
    
    Also, if you do want to put the new fonts to an already existing font directory. you have to concatenate the old and the new files named fonts.alias in the case both of them exist.
  4. Each font directory in the X must contain a list of fonts in it. This list is stored in the file fonts.dir. You don't have to create this list manually. Instead, do:
    cd <new font directory>
    mkfontdir .
    
  5. Now you have to make this font directory known to the X server. Here, you have a number of options:
    xset +fp <new font directory>
    xset fp rehash
    
    It is important to note that '+fp' means that the new fonts will be added to the head of the font path list. That is, if an application requests say a fixed font, it'll be given the one with Cyrillic characters, which is definitely what we are trying to achieve. There are problems, though. The fixed font in the cyrillic fonts distribution doesn't have it's bold and italic counterparts. My font of choice is 6x13, so, since it also lacks bold and italic typefaces, I cannot use Emacs/XEmacs faces in their full glory. Hopefully somebody will ultimately create those fonts and the situation will change.
  6. Now restart your X. If you have done everything right, the tests in the beginning of the section will be successful. Also, play with xfontsel(1x) to make sure you are able to select the cyrillic fonts.

In order to make the X clients use the Cyrillic fonts, you have to set up the appropriate X resources. For example, I make the russian font the default one in my ~/.Xdefaults:

*font:         6x13

Since my cyrillic fonts are first in the font path (see output of 'xset q'), the font above is taken from the "cyrillic" directory.

This just a simple case. If you want to set the appropriate part of the X client to a cyrillic font, you have to figure out the name of the resource (eg. using editres(1x)) and to specify it either in the resource database, or in the command line. Here go some examples:

$ xterm -font '-cronyx-*-bold-*-*-*-19-*-*-*-*-*-*-*'

...will run xterm with some ugly font; and

$ xfontsel -xrm '*quitButton.font: -*-times-*-*-*-*-13-*-*-*-*-*-koi8-*'

...will set a Cyrillic Times font for the Quit button in xfontsel.

The input translation

In the newest X releases (X11R61 and higher) there are two "standard" input methods: the original one, working through the xmodmap utility, and the new one called Xkb (X KeyBoard). The very first thing you have to do is to disable the Xkb method! Don't get charmed by it's ability to set up a "russian keyboard". It looks like this method is using the Cyrillic keysyms defined in keysymdef.h. This file defines keysyms for many languages. The only problem is that those definitions have nothing to do with the extended ASCII codeset - the one most programs are only able to operate with! I hardly know any programs being able to grok the keysymdef.h keysyms, different from 8-bit ASCII. However our goal is to get the KOI8-R support to work.

To disable the Xkb support, browse through the Keyboard section of your XF86Config file and comment all lines starting with Xkb (case doesn't matter). Instead, put the following line:

XkbDisable

The xmodmap program.allows customization of codes emitted by various characters and their combinations. It sets the things up based on the file containing the translation table.

In the previous versions of this document I used to describe the xmodmap-based setup in a great detail. This proved to be almost useless. The Xmodmap-based input translation method is well known as being it is non-portable, inflexible, and incomplete. Your configuration may work with one XFree version and fail with a different one. Even worse, sometimes things differ accross different servers in the same distribution.

I strongly suggest you not to play with this xmodmap, at least for now. Apart from headache and disappointment you'll gain nothing. Instead, I recommend installing the xruskb package, which allows you to configure most of the input translation parameters without having to know about xmodmap. Again, the RedHat Linux users are free to download and install an RPM package.

3.3 First steps - Cyrillic in shells

3.4 bash

Three variables should be set on order to make bash understand the 8-bit characters. The best place is ~/.inputrc file. The following should be set:

set meta-flag on
set convert-meta off
set output-meta on

3.5 csh/tcsh

The following should be set in .cshrc:

setenv LC_CTYPE iso_8859_5
stty pass8

If you don't have the POSIX stty (impossible for Linux), then replace the last call to the following:

stty -istrip cs8

3.6 ksh

As for the public domain ksh implementation - pdksh 5.1.3, you can input 8 bit characters only in vi input mode. Use:

set -o vi

3.7 less

So far, less doesn't support the KOI8-R character set, but the following environment variable will do the job:

LESSCHARSET=latin1

3.8 mc (The Midnight Commander)

To display Cyrillic text correctly, select the full 8 bits item in the Options/Display menu.

If your problem is the ugly windows' borders, consult the linux-console section.

As an off-topic, if you want to make mc use color in an Xterm window, set the variable COLORTERM:

COLORTERM= ; export COLORTERM

3.9 rlogin

Make sure that the shell on the destination site is properly set up. Then, if your rlogin doesn't work by default, use 'rlogin -8'.

3.10 zsh

Use the same way as with csh (see section csh). The startup files in this case are .zshrc or /etc/zshrc.


Next Previous Contents