disable float support on m68k to prevent unwanted symbols being used in rom code...
[AROS.git] / workbench / prefs / icontrol / prefs.c
blobf4136c59d7b7e2b1a68a3323f07c9ed3ab7c21d6
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*********************************************************************************************/
11 #include <aros/macros.h>
13 #define DEBUG 0
14 #include <aros/debug.h>
16 #include <proto/exec.h>
17 #include <proto/dos.h>
18 #include <proto/iffparse.h>
20 #include <prefs/prefhdr.h>
21 #include <devices/inputevent.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdlib.h>
27 #include "prefs.h"
28 #include "misc.h"
30 /*********************************************************************************************/
32 #define PREFS_PATH_ENVARC "ENVARC:SYS/icontrol.prefs"
33 #define PREFS_PATH_ENV "ENV:SYS/icontrol.prefs"
35 /*********************************************************************************************/
37 struct FilePrefHeader
39 UBYTE ph_Version;
40 UBYTE ph_Type;
41 UBYTE ph_Flags[4];
44 /*********************************************************************************************/
46 struct IControlPrefs icontrolprefs;
48 /*********************************************************************************************/
50 static BOOL Prefs_Load(STRPTR from)
52 BOOL retval = FALSE;
54 BPTR fh = Open(from, MODE_OLDFILE);
55 if (fh)
57 retval = Prefs_ImportFH(fh);
58 Close(fh);
61 return retval;
64 /*********************************************************************************************/
66 BOOL Prefs_ImportFH(BPTR fh)
68 struct IControlPrefs loadprefs;
69 struct IFFHandle *iff;
70 BOOL retval = FALSE;
72 if ((iff = AllocIFF()))
74 iff->iff_Stream = (IPTR)fh;
76 InitIFFasDOS(iff);
78 if (!OpenIFF(iff, IFFF_READ))
80 D(bug("LoadPrefs: OpenIFF okay.\n"));
82 if (!StopChunk(iff, ID_PREF, ID_ICTL))
84 D(bug("LoadPrefs: StopChunk okay.\n"));
86 if (!ParseIFF(iff, IFFPARSE_SCAN))
88 struct ContextNode *cn;
90 D(bug("LoadPrefs: ParseIFF okay.\n"));
92 cn = CurrentChunk(iff);
94 if (cn->cn_Size == sizeof(struct IControlPrefs))
96 D(bug("LoadPrefs: ID_ICTL chunk size okay.\n"));
98 if (ReadChunkBytes(iff, &loadprefs, sizeof(struct IControlPrefs)) == sizeof(struct IControlPrefs))
100 D(bug("LoadPrefs: Reading chunk successful.\n"));
102 CopyMem(loadprefs.ic_Reserved, icontrolprefs.ic_Reserved, sizeof(icontrolprefs.ic_Reserved));
104 icontrolprefs.ic_TimeOut = AROS_BE2WORD(loadprefs.ic_TimeOut);
105 icontrolprefs.ic_MetaDrag = AROS_BE2WORD(loadprefs.ic_MetaDrag);
106 icontrolprefs.ic_Flags = AROS_BE2LONG(loadprefs.ic_Flags);
107 icontrolprefs.ic_WBtoFront = loadprefs.ic_WBtoFront;
108 icontrolprefs.ic_FrontToBack = loadprefs.ic_FrontToBack;
109 icontrolprefs.ic_ReqTrue = loadprefs.ic_ReqTrue;
110 icontrolprefs.ic_ReqFalse = loadprefs.ic_ReqFalse;
111 icontrolprefs.ic_Reserved2 = AROS_BE2WORD(loadprefs.ic_Reserved2);
112 icontrolprefs.ic_VDragModes[0] = AROS_BE2WORD(loadprefs.ic_VDragModes[0]);
113 icontrolprefs.ic_VDragModes[1] = AROS_BE2WORD(loadprefs.ic_VDragModes[1]);
115 D(bug("LoadPrefs: Everything okay :-)\n"));
117 retval = TRUE;
120 } /* if (!ParseIFF(iff, IFFPARSE_SCAN)) */
121 } /* if (!StopChunk(iff, ID_PREF, ID_ICTL)) */
122 CloseIFF(iff);
123 } /* if (!OpenIFF(iff, IFFF_READ)) */
124 FreeIFF(iff);
125 } /* if ((iff = AllocIFF())) */
126 return retval;
129 /*********************************************************************************************/
131 BOOL Prefs_ExportFH(BPTR fh)
133 struct IControlPrefs saveprefs;
134 struct IFFHandle *iff;
135 BOOL retval = FALSE;
136 #if 0 /* unused */
137 BOOL delete_if_error = FALSE;
138 #endif
140 CopyMem(icontrolprefs.ic_Reserved, saveprefs.ic_Reserved, sizeof(icontrolprefs.ic_Reserved));
142 saveprefs.ic_TimeOut = AROS_WORD2BE(icontrolprefs.ic_TimeOut);
143 saveprefs.ic_MetaDrag = AROS_WORD2BE(icontrolprefs.ic_MetaDrag);
144 saveprefs.ic_Flags = AROS_LONG2BE(icontrolprefs.ic_Flags);
145 saveprefs.ic_WBtoFront = icontrolprefs.ic_WBtoFront;
146 saveprefs.ic_FrontToBack = icontrolprefs.ic_FrontToBack;
147 saveprefs.ic_ReqTrue = icontrolprefs.ic_ReqTrue;
148 saveprefs.ic_ReqFalse = icontrolprefs.ic_ReqFalse;
149 saveprefs.ic_Reserved2 = AROS_WORD2BE(icontrolprefs.ic_Reserved2);
150 saveprefs.ic_VDragModes[0] = AROS_WORD2BE(icontrolprefs.ic_VDragModes[0]);
151 saveprefs.ic_VDragModes[1] = AROS_WORD2BE(icontrolprefs.ic_VDragModes[1]);
153 D(bug("SavePrefsFH: fh: %lx\n", fh));
155 if ((iff = AllocIFF()))
157 iff->iff_Stream = (IPTR) fh;
158 D(bug("SavePrefsFH: stream opened.\n"));
160 #if 0 /* unused */
161 delete_if_error = TRUE;
162 #endif
164 InitIFFasDOS(iff);
166 if (!OpenIFF(iff, IFFF_WRITE))
168 D(bug("SavePrefsFH: OpenIFF okay.\n"));
170 if (!PushChunk(iff, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN))
172 D(bug("SavePrefsFH: PushChunk(FORM) okay.\n"));
174 if (!PushChunk(iff, ID_PREF, ID_PRHD, sizeof(struct FilePrefHeader)))
176 struct FilePrefHeader head;
178 D(bug("SavePrefsFH: PushChunk(PRHD) okay.\n"));
180 head.ph_Version = PHV_CURRENT;
181 head.ph_Type = 0;
182 head.ph_Flags[0] =
183 head.ph_Flags[1] =
184 head.ph_Flags[2] =
185 head.ph_Flags[3] = 0;
187 if (WriteChunkBytes(iff, &head, sizeof(head)) == sizeof(head))
189 D(bug("SavePrefsFH: WriteChunkBytes(PRHD) okay.\n"));
191 PopChunk(iff);
193 if (!PushChunk(iff, ID_PREF, ID_ICTL, sizeof(struct IControlPrefs)))
195 D(bug("SavePrefsFH: PushChunk(LCLE) okay.\n"));
197 if (WriteChunkBytes(iff, &saveprefs, sizeof(saveprefs)) == sizeof(saveprefs))
199 D(bug("SavePrefsFH: WriteChunkBytes(ICTL) okay.\n"));
200 D(bug("SavePrefsFH: Everything okay :-)\n"));
202 retval = TRUE;
204 PopChunk(iff);
205 } /* if (!PushChunk(iff, ID_PREF, ID_ICTL, sizeof(struct IControlPrefs))) */
206 } /* if (WriteChunkBytes(iff, &head, sizeof(head)) == sizeof(head)) */
207 else
209 PopChunk(iff);
211 } /* if (!PushChunk(iff, ID_PREF, ID_PRHD, sizeof(struct PrefHeader))) */
212 PopChunk(iff);
213 } /* if (!PushChunk(iff, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN)) */
214 CloseIFF(iff);
215 } /* if (!OpenIFF(iff, IFFFWRITE)) */
216 FreeIFF(iff);
218 } /* if ((iff = AllocIFF())) */
220 #if 0 /* unused */
221 if (!retval && delete_if_error)
223 DeleteFile(filename);
225 #endif
227 return retval;
230 /*********************************************************************************************/
232 BOOL Prefs_HandleArgs(STRPTR from, BOOL use, BOOL save)
234 BPTR fh;
236 if (from)
238 if (!Prefs_Load(from))
240 ShowMessage("Can't read from input file");
241 return FALSE;
244 else
246 if (!Prefs_Load(PREFS_PATH_ENV))
248 if (!Prefs_Load(PREFS_PATH_ENVARC))
250 ShowMessage
252 "Can't read from file " PREFS_PATH_ENVARC
253 ".\nUsing default values."
255 Prefs_Default();
260 if (use || save)
262 fh = Open(PREFS_PATH_ENV, MODE_NEWFILE);
263 if (fh)
265 Prefs_ExportFH(fh);
266 Close(fh);
268 else
270 ShowMessage("Cant' open " PREFS_PATH_ENV " for writing.");
273 if (save)
275 fh = Open(PREFS_PATH_ENVARC, MODE_NEWFILE);
276 if (fh)
278 Prefs_ExportFH(fh);
279 Close(fh);
281 else
283 ShowMessage("Cant' open " PREFS_PATH_ENVARC " for writing.");
286 return TRUE;
289 /*********************************************************************************************/
291 BOOL Prefs_Default(VOID)
293 icontrolprefs.ic_Reserved[0] = 0;
294 icontrolprefs.ic_Reserved[1] = 0;
295 icontrolprefs.ic_Reserved[2] = 0;
296 icontrolprefs.ic_Reserved[3] = 0;
297 icontrolprefs.ic_TimeOut = 50;
298 icontrolprefs.ic_MetaDrag = IEQUALIFIER_LCOMMAND;
299 icontrolprefs.ic_Flags = ICF_3DMENUS |
300 ICF_MODEPROMOTE |
301 ICF_MENUSNAP |
302 ICF_STRGAD_FILTER |
303 ICF_COERCE_LACE |
304 ICF_OFFSCREENLAYERS;
305 /* FIXME: check whether ICF_DEFPUBSCREEN is set as default */
306 icontrolprefs.ic_WBtoFront = 'N';
307 icontrolprefs.ic_FrontToBack = 'M';
308 icontrolprefs.ic_ReqTrue = 'V';
309 icontrolprefs.ic_ReqFalse = 'B';
310 icontrolprefs.ic_VDragModes[0] = 0;
311 icontrolprefs.ic_VDragModes[1] = 0;
313 return TRUE;