Implemented copying to clipboard
[cake.git] / workbench / c / SetKeyboard.c
blob3c1fa46dc44d73af997f470322712ff04bd98610
1 /*
2 Copyright © 1995-2007, 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
21 Sys:C
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>
64 #include <string.h>
65 #include <stdlib.h>
67 const TEXT version[] = "$VER: SetKeyboard 41.2 (16.1.2000)\n";
69 #define ARG_TEMPLATE "KEYMAP/A"
71 enum
73 ARG_NAME = 0,
74 NOOFARGS
77 struct Library *KeymapBase = NULL;
78 struct KeyMapResource *KeyMapResource;
80 static struct RDArgs *myargs;
81 static struct KeyMapNode *kmn;
82 static BPTR seg;
83 static IPTR args[NOOFARGS];
84 static char s[256];
85 static char *filename, *name;
87 static void Cleanup(char *msg, WORD rc)
89 if (msg)
91 Printf("SetKeyboard: %s\n",msg);
94 if (seg)
96 UnLoadSeg(seg);
99 if (myargs)
101 FreeArgs(myargs);
104 if (KeymapBase)
106 CloseLibrary(KeymapBase);
109 exit(rc);
113 static void OpenLibs(void)
115 if (!(KeymapBase = OpenLibrary("keymap.library", 0)))
117 Cleanup("Can´t open keymap.library!", RETURN_FAIL);
122 static void OpenKeyMapResoure(void)
124 if (!(KeyMapResource = OpenResource("keymap.resource")))
126 Cleanup("Can´t open keymap.resoure!", RETURN_FAIL);
131 static void GetArguments(void)
133 if (!(myargs = ReadArgs(ARG_TEMPLATE, args, 0)))
135 Fault(IoErr(), 0, s, 255);
136 Cleanup(s, RETURN_FAIL);
139 filename = (char *)args[ARG_NAME];
140 name = FilePart(filename);
144 static struct KeyMapNode *KeymapAlreadyOpen(void)
146 struct Node *node;
147 struct KeyMapNode *kmn = NULL;
149 Forbid();
151 ForeachNode(&KeyMapResource->kr_List, node)
153 if (!stricmp(name, node->ln_Name))
155 kmn = (struct KeyMapNode *)node;
156 break;
160 Permit();
162 return kmn;
166 static void Action(void)
168 kmn = KeymapAlreadyOpen();
170 if (!kmn)
172 struct KeyMapNode *kmn_check;
174 if (name == filename)
176 strcpy(s, "DEVS:Keymaps");
177 AddPart(s, name, 255);
179 else
181 strcpy(s, filename);
184 if (!(seg = LoadSeg(s)))
186 Fault(IoErr(), 0, s, 255);
187 Cleanup(s, RETURN_FAIL);
190 kmn = (struct KeyMapNode *) (((UBYTE *)BADDR(seg)) + sizeof(APTR));
192 Forbid();
194 if ((kmn_check = KeymapAlreadyOpen()))
196 kmn = kmn_check;
198 else
200 AddHead(&KeyMapResource->kr_List, &kmn->kn_Node);
201 seg = 0;
204 Permit();
206 } /* if (!kmn) */
208 SetKeyMapDefault(&kmn->kn_KeyMap);
212 int __nocommandline;
214 int main(void)
216 OpenLibs();
217 OpenKeyMapResoure();
218 GetArguments();
220 Action();
221 Cleanup(0, RETURN_OK);
223 return 0;