added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / c / iprefs / inputprefs.c
blob0c89eabd28ceede809cf62803fe53b9ea956f368
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*********************************************************************************************/
11 #include "global.h"
13 #include <prefs/prefhdr.h>
14 #include <prefs/input.h>
15 #include <devices/input.h>
16 #include <devices/keymap.h>
18 #include <string.h>
20 #define DEBUG 0
21 #include <aros/debug.h>
23 /*********************************************************************************************/
25 struct FileInputPrefs
27 char ip_Keymap[16];
28 UBYTE ip_PointerTicks[2];
29 UBYTE ip_DoubleClick_secs[4];
30 UBYTE ip_DoubleClick_micro[4];
31 UBYTE ip_KeyRptDelay_secs[4];
32 UBYTE ip_KeyRptDelay_micro[4];
33 UBYTE ip_KeyRptSpeed_secs[4];
34 UBYTE ip_KeyRptSpeed_micro[4];
35 UBYTE ip_MouseAccel[2];
38 /*********************************************************************************************/
40 static LONG stopchunks[] =
42 ID_PREF, ID_INPT
45 /*********************************************************************************************/
47 static struct KeyMapNode *KeymapAlreadyOpen(struct KeyMapResource *KeyMapResource, STRPTR name)
49 struct KeyMapNode *kmn = NULL;
50 struct Node *node;
52 Forbid();
54 ForeachNode(&KeyMapResource->kr_List, node)
56 if (!stricmp(name, node->ln_Name))
58 kmn = (struct KeyMapNode *)node;
59 break;
63 Permit();
65 return kmn;
68 /*********************************************************************************************/
70 static void SetInputPrefs(struct FileInputPrefs *prefs)
72 struct KeyMapResource *KeyMapResource;
73 struct KeyMapNode *kmn;
74 struct Preferences p;
76 if ((KeyMapResource = OpenResource("keymap.resource")))
78 kmn = KeymapAlreadyOpen(KeyMapResource, prefs->ip_Keymap);
80 if (!kmn)
82 struct KeyMapNode *kmn_check;
83 BPTR lock, olddir, seg;
85 lock = Lock("DEVS:Keymaps", SHARED_LOCK);
86 if (lock)
88 olddir = CurrentDir(lock);
90 if ((seg = LoadSeg(prefs->ip_Keymap)))
92 kmn = (struct KeyMapNode *) (((UBYTE *)BADDR(seg)) + sizeof(APTR));
94 Forbid();
95 if ((kmn_check = KeymapAlreadyOpen(KeyMapResource, prefs->ip_Keymap)))
97 kmn = kmn_check;
99 else
101 AddHead(&KeyMapResource->kr_List, &kmn->kn_Node);
102 seg = 0;
104 Permit();
106 if (seg) UnLoadSeg(seg);
109 CurrentDir(olddir);
111 UnLock(lock);
113 } /* if (lock) */
115 } /* if (!kmn) */
117 if (kmn) SetKeyMapDefault(&kmn->kn_KeyMap);
119 } /* if ((KeyMapResource = OpenResource("keymap.resource"))) */
121 GetPrefs(&p, sizeof(p));
123 #define GETLONG(x) ((x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3])
124 #define GETWORD(x) ((x[0] << 8) | x[1])
126 p.PointerTicks = GETWORD(prefs->ip_PointerTicks);
127 p.DoubleClick.tv_secs = GETLONG(prefs->ip_DoubleClick_secs);
128 p.DoubleClick.tv_micro = GETLONG(prefs->ip_DoubleClick_micro);
129 p.KeyRptDelay.tv_secs = GETLONG(prefs->ip_KeyRptDelay_secs);
130 p.KeyRptDelay.tv_micro = GETLONG(prefs->ip_KeyRptDelay_micro);
131 p.KeyRptSpeed.tv_secs = GETLONG(prefs->ip_KeyRptSpeed_secs);
132 p.KeyRptSpeed.tv_micro = GETLONG(prefs->ip_KeyRptSpeed_micro);
133 if (GETWORD(prefs->ip_MouseAccel))
135 p.EnableCLI |= MOUSE_ACCEL;
137 else
139 p.EnableCLI &= ~MOUSE_ACCEL;
142 SetPrefs(&p, sizeof(p), FALSE);
146 /*********************************************************************************************/
148 void InputPrefs_Handler(STRPTR filename)
150 struct IFFHandle *iff;
152 D(bug("In IPrefs:InputPrefs_Handler\n"));
154 if ((iff = CreateIFF(filename, stopchunks, 1)))
156 while(ParseIFF(iff, IFFPARSE_SCAN) == 0)
158 struct ContextNode *cn;
159 struct FileInputPrefs inputprefs;
161 cn = CurrentChunk(iff);
163 D(bug("InputPrefs_Handler: ParseIFF okay. Chunk Type = %c%c%c%c ChunkID = %c%c%c%c\n",
164 cn->cn_Type >> 24,
165 cn->cn_Type >> 16,
166 cn->cn_Type >> 8,
167 cn->cn_Type,
168 cn->cn_ID >> 24,
169 cn->cn_ID >> 16,
170 cn->cn_ID >> 8,
171 cn->cn_ID));
173 if ((cn->cn_ID == ID_INPT) && (cn->cn_Size == sizeof(inputprefs)))
175 D(bug("InputPrefs_Handler: ID_INPT chunk with correct size found.\n"));
177 if (ReadChunkBytes(iff, &inputprefs, sizeof(inputprefs)) == sizeof(inputprefs))
179 SetInputPrefs(&inputprefs);
181 } /* if (ReadChunkBytes(iff, &inputprefs, sizeof(inputprefs)) == sizeof(inputprefs)) */
183 } /* if ((cn->cn_ID == ID_INPT) && (cn->cn_Size == sizeof(inputprefs))) */
185 } /* while(ParseIFF(iff, IFFPARSE_SCAN) == 0) */
187 KillIFF(iff);
189 } /* if ((iff = CreateIFF(filename))) */
192 D(bug("In IPrefs:InputPrefs_Handler. Done.\n", filename));
195 /*********************************************************************************************/