revert between 56095 -> 55830 in arch
[AROS.git] / workbench / system / Snoopy / setup.c
blob131832f3c4471f492d46b0d68f045e62ceed5475
1 /*
2 Copyright © 2006-2008, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 //#define DEBUG 1
7 #include <aros/debug.h>
9 #include "setup.h"
11 #include <proto/dos.h>
12 #include <stdio.h>
13 #include <string.h>
15 struct Setup setup;
16 struct Setup oldsetup;
18 enum
20 onlyShowFailsOpt,
21 useDevNamesOpt,
22 showPathsOpt,
23 showCliNrOpt,
24 ignoreWBOpt,
25 breakPointOpt,
27 ChangeDirOpt,
28 DeleteOpt,
29 ExecuteOpt,
30 GetVarOpt,
31 LoadSegOpt,
32 LockOpt,
33 MakeDirOpt,
34 MakeLinkOpt,
35 OpenOpt,
36 RenameOpt,
37 RunCommandOpt,
38 SetVarOpt,
39 SystemOpt,
41 FindPortOpt,
42 FindResidentOpt,
43 FindSemaphoreOpt,
44 FindTaskOpt,
45 LockScreenOpt,
46 OpenDeviceOpt,
47 OpenFontOpt,
48 OpenLibraryOpt,
49 OpenResourceOpt,
50 ReadToolTypesOpt,
52 nameLenOpt,
53 actionLenOpt,
54 targetLenOpt,
55 optionLenOpt
58 // must be same order than previous enum
59 static CONST_STRPTR opts[] =
61 "ShowFails",
62 "DeviceNames",
63 "Paths",
64 "CliNr",
65 "IgnoreWB",
66 "BreakPoint",
68 "ChangeDir",
69 "Delete",
70 "Execute",
71 "GetVar",
72 "LoadSeg",
73 "LockOpt",
74 "MakeDir",
75 "MakeLink",
76 "OpenOpt",
77 "RenameOpt",
78 "RunCommandOpt",
79 "SetVarOpt",
80 "SystemOpt",
82 "FindPort",
83 "FindResident",
84 "FindSemaphore",
85 "FindTask",
86 "LockScreen",
87 "OpenDevice",
88 "OpenFont",
89 "OpenLibrary",
90 "OpenResource",
91 "ReadToolTypes",
93 "NameLen",
94 "ActionLen",
95 "TargetLen",
96 "OptionLen"
99 static void setup_write_parameter(BPTR fh, int argindex, int value)
101 static char buffer[50];
102 sprintf(buffer, "%s %d\n", opts[argindex], value);
103 FPuts(fh, (STRPTR)buffer);
106 void setup_init(void)
108 setup_reset();
109 setup_open();
112 void setup_reset(void)
114 setup.onlyShowFails = FALSE;
115 setup.useDevNames = FALSE;
116 setup.showPaths = FALSE;
117 setup.showCliNr = FALSE;
118 setup.ignoreWB = FALSE;
119 setup.breakPoint = FALSE;
121 setup.match = FALSE;
122 setup.pattern = NULL;
123 setup.parsedpattern[0] = '\0';
125 setup.enableChangeDir = FALSE;
126 setup.enableDelete = FALSE;
127 setup.enableExecute = FALSE;
128 setup.enableGetVar = FALSE;
129 setup.enableLoadSeg = FALSE;
130 setup.enableLock = FALSE;
131 setup.enableMakeDir = FALSE;
132 setup.enableMakeLink = FALSE;
133 setup.enableOpen = TRUE;
134 setup.enableRename = FALSE;
135 setup.enableRunCommand = FALSE;
136 setup.enableSetVar = FALSE;
137 setup.enableSystem = FALSE;
139 setup.enableFindPort = FALSE;
140 setup.enableFindResident = FALSE;
141 setup.enableFindSemaphore = FALSE;
142 setup.enableFindTask = FALSE;
143 setup.enableLockScreen = FALSE;
144 setup.enableOpenDevice = FALSE;
145 setup.enableOpenFont = FALSE;
146 setup.enableOpenLibrary = TRUE;
147 setup.enableOpenResource = FALSE;
148 setup.enableReadToolTypes = FALSE;
150 setup.nameLen = 15;
151 setup.actionLen = 15;
152 setup.targetLen = 40;
153 setup.optionLen = 15;
155 oldsetup = setup;
158 BOOL setup_save(void)
160 // temporary disable breakpoint option to ensure that
161 // a) Open() and other functions aren't interrupted while saving the prefs file
162 // b) the breakpoint option is always saved as "FALSE" to the prefs file
163 BOOL breakPoint = setup.breakPoint;
164 setup.breakPoint = FALSE;
166 BOOL retvalue = FALSE;
168 BPTR fh = Open(PREFFILE, MODE_NEWFILE);
169 if (fh)
171 setup_write_parameter(fh, onlyShowFailsOpt, setup.onlyShowFails);
172 setup_write_parameter(fh, useDevNamesOpt, setup.useDevNames);
173 setup_write_parameter(fh, showPathsOpt, setup.showPaths);
174 setup_write_parameter(fh, showCliNrOpt, setup.showCliNr);
175 setup_write_parameter(fh, ignoreWBOpt, setup.ignoreWB);
176 setup_write_parameter(fh, breakPointOpt, setup.breakPoint);
178 // TODO: write pattern
180 setup_write_parameter(fh, ChangeDirOpt, setup.enableChangeDir);
181 setup_write_parameter(fh, DeleteOpt, setup.enableDelete);
182 setup_write_parameter(fh, ExecuteOpt, setup.enableExecute);
183 setup_write_parameter(fh, GetVarOpt, setup.enableGetVar);
184 setup_write_parameter(fh, LoadSegOpt, setup.enableLoadSeg);
185 setup_write_parameter(fh, LockOpt, setup.enableLock);
186 setup_write_parameter(fh, MakeDirOpt, setup.enableMakeDir);
187 setup_write_parameter(fh, MakeLinkOpt, setup.enableMakeLink);
188 setup_write_parameter(fh, OpenOpt, setup.enableOpen);
189 setup_write_parameter(fh, RenameOpt, setup.enableRename);
190 setup_write_parameter(fh, RunCommandOpt, setup.enableRunCommand);
191 setup_write_parameter(fh, SetVarOpt, setup.enableSetVar);
192 setup_write_parameter(fh, SystemOpt, setup.enableSystem);
194 setup_write_parameter(fh, FindPortOpt, setup.enableFindPort);
195 setup_write_parameter(fh, FindResidentOpt, setup.enableFindResident);
196 setup_write_parameter(fh, FindSemaphoreOpt, setup.enableFindSemaphore);
197 setup_write_parameter(fh, FindTaskOpt, setup.enableFindTask);
198 setup_write_parameter(fh, LockScreenOpt, setup.enableLockScreen);
199 setup_write_parameter(fh, OpenDeviceOpt, setup.enableOpenDevice);
200 setup_write_parameter(fh, OpenFontOpt, setup.enableOpenFont);
201 setup_write_parameter(fh, OpenLibraryOpt, setup.enableOpenLibrary);
202 setup_write_parameter(fh, OpenResourceOpt, setup.enableOpenResource);
203 setup_write_parameter(fh, ReadToolTypesOpt, setup.enableReadToolTypes);
205 setup_write_parameter(fh, nameLenOpt, setup.nameLen);
206 setup_write_parameter(fh, actionLenOpt, setup.actionLen);
207 setup_write_parameter(fh, targetLenOpt, setup.targetLen);
208 setup_write_parameter(fh, optionLenOpt, setup.optionLen);
210 Close(fh);
211 retvalue = TRUE;
214 // restore breakpoint option
215 setup.breakPoint = breakPoint;
217 return retvalue;
220 BOOL setup_open(void)
222 // temporary disable breakpoint option
223 BOOL breakPoint = setup.breakPoint;
224 setup.breakPoint = FALSE;
226 BOOL retval = TRUE;
227 char buffer[60];
228 char option[60];
229 int value;
231 BPTR fh = Open(PREFFILE, MODE_OLDFILE);
232 if (fh)
234 D(bug("Snoopy: File open\n"));
235 while (FGets(fh, buffer, sizeof(buffer)))
237 // TODO: read pattern
238 D(bug("Snoopy: %s read\n", buffer));
239 if (sscanf(buffer,"%59s %d", option, &value) == 2)
241 D(bug("Snoopy: %s | %d\n", option, value));
242 if ( ! stricmp(option, opts[onlyShowFailsOpt]))
243 setup.onlyShowFails = value;
244 else if ( ! stricmp(option, opts[useDevNamesOpt]))
245 setup.useDevNames = value;
246 else if ( ! stricmp(option, opts[showPathsOpt]))
247 setup.showPaths = value;
248 else if ( ! stricmp(option, opts[showCliNrOpt]))
249 setup.showCliNr = value;
250 else if ( ! stricmp(option, opts[ignoreWBOpt]))
251 setup.ignoreWB = value;
252 else if ( ! stricmp(option, opts[breakPointOpt]))
253 breakPoint = value; // use temp variable
254 else if ( ! stricmp(option, opts[ChangeDirOpt]))
255 setup.enableChangeDir = value;
256 else if ( ! stricmp(option, opts[DeleteOpt]))
257 setup.enableDelete = value;
258 else if ( ! stricmp(option, opts[ExecuteOpt]))
259 setup.enableExecute = value;
260 else if ( ! stricmp(option, opts[GetVarOpt]))
261 setup.enableGetVar = value;
262 else if ( ! stricmp(option, opts[LoadSegOpt]))
263 setup.enableLoadSeg = value;
264 else if ( ! stricmp(option, opts[LockOpt]))
265 setup.enableLock = value;
266 else if ( ! stricmp(option, opts[MakeDirOpt]))
267 setup.enableMakeDir = value;
268 else if ( ! stricmp(option, opts[MakeLinkOpt]))
269 setup.enableMakeLink = value;
270 else if ( ! stricmp(option, opts[OpenOpt]))
271 setup.enableOpen = value;
272 else if ( ! stricmp(option, opts[RenameOpt]))
273 setup.enableRename = value;
274 else if ( ! stricmp(option, opts[RunCommandOpt]))
275 setup.enableRunCommand = value;
276 else if ( ! stricmp(option, opts[SetVarOpt]))
277 setup.enableSetVar = value;
278 else if ( ! stricmp(option, opts[SystemOpt]))
279 setup.enableSystem = value;
280 else if ( ! stricmp(option, opts[FindPortOpt]))
281 setup.enableFindPort = value;
282 else if ( ! stricmp(option, opts[FindResidentOpt]))
283 setup.enableFindResident = value;
284 else if ( ! stricmp(option, opts[FindSemaphoreOpt]))
285 setup.enableFindSemaphore = value;
286 else if ( ! stricmp(option, opts[FindTaskOpt]))
287 setup.enableFindTask = value;
288 else if ( ! stricmp(option, opts[LockScreenOpt]))
289 setup.enableLockScreen = value;
290 else if ( ! stricmp(option, opts[OpenDeviceOpt]))
291 setup.enableOpenDevice = value;
292 else if ( ! stricmp(option, opts[OpenFontOpt]))
293 setup.enableOpenFont = value;
294 else if ( ! stricmp(option, opts[OpenLibraryOpt]))
295 setup.enableOpenLibrary = value;
296 else if ( ! stricmp(option, opts[OpenResourceOpt]))
297 setup.enableOpenResource = value;
298 else if ( ! stricmp(option, opts[ReadToolTypesOpt]))
299 setup.enableReadToolTypes = value;
300 else if ( ! stricmp(option, opts[nameLenOpt]))
301 setup.nameLen = value;
302 else if ( ! stricmp(option, opts[actionLenOpt]))
303 setup.actionLen = value;
304 else if ( ! stricmp(option, opts[targetLenOpt]))
305 setup.targetLen = value;
306 else if ( ! stricmp(option, opts[optionLenOpt]))
307 setup.optionLen = value;
308 } // if
309 else if ((buffer[0] != '\0') && (buffer[0] != '\n'))
311 retval = FALSE;
313 } // while
314 Close(fh);
316 else
318 retval = FALSE;
321 // restore breakpoint option
322 setup.breakPoint = breakPoint;
324 return retval;