Fixed a potential strict aliasing bug.
[AROS.git] / workbench / c / SetKeyboard.c
blob50eedecacc9314891046ac8aacd1123da2699def
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /******************************************************************************
11 NAME
13 SetKeyboard
15 SYNOPSIS
17 KEYMAP/A
19 LOCATION
23 FUNCTION
25 Set the keymap for the current shell.
27 INPUTS
29 KEYMAP -- the keymap to use with the current shell
31 RESULT
33 NOTES
35 To make a certain keymap be the default for all shells, use the
36 preferences input program so specify your default choice.
38 EXAMPLE
40 SetKeyboard s
42 Makes the current shell use the Swedish keymap.
44 BUGS
46 SEE ALSO
48 INTERNALS
50 HISTORY
52 ******************************************************************************/
55 #include <exec/exec.h>
56 #include <dos/dos.h>
57 #include <devices/keymap.h>
58 #include <devices/console.h>
59 #include <devices/keymap.h>
60 #include <proto/exec.h>
61 #include <proto/dos.h>
62 #include <proto/keymap.h>
63 #include <proto/kms.h>
65 #include <string.h>
67 const TEXT version[] = "$VER: SetKeyboard 41.3 (03.03.2011)\n";
69 #define ARG_TEMPLATE "KEYMAP/A"
71 enum
73 ARG_NAME = 0,
74 NOOFARGS
77 AROS_ENTRY(__startup static ULONG, Start,
78 AROS_UFHA(char *, argstr, A0),
79 AROS_UFHA(ULONG, argsize, D0),
80 struct ExecBase *, SysBase)
82 AROS_USERFUNC_INIT
84 struct DosLibrary *DOSBase;
85 struct Library *KeymapBase;
86 struct KMSLibrary *KMSBase;
87 STRPTR err = NULL;
88 ULONG rc = RETURN_FAIL;
90 DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 36);
91 if (!DOSBase)
92 return RETURN_FAIL;
94 KeymapBase = OpenLibrary("keymap.library", 0);
95 if (KeymapBase)
97 KMSBase = (struct KMSLibrary *)OpenLibrary("kms.library", 0);
98 if (KMSBase)
100 IPTR args[NOOFARGS];
101 struct RDArgs *myargs = ReadArgs(ARG_TEMPLATE, args, 0);
103 if (myargs)
105 struct KeyMapNode *kmn = OpenKeymap((STRPTR)args[ARG_NAME]);
107 if (kmn)
109 SetKeyMapDefault(&kmn->kn_KeyMap);
110 rc = RETURN_OK;
114 if (rc != RETURN_OK)
115 PrintFault(IoErr(), "SetKeyboard");
117 if (myargs)
118 FreeArgs(myargs);
120 CloseLibrary(&KMSBase->kms_Lib);
122 else
123 err = "Can't opem kms.library!";
125 CloseLibrary(KeymapBase);
127 else
128 err = "Can't open keymap.library!";
130 if (err)
131 Printf("SetKeyboard: %s\n", err);
133 CloseLibrary(&DOSBase->dl_lib);
135 return rc;
137 AROS_USERFUNC_EXIT