grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / c / iprefs / serialprefs.c
blob79c79de81d3de73cba66863cbe98213693f51ade
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*********************************************************************************************/
11 #include "global.h"
13 #define DEBUG 0
14 #include <aros/debug.h>
16 #include <prefs/prefhdr.h>
17 #include <prefs/serial.h>
19 static const ULONG buffersizes[] =
21 512,
22 1024,
23 2048,
24 4096,
25 8000,
26 16000,
30 static LONG stopchunks[] =
32 ID_PREF, ID_SERL
35 /*********************************************************************************************/
37 void SerialPrefs_Handler(STRPTR filename)
39 struct IFFHandle *iff;
40 struct SerialPrefs *serialprefs;
42 D(bug("In IPrefs:SerialPrefs_Handler\n"));
43 D(bug("filename=%s\n",filename));
45 iff = CreateIFF(filename, stopchunks, 1);
47 if (iff) {
48 while(ParseIFF(iff, IFFPARSE_SCAN) == 0) {
49 serialprefs = LoadChunk(iff, sizeof(struct SerialPrefs), MEMF_ANY);
50 if (serialprefs) {
51 struct Preferences prefs;
52 ULONG index = 0;
54 GetPrefs(&prefs, sizeof(prefs));
56 while (-1 != buffersizes[index]) {
57 if (buffersizes[index] == serialprefs->sp_InputBuffer)
58 break;
59 index++;
62 if (-1 == buffersizes[index])
63 index = 0;
65 D(bug("Setting new serial prefs.\n"));
66 D(bug("Setting baudrate to %d\n", GET_LONG(serialprefs->sp_BaudRate)));
67 D(bug("Setting receive buffer size to %d\n",buffersizes[index]));
68 D(bug("Setting read bit len to %d\n",8-serialprefs->sp_BitsPerChar));
69 D(bug("Setting write bit len to %d\n",8-serialprefs->sp_BitsPerChar));
70 D(bug("Setting stop bits to %d\n",1+serialprefs->sp_StopBits));
72 prefs.BaudRate = GET_LONG(serialprefs->sp_BaudRate);
73 prefs.SerRWBits = (serialprefs->sp_BitsPerChar << 4) | serialprefs->sp_BitsPerChar;
74 prefs.SerStopBuf = (serialprefs->sp_StopBits << 4) | index;
75 prefs.SerParShk = (serialprefs->sp_Parity << 4) | serialprefs->sp_InputHandshake;
77 SetPrefs(&prefs, sizeof(prefs), TRUE);
78 FreeVec(serialprefs);
81 KillIFF(iff);