From 8bb50a63202996f210ed1459306e1942411d1008 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 3 Oct 2001 02:05:53 +0000 Subject: [PATCH] Added old libPropList compatibility through proplist-compat.h --- WINGs/WINGs/Makefile.am | 2 +- WINGs/WINGs/WUtil.h | 14 +-- WINGs/WINGs/proplist-compat.h | 74 +++++++++++++ WINGs/proplist.c | 198 +++++++++++++++++----------------- 4 files changed, 181 insertions(+), 107 deletions(-) create mode 100644 WINGs/WINGs/proplist-compat.h diff --git a/WINGs/WINGs/Makefile.am b/WINGs/WINGs/Makefile.am index 0c5e38f0..eb725be1 100644 --- a/WINGs/WINGs/Makefile.am +++ b/WINGs/WINGs/Makefile.am @@ -5,5 +5,5 @@ AUTOMAKE_OPTIONS = no-dependencies # is this a kluge? if so, how should i do it? includedir = @includedir@/WINGs -include_HEADERS = WINGs.h WUtil.h WINGsP.h +include_HEADERS = WINGs.h WUtil.h WINGsP.h proplist-compat.h diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h index 9a2cf790..f0a9aef4 100644 --- a/WINGs/WINGs/WUtil.h +++ b/WINGs/WINGs/WUtil.h @@ -757,6 +757,10 @@ WMPropList* WMCreatePLArray(WMPropList *elem, ...); WMPropList* WMCreatePLDictionary(WMPropList *key, WMPropList *value, ...); +WMPropList* WMRetainPropList(WMPropList *plist); + +void WMReleasePropList(WMPropList *plist); + void WMInsertInPLArray(WMPropList *plist, int index, WMPropList *item); void WMAddToPLArray(WMPropList *plist, WMPropList *item); @@ -771,9 +775,7 @@ void WMRemoveFromPLDictionary(WMPropList *plist, WMPropList *key); WMPropList* WMMergePLDictionaries(WMPropList *dest, WMPropList *source); -WMPropList* WMRetainPropList(WMPropList *plist); - -void WMReleasePropList(WMPropList *plist); +int WMGetPropListItemCount(WMPropList *plist); Bool WMIsPLString(WMPropList *plist); @@ -785,8 +787,6 @@ Bool WMIsPLDictionary(WMPropList *plist); Bool WMIsPropListEqualTo(WMPropList *plist, WMPropList *other); -int WMGetPropListItemCount(WMPropList *plist); - char* WMGetFromPLString(WMPropList *plist); WMData* WMGetFromPLData(WMPropList *plist); @@ -805,10 +805,10 @@ WMPropList* WMShallowCopyPropList(WMPropList *plist); WMPropList* WMDeepCopyPropList(WMPropList *plist); -char* WMGetPropListDescription(WMPropList *plist, Bool indented); - WMPropList* WMCreatePropListFromDescription(char *desc); +char* WMGetPropListDescription(WMPropList *plist, Bool indented); + WMPropList* WMReadPropListFromFile(char *file); Bool WMWritePropListToFile(WMPropList *plist, char *path, Bool atomically); diff --git a/WINGs/WINGs/proplist-compat.h b/WINGs/WINGs/proplist-compat.h new file mode 100644 index 00000000..25ceb778 --- /dev/null +++ b/WINGs/WINGs/proplist-compat.h @@ -0,0 +1,74 @@ + + +#ifndef _PROPLIST_COMPAT_H_ +#define _PROPLIST_COMPAT_H_ + +#include + + +typedef WMPropList* proplist_t; + +#define PLSetCaseSensitive(c) WMPLSetCaseSensitive(c) + +#define PLMakeString(bytes) WMCreatePLString(bytes) +#define PLMakeData(bytes, length) WMCreatePLDataFromBytes(bytes, length) +#define PLMakeArrayFromElements(pl, ...) WMCreatePLArray(pl, ...) +#define PLMakeDictionaryFromEntries(key, value, ...) WMCreatePLDictionary(key, value, ...) + +#define PLRetain(pl) WMRetainPropList(pl) +#define PLRelease(pl) WMReleasePropList(pl) + +#define PLInsertArrayElement(array, pl, pos) WMInsertInPLArray(array, pos, pl) +#define PLAppendArrayElement(array, pl) WMAddToPLArray(array, pl) +#define PLRemoveArrayElement(array, pos) WMDeleteFromPLArray(array, pos) +#define PLInsertDictionaryEntry(dict, key, value) WMPutInPLDictionary(dict, key, value) +#define PLRemoveDictionaryEntry(dict, key) WMRemoveFromPLDictionary(dict, key) +#define PLMergeDictionaries(dest, source) WMMergePLDictionaries(dest, source) + +#define PLGetNumberOfElements(pl) WMGetPropListItemCount(pl) + +#define PLIsString(pl) WMIsPLString(pl) +#define PLIsData(pl) WMIsPLData(pl) +#define PLIsArray(pl) WMIsPLArray(pl) +#define PLIsDictionary(pl) WMIsPLDictionary(pl) +#define PLIsSimple(pl) (WMIsPLString(pl) || WMIsPLData(pl)) +#define PLIsCompound(pl) (WMIsPLArray(pl) || WMIsPLDictionary(pl)) +#define PLIsEqual(pl1, pl2) WMIsPropListEqualTo(pl1, pl2) + +#define PLGetString(pl) WMGetFromPLString(pl) +#define PLGetDataBytes(pl) WMGetPLDataBytes(pl) +#define PLGetDataLength(pl) WMGetPLDataLength(pl) +#define PLGetArrayElement(pl, index) WMGetFromArray(pl, index) +#define PLGetDictionaryEntry(pl, key) WMGetFromPLDictionary(pl, key) +#define PLGetAllDictionaryKeys(pl) WMGetPLDictionaryKeys(pl) + +#define PLShallowCopy(pl) WMShallowCopyPropList(pl) +#define PLDeepCopy(pl) WMDeepCopyPropList(pl) + +#define PLGetProplistWithDescription(desc) WMCreatePropListFromDescription(desc) +#define PLGetDescriptionIndent(pl, level) WMGetPropListDescription(pl, True) +#define PLGetDescription(pl) WMGetPropListDescription(pl, False) +#define PLGetStringDescription(pl) WMGetPropListDescription(pl, False) +#define PLGetDataDescription(pl) WMGetPropListDescription(pl, False) + +#define PLGetProplistWithPath(file) WMReadPropListFromFile(file) +#define PLSave(pl, file, atm) WMWritePropListToFile(pl, file, atm) + + + +//#define PLSetStringCmpHook(fn) +//#define PLDeepSynchronize(pl) PLDeepSynchronize_is_not_supported +//#define PLSynchronize(pl) PLSynchronize_is_not_supported +//#define PLShallowSynchronize(pl) error_PLShallowSynchronize_is_not_supported +//#define PLSetFilename(pl, filename) error_PLSetFilename_is_not_supported +//#define PLGetFilename(pl, filename) error_PLGetFilename_is_not_supported +//#define PLGetDomainNames() +//#define PLGetDomain(name) +//#define PLSetDomain(name, value, kickme) +//#define PLDeleteDomain(name, kickme) +//#define PLRegister(name, callback) +//#define PLUnregister(name) +//#define PLGetContainer(pl) + + +#endif diff --git a/WINGs/proplist.c b/WINGs/proplist.c index fb771ff9..9b50ed0c 100644 --- a/WINGs/proplist.c +++ b/WINGs/proplist.c @@ -1031,6 +1031,91 @@ WMCreatePLDictionary(WMPropList *key, WMPropList *value, ...) } +WMPropList* +WMRetainPropList(WMPropList *plist) +{ + WMPropList *key, *value; + WMHashEnumerator e; + int i; + + plist->retainCount++; + + switch(plist->type) { + case WPLString: + case WPLData: + break; + case WPLArray: + for (i=0; id.array); i++) { + WMRetainPropList(WMGetFromArray(plist->d.array, i)); + } + break; + case WPLDictionary: + e = WMEnumerateHashTable(plist->d.dict); + while (WMNextHashEnumeratorItemAndKey(&e, (void**)&value, (void**)&key)) { + WMRetainPropList(key); + WMRetainPropList(value); + } + break; + default: + wwarning(_("Used proplist functions on non-WMPropLists objects")); + wassertrv(False, NULL); + break; + } + + return plist; +} + + +void +WMReleasePropList(WMPropList *plist) +{ + WMPropList *key, *value; + WMHashEnumerator e; + int i; + + plist->retainCount--; + + switch(plist->type) { + case WPLString: + if (plist->retainCount < 1) { + wfree(plist->d.string); + wfree(plist); + } + break; + case WPLData: + if (plist->retainCount < 1) { + WMReleaseData(plist->d.data); + wfree(plist); + } + break; + case WPLArray: + for (i=0; id.array); i++) { + WMReleasePropList(WMGetFromArray(plist->d.array, i)); + } + if (plist->retainCount < 1) { + WMFreeArray(plist->d.array); + wfree(plist); + } + break; + case WPLDictionary: + e = WMEnumerateHashTable(plist->d.dict); + while (WMNextHashEnumeratorItemAndKey(&e, (void**)&value, (void**)&key)) { + WMReleasePropList(key); + WMReleasePropList(value); + } + if (plist->retainCount < 1) { + WMFreeHashTable(plist->d.dict); + wfree(plist); + } + break; + default: + wwarning(_("Used proplist functions on non-WMPropLists objects")); + wassertr(False); + break; + } +} + + void WMInsertInPLArray(WMPropList *plist, int index, WMPropList *item) { @@ -1129,88 +1214,24 @@ WMMergePLDictionaries(WMPropList *dest, WMPropList *source) } -WMPropList* -WMRetainPropList(WMPropList *plist) +int +WMGetPropListItemCount(WMPropList *plist) { - WMPropList *key, *value; - WMHashEnumerator e; - int i; - - plist->retainCount++; - switch(plist->type) { case WPLString: case WPLData: - break; + return 0; /* should this be 1 instead? */ case WPLArray: - for (i=0; id.array); i++) { - WMRetainPropList(WMGetFromArray(plist->d.array, i)); - } - break; + return WMGetArrayItemCount(plist->d.array); case WPLDictionary: - e = WMEnumerateHashTable(plist->d.dict); - while (WMNextHashEnumeratorItemAndKey(&e, (void**)&value, (void**)&key)) { - WMRetainPropList(key); - WMRetainPropList(value); - } - break; + return (int)WMCountHashTable(plist->d.dict); default: wwarning(_("Used proplist functions on non-WMPropLists objects")); - wassertrv(False, NULL); + wassertrv(False, 0); break; } - return plist; -} - - -void -WMReleasePropList(WMPropList *plist) -{ - WMPropList *key, *value; - WMHashEnumerator e; - int i; - - plist->retainCount--; - - switch(plist->type) { - case WPLString: - if (plist->retainCount < 1) { - wfree(plist->d.string); - wfree(plist); - } - break; - case WPLData: - if (plist->retainCount < 1) { - WMReleaseData(plist->d.data); - wfree(plist); - } - break; - case WPLArray: - for (i=0; id.array); i++) { - WMReleasePropList(WMGetFromArray(plist->d.array, i)); - } - if (plist->retainCount < 1) { - WMFreeArray(plist->d.array); - wfree(plist); - } - break; - case WPLDictionary: - e = WMEnumerateHashTable(plist->d.dict); - while (WMNextHashEnumeratorItemAndKey(&e, (void**)&value, (void**)&key)) { - WMReleasePropList(key); - WMReleasePropList(value); - } - if (plist->retainCount < 1) { - WMFreeHashTable(plist->d.dict); - wfree(plist); - } - break; - default: - wwarning(_("Used proplist functions on non-WMPropLists objects")); - wassertr(False); - break; - } + return 0; } @@ -1293,27 +1314,6 @@ WMIsPropListEqualTo(WMPropList *plist, WMPropList *other) } -int -WMGetPropListItemCount(WMPropList *plist) -{ - switch(plist->type) { - case WPLString: - case WPLData: - return 0; /* should this be 1 instead? */ - case WPLArray: - return WMGetArrayItemCount(plist->d.array); - case WPLDictionary: - return (int)WMCountHashTable(plist->d.dict); - default: - wwarning(_("Used proplist functions on non-WMPropLists objects")); - wassertrv(False, 0); - break; - } - - return 0; -} - - char* WMGetFromPLString(WMPropList *plist) { @@ -1482,13 +1482,6 @@ WMDeepCopyPropList(WMPropList *plist) } -char* -WMGetPropListDescription(WMPropList *plist, Bool indented) -{ - return (indented ? indentedDescription(plist, 0) : description(plist)); -} - - WMPropList* WMCreatePropListFromDescription(char *desc) { @@ -1520,6 +1513,13 @@ WMCreatePropListFromDescription(char *desc) } +char* +WMGetPropListDescription(WMPropList *plist, Bool indented) +{ + return (indented ? indentedDescription(plist, 0) : description(plist)); +} + + WMPropList* WMReadPropListFromFile(char *file) {