1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-23 06:38:05 +01:00

more updates to the proplist code

This commit is contained in:
dan
2001-09-14 00:24:15 +00:00
parent e0f7284142
commit aedbe70f63
2 changed files with 206 additions and 177 deletions

View File

@@ -741,77 +741,73 @@ void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
/* Property Lists handling */ /* Property Lists handling */
void WMSetPropListStringComparer(WMCompareDataProc *comparer); void WMPLSetCaseSensitive(Bool useCase);
WMPropList* WMCreatePropListString(char *str); WMPropList* WMPLCreateString(char *str);
WMPropList* WMCreatePropListDataWithBytes(unsigned char *bytes, WMPropList* WMPLCreateData(WMData *data);
unsigned int length);
WMPropList* WMCreatePropListDataWithBytesNoCopy(unsigned char *bytes, WMPropList* WMPLCreateDataWithBytes(unsigned char *bytes, unsigned int length);
WMPropList* WMPLCreateDataWithBytesNoCopy(unsigned char *bytes,
unsigned int length, unsigned int length,
WMFreeDataProc *destructor); WMFreeDataProc *destructor);
WMPropList* WMCreatePropListDataWithData(WMData *data); WMPropList* WMPLCreateArray(WMPropList *elem, ...);
WMPropList* WMCreatePropListArrayFromElements(WMPropList *elem, ...); WMPropList* WMPLCreateDictionary(WMPropList *key, WMPropList *value, ...);
WMPropList* WMCreatePropListDictionaryFromEntries(WMPropList *key, void WMPLInsertInArray(WMPropList *plist, int index, WMPropList *item);
WMPropList *value, ...);
void WMInsertPropListArrayElement(WMPropList *plist, WMPropList *item, int index); void WMPLAddToArray(WMPropList *plist, WMPropList *item);
void WMAppendPropListArrayElement(WMPropList *plist, WMPropList *item); void WMPLDeleteFromArray(WMPropList *plist, int index);
void WMRemovePropListArrayElement(WMPropList *plist, int index); void WMPLRemoveFromArray(WMPropList *plist, WMPropList *item);
void WMInsertPropListDictionaryEntry(WMPropList *plist, WMPropList *key, void WMPLPutInDictionary(WMPropList *plist, WMPropList *key, WMPropList *value);
WMPropList *value);
void WMRemovePropListDictionaryEntry(WMPropList *plist, WMPropList *key); void WMPLRemoveFromDictionary(WMPropList *plist, WMPropList *key);
WMPropList* WMMergePropListDictionaries(WMPropList *dest, WMPropList *source); WMPropList* WMPLMergeDictionaries(WMPropList *dest, WMPropList *source);
WMPropList* WMRetainPropList(WMPropList *plist); WMPropList* WMPLRetain(WMPropList *plist);
void WMReleasePropList(WMPropList *plist); void WMPLRelease(WMPropList *plist);
Bool WMPropListIsString(WMPropList *plist); Bool WMPLIsString(WMPropList *plist);
Bool WMPropListIsData(WMPropList *plist); Bool WMPLIsData(WMPropList *plist);
Bool WMPropListIsArray(WMPropList *plist); Bool WMPLIsArray(WMPropList *plist);
Bool WMPropListIsDictionary(WMPropList *plist); Bool WMPLIsDictionary(WMPropList *plist);
Bool WMPropListIsSimple(WMPropList *plist); Bool WMPLIsEqualToPL(WMPropList *plist, WMPropList *other);
Bool WMPropListIsCompound(WMPropList *plist); int WMPLGetItemCount(WMPropList *plist);
Bool WMIsPropListEqualToPropList(WMPropList *plist, WMPropList *other); char* WMPLGetString(WMPropList *plist);
int WMGetPropListNumberOfElements(WMPropList *plist); WMData* WMPLGetData(WMPropList *plist);
char* WMGetPropListString(WMPropList *plist); const unsigned char* WMPLGetDataBytes(WMPropList *plist);
WMData* WMGetPropListData(WMPropList *plist); int WMPLGetDataLength(WMPropList *plist);
const unsigned char* WMGetPropListDataBytes(WMPropList *plist); WMPropList* WMPLGetFromArray(WMPropList *plist, int index);
int WMGetPropListDataLength(WMPropList *plist); WMPropList* WMPLGetFromDictionary(WMPropList *plist, WMPropList *key);
WMPropList* WMGetPropListArrayElement(WMPropList *plist, int index); WMPropList* WMPLGetDictionaryKeys(WMPropList *plist);
WMPropList* WMGetPropListDictionaryEntry(WMPropList *plist, WMPropList *key); char* WMPLGetDescription(WMPropList *plist, Bool indented);
WMPropList* WMGetPropListAllDictionaryKeys(WMPropList *plist); Bool WMPLWriteToFile(WMPropList *plist, char *path, Bool atomically);
char* WMGetPropListDescription(WMPropList *plist, Bool indented); WMPropList* WMPLShallowCopy(WMPropList *plist);
Bool WMSavePropListToFile(WMPropList *plist, char *path, Bool atomically); WMPropList* WMPLDuplicate(WMPropList *plist);
WMPropList* WMShallowCopyPropList(WMPropList *plist);
WMPropList* WMDeepCopyPropList(WMPropList *plist);
/*......................................................................*/ /*......................................................................*/

View File

@@ -37,6 +37,7 @@ typedef struct W_PropList {
static unsigned hashPropList(WMPropList *plist); static unsigned hashPropList(WMPropList *plist);
@@ -48,18 +49,19 @@ typedef void (*releaseFunc)(const void*);
static const WMHashTableCallbacks WMPropListHashCallbacks = { static const WMHashTableCallbacks WMPropListHashCallbacks = {
(hashFunc)hashPropList, (hashFunc)hashPropList,
(isEqualFunc)WMIsPropListEqualToPropList, (isEqualFunc)WMPLIsEqualToPL,
(retainFunc)NULL, (retainFunc)NULL,
(releaseFunc)NULL (releaseFunc)NULL
}; };
static WMCompareDataProc *strCmp = (WMCompareDataProc*) strcmp;
static Bool caseSensitive = True;
#define MaxHashLength 64 #define MaxHashLength 64
static unsigned static unsigned
hashPropList(WMPropList *plist) hashPropList(WMPropList *plist)
{ {
@@ -80,8 +82,7 @@ hashPropList(WMPropList *plist)
ret ^= tolower(*key++) << ctr; ret ^= tolower(*key++) << ctr;
ctr = (ctr + 1) % sizeof (char *); ctr = (ctr + 1) % sizeof (char *);
}*/ }*/
return ret; break;
/*return strlen(plist->d.string);*/
case WPLData: case WPLData:
key = WMDataBytes(plist->d.data); key = WMDataBytes(plist->d.data);
@@ -90,18 +91,16 @@ hashPropList(WMPropList *plist)
ret ^= key[i] << ctr; ret ^= key[i] << ctr;
ctr = (ctr + 1) % sizeof (char *); ctr = (ctr + 1) % sizeof (char *);
} }
return ret; break;
/*return WMGetDataLength(plist->d.data);*/
default: default:
wwarning(_("Only string or data is supported for a proplist dictionary key")); wwarning(_("Only string or data is supported for a proplist dictionary key"));
wassertrv(False, 0); wassertrv(False, 0);
} break;
} }
/*WMSetPropListStringComparisonCaseSensitive return ret;
WMSetPropListStringComparerIsCaseSensitive }
WMSetPLStringComparisonCaseSensitive*/
static WMPropList* static WMPropList*
retainPropListByCount(WMPropList *plist, int count) retainPropListByCount(WMPropList *plist, int count)
@@ -131,6 +130,7 @@ retainPropListByCount(WMPropList *plist, int count)
default: default:
wwarning(_("Used proplist functions on non-WMPropLists objects")); wwarning(_("Used proplist functions on non-WMPropLists objects"));
wassertrv(False, NULL); wassertrv(False, NULL);
break;
} }
return plist; return plist;
@@ -182,6 +182,7 @@ releasePropListByCount(WMPropList *plist, int count)
default: default:
wwarning(_("Used proplist functions on non-WMPropLists objects")); wwarning(_("Used proplist functions on non-WMPropLists objects"));
wassertr(False); wassertr(False);
break;
} }
} }
@@ -300,15 +301,18 @@ static char*
description(WMPropList *plist) description(WMPropList *plist)
{ {
WMPropList *key, *val; WMPropList *key, *val;
char *retstr, *str, *tmp, *skey, *sval; char *retstr = NULL;
char *str, *tmp, *skey, *sval;
WMHashEnumerator e; WMHashEnumerator e;
int i; int i;
switch (plist->type) { switch (plist->type) {
case WPLString: case WPLString:
return stringDescription(plist); retstr = stringDescription(plist);
break;
case WPLData: case WPLData:
return dataDescription(plist); retstr = dataDescription(plist);
break;
case WPLArray: case WPLArray:
retstr = wstrdup("("); retstr = wstrdup("(");
for (i=0; i<WMGetArrayItemCount(plist->d.array); i++) { for (i=0; i<WMGetArrayItemCount(plist->d.array); i++) {
@@ -343,6 +347,7 @@ description(WMPropList *plist)
default: default:
wwarning(_("Used proplist functions on non-WMPropLists objects")); wwarning(_("Used proplist functions on non-WMPropLists objects"));
wassertrv(False, NULL); wassertrv(False, NULL);
break;
} }
return retstr; return retstr;
@@ -353,15 +358,18 @@ static char*
indentedDescription(WMPropList *plist, int level) indentedDescription(WMPropList *plist, int level)
{ {
WMPropList *key, *val; WMPropList *key, *val;
char *retstr, *str, *tmp, *skey, *sval; char *retstr = NULL;
char *str, *tmp, *skey, *sval;
WMHashEnumerator e; WMHashEnumerator e;
int i; int i;
switch (plist->type) { switch (plist->type) {
case WPLString: case WPLString:
return stringDescription(plist); retstr = stringDescription(plist);
break;
case WPLData: case WPLData:
return dataDescription(plist); retstr = dataDescription(plist);
break;
case WPLArray: case WPLArray:
retstr = wstrdup("(\n"); retstr = wstrdup("(\n");
for (i=0; i<WMGetArrayItemCount(plist->d.array); i++) { for (i=0; i<WMGetArrayItemCount(plist->d.array); i++) {
@@ -408,6 +416,7 @@ indentedDescription(WMPropList *plist, int level)
default: default:
wwarning(_("Used proplist functions on non-WMPropLists objects")); wwarning(_("Used proplist functions on non-WMPropLists objects"));
wassertrv(False, NULL); wassertrv(False, NULL);
break;
} }
return retstr; return retstr;
@@ -415,17 +424,14 @@ indentedDescription(WMPropList *plist, int level)
void void
WMSetPropListStringComparer(WMCompareDataProc *comparer) WMPLSetCaseSensitive(Bool useCase)
{ {
if (!comparer) caseSensitive = useCase;
strCmp = (WMCompareDataProc*) strcmp;
else
strCmp = comparer;
} }
WMPropList* WMPropList*
WMCreatePropListString(char *str) WMPLCreateString(char *str)
{ {
WMPropList *plist; WMPropList *plist;
@@ -442,7 +448,24 @@ WMCreatePropListString(char *str)
WMPropList* WMPropList*
WMCreatePropListDataWithBytes(unsigned char *bytes, unsigned int length) WMPLCreateData(WMData *data)
{
WMPropList *plist;
wassertrv(data!=NULL, NULL);
plist = (WMPropList*)wmalloc(sizeof(W_PropList));
plist->type = WPLData;
plist->d.data = WMRetainData(data);
plist->retainCount = 1;
return plist;
}
WMPropList*
WMPLCreateDataWithBytes(unsigned char *bytes, unsigned int length)
{ {
WMPropList *plist; WMPropList *plist;
@@ -459,7 +482,7 @@ WMCreatePropListDataWithBytes(unsigned char *bytes, unsigned int length)
WMPropList* WMPropList*
WMCreatePropListDataWithBytesNoCopy(unsigned char *bytes, unsigned int length, WMPLCreateDataWithBytesNoCopy(unsigned char *bytes, unsigned int length,
WMFreeDataProc *destructor) WMFreeDataProc *destructor)
{ {
WMPropList *plist; WMPropList *plist;
@@ -477,24 +500,7 @@ WMCreatePropListDataWithBytesNoCopy(unsigned char *bytes, unsigned int length,
WMPropList* WMPropList*
WMCreatePropListDataWithData(WMData *data) WMPLCreateArray(WMPropList *elem, ...)
{
WMPropList *plist;
wassertrv(data!=NULL, NULL);
plist = (WMPropList*)wmalloc(sizeof(W_PropList));
plist->type = WPLData;
plist->d.data = WMRetainData(data);
plist->retainCount = 1;
return plist;
}
WMPropList*
WMCreatePropListArrayFromElements(WMPropList *elem, ...)
{ {
WMPropList *plist, *nelem; WMPropList *plist, *nelem;
va_list ap; va_list ap;
@@ -507,7 +513,7 @@ WMCreatePropListArrayFromElements(WMPropList *elem, ...)
if (!elem) if (!elem)
return plist; return plist;
WMAddToArray(plist->d.array, WMRetainPropList(elem)); WMAddToArray(plist->d.array, WMPLRetain(elem));
va_start(ap, elem); va_start(ap, elem);
@@ -517,13 +523,13 @@ WMCreatePropListArrayFromElements(WMPropList *elem, ...)
va_end(ap); va_end(ap);
return plist; return plist;
} }
WMAddToArray(plist->d.array, WMRetainPropList(nelem)); WMAddToArray(plist->d.array, WMPLRetain(nelem));
} }
} }
WMPropList* WMPropList*
WMCreatePropListDictionaryFromEntries(WMPropList *key, WMPropList *value, ...) WMPLCreateDictionary(WMPropList *key, WMPropList *value, ...)
{ {
WMPropList *plist, *nkey, *nvalue, *k, *v; WMPropList *plist, *nkey, *nvalue, *k, *v;
va_list ap; va_list ap;
@@ -536,7 +542,7 @@ WMCreatePropListDictionaryFromEntries(WMPropList *key, WMPropList *value, ...)
if (!key || !value) if (!key || !value)
return plist; return plist;
WMHashInsert(plist->d.dict, WMRetainPropList(key), WMRetainPropList(value)); WMHashInsert(plist->d.dict, WMPLRetain(key), WMPLRetain(value));
va_start(ap, value); va_start(ap, value);
@@ -553,17 +559,16 @@ WMCreatePropListDictionaryFromEntries(WMPropList *key, WMPropList *value, ...)
} }
if (WMHashGetItemAndKey(plist->d.dict, nkey, (void**)&v, (void**)&k)) { if (WMHashGetItemAndKey(plist->d.dict, nkey, (void**)&v, (void**)&k)) {
WMHashRemove(plist->d.dict, k); WMHashRemove(plist->d.dict, k);
WMReleasePropList(k); WMPLRelease(k);
WMReleasePropList(v); WMPLRelease(v);
} }
WMHashInsert(plist->d.dict, WMRetainPropList(nkey), WMHashInsert(plist->d.dict, WMPLRetain(nkey), WMPLRetain(nvalue));
WMRetainPropList(nvalue));
} }
} }
void void
WMInsertPropListArrayElement(WMPropList *plist, WMPropList *item, int index) WMPLInsertInArray(WMPropList *plist, int index, WMPropList *item)
{ {
wassertr(plist->type==WPLArray); wassertr(plist->type==WPLArray);
@@ -573,7 +578,7 @@ WMInsertPropListArrayElement(WMPropList *plist, WMPropList *item, int index)
void void
WMAppendPropListArrayElement(WMPropList *plist, WMPropList *item) WMPLAddToArray(WMPropList *plist, WMPropList *item)
{ {
wassertr(plist->type==WPLArray); wassertr(plist->type==WPLArray);
@@ -583,7 +588,7 @@ WMAppendPropListArrayElement(WMPropList *plist, WMPropList *item)
void void
WMRemovePropListArrayElement(WMPropList *plist, int index) WMPLDeleteFromArray(WMPropList *plist, int index)
{ {
WMPropList *item; WMPropList *item;
@@ -598,12 +603,30 @@ WMRemovePropListArrayElement(WMPropList *plist, int index)
void void
WMInsertPropListDictionaryEntry(WMPropList *plist, WMPropList *key, WMPLRemoveFromArray(WMPropList *plist, WMPropList *item)
WMPropList *value) {
WMPropList *iPtr;
int i;
wassertr(plist->type==WPLArray);
for (i=0; i<WMGetArrayItemCount(plist->d.array); i++) {
iPtr = WMGetFromArray(plist->d.array, i);
if (WMPLIsEqualToPL(item, iPtr)) {
WMDeleteFromArray(plist->d.array, i);
releasePropListByCount(iPtr, plist->retainCount);
break;
}
}
}
void
WMPLPutInDictionary(WMPropList *plist, WMPropList *key, WMPropList *value)
{ {
wassertr(plist->type==WPLDictionary); wassertr(plist->type==WPLDictionary);
WMRemovePropListDictionaryEntry(plist, key); WMPLRemoveFromDictionary(plist, key);
retainPropListByCount(key, plist->retainCount); retainPropListByCount(key, plist->retainCount);
retainPropListByCount(value, plist->retainCount); retainPropListByCount(value, plist->retainCount);
WMHashInsert(plist->d.dict, key, value); WMHashInsert(plist->d.dict, key, value);
@@ -611,7 +634,7 @@ WMInsertPropListDictionaryEntry(WMPropList *plist, WMPropList *key,
void void
WMRemovePropListDictionaryEntry(WMPropList *plist, WMPropList *key) WMPLRemoveFromDictionary(WMPropList *plist, WMPropList *key)
{ {
WMPropList *k, *v; WMPropList *k, *v;
@@ -626,7 +649,7 @@ WMRemovePropListDictionaryEntry(WMPropList *plist, WMPropList *key)
WMPropList* WMPropList*
WMMergePropListDictionaries(WMPropList *dest, WMPropList *source) WMPLMergeDictionaries(WMPropList *dest, WMPropList *source)
{ {
WMPropList *key, *value; WMPropList *key, *value;
WMHashEnumerator e; WMHashEnumerator e;
@@ -635,7 +658,7 @@ WMMergePropListDictionaries(WMPropList *dest, WMPropList *source)
e = WMEnumerateHashTable(source->d.dict); e = WMEnumerateHashTable(source->d.dict);
while (WMNextHashEnumeratorItemAndKey(&e, (void**)&value, (void**)&key)) { while (WMNextHashEnumeratorItemAndKey(&e, (void**)&value, (void**)&key)) {
WMInsertPropListDictionaryEntry(dest, key, value); WMPLPutInDictionary(dest, key, value);
} }
return dest; return dest;
@@ -643,7 +666,7 @@ WMMergePropListDictionaries(WMPropList *dest, WMPropList *source)
WMPropList* WMPropList*
WMRetainPropList(WMPropList *plist) WMPLRetain(WMPropList *plist)
{ {
WMPropList *key, *value; WMPropList *key, *value;
WMHashEnumerator e; WMHashEnumerator e;
@@ -657,19 +680,20 @@ WMRetainPropList(WMPropList *plist)
break; break;
case WPLArray: case WPLArray:
for (i=0; i<WMGetArrayItemCount(plist->d.array); i++) { for (i=0; i<WMGetArrayItemCount(plist->d.array); i++) {
WMRetainPropList(WMGetFromArray(plist->d.array, i)); WMPLRetain(WMGetFromArray(plist->d.array, i));
} }
break; break;
case WPLDictionary: case WPLDictionary:
e = WMEnumerateHashTable(plist->d.dict); e = WMEnumerateHashTable(plist->d.dict);
while (WMNextHashEnumeratorItemAndKey(&e, (void**)&value, (void**)&key)) { while (WMNextHashEnumeratorItemAndKey(&e, (void**)&value, (void**)&key)) {
WMRetainPropList(key); WMPLRetain(key);
WMRetainPropList(value); WMPLRetain(value);
} }
break; break;
default: default:
wwarning(_("Used proplist functions on non-WMPropLists objects")); wwarning(_("Used proplist functions on non-WMPropLists objects"));
wassertrv(False, NULL); wassertrv(False, NULL);
break;
} }
return plist; return plist;
@@ -677,7 +701,7 @@ WMRetainPropList(WMPropList *plist)
void void
WMReleasePropList(WMPropList *plist) WMPLRelease(WMPropList *plist)
{ {
WMPropList *key, *value; WMPropList *key, *value;
WMHashEnumerator e; WMHashEnumerator e;
@@ -700,7 +724,7 @@ WMReleasePropList(WMPropList *plist)
break; break;
case WPLArray: case WPLArray:
for (i=0; i<WMGetArrayItemCount(plist->d.array); i++) { for (i=0; i<WMGetArrayItemCount(plist->d.array); i++) {
WMReleasePropList(WMGetFromArray(plist->d.array, i)); WMPLRelease(WMGetFromArray(plist->d.array, i));
} }
if (plist->retainCount < 1) { if (plist->retainCount < 1) {
WMFreeArray(plist->d.array); WMFreeArray(plist->d.array);
@@ -710,8 +734,8 @@ WMReleasePropList(WMPropList *plist)
case WPLDictionary: case WPLDictionary:
e = WMEnumerateHashTable(plist->d.dict); e = WMEnumerateHashTable(plist->d.dict);
while (WMNextHashEnumeratorItemAndKey(&e, (void**)&value, (void**)&key)) { while (WMNextHashEnumeratorItemAndKey(&e, (void**)&value, (void**)&key)) {
WMReleasePropList(key); WMPLRelease(key);
WMReleasePropList(value); WMPLRelease(value);
} }
if (plist->retainCount < 1) { if (plist->retainCount < 1) {
WMFreeHashTable(plist->d.dict); WMFreeHashTable(plist->d.dict);
@@ -721,54 +745,41 @@ WMReleasePropList(WMPropList *plist)
default: default:
wwarning(_("Used proplist functions on non-WMPropLists objects")); wwarning(_("Used proplist functions on non-WMPropLists objects"));
wassertr(False); wassertr(False);
break;
} }
} }
Bool Bool
WMPropListIsString(WMPropList *plist) WMPLIsString(WMPropList *plist)
{ {
return (plist->type == WPLString); return (plist->type == WPLString);
} }
Bool Bool
WMPropListIsData(WMPropList *plist) WMPLIsData(WMPropList *plist)
{ {
return (plist->type == WPLData); return (plist->type == WPLData);
} }
Bool Bool
WMPropListIsArray(WMPropList *plist) WMPLIsArray(WMPropList *plist)
{ {
return (plist->type == WPLArray); return (plist->type == WPLArray);
} }
Bool Bool
WMPropListIsDictionary(WMPropList *plist) WMPLIsDictionary(WMPropList *plist)
{ {
return (plist->type == WPLDictionary); return (plist->type == WPLDictionary);
} }
Bool Bool
WMPropListIsSimple(WMPropList *plist) WMPLIsEqualToPL(WMPropList *plist, WMPropList *other)
{
return (plist->type==WPLString || plist->type==WPLData);
}
Bool
WMPropListIsCompound(WMPropList *plist)
{
return (plist->type==WPLArray || plist->type==WPLDictionary);
}
Bool
WMIsPropListEqualToPropList(WMPropList *plist, WMPropList *other)
{ {
WMPropList *key1, *item1, *item2; WMPropList *key1, *item1, *item2;
WMHashEnumerator enumerator; WMHashEnumerator enumerator;
@@ -779,7 +790,11 @@ WMIsPropListEqualToPropList(WMPropList *plist, WMPropList *other)
switch(plist->type) { switch(plist->type) {
case WPLString: case WPLString:
return (strCmp(plist->d.string, other->d.string) == 0); if (caseSensitive) {
return (strcmp(plist->d.string, other->d.string) == 0);
} else {
return (strcasecmp(plist->d.string, other->d.string) == 0);
}
case WPLData: case WPLData:
return WMIsDataEqualToData(plist->d.data, other->d.data); return WMIsDataEqualToData(plist->d.data, other->d.data);
case WPLArray: case WPLArray:
@@ -789,7 +804,7 @@ WMIsPropListEqualToPropList(WMPropList *plist, WMPropList *other)
for (i=0; i<n; i++) { for (i=0; i<n; i++) {
item1 = WMGetFromArray(plist->d.array, i); item1 = WMGetFromArray(plist->d.array, i);
item2 = WMGetFromArray(other->d.array, i); item2 = WMGetFromArray(other->d.array, i);
if (!WMIsPropListEqualToPropList(item1, item2)) if (!WMPLIsEqualToPL(item1, item2))
return False; return False;
} }
return True; return True;
@@ -800,13 +815,14 @@ WMIsPropListEqualToPropList(WMPropList *plist, WMPropList *other)
while (WMNextHashEnumeratorItemAndKey(&enumerator, (void**)&item1, while (WMNextHashEnumeratorItemAndKey(&enumerator, (void**)&item1,
(void**)&key1)) { (void**)&key1)) {
item2 = WMHashGet(other->d.dict, key1); item2 = WMHashGet(other->d.dict, key1);
if (!item2 || !item1 || !WMIsPropListEqualToPropList(item1, item2)) if (!item2 || !item1 || !WMPLIsEqualToPL(item1, item2))
return False; return False;
} }
return True; return True;
default: default:
wwarning(_("Used proplist functions on non-WMPropLists objects")); wwarning(_("Used proplist functions on non-WMPropLists objects"));
wassertrv(False, False); wassertrv(False, False);
break;
} }
return False; return False;
@@ -814,7 +830,7 @@ WMIsPropListEqualToPropList(WMPropList *plist, WMPropList *other)
int int
WMGetPropListNumberOfElements(WMPropList *plist) WMPLGetItemCount(WMPropList *plist)
{ {
switch(plist->type) { switch(plist->type) {
case WPLString: case WPLString:
@@ -827,12 +843,15 @@ WMGetPropListNumberOfElements(WMPropList *plist)
default: default:
wwarning(_("Used proplist functions on non-WMPropLists objects")); wwarning(_("Used proplist functions on non-WMPropLists objects"));
wassertrv(False, 0); wassertrv(False, 0);
break;
} }
return 0;
} }
char* char*
WMGetPropListString(WMPropList *plist) WMPLGetString(WMPropList *plist)
{ {
wassertrv(plist->type==WPLString, NULL); wassertrv(plist->type==WPLString, NULL);
@@ -841,7 +860,7 @@ WMGetPropListString(WMPropList *plist)
WMData* WMData*
WMGetPropListData(WMPropList *plist) WMPLGetData(WMPropList *plist)
{ {
wassertrv(plist->type==WPLData, NULL); wassertrv(plist->type==WPLData, NULL);
@@ -850,7 +869,7 @@ WMGetPropListData(WMPropList *plist)
const unsigned char* const unsigned char*
WMGetPropListDataBytes(WMPropList *plist) WMPLGetDataBytes(WMPropList *plist)
{ {
wassertrv(plist->type==WPLData, NULL); wassertrv(plist->type==WPLData, NULL);
@@ -859,7 +878,7 @@ WMGetPropListDataBytes(WMPropList *plist)
int int
WMGetPropListDataLength(WMPropList *plist) WMPLGetDataLength(WMPropList *plist)
{ {
wassertrv(plist->type==WPLData, 0); wassertrv(plist->type==WPLData, 0);
@@ -868,7 +887,7 @@ WMGetPropListDataLength(WMPropList *plist)
WMPropList* WMPropList*
WMGetPropListArrayElement(WMPropList *plist, int index) WMPLGetFromArray(WMPropList *plist, int index)
{ {
wassertrv(plist->type==WPLArray, NULL); wassertrv(plist->type==WPLArray, NULL);
@@ -877,7 +896,7 @@ WMGetPropListArrayElement(WMPropList *plist, int index)
WMPropList* WMPropList*
WMGetPropListDictionaryEntry(WMPropList *plist, WMPropList *key) WMPLGetFromDictionary(WMPropList *plist, WMPropList *key)
{ {
wassertrv(plist->type==WPLDictionary, NULL); wassertrv(plist->type==WPLDictionary, NULL);
@@ -886,7 +905,7 @@ WMGetPropListDictionaryEntry(WMPropList *plist, WMPropList *key)
WMPropList* WMPropList*
WMGetPropListAllDictionaryKeys(WMPropList *plist) WMPLGetDictionaryKeys(WMPropList *plist)
{ {
WMPropList *array, *key; WMPropList *array, *key;
WMHashEnumerator enumerator; WMHashEnumerator enumerator;
@@ -900,7 +919,7 @@ WMGetPropListAllDictionaryKeys(WMPropList *plist)
enumerator = WMEnumerateHashTable(plist->d.dict); enumerator = WMEnumerateHashTable(plist->d.dict);
while ((key = WMNextHashEnumeratorKey(&enumerator))) { while ((key = WMNextHashEnumeratorKey(&enumerator))) {
WMAddToArray(array->d.array, WMRetainPropList(key)); WMAddToArray(array->d.array, WMPLRetain(key));
} }
return array; return array;
@@ -908,7 +927,7 @@ WMGetPropListAllDictionaryKeys(WMPropList *plist)
char* char*
WMGetPropListDescription(WMPropList *plist, Bool indented) WMPLGetDescription(WMPropList *plist, Bool indented)
{ {
return (indented ? indentedDescription(plist, 0) : description(plist)); return (indented ? indentedDescription(plist, 0) : description(plist));
} }
@@ -918,7 +937,7 @@ WMGetPropListDescription(WMPropList *plist, Bool indented)
/* TODO: review this function's code */ /* TODO: review this function's code */
Bool Bool
WMSavePropListToFile(WMPropList *plist, char *path, Bool atomically) WMPLWriteToFile(WMPropList *plist, char *path, Bool atomically)
{ {
char *thePath=NULL; char *thePath=NULL;
char *description; char *description;
@@ -1001,16 +1020,23 @@ failure:
WMPropList* WMPropList*
WMShallowCopyPropList(WMPropList *plist) WMPLShallowCopy(WMPropList *plist)
{ {
WMPropList *ret, *key, *item; WMPropList *ret = NULL;
WMPropList *key, *item;
WMHashEnumerator e; WMHashEnumerator e;
WMData *data;
int i; int i;
switch(plist->type) { switch(plist->type) {
case WPLString: case WPLString:
ret = WMPLCreateString(plist->d.string);
break;
case WPLData: case WPLData:
return WMDeepCopyPropList(plist); data = WMCreateDataWithData(plist->d.data);
ret = WMPLCreateData(data);
WMReleaseData(data);
break;
case WPLArray: case WPLArray:
ret = (WMPropList*)wmalloc(sizeof(W_PropList)); ret = (WMPropList*)wmalloc(sizeof(W_PropList));
ret->type = WPLArray; ret->type = WPLArray;
@@ -1018,62 +1044,69 @@ WMShallowCopyPropList(WMPropList *plist)
ret->retainCount = 1; ret->retainCount = 1;
for(i=0; i<WMGetArrayItemCount(ret->d.array); i++) for(i=0; i<WMGetArrayItemCount(ret->d.array); i++)
WMRetainPropList(WMGetFromArray(ret->d.array, i)); WMPLRetain(WMGetFromArray(ret->d.array, i));
return ret; break;
case WPLDictionary: case WPLDictionary:
ret = WMCreatePropListDictionaryFromEntries(NULL, NULL); ret = WMPLCreateDictionary(NULL, NULL);
e = WMEnumerateHashTable(plist->d.dict); e = WMEnumerateHashTable(plist->d.dict);
while (WMNextHashEnumeratorItemAndKey(&e, (void**)&item, (void**)&key)) { while (WMNextHashEnumeratorItemAndKey(&e, (void**)&item, (void**)&key)) {
WMInsertPropListDictionaryEntry(ret, key, item); WMPLPutInDictionary(ret, key, item);
} }
return ret; break;
default: default:
wwarning(_("Used proplist functions on non-WMPropLists objects")); wwarning(_("Used proplist functions on non-WMPropLists objects"));
wassertrv(False, NULL); wassertrv(False, NULL);
break;
} }
return ret;
} }
WMPropList* WMPropList*
WMDeepCopyPropList(WMPropList *plist) WMPLDuplicate(WMPropList *plist)
{ {
WMPropList *ret, *key, *item; WMPropList *ret = NULL;
WMPropList *key, *item;
WMHashEnumerator e; WMHashEnumerator e;
WMData *data; WMData *data;
int i; int i;
switch(plist->type) { switch(plist->type) {
case WPLString: case WPLString:
return WMCreatePropListString(plist->d.string); ret = WMPLCreateString(plist->d.string);
break;
case WPLData: case WPLData:
data = WMCreateDataWithData(plist->d.data); data = WMCreateDataWithData(plist->d.data);
ret = WMCreatePropListDataWithData(data); ret = WMPLCreateData(data);
WMReleaseData(data); WMReleaseData(data);
return ret; break;
case WPLArray: case WPLArray:
ret = WMCreatePropListArrayFromElements(NULL); ret = WMPLCreateArray(NULL);
for(i=0; i<WMGetArrayItemCount(plist->d.array); i++) { for(i=0; i<WMGetArrayItemCount(plist->d.array); i++) {
item = WMDeepCopyPropList(WMGetFromArray(plist->d.array, i)); item = WMPLDuplicate(WMGetFromArray(plist->d.array, i));
WMAddToArray(ret->d.array, item); WMAddToArray(ret->d.array, item);
} }
return ret; break;
case WPLDictionary: case WPLDictionary:
ret = WMCreatePropListDictionaryFromEntries(NULL, NULL); ret = WMPLCreateDictionary(NULL, NULL);
e = WMEnumerateHashTable(plist->d.dict); e = WMEnumerateHashTable(plist->d.dict);
/* While we copy an existing dictionary there is no way that we can /* While we copy an existing dictionary there is no way that we can
* have duplicate keys, so we don't need to first remove a key/value * have duplicate keys, so we don't need to first remove a key/value
* pair before inserting the new key/value. * pair before inserting the new key/value.
*/ */
while (WMNextHashEnumeratorItemAndKey(&e, (void**)&item, (void**)&key)) { while (WMNextHashEnumeratorItemAndKey(&e, (void**)&item, (void**)&key)) {
WMHashInsert(ret->d.dict, WMDeepCopyPropList(key), WMHashInsert(ret->d.dict, WMPLDuplicate(key), WMPLDuplicate(item));
WMDeepCopyPropList(item));
} }
return ret; break;
default: default:
wwarning(_("Used proplist functions on non-WMPropLists objects")); wwarning(_("Used proplist functions on non-WMPropLists objects"));
wassertrv(False, NULL); wassertrv(False, NULL);
break;
} }
return ret;
} }