fix localeprefs language display after behaviour changes in the code for native name...
[AROS.git] / workbench / prefs / boingiconbar / prefs.c
blobf233d834ecc8b143838494b5d9fb7951e0c55183
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*********************************************************************************************/
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdlib.h>
15 #include <aros/macros.h>
17 // #define DEBUG 1
18 #include <aros/debug.h>
20 #include <proto/exec.h>
21 #include <proto/iffparse.h>
22 #include <proto/dos.h>
24 #include "prefs.h"
25 #include "misc.h"
27 /*********************************************************************************************/
29 #define PREFS_PATH_ENVARC "ENVARC:Iconbar.prefs"
30 #define PREFS_PATH_ENV "ENV:Iconbar.prefs"
32 /*********************************************************************************************/
34 struct BIBPrefs bibprefs;
36 /*********************************************************************************************/
38 static BOOL Prefs_Load(STRPTR from)
40 BOOL retval = FALSE;
42 BPTR fh = Open(from, MODE_OLDFILE);
43 if (fh)
45 retval = Prefs_ImportFH(fh);
46 Close(fh);
49 return retval;
52 /*********************************************************************************************/
54 BOOL Prefs_ImportFH(BPTR fh)
56 BOOL retval = TRUE;
58 LONG dock = -1;
59 LONG program = 0;
60 LONG line = 0;
61 LONG slen;
62 char buffer[500];
64 while ((FGets(fh, buffer, sizeof(buffer))) != NULL)
66 slen = strlen(buffer);
67 if (buffer[slen - 1] == '\n')
68 buffer[slen - 1] = 0;
70 if (line == 0)
72 if (strncmp(buffer, "BOING_PREFS", 11 ) != 0)
74 D(bug("[IconBarPrefs] %s: is not BOING BAR configuration file!\n"));
75 retval = FALSE;
76 break;
79 else
81 if (buffer[0] == ';' )
83 dock++;
84 strcpy(bibprefs.docks[dock].name, &buffer[1]);
85 program = 0;
86 D(bug("[IconBarPrefs] %s buffer\n", &buffer[1]));
88 else
90 strcpy(bibprefs.docks[dock].programs[program], buffer);
91 D(bug("[IconBarPrefs] data set %d / %d - %s\n", dock, program, bibprefs.docks[dock].programs[program]));
92 program++;
95 line++;
98 #if 0
99 LONG i,j;
100 for (i = 0; (i < BIB_MAX_DOCKS) && (bibprefs.docks[i].name[0] != '\0'); i++)
102 bug("Dock %s\n", bibprefs.docks[i].name);
104 for (j = 0; (j < BIB_MAX_PROGRAMS) && (bibprefs.docks[i].programs[j][0] != 0); j++)
106 bug(" App %s\n", bibprefs.docks[i].programs[j]);
109 #endif
111 return retval;
114 /*********************************************************************************************/
116 BOOL Prefs_ExportFH(BPTR fh)
118 BOOL retval = TRUE;
119 LONG i, j;
121 FPuts(fh, "BOING_PREFS\n");
123 for (i = 0; (i < BIB_MAX_DOCKS) && (bibprefs.docks[i].name[0] != '\0'); i++)
125 FPutC(fh, ';');
126 FPuts(fh, bibprefs.docks[i].name);
127 FPutC(fh, '\n');
129 for (j = 0; (j < BIB_MAX_PROGRAMS) && (bibprefs.docks[i].programs[j][0] != 0); j++)
131 FPuts(fh, bibprefs.docks[i].programs[j]);
132 FPutC(fh, '\n');
136 return retval;
139 /*********************************************************************************************/
141 BOOL Prefs_HandleArgs(STRPTR from, BOOL use, BOOL save)
143 BPTR fh;
145 if (from)
147 if (!Prefs_Load(from))
149 ShowMessage("Can't read from input file");
150 return FALSE;
153 else
155 if (!Prefs_Load(PREFS_PATH_ENV))
157 if (!Prefs_Load(PREFS_PATH_ENVARC))
159 ShowMessage
161 "Can't read from file " PREFS_PATH_ENVARC
162 ".\nUsing default values."
164 Prefs_Default();
169 if (use || save)
171 fh = Open(PREFS_PATH_ENV, MODE_NEWFILE);
172 if (fh)
174 Prefs_ExportFH(fh);
175 Close(fh);
177 else
179 ShowMessage("Cant' open " PREFS_PATH_ENV " for writing.");
182 if (save)
184 fh = Open(PREFS_PATH_ENVARC, MODE_NEWFILE);
185 if (fh)
187 Prefs_ExportFH(fh);
188 Close(fh);
190 else
192 ShowMessage("Cant' open " PREFS_PATH_ENVARC " for writing.");
195 return TRUE;
198 /*********************************************************************************************/
200 BOOL Prefs_Default(VOID)
202 D(bug("[IconBarPrefs] Prefs_Default\n"));
204 memset(&bibprefs, 0, sizeof bibprefs);
206 return TRUE;