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);\
93 #endif /* __cplusplus */
107 } WMNotificationCoalescing
;
112 WBNotFound
= INT_MIN
, /* element was not found in WMBag */
113 WANotFound
= -1 /* element was not found in WMArray */
117 typedef struct W_Array WMArray
;
118 typedef struct W_Bag WMBag
;
119 typedef struct W_Data WMData
;
120 typedef struct W_TreeNode WMTreeNode
;
121 typedef struct W_HashTable WMHashTable
;
122 typedef struct W_UserDefaults WMUserDefaults
;
123 typedef struct W_Notification WMNotification
;
124 typedef struct W_NotificationQueue WMNotificationQueue
;
125 typedef struct W_Host WMHost
;
126 typedef struct W_Connection WMConnection
;
127 typedef struct W_PropList WMPropList
;
131 /* Some typedefs for the handler stuff */
132 typedef void *WMHandlerID
;
134 typedef void WMCallback(void *data
);
136 typedef void WMInputProc(int fd
, int mask
, void *clientData
);
140 typedef int WMCompareDataProc(const void *item1
, const void *item2
);
141 typedef void WMTreeWalkProc(WMTreeNode
*aNode
, void *data
);
143 typedef void WMFreeDataProc(void *data
);
145 /* Used by WMBag or WMArray for matching data */
146 typedef int WMMatchDataProc(const void *item
, const void *cdata
);
157 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
166 /* NULL is pointer hash */
167 unsigned (*hash
)(const void *);
168 /* NULL is pointer compare */
169 Bool (*keyIsEqual
)(const void *, const void *);
170 /* NULL does nothing */
171 void* (*retainKey
)(const void *);
172 /* NULL does nothing */
173 void (*releaseKey
)(const void *);
174 } WMHashTableCallbacks
;
177 typedef int WMArrayIterator
;
178 typedef void *WMBagIterator
;
181 typedef void WMNotificationObserverAction(void *observerData
,
182 WMNotification
*notification
);
185 /* ---[ WINGs/memory.c ]-------------------------------------------------- */
187 void* wmalloc(size_t size
);
188 void* wrealloc(void *ptr
, size_t newsize
);
189 void wfree(void *ptr
);
191 void wrelease(void *ptr
);
192 void* wretain(void *ptr
);
194 typedef void waborthandler(int);
196 waborthandler
* wsetabort(waborthandler
* handler
);
198 /* ---[ WINGs/error.c ]--------------------------------------------------- */
201 WMESSAGE_TYPE_MESSAGE
,
202 WMESSAGE_TYPE_WARNING
,
207 #define wmessage(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_MESSAGE, fmt, ## args)
208 #define wwarning(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_WARNING, fmt, ## args)
209 #define werror(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_ERROR, fmt, ## args)
210 #define wfatal(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_FATAL, fmt, ## args)
212 void __wmessage(const char *func
, const char *file
, int line
, int type
, const char *msg
, ...)
213 __attribute__((__format__(printf
,5,6)));
215 /* ---[ WINGs/findfile.c ]------------------------------------------------ */
217 /* For the 4 function below, you have to free the returned string when you no longer need it */
219 char* wfindfile(const char *paths
, const char *file
);
221 char* wfindfileinlist(char *const *path_list
, const char *file
);
223 char* wfindfileinarray(WMPropList
* array
, const char *file
);
225 char* wexpandpath(const char *path
);
227 int wcopy_file(const char *toPath
, const char *srcFile
, const char *destFile
);
229 /* don't free the returned string */
230 char* wgethomedir(void);
232 /* ---[ WINGs/proplist.c ]------------------------------------------------ */
234 int wmkdirhier(const char *path
);
235 int wrmdirhier(const char *path
);
237 /* ---[ WINGs/string.c ]-------------------------------------------------- */
239 char *wstrdup(const char *str
);
240 char* wstrndup(const char *str
, size_t len
);
242 /* Concatenate str1 with str2 and return that in a newly malloc'ed string.
243 * str1 and str2 can be any strings including static and constant strings.
244 * str1 and str2 will not be modified.
245 * Free the returned string when you're done with it. */
246 char* wstrconcat(const char *str1
, const char *str2
);
248 /* This will append src to dst, and return dst. dst MUST be either NULL
249 * or a string that was a result of a dynamic allocation (malloc, realloc
250 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
251 * Modifies dst (no new string is created except if dst==NULL in which case
252 * it is equivalent to calling wstrdup(src) ).
253 * The returned address may be different from the original address of dst,
254 * so always assign the returned address to avoid dangling pointers. */
255 char* wstrappend(char *dst
, const char *src
);
257 size_t wstrlcpy(char *, const char *, size_t);
258 size_t wstrlcat(char *, const char *, size_t);
261 void wtokensplit(char *command
, char ***argv
, int *argc
);
263 char* wtokennext(char *word
, char **next
);
265 char* wtokenjoin(char **list
, int count
);
267 void wtokenfree(char **tokens
, int count
);
269 char* wtrimspace(const char *s
);
271 /* transform `s' so that the result is safe to pass to the shell as an argument.
272 * returns a newly allocated string.
273 * with very heavy inspirations from NetBSD's shquote(3).
275 char *wshellquote(const char *s
);
277 /* ---[ WINGs/wmisc.c ]--------------------------------------------------- */
279 WMRange
wmkrange(int start
, int count
);
281 /* ---[ WINGs/usleep.c ]-------------------------------------------------- */
283 void wusleep(unsigned int usec
);
285 /* ---[ WINGs/handlers.c ]------------------------------------------------ */
287 /* Event handlers: timer, idle, input */
289 WMHandlerID
WMAddTimerHandler(int milliseconds
, WMCallback
*callback
,
292 WMHandlerID
WMAddPersistentTimerHandler(int milliseconds
, WMCallback
*callback
,
295 void WMDeleteTimerWithClientData(void *cdata
);
297 void WMDeleteTimerHandler(WMHandlerID handlerID
);
299 WMHandlerID
WMAddIdleHandler(WMCallback
*callback
, void *cdata
);
301 void WMDeleteIdleHandler(WMHandlerID handlerID
);
303 WMHandlerID
WMAddInputHandler(int fd
, int condition
, WMInputProc
*proc
,
306 void WMDeleteInputHandler(WMHandlerID handlerID
);
309 /* This function is used _only_ if you create a non-GUI program.
310 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
311 * This function will handle all input/timer/idle events, then return.
314 void WHandleEvents(void);
316 /* ---[ WINGs/hashtable.c ]----------------------------------------------- */
319 WMHashTable
* WMCreateHashTable(WMHashTableCallbacks callbacks
);
321 void WMFreeHashTable(WMHashTable
*table
);
323 void WMResetHashTable(WMHashTable
*table
);
325 unsigned WMCountHashTable(WMHashTable
*table
);
327 void* WMHashGet(WMHashTable
*table
, const void *key
);
329 /* Returns True if there is a value associated with <key> in the table, in
330 * which case <retKey> and <retItem> will contain the item's internal key
331 * address and the item's value respectively.
332 * If there is no value associated with <key> it will return False and in
333 * this case <retKey> and <retItem> will be undefined.
334 * Use this when you need to perform your own custom retain/release mechanism
335 * which requires access to the keys too.
337 Bool
WMHashGetItemAndKey(WMHashTable
*table
, const void *key
,
338 void **retItem
, void **retKey
);
340 /* put data in table, replacing already existing data and returning
342 void* WMHashInsert(WMHashTable
*table
, const void *key
, const void *data
);
344 void WMHashRemove(WMHashTable
*table
, const void *key
);
346 /* warning: do not manipulate the table while using the enumerator functions */
347 WMHashEnumerator
WMEnumerateHashTable(WMHashTable
*table
);
349 void* WMNextHashEnumeratorItem(WMHashEnumerator
*enumerator
);
351 void* WMNextHashEnumeratorKey(WMHashEnumerator
*enumerator
);
353 /* Returns True if there is a next element, in which case key and item
354 * will contain the next element's key and value respectively.
355 * If there is no next element available it will return False and in this
356 * case key and item will be undefined.
358 Bool
WMNextHashEnumeratorItemAndKey(WMHashEnumerator
*enumerator
,
359 void **item
, void **key
);
364 /* some predefined callback sets */
366 extern const WMHashTableCallbacks WMIntHashCallbacks
;
367 /* sizeof(keys) are <= sizeof(void*) */
369 extern const WMHashTableCallbacks WMStringHashCallbacks
;
370 /* keys are strings. Strings will be copied with wstrdup()
371 * and freed with wfree() */
373 extern const WMHashTableCallbacks WMStringPointerHashCallbacks
;
374 /* keys are strings, but they are not copied */
377 /* ---[ WINGs/array.c ]--------------------------------------------------- */
380 * WMArray use an array to store the elements.
381 * Item indexes may be only positive integer numbers.
382 * The array cannot contain holes in it.
385 * Fast [O(1)] access to elements
386 * Fast [O(1)] push/pop
389 * A little slower [O(n)] for insertion/deletion of elements that
393 WMArray
* WMCreateArray(int initialSize
);
395 WMArray
* WMCreateArrayWithDestructor(int initialSize
, WMFreeDataProc
*destructor
);
397 WMArray
* WMCreateArrayWithArray(WMArray
*array
);
399 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
401 void WMEmptyArray(WMArray
*array
);
403 void WMFreeArray(WMArray
*array
);
405 int WMGetArrayItemCount(WMArray
*array
);
407 /* appends other to array. other remains unchanged */
408 void WMAppendArray(WMArray
*array
, WMArray
*other
);
410 /* add will place the element at the end of the array */
411 void WMAddToArray(WMArray
*array
, void *item
);
413 /* insert will increment the index of elements after it by 1 */
414 void WMInsertInArray(WMArray
*array
, int index
, void *item
);
416 /* replace and set will return the old item WITHOUT calling the
417 * destructor on it even if its available. Free the returned item yourself.
419 void* WMReplaceInArray(WMArray
*array
, int index
, void *item
);
421 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
423 /* delete and remove will remove the elements and cause the elements
424 * after them to decrement their indexes by 1. Also will call the
425 * destructor on the deleted element if there's one available.
427 int WMDeleteFromArray(WMArray
*array
, int index
);
429 #define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
431 int WMRemoveFromArrayMatching(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
433 void* WMGetFromArray(WMArray
*array
, int index
);
435 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
437 /* pop will return the last element from the array, also removing it
438 * from the array. The destructor is NOT called, even if available.
439 * Free the returned element if needed by yourself
441 void* WMPopFromArray(WMArray
*array
);
443 int WMFindInArray(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
445 int WMCountInArray(WMArray
*array
, void *item
);
447 /* comparer must return:
452 void WMSortArray(WMArray
*array
, WMCompareDataProc
*comparer
);
454 void WMMapArray(WMArray
*array
, void (*function
)(void*, void*), void *data
);
456 WMArray
* WMGetSubarrayWithRange(WMArray
* array
, WMRange aRange
);
458 void* WMArrayFirst(WMArray
*array
, WMArrayIterator
*iter
);
460 void* WMArrayLast(WMArray
*array
, WMArrayIterator
*iter
);
462 /* The following 2 functions assume that the array doesn't change between calls */
463 void* WMArrayNext(WMArray
*array
, WMArrayIterator
*iter
);
465 void* WMArrayPrevious(WMArray
*array
, WMArrayIterator
*iter
);
468 /* The following 2 macros assume that the array doesn't change in the for loop */
469 #define WM_ITERATE_ARRAY(array, var, i) \
470 for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
471 var = WMArrayNext(array, &(i)))
473 #define WM_ETARETI_ARRAY(array, var, i) \
474 for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
475 var = WMArrayPrevious(array, &(i)))
477 /* ---[ WINGs/bagtree.c ]------------------------------------------------- */
480 * Tree bags use a red-black tree for storage.
481 * Item indexes may be any integer number.
484 * O(lg n) insertion/deletion/search
485 * Good for large numbers of elements with sparse indexes
488 * O(lg n) insertion/deletion/search
489 * Slow for storing small numbers of elements
492 #define WMCreateBag(size) WMCreateTreeBag()
494 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
496 WMBag
* WMCreateTreeBag(void);
498 WMBag
* WMCreateTreeBagWithDestructor(WMFreeDataProc
*destructor
);
500 int WMGetBagItemCount(WMBag
*bag
);
502 void WMAppendBag(WMBag
*bag
, WMBag
*other
);
504 void WMPutInBag(WMBag
*bag
, void *item
);
506 /* insert will increment the index of elements after it by 1 */
507 void WMInsertInBag(WMBag
*bag
, int index
, void *item
);
509 /* erase will remove the element from the bag,
510 * but will keep the index of the other elements unchanged */
511 int WMEraseFromBag(WMBag
*bag
, int index
);
513 /* delete and remove will remove the elements and cause the elements
514 * after them to decrement their indexes by 1 */
515 int WMDeleteFromBag(WMBag
*bag
, int index
);
517 int WMRemoveFromBag(WMBag
*bag
, void *item
);
519 void* WMGetFromBag(WMBag
*bag
, int index
);
521 void* WMReplaceInBag(WMBag
*bag
, int index
, void *item
);
523 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
525 /* comparer must return:
530 void WMSortBag(WMBag
*bag
, WMCompareDataProc
*comparer
);
532 void WMEmptyBag(WMBag
*bag
);
534 void WMFreeBag(WMBag
*bag
);
536 void WMMapBag(WMBag
*bag
, void (*function
)(void*, void*), void *data
);
538 int WMGetFirstInBag(WMBag
*bag
, void *item
);
540 int WMCountInBag(WMBag
*bag
, void *item
);
542 int WMFindInBag(WMBag
*bag
, WMMatchDataProc
*match
, void *cdata
);
544 void* WMBagFirst(WMBag
*bag
, WMBagIterator
*ptr
);
546 void* WMBagLast(WMBag
*bag
, WMBagIterator
*ptr
);
548 /* The following 4 functions assume that the bag doesn't change between calls */
549 void* WMBagNext(WMBag
*bag
, WMBagIterator
*ptr
);
551 void* WMBagPrevious(WMBag
*bag
, WMBagIterator
*ptr
);
553 void* WMBagIteratorAtIndex(WMBag
*bag
, int index
, WMBagIterator
*ptr
);
555 int WMBagIndexForIterator(WMBag
*bag
, WMBagIterator ptr
);
558 /* The following 2 macros assume that the bag doesn't change in the for loop */
559 #define WM_ITERATE_BAG(bag, var, i) \
560 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
561 var = WMBagNext(bag, &(i)))
563 #define WM_ETARETI_BAG(bag, var, i) \
564 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
565 var = WMBagPrevious(bag, &(i)))
569 /* ---[ WINGs/data.c ]---------------------------------------------------- */
571 /* WMData handling */
573 /* Creating/destroying data */
575 WMData
* WMCreateDataWithCapacity(unsigned capacity
);
577 WMData
* WMCreateDataWithLength(unsigned length
);
579 WMData
* WMCreateDataWithBytes(const void *bytes
, unsigned length
);
581 /* destructor is a function called to free the data when releasing the data
582 * object, or NULL if no freeing of data is necesary. */
583 WMData
* WMCreateDataWithBytesNoCopy(void *bytes
, unsigned length
,
584 WMFreeDataProc
*destructor
);
586 WMData
* WMCreateDataWithData(WMData
*aData
);
588 WMData
* WMRetainData(WMData
*aData
);
590 void WMReleaseData(WMData
*aData
);
592 /* Adjusting capacity */
594 void WMSetDataCapacity(WMData
*aData
, unsigned capacity
);
596 void WMSetDataLength(WMData
*aData
, unsigned length
);
598 void WMIncreaseDataLengthBy(WMData
*aData
, unsigned extraLength
);
602 const void* WMDataBytes(WMData
*aData
);
604 void WMGetDataBytes(WMData
*aData
, void *buffer
);
606 void WMGetDataBytesWithLength(WMData
*aData
, void *buffer
, unsigned length
);
608 void WMGetDataBytesWithRange(WMData
*aData
, void *buffer
, WMRange aRange
);
610 WMData
* WMGetSubdataWithRange(WMData
*aData
, WMRange aRange
);
614 Bool
WMIsDataEqualToData(WMData
*aData
, WMData
*anotherData
);
616 unsigned WMGetDataLength(WMData
*aData
);
620 void WMAppendDataBytes(WMData
*aData
, const void *bytes
, unsigned length
);
622 void WMAppendData(WMData
*aData
, WMData
*anotherData
);
626 void WMReplaceDataBytesInRange(WMData
*aData
, WMRange aRange
, const void *bytes
);
628 void WMResetDataBytesInRange(WMData
*aData
, WMRange aRange
);
630 void WMSetData(WMData
*aData
, WMData
*anotherData
);
633 void WMSetDataFormat(WMData
*aData
, unsigned format
);
635 unsigned WMGetDataFormat(WMData
*aData
);
638 /* ---[ WINGs/tree.c ]---------------------------------------------------- */
640 /* Generic Tree and TreeNode */
642 WMTreeNode
* WMCreateTreeNode(void *data
);
644 WMTreeNode
* WMCreateTreeNodeWithDestructor(void *data
, WMFreeDataProc
*destructor
);
646 WMTreeNode
* WMInsertItemInTree(WMTreeNode
*parent
, int index
, void *item
);
648 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
650 WMTreeNode
* WMInsertNodeInTree(WMTreeNode
*parent
, int index
, WMTreeNode
*aNode
);
652 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
654 void WMDestroyTreeNode(WMTreeNode
*aNode
);
656 void WMDeleteLeafForTreeNode(WMTreeNode
*aNode
, int index
);
658 void WMRemoveLeafForTreeNode(WMTreeNode
*aNode
, void *leaf
);
660 void* WMReplaceDataForTreeNode(WMTreeNode
*aNode
, void *newData
);
662 void* WMGetDataForTreeNode(WMTreeNode
*aNode
);
664 int WMGetTreeNodeDepth(WMTreeNode
*aNode
);
666 WMTreeNode
* WMGetParentForTreeNode(WMTreeNode
*aNode
);
668 /* Sort only the leaves of the passed node */
669 void WMSortLeavesForTreeNode(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
671 /* Sort all tree recursively starting from the passed node */
672 void WMSortTree(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
674 /* Returns the first node which matches node's data with cdata by 'match' */
675 WMTreeNode
* WMFindInTree(WMTreeNode
*aTree
, WMMatchDataProc
*match
, void *cdata
);
677 /* Returns the first node where node's data matches cdata by 'match' and node is
678 * at most `limit' depths down from `aTree'. */
679 WMTreeNode
*WMFindInTreeWithDepthLimit(WMTreeNode
* aTree
, WMMatchDataProc
* match
, void *cdata
, int limit
);
681 /* Returns first tree node that has data == cdata */
682 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(aTree, NULL, cdata)
684 /* Walk every node of aNode with `walk' */
685 void WMTreeWalk(WMTreeNode
*aNode
, WMTreeWalkProc
* walk
, void *data
, Bool DepthFirst
);
687 /* ---[ WINGs/data.c ]---------------------------------------------------- */
690 WMNotification
* WMCreateNotification(const char *name
, void *object
, void *clientData
);
692 void WMReleaseNotification(WMNotification
*notification
);
694 WMNotification
* WMRetainNotification(WMNotification
*notification
);
696 void* WMGetNotificationClientData(WMNotification
*notification
);
698 void* WMGetNotificationObject(WMNotification
*notification
);
700 const char* WMGetNotificationName(WMNotification
*notification
);
703 void WMAddNotificationObserver(WMNotificationObserverAction
*observerAction
,
704 void *observer
, const char *name
, void *object
);
706 void WMPostNotification(WMNotification
*notification
);
708 void WMRemoveNotificationObserver(void *observer
);
710 void WMRemoveNotificationObserverWithName(void *observer
, const char *name
,
713 void WMPostNotificationName(const char *name
, void *object
, void *clientData
);
715 WMNotificationQueue
* WMGetDefaultNotificationQueue(void);
717 WMNotificationQueue
* WMCreateNotificationQueue(void);
719 void WMDequeueNotificationMatching(WMNotificationQueue
*queue
,
720 WMNotification
*notification
,
723 void WMEnqueueNotification(WMNotificationQueue
*queue
,
724 WMNotification
*notification
,
725 WMPostingStyle postingStyle
);
727 void WMEnqueueCoalesceNotification(WMNotificationQueue
*queue
,
728 WMNotification
*notification
,
729 WMPostingStyle postingStyle
,
730 unsigned coalesceMask
);
733 /* ---[ WINGs/proplist.c ]------------------------------------------------ */
735 /* Property Lists handling */
737 void WMPLSetCaseSensitive(Bool caseSensitive
);
739 WMPropList
* WMCreatePLString(const char *str
);
741 WMPropList
* WMCreatePLData(WMData
*data
);
743 WMPropList
* WMCreatePLDataWithBytes(const unsigned char *bytes
, unsigned int length
);
745 WMPropList
* WMCreatePLDataWithBytesNoCopy(unsigned char *bytes
,
747 WMFreeDataProc
*destructor
);
749 WMPropList
* WMCreatePLArray(WMPropList
*elem
, ...);
751 WMPropList
* WMCreatePLDictionary(WMPropList
*key
, WMPropList
*value
, ...);
753 WMPropList
* WMRetainPropList(WMPropList
*plist
);
755 void WMReleasePropList(WMPropList
*plist
);
757 /* Objects inserted in arrays and dictionaries will be retained,
758 * so you can safely release them after insertion.
759 * For dictionaries both the key and value are retained.
760 * Objects removed from arrays or dictionaries are released */
761 void WMInsertInPLArray(WMPropList
*plist
, int index
, WMPropList
*item
);
763 void WMAddToPLArray(WMPropList
*plist
, WMPropList
*item
);
765 void WMDeleteFromPLArray(WMPropList
*plist
, int index
);
767 void WMRemoveFromPLArray(WMPropList
*plist
, WMPropList
*item
);
769 void WMPutInPLDictionary(WMPropList
*plist
, WMPropList
*key
, WMPropList
*value
);
771 void WMRemoveFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
773 /* It will insert all key/value pairs from source into dest, overwriting
774 * the values with the same keys from dest, keeping all values with keys
775 * only present in dest unchanged */
776 WMPropList
* WMMergePLDictionaries(WMPropList
*dest
, WMPropList
*source
,
779 /* It will remove all key/value pairs from dest for which there is an
780 * identical key/value present in source. Entires only present in dest, or
781 * which have different values in dest than in source will be preserved. */
782 WMPropList
* WMSubtractPLDictionaries(WMPropList
*dest
, WMPropList
*source
,
785 int WMGetPropListItemCount(WMPropList
*plist
);
787 Bool
WMIsPLString(WMPropList
*plist
);
789 Bool
WMIsPLData(WMPropList
*plist
);
791 Bool
WMIsPLArray(WMPropList
*plist
);
793 Bool
WMIsPLDictionary(WMPropList
*plist
);
795 Bool
WMIsPropListEqualTo(WMPropList
*plist
, WMPropList
*other
);
797 /* Returns a reference. Do not free it! */
798 char* WMGetFromPLString(WMPropList
*plist
);
800 /* Returns a reference. Do not free it! */
801 WMData
* WMGetFromPLData(WMPropList
*plist
);
803 /* Returns a reference. Do not free it! */
804 const unsigned char* WMGetPLDataBytes(WMPropList
*plist
);
806 int WMGetPLDataLength(WMPropList
*plist
);
808 /* Returns a reference. */
809 WMPropList
* WMGetFromPLArray(WMPropList
*plist
, int index
);
811 /* Returns a reference. */
812 WMPropList
* WMGetFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
814 /* Returns a PropList array with all the dictionary keys. Release it when
815 * you're done. Keys in array are retained from the original dictionary
816 * not copied and need NOT to be released individually. */
817 WMPropList
* WMGetPLDictionaryKeys(WMPropList
*plist
);
819 /* Creates only the first level deep object. All the elements inside are
820 * retained from the original */
821 WMPropList
* WMShallowCopyPropList(WMPropList
*plist
);
823 /* Makes a completely separate replica of the original proplist */
824 WMPropList
* WMDeepCopyPropList(WMPropList
*plist
);
826 WMPropList
* WMCreatePropListFromDescription(const char *desc
);
828 /* Free the returned string when you no longer need it */
829 char* WMGetPropListDescription(WMPropList
*plist
, Bool indented
);
831 WMPropList
* WMReadPropListFromFile(const char *file
);
833 WMPropList
* WMReadPropListFromPipe(const char *command
);
835 Bool
WMWritePropListToFile(WMPropList
*plist
, const char *path
);
837 /* ---[ WINGs/userdefaults.c ]-------------------------------------------- */
839 /* don't free the returned string */
840 const char* wusergnusteppath(void);
842 /* Free the returned string when you no longer need it */
843 char* wdefaultspathfordomain(const char *domain
);
845 /* Free the returned string when you no longer need it */
846 char* wglobaldefaultspathfordomain(const char *domain
);
848 WMUserDefaults
* WMGetStandardUserDefaults(void);
850 WMUserDefaults
* WMGetDefaultsFromPath(const char *path
);
852 void WMSynchronizeUserDefaults(WMUserDefaults
*database
);
854 void WMSaveUserDefaults(WMUserDefaults
*database
);
856 void WMEnableUDPeriodicSynchronization(WMUserDefaults
*database
, Bool enable
);
858 /* Returns a WMPropList array with all the keys in the user defaults database.
859 * Free the array with WMReleasePropList() when no longer needed.
860 * Keys in array are just retained references to the original keys */
861 WMPropList
* WMGetUDKeys(WMUserDefaults
*database
);
863 WMPropList
* WMGetUDObjectForKey(WMUserDefaults
*database
, const char *defaultName
);
865 void WMSetUDObjectForKey(WMUserDefaults
*database
, WMPropList
*object
,
866 const char *defaultName
);
868 void WMRemoveUDObjectForKey(WMUserDefaults
*database
, const char *defaultName
);
870 /* Returns a reference. Do not free it! */
871 char* WMGetUDStringForKey(WMUserDefaults
*database
, const char *defaultName
);
873 int WMGetUDIntegerForKey(WMUserDefaults
*database
, const char *defaultName
);
875 float WMGetUDFloatForKey(WMUserDefaults
*database
, const char *defaultName
);
877 Bool
WMGetUDBoolForKey(WMUserDefaults
*database
, const char *defaultName
);
879 void WMSetUDStringForKey(WMUserDefaults
*database
, const char *value
,
880 const char *defaultName
);
882 void WMSetUDIntegerForKey(WMUserDefaults
*database
, int value
,
883 const char *defaultName
);
885 void WMSetUDFloatForKey(WMUserDefaults
*database
, float value
,
886 const char *defaultName
);
888 void WMSetUDBoolForKey(WMUserDefaults
*database
, Bool value
,
889 const char *defaultName
);
891 WMPropList
* WMGetUDSearchList(WMUserDefaults
*database
);
893 void WMSetUDSearchList(WMUserDefaults
*database
, WMPropList
*list
);
895 extern char *WMUserDefaultsDidChangeNotification
;
898 /* ---[ WINGs/menuparser.c ]---------------------------------------------- */
901 typedef struct w_menu_parser
*WMenuParser
;
904 WMenuParser
WMenuParserCreate(const char *file_name
, void *file
, const char *include_default_paths
);
906 void WMenuParserRegisterSimpleMacro(WMenuParser parser
, const char *name
, const char *value
);
908 void WMenuParserError(WMenuParser parser
, const char *msg
, ...)
909 __attribute__ ((format (printf
, 2, 3)));
911 const char *WMenuParserGetFilename(WMenuParser parser
);
913 Bool
WMenuParserGetLine(WMenuParser parser
, char **title
, char **command
, char **parameter
, char **shortcut
);
915 void WMenuParserDelete(WMenuParser parser
);
918 /*-------------------------------------------------------------------------*/
920 /* Global variables */
922 extern int WCErrorCode
;
925 /*-------------------------------------------------------------------------*/
929 #endif /* __cplusplus */