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/wmisc.c ]--------------------------------------------------- */
310 WMRange
wmkrange(int start
, int count
);
312 /* ---[ WINGs/usleep.c ]-------------------------------------------------- */
314 void wusleep(unsigned int usec
);
316 /* ---[ WINGs/handlers.c ]------------------------------------------------ */
318 /* Event handlers: timer, idle, input */
320 WMHandlerID
WMAddTimerHandler(int milliseconds
, WMCallback
*callback
,
323 WMHandlerID
WMAddPersistentTimerHandler(int milliseconds
, WMCallback
*callback
,
326 void WMDeleteTimerWithClientData(void *cdata
);
328 void WMDeleteTimerHandler(WMHandlerID handlerID
);
330 WMHandlerID
WMAddIdleHandler(WMCallback
*callback
, void *cdata
);
332 void WMDeleteIdleHandler(WMHandlerID handlerID
);
334 WMHandlerID
WMAddInputHandler(int fd
, int condition
, WMInputProc
*proc
,
337 void WMDeleteInputHandler(WMHandlerID handlerID
);
340 /* This function is used _only_ if you create a non-GUI program.
341 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
342 * This function will handle all input/timer/idle events, then return.
345 void WHandleEvents(void);
347 /* ---[ WINGs/hashtable.c ]----------------------------------------------- */
350 WMHashTable
* WMCreateHashTable(const WMHashTableCallbacks callbacks
);
352 void WMFreeHashTable(WMHashTable
*table
);
354 void WMResetHashTable(WMHashTable
*table
);
356 unsigned WMCountHashTable(WMHashTable
*table
);
358 void* WMHashGet(WMHashTable
*table
, const void *key
);
360 /* Returns True if there is a value associated with <key> in the table, in
361 * which case <retKey> and <retItem> will contain the item's internal key
362 * address and the item's value respectively.
363 * If there is no value associated with <key> it will return False and in
364 * this case <retKey> and <retItem> will be undefined.
365 * Use this when you need to perform your own custom retain/release mechanism
366 * which requires access to the keys too.
368 Bool
WMHashGetItemAndKey(WMHashTable
*table
, const void *key
,
369 void **retItem
, void **retKey
);
371 /* put data in table, replacing already existing data and returning
373 void* WMHashInsert(WMHashTable
*table
, const void *key
, const void *data
);
375 void WMHashRemove(WMHashTable
*table
, const void *key
);
377 /* warning: do not manipulate the table while using the enumerator functions */
378 WMHashEnumerator
WMEnumerateHashTable(WMHashTable
*table
);
380 void* WMNextHashEnumeratorItem(WMHashEnumerator
*enumerator
);
382 void* WMNextHashEnumeratorKey(WMHashEnumerator
*enumerator
);
384 /* Returns True if there is a next element, in which case key and item
385 * will contain the next element's key and value respectively.
386 * If there is no next element available it will return False and in this
387 * case key and item will be undefined.
389 Bool
WMNextHashEnumeratorItemAndKey(WMHashEnumerator
*enumerator
,
390 void **item
, void **key
);
395 /* some predefined callback sets */
397 extern const WMHashTableCallbacks WMIntHashCallbacks
;
398 /* sizeof(keys) are <= sizeof(void*) */
400 extern const WMHashTableCallbacks WMStringHashCallbacks
;
401 /* keys are strings. Strings will be copied with wstrdup()
402 * and freed with wfree() */
404 extern const WMHashTableCallbacks WMStringPointerHashCallbacks
;
405 /* keys are strings, but they are not copied */
408 /* ---[ WINGs/array.c ]--------------------------------------------------- */
411 * WMArray use an array to store the elements.
412 * Item indexes may be only positive integer numbers.
413 * The array cannot contain holes in it.
416 * Fast [O(1)] access to elements
417 * Fast [O(1)] push/pop
420 * A little slower [O(n)] for insertion/deletion of elements that
424 WMArray
* WMCreateArray(int initialSize
);
426 WMArray
* WMCreateArrayWithDestructor(int initialSize
, WMFreeDataProc
*destructor
);
428 WMArray
* WMCreateArrayWithArray(WMArray
*array
);
430 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
432 void WMEmptyArray(WMArray
*array
);
434 void WMFreeArray(WMArray
*array
);
436 int WMGetArrayItemCount(WMArray
*array
);
438 /* appends other to array. other remains unchanged */
439 void WMAppendArray(WMArray
*array
, WMArray
*other
);
441 /* add will place the element at the end of the array */
442 void WMAddToArray(WMArray
*array
, void *item
);
444 /* insert will increment the index of elements after it by 1 */
445 void WMInsertInArray(WMArray
*array
, int index
, void *item
);
447 /* replace and set will return the old item WITHOUT calling the
448 * destructor on it even if its available. Free the returned item yourself.
450 void* WMReplaceInArray(WMArray
*array
, int index
, void *item
);
452 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
454 /* delete and remove will remove the elements and cause the elements
455 * after them to decrement their indexes by 1. Also will call the
456 * destructor on the deleted element if there's one available.
458 int WMDeleteFromArray(WMArray
*array
, int index
);
460 #define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
462 int WMRemoveFromArrayMatching(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
464 void* WMGetFromArray(WMArray
*array
, int index
);
466 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
468 /* pop will return the last element from the array, also removing it
469 * from the array. The destructor is NOT called, even if available.
470 * Free the returned element if needed by yourself
472 void* WMPopFromArray(WMArray
*array
);
474 int WMFindInArray(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
476 int WMCountInArray(WMArray
*array
, void *item
);
478 /* comparer must return:
483 void WMSortArray(WMArray
*array
, WMCompareDataProc
*comparer
);
485 void WMMapArray(WMArray
*array
, void (*function
)(void*, void*), void *data
);
487 WMArray
* WMGetSubarrayWithRange(WMArray
* array
, WMRange aRange
);
489 void* WMArrayFirst(WMArray
*array
, WMArrayIterator
*iter
);
491 void* WMArrayLast(WMArray
*array
, WMArrayIterator
*iter
);
493 /* The following 2 functions assume that the array doesn't change between calls */
494 void* WMArrayNext(WMArray
*array
, WMArrayIterator
*iter
);
496 void* WMArrayPrevious(WMArray
*array
, WMArrayIterator
*iter
);
499 /* The following 2 macros assume that the array doesn't change in the for loop */
500 #define WM_ITERATE_ARRAY(array, var, i) \
501 for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
502 var = WMArrayNext(array, &(i)))
504 #define WM_ETARETI_ARRAY(array, var, i) \
505 for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
506 var = WMArrayPrevious(array, &(i)))
508 /* ---[ WINGs/bagtree.c ]------------------------------------------------- */
511 * Tree bags use a red-black tree for storage.
512 * Item indexes may be any integer number.
515 * O(lg n) insertion/deletion/search
516 * Good for large numbers of elements with sparse indexes
519 * O(lg n) insertion/deletion/search
520 * Slow for storing small numbers of elements
523 #define WMCreateBag(size) WMCreateTreeBag()
525 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
527 WMBag
* WMCreateTreeBag(void);
529 WMBag
* WMCreateTreeBagWithDestructor(WMFreeDataProc
*destructor
);
531 int WMGetBagItemCount(WMBag
*bag
);
533 void WMAppendBag(WMBag
*bag
, WMBag
*other
);
535 void WMPutInBag(WMBag
*bag
, void *item
);
537 /* insert will increment the index of elements after it by 1 */
538 void WMInsertInBag(WMBag
*bag
, int index
, void *item
);
540 /* erase will remove the element from the bag,
541 * but will keep the index of the other elements unchanged */
542 int WMEraseFromBag(WMBag
*bag
, int index
);
544 /* delete and remove will remove the elements and cause the elements
545 * after them to decrement their indexes by 1 */
546 int WMDeleteFromBag(WMBag
*bag
, int index
);
548 int WMRemoveFromBag(WMBag
*bag
, void *item
);
550 void* WMGetFromBag(WMBag
*bag
, int index
);
552 void* WMReplaceInBag(WMBag
*bag
, int index
, void *item
);
554 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
556 /* comparer must return:
561 void WMSortBag(WMBag
*bag
, WMCompareDataProc
*comparer
);
563 void WMEmptyBag(WMBag
*bag
);
565 void WMFreeBag(WMBag
*bag
);
567 void WMMapBag(WMBag
*bag
, void (*function
)(void*, void*), void *data
);
569 int WMGetFirstInBag(WMBag
*bag
, void *item
);
571 int WMCountInBag(WMBag
*bag
, void *item
);
573 int WMFindInBag(WMBag
*bag
, WMMatchDataProc
*match
, void *cdata
);
575 void* WMBagFirst(WMBag
*bag
, WMBagIterator
*ptr
);
577 void* WMBagLast(WMBag
*bag
, WMBagIterator
*ptr
);
579 /* The following 4 functions assume that the bag doesn't change between calls */
580 void* WMBagNext(WMBag
*bag
, WMBagIterator
*ptr
);
582 void* WMBagPrevious(WMBag
*bag
, WMBagIterator
*ptr
);
584 void* WMBagIteratorAtIndex(WMBag
*bag
, int index
, WMBagIterator
*ptr
);
586 int WMBagIndexForIterator(WMBag
*bag
, WMBagIterator ptr
);
589 /* The following 2 macros assume that the bag doesn't change in the for loop */
590 #define WM_ITERATE_BAG(bag, var, i) \
591 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
592 var = WMBagNext(bag, &(i)))
594 #define WM_ETARETI_BAG(bag, var, i) \
595 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
596 var = WMBagPrevious(bag, &(i)))
600 /* ---[ WINGs/data.c ]---------------------------------------------------- */
602 /* WMData handling */
604 /* Creating/destroying data */
606 WMData
* WMCreateDataWithCapacity(unsigned capacity
);
608 WMData
* WMCreateDataWithLength(unsigned length
);
610 WMData
* WMCreateDataWithBytes(const void *bytes
, unsigned length
);
612 /* destructor is a function called to free the data when releasing the data
613 * object, or NULL if no freeing of data is necesary. */
614 WMData
* WMCreateDataWithBytesNoCopy(void *bytes
, unsigned length
,
615 WMFreeDataProc
*destructor
);
617 WMData
* WMCreateDataWithData(WMData
*aData
);
619 WMData
* WMRetainData(WMData
*aData
);
621 void WMReleaseData(WMData
*aData
);
623 /* Adjusting capacity */
625 void WMSetDataCapacity(WMData
*aData
, unsigned capacity
);
627 void WMSetDataLength(WMData
*aData
, unsigned length
);
629 void WMIncreaseDataLengthBy(WMData
*aData
, unsigned extraLength
);
633 const void* WMDataBytes(WMData
*aData
);
635 void WMGetDataBytes(WMData
*aData
, void *buffer
);
637 void WMGetDataBytesWithLength(WMData
*aData
, void *buffer
, unsigned length
);
639 void WMGetDataBytesWithRange(WMData
*aData
, void *buffer
, WMRange aRange
);
641 WMData
* WMGetSubdataWithRange(WMData
*aData
, WMRange aRange
);
645 Bool
WMIsDataEqualToData(WMData
*aData
, WMData
*anotherData
);
647 unsigned WMGetDataLength(WMData
*aData
);
651 void WMAppendDataBytes(WMData
*aData
, const void *bytes
, unsigned length
);
653 void WMAppendData(WMData
*aData
, WMData
*anotherData
);
657 void WMReplaceDataBytesInRange(WMData
*aData
, WMRange aRange
, const void *bytes
);
659 void WMResetDataBytesInRange(WMData
*aData
, WMRange aRange
);
661 void WMSetData(WMData
*aData
, WMData
*anotherData
);
664 void WMSetDataFormat(WMData
*aData
, unsigned format
);
666 unsigned WMGetDataFormat(WMData
*aData
);
669 /* ---[ WINGs/tree.c ]---------------------------------------------------- */
671 /* Generic Tree and TreeNode */
673 WMTreeNode
* WMCreateTreeNode(void *data
);
675 WMTreeNode
* WMCreateTreeNodeWithDestructor(void *data
, WMFreeDataProc
*destructor
);
677 WMTreeNode
* WMInsertItemInTree(WMTreeNode
*parent
, int index
, void *item
);
679 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
681 WMTreeNode
* WMInsertNodeInTree(WMTreeNode
*parent
, int index
, WMTreeNode
*aNode
);
683 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
685 void WMDestroyTreeNode(WMTreeNode
*aNode
);
687 void WMDeleteLeafForTreeNode(WMTreeNode
*aNode
, int index
);
689 void WMRemoveLeafForTreeNode(WMTreeNode
*aNode
, void *leaf
);
691 void* WMReplaceDataForTreeNode(WMTreeNode
*aNode
, void *newData
);
693 void* WMGetDataForTreeNode(WMTreeNode
*aNode
);
695 int WMGetTreeNodeDepth(WMTreeNode
*aNode
);
697 WMTreeNode
* WMGetParentForTreeNode(WMTreeNode
*aNode
);
699 /* Sort only the leaves of the passed node */
700 void WMSortLeavesForTreeNode(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
702 /* Sort all tree recursively starting from the passed node */
703 void WMSortTree(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
705 /* Returns the first node which matches node's data with cdata by 'match' */
706 WMTreeNode
* WMFindInTree(WMTreeNode
*aTree
, WMMatchDataProc
*match
, void *cdata
);
708 /* Returns the first node where node's data matches cdata by 'match' and node is
709 * at most `limit' depths down from `aTree'. */
710 WMTreeNode
*WMFindInTreeWithDepthLimit(WMTreeNode
* aTree
, WMMatchDataProc
* match
, void *cdata
, int limit
);
712 /* Returns first tree node that has data == cdata */
713 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(aTree, NULL, cdata)
715 /* Walk every node of aNode with `walk' */
716 void WMTreeWalk(WMTreeNode
*aNode
, WMTreeWalkProc
* walk
, void *data
, Bool DepthFirst
);
718 /* ---[ WINGs/data.c ]---------------------------------------------------- */
721 WMNotification
* WMCreateNotification(const char *name
, void *object
, void *clientData
);
723 void WMReleaseNotification(WMNotification
*notification
);
725 WMNotification
* WMRetainNotification(WMNotification
*notification
);
727 void* WMGetNotificationClientData(WMNotification
*notification
);
729 void* WMGetNotificationObject(WMNotification
*notification
);
731 const char* WMGetNotificationName(WMNotification
*notification
);
734 void WMAddNotificationObserver(WMNotificationObserverAction
*observerAction
,
735 void *observer
, const char *name
, void *object
);
737 void WMPostNotification(WMNotification
*notification
);
739 void WMRemoveNotificationObserver(void *observer
);
741 void WMRemoveNotificationObserverWithName(void *observer
, const char *name
,
744 void WMPostNotificationName(const char *name
, void *object
, void *clientData
);
746 WMNotificationQueue
* WMGetDefaultNotificationQueue(void);
748 WMNotificationQueue
* WMCreateNotificationQueue(void);
750 void WMDequeueNotificationMatching(WMNotificationQueue
*queue
,
751 WMNotification
*notification
,
754 void WMEnqueueNotification(WMNotificationQueue
*queue
,
755 WMNotification
*notification
,
756 WMPostingStyle postingStyle
);
758 void WMEnqueueCoalesceNotification(WMNotificationQueue
*queue
,
759 WMNotification
*notification
,
760 WMPostingStyle postingStyle
,
761 unsigned coalesceMask
);
764 /* ---[ WINGs/proplist.c ]------------------------------------------------ */
766 /* Property Lists handling */
768 void WMPLSetCaseSensitive(Bool caseSensitive
);
770 WMPropList
* WMCreatePLString(const char *str
);
772 WMPropList
* WMCreatePLData(WMData
*data
);
774 WMPropList
* WMCreatePLDataWithBytes(const unsigned char *bytes
, unsigned int length
);
776 WMPropList
* WMCreatePLDataWithBytesNoCopy(unsigned char *bytes
,
778 WMFreeDataProc
*destructor
);
780 WMPropList
* WMCreatePLArray(WMPropList
*elem
, ...);
782 WMPropList
* WMCreatePLDictionary(WMPropList
*key
, WMPropList
*value
, ...);
784 WMPropList
* WMRetainPropList(WMPropList
*plist
);
786 void WMReleasePropList(WMPropList
*plist
);
788 /* Objects inserted in arrays and dictionaries will be retained,
789 * so you can safely release them after insertion.
790 * For dictionaries both the key and value are retained.
791 * Objects removed from arrays or dictionaries are released */
792 void WMInsertInPLArray(WMPropList
*plist
, int index
, WMPropList
*item
);
794 void WMAddToPLArray(WMPropList
*plist
, WMPropList
*item
);
796 void WMDeleteFromPLArray(WMPropList
*plist
, int index
);
798 void WMRemoveFromPLArray(WMPropList
*plist
, WMPropList
*item
);
800 void WMPutInPLDictionary(WMPropList
*plist
, WMPropList
*key
, WMPropList
*value
);
802 void WMRemoveFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
804 /* It will insert all key/value pairs from source into dest, overwriting
805 * the values with the same keys from dest, keeping all values with keys
806 * only present in dest unchanged */
807 WMPropList
* WMMergePLDictionaries(WMPropList
*dest
, WMPropList
*source
,
810 /* It will remove all key/value pairs from dest for which there is an
811 * identical key/value present in source. Entires only present in dest, or
812 * which have different values in dest than in source will be preserved. */
813 WMPropList
* WMSubtractPLDictionaries(WMPropList
*dest
, WMPropList
*source
,
816 int WMGetPropListItemCount(WMPropList
*plist
);
818 Bool
WMIsPLString(WMPropList
*plist
);
820 Bool
WMIsPLData(WMPropList
*plist
);
822 Bool
WMIsPLArray(WMPropList
*plist
);
824 Bool
WMIsPLDictionary(WMPropList
*plist
);
826 Bool
WMIsPropListEqualTo(WMPropList
*plist
, WMPropList
*other
);
828 /* Returns a reference. Do not free it! */
829 char* WMGetFromPLString(WMPropList
*plist
);
831 /* Returns a reference. Do not free it! */
832 WMData
* WMGetFromPLData(WMPropList
*plist
);
834 /* Returns a reference. Do not free it! */
835 const unsigned char* WMGetPLDataBytes(WMPropList
*plist
);
837 int WMGetPLDataLength(WMPropList
*plist
);
839 /* Returns a reference. */
840 WMPropList
* WMGetFromPLArray(WMPropList
*plist
, int index
);
842 /* Returns a reference. */
843 WMPropList
* WMGetFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
845 /* Returns a PropList array with all the dictionary keys. Release it when
846 * you're done. Keys in array are retained from the original dictionary
847 * not copied and need NOT to be released individually. */
848 WMPropList
* WMGetPLDictionaryKeys(WMPropList
*plist
);
850 /* Creates only the first level deep object. All the elements inside are
851 * retained from the original */
852 WMPropList
* WMShallowCopyPropList(WMPropList
*plist
);
854 /* Makes a completely separate replica of the original proplist */
855 WMPropList
* WMDeepCopyPropList(WMPropList
*plist
);
857 WMPropList
* WMCreatePropListFromDescription(const char *desc
);
859 /* Free the returned string when you no longer need it */
860 char* WMGetPropListDescription(WMPropList
*plist
, Bool indented
);
862 WMPropList
* WMReadPropListFromFile(const char *file
);
864 WMPropList
* WMReadPropListFromPipe(const char *command
);
866 Bool
WMWritePropListToFile(WMPropList
*plist
, const char *path
);
868 /* ---[ WINGs/userdefaults.c ]-------------------------------------------- */
870 /* don't free the returned string */
871 const char* wusergnusteppath(void);
873 /* Free the returned string when you no longer need it */
874 char* wdefaultspathfordomain(const char *domain
);
876 /* Free the returned string when you no longer need it */
877 char* wglobaldefaultspathfordomain(const char *domain
);
879 WMUserDefaults
* WMGetStandardUserDefaults(void);
881 WMUserDefaults
* WMGetDefaultsFromPath(const char *path
);
883 void WMSynchronizeUserDefaults(WMUserDefaults
*database
);
885 void WMSaveUserDefaults(WMUserDefaults
*database
);
887 void WMEnableUDPeriodicSynchronization(WMUserDefaults
*database
, Bool enable
);
889 /* Returns a WMPropList array with all the keys in the user defaults database.
890 * Free the array with WMReleasePropList() when no longer needed.
891 * Keys in array are just retained references to the original keys */
892 WMPropList
* WMGetUDKeys(WMUserDefaults
*database
);
894 WMPropList
* WMGetUDObjectForKey(WMUserDefaults
*database
, const char *defaultName
);
896 void WMSetUDObjectForKey(WMUserDefaults
*database
, WMPropList
*object
,
897 const char *defaultName
);
899 void WMRemoveUDObjectForKey(WMUserDefaults
*database
, const char *defaultName
);
901 /* Returns a reference. Do not free it! */
902 char* WMGetUDStringForKey(WMUserDefaults
*database
, const char *defaultName
);
904 int WMGetUDIntegerForKey(WMUserDefaults
*database
, const char *defaultName
);
906 float WMGetUDFloatForKey(WMUserDefaults
*database
, const char *defaultName
);
908 Bool
WMGetUDBoolForKey(WMUserDefaults
*database
, const char *defaultName
);
910 void WMSetUDStringForKey(WMUserDefaults
*database
, const char *value
,
911 const char *defaultName
);
913 void WMSetUDIntegerForKey(WMUserDefaults
*database
, int value
,
914 const char *defaultName
);
916 void WMSetUDFloatForKey(WMUserDefaults
*database
, float value
,
917 const char *defaultName
);
919 void WMSetUDBoolForKey(WMUserDefaults
*database
, Bool value
,
920 const char *defaultName
);
922 WMPropList
* WMGetUDSearchList(WMUserDefaults
*database
);
924 void WMSetUDSearchList(WMUserDefaults
*database
, WMPropList
*list
);
926 extern char *WMUserDefaultsDidChangeNotification
;
929 /* ---[ WINGs/menuparser.c ]---------------------------------------------- */
932 typedef struct w_menu_parser
*WMenuParser
;
935 WMenuParser
WMenuParserCreate(const char *file_name
, void *file
, const char *include_default_paths
);
937 void WMenuParserRegisterSimpleMacro(WMenuParser parser
, const char *name
, const char *value
);
939 void WMenuParserError(WMenuParser parser
, const char *msg
, ...)
940 __attribute__ ((format (printf
, 2, 3)));
942 const char *WMenuParserGetFilename(WMenuParser parser
);
944 Bool
WMenuParserGetLine(WMenuParser parser
, char **title
, char **command
, char **parameter
, char **shortcut
);
946 void WMenuParserDelete(WMenuParser parser
);
949 /*-------------------------------------------------------------------------*/
951 /* Global variables */
953 extern int WCErrorCode
;
956 /*-------------------------------------------------------------------------*/
960 #endif /* __cplusplus */