added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / utilities / Snoopy / setup.c
blob5d7e009c910cf3b80312423ba42878edc17b1af1
1 /*
2 Copyright © 2006, 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,
26 ChangeDirOpt,
27 DeleteOpt,
28 ExecuteOpt,
29 GetVarOpt,
30 LoadSegOpt,
31 LockOpt,
32 MakeDirOpt,
33 MakeLinkOpt,
34 OpenOpt,
35 RenameOpt,
36 RunCommandOpt,
37 SetVarOpt,
38 SystemOpt,
40 FindPortOpt,
41 FindResidentOpt,
42 FindSemaphoreOpt,
43 FindTaskOpt,
44 LockScreenOpt,
45 OpenDeviceOpt,
46 OpenFontOpt,
47 OpenLibraryOpt,
48 OpenResourceOpt,
49 ReadToolTypesOpt,
51 nameLenOpt,
52 actionLenOpt,
53 targetLenOpt,
54 optionLenOpt
57 // must be same order than previous enum
58 static CONST_STRPTR opts[] =
60 "ShowFails",
61 "DeviceNames",
62 "Paths",
63 "CliNr",
64 "IgnoreWB",
66 "ChangeDir",
67 "Delete",
68 "Execute",
69 "GetVar",
70 "LoadSeg",
71 "LockOpt",
72 "MakeDir",
73 "MakeLink",
74 "OpenOpt",
75 "RenameOpt",
76 "RunCommandOpt",
77 "SetVarOpt",
78 "SystemOpt",
80 "FindPort",
81 "FindResident",
82 "FindSemaphore",
83 "FindTask",
84 "LockScreen",
85 "OpenDevice",
86 "OpenFont",
87 "OpenLibrary",
88 "OpenResource",
89 "ReadToolTypes",
91 "NameLen",
92 "ActionLen",
93 "TargetLen",
94 "OptionLen"
97 static void setup_write_parameter(BPTR fh, int argindex, int value)
99 static char buffer[50];
100 sprintf(buffer, "%s %d\n", opts[argindex], value);
101 FPuts(fh, (STRPTR)buffer);
104 void setup_init(void)
106 setup_reset();
107 setup_open();
110 void setup_reset(void)
112 setup.onlyShowFails = FALSE;
113 setup.useDevNames = FALSE;
114 setup.showPaths = FALSE;
115 setup.showCliNr = FALSE;
116 setup.ignoreWB = FALSE;
118 setup.enableChangeDir = FALSE;
119 setup.enableDelete = FALSE;
120 setup.enableExecute = FALSE;
121 setup.enableGetVar = FALSE;
122 setup.enableLoadSeg = FALSE;
123 setup.enableLock = FALSE;
124 setup.enableMakeDir = FALSE;
125 setup.enableMakeLink = FALSE;
126 setup.enableOpen = TRUE;
127 setup.enableRename = FALSE;
128 setup.enableRunCommand = FALSE;
129 setup.enableSetVar = FALSE;
130 setup.enableSystem = FALSE;
132 setup.enableFindPort = FALSE;
133 setup.enableFindResident = FALSE;
134 setup.enableFindSemaphore = FALSE;
135 setup.enableFindTask = FALSE;
136 setup.enableLockScreen = FALSE;
137 setup.enableOpenDevice = FALSE;
138 setup.enableOpenFont = FALSE;
139 setup.enableOpenLibrary = TRUE;
140 setup.enableOpenResource = FALSE;
141 setup.enableReadToolTypes = FALSE;
143 setup.nameLen = 15;
144 setup.actionLen = 15;
145 setup.targetLen = 40;
146 setup.optionLen = 15;
148 oldsetup = setup;
151 BOOL setup_save(void)
153 BPTR fh = Open(PREFFILE, MODE_NEWFILE);
154 if (!fh) return FALSE;
156 setup_write_parameter(fh, onlyShowFailsOpt, setup.onlyShowFails);
157 setup_write_parameter(fh, useDevNamesOpt, setup.useDevNames);
158 setup_write_parameter(fh, showPathsOpt, setup.showPaths);
159 setup_write_parameter(fh, showCliNrOpt, setup.showCliNr);
160 setup_write_parameter(fh, ignoreWBOpt, setup.ignoreWB);
162 setup_write_parameter(fh, ChangeDirOpt, setup.enableChangeDir);
163 setup_write_parameter(fh, DeleteOpt, setup.enableDelete);
164 setup_write_parameter(fh, ExecuteOpt, setup.enableExecute);
165 setup_write_parameter(fh, GetVarOpt, setup.enableGetVar);
166 setup_write_parameter(fh, LoadSegOpt, setup.enableLoadSeg);
167 setup_write_parameter(fh, LockOpt, setup.enableLock);
168 setup_write_parameter(fh, MakeDirOpt, setup.enableMakeDir);
169 setup_write_parameter(fh, MakeLinkOpt, setup.enableMakeLink);
170 setup_write_parameter(fh, OpenOpt, setup.enableOpen);
171 setup_write_parameter(fh, RenameOpt, setup.enableRename);
172 setup_write_parameter(fh, RunCommandOpt, setup.enableRunCommand);
173 setup_write_parameter(fh, SetVarOpt, setup.enableSetVar);
174 setup_write_parameter(fh, SystemOpt, setup.enableSystem);
176 setup_write_parameter(fh, FindPortOpt, setup.enableFindPort);
177 setup_write_parameter(fh, FindResidentOpt, setup.enableFindResident);
178 setup_write_parameter(fh, FindSemaphoreOpt, setup.enableFindSemaphore);
179 setup_write_parameter(fh, FindTaskOpt, setup.enableFindTask);
180 setup_write_parameter(fh, LockScreenOpt, setup.enableLockScreen);
181 setup_write_parameter(fh, OpenDeviceOpt, setup.enableOpenDevice);
182 setup_write_parameter(fh, OpenFontOpt, setup.enableOpenFont);
183 setup_write_parameter(fh, OpenLibraryOpt, setup.enableOpenLibrary);
184 setup_write_parameter(fh, OpenResourceOpt, setup.enableOpenResource);
185 setup_write_parameter(fh, ReadToolTypesOpt, setup.enableReadToolTypes);
187 setup_write_parameter(fh, nameLenOpt, setup.nameLen);
188 setup_write_parameter(fh, actionLenOpt, setup.actionLen);
189 setup_write_parameter(fh, targetLenOpt, setup.targetLen);
190 setup_write_parameter(fh, optionLenOpt, setup.optionLen);
192 Close(fh);
193 return TRUE;
196 BOOL setup_open(void)
198 BOOL retval = TRUE;
199 char buffer[60];
200 char option[60];
201 int value;
202 BPTR fh = Open(PREFFILE, MODE_OLDFILE);
203 if (!fh) return FALSE;
204 D(bug("Snoopy: File open\n"));
205 while (FGets(fh, buffer, sizeof(buffer)))
207 D(bug("Snoopy: %s read\n", buffer));
208 if (sscanf(buffer,"%59s %d", option, &value) == 2)
210 D(bug("Snoopy: %s | %d\n", option, value));
211 if ( ! stricmp(option, opts[onlyShowFailsOpt]))
212 setup.onlyShowFails = value;
213 else if ( ! stricmp(option, opts[useDevNamesOpt]))
214 setup.useDevNames = value;
215 else if ( ! stricmp(option, opts[showPathsOpt]))
216 setup.showPaths = value;
217 else if ( ! stricmp(option, opts[showCliNrOpt]))
218 setup.showCliNr = value;
219 else if ( ! stricmp(option, opts[ignoreWBOpt]))
220 setup.ignoreWB = value;
221 else if ( ! stricmp(option, opts[ChangeDirOpt]))
222 setup.enableChangeDir = value;
223 else if ( ! stricmp(option, opts[DeleteOpt]))
224 setup.enableDelete = value;
225 else if ( ! stricmp(option, opts[ExecuteOpt]))
226 setup.enableExecute = value;
227 else if ( ! stricmp(option, opts[GetVarOpt]))
228 setup.enableGetVar = value;
229 else if ( ! stricmp(option, opts[LoadSegOpt]))
230 setup.enableLoadSeg = value;
231 else if ( ! stricmp(option, opts[LockOpt]))
232 setup.enableLock = value;
233 else if ( ! stricmp(option, opts[MakeDirOpt]))
234 setup.enableMakeDir = value;
235 else if ( ! stricmp(option, opts[MakeLinkOpt]))
236 setup.enableMakeLink = value;
237 else if ( ! stricmp(option, opts[OpenOpt]))
238 setup.enableOpen = value;
239 else if ( ! stricmp(option, opts[RenameOpt]))
240 setup.enableRename = value;
241 else if ( ! stricmp(option, opts[RunCommandOpt]))
242 setup.enableRunCommand = value;
243 else if ( ! stricmp(option, opts[SetVarOpt]))
244 setup.enableSetVar = value;
245 else if ( ! stricmp(option, opts[SystemOpt]))
246 setup.enableSystem = value;
247 else if ( ! stricmp(option, opts[FindPortOpt]))
248 setup.enableFindPort = value;
249 else if ( ! stricmp(option, opts[FindResidentOpt]))
250 setup.enableFindResident = value;
251 else if ( ! stricmp(option, opts[FindSemaphoreOpt]))
252 setup.enableFindSemaphore = value;
253 else if ( ! stricmp(option, opts[FindTaskOpt]))
254 setup.enableFindTask = value;
255 else if ( ! stricmp(option, opts[LockScreenOpt]))
256 setup.enableLockScreen = value;
257 else if ( ! stricmp(option, opts[OpenDeviceOpt]))
258 setup.enableOpenDevice = value;
259 else if ( ! stricmp(option, opts[OpenFontOpt]))
260 setup.enableOpenFont = value;
261 else if ( ! stricmp(option, opts[OpenLibraryOpt]))
262 setup.enableOpenLibrary = value;
263 else if ( ! stricmp(option, opts[OpenResourceOpt]))
264 setup.enableOpenResource = value;
265 else if ( ! stricmp(option, opts[ReadToolTypesOpt]))
266 setup.enableReadToolTypes = value;
267 else if ( ! stricmp(option, opts[nameLenOpt]))
268 setup.nameLen = value;
269 else if ( ! stricmp(option, opts[actionLenOpt]))
270 setup.actionLen = value;
271 else if ( ! stricmp(option, opts[targetLenOpt]))
272 setup.targetLen = value;
273 else if ( ! stricmp(option, opts[optionLenOpt]))
274 setup.optionLen = value;
275 } // if
276 else if ((buffer[0] != '\0') && (buffer[0] != '\n'))
278 retval = FALSE;
280 } // while
281 Close(fh);
282 return retval;