3 * Copyright (c) 1998 scottc
4 * Copyright (c) 1999-2004 Dan Pascu
5 * Copyright (c) 1999-2000 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <sys/types.h>
29 /* SunOS 4.x Blargh.... */
31 #define NULL ((void*)0)
36 # define WMAX(a,b) ((a)>(b) ? (a) : (b))
39 # define WMIN(a,b) ((a)<(b) ? (a) : (b))
43 #ifndef __ASSERT_FUNCTION
44 # if (!defined (__GNUC__) || (__GNUC__ < 2 && \
45 __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4)))
46 # define __ASSERT_FUNCTION ((char *) 0)
48 # define __ASSERT_FUNCTION __PRETTY_FUNCTION__
53 #define __attribute__(x) /*NOTHING*/
58 #define wassertr(expr) {}
59 #define wassertrv(expr, val) {}
67 #define wassertr(expr) assert(expr)
69 #define wassertrv(expr, val) assert(expr)
73 #define wassertr(expr) \
75 wwarning("%s line %i (%s): assertion %s failed",\
76 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
80 #define wassertrv(expr, val) \
82 wwarning("%s line %i (%s): assertion %s failed",\
83 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
92 # define _wutil_static_assert(check, message) static_assert(check, message)
94 # ifdef __STDC_VERSION__
95 # if __STDC_VERSION__ >= 201112L
97 * Ideally, we would like to include <assert.h> to have 'static_assert'
98 * properly defined, but as we have to be sure about portability and
99 * because we're a public header we can't count on 'configure' to tell
100 * us about availability, so we use the raw C11 keyword
102 # define _wutil_static_assert(check, message) _Static_assert(check, message)
104 # define _wutil_static_assert(check, message) /**/
107 # define _wutil_static_assert(check, message) /**/
114 #endif /* __cplusplus */
128 } WMNotificationCoalescing
;
133 WBNotFound
= INT_MIN
, /* element was not found in WMBag */
134 WANotFound
= -1 /* element was not found in WMArray */
138 typedef struct W_Array WMArray
;
139 typedef struct W_Bag WMBag
;
140 typedef struct W_Data WMData
;
141 typedef struct W_TreeNode WMTreeNode
;
142 typedef struct W_HashTable WMHashTable
;
143 typedef struct W_UserDefaults WMUserDefaults
;
144 typedef struct W_Notification WMNotification
;
145 typedef struct W_NotificationQueue WMNotificationQueue
;
146 typedef struct W_Host WMHost
;
147 typedef struct W_Connection WMConnection
;
148 typedef struct W_PropList WMPropList
;
152 /* Some typedefs for the handler stuff */
153 typedef void *WMHandlerID
;
155 typedef void WMCallback(void *data
);
157 typedef void WMInputProc(int fd
, int mask
, void *clientData
);
161 typedef int WMCompareDataProc(const void *item1
, const void *item2
);
162 typedef void WMTreeWalkProc(WMTreeNode
*aNode
, void *data
);
164 typedef void WMFreeDataProc(void *data
);
166 /* Used by WMBag or WMArray for matching data */
167 typedef int WMMatchDataProc(const void *item
, const void *cdata
);
178 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
187 /* NULL is pointer hash */
188 unsigned (*hash
)(const void *);
189 /* NULL is pointer compare */
190 Bool (*keyIsEqual
)(const void *, const void *);
191 /* NULL does nothing */
192 void* (*retainKey
)(const void *);
193 /* NULL does nothing */
194 void (*releaseKey
)(const void *);
195 } WMHashTableCallbacks
;
198 typedef int WMArrayIterator
;
199 typedef void *WMBagIterator
;
202 typedef void WMNotificationObserverAction(void *observerData
,
203 WMNotification
*notification
);
206 /* ---[ Macros ]---------------------------------------------------------- */
208 #define wlengthof(array) \
210 _wutil_static_assert(sizeof(array) > sizeof(array[0]), \
211 "the macro 'wlengthof' cannot be used on pointers, only on known size arrays"); \
212 sizeof(array) / sizeof(array[0]); \
216 /* ---[ WINGs/memory.c ]-------------------------------------------------- */
218 void* wmalloc(size_t size
);
219 void* wrealloc(void *ptr
, size_t newsize
);
220 void wfree(void *ptr
);
222 void wrelease(void *ptr
);
223 void* wretain(void *ptr
);
225 typedef void waborthandler(int);
227 waborthandler
* wsetabort(waborthandler
* handler
);
229 /* ---[ WINGs/error.c ]--------------------------------------------------- */
232 WMESSAGE_TYPE_MESSAGE
,
233 WMESSAGE_TYPE_WARNING
,
238 #define wmessage(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_MESSAGE, fmt, ## args)
239 #define wwarning(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_WARNING, fmt, ## args)
240 #define werror(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_ERROR, fmt, ## args)
241 #define wfatal(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_FATAL, fmt, ## args)
243 void __wmessage(const char *func
, const char *file
, int line
, int type
, const char *msg
, ...)
244 __attribute__((__format__(printf
,5,6)));
246 /* ---[ WINGs/findfile.c ]------------------------------------------------ */
248 /* For the 4 function below, you have to free the returned string when you no longer need it */
250 char* wfindfile(const char *paths
, const char *file
);
252 char* wfindfileinlist(char *const *path_list
, const char *file
);
254 char* wfindfileinarray(WMPropList
* array
, const char *file
);
256 char* wexpandpath(const char *path
);
258 int wcopy_file(const char *toPath
, const char *srcFile
, const char *destFile
);
260 /* don't free the returned string */
261 char* wgethomedir(void);
263 /* ---[ WINGs/proplist.c ]------------------------------------------------ */
265 int wmkdirhier(const char *path
);
266 int wrmdirhier(const char *path
);
268 /* ---[ WINGs/string.c ]-------------------------------------------------- */
270 char *wstrdup(const char *str
);
271 char* wstrndup(const char *str
, size_t len
);
273 /* Concatenate str1 with str2 and return that in a newly malloc'ed string.
274 * str1 and str2 can be any strings including static and constant strings.
275 * str1 and str2 will not be modified.
276 * Free the returned string when you're done with it. */
277 char* wstrconcat(const char *str1
, const char *str2
);
279 /* This will append src to dst, and return dst. dst MUST be either NULL
280 * or a string that was a result of a dynamic allocation (malloc, realloc
281 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
282 * Modifies dst (no new string is created except if dst==NULL in which case
283 * it is equivalent to calling wstrdup(src) ).
284 * The returned address may be different from the original address of dst,
285 * so always assign the returned address to avoid dangling pointers. */
286 char* wstrappend(char *dst
, const char *src
);
288 size_t wstrlcpy(char *, const char *, size_t);
289 size_t wstrlcat(char *, const char *, size_t);
292 void wtokensplit(char *command
, char ***argv
, int *argc
);
294 char* wtokennext(char *word
, char **next
);
296 char* wtokenjoin(char **list
, int count
);
298 void wtokenfree(char **tokens
, int count
);
300 char* wtrimspace(const char *s
);
302 /* transform `s' so that the result is safe to pass to the shell as an argument.
303 * returns a newly allocated string.
304 * with very heavy inspirations from NetBSD's shquote(3).
306 char *wshellquote(const char *s
);
308 /* ---[ WINGs/misc.c ]--------------------------------------------------- */
310 WMRange
wmkrange(int start
, int count
);
312 /* An application must call this function before exiting, to let WUtil do some internal cleanup */
313 void wutil_shutdown(void);
316 /* ---[ WINGs/usleep.c ]-------------------------------------------------- */
318 void wusleep(unsigned int usec
);
320 /* ---[ WINGs/handlers.c ]------------------------------------------------ */
322 /* Event handlers: timer, idle, input */
324 WMHandlerID
WMAddTimerHandler(int milliseconds
, WMCallback
*callback
,
327 WMHandlerID
WMAddPersistentTimerHandler(int milliseconds
, WMCallback
*callback
,
330 void WMDeleteTimerWithClientData(void *cdata
);
332 void WMDeleteTimerHandler(WMHandlerID handlerID
);
334 WMHandlerID
WMAddIdleHandler(WMCallback
*callback
, void *cdata
);
336 void WMDeleteIdleHandler(WMHandlerID handlerID
);
338 WMHandlerID
WMAddInputHandler(int fd
, int condition
, WMInputProc
*proc
,
341 void WMDeleteInputHandler(WMHandlerID handlerID
);
344 /* This function is used _only_ if you create a non-GUI program.
345 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
346 * This function will handle all input/timer/idle events, then return.
349 void WHandleEvents(void);
351 /* ---[ WINGs/hashtable.c ]----------------------------------------------- */
354 WMHashTable
* WMCreateHashTable(const WMHashTableCallbacks callbacks
);
356 void WMFreeHashTable(WMHashTable
*table
);
358 void WMResetHashTable(WMHashTable
*table
);
360 unsigned WMCountHashTable(WMHashTable
*table
);
362 void* WMHashGet(WMHashTable
*table
, const void *key
);
364 /* Returns True if there is a value associated with <key> in the table, in
365 * which case <retKey> and <retItem> will contain the item's internal key
366 * address and the item's value respectively.
367 * If there is no value associated with <key> it will return False and in
368 * this case <retKey> and <retItem> will be undefined.
369 * Use this when you need to perform your own custom retain/release mechanism
370 * which requires access to the keys too.
372 Bool
WMHashGetItemAndKey(WMHashTable
*table
, const void *key
,
373 void **retItem
, void **retKey
);
375 /* put data in table, replacing already existing data and returning
377 void* WMHashInsert(WMHashTable
*table
, const void *key
, const void *data
);
379 void WMHashRemove(WMHashTable
*table
, const void *key
);
381 /* warning: do not manipulate the table while using the enumerator functions */
382 WMHashEnumerator
WMEnumerateHashTable(WMHashTable
*table
);
384 void* WMNextHashEnumeratorItem(WMHashEnumerator
*enumerator
);
386 void* WMNextHashEnumeratorKey(WMHashEnumerator
*enumerator
);
388 /* Returns True if there is a next element, in which case key and item
389 * will contain the next element's key and value respectively.
390 * If there is no next element available it will return False and in this
391 * case key and item will be undefined.
393 Bool
WMNextHashEnumeratorItemAndKey(WMHashEnumerator
*enumerator
,
394 void **item
, void **key
);
399 /* some predefined callback sets */
401 extern const WMHashTableCallbacks WMIntHashCallbacks
;
402 /* sizeof(keys) are <= sizeof(void*) */
404 extern const WMHashTableCallbacks WMStringHashCallbacks
;
405 /* keys are strings. Strings will be copied with wstrdup()
406 * and freed with wfree() */
408 extern const WMHashTableCallbacks WMStringPointerHashCallbacks
;
409 /* keys are strings, but they are not copied */
412 /* ---[ WINGs/array.c ]--------------------------------------------------- */
415 * WMArray use an array to store the elements.
416 * Item indexes may be only positive integer numbers.
417 * The array cannot contain holes in it.
420 * Fast [O(1)] access to elements
421 * Fast [O(1)] push/pop
424 * A little slower [O(n)] for insertion/deletion of elements that
428 WMArray
* WMCreateArray(int initialSize
);
430 WMArray
* WMCreateArrayWithDestructor(int initialSize
, WMFreeDataProc
*destructor
);
432 WMArray
* WMCreateArrayWithArray(WMArray
*array
);
434 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
436 void WMEmptyArray(WMArray
*array
);
438 void WMFreeArray(WMArray
*array
);
440 int WMGetArrayItemCount(WMArray
*array
);
442 /* appends other to array. other remains unchanged */
443 void WMAppendArray(WMArray
*array
, WMArray
*other
);
445 /* add will place the element at the end of the array */
446 void WMAddToArray(WMArray
*array
, void *item
);
448 /* insert will increment the index of elements after it by 1 */
449 void WMInsertInArray(WMArray
*array
, int index
, void *item
);
451 /* replace and set will return the old item WITHOUT calling the
452 * destructor on it even if its available. Free the returned item yourself.
454 void* WMReplaceInArray(WMArray
*array
, int index
, void *item
);
456 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
458 /* delete and remove will remove the elements and cause the elements
459 * after them to decrement their indexes by 1. Also will call the
460 * destructor on the deleted element if there's one available.
462 int WMDeleteFromArray(WMArray
*array
, int index
);
464 #define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
466 int WMRemoveFromArrayMatching(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
468 void* WMGetFromArray(WMArray
*array
, int index
);
470 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
472 /* pop will return the last element from the array, also removing it
473 * from the array. The destructor is NOT called, even if available.
474 * Free the returned element if needed by yourself
476 void* WMPopFromArray(WMArray
*array
);
478 int WMFindInArray(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
480 int WMCountInArray(WMArray
*array
, void *item
);
482 /* comparer must return:
487 void WMSortArray(WMArray
*array
, WMCompareDataProc
*comparer
);
489 void WMMapArray(WMArray
*array
, void (*function
)(void*, void*), void *data
);
491 WMArray
* WMGetSubarrayWithRange(WMArray
* array
, WMRange aRange
);
493 void* WMArrayFirst(WMArray
*array
, WMArrayIterator
*iter
);
495 void* WMArrayLast(WMArray
*array
, WMArrayIterator
*iter
);
497 /* The following 2 functions assume that the array doesn't change between calls */
498 void* WMArrayNext(WMArray
*array
, WMArrayIterator
*iter
);
500 void* WMArrayPrevious(WMArray
*array
, WMArrayIterator
*iter
);
503 /* The following 2 macros assume that the array doesn't change in the for loop */
504 #define WM_ITERATE_ARRAY(array, var, i) \
505 for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
506 var = WMArrayNext(array, &(i)))
508 #define WM_ETARETI_ARRAY(array, var, i) \
509 for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
510 var = WMArrayPrevious(array, &(i)))
512 /* ---[ WINGs/bagtree.c ]------------------------------------------------- */
515 * Tree bags use a red-black tree for storage.
516 * Item indexes may be any integer number.
519 * O(lg n) insertion/deletion/search
520 * Good for large numbers of elements with sparse indexes
523 * O(lg n) insertion/deletion/search
524 * Slow for storing small numbers of elements
527 #define WMCreateBag(size) WMCreateTreeBag()
529 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
531 WMBag
* WMCreateTreeBag(void);
533 WMBag
* WMCreateTreeBagWithDestructor(WMFreeDataProc
*destructor
);
535 int WMGetBagItemCount(WMBag
*bag
);
537 void WMAppendBag(WMBag
*bag
, WMBag
*other
);
539 void WMPutInBag(WMBag
*bag
, void *item
);
541 /* insert will increment the index of elements after it by 1 */
542 void WMInsertInBag(WMBag
*bag
, int index
, void *item
);
544 /* erase will remove the element from the bag,
545 * but will keep the index of the other elements unchanged */
546 int WMEraseFromBag(WMBag
*bag
, int index
);
548 /* delete and remove will remove the elements and cause the elements
549 * after them to decrement their indexes by 1 */
550 int WMDeleteFromBag(WMBag
*bag
, int index
);
552 int WMRemoveFromBag(WMBag
*bag
, void *item
);
554 void* WMGetFromBag(WMBag
*bag
, int index
);
556 void* WMReplaceInBag(WMBag
*bag
, int index
, void *item
);
558 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
560 /* comparer must return:
565 void WMSortBag(WMBag
*bag
, WMCompareDataProc
*comparer
);
567 void WMEmptyBag(WMBag
*bag
);
569 void WMFreeBag(WMBag
*bag
);
571 void WMMapBag(WMBag
*bag
, void (*function
)(void*, void*), void *data
);
573 int WMGetFirstInBag(WMBag
*bag
, void *item
);
575 int WMCountInBag(WMBag
*bag
, void *item
);
577 int WMFindInBag(WMBag
*bag
, WMMatchDataProc
*match
, void *cdata
);
579 void* WMBagFirst(WMBag
*bag
, WMBagIterator
*ptr
);
581 void* WMBagLast(WMBag
*bag
, WMBagIterator
*ptr
);
583 /* The following 4 functions assume that the bag doesn't change between calls */
584 void* WMBagNext(WMBag
*bag
, WMBagIterator
*ptr
);
586 void* WMBagPrevious(WMBag
*bag
, WMBagIterator
*ptr
);
588 void* WMBagIteratorAtIndex(WMBag
*bag
, int index
, WMBagIterator
*ptr
);
590 int WMBagIndexForIterator(WMBag
*bag
, WMBagIterator ptr
);
593 /* The following 2 macros assume that the bag doesn't change in the for loop */
594 #define WM_ITERATE_BAG(bag, var, i) \
595 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
596 var = WMBagNext(bag, &(i)))
598 #define WM_ETARETI_BAG(bag, var, i) \
599 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
600 var = WMBagPrevious(bag, &(i)))
604 /* ---[ WINGs/data.c ]---------------------------------------------------- */
606 /* WMData handling */
608 /* Creating/destroying data */
610 WMData
* WMCreateDataWithCapacity(unsigned capacity
);
612 WMData
* WMCreateDataWithLength(unsigned length
);
614 WMData
* WMCreateDataWithBytes(const void *bytes
, unsigned length
);
616 /* destructor is a function called to free the data when releasing the data
617 * object, or NULL if no freeing of data is necesary. */
618 WMData
* WMCreateDataWithBytesNoCopy(void *bytes
, unsigned length
,
619 WMFreeDataProc
*destructor
);
621 WMData
* WMCreateDataWithData(WMData
*aData
);
623 WMData
* WMRetainData(WMData
*aData
);
625 void WMReleaseData(WMData
*aData
);
627 /* Adjusting capacity */
629 void WMSetDataCapacity(WMData
*aData
, unsigned capacity
);
631 void WMSetDataLength(WMData
*aData
, unsigned length
);
633 void WMIncreaseDataLengthBy(WMData
*aData
, unsigned extraLength
);
637 const void* WMDataBytes(WMData
*aData
);
639 void WMGetDataBytes(WMData
*aData
, void *buffer
);
641 void WMGetDataBytesWithLength(WMData
*aData
, void *buffer
, unsigned length
);
643 void WMGetDataBytesWithRange(WMData
*aData
, void *buffer
, WMRange aRange
);
645 WMData
* WMGetSubdataWithRange(WMData
*aData
, WMRange aRange
);
649 Bool
WMIsDataEqualToData(WMData
*aData
, WMData
*anotherData
);
651 unsigned WMGetDataLength(WMData
*aData
);
655 void WMAppendDataBytes(WMData
*aData
, const void *bytes
, unsigned length
);
657 void WMAppendData(WMData
*aData
, WMData
*anotherData
);
661 void WMReplaceDataBytesInRange(WMData
*aData
, WMRange aRange
, const void *bytes
);
663 void WMResetDataBytesInRange(WMData
*aData
, WMRange aRange
);
665 void WMSetData(WMData
*aData
, WMData
*anotherData
);
668 void WMSetDataFormat(WMData
*aData
, unsigned format
);
670 unsigned WMGetDataFormat(WMData
*aData
);
673 /* ---[ WINGs/tree.c ]---------------------------------------------------- */
675 /* Generic Tree and TreeNode */
677 WMTreeNode
* WMCreateTreeNode(void *data
);
679 WMTreeNode
* WMCreateTreeNodeWithDestructor(void *data
, WMFreeDataProc
*destructor
);
681 WMTreeNode
* WMInsertItemInTree(WMTreeNode
*parent
, int index
, void *item
);
683 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
685 WMTreeNode
* WMInsertNodeInTree(WMTreeNode
*parent
, int index
, WMTreeNode
*aNode
);
687 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
689 void WMDestroyTreeNode(WMTreeNode
*aNode
);
691 void WMDeleteLeafForTreeNode(WMTreeNode
*aNode
, int index
);
693 void WMRemoveLeafForTreeNode(WMTreeNode
*aNode
, void *leaf
);
695 void* WMReplaceDataForTreeNode(WMTreeNode
*aNode
, void *newData
);
697 void* WMGetDataForTreeNode(WMTreeNode
*aNode
);
699 int WMGetTreeNodeDepth(WMTreeNode
*aNode
);
701 WMTreeNode
* WMGetParentForTreeNode(WMTreeNode
*aNode
);
703 /* Sort only the leaves of the passed node */
704 void WMSortLeavesForTreeNode(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
706 /* Sort all tree recursively starting from the passed node */
707 void WMSortTree(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
709 /* Returns the first node which matches node's data with cdata by 'match' */
710 WMTreeNode
* WMFindInTree(WMTreeNode
*aTree
, WMMatchDataProc
*match
, void *cdata
);
712 /* Returns the first node where node's data matches cdata by 'match' and node is
713 * at most `limit' depths down from `aTree'. */
714 WMTreeNode
*WMFindInTreeWithDepthLimit(WMTreeNode
* aTree
, WMMatchDataProc
* match
, void *cdata
, int limit
);
716 /* Returns first tree node that has data == cdata */
717 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(aTree, NULL, cdata)
719 /* Walk every node of aNode with `walk' */
720 void WMTreeWalk(WMTreeNode
*aNode
, WMTreeWalkProc
* walk
, void *data
, Bool DepthFirst
);
722 /* ---[ WINGs/data.c ]---------------------------------------------------- */
725 WMNotification
* WMCreateNotification(const char *name
, void *object
, void *clientData
);
727 void WMReleaseNotification(WMNotification
*notification
);
729 WMNotification
* WMRetainNotification(WMNotification
*notification
);
731 void* WMGetNotificationClientData(WMNotification
*notification
);
733 void* WMGetNotificationObject(WMNotification
*notification
);
735 const char* WMGetNotificationName(WMNotification
*notification
);
738 void WMAddNotificationObserver(WMNotificationObserverAction
*observerAction
,
739 void *observer
, const char *name
, void *object
);
741 void WMPostNotification(WMNotification
*notification
);
743 void WMRemoveNotificationObserver(void *observer
);
745 void WMRemoveNotificationObserverWithName(void *observer
, const char *name
,
748 void WMPostNotificationName(const char *name
, void *object
, void *clientData
);
750 WMNotificationQueue
* WMGetDefaultNotificationQueue(void);
752 WMNotificationQueue
* WMCreateNotificationQueue(void);
754 void WMDequeueNotificationMatching(WMNotificationQueue
*queue
,
755 WMNotification
*notification
,
758 void WMEnqueueNotification(WMNotificationQueue
*queue
,
759 WMNotification
*notification
,
760 WMPostingStyle postingStyle
);
762 void WMEnqueueCoalesceNotification(WMNotificationQueue
*queue
,
763 WMNotification
*notification
,
764 WMPostingStyle postingStyle
,
765 unsigned coalesceMask
);
768 /* ---[ WINGs/proplist.c ]------------------------------------------------ */
770 /* Property Lists handling */
772 void WMPLSetCaseSensitive(Bool caseSensitive
);
774 WMPropList
* WMCreatePLString(const char *str
);
776 WMPropList
* WMCreatePLData(WMData
*data
);
778 WMPropList
* WMCreatePLDataWithBytes(const unsigned char *bytes
, unsigned int length
);
780 WMPropList
* WMCreatePLDataWithBytesNoCopy(unsigned char *bytes
,
782 WMFreeDataProc
*destructor
);
784 WMPropList
* WMCreatePLArray(WMPropList
*elem
, ...);
786 WMPropList
* WMCreatePLDictionary(WMPropList
*key
, WMPropList
*value
, ...);
788 WMPropList
* WMRetainPropList(WMPropList
*plist
);
790 void WMReleasePropList(WMPropList
*plist
);
792 /* Objects inserted in arrays and dictionaries will be retained,
793 * so you can safely release them after insertion.
794 * For dictionaries both the key and value are retained.
795 * Objects removed from arrays or dictionaries are released */
796 void WMInsertInPLArray(WMPropList
*plist
, int index
, WMPropList
*item
);
798 void WMAddToPLArray(WMPropList
*plist
, WMPropList
*item
);
800 void WMDeleteFromPLArray(WMPropList
*plist
, int index
);
802 void WMRemoveFromPLArray(WMPropList
*plist
, WMPropList
*item
);
804 void WMPutInPLDictionary(WMPropList
*plist
, WMPropList
*key
, WMPropList
*value
);
806 void WMRemoveFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
808 /* It will insert all key/value pairs from source into dest, overwriting
809 * the values with the same keys from dest, keeping all values with keys
810 * only present in dest unchanged */
811 WMPropList
* WMMergePLDictionaries(WMPropList
*dest
, WMPropList
*source
,
814 /* It will remove all key/value pairs from dest for which there is an
815 * identical key/value present in source. Entires only present in dest, or
816 * which have different values in dest than in source will be preserved. */
817 WMPropList
* WMSubtractPLDictionaries(WMPropList
*dest
, WMPropList
*source
,
820 int WMGetPropListItemCount(WMPropList
*plist
);
822 Bool
WMIsPLString(WMPropList
*plist
);
824 Bool
WMIsPLData(WMPropList
*plist
);
826 Bool
WMIsPLArray(WMPropList
*plist
);
828 Bool
WMIsPLDictionary(WMPropList
*plist
);
830 Bool
WMIsPropListEqualTo(WMPropList
*plist
, WMPropList
*other
);
832 /* Returns a reference. Do not free it! */
833 char* WMGetFromPLString(WMPropList
*plist
);
835 /* Returns a reference. Do not free it! */
836 WMData
* WMGetFromPLData(WMPropList
*plist
);
838 /* Returns a reference. Do not free it! */
839 const unsigned char* WMGetPLDataBytes(WMPropList
*plist
);
841 int WMGetPLDataLength(WMPropList
*plist
);
843 /* Returns a reference. */
844 WMPropList
* WMGetFromPLArray(WMPropList
*plist
, int index
);
846 /* Returns a reference. */
847 WMPropList
* WMGetFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
849 /* Returns a PropList array with all the dictionary keys. Release it when
850 * you're done. Keys in array are retained from the original dictionary
851 * not copied and need NOT to be released individually. */
852 WMPropList
* WMGetPLDictionaryKeys(WMPropList
*plist
);
854 /* Creates only the first level deep object. All the elements inside are
855 * retained from the original */
856 WMPropList
* WMShallowCopyPropList(WMPropList
*plist
);
858 /* Makes a completely separate replica of the original proplist */
859 WMPropList
* WMDeepCopyPropList(WMPropList
*plist
);
861 WMPropList
* WMCreatePropListFromDescription(const char *desc
);
863 /* Free the returned string when you no longer need it */
864 char* WMGetPropListDescription(WMPropList
*plist
, Bool indented
);
866 WMPropList
* WMReadPropListFromFile(const char *file
);
868 WMPropList
* WMReadPropListFromPipe(const char *command
);
870 Bool
WMWritePropListToFile(WMPropList
*plist
, const char *path
);
872 /* ---[ WINGs/userdefaults.c ]-------------------------------------------- */
874 /* don't free the returned string */
875 const char* wusergnusteppath(void);
877 /* Free the returned string when you no longer need it */
878 char* wdefaultspathfordomain(const char *domain
);
880 /* Free the returned string when you no longer need it */
881 char* wglobaldefaultspathfordomain(const char *domain
);
883 WMUserDefaults
* WMGetStandardUserDefaults(void);
885 WMUserDefaults
* WMGetDefaultsFromPath(const char *path
);
887 void WMSynchronizeUserDefaults(WMUserDefaults
*database
);
889 void WMSaveUserDefaults(WMUserDefaults
*database
);
891 void WMEnableUDPeriodicSynchronization(WMUserDefaults
*database
, Bool enable
);
893 /* Returns a WMPropList array with all the keys in the user defaults database.
894 * Free the array with WMReleasePropList() when no longer needed.
895 * Keys in array are just retained references to the original keys */
896 WMPropList
* WMGetUDKeys(WMUserDefaults
*database
);
898 WMPropList
* WMGetUDObjectForKey(WMUserDefaults
*database
, const char *defaultName
);
900 void WMSetUDObjectForKey(WMUserDefaults
*database
, WMPropList
*object
,
901 const char *defaultName
);
903 void WMRemoveUDObjectForKey(WMUserDefaults
*database
, const char *defaultName
);
905 /* Returns a reference. Do not free it! */
906 char* WMGetUDStringForKey(WMUserDefaults
*database
, const char *defaultName
);
908 int WMGetUDIntegerForKey(WMUserDefaults
*database
, const char *defaultName
);
910 float WMGetUDFloatForKey(WMUserDefaults
*database
, const char *defaultName
);
912 Bool
WMGetUDBoolForKey(WMUserDefaults
*database
, const char *defaultName
);
914 void WMSetUDStringForKey(WMUserDefaults
*database
, const char *value
,
915 const char *defaultName
);
917 void WMSetUDIntegerForKey(WMUserDefaults
*database
, int value
,
918 const char *defaultName
);
920 void WMSetUDFloatForKey(WMUserDefaults
*database
, float value
,
921 const char *defaultName
);
923 void WMSetUDBoolForKey(WMUserDefaults
*database
, Bool value
,
924 const char *defaultName
);
926 WMPropList
* WMGetUDSearchList(WMUserDefaults
*database
);
928 void WMSetUDSearchList(WMUserDefaults
*database
, WMPropList
*list
);
930 extern char *WMUserDefaultsDidChangeNotification
;
933 /* ---[ WINGs/menuparser.c ]---------------------------------------------- */
936 typedef struct w_menu_parser
*WMenuParser
;
939 WMenuParser
WMenuParserCreate(const char *file_name
, void *file
, const char *include_default_paths
);
941 void WMenuParserRegisterSimpleMacro(WMenuParser parser
, const char *name
, const char *value
);
943 void WMenuParserError(WMenuParser parser
, const char *msg
, ...)
944 __attribute__ ((format (printf
, 2, 3)));
946 const char *WMenuParserGetFilename(WMenuParser parser
);
948 Bool
WMenuParserGetLine(WMenuParser parser
, char **title
, char **command
, char **parameter
, char **shortcut
);
950 void WMenuParserDelete(WMenuParser parser
);
953 /*-------------------------------------------------------------------------*/
955 /* Global variables */
957 extern int WCErrorCode
;
960 /*-------------------------------------------------------------------------*/
964 #endif /* __cplusplus */