added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / c / iprefs / serialprefs.c
blob50a5618a1e2d744ecaa6d8d656dae15f50ed85fb
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 #define DEBUG 1
14 #include <aros/debug.h>
16 #include <prefs/prefhdr.h>
17 #include <prefs/serial.h>
19 static BOOL LoadSerialPrefs(STRPTR filename, struct SerialPrefs * serialprefs);
21 static const ULONG buffersizes[] =
23 512,
24 1024,
25 2048,
26 4096,
27 8000,
28 16000,
32 /*********************************************************************************************/
34 void SerialPrefs_Handler(STRPTR filename)
36 static struct SerialPrefs serialprefs;
37 D(bug("In IPrefs:SerialPrefs_Handler\n"));
38 D(bug("filename=%s\n",filename));
39 if (TRUE == LoadSerialPrefs(filename, &serialprefs)) {
40 struct Preferences prefs;
41 ULONG index = 0;
42 GetPrefs(&prefs, sizeof(prefs));
44 while (-1 != buffersizes[index]) {
45 if (buffersizes[index] == serialprefs.sp_InputBuffer)
46 break;
47 index++;
50 if (-1 == buffersizes[index])
51 index = 0;
53 D(bug("Setting new serial prefs.\n"));
54 D(bug("Setting baudrate to %d\n",serialprefs.sp_BaudRate));
55 D(bug("Setting receive buffer size to %d\n",buffersizes[index]));
56 D(bug("Setting read bit len to %d\n",8-serialprefs.sp_BitsPerChar));
57 D(bug("Setting write bit len to %d\n",8-serialprefs.sp_BitsPerChar));
58 D(bug("Setting stop bits to %d\n",1+serialprefs.sp_StopBits));
60 prefs.BaudRate = serialprefs.sp_BaudRate;
61 prefs.SerRWBits = (serialprefs.sp_BitsPerChar << 4) | serialprefs.sp_BitsPerChar;
62 prefs.SerStopBuf = (serialprefs.sp_StopBits << 4) | index;
63 prefs.SerParShk = (serialprefs.sp_Parity << 4) | serialprefs.sp_InputHandshake;
65 SetPrefs(&prefs, sizeof(prefs), TRUE);
68 /*********************************************************************************************/
70 static BOOL LoadSerialPrefs(STRPTR filename, struct SerialPrefs * serialprefs)
72 struct IFFHandle *iff;
73 BOOL retval = FALSE;
75 D(bug("LoadPrefs: Trying to open \"%s\"\n", filename));
77 if ((iff = AllocIFF()))
79 if ((iff->iff_Stream = (IPTR)Open(filename, MODE_OLDFILE)))
81 D(bug("LoadPrefs: stream opened.\n"));
83 InitIFFasDOS(iff);
85 if (!OpenIFF(iff, IFFF_READ))
87 D(bug("LoadPrefs: OpenIFF okay.\n"));
89 if (!StopChunk(iff, ID_PREF, ID_SERL))
91 D(bug("LoadPrefs: StopChunk okay.\n"));
93 if (!ParseIFF(iff, IFFPARSE_SCAN))
95 struct ContextNode *cn;
97 D(bug("LoadPrefs: ParseIFF okay.\n"));
99 cn = CurrentChunk(iff);
101 if (cn->cn_Size == sizeof(struct SerialPrefs))
103 D(bug("LoadPrefs: ID_SERL chunk size okay.\n"));
105 if (ReadChunkBytes(iff, serialprefs, sizeof(struct SerialPrefs)) == sizeof(struct SerialPrefs))
107 D(bug("LoadSerialPrefs: Reading chunk successful.\n"));
109 D(bug("LoadSerialPrefs: Everything okay :-)\n"));
111 retval = TRUE;
115 } /* if (!ParseIFF(iff, IFFPARSE_SCAN)) */
117 } /* if (!StopChunk(iff, ID_PREF, ID_SERL)) */
119 CloseIFF(iff);
121 } /* if (!OpenIFF(iff, IFFF_READ)) */
123 Close((BPTR)iff->iff_Stream);
125 } /* if ((iff->iff_Stream = (IPTR)Open(filename, MODE_OLDFILE))) */
127 FreeIFF(iff);
129 } /* if ((iff = AllocIFF())) */
131 return retval;