WUtil: Added comment about values returned by API functions
[wmaker-crm.git] / WINGs / WINGs / WUtil.h
bloba4e8f270b3a024e9ee94788f9c99b2dd44c9e914
1 #ifndef _WUTIL_H_
2 #define _WUTIL_H_
4 #include <X11/Xlib.h>
5 #include <limits.h>
6 #include <sys/types.h>
8 /* SunOS 4.x Blargh.... */
9 #ifndef NULL
10 #define NULL ((void*)0)
11 #endif
14 #ifndef WMAX
15 # define WMAX(a,b) ((a)>(b) ? (a) : (b))
16 #endif
17 #ifndef WMIN
18 # define WMIN(a,b) ((a)<(b) ? (a) : (b))
19 #endif
22 #ifndef __ASSERT_FUNCTION
23 # if (!defined (__GNUC__) || (__GNUC__ < 2 && \
24 __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4)))
25 # define __ASSERT_FUNCTION ((char *) 0)
26 # else
27 # define __ASSERT_FUNCTION __PRETTY_FUNCTION__
28 # endif
29 #endif
31 #ifndef __GNUC__
32 #define __attribute__(x) /*NOTHING*/
33 #endif
35 #ifdef NDEBUG
37 #define wassertr(expr) {}
38 #define wassertrv(expr, val) {}
40 #else /* !NDEBUG */
42 #ifdef DEBUG
44 #include <assert.h>
46 #define wassertr(expr) assert(expr)
48 #define wassertrv(expr, val) assert(expr)
50 #else /* !DEBUG */
52 #define wassertr(expr) \
53 if (!(expr)) { \
54 wwarning("%s line %i (%s): assertion %s failed",\
55 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
56 return;\
59 #define wassertrv(expr, val) \
60 if (!(expr)) { \
61 wwarning("%s line %i (%s): assertion %s failed",\
62 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
63 return (val);\
65 #endif /* !DEBUG */
67 #endif /* !NDEBUG */
70 #ifdef __cplusplus
71 extern "C" {
72 #endif /* __cplusplus */
75 typedef enum {
76 WMPostWhenIdle = 1,
77 WMPostASAP = 2,
78 WMPostNow = 3
79 } WMPostingStyle;
82 typedef enum {
83 WNCNone = 0,
84 WNCOnName = 1,
85 WNCOnSender = 2
86 } WMNotificationCoalescing;
90 enum {
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);
120 typedef void WMTreeWalkProc(WMTreeNode *aNode, void *data);
122 typedef void WMFreeDataProc(void *data);
124 /* Used by WMBag or WMArray for matching data */
125 typedef int WMMatchDataProc(const void *item, const void *cdata);
129 typedef struct {
130 int position;
131 int count;
132 } WMRange;
136 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
137 typedef struct {
138 void *table;
139 void *nextItem;
140 int index;
141 } WMHashEnumerator;
144 typedef struct {
145 /* NULL is pointer hash */
146 unsigned (*hash)(const void *);
147 /* NULL is pointer compare */
148 Bool (*keyIsEqual)(const void *, const void *);
149 /* NULL does nothing */
150 void* (*retainKey)(const void *);
151 /* NULL does nothing */
152 void (*releaseKey)(const void *);
153 } WMHashTableCallbacks;
156 typedef int WMArrayIterator;
157 typedef void *WMBagIterator;
160 typedef void WMNotificationObserverAction(void *observerData,
161 WMNotification *notification);
164 /* ---[ WINGs/memory.c ]-------------------------------------------------- */
166 void* wmalloc(size_t size);
167 void* wrealloc(void *ptr, size_t newsize);
168 void wfree(void *ptr);
170 void wrelease(void *ptr);
171 void* wretain(void *ptr);
173 typedef void waborthandler(int);
175 waborthandler* wsetabort(waborthandler* handler);
177 /* ---[ WINGs/error.c ]--------------------------------------------------- */
179 enum {
180 WMESSAGE_TYPE_MESSAGE,
181 WMESSAGE_TYPE_WARNING,
182 WMESSAGE_TYPE_ERROR,
183 WMESSAGE_TYPE_FATAL
186 #define wmessage(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_MESSAGE, fmt, ## args)
187 #define wwarning(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_WARNING, fmt, ## args)
188 #define werror(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_ERROR, fmt, ## args)
189 #define wfatal(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_FATAL, fmt, ## args)
191 void __wmessage(const char *func, const char *file, int line, int type, const char *msg, ...)
192 __attribute__((__format__(printf,5,6)));
194 /* ---[ WINGs/findfile.c ]------------------------------------------------ */
196 /* For the 4 function below, you have to free the returned string when you no longer need it */
198 char* wfindfile(const char *paths, const char *file);
200 char* wfindfileinlist(char *const *path_list, const char *file);
202 char* wfindfileinarray(WMPropList* array, const char *file);
204 char* wexpandpath(const char *path);
206 int wcopy_file(const char *toPath, const char *srcFile, const char *destFile);
208 /* don't free the returned string */
209 char* wgethomedir(void);
211 /* ---[ WINGs/proplist.c ]------------------------------------------------ */
213 int wmkdirhier(const char *path);
214 int wrmdirhier(const char *path);
216 /* ---[ WINGs/string.c ]-------------------------------------------------- */
218 char *wstrdup(const char *str);
219 char* wstrndup(const char *str, size_t len);
221 /* Concatenate str1 with str2 and return that in a newly malloc'ed string.
222 * str1 and str2 can be any strings including static and constant strings.
223 * str1 and str2 will not be modified.
224 * Free the returned string when you're done with it. */
225 char* wstrconcat(const char *str1, const char *str2);
227 /* This will append src to dst, and return dst. dst MUST be either NULL
228 * or a string that was a result of a dynamic allocation (malloc, realloc
229 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
230 * Modifies dst (no new string is created except if dst==NULL in which case
231 * it is equivalent to calling wstrdup(src) ).
232 * The returned address may be different from the original address of dst,
233 * so always assign the returned address to avoid dangling pointers. */
234 char* wstrappend(char *dst, const char *src);
236 size_t wstrlcpy(char *, const char *, size_t);
237 size_t wstrlcat(char *, const char *, size_t);
240 void wtokensplit(char *command, char ***argv, int *argc);
242 char* wtokennext(char *word, char **next);
244 char* wtokenjoin(char **list, int count);
246 void wtokenfree(char **tokens, int count);
248 char* wtrimspace(const char *s);
250 /* transform `s' so that the result is safe to pass to the shell as an argument.
251 * returns a newly allocated string.
252 * with very heavy inspirations from NetBSD's shquote(3).
254 char *wshellquote(const char *s);
256 /* ---[ WINGs/wmisc.c ]--------------------------------------------------- */
258 WMRange wmkrange(int start, int count);
260 /* ---[ WINGs/usleep.c ]-------------------------------------------------- */
262 void wusleep(unsigned int usec);
264 /* ---[ WINGs/handlers.c ]------------------------------------------------ */
266 /* Event handlers: timer, idle, input */
268 WMHandlerID WMAddTimerHandler(int milliseconds, WMCallback *callback,
269 void *cdata);
271 WMHandlerID WMAddPersistentTimerHandler(int milliseconds, WMCallback *callback,
272 void *cdata);
274 void WMDeleteTimerWithClientData(void *cdata);
276 void WMDeleteTimerHandler(WMHandlerID handlerID);
278 WMHandlerID WMAddIdleHandler(WMCallback *callback, void *cdata);
280 void WMDeleteIdleHandler(WMHandlerID handlerID);
282 WMHandlerID WMAddInputHandler(int fd, int condition, WMInputProc *proc,
283 void *clientData);
285 void WMDeleteInputHandler(WMHandlerID handlerID);
288 /* This function is used _only_ if you create a non-GUI program.
289 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
290 * This function will handle all input/timer/idle events, then return.
293 void WHandleEvents(void);
295 /* ---[ WINGs/hashtable.c ]----------------------------------------------- */
298 WMHashTable* WMCreateHashTable(WMHashTableCallbacks callbacks);
300 void WMFreeHashTable(WMHashTable *table);
302 void WMResetHashTable(WMHashTable *table);
304 unsigned WMCountHashTable(WMHashTable *table);
306 void* WMHashGet(WMHashTable *table, const void *key);
308 /* Returns True if there is a value associated with <key> in the table, in
309 * which case <retKey> and <retItem> will contain the item's internal key
310 * address and the item's value respectively.
311 * If there is no value associated with <key> it will return False and in
312 * this case <retKey> and <retItem> will be undefined.
313 * Use this when you need to perform your own custom retain/release mechanism
314 * which requires access to the keys too.
316 Bool WMHashGetItemAndKey(WMHashTable *table, const void *key,
317 void **retItem, void **retKey);
319 /* put data in table, replacing already existing data and returning
320 * the old value */
321 void* WMHashInsert(WMHashTable *table, const void *key, const void *data);
323 void WMHashRemove(WMHashTable *table, const void *key);
325 /* warning: do not manipulate the table while using the enumerator functions */
326 WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
328 void* WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
330 void* WMNextHashEnumeratorKey(WMHashEnumerator *enumerator);
332 /* Returns True if there is a next element, in which case key and item
333 * will contain the next element's key and value respectively.
334 * If there is no next element available it will return False and in this
335 * case key and item will be undefined.
337 Bool WMNextHashEnumeratorItemAndKey(WMHashEnumerator *enumerator,
338 void **item, void **key);
343 /* some predefined callback sets */
345 extern const WMHashTableCallbacks WMIntHashCallbacks;
346 /* sizeof(keys) are <= sizeof(void*) */
348 extern const WMHashTableCallbacks WMStringHashCallbacks;
349 /* keys are strings. Strings will be copied with wstrdup()
350 * and freed with wfree() */
352 extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
353 /* keys are strings, but they are not copied */
356 /* ---[ WINGs/array.c ]--------------------------------------------------- */
359 * WMArray use an array to store the elements.
360 * Item indexes may be only positive integer numbers.
361 * The array cannot contain holes in it.
363 * Pros:
364 * Fast [O(1)] access to elements
365 * Fast [O(1)] push/pop
367 * Cons:
368 * A little slower [O(n)] for insertion/deletion of elements that
369 * aren't in the end
372 WMArray* WMCreateArray(int initialSize);
374 WMArray* WMCreateArrayWithDestructor(int initialSize, WMFreeDataProc *destructor);
376 WMArray* WMCreateArrayWithArray(WMArray *array);
378 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
380 void WMEmptyArray(WMArray *array);
382 void WMFreeArray(WMArray *array);
384 int WMGetArrayItemCount(WMArray *array);
386 /* appends other to array. other remains unchanged */
387 void WMAppendArray(WMArray *array, WMArray *other);
389 /* add will place the element at the end of the array */
390 void WMAddToArray(WMArray *array, void *item);
392 /* insert will increment the index of elements after it by 1 */
393 void WMInsertInArray(WMArray *array, int index, void *item);
395 /* replace and set will return the old item WITHOUT calling the
396 * destructor on it even if its available. Free the returned item yourself.
398 void* WMReplaceInArray(WMArray *array, int index, void *item);
400 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
402 /* delete and remove will remove the elements and cause the elements
403 * after them to decrement their indexes by 1. Also will call the
404 * destructor on the deleted element if there's one available.
406 int WMDeleteFromArray(WMArray *array, int index);
408 #define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
410 int WMRemoveFromArrayMatching(WMArray *array, WMMatchDataProc *match, void *cdata);
412 void* WMGetFromArray(WMArray *array, int index);
414 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
416 /* pop will return the last element from the array, also removing it
417 * from the array. The destructor is NOT called, even if available.
418 * Free the returned element if needed by yourself
420 void* WMPopFromArray(WMArray *array);
422 int WMFindInArray(WMArray *array, WMMatchDataProc *match, void *cdata);
424 int WMCountInArray(WMArray *array, void *item);
426 /* comparer must return:
427 * < 0 if a < b
428 * > 0 if a > b
429 * = 0 if a = b
431 void WMSortArray(WMArray *array, WMCompareDataProc *comparer);
433 void WMMapArray(WMArray *array, void (*function)(void*, void*), void *data);
435 WMArray* WMGetSubarrayWithRange(WMArray* array, WMRange aRange);
437 void* WMArrayFirst(WMArray *array, WMArrayIterator *iter);
439 void* WMArrayLast(WMArray *array, WMArrayIterator *iter);
441 /* The following 2 functions assume that the array doesn't change between calls */
442 void* WMArrayNext(WMArray *array, WMArrayIterator *iter);
444 void* WMArrayPrevious(WMArray *array, WMArrayIterator *iter);
447 /* The following 2 macros assume that the array doesn't change in the for loop */
448 #define WM_ITERATE_ARRAY(array, var, i) \
449 for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
450 var = WMArrayNext(array, &(i)))
452 #define WM_ETARETI_ARRAY(array, var, i) \
453 for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
454 var = WMArrayPrevious(array, &(i)))
456 /* ---[ WINGs/bagtree.c ]------------------------------------------------- */
459 * Tree bags use a red-black tree for storage.
460 * Item indexes may be any integer number.
462 * Pros:
463 * O(lg n) insertion/deletion/search
464 * Good for large numbers of elements with sparse indexes
466 * Cons:
467 * O(lg n) insertion/deletion/search
468 * Slow for storing small numbers of elements
471 #define WMCreateBag(size) WMCreateTreeBag()
473 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
475 WMBag* WMCreateTreeBag(void);
477 WMBag* WMCreateTreeBagWithDestructor(WMFreeDataProc *destructor);
479 int WMGetBagItemCount(WMBag *bag);
481 void WMAppendBag(WMBag *bag, WMBag *other);
483 void WMPutInBag(WMBag *bag, void *item);
485 /* insert will increment the index of elements after it by 1 */
486 void WMInsertInBag(WMBag *bag, int index, void *item);
488 /* erase will remove the element from the bag,
489 * but will keep the index of the other elements unchanged */
490 int WMEraseFromBag(WMBag *bag, int index);
492 /* delete and remove will remove the elements and cause the elements
493 * after them to decrement their indexes by 1 */
494 int WMDeleteFromBag(WMBag *bag, int index);
496 int WMRemoveFromBag(WMBag *bag, void *item);
498 void* WMGetFromBag(WMBag *bag, int index);
500 void* WMReplaceInBag(WMBag *bag, int index, void *item);
502 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
504 /* comparer must return:
505 * < 0 if a < b
506 * > 0 if a > b
507 * = 0 if a = b
509 void WMSortBag(WMBag *bag, WMCompareDataProc *comparer);
511 void WMEmptyBag(WMBag *bag);
513 void WMFreeBag(WMBag *bag);
515 void WMMapBag(WMBag *bag, void (*function)(void*, void*), void *data);
517 int WMGetFirstInBag(WMBag *bag, void *item);
519 int WMCountInBag(WMBag *bag, void *item);
521 int WMFindInBag(WMBag *bag, WMMatchDataProc *match, void *cdata);
523 void* WMBagFirst(WMBag *bag, WMBagIterator *ptr);
525 void* WMBagLast(WMBag *bag, WMBagIterator *ptr);
527 /* The following 4 functions assume that the bag doesn't change between calls */
528 void* WMBagNext(WMBag *bag, WMBagIterator *ptr);
530 void* WMBagPrevious(WMBag *bag, WMBagIterator *ptr);
532 void* WMBagIteratorAtIndex(WMBag *bag, int index, WMBagIterator *ptr);
534 int WMBagIndexForIterator(WMBag *bag, WMBagIterator ptr);
537 /* The following 2 macros assume that the bag doesn't change in the for loop */
538 #define WM_ITERATE_BAG(bag, var, i) \
539 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
540 var = WMBagNext(bag, &(i)))
542 #define WM_ETARETI_BAG(bag, var, i) \
543 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
544 var = WMBagPrevious(bag, &(i)))
548 /* ---[ WINGs/data.c ]---------------------------------------------------- */
550 /* WMData handling */
552 /* Creating/destroying data */
554 WMData* WMCreateDataWithCapacity(unsigned capacity);
556 WMData* WMCreateDataWithLength(unsigned length);
558 WMData* WMCreateDataWithBytes(const void *bytes, unsigned length);
560 /* destructor is a function called to free the data when releasing the data
561 * object, or NULL if no freeing of data is necesary. */
562 WMData* WMCreateDataWithBytesNoCopy(void *bytes, unsigned length,
563 WMFreeDataProc *destructor);
565 WMData* WMCreateDataWithData(WMData *aData);
567 WMData* WMRetainData(WMData *aData);
569 void WMReleaseData(WMData *aData);
571 /* Adjusting capacity */
573 void WMSetDataCapacity(WMData *aData, unsigned capacity);
575 void WMSetDataLength(WMData *aData, unsigned length);
577 void WMIncreaseDataLengthBy(WMData *aData, unsigned extraLength);
579 /* Accessing data */
581 const void* WMDataBytes(WMData *aData);
583 void WMGetDataBytes(WMData *aData, void *buffer);
585 void WMGetDataBytesWithLength(WMData *aData, void *buffer, unsigned length);
587 void WMGetDataBytesWithRange(WMData *aData, void *buffer, WMRange aRange);
589 WMData* WMGetSubdataWithRange(WMData *aData, WMRange aRange);
591 /* Testing data */
593 Bool WMIsDataEqualToData(WMData *aData, WMData *anotherData);
595 unsigned WMGetDataLength(WMData *aData);
597 /* Adding data */
599 void WMAppendDataBytes(WMData *aData, const void *bytes, unsigned length);
601 void WMAppendData(WMData *aData, WMData *anotherData);
603 /* Modifying data */
605 void WMReplaceDataBytesInRange(WMData *aData, WMRange aRange, const void *bytes);
607 void WMResetDataBytesInRange(WMData *aData, WMRange aRange);
609 void WMSetData(WMData *aData, WMData *anotherData);
612 void WMSetDataFormat(WMData *aData, unsigned format);
614 unsigned WMGetDataFormat(WMData *aData);
615 /* Storing data */
617 /* ---[ WINGs/tree.c ]---------------------------------------------------- */
619 /* Generic Tree and TreeNode */
621 WMTreeNode* WMCreateTreeNode(void *data);
623 WMTreeNode* WMCreateTreeNodeWithDestructor(void *data, WMFreeDataProc *destructor);
625 WMTreeNode* WMInsertItemInTree(WMTreeNode *parent, int index, void *item);
627 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
629 WMTreeNode* WMInsertNodeInTree(WMTreeNode *parent, int index, WMTreeNode *aNode);
631 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
633 void WMDestroyTreeNode(WMTreeNode *aNode);
635 void WMDeleteLeafForTreeNode(WMTreeNode *aNode, int index);
637 void WMRemoveLeafForTreeNode(WMTreeNode *aNode, void *leaf);
639 void* WMReplaceDataForTreeNode(WMTreeNode *aNode, void *newData);
641 void* WMGetDataForTreeNode(WMTreeNode *aNode);
643 int WMGetTreeNodeDepth(WMTreeNode *aNode);
645 WMTreeNode* WMGetParentForTreeNode(WMTreeNode *aNode);
647 /* Sort only the leaves of the passed node */
648 void WMSortLeavesForTreeNode(WMTreeNode *aNode, WMCompareDataProc *comparer);
650 /* Sort all tree recursively starting from the passed node */
651 void WMSortTree(WMTreeNode *aNode, WMCompareDataProc *comparer);
653 /* Returns the first node which matches node's data with cdata by 'match' */
654 WMTreeNode* WMFindInTree(WMTreeNode *aTree, WMMatchDataProc *match, void *cdata);
656 /* Returns the first node where node's data matches cdata by 'match' and node is
657 * at most `limit' depths down from `aTree'. */
658 WMTreeNode *WMFindInTreeWithDepthLimit(WMTreeNode * aTree, WMMatchDataProc * match, void *cdata, int limit);
660 /* Returns first tree node that has data == cdata */
661 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(aTree, NULL, cdata)
663 /* Walk every node of aNode with `walk' */
664 void WMTreeWalk(WMTreeNode *aNode, WMTreeWalkProc * walk, void *data, Bool DepthFirst);
666 /* ---[ WINGs/data.c ]---------------------------------------------------- */
669 WMNotification* WMCreateNotification(const char *name, void *object, void *clientData);
671 void WMReleaseNotification(WMNotification *notification);
673 WMNotification* WMRetainNotification(WMNotification *notification);
675 void* WMGetNotificationClientData(WMNotification *notification);
677 void* WMGetNotificationObject(WMNotification *notification);
679 const char* WMGetNotificationName(WMNotification *notification);
682 void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
683 void *observer, const char *name, void *object);
685 void WMPostNotification(WMNotification *notification);
687 void WMRemoveNotificationObserver(void *observer);
689 void WMRemoveNotificationObserverWithName(void *observer, const char *name,
690 void *object);
692 void WMPostNotificationName(const char *name, void *object, void *clientData);
694 WMNotificationQueue* WMGetDefaultNotificationQueue(void);
696 WMNotificationQueue* WMCreateNotificationQueue(void);
698 void WMDequeueNotificationMatching(WMNotificationQueue *queue,
699 WMNotification *notification,
700 unsigned mask);
702 void WMEnqueueNotification(WMNotificationQueue *queue,
703 WMNotification *notification,
704 WMPostingStyle postingStyle);
706 void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
707 WMNotification *notification,
708 WMPostingStyle postingStyle,
709 unsigned coalesceMask);
712 /* ---[ WINGs/proplist.c ]------------------------------------------------ */
714 /* Property Lists handling */
716 void WMPLSetCaseSensitive(Bool caseSensitive);
718 WMPropList* WMCreatePLString(const char *str);
720 WMPropList* WMCreatePLData(WMData *data);
722 WMPropList* WMCreatePLDataWithBytes(const unsigned char *bytes, unsigned int length);
724 WMPropList* WMCreatePLDataWithBytesNoCopy(unsigned char *bytes,
725 unsigned int length,
726 WMFreeDataProc *destructor);
728 WMPropList* WMCreatePLArray(WMPropList *elem, ...);
730 WMPropList* WMCreatePLDictionary(WMPropList *key, WMPropList *value, ...);
732 WMPropList* WMRetainPropList(WMPropList *plist);
734 void WMReleasePropList(WMPropList *plist);
736 /* Objects inserted in arrays and dictionaries will be retained,
737 * so you can safely release them after insertion.
738 * For dictionaries both the key and value are retained.
739 * Objects removed from arrays or dictionaries are released */
740 void WMInsertInPLArray(WMPropList *plist, int index, WMPropList *item);
742 void WMAddToPLArray(WMPropList *plist, WMPropList *item);
744 void WMDeleteFromPLArray(WMPropList *plist, int index);
746 void WMRemoveFromPLArray(WMPropList *plist, WMPropList *item);
748 void WMPutInPLDictionary(WMPropList *plist, WMPropList *key, WMPropList *value);
750 void WMRemoveFromPLDictionary(WMPropList *plist, WMPropList *key);
752 /* It will insert all key/value pairs from source into dest, overwriting
753 * the values with the same keys from dest, keeping all values with keys
754 * only present in dest unchanged */
755 WMPropList* WMMergePLDictionaries(WMPropList *dest, WMPropList *source,
756 Bool recursive);
758 /* It will remove all key/value pairs from dest for which there is an
759 * identical key/value present in source. Entires only present in dest, or
760 * which have different values in dest than in source will be preserved. */
761 WMPropList* WMSubtractPLDictionaries(WMPropList *dest, WMPropList *source,
762 Bool recursive);
764 int WMGetPropListItemCount(WMPropList *plist);
766 Bool WMIsPLString(WMPropList *plist);
768 Bool WMIsPLData(WMPropList *plist);
770 Bool WMIsPLArray(WMPropList *plist);
772 Bool WMIsPLDictionary(WMPropList *plist);
774 Bool WMIsPropListEqualTo(WMPropList *plist, WMPropList *other);
776 /* Returns a reference. Do not free it! */
777 char* WMGetFromPLString(WMPropList *plist);
779 /* Returns a reference. Do not free it! */
780 WMData* WMGetFromPLData(WMPropList *plist);
782 /* Returns a reference. Do not free it! */
783 const unsigned char* WMGetPLDataBytes(WMPropList *plist);
785 int WMGetPLDataLength(WMPropList *plist);
787 /* Returns a reference. */
788 WMPropList* WMGetFromPLArray(WMPropList *plist, int index);
790 /* Returns a reference. */
791 WMPropList* WMGetFromPLDictionary(WMPropList *plist, WMPropList *key);
793 /* Returns a PropList array with all the dictionary keys. Release it when
794 * you're done. Keys in array are retained from the original dictionary
795 * not copied and need NOT to be released individually. */
796 WMPropList* WMGetPLDictionaryKeys(WMPropList *plist);
798 /* Creates only the first level deep object. All the elements inside are
799 * retained from the original */
800 WMPropList* WMShallowCopyPropList(WMPropList *plist);
802 /* Makes a completely separate replica of the original proplist */
803 WMPropList* WMDeepCopyPropList(WMPropList *plist);
805 WMPropList* WMCreatePropListFromDescription(char *desc);
807 /* Free the returned string when you no longer need it */
808 char* WMGetPropListDescription(WMPropList *plist, Bool indented);
810 WMPropList* WMReadPropListFromFile(const char *file);
812 WMPropList* WMReadPropListFromPipe(const char *command);
814 Bool WMWritePropListToFile(WMPropList *plist, const char *path);
816 /* ---[ WINGs/userdefaults.c ]-------------------------------------------- */
818 /* don't free the returned string */
819 char* wusergnusteppath(void);
821 /* Free the returned string when you no longer need it */
822 char* wdefaultspathfordomain(const char *domain);
824 /* Free the returned string when you no longer need it */
825 char* wglobaldefaultspathfordomain(const char *domain);
827 WMUserDefaults* WMGetStandardUserDefaults(void);
829 WMUserDefaults* WMGetDefaultsFromPath(const char *path);
831 void WMSynchronizeUserDefaults(WMUserDefaults *database);
833 void WMSaveUserDefaults(WMUserDefaults *database);
835 void WMEnableUDPeriodicSynchronization(WMUserDefaults *database, Bool enable);
837 /* Returns a WMPropList array with all the keys in the user defaults database.
838 * Free the array with WMReleasePropList() when no longer needed.
839 * Keys in array are just retained references to the original keys */
840 WMPropList* WMGetUDKeys(WMUserDefaults *database);
842 WMPropList* WMGetUDObjectForKey(WMUserDefaults *database, const char *defaultName);
844 void WMSetUDObjectForKey(WMUserDefaults *database, WMPropList *object,
845 const char *defaultName);
847 void WMRemoveUDObjectForKey(WMUserDefaults *database, const char *defaultName);
849 /* Returns a reference. Do not free it! */
850 char* WMGetUDStringForKey(WMUserDefaults *database, const char *defaultName);
852 int WMGetUDIntegerForKey(WMUserDefaults *database, const char *defaultName);
854 float WMGetUDFloatForKey(WMUserDefaults *database, const char *defaultName);
856 Bool WMGetUDBoolForKey(WMUserDefaults *database, const char *defaultName);
858 void WMSetUDStringForKey(WMUserDefaults *database, const char *value,
859 const char *defaultName);
861 void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
862 const char *defaultName);
864 void WMSetUDFloatForKey(WMUserDefaults *database, float value,
865 const char *defaultName);
867 void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
868 const char *defaultName);
870 WMPropList* WMGetUDSearchList(WMUserDefaults *database);
872 void WMSetUDSearchList(WMUserDefaults *database, WMPropList *list);
874 extern char *WMUserDefaultsDidChangeNotification;
877 /* ---[ WINGs/menuparser.c ]---------------------------------------------- */
880 typedef struct w_menu_parser *WMenuParser;
883 WMenuParser WMenuParserCreate(const char *file_name, void *file, const char *include_default_paths);
885 void WMenuParserRegisterSimpleMacro(WMenuParser parser, const char *name, const char *value);
887 void WMenuParserError(WMenuParser parser, const char *msg, ...)
888 __attribute__ ((format (printf, 2, 3)));
890 const char *WMenuParserGetFilename(WMenuParser parser);
892 Bool WMenuParserGetLine(WMenuParser parser, char **title, char **command, char **parameter, char **shortcut);
894 void WMenuParserDelete(WMenuParser parser);
897 /*-------------------------------------------------------------------------*/
899 /* Global variables */
901 extern int WCErrorCode;
904 /*-------------------------------------------------------------------------*/
906 #ifdef __cplusplus
908 #endif /* __cplusplus */
911 #endif