Initial import of Scalos. To decrease size I have
[AROS-Contrib.git] / scalos / main / docs / AutoDocs / html / preferences.html
blob961a1b5fd087b056a35172eb185cb345cce39eea
1 <HTML><HEAD><TITLE>preferences.library</TITLE></HEAD><BODY BACKGROUND='http://scalos.striatum.org/gfx/backdrop.gif'>
3 <FONT SIZE="5"><B>preferences.library</B></FONT><P><UL>
4 <LI><A HREF="#1">--background--</A></LI><LI><A HREF="#2">AllocPrefsHandle</A></LI><LI><A HREF="#3">FindPreferences</A></LI><LI><A HREF="#4">FreePrefsHandle</A></LI><LI><A HREF="#5">GetEntry</A></LI><LI><A HREF="#6">GetPreferences</A></LI><LI><A HREF="#7">ReadPrefsHandle</A></LI><LI><A HREF="#8">RemEntry</A></LI><LI><A HREF="#9">SetEntry</A></LI><LI><A HREF="#10">SetPreferences</A></LI><LI><A HREF="#11">WritePrefsHandle</A></LI></UL><P><UL><UL><A NAME="1"><br>
5 </LI><LI><B><FONT SIZE="4">NAME</FONT></B><UL><br>
6 --background<br>
7 <br>
8 </UL><FONT SIZE="4"><B> PURPOSE<br>
9 </B></FONT><UL> The preferences.library provides a convenient way to store the<br>
10 preferences for your program. All internal management and I/O of your<br>
11 data is handled by the library, and is controlled via a simple interface<br>
12 which makes use of identifiers and tags to access the data. Multiple<br>
13 programs can access the data (held only once in memory) at the same time<br>
14 as access is arbitrated through the use of semaphores.<br>
15 <br>
16 OVERVIEW<br>
17 Most of the data and structures mentioned here will be unavailable to<br>
18 the programmer, but it is useful to know, so that the correct use of the<br>
19 library can be adhered to.<br>
20 <br>
21 * All accesses to a preferences structure must be made through a<br>
22 &quot;PrefsHandle&quot;. A PrefsHandle is accessed by name (maximum of 32<br>
23 unique characters) using AllocPrefsHandle(). Within a PrefsHandle a<br>
24 list of ID's within this handle is stored. The pointer remains valid<br>
25 until you call FreePrefsHandle().<br>
26 <br>
27 * The ID's are the first level of separation of preference data. Each<br>
28 ID must be 4 ASCII characters, for example &quot;MAIN&quot;, or &quot;MENU&quot;. For<br>
29 creating the ID you can use the MAKE_ID macro as defined in<br>
30 libraries/iffparse.h. ID's are unique within each PrefsHandle. This<br>
31 means that you can have an ID &quot;MAIN&quot; within two PrefsHandle's<br>
32 and they will be completely different ID's.<br>
33 <br>
34 * The second level of separating the data is to use tags. A tag can have<br>
35 any value except 0. The data is stored along with the tag. Tags are<br>
36 unique within an ID the same way an ID is unique within a PrefsHandle.<br>
37 <br>
38 This gives the following structure to preferences items:<br>
39 <br>
40 Main list of all preferences handles<br>
41 / | \<br>
42 ______________/ | \___________________<br>
43 / | \<br>
44 PrefsHandle PrefsHandle ... PrefsHandle<br>
45 _/ \_<br>
46 / \<br>
47 ID ______ID<br>
48 _/ |\ / __/ |\<br>
49 / | \ | / / \ etc.<br>
50 Tag+ | Tag+ | Tag+ | Tag+<br>
51 Data | Data | Data | Data<br>
52 | | |<br>
53 Tag+ Tag+ Tag+<br>
54 Data Data Data<br>
55 <br>
56 <br>
57 The data can be manipulated in these structures using SetPreferences()<br>
58 to set the data and GetPreferences() to retrieve the data.<br>
59 <br>
60 <br>
61 There is an alternative way to store the data. You can also have a list<br>
62 of data items for each tag value. NB: you cannot mix normal single data<br>
63 tags and their functions with the list type tags and their functions.<br>
64 This is achieved using SetEntry(), GetEntry() and RemEntry() functions.<br>
65 Each data item in the list is accessed using a logical entry number.<br>
66 Since the data items are not explicitly accessed using this entry<br>
67 number (such as with an array), their positions can change when you add<br>
68 items in the middle of the list. For this reason you cannot guarantee<br>
69 the order of data items in this sub-list. Applications of this method of<br>
70 storing data could be a list of files which your program runs at<br>
71 startup, without needing them to be in any specific order.<br>
72 <br>
73 <br>
74 FindPreferences() will return a pointer to the tag specified and can be<br>
75 used to find whether a certain tag exists or to access the data (if you<br>
76 know the internal structure of tag items :). This works for either<br>
77 type of tag (single data item or list of data items).<br>
78 <br>
79 ReadPrefsHandle() and WritePrefsHandle() can be used to read or write an<br>
80 entire PrefsHandle in the specified file.<br>
81 <br>
82 </UL><HR><A NAME="#2"><br>
83 <br>
84 </LI><LI><B><FONT SIZE="4">NAME</FONT></B><UL><br>
85 AllocPrefsHandle -- Allocate preferences handle<br>
86 <br>
87 </UL><FONT SIZE="4"><B> SYNOPSIS<br>
88 </B></FONT><PRE> prefshandle = AllocPrefsHandle( name )<br>
89 D0 A0<br>
90 <br>
91 APTR AllocPrefsHandle( CONST_STRPTR );<br>
92 <br>
93 </PRE>&nbsp;<br>
94 <FONT SIZE="4"><B> FUNCTION<br>
95 </B></FONT><UL> Allocate a handle so that the preferences inside can be accessed. All<br>
96 successful calls to this function must be matched by a call to the<br>
97 FreePrefsHandle() function.<br>
98 <br>
99 </UL><FONT SIZE="4"><B> INPUTS<br>
100 </B></FONT><UL> name - a string that you can identify the preferences set by<br>
101 <br>
102 </UL><FONT SIZE="4"><B> RESULT<br>
103 </B></FONT><UL> prefshandle - a pointer to the newly allocated preferences set or NULL<br>
104 for failure.<br>
105 <br>
106 EXAMPLE<br>
107 <br>
108 NOTES<br>
109 <br>
110 BUGS<br>
111 <br>
112 </UL><FONT SIZE="4"><B> SEE ALSO<br>
113 </B></FONT><UL> FreePrefsHandle()<br>
114 <br>
115 </UL><HR><A NAME="#3"><br>
116 <br>
117 </LI><LI><B><FONT SIZE="4">NAME</FONT></B><UL><br>
118 FindPreferences -- get pointer to data stored for a preference tag<br>
119 <br>
120 </UL><FONT SIZE="4"><B> SYNOPSIS<br>
121 </B></FONT><PRE> prefsstruct = FindPreferences(prefshandle, ID, Tag);<br>
122 D0 A0 D0 D1<br>
123 <br>
124 struct PrefsStruct *FindPreferences(APTR, ULONG, ULONG);<br>
125 <br>
126 </PRE>&nbsp;<br>
127 <FONT SIZE="4"><B> FUNCTION<br>
128 </B></FONT><UL> Searchs for the preferences entry specified by the preferences handle,<br>
129 ID and Tag values and returns a pointer to whatever is stored there.<br>
130 Similar to GetPreferences() and GetEntry(), but since it does not copy<br>
131 any data can be used on both types of tag it can be used to find out<br>
132 whether a tag is present in a PrefsHandle.<br>
133 <br>
134 </UL><FONT SIZE="4"><B> INPUTS<br>
135 </B></FONT><UL> PrefsHandle - pointer to a previously successfully allocated<br>
136 preferences handle<br>
137 ID - id of the set within the preferences handle you wish to<br>
138 use<br>
139 Tag - the tag used to identify this preference data within the<br>
140 the ID set<br>
141 <br>
142 </UL><FONT SIZE="4"><B> RESULT<br>
143 </B></FONT><UL> prefsstruct - pointer to the preferences item if found, NULL otherwise<br>
144 <br>
145 EXAMPLE<br>
146 <br>
147 NOTES<br>
148 The returned pointer will return a pointer to the tag item, which will<br>
149 either be followed by the data (if set with SetPreferences()) or the<br>
150 list of sub items (if set by SetEntry()).<br>
151 <br>
152 BUGS<br>
153 <br>
154 </UL><FONT SIZE="4"><B> SEE ALSO<br>
155 </B></FONT><UL> AllocPrefsHandle(), SetPreferences(), SetEntry(), GetPreferences(),<br>
156 GetEntry()<br>
157 <br>
158 </UL><HR><A NAME="#4"><br>
159 <br>
160 </LI><LI><B><FONT SIZE="4">NAME</FONT></B><UL><br>
161 FreePrefsHandle -- free a previously allocated preferences handle<br>
162 <br>
163 </UL><FONT SIZE="4"><B> SYNOPSIS<br>
164 </B></FONT><PRE> FreePrefsHandle(PrefsHandle);<br>
165 A0<br>
166 <br>
167 void FreePrefsHandle(APTR);<br>
168 <br>
169 </PRE>&nbsp;<br>
170 <FONT SIZE="4"><B> FUNCTION<br>
171 </B></FONT><UL> Frees the preferences set associated with the handle passed into this<br>
172 function. This handle can ONLY be created by calling AllocPrefsHandle<br>
173 successfully. You MUST NOT use this preferences handle after you free<br>
174 it.<br>
175 <br>
176 </UL><FONT SIZE="4"><B> INPUTS<br>
177 </B></FONT><UL> PrefsHandle - pointer to the preferences handle successfully allocated<br>
178 using AllocPrefsHandle()<br>
179 <br>
180 </UL><FONT SIZE="4"><B> RESULT<br>
181 </B></FONT><UL><br>
182 EXAMPLE<br>
183 <br>
184 NOTES<br>
185 <br>
186 BUGS<br>
187 <br>
188 </UL><FONT SIZE="4"><B> SEE ALSO<br>
189 </B></FONT><UL> AllocPrefsHandle()<br>
190 <br>
191 </UL><HR><A NAME="#5"><br>
192 <br>
193 </LI><LI><B><FONT SIZE="4">NAME</FONT></B><UL><br>
194 GetEntry -- fills in a user structure from a preferences item<br>
195 <br>
196 </UL><FONT SIZE="4"><B> SYNOPSIS<br>
197 </B></FONT><PRE> bytescopied = GetEntry(PrefsHandle, ID, Tag, Struct, Struct_Size, Entry)<br>
198 D0 A0 D0 D1 A1 D2 D3<br>
199 <br>
200 ULONG GetEntry(APTR, ULONG, ULONG, APTR, UWORD, ULONG);<br>
201 <br>
202 </PRE>&nbsp;<br>
203 <FONT SIZE="4"><B> FUNCTION<br>
204 </B></FONT><UL> Copies the data stored in a preferences item to a struture or area of<br>
205 memory supplied by the programmer. The preference item will come from<br>
206 the list item at position &quot;Entry&quot; from the list in the Tag / ID /<br>
207 preferences handle.<br>
208 <br>
209 </UL><FONT SIZE="4"><B> INPUTS<br>
210 </B></FONT><UL> PrefsHandle - pointer to a previously successfully allocated<br>
211 preferences handle<br>
212 ID - id of the set within the preferences handle you wish to<br>
213 use<br>
214 Tag - the tag used to identify this preference data within the<br>
215 the ID set<br>
216 Struct - pointer to the structure/memory you wish to copy the<br>
217 preferences data to<br>
218 Struct_Size - size of the structure/memory<br>
219 Entry - the position in the Tag's entry list to read this data<br>
220 from<br>
221 <br>
222 </UL><FONT SIZE="4"><B> RESULT<br>
223 </B></FONT><UL> bytescopied - the actual number of bytes copied from the preference data<br>
224 to the structure/memory pointer.<br>
225 <br>
226 EXAMPLE<br>
227 <br>
228 NOTES<br>
229 DO NOT MIX this command with Tag's which have had their preference data<br>
230 set with SetPreferences. They are different internally. Only use this<br>
231 with Tag's used with SetEntry.<br>
232 <br>
233 BUGS<br>
234 <br>
235 </UL><FONT SIZE="4"><B> SEE ALSO<br>
236 </B></FONT><UL> AllocPrefsHandle(), SetPreferences(), SetEntry()<br>
237 <br>
238 </UL><HR><A NAME="#6"><br>
239 <br>
240 </LI><LI><B><FONT SIZE="4">NAME</FONT></B><UL><br>
241 GetPreferences -- returns data from a preference item to the programmer<br>
242 <br>
243 </UL><FONT SIZE="4"><B> SYNOPSIS<br>
244 </B></FONT><PRE> bytescopied = GetPreferences(PrefsHandle, ID, Tag, Struct, Struct_Size);<br>
245 D0 A0 D0 D1 A1 D2<br>
246 <br>
247 ULONG GetPreferences(APTR, ULONG, ULONG, const APTR, UWORD);<br>
248 <br>
249 </PRE>&nbsp;<br>
250 <FONT SIZE="4"><B> FUNCTION<br>
251 </B></FONT><UL> Copies the data stored in a preferences item (as referenced the prefs<br>
252 handle, ID and Tag values) into a structure/memory that the user passes.<br>
253 The number of bytes actually copied will be returned.<br>
254 <br>
255 </UL><FONT SIZE="4"><B> INPUTS<br>
256 </B></FONT><UL> PrefsHandle - pointer to a previously successfully allocated<br>
257 preferences handle<br>
258 ID - id of the set within the preferences handle you wish to<br>
259 use<br>
260 Tag - the tag used to identify this preference data within the<br>
261 the ID set<br>
262 Struct - pointer to the structure/memory you wish to store<br>
263 Struct_Size - size of the structure/memory<br>
264 <br>
265 </UL><FONT SIZE="4"><B> RESULT<br>
266 </B></FONT><UL><br>
267 EXAMPLE<br>
268 <br>
269 NOTES<br>
270 This function does nothing if the ID and Tag values are 0, as they are<br>
271 not considered valid as an ID or a Tag.<br>
272 <br>
273 This function assumes a single preferences item per tag, DO NOT USE IT<br>
274 with preferences items set up with the &quot;Entry&quot; functions.<br>
275 <br>
276 BUGS<br>
277 <br>
278 </UL><FONT SIZE="4"><B> SEE ALSO<br>
279 </B></FONT><UL> AllocPrefsHandle(), SetPreferences()<br>
280 <br>
281 </UL><HR><A NAME="#7"><br>
282 <br>
283 </LI><LI><B><FONT SIZE="4">NAME</FONT></B><UL><br>
284 ReadPrefsHandle -- Load an entire prefs handle from disk<br>
285 <br>
286 </UL><FONT SIZE="4"><B> SYNOPSIS<br>
287 </B></FONT><PRE> ReadPrefsHandle(PrefsHandle, Filename);<br>
288 A0 A1<br>
289 <br>
290 void ReadPrefsHandle(APTR, CONST_STRPTR);<br>
291 <br>
292 </PRE>&nbsp;<br>
293 <FONT SIZE="4"><B> FUNCTION<br>
294 </B></FONT><UL> Attempts to read data from a file on disk (previously saved with<br>
295 WritePrefsHandle) into the specified preferences handle.<br>
296 <br>
297 </UL><FONT SIZE="4"><B> INPUTS<br>
298 </B></FONT><UL> PrefsHandle - pointer to a previously allocated preferences handle<br>
299 Filename - full path and name of file to load from<br>
300 <br>
301 </UL><FONT SIZE="4"><B> RESULT<br>
302 </B></FONT><UL><br>
303 EXAMPLE<br>
304 <br>
305 NOTES<br>
306 Data is stored in memory using SetPreferences() and SetEntry()<br>
307 functions.<br>
308 <br>
309 BUGS<br>
310 Should probably return a value to indicate whether file was read<br>
311 successfully or not.<br>
312 <br>
313 </UL><FONT SIZE="4"><B> SEE ALSO<br>
314 </B></FONT><UL> AllocPrefsHandle(), WritePrefsHandle(), SetPreferences(), SetEntry()<br>
315 <br>
316 </UL><HR><A NAME="#8"><br>
317 <br>
318 </LI><LI><B><FONT SIZE="4">NAME</FONT></B><UL><br>
319 RemEntry -- remove an preferences item entry from a Tag that has a list<br>
320 <br>
321 </UL><FONT SIZE="4"><B> SYNOPSIS<br>
322 </B></FONT><PRE> success = RemEntry(PrefsHandle, ID, Tag, Entry);<br>
323 D0 A0 D0 D1 D2<br>
324 <br>
325 ULONG RemEntry(APTR, ULONG, ULONG, ULONG);<br>
326 <br>
327 </PRE>&nbsp;<br>
328 <FONT SIZE="4"><B> FUNCTION<br>
329 </B></FONT><UL> Removes a preferences item, that is in a list at position &quot;Entry&quot;, at<br>
330 the given preferences handle, ID and Tag locations.<br>
331 <br>
332 </UL><FONT SIZE="4"><B> INPUTS<br>
333 </B></FONT><UL> PrefsHandle - pointer to a previously successfully allocated<br>
334 preferences handle<br>
335 ID - id of the set within the preferences handle you wish to<br>
336 use<br>
337 Tag - the tag used to identify this preference data within the<br>
338 the ID set<br>
339 Entry - the position in the Tag's entry list to read this data<br>
340 from<br>
341 <br>
342 </UL><FONT SIZE="4"><B> RESULT<br>
343 </B></FONT><UL> success - whether the entry was successfully removed or not.<br>
344 <br>
345 EXAMPLE<br>
346 <br>
347 NOTES<br>
348 DO NOT MIX this function with Tag's which have been created with<br>
349 SetPreferences.<br>
350 <br>
351 BUGS<br>
352 <br>
353 </UL><FONT SIZE="4"><B> SEE ALSO<br>
354 </B></FONT><UL> AllocPrefsHandle(), SetPreferences(), SetEntry()<br>
355 <br>
356 </UL><HR><A NAME="#9"><br>
357 <br>
358 </LI><LI><B><FONT SIZE="4">NAME</FONT></B><UL><br>
359 SetEntry -- adds preference data to a list of entries related to the Tag<br>
360 <br>
361 </UL><FONT SIZE="4"><B> SYNOPSIS<br>
362 </B></FONT><PRE> SetEntry(PrefsHandle, ID, Tag, Struct, Struct_Size, Entry)<br>
363 A0 D0 D1 A1 D2 D3<br>
364 <br>
365 void SetEntry(APTR, ULONG, ULONG, const APTR, UWORD, ULONG);<br>
366 <br>
367 </PRE>&nbsp;<br>
368 <FONT SIZE="4"><B> FUNCTION<br>
369 </B></FONT><UL> Stores some user data in the preferences item in the preferences handle,<br>
370 under the specified ID and Tag values. It will be stored at position<br>
371 &quot;Entry&quot; in a list of values being stored under the given Tag value.<br>
372 <br>
373 </UL><FONT SIZE="4"><B> INPUTS<br>
374 </B></FONT><UL> PrefsHandle - pointer to a previously successfully allocated<br>
375 preferences handle<br>
376 ID - id of the set within the preferences handle you wish to<br>
377 use<br>
378 Tag - the tag used to identify this preference data within the<br>
379 the ID set<br>
380 Struct - pointer to the structure/memory you wish to store<br>
381 Struct_Size - size of the structure/memory<br>
382 Entry - the position in the Tag's entry list to store this data<br>
383 <br>
384 </UL><FONT SIZE="4"><B> RESULT<br>
385 </B></FONT><UL><br>
386 EXAMPLE<br>
387 <br>
388 NOTES<br>
389 DO NOT MIX this command with Tag values which have been created with<br>
390 SetPreferences. They are different internally. If you have previously<br>
391 stored data in this PrefsHandle/ID/Tag/Entry combination, it will be<br>
392 overwritten if the data sizes are the same, otherwise this new data will<br>
393 be inserted at the position specified.<br>
394 <br>
395 BUGS<br>
396 Since the entry can be added at the end of the list (if the position is<br>
397 not found), this means that it can be added at a position not equal to<br>
398 the given Entry value. This is not a bug as such, but the function<br>
399 should probably return the actual position that it is inserted at. Also,<br>
400 the function can fail (when allocating memory) so it should also return<br>
401 a value to indicate that failure.<br>
402 <br>
403 </UL><FONT SIZE="4"><B> SEE ALSO<br>
404 </B></FONT><UL> AllocPrefsHandle(), SetPreferences()<br>
405 <br>
406 </UL><HR><A NAME="#10"><br>
407 <br>
408 </LI><LI><B><FONT SIZE="4">NAME</FONT></B><UL><br>
409 SetPreferences -- store data in a preference item<br>
410 <br>
411 </UL><FONT SIZE="4"><B> SYNOPSIS<br>
412 </B></FONT><PRE> SetPreferences(PrefsHandle, ID, Tag, Struct, Struct_Size);<br>
413 A0, D0, D1, A1, D2<br>
414 <br>
415 void SetPreferences(APTR, ULONG, ULONG, const APTR, UWORD);<br>
416 <br>
417 </PRE>&nbsp;<br>
418 <FONT SIZE="4"><B> FUNCTION<br>
419 </B></FONT><UL> Stores a structure of data in the preferences handle, under the given<br>
420 ID and tag values.<br>
421 <br>
422 </UL><FONT SIZE="4"><B> INPUTS<br>
423 </B></FONT><UL> PrefsHandle - pointer to a previously successfully allocated<br>
424 preferences handle<br>
425 ID - id of the set within the preferences handle you wish to<br>
426 use<br>
427 Tag - the tag used to identify this preference data within the<br>
428 the ID set<br>
429 Struct - pointer to the structure/memory you wish to store<br>
430 Struct_Size - size of the structure/memory<br>
431 <br>
432 </UL><FONT SIZE="4"><B> RESULT<br>
433 </B></FONT><UL><br>
434 EXAMPLE<br>
435 <br>
436 NOTES<br>
437 This function does nothing if the ID and Tag values are 0, as they are<br>
438 not considered valid as an ID or a Tag. This will overwrite any data<br>
439 that has previously been stored in this PrefsHandle/ID/Tag combination.<br>
440 <br>
441 This sets up a single preferences item for the given tag. DO NOT MIX<br>
442 preferences created with this function with the &quot;Entry&quot; commands!!!<br>
443 <br>
444 BUGS<br>
445 <br>
446 </UL><FONT SIZE="4"><B> SEE ALSO<br>
447 </B></FONT><UL> AllocPrefsHandle()<br>
448 <br>
449 </UL><HR><A NAME="#11"><br>
450 <br>
451 </LI><LI><B><FONT SIZE="4">NAME</FONT></B><UL><br>
452 WritePrefsHandle -- saves an entire preferences handle to a file<br>
453 <br>
454 </UL><FONT SIZE="4"><B> SYNOPSIS<br>
455 </B></FONT><PRE> WritePrefsHandle(PrefsHandle, Filename);<br>
456 A0 A1<br>
457 <br>
458 void WritePrefsHandle(APTR, CONST_STRPTR);<br>
459 <br>
460 </PRE>&nbsp;<br>
461 <FONT SIZE="4"><B> FUNCTION<br>
462 </B></FONT><UL> Stores all the data and structure of the preferences handle to a file<br>
463 on disk.<br>
464 <br>
465 </UL><FONT SIZE="4"><B> INPUTS<br>
466 </B></FONT><UL> PrefsHandle - pointer to a previously allocated preferences handle<br>
467 Filename - full path and name of file to save to<br>
468 <br>
469 </UL><FONT SIZE="4"><B> RESULT<br>
470 </B></FONT><UL><br>
471 EXAMPLE<br>
472 <br>
473 NOTES<br>
474 This function can deal with single or list entries for a Tag value.<br>
475 <br>
476 BUGS<br>
477 Should probably return a value to show if the file was successfully<br>
478 saved or not.<br>
479 <br>
480 </UL><FONT SIZE="4"><B> SEE ALSO<br>
481 </B></FONT><UL> AllocPrefsHandle(), ReadPrefsHandle()<br>
482 <br>
483 </UL><HR><A NAME="#12"><br>
485 </LI></UL><P align="right">
486 Generated on 12th April 2004 by ad2html.pl v0.87 by <A HREF="http://www.philprice.net" TARGET="_blank">Phil Price</A>
487 </BODY></HTML>