sc_init(S) 6 January 1993 sc_init(S) Name sc_init - scancode Application Programming Interface (API) initialization and internal administration functions Syntax cc . . . -lscs #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 scinit takes a file descriptor parameter and initializes the tty soft- ware to accept scancode input. It performs the following steps: 1. Calls scraw(S) to get the current scancode modes and put the tty into raw scancode mode, saving the original modes to be restored later. If KBISSCANCODE is not set, the routine returns failure status. 2. Calls scmapinit(S) to read the keymap table, the mapchan table and the scbitmask 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. scexit restores the terminal mode and tty settings that scinit saves. Do not call scexit if you did not use scinit to initialize scancode mode. scexit performs the following steps: 1. Calls scsetinfo(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). scmapinit 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 scstr2kb(S), and initializes the function key table. scmapinit provides a lower level initialization interface than scinit. If the application itself sets tty modes, it should call scmapinit instead of scinit. 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. scgetkbmap returns a pointer to scbitmap, which contains the make/break state of all the keys on the keyboard. The sckb2mapcode(S) and screceivekb(S) functions maintain this map and they are called by screadkb(S), screadmapcode(S) and screadstr(S). If the ``read'' func- tions have not read all the characters in the input buffer, scbitmap will not accurately reflect the current state of the keyboard. screceivekb 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). screceivekb returns a scancode that is usually the same as its input parameter. The application needs to call screceivekb 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 screadkb(S) or ckb2mapcode(S)) it should not call screceivekb. scgetkeymap returns the current active keymap table in the API. scsetkeymap takes a pointer to a keymap structure as a parameter and sets the current active keymap table in the API. scgetfkeystr 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. scsetfkeystr 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. scgetled gets the current keyboard LED state. scsetled sets the key- board 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 scinit, scexit, scmapinit, and scsetfkeystr return 0 on success or -1 on failure. scgetkbmap returns a NULL pointer if scbitmap has not been initialized. sc_receive_kb returns 0 if its input scancode causes a screen switch. scgetkeymap returns a NULL pointer if the keymap table has not been initialized. scgetfkeystr returns a NULL pointer if the function key table has not been initialized. scsetled 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. scinit(S) and scmapinit(S) affect only one terminal at a time, and the application using the API affects only the terminal specified for scinit(S) or scmapinit(S). scgetkeymap does not return the keymap table stored in the kernel. See also sckb2mapcode(S), scmapinit(S), scraw(S), screadkb(S), screadmapcode(S), screadstr(S), screceivekb(S), scsetinfo(S), scstr2kb(S) Standards conformance scexit, scmapinit, scgetkbmap, screceivekb, scgetkeymap, scsetkeymap, scgetfkeystr, scsetfkeystr, scgetled, and scsetled are extensions of AT&T System V provided by the Santa Cruz Operation.