8 /* SunOS 4.x Blargh.... */
10 #define NULL ((void*)0)
15 # define WMAX(a,b) ((a)>(b) ? (a) : (b))
18 # define WMIN(a,b) ((a)<(b) ? (a) : (b))
22 #ifndef __ASSERT_FUNCTION
23 # if (!defined (__GNUC__) || (__GNUC__ < 2 && \
24 __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4)))
25 # define __ASSERT_FUNCTION ((char *) 0)
27 # define __ASSERT_FUNCTION __PRETTY_FUNCTION__
32 #define __attribute__(x) /*NOTHING*/
37 #define wassertr(expr) {}
38 #define wassertrv(expr, val) {}
46 #define wassertr(expr) assert(expr)
48 #define wassertrv(expr, val) assert(expr)
52 #define wassertr(expr) \
54 wwarning("%s line %i (%s): assertion %s failed",\
55 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
59 #define wassertrv(expr, val) \
61 wwarning("%s line %i (%s): assertion %s failed",\
62 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
72 #endif /* __cplusplus */
86 } WMNotificationCoalescing
;
91 WBNotFound
= INT_MIN
, /* element was not found in WMBag */
92 WANotFound
= -1 /* element was not found in WMArray */
96 typedef struct W_Array WMArray
;
97 typedef struct W_Bag WMBag
;
98 typedef struct W_Data WMData
;
99 typedef struct W_TreeNode WMTreeNode
;
100 typedef struct W_HashTable WMHashTable
;
101 typedef struct W_UserDefaults WMUserDefaults
;
102 typedef struct W_Notification WMNotification
;
103 typedef struct W_NotificationQueue WMNotificationQueue
;
104 typedef struct W_Host WMHost
;
105 typedef struct W_Connection WMConnection
;
106 typedef struct W_PropList WMPropList
;
110 /* Some typedefs for the handler stuff */
111 typedef void *WMHandlerID
;
113 typedef void WMCallback(void *data
);
115 typedef void WMInputProc(int fd
, int mask
, void *clientData
);
119 typedef int WMCompareDataProc(const void *item1
, const void *item2
);
121 typedef void WMFreeDataProc(void *data
);
123 /* Used by WMBag or WMArray for matching data */
124 typedef int WMMatchDataProc(const void *item
, const void *cdata
);
135 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
144 /* NULL is pointer hash */
145 unsigned (*hash
)(const void *);
146 /* NULL is pointer compare */
147 Bool (*keyIsEqual
)(const void *, const void *);
148 /* NULL does nothing */
149 void* (*retainKey
)(const void *);
150 /* NULL does nothing */
151 void (*releaseKey
)(const void *);
152 } WMHashTableCallbacks
;
155 typedef int WMArrayIterator
;
156 typedef void *WMBagIterator
;
159 typedef void WMNotificationObserverAction(void *observerData
,
160 WMNotification
*notification
);
163 /*......................................................................*/
165 typedef void waborthandler(int);
167 waborthandler
* wsetabort(waborthandler
* handler
);
170 WMESSAGE_TYPE_MESSAGE
,
171 WMESSAGE_TYPE_WARNING
,
173 WMESSAGE_TYPE_WSYSERROR
,
174 WMESSAGE_TYPE_WSYSERRORWITHCODE
177 #define wmessage(fmt, args...) __wmessage( WMESSAGE_TYPE_MESSAGE, NULL, fmt, ## args)
178 #define wwarning(fmt, args...) __wmessage( WMESSAGE_TYPE_WARNING, NULL, fmt, ## args)
179 #define wfatal(fmt, args...) __wmessage( WMESSAGE_TYPE_FATAL, NULL, fmt, ## args)
180 #define wsyserror(fmt, args...) __wmessage( WMESSAGE_TYPE_WSYSERROR, NULL, fmt, ## args)
181 #define wsyserrorwithcode(errno, fmt, args...) \
182 __wmessage( WMESSAGE_TYPE_WSYSERRORWITHCODE, &errno, fmt, ## args)
184 void __wmessage(int type
, void *extra
, const char *msg
, ...) __attribute__((__format__(printf
,3,4)));
186 char* wfindfile(char *paths
, char *file
);
188 char* wfindfileinlist(char **path_list
, char *file
);
190 char* wfindfileinarray(WMPropList
* array
, char *file
);
192 char* wexpandpath(char *path
);
194 int wmkdirhier(const char *path
);
195 int wrmdirhier(const char *path
);
197 /* don't free the returned string */
198 char* wgethomedir(void);
200 void* wmalloc(size_t size
);
201 void* wrealloc(void *ptr
, size_t newsize
);
202 void wfree(void *ptr
);
204 void wrelease(void *ptr
);
205 void* wretain(void *ptr
);
207 char *wstrdup(const char *str
);
208 char* wstrndup(const char *str
, size_t len
);
210 /* Concatenate str1 with str2 and return that in a newly malloc'ed string.
211 * str1 and str2 can be any strings including static and constant strings.
212 * str1 and str2 will not be modified.
213 * Free the returned string when you're done with it. */
214 char* wstrconcat(char *str1
, char *str2
);
216 /* This will append src to dst, and return dst. dst MUST be either NULL
217 * or a string that was a result of a dynamic allocation (malloc, realloc
218 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
219 * Modifies dst (no new string is created except if dst==NULL in which case
220 * it is equivalent to calling wstrdup(src) ).
221 * The returned address may be different from the original address of dst,
222 * so always assign the returned address to avoid dangling pointers. */
223 char* wstrappend(char *dst
, char *src
);
226 void wtokensplit(char *command
, char ***argv
, int *argc
);
228 char* wtokennext(char *word
, char **next
);
230 char* wtokenjoin(char **list
, int count
);
232 void wtokenfree(char **tokens
, int count
);
234 char* wtrimspace(const char *s
);
237 WMRange
wmkrange(int start
, int count
);
240 char* wusergnusteppath(void);
242 char* wdefaultspathfordomain(char *domain
);
243 char* wglobaldefaultspathfordomain(const char *domain
);
245 void wusleep(unsigned int microsec
);
247 /*......................................................................*/
249 /* Event handlers: timer, idle, input */
251 WMHandlerID
WMAddTimerHandler(int milliseconds
, WMCallback
*callback
,
254 WMHandlerID
WMAddPersistentTimerHandler(int milliseconds
, WMCallback
*callback
,
257 void WMDeleteTimerWithClientData(void *cdata
);
259 void WMDeleteTimerHandler(WMHandlerID handlerID
);
261 WMHandlerID
WMAddIdleHandler(WMCallback
*callback
, void *cdata
);
263 void WMDeleteIdleHandler(WMHandlerID handlerID
);
265 WMHandlerID
WMAddInputHandler(int fd
, int condition
, WMInputProc
*proc
,
268 void WMDeleteInputHandler(WMHandlerID handlerID
);
271 /* This function is used _only_ if you create a non-GUI program.
272 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
273 * This function will handle all input/timer/idle events, then return.
276 void WHandleEvents(void);
278 /*......................................................................*/
281 WMHashTable
* WMCreateHashTable(WMHashTableCallbacks callbacks
);
283 void WMFreeHashTable(WMHashTable
*table
);
285 void WMResetHashTable(WMHashTable
*table
);
287 unsigned WMCountHashTable(WMHashTable
*table
);
289 void* WMHashGet(WMHashTable
*table
, const void *key
);
291 /* Returns True if there is a value associated with <key> in the table, in
292 * which case <retKey> and <retItem> will contain the item's internal key
293 * address and the item's value respectively.
294 * If there is no value associated with <key> it will return False and in
295 * this case <retKey> and <retItem> will be undefined.
296 * Use this when you need to perform your own custom retain/release mechanism
297 * which requires access to the keys too.
299 Bool
WMHashGetItemAndKey(WMHashTable
*table
, const void *key
,
300 void **retItem
, void **retKey
);
302 /* put data in table, replacing already existing data and returning
304 void* WMHashInsert(WMHashTable
*table
, const void *key
, const void *data
);
306 void WMHashRemove(WMHashTable
*table
, const void *key
);
308 /* warning: do not manipulate the table while using the enumerator functions */
309 WMHashEnumerator
WMEnumerateHashTable(WMHashTable
*table
);
311 void* WMNextHashEnumeratorItem(WMHashEnumerator
*enumerator
);
313 void* WMNextHashEnumeratorKey(WMHashEnumerator
*enumerator
);
315 /* Returns True if there is a next element, in which case key and item
316 * will contain the next element's key and value respectively.
317 * If there is no next element available it will return False and in this
318 * case key and item will be undefined.
320 Bool
WMNextHashEnumeratorItemAndKey(WMHashEnumerator
*enumerator
,
321 void **item
, void **key
);
326 /* some predefined callback sets */
328 extern const WMHashTableCallbacks WMIntHashCallbacks
;
329 /* sizeof(keys) are <= sizeof(void*) */
331 extern const WMHashTableCallbacks WMStringHashCallbacks
;
332 /* keys are strings. Strings will be copied with wstrdup()
333 * and freed with wfree() */
335 extern const WMHashTableCallbacks WMStringPointerHashCallbacks
;
336 /* keys are strings, but they are not copied */
339 /*......................................................................*/
342 * WMArray use an array to store the elements.
343 * Item indexes may be only positive integer numbers.
344 * The array cannot contain holes in it.
347 * Fast [O(1)] access to elements
348 * Fast [O(1)] push/pop
351 * A little slower [O(n)] for insertion/deletion of elements that
355 WMArray
* WMCreateArray(int initialSize
);
357 WMArray
* WMCreateArrayWithDestructor(int initialSize
, WMFreeDataProc
*destructor
);
359 WMArray
* WMCreateArrayWithArray(WMArray
*array
);
361 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
363 void WMEmptyArray(WMArray
*array
);
365 void WMFreeArray(WMArray
*array
);
367 int WMGetArrayItemCount(WMArray
*array
);
369 /* appends other to array. other remains unchanged */
370 void WMAppendArray(WMArray
*array
, WMArray
*other
);
372 /* add will place the element at the end of the array */
373 void WMAddToArray(WMArray
*array
, void *item
);
375 /* insert will increment the index of elements after it by 1 */
376 void WMInsertInArray(WMArray
*array
, int index
, void *item
);
378 /* replace and set will return the old item WITHOUT calling the
379 * destructor on it even if its available. Free the returned item yourself.
381 void* WMReplaceInArray(WMArray
*array
, int index
, void *item
);
383 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
385 /* delete and remove will remove the elements and cause the elements
386 * after them to decrement their indexes by 1. Also will call the
387 * destructor on the deleted element if there's one available.
389 int WMDeleteFromArray(WMArray
*array
, int index
);
391 #define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
393 int WMRemoveFromArrayMatching(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
395 void* WMGetFromArray(WMArray
*array
, int index
);
397 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
399 /* pop will return the last element from the array, also removing it
400 * from the array. The destructor is NOT called, even if available.
401 * Free the returned element if needed by yourself
403 void* WMPopFromArray(WMArray
*array
);
405 int WMFindInArray(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
407 int WMCountInArray(WMArray
*array
, void *item
);
409 /* comparer must return:
414 void WMSortArray(WMArray
*array
, WMCompareDataProc
*comparer
);
416 void WMMapArray(WMArray
*array
, void (*function
)(void*, void*), void *data
);
418 WMArray
* WMGetSubarrayWithRange(WMArray
* array
, WMRange aRange
);
420 void* WMArrayFirst(WMArray
*array
, WMArrayIterator
*iter
);
422 void* WMArrayLast(WMArray
*array
, WMArrayIterator
*iter
);
424 /* The following 2 functions assume that the array doesn't change between calls */
425 void* WMArrayNext(WMArray
*array
, WMArrayIterator
*iter
);
427 void* WMArrayPrevious(WMArray
*array
, WMArrayIterator
*iter
);
430 /* The following 2 macros assume that the array doesn't change in the for loop */
431 #define WM_ITERATE_ARRAY(array, var, i) \
432 for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
433 var = WMArrayNext(array, &(i)))
435 #define WM_ETARETI_ARRAY(array, var, i) \
436 for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
437 var = WMArrayPrevious(array, &(i)))
439 /*..........................................................................*/
442 * Tree bags use a red-black tree for storage.
443 * Item indexes may be any integer number.
446 * O(lg n) insertion/deletion/search
447 * Good for large numbers of elements with sparse indexes
450 * O(lg n) insertion/deletion/search
451 * Slow for storing small numbers of elements
454 #define WMCreateBag(size) WMCreateTreeBag()
456 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
458 WMBag
* WMCreateTreeBag(void);
460 WMBag
* WMCreateTreeBagWithDestructor(WMFreeDataProc
*destructor
);
462 int WMGetBagItemCount(WMBag
*bag
);
464 void WMAppendBag(WMBag
*bag
, WMBag
*other
);
466 void WMPutInBag(WMBag
*bag
, void *item
);
468 /* insert will increment the index of elements after it by 1 */
469 void WMInsertInBag(WMBag
*bag
, int index
, void *item
);
471 /* erase will remove the element from the bag,
472 * but will keep the index of the other elements unchanged */
473 int WMEraseFromBag(WMBag
*bag
, int index
);
475 /* delete and remove will remove the elements and cause the elements
476 * after them to decrement their indexes by 1 */
477 int WMDeleteFromBag(WMBag
*bag
, int index
);
479 int WMRemoveFromBag(WMBag
*bag
, void *item
);
481 void* WMGetFromBag(WMBag
*bag
, int index
);
483 void* WMReplaceInBag(WMBag
*bag
, int index
, void *item
);
485 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
487 /* comparer must return:
492 void WMSortBag(WMBag
*bag
, WMCompareDataProc
*comparer
);
494 void WMEmptyBag(WMBag
*bag
);
496 void WMFreeBag(WMBag
*bag
);
498 void WMMapBag(WMBag
*bag
, void (*function
)(void*, void*), void *data
);
500 int WMGetFirstInBag(WMBag
*bag
, void *item
);
502 int WMCountInBag(WMBag
*bag
, void *item
);
504 int WMFindInBag(WMBag
*bag
, WMMatchDataProc
*match
, void *cdata
);
506 void* WMBagFirst(WMBag
*bag
, WMBagIterator
*ptr
);
508 void* WMBagLast(WMBag
*bag
, WMBagIterator
*ptr
);
510 /* The following 4 functions assume that the bag doesn't change between calls */
511 void* WMBagNext(WMBag
*bag
, WMBagIterator
*ptr
);
513 void* WMBagPrevious(WMBag
*bag
, WMBagIterator
*ptr
);
515 void* WMBagIteratorAtIndex(WMBag
*bag
, int index
, WMBagIterator
*ptr
);
517 int WMBagIndexForIterator(WMBag
*bag
, WMBagIterator ptr
);
520 /* The following 2 macros assume that the bag doesn't change in the for loop */
521 #define WM_ITERATE_BAG(bag, var, i) \
522 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
523 var = WMBagNext(bag, &(i)))
525 #define WM_ETARETI_BAG(bag, var, i) \
526 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
527 var = WMBagPrevious(bag, &(i)))
531 /*-------------------------------------------------------------------------*/
533 /* WMData handling */
535 /* Creating/destroying data */
537 WMData
* WMCreateDataWithCapacity(unsigned capacity
);
539 WMData
* WMCreateDataWithLength(unsigned length
);
541 WMData
* WMCreateDataWithBytes(void *bytes
, unsigned length
);
543 /* destructor is a function called to free the data when releasing the data
544 * object, or NULL if no freeing of data is necesary. */
545 WMData
* WMCreateDataWithBytesNoCopy(void *bytes
, unsigned length
,
546 WMFreeDataProc
*destructor
);
548 WMData
* WMCreateDataWithData(WMData
*aData
);
550 WMData
* WMRetainData(WMData
*aData
);
552 void WMReleaseData(WMData
*aData
);
554 /* Adjusting capacity */
556 void WMSetDataCapacity(WMData
*aData
, unsigned capacity
);
558 void WMSetDataLength(WMData
*aData
, unsigned length
);
560 void WMIncreaseDataLengthBy(WMData
*aData
, unsigned extraLength
);
564 const void* WMDataBytes(WMData
*aData
);
566 void WMGetDataBytes(WMData
*aData
, void *buffer
);
568 void WMGetDataBytesWithLength(WMData
*aData
, void *buffer
, unsigned length
);
570 void WMGetDataBytesWithRange(WMData
*aData
, void *buffer
, WMRange aRange
);
572 WMData
* WMGetSubdataWithRange(WMData
*aData
, WMRange aRange
);
576 Bool
WMIsDataEqualToData(WMData
*aData
, WMData
*anotherData
);
578 unsigned WMGetDataLength(WMData
*aData
);
582 void WMAppendDataBytes(WMData
*aData
, void *bytes
, unsigned length
);
584 void WMAppendData(WMData
*aData
, WMData
*anotherData
);
588 void WMReplaceDataBytesInRange(WMData
*aData
, WMRange aRange
, void *bytes
);
590 void WMResetDataBytesInRange(WMData
*aData
, WMRange aRange
);
592 void WMSetData(WMData
*aData
, WMData
*anotherData
);
595 void WMSetDataFormat(WMData
*aData
, unsigned format
);
597 unsigned WMGetDataFormat(WMData
*aData
);
601 /*--------------------------------------------------------------------------*/
603 /* Generic Tree and TreeNode */
605 WMTreeNode
* WMCreateTreeNode(void *data
);
607 WMTreeNode
* WMCreateTreeNodeWithDestructor(void *data
, WMFreeDataProc
*destructor
);
609 WMTreeNode
* WMInsertItemInTree(WMTreeNode
*parent
, int index
, void *item
);
611 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
613 WMTreeNode
* WMInsertNodeInTree(WMTreeNode
*parent
, int index
, WMTreeNode
*aNode
);
615 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
617 void WMDestroyTreeNode(WMTreeNode
*aNode
);
619 void WMDeleteLeafForTreeNode(WMTreeNode
*aNode
, int index
);
621 void WMRemoveLeafForTreeNode(WMTreeNode
*aNode
, void *leaf
);
623 void* WMReplaceDataForTreeNode(WMTreeNode
*aNode
, void *newData
);
625 void* WMGetDataForTreeNode(WMTreeNode
*aNode
);
627 int WMGetTreeNodeDepth(WMTreeNode
*aNode
);
629 WMTreeNode
* WMGetParentForTreeNode(WMTreeNode
*aNode
);
631 /* Sort only the leaves of the passed node */
632 void WMSortLeavesForTreeNode(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
634 /* Sort all tree recursively starting from the passed node */
635 void WMSortTree(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
637 /* Returns the first node which matches node's data with cdata by 'match' */
638 WMTreeNode
* WMFindInTree(WMTreeNode
*aTree
, WMMatchDataProc
*match
, void *cdata
);
640 /* Returns first tree node that has data == cdata */
641 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(aTree, NULL, cdata)
644 /*--------------------------------------------------------------------------*/
647 WMNotification
* WMCreateNotification(const char *name
, void *object
, void *clientData
);
649 void WMReleaseNotification(WMNotification
*notification
);
651 WMNotification
* WMRetainNotification(WMNotification
*notification
);
653 void* WMGetNotificationClientData(WMNotification
*notification
);
655 void* WMGetNotificationObject(WMNotification
*notification
);
657 const char* WMGetNotificationName(WMNotification
*notification
);
660 void WMAddNotificationObserver(WMNotificationObserverAction
*observerAction
,
661 void *observer
, const char *name
, void *object
);
663 void WMPostNotification(WMNotification
*notification
);
665 void WMRemoveNotificationObserver(void *observer
);
667 void WMRemoveNotificationObserverWithName(void *observer
, const char *name
,
670 void WMPostNotificationName(const char *name
, void *object
, void *clientData
);
672 WMNotificationQueue
* WMGetDefaultNotificationQueue(void);
674 WMNotificationQueue
* WMCreateNotificationQueue(void);
676 void WMDequeueNotificationMatching(WMNotificationQueue
*queue
,
677 WMNotification
*notification
,
680 void WMEnqueueNotification(WMNotificationQueue
*queue
,
681 WMNotification
*notification
,
682 WMPostingStyle postingStyle
);
684 void WMEnqueueCoalesceNotification(WMNotificationQueue
*queue
,
685 WMNotification
*notification
,
686 WMPostingStyle postingStyle
,
687 unsigned coalesceMask
);
690 /*......................................................................*/
692 /* Property Lists handling */
694 void WMPLSetCaseSensitive(Bool caseSensitive
);
696 WMPropList
* WMCreatePLString(char *str
);
698 WMPropList
* WMCreatePLData(WMData
*data
);
700 WMPropList
* WMCreatePLDataWithBytes(unsigned char *bytes
, unsigned int length
);
702 WMPropList
* WMCreatePLDataWithBytesNoCopy(unsigned char *bytes
,
704 WMFreeDataProc
*destructor
);
706 WMPropList
* WMCreatePLArray(WMPropList
*elem
, ...);
708 WMPropList
* WMCreatePLDictionary(WMPropList
*key
, WMPropList
*value
, ...);
710 WMPropList
* WMRetainPropList(WMPropList
*plist
);
712 void WMReleasePropList(WMPropList
*plist
);
714 /* Objects inserted in arrays and dictionaries will be retained,
715 * so you can safely release them after insertion.
716 * For dictionaries both the key and value are retained.
717 * Objects removed from arrays or dictionaries are released */
718 void WMInsertInPLArray(WMPropList
*plist
, int index
, WMPropList
*item
);
720 void WMAddToPLArray(WMPropList
*plist
, WMPropList
*item
);
722 void WMDeleteFromPLArray(WMPropList
*plist
, int index
);
724 void WMRemoveFromPLArray(WMPropList
*plist
, WMPropList
*item
);
726 void WMPutInPLDictionary(WMPropList
*plist
, WMPropList
*key
, WMPropList
*value
);
728 void WMRemoveFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
730 /* It will insert all key/value pairs from source into dest, overwriting
731 * the values with the same keys from dest, keeping all values with keys
732 * only present in dest unchanged */
733 WMPropList
* WMMergePLDictionaries(WMPropList
*dest
, WMPropList
*source
,
736 /* It will remove all key/value pairs from dest for which there is an
737 * identical key/value present in source. Entires only present in dest, or
738 * which have different values in dest than in source will be preserved. */
739 WMPropList
* WMSubtractPLDictionaries(WMPropList
*dest
, WMPropList
*source
,
742 int WMGetPropListItemCount(WMPropList
*plist
);
744 Bool
WMIsPLString(WMPropList
*plist
);
746 Bool
WMIsPLData(WMPropList
*plist
);
748 Bool
WMIsPLArray(WMPropList
*plist
);
750 Bool
WMIsPLDictionary(WMPropList
*plist
);
752 Bool
WMIsPropListEqualTo(WMPropList
*plist
, WMPropList
*other
);
754 /* Returns a reference. Do not free it! */
755 char* WMGetFromPLString(WMPropList
*plist
);
757 /* Returns a reference. Do not free it! */
758 WMData
* WMGetFromPLData(WMPropList
*plist
);
760 /* Returns a reference. Do not free it! */
761 const unsigned char* WMGetPLDataBytes(WMPropList
*plist
);
763 int WMGetPLDataLength(WMPropList
*plist
);
765 /* Returns a reference. */
766 WMPropList
* WMGetFromPLArray(WMPropList
*plist
, int index
);
768 /* Returns a reference. */
769 WMPropList
* WMGetFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
771 /* Returns a PropList array with all the dictionary keys. Release it when
772 * you're done. Keys in array are retained from the original dictionary
773 * not copied and need NOT to be released individually. */
774 WMPropList
* WMGetPLDictionaryKeys(WMPropList
*plist
);
776 /* Creates only the first level deep object. All the elements inside are
777 * retained from the original */
778 WMPropList
* WMShallowCopyPropList(WMPropList
*plist
);
780 /* Makes a completely separate replica of the original proplist */
781 WMPropList
* WMDeepCopyPropList(WMPropList
*plist
);
783 WMPropList
* WMCreatePropListFromDescription(char *desc
);
785 /* Free the returned string when you no longer need it */
786 char* WMGetPropListDescription(WMPropList
*plist
, Bool indented
);
788 WMPropList
* WMReadPropListFromFile(char *file
);
790 Bool
WMWritePropListToFile(WMPropList
*plist
, char *path
);
792 /*......................................................................*/
794 WMUserDefaults
* WMGetStandardUserDefaults(void);
796 WMUserDefaults
* WMGetDefaultsFromPath(char *path
);
798 void WMSynchronizeUserDefaults(WMUserDefaults
*database
);
800 void WMSaveUserDefaults(WMUserDefaults
*database
);
802 void WMEnableUDPeriodicSynchronization(WMUserDefaults
*database
, Bool enable
);
804 /* Returns a WMPropList array with all the keys in the user defaults database.
805 * Free the array with WMReleasePropList() when no longer needed.
806 * Keys in array are just retained references to the original keys */
807 WMPropList
* WMGetUDKeys(WMUserDefaults
*database
);
809 WMPropList
* WMGetUDObjectForKey(WMUserDefaults
*database
, char *defaultName
);
811 void WMSetUDObjectForKey(WMUserDefaults
*database
, WMPropList
*object
,
814 void WMRemoveUDObjectForKey(WMUserDefaults
*database
, char *defaultName
);
816 char* WMGetUDStringForKey(WMUserDefaults
*database
, char *defaultName
);
818 int WMGetUDIntegerForKey(WMUserDefaults
*database
, char *defaultName
);
820 float WMGetUDFloatForKey(WMUserDefaults
*database
, char *defaultName
);
822 Bool
WMGetUDBoolForKey(WMUserDefaults
*database
, char *defaultName
);
824 void WMSetUDStringForKey(WMUserDefaults
*database
, char *value
,
827 void WMSetUDIntegerForKey(WMUserDefaults
*database
, int value
,
830 void WMSetUDFloatForKey(WMUserDefaults
*database
, float value
,
833 void WMSetUDBoolForKey(WMUserDefaults
*database
, Bool value
,
836 WMPropList
* WMGetUDSearchList(WMUserDefaults
*database
);
838 void WMSetUDSearchList(WMUserDefaults
*database
, WMPropList
*list
);
840 extern char *WMUserDefaultsDidChangeNotification
;
843 /*-------------------------------------------------------------------------*/
845 /* Global variables */
847 extern int WCErrorCode
;
850 /*-------------------------------------------------------------------------*/
853 size_t strlcpy(char *, const char *, size_t);
856 size_t strlcat(char *, const char *, size_t);
861 #endif /* __cplusplus */