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>
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>
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>
21 * All accesses to a preferences structure must be made through a
<br>
22 "PrefsHandle
". 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>
27 * The ID's are the first level of separation of preference data. Each
<br>
28 ID must be
4 ASCII characters, for example
"MAIN
", or
"MENU
". 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
"MAIN
" within two PrefsHandle's
<br>
32 and they will be completely different ID's.
<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>
38 This gives the following structure to preferences items:
<br>
40 Main list of all preferences handles
<br>
42 ______________/ | \___________________
<br>
44 PrefsHandle PrefsHandle ... PrefsHandle
<br>
49 / | \ | / / \ etc.
<br>
50 Tag+ | Tag+ | Tag+ | Tag+
<br>
51 Data | Data | Data | Data
<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>
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>
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>
79 ReadPrefsHandle() and WritePrefsHandle() can be used to read or write an
<br>
80 entire PrefsHandle in the specified file.
<br>
82 </UL><HR><A NAME=
"#2"><br>
84 </LI><LI><B><FONT SIZE=
"4">NAME
</FONT></B><UL><br>
85 AllocPrefsHandle -- Allocate preferences handle
<br>
87 </UL><FONT SIZE=
"4"><B> SYNOPSIS
<br>
88 </B></FONT><PRE> prefshandle = AllocPrefsHandle( name )
<br>
91 APTR AllocPrefsHandle( CONST_STRPTR );
<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>
99 </UL><FONT SIZE=
"4"><B> INPUTS
<br>
100 </B></FONT><UL> name - a string that you can identify the preferences set by
<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>
112 </UL><FONT SIZE=
"4"><B> SEE ALSO
<br>
113 </B></FONT><UL> FreePrefsHandle()
<br>
115 </UL><HR><A NAME=
"#3"><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>
120 </UL><FONT SIZE=
"4"><B> SYNOPSIS
<br>
121 </B></FONT><PRE> prefsstruct = FindPreferences(prefshandle, ID, Tag);
<br>
124 struct PrefsStruct *FindPreferences(APTR, ULONG, ULONG);
<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>
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>
139 Tag - the tag used to identify this preference data within the
<br>
142 </UL><FONT SIZE=
"4"><B> RESULT
<br>
143 </B></FONT><UL> prefsstruct - pointer to the preferences item if found, NULL otherwise
<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>
154 </UL><FONT SIZE=
"4"><B> SEE ALSO
<br>
155 </B></FONT><UL> AllocPrefsHandle(), SetPreferences(), SetEntry(), GetPreferences(),
<br>
158 </UL><HR><A NAME=
"#4"><br>
160 </LI><LI><B><FONT SIZE=
"4">NAME
</FONT></B><UL><br>
161 FreePrefsHandle -- free a previously allocated preferences handle
<br>
163 </UL><FONT SIZE=
"4"><B> SYNOPSIS
<br>
164 </B></FONT><PRE> FreePrefsHandle(PrefsHandle);
<br>
167 void FreePrefsHandle(APTR);
<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>
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>
180 </UL><FONT SIZE=
"4"><B> RESULT
<br>
188 </UL><FONT SIZE=
"4"><B> SEE ALSO
<br>
189 </B></FONT><UL> AllocPrefsHandle()
<br>
191 </UL><HR><A NAME=
"#5"><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>
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>
200 ULONG GetEntry(APTR, ULONG, ULONG, APTR, UWORD, ULONG);
<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
"Entry
" from the list in the Tag / ID /
<br>
207 preferences handle.
<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>
214 Tag - the tag used to identify this preference data within the
<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>
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>
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>
235 </UL><FONT SIZE=
"4"><B> SEE ALSO
<br>
236 </B></FONT><UL> AllocPrefsHandle(), SetPreferences(), SetEntry()
<br>
238 </UL><HR><A NAME=
"#6"><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>
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>
247 ULONG GetPreferences(APTR, ULONG, ULONG, const APTR, UWORD);
<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>
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>
260 Tag - the tag used to identify this preference data within the
<br>
262 Struct - pointer to the structure/memory you wish to store
<br>
263 Struct_Size - size of the structure/memory
<br>
265 </UL><FONT SIZE=
"4"><B> RESULT
<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>
273 This function assumes a single preferences item per tag, DO NOT USE IT
<br>
274 with preferences items set up with the
"Entry
" functions.
<br>
278 </UL><FONT SIZE=
"4"><B> SEE ALSO
<br>
279 </B></FONT><UL> AllocPrefsHandle(), SetPreferences()
<br>
281 </UL><HR><A NAME=
"#7"><br>
283 </LI><LI><B><FONT SIZE=
"4">NAME
</FONT></B><UL><br>
284 ReadPrefsHandle -- Load an entire prefs handle from disk
<br>
286 </UL><FONT SIZE=
"4"><B> SYNOPSIS
<br>
287 </B></FONT><PRE> ReadPrefsHandle(PrefsHandle, Filename);
<br>
290 void ReadPrefsHandle(APTR, CONST_STRPTR);
<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>
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>
301 </UL><FONT SIZE=
"4"><B> RESULT
<br>
306 Data is stored in memory using SetPreferences() and SetEntry()
<br>
310 Should probably return a value to indicate whether file was read
<br>
311 successfully or not.
<br>
313 </UL><FONT SIZE=
"4"><B> SEE ALSO
<br>
314 </B></FONT><UL> AllocPrefsHandle(), WritePrefsHandle(), SetPreferences(), SetEntry()
<br>
316 </UL><HR><A NAME=
"#8"><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>
321 </UL><FONT SIZE=
"4"><B> SYNOPSIS
<br>
322 </B></FONT><PRE> success = RemEntry(PrefsHandle, ID, Tag, Entry);
<br>
325 ULONG RemEntry(APTR, ULONG, ULONG, ULONG);
<br>
328 <FONT SIZE=
"4"><B> FUNCTION
<br>
329 </B></FONT><UL> Removes a preferences item, that is in a list at position
"Entry
", at
<br>
330 the given preferences handle, ID and Tag locations.
<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>
337 Tag - the tag used to identify this preference data within the
<br>
339 Entry - the position in the Tag's entry list to read this data
<br>
342 </UL><FONT SIZE=
"4"><B> RESULT
<br>
343 </B></FONT><UL> success - whether the entry was successfully removed or not.
<br>
348 DO NOT MIX this function with Tag's which have been created with
<br>
353 </UL><FONT SIZE=
"4"><B> SEE ALSO
<br>
354 </B></FONT><UL> AllocPrefsHandle(), SetPreferences(), SetEntry()
<br>
356 </UL><HR><A NAME=
"#9"><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>
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>
365 void SetEntry(APTR, ULONG, ULONG, const APTR, UWORD, ULONG);
<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 "Entry
" in a list of values being stored under the given Tag value.
<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>
378 Tag - the tag used to identify this preference data within the
<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>
384 </UL><FONT SIZE=
"4"><B> RESULT
<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>
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>
403 </UL><FONT SIZE=
"4"><B> SEE ALSO
<br>
404 </B></FONT><UL> AllocPrefsHandle(), SetPreferences()
<br>
406 </UL><HR><A NAME=
"#10"><br>
408 </LI><LI><B><FONT SIZE=
"4">NAME
</FONT></B><UL><br>
409 SetPreferences -- store data in a preference item
<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>
415 void SetPreferences(APTR, ULONG, ULONG, const APTR, UWORD);
<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>
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>
427 Tag - the tag used to identify this preference data within the
<br>
429 Struct - pointer to the structure/memory you wish to store
<br>
430 Struct_Size - size of the structure/memory
<br>
432 </UL><FONT SIZE=
"4"><B> RESULT
<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>
441 This sets up a single preferences item for the given tag. DO NOT MIX
<br>
442 preferences created with this function with the
"Entry
" commands!!!
<br>
446 </UL><FONT SIZE=
"4"><B> SEE ALSO
<br>
447 </B></FONT><UL> AllocPrefsHandle()
<br>
449 </UL><HR><A NAME=
"#11"><br>
451 </LI><LI><B><FONT SIZE=
"4">NAME
</FONT></B><UL><br>
452 WritePrefsHandle -- saves an entire preferences handle to a file
<br>
454 </UL><FONT SIZE=
"4"><B> SYNOPSIS
<br>
455 </B></FONT><PRE> WritePrefsHandle(PrefsHandle, Filename);
<br>
458 void WritePrefsHandle(APTR, CONST_STRPTR);
<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>
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>
469 </UL><FONT SIZE=
"4"><B> RESULT
<br>
474 This function can deal with single or list entries for a Tag value.
<br>
477 Should probably return a value to show if the file was successfully
<br>
480 </UL><FONT SIZE=
"4"><B> SEE ALSO
<br>
481 </B></FONT><UL> AllocPrefsHandle(), ReadPrefsHandle()
<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>