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))
44 #define __attribute__(x) /*NOTHING*/
49 #define wassertr(expr) \
50 if (!(expr)) { return; }
52 #define wassertrv(expr, val) \
53 if (!(expr)) { return (val); }
57 #define wassertr(expr) \
59 wwarning("wassertr: assertion %s failed", #expr); \
63 #define wassertrv(expr, val) \
65 wwarning("wassertrv: assertion %s failed", #expr); \
73 # define _wutil_static_assert(check, message) static_assert(check, message)
75 # ifdef __STDC_VERSION__
76 # if __STDC_VERSION__ >= 201112L
78 * Ideally, we would like to include <assert.h> to have 'static_assert'
79 * properly defined, but as we have to be sure about portability and
80 * because we're a public header we can't count on 'configure' to tell
81 * us about availability, so we use the raw C11 keyword
83 # define _wutil_static_assert(check, message) _Static_assert(check, message)
85 # define _wutil_static_assert(check, message) /**/
88 # define _wutil_static_assert(check, message) /**/
95 #endif /* __cplusplus */
109 } WMNotificationCoalescing
;
114 WBNotFound
= INT_MIN
, /* element was not found in WMBag */
115 WANotFound
= -1 /* element was not found in WMArray */
119 typedef struct W_Array WMArray
;
120 typedef struct W_Bag WMBag
;
121 typedef struct W_Data WMData
;
122 typedef struct W_TreeNode WMTreeNode
;
123 typedef struct W_HashTable WMHashTable
;
124 typedef struct W_UserDefaults WMUserDefaults
;
125 typedef struct W_Notification WMNotification
;
126 typedef struct W_NotificationQueue WMNotificationQueue
;
127 typedef struct W_Host WMHost
;
128 typedef struct W_Connection WMConnection
;
129 typedef struct W_PropList WMPropList
;
133 /* Some typedefs for the handler stuff */
134 typedef void *WMHandlerID
;
136 typedef void WMCallback(void *data
);
138 typedef void WMInputProc(int fd
, int mask
, void *clientData
);
142 typedef int WMCompareDataProc(const void *item1
, const void *item2
);
143 typedef void WMTreeWalkProc(WMTreeNode
*aNode
, void *data
);
145 typedef void WMFreeDataProc(void *data
);
147 /* Used by WMBag or WMArray for matching data */
148 typedef int WMMatchDataProc(const void *item
, const void *cdata
);
159 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
168 /* NULL is pointer hash */
169 unsigned (*hash
)(const void *);
170 /* NULL is pointer compare */
171 Bool (*keyIsEqual
)(const void *, const void *);
172 /* NULL does nothing */
173 void* (*retainKey
)(const void *);
174 /* NULL does nothing */
175 void (*releaseKey
)(const void *);
176 } WMHashTableCallbacks
;
179 typedef int WMArrayIterator
;
180 typedef void *WMBagIterator
;
183 typedef void WMNotificationObserverAction(void *observerData
,
184 WMNotification
*notification
);
187 /* ---[ Macros ]---------------------------------------------------------- */
189 #define wlengthof(array) \
191 _wutil_static_assert(sizeof(array) > sizeof(array[0]), \
192 "the macro 'wlengthof' cannot be used on pointers, only on known size arrays"); \
193 sizeof(array) / sizeof(array[0]); \
197 /* ---[ WINGs/memory.c ]-------------------------------------------------- */
199 void* wmalloc(size_t size
);
200 void* wrealloc(void *ptr
, size_t newsize
);
201 void wfree(void *ptr
);
203 void wrelease(void *ptr
);
204 void* wretain(void *ptr
);
206 typedef void waborthandler(int);
208 waborthandler
* wsetabort(waborthandler
* handler
);
210 /* ---[ WINGs/error.c ]--------------------------------------------------- */
213 WMESSAGE_TYPE_MESSAGE
,
214 WMESSAGE_TYPE_WARNING
,
219 #define wmessage(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_MESSAGE, fmt, ## args)
220 #define wwarning(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_WARNING, fmt, ## args)
221 #define werror(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_ERROR, fmt, ## args)
222 #define wfatal(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_FATAL, fmt, ## args)
224 void __wmessage(const char *func
, const char *file
, int line
, int type
, const char *msg
, ...)
225 __attribute__((__format__(printf
,5,6)));
227 /* ---[ WINGs/findfile.c ]------------------------------------------------ */
229 /* For the 4 function below, you have to free the returned string when you no longer need it */
231 char* wfindfile(const char *paths
, const char *file
);
233 char* wfindfileinlist(char *const *path_list
, const char *file
);
235 char* wfindfileinarray(WMPropList
* array
, const char *file
);
237 char* wexpandpath(const char *path
);
239 int wcopy_file(const char *toPath
, const char *srcFile
, const char *destFile
);
241 /* don't free the returned string */
242 char* wgethomedir(void);
244 /* ---[ WINGs/proplist.c ]------------------------------------------------ */
246 int wmkdirhier(const char *path
);
247 int wrmdirhier(const char *path
);
249 /* ---[ WINGs/string.c ]-------------------------------------------------- */
251 char *wstrdup(const char *str
);
252 char* wstrndup(const char *str
, size_t len
);
254 /* Concatenate str1 with str2 and return that in a newly malloc'ed string.
255 * str1 and str2 can be any strings including static and constant strings.
256 * str1 and str2 will not be modified.
257 * Free the returned string when you're done with it. */
258 char* wstrconcat(const char *str1
, const char *str2
);
260 /* This will append src to dst, and return dst. dst MUST be either NULL
261 * or a string that was a result of a dynamic allocation (malloc, realloc
262 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
263 * Modifies dst (no new string is created except if dst==NULL in which case
264 * it is equivalent to calling wstrdup(src) ).
265 * The returned address may be different from the original address of dst,
266 * so always assign the returned address to avoid dangling pointers. */
267 char* wstrappend(char *dst
, const char *src
);
269 size_t wstrlcpy(char *, const char *, size_t);
270 size_t wstrlcat(char *, const char *, size_t);
273 void wtokensplit(char *command
, char ***argv
, int *argc
);
275 char* wtokennext(char *word
, char **next
);
277 char* wtokenjoin(char **list
, int count
);
279 void wtokenfree(char **tokens
, int count
);
281 char* wtrimspace(const char *s
);
283 /* transform `s' so that the result is safe to pass to the shell as an argument.
284 * returns a newly allocated string.
285 * with very heavy inspirations from NetBSD's shquote(3).
287 char *wshellquote(const char *s
);
289 /* ---[ WINGs/misc.c ]--------------------------------------------------- */
291 WMRange
wmkrange(int start
, int count
);
293 /* An application must call this function before exiting, to let WUtil do some internal cleanup */
294 void wutil_shutdown(void);
297 /* ---[ WINGs/usleep.c ]-------------------------------------------------- */
299 void wusleep(unsigned int usec
);
301 /* ---[ WINGs/handlers.c ]------------------------------------------------ */
303 /* Event handlers: timer, idle, input */
305 WMHandlerID
WMAddTimerHandler(int milliseconds
, WMCallback
*callback
,
308 WMHandlerID
WMAddPersistentTimerHandler(int milliseconds
, WMCallback
*callback
,
311 void WMDeleteTimerWithClientData(void *cdata
);
313 void WMDeleteTimerHandler(WMHandlerID handlerID
);
315 WMHandlerID
WMAddIdleHandler(WMCallback
*callback
, void *cdata
);
317 void WMDeleteIdleHandler(WMHandlerID handlerID
);
319 WMHandlerID
WMAddInputHandler(int fd
, int condition
, WMInputProc
*proc
,
322 void WMDeleteInputHandler(WMHandlerID handlerID
);
325 /* This function is used _only_ if you create a non-GUI program.
326 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
327 * This function will handle all input/timer/idle events, then return.
330 void WHandleEvents(void);
332 /* ---[ WINGs/hashtable.c ]----------------------------------------------- */
335 WMHashTable
* WMCreateHashTable(const WMHashTableCallbacks callbacks
);
337 void WMFreeHashTable(WMHashTable
*table
);
339 void WMResetHashTable(WMHashTable
*table
);
341 unsigned WMCountHashTable(WMHashTable
*table
);
343 void* WMHashGet(WMHashTable
*table
, const void *key
);
345 /* Returns True if there is a value associated with <key> in the table, in
346 * which case <retKey> and <retItem> will contain the item's internal key
347 * address and the item's value respectively.
348 * If there is no value associated with <key> it will return False and in
349 * this case <retKey> and <retItem> will be undefined.
350 * Use this when you need to perform your own custom retain/release mechanism
351 * which requires access to the keys too.
353 Bool
WMHashGetItemAndKey(WMHashTable
*table
, const void *key
,
354 void **retItem
, void **retKey
);
356 /* put data in table, replacing already existing data and returning
358 void* WMHashInsert(WMHashTable
*table
, const void *key
, const void *data
);
360 void WMHashRemove(WMHashTable
*table
, const void *key
);
362 /* warning: do not manipulate the table while using the enumerator functions */
363 WMHashEnumerator
WMEnumerateHashTable(WMHashTable
*table
);
365 void* WMNextHashEnumeratorItem(WMHashEnumerator
*enumerator
);
367 void* WMNextHashEnumeratorKey(WMHashEnumerator
*enumerator
);
369 /* Returns True if there is a next element, in which case key and item
370 * will contain the next element's key and value respectively.
371 * If there is no next element available it will return False and in this
372 * case key and item will be undefined.
374 Bool
WMNextHashEnumeratorItemAndKey(WMHashEnumerator
*enumerator
,
375 void **item
, void **key
);
380 /* some predefined callback sets */
382 extern const WMHashTableCallbacks WMIntHashCallbacks
;
383 /* sizeof(keys) are <= sizeof(void*) */
385 extern const WMHashTableCallbacks WMStringHashCallbacks
;
386 /* keys are strings. Strings will be copied with wstrdup()
387 * and freed with wfree() */
389 extern const WMHashTableCallbacks WMStringPointerHashCallbacks
;
390 /* keys are strings, but they are not copied */
393 /* ---[ WINGs/array.c ]--------------------------------------------------- */
396 * WMArray use an array to store the elements.
397 * Item indexes may be only positive integer numbers.
398 * The array cannot contain holes in it.
401 * Fast [O(1)] access to elements
402 * Fast [O(1)] push/pop
405 * A little slower [O(n)] for insertion/deletion of elements that
409 WMArray
* WMCreateArray(int initialSize
);
411 WMArray
* WMCreateArrayWithDestructor(int initialSize
, WMFreeDataProc
*destructor
);
413 WMArray
* WMCreateArrayWithArray(WMArray
*array
);
415 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
417 void WMEmptyArray(WMArray
*array
);
419 void WMFreeArray(WMArray
*array
);
421 int WMGetArrayItemCount(WMArray
*array
);
423 /* appends other to array. other remains unchanged */
424 void WMAppendArray(WMArray
*array
, WMArray
*other
);
426 /* add will place the element at the end of the array */
427 void WMAddToArray(WMArray
*array
, void *item
);
429 /* insert will increment the index of elements after it by 1 */
430 void WMInsertInArray(WMArray
*array
, int index
, void *item
);
432 /* replace and set will return the old item WITHOUT calling the
433 * destructor on it even if its available. Free the returned item yourself.
435 void* WMReplaceInArray(WMArray
*array
, int index
, void *item
);
437 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
439 /* delete and remove will remove the elements and cause the elements
440 * after them to decrement their indexes by 1. Also will call the
441 * destructor on the deleted element if there's one available.
443 int WMDeleteFromArray(WMArray
*array
, int index
);
445 #define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
447 int WMRemoveFromArrayMatching(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
449 void* WMGetFromArray(WMArray
*array
, int index
);
451 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
453 /* pop will return the last element from the array, also removing it
454 * from the array. The destructor is NOT called, even if available.
455 * Free the returned element if needed by yourself
457 void* WMPopFromArray(WMArray
*array
);
459 int WMFindInArray(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
461 int WMCountInArray(WMArray
*array
, void *item
);
463 /* comparer must return:
468 void WMSortArray(WMArray
*array
, WMCompareDataProc
*comparer
);
470 void WMMapArray(WMArray
*array
, void (*function
)(void*, void*), void *data
);
472 WMArray
* WMGetSubarrayWithRange(WMArray
* array
, WMRange aRange
);
474 void* WMArrayFirst(WMArray
*array
, WMArrayIterator
*iter
);
476 void* WMArrayLast(WMArray
*array
, WMArrayIterator
*iter
);
478 /* The following 2 functions assume that the array doesn't change between calls */
479 void* WMArrayNext(WMArray
*array
, WMArrayIterator
*iter
);
481 void* WMArrayPrevious(WMArray
*array
, WMArrayIterator
*iter
);
484 /* The following 2 macros assume that the array doesn't change in the for loop */
485 #define WM_ITERATE_ARRAY(array, var, i) \
486 for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
487 var = WMArrayNext(array, &(i)))
489 #define WM_ETARETI_ARRAY(array, var, i) \
490 for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
491 var = WMArrayPrevious(array, &(i)))
493 /* ---[ WINGs/bagtree.c ]------------------------------------------------- */
496 * Tree bags use a red-black tree for storage.
497 * Item indexes may be any integer number.
500 * O(lg n) insertion/deletion/search
501 * Good for large numbers of elements with sparse indexes
504 * O(lg n) insertion/deletion/search
505 * Slow for storing small numbers of elements
508 #define WMCreateBag(size) WMCreateTreeBag()
510 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
512 WMBag
* WMCreateTreeBag(void);
514 WMBag
* WMCreateTreeBagWithDestructor(WMFreeDataProc
*destructor
);
516 int WMGetBagItemCount(WMBag
*bag
);
518 void WMAppendBag(WMBag
*bag
, WMBag
*other
);
520 void WMPutInBag(WMBag
*bag
, void *item
);
522 /* insert will increment the index of elements after it by 1 */
523 void WMInsertInBag(WMBag
*bag
, int index
, void *item
);
525 /* erase will remove the element from the bag,
526 * but will keep the index of the other elements unchanged */
527 int WMEraseFromBag(WMBag
*bag
, int index
);
529 /* delete and remove will remove the elements and cause the elements
530 * after them to decrement their indexes by 1 */
531 int WMDeleteFromBag(WMBag
*bag
, int index
);
533 int WMRemoveFromBag(WMBag
*bag
, void *item
);
535 void* WMGetFromBag(WMBag
*bag
, int index
);
537 void* WMReplaceInBag(WMBag
*bag
, int index
, void *item
);
539 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
541 /* comparer must return:
546 void WMSortBag(WMBag
*bag
, WMCompareDataProc
*comparer
);
548 void WMEmptyBag(WMBag
*bag
);
550 void WMFreeBag(WMBag
*bag
);
552 void WMMapBag(WMBag
*bag
, void (*function
)(void*, void*), void *data
);
554 int WMGetFirstInBag(WMBag
*bag
, void *item
);
556 int WMCountInBag(WMBag
*bag
, void *item
);
558 int WMFindInBag(WMBag
*bag
, WMMatchDataProc
*match
, void *cdata
);
560 void* WMBagFirst(WMBag
*bag
, WMBagIterator
*ptr
);
562 void* WMBagLast(WMBag
*bag
, WMBagIterator
*ptr
);
564 /* The following 4 functions assume that the bag doesn't change between calls */
565 void* WMBagNext(WMBag
*bag
, WMBagIterator
*ptr
);
567 void* WMBagPrevious(WMBag
*bag
, WMBagIterator
*ptr
);
569 void* WMBagIteratorAtIndex(WMBag
*bag
, int index
, WMBagIterator
*ptr
);
571 int WMBagIndexForIterator(WMBag
*bag
, WMBagIterator ptr
);
574 /* The following 2 macros assume that the bag doesn't change in the for loop */
575 #define WM_ITERATE_BAG(bag, var, i) \
576 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
577 var = WMBagNext(bag, &(i)))
579 #define WM_ETARETI_BAG(bag, var, i) \
580 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
581 var = WMBagPrevious(bag, &(i)))
585 /* ---[ WINGs/data.c ]---------------------------------------------------- */
587 /* WMData handling */
589 /* Creating/destroying data */
591 WMData
* WMCreateDataWithCapacity(unsigned capacity
);
593 WMData
* WMCreateDataWithLength(unsigned length
);
595 WMData
* WMCreateDataWithBytes(const void *bytes
, unsigned length
);
597 /* destructor is a function called to free the data when releasing the data
598 * object, or NULL if no freeing of data is necesary. */
599 WMData
* WMCreateDataWithBytesNoCopy(void *bytes
, unsigned length
,
600 WMFreeDataProc
*destructor
);
602 WMData
* WMCreateDataWithData(WMData
*aData
);
604 WMData
* WMRetainData(WMData
*aData
);
606 void WMReleaseData(WMData
*aData
);
608 /* Adjusting capacity */
610 void WMSetDataCapacity(WMData
*aData
, unsigned capacity
);
612 void WMSetDataLength(WMData
*aData
, unsigned length
);
614 void WMIncreaseDataLengthBy(WMData
*aData
, unsigned extraLength
);
618 const void* WMDataBytes(WMData
*aData
);
620 void WMGetDataBytes(WMData
*aData
, void *buffer
);
622 void WMGetDataBytesWithLength(WMData
*aData
, void *buffer
, unsigned length
);
624 void WMGetDataBytesWithRange(WMData
*aData
, void *buffer
, WMRange aRange
);
626 WMData
* WMGetSubdataWithRange(WMData
*aData
, WMRange aRange
);
630 Bool
WMIsDataEqualToData(WMData
*aData
, WMData
*anotherData
);
632 unsigned WMGetDataLength(WMData
*aData
);
636 void WMAppendDataBytes(WMData
*aData
, const void *bytes
, unsigned length
);
638 void WMAppendData(WMData
*aData
, WMData
*anotherData
);
642 void WMReplaceDataBytesInRange(WMData
*aData
, WMRange aRange
, const void *bytes
);
644 void WMResetDataBytesInRange(WMData
*aData
, WMRange aRange
);
646 void WMSetData(WMData
*aData
, WMData
*anotherData
);
649 void WMSetDataFormat(WMData
*aData
, unsigned format
);
651 unsigned WMGetDataFormat(WMData
*aData
);
654 /* ---[ WINGs/tree.c ]---------------------------------------------------- */
656 /* Generic Tree and TreeNode */
658 WMTreeNode
* WMCreateTreeNode(void *data
);
660 WMTreeNode
* WMCreateTreeNodeWithDestructor(void *data
, WMFreeDataProc
*destructor
);
662 WMTreeNode
* WMInsertItemInTree(WMTreeNode
*parent
, int index
, void *item
);
664 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
666 WMTreeNode
* WMInsertNodeInTree(WMTreeNode
*parent
, int index
, WMTreeNode
*aNode
);
668 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
670 void WMDestroyTreeNode(WMTreeNode
*aNode
);
672 void WMDeleteLeafForTreeNode(WMTreeNode
*aNode
, int index
);
674 void WMRemoveLeafForTreeNode(WMTreeNode
*aNode
, void *leaf
);
676 void* WMReplaceDataForTreeNode(WMTreeNode
*aNode
, void *newData
);
678 void* WMGetDataForTreeNode(WMTreeNode
*aNode
);
680 int WMGetTreeNodeDepth(WMTreeNode
*aNode
);
682 WMTreeNode
* WMGetParentForTreeNode(WMTreeNode
*aNode
);
684 /* Sort only the leaves of the passed node */
685 void WMSortLeavesForTreeNode(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
687 /* Sort all tree recursively starting from the passed node */
688 void WMSortTree(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
690 /* Returns the first node which matches node's data with cdata by 'match' */
691 WMTreeNode
* WMFindInTree(WMTreeNode
*aTree
, WMMatchDataProc
*match
, void *cdata
);
693 /* Returns the first node where node's data matches cdata by 'match' and node is
694 * at most `limit' depths down from `aTree'. */
695 WMTreeNode
*WMFindInTreeWithDepthLimit(WMTreeNode
* aTree
, WMMatchDataProc
* match
, void *cdata
, int limit
);
697 /* Returns first tree node that has data == cdata */
698 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(aTree, NULL, cdata)
700 /* Walk every node of aNode with `walk' */
701 void WMTreeWalk(WMTreeNode
*aNode
, WMTreeWalkProc
* walk
, void *data
, Bool DepthFirst
);
703 /* ---[ WINGs/data.c ]---------------------------------------------------- */
706 WMNotification
* WMCreateNotification(const char *name
, void *object
, void *clientData
);
708 void WMReleaseNotification(WMNotification
*notification
);
710 WMNotification
* WMRetainNotification(WMNotification
*notification
);
712 void* WMGetNotificationClientData(WMNotification
*notification
);
714 void* WMGetNotificationObject(WMNotification
*notification
);
716 const char* WMGetNotificationName(WMNotification
*notification
);
719 void WMAddNotificationObserver(WMNotificationObserverAction
*observerAction
,
720 void *observer
, const char *name
, void *object
);
722 void WMPostNotification(WMNotification
*notification
);
724 void WMRemoveNotificationObserver(void *observer
);
726 void WMRemoveNotificationObserverWithName(void *observer
, const char *name
,
729 void WMPostNotificationName(const char *name
, void *object
, void *clientData
);
731 WMNotificationQueue
* WMGetDefaultNotificationQueue(void);
733 WMNotificationQueue
* WMCreateNotificationQueue(void);
735 void WMDequeueNotificationMatching(WMNotificationQueue
*queue
,
736 WMNotification
*notification
,
739 void WMEnqueueNotification(WMNotificationQueue
*queue
,
740 WMNotification
*notification
,
741 WMPostingStyle postingStyle
);
743 void WMEnqueueCoalesceNotification(WMNotificationQueue
*queue
,
744 WMNotification
*notification
,
745 WMPostingStyle postingStyle
,
746 unsigned coalesceMask
);
749 /* ---[ WINGs/proplist.c ]------------------------------------------------ */
751 /* Property Lists handling */
753 void WMPLSetCaseSensitive(Bool caseSensitive
);
755 WMPropList
* WMCreatePLString(const char *str
);
757 WMPropList
* WMCreatePLData(WMData
*data
);
759 WMPropList
* WMCreatePLDataWithBytes(const unsigned char *bytes
, unsigned int length
);
761 WMPropList
* WMCreatePLDataWithBytesNoCopy(unsigned char *bytes
,
763 WMFreeDataProc
*destructor
);
765 WMPropList
* WMCreatePLArray(WMPropList
*elem
, ...);
767 WMPropList
* WMCreatePLDictionary(WMPropList
*key
, WMPropList
*value
, ...);
769 WMPropList
* WMRetainPropList(WMPropList
*plist
);
771 void WMReleasePropList(WMPropList
*plist
);
773 /* Objects inserted in arrays and dictionaries will be retained,
774 * so you can safely release them after insertion.
775 * For dictionaries both the key and value are retained.
776 * Objects removed from arrays or dictionaries are released */
777 void WMInsertInPLArray(WMPropList
*plist
, int index
, WMPropList
*item
);
779 void WMAddToPLArray(WMPropList
*plist
, WMPropList
*item
);
781 void WMDeleteFromPLArray(WMPropList
*plist
, int index
);
783 void WMRemoveFromPLArray(WMPropList
*plist
, WMPropList
*item
);
785 void WMPutInPLDictionary(WMPropList
*plist
, WMPropList
*key
, WMPropList
*value
);
787 void WMRemoveFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
789 /* It will insert all key/value pairs from source into dest, overwriting
790 * the values with the same keys from dest, keeping all values with keys
791 * only present in dest unchanged */
792 WMPropList
* WMMergePLDictionaries(WMPropList
*dest
, WMPropList
*source
,
795 /* It will remove all key/value pairs from dest for which there is an
796 * identical key/value present in source. Entires only present in dest, or
797 * which have different values in dest than in source will be preserved. */
798 WMPropList
* WMSubtractPLDictionaries(WMPropList
*dest
, WMPropList
*source
,
801 int WMGetPropListItemCount(WMPropList
*plist
);
803 Bool
WMIsPLString(WMPropList
*plist
);
805 Bool
WMIsPLData(WMPropList
*plist
);
807 Bool
WMIsPLArray(WMPropList
*plist
);
809 Bool
WMIsPLDictionary(WMPropList
*plist
);
811 Bool
WMIsPropListEqualTo(WMPropList
*plist
, WMPropList
*other
);
813 /* Returns a reference. Do not free it! */
814 char* WMGetFromPLString(WMPropList
*plist
);
816 /* Returns a reference. Do not free it! */
817 WMData
* WMGetFromPLData(WMPropList
*plist
);
819 /* Returns a reference. Do not free it! */
820 const unsigned char* WMGetPLDataBytes(WMPropList
*plist
);
822 int WMGetPLDataLength(WMPropList
*plist
);
824 /* Returns a reference. */
825 WMPropList
* WMGetFromPLArray(WMPropList
*plist
, int index
);
827 /* Returns a reference. */
828 WMPropList
* WMGetFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
830 /* Returns a PropList array with all the dictionary keys. Release it when
831 * you're done. Keys in array are retained from the original dictionary
832 * not copied and need NOT to be released individually. */
833 WMPropList
* WMGetPLDictionaryKeys(WMPropList
*plist
);
835 /* Creates only the first level deep object. All the elements inside are
836 * retained from the original */
837 WMPropList
* WMShallowCopyPropList(WMPropList
*plist
);
839 /* Makes a completely separate replica of the original proplist */
840 WMPropList
* WMDeepCopyPropList(WMPropList
*plist
);
842 WMPropList
* WMCreatePropListFromDescription(const char *desc
);
844 /* Free the returned string when you no longer need it */
845 char* WMGetPropListDescription(WMPropList
*plist
, Bool indented
);
847 WMPropList
* WMReadPropListFromFile(const char *file
);
849 WMPropList
* WMReadPropListFromPipe(const char *command
);
851 Bool
WMWritePropListToFile(WMPropList
*plist
, const char *path
);
853 /* ---[ WINGs/userdefaults.c ]-------------------------------------------- */
855 /* don't free the returned string */
856 const char* wusergnusteppath(void);
858 /* Free the returned string when you no longer need it */
859 char* wdefaultspathfordomain(const char *domain
);
861 /* Free the returned string when you no longer need it */
862 char* wglobaldefaultspathfordomain(const char *domain
);
864 WMUserDefaults
* WMGetStandardUserDefaults(void);
866 WMUserDefaults
* WMGetDefaultsFromPath(const char *path
);
868 void WMSynchronizeUserDefaults(WMUserDefaults
*database
);
870 void WMSaveUserDefaults(WMUserDefaults
*database
);
872 void WMEnableUDPeriodicSynchronization(WMUserDefaults
*database
, Bool enable
);
874 /* Returns a WMPropList array with all the keys in the user defaults database.
875 * Free the array with WMReleasePropList() when no longer needed.
876 * Keys in array are just retained references to the original keys */
877 WMPropList
* WMGetUDKeys(WMUserDefaults
*database
);
879 WMPropList
* WMGetUDObjectForKey(WMUserDefaults
*database
, const char *defaultName
);
881 void WMSetUDObjectForKey(WMUserDefaults
*database
, WMPropList
*object
,
882 const char *defaultName
);
884 void WMRemoveUDObjectForKey(WMUserDefaults
*database
, const char *defaultName
);
886 /* Returns a reference. Do not free it! */
887 char* WMGetUDStringForKey(WMUserDefaults
*database
, const char *defaultName
);
889 int WMGetUDIntegerForKey(WMUserDefaults
*database
, const char *defaultName
);
891 float WMGetUDFloatForKey(WMUserDefaults
*database
, const char *defaultName
);
893 Bool
WMGetUDBoolForKey(WMUserDefaults
*database
, const char *defaultName
);
895 void WMSetUDStringForKey(WMUserDefaults
*database
, const char *value
,
896 const char *defaultName
);
898 void WMSetUDIntegerForKey(WMUserDefaults
*database
, int value
,
899 const char *defaultName
);
901 void WMSetUDFloatForKey(WMUserDefaults
*database
, float value
,
902 const char *defaultName
);
904 void WMSetUDBoolForKey(WMUserDefaults
*database
, Bool value
,
905 const char *defaultName
);
907 WMPropList
* WMGetUDSearchList(WMUserDefaults
*database
);
909 void WMSetUDSearchList(WMUserDefaults
*database
, WMPropList
*list
);
911 extern char *WMUserDefaultsDidChangeNotification
;
914 /* ---[ WINGs/menuparser.c ]---------------------------------------------- */
917 typedef struct w_menu_parser
*WMenuParser
;
920 WMenuParser
WMenuParserCreate(const char *file_name
, void *file
, const char *include_default_paths
);
922 void WMenuParserRegisterSimpleMacro(WMenuParser parser
, const char *name
, const char *value
);
924 void WMenuParserError(WMenuParser parser
, const char *msg
, ...)
925 __attribute__ ((format (printf
, 2, 3)));
927 const char *WMenuParserGetFilename(WMenuParser parser
);
929 Bool
WMenuParserGetLine(WMenuParser parser
, char **title
, char **command
, char **parameter
, char **shortcut
);
931 void WMenuParserDelete(WMenuParser parser
);
934 /*-------------------------------------------------------------------------*/
936 /* Global variables */
938 extern int WCErrorCode
;
941 /*-------------------------------------------------------------------------*/
945 #endif /* __cplusplus */