DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

sc_init(S)


sc_init -- scancode Application Programming Interface (API) initialization and internal administration functions

Syntax

cc . . . -lsc_s

#include  <scancode.h>

int sc_init (filedes) int filedes;

int sc_exit ()

int sc_mapinit (filedes) int filedes;

ulong *sc_getkbmap ()

void sc_receive_kb (scancode) scancode_t scancode;

keymap_t *sc_getkeymap ()

void sc_setkeymap (keymap_ptr) keymap_t *keymap_ptr;

char *sc_getfkeystr (keyno) int keyno;

int sc_setfkeystr (keyno, string) int keyno; char *string;

char sc_getled ()

int sc_setled (value) char value;

Description

sc_init takes a file descriptor parameter and initializes the tty software to accept scancode input. It performs the following steps:

  1. Calls sc_raw(S) to get the current scancode modes and put the tty into raw scancode mode, saving the original modes to be restored later. If KB_ISSCANCODE is not set, the routine returns failure status.

  2. Calls sc_mapinit(S) to read the keymap table, the mapchan table and the sc_bitmask array into local data structures for later use by the mapping functions.

  3. Gets the current tty modes and XON/XOFF characters with an XCGETA ioctl call and saves them to be restored later.

  4. Sets the correct tty modes (raw, echo off) with an XCSETA ioctl call.

  5. Saves the state of the keyboard LEDs (if running on the console) to be restored later.

sc_exit restores the terminal mode and tty settings that sc_init saves. Do not call sc_exit if you did not use sc_init to initialize scancode mode. sc_exit performs the following steps:

  1. Calls sc_setinfo(S) to restore the tty scancode modes.

  2. Restores the tty modes and XON/XOFF characters with an XCSETA ioctl call.

  3. Restores the state of the keyboard LEDs (if running on the console).

sc_mapinit takes a file descriptor as a parameter and initializes the maps used by the input/output mapping functions. It reads the keymap and mapchan tables into local data structures, constructs the mapcode-to-scancode table used by sc_str2kb(S), and initializes the function key table. sc_mapinit provides a lower level initialization interface than sc_init. If the application itself sets tty modes, it should call sc_mapinit instead of sc_init. The application can only use one of these two functions. It does not need to call either function to simply read scancodes or mapcodes or to translate scancodes to mapcodes. However, if the desired end result is ASCII data, or if the application wants the API to do screen switching, the application must call one of these routines.

sc_getkbmap returns a pointer to sc_bitmap, which contains the make/break state of all the keys on the keyboard. The sc_kb2mapcode(S) and sc_receive_kb(S) functions maintain this map and they are called by sc_readkb(S), sc_readmapcode(S) and sc_readstr(S). If the ``read'' functions have not read all the characters in the input buffer, sc_bitmap will not accurately reflect the current state of the keyboard.

sc_receive_kb parses an input scancode to maintain the internal state of the <Shift>, <Ctrl>, <Alt>, and <Lock> keys. It also performs screen switching (on the console only). sc_receive_kb returns a scancode that is usually the same as its input parameter. The application needs to call sc_receive_kb only if it reads scancodes on its own and does not want any other translation performed but does want screen switching to occur. If the application uses any other input or translation routines (such as sc_readkb(S) or sc_kb2mapcode(S)) it should not call sc_receive_kb.

sc_getkeymap returns the current active keymap table in the API. sc_setkeymap takes a pointer to a keymap structure as a parameter and sets the current active keymap table in the API.

sc_getfkeystr returns a pointer to the character string associated with the function key specified by the input parameter. A parameter of 1 returns <F1>, and so on. sc_setfkeystr sets the character string of the function key associated with the input parameter. A parameter of 1 causes <F1> to be set, and so on.

sc_getled gets the current keyboard LED state. sc_setled sets the keyboard LED state. These functions only work if the application is running on the console. The LED state is defined as follows:

   #define LED_CLK 0x01     /* caps lock on */
   #define LED_NLK 0x02     /* num lock on */
   #define LED_SLK 0x04     /* scroll lock on */

Diagnostics

sc_init, sc_exit, sc_mapinit, and sc_setfkeystr return 0 on success or -1 on failure. sc_getkbmap returns a NULL pointer if sc_bitmap has not been initialized. sc_receive_kb returns 0 if its input scancode causes a screen switch. sc_getkeymap returns a NULL pointer if the keymap table has not been initialized. sc_getfkeystr returns a NULL pointer if the function key table has not been initialized. sc_setled returns -1 if it cannot set the keyboard LED state.

If an API function returns failure status, the global variable sc_error might contain a number corresponding to an error condition listed in scancode.h.

Notes

The API does not set the XON/XOFF characters for scancode mode. The application must set these characters.

sc_init(S) and sc_mapinit(S) affect only one terminal at a time, and the application using the API affects only the terminal specified for sc_init(S) or sc_mapinit(S).

sc_getkeymap does not return the keymap table stored in the kernel.

See also

sc_kb2mapcode(S), sc_mapinit(S), sc_raw(S), sc_readkb(S), sc_readmapcode(S), sc_readstr(S), sc_receive_kb(S), sc_setinfo(S), sc_str2kb(S)

Standards conformance

sc_exit, sc_mapinit, sc_getkbmap, sc_receive_kb, sc_getkeymap, sc_setkeymap, sc_getfkeystr, sc_setfkeystr, sc_getled, and sc_setled are extensions of AT&T System V provided by the Santa Cruz Operation.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003