Compare commits

..
Author SHA1 Message Date
trurl ec5932ff9a Drop unused wAbort function from WPrefs.app. 2025-09-23 17:09:52 -04:00
trurl 85bbc8f975 Replace WUtil hashtable with a Rust impl.
This tweaks the hashtable API, and it is incomplete because the WUtil proplist
impl depends heavily on a feature of the old API that is being discontinued.

Moving the proplist code into Rust is our next objective.
2025-09-23 17:08:32 -04:00
trurl b94d48a812 Eliminate the retainKey and releaseKey hashtable callbacks.
These fields are only ever NULL, so there's no reason to keep them.
2025-09-23 17:03:58 -04:00
trurl ac606156c4 Drop WMStringHashCallbacks, which is unused. 2025-09-23 17:03:58 -04:00
trurl d7bde34561 Port custom allocators (WINGs memory.c) to Rust.
This introduces the crate wutil-rs, which is intended to be the destination for
migrating the API of WINGs/WINGs/WUtil.h to Rust.
2025-09-21 15:31:47 -04:00
trurl ceeddfb9da Rip out Boehm GC support.
This is done to simplify memory management across the boundary between C and
Rust. While rewriting WINGs, we may want to be able to malloc/free with the libc
allocator on both sides of that divide.
2025-09-19 20:04:10 -04:00
116 changed files with 5673 additions and 6282 deletions
+7 -1
View File
@@ -15,7 +15,7 @@ wraster = $(top_builddir)/wrlib/libwraster.la
LDADD= libWUtil.la libWINGs.la $(wraster) $(wutilrs) @INTLIBS@
libWINGs_la_LIBADD = libWUtil.la $(wraster) $(wutilrs) @XLIBS@ @XFT_LIBS@ @FCLIBS@ @LIBM@ @PANGO_LIBS@
libWUtil_la_LIBADD = $(wutilrs)
libWUtil_la_LIBADD = @LIBBSD@ $(wutilrs)
EXTRA_DIST = BUGS make-rgb Examples Extras Tests
@@ -65,6 +65,9 @@ libWINGs_la_SOURCES = \
wwindow.c
libWUtil_la_SOURCES = \
array.c \
bagtree.c \
data.c \
error.c \
error.h \
findfile.c \
@@ -73,7 +76,10 @@ libWUtil_la_SOURCES = \
menuparser.h \
menuparser_macros.c \
misc.c \
notification.c \
proplist.c \
string.c \
tree.c \
userdefaults.c \
userdefaults.h \
usleep.c \
+10 -7
View File
@@ -233,7 +233,7 @@ typedef enum {
/* text movement types */
typedef enum {
enum {
WMIllegalTextMovement,
WMReturnTextMovement,
WMEscapeTextMovement,
@@ -243,13 +243,13 @@ typedef enum {
WMRightTextMovement,
WMUpTextMovement,
WMDownTextMovement
} WMTextMovementType;
};
/* text field special events */
typedef enum {
enum {
WMInsertTextEvent,
WMDeleteTextEvent
} WMTextFieldSpecialEventType;
};
enum {
@@ -533,11 +533,14 @@ typedef struct WMBrowserDelegate {
typedef struct WMTextFieldDelegate {
void *data;
void (*didBeginEditing)(struct WMTextFieldDelegate *self, WMTextMovementType reason);
void (*didBeginEditing)(struct WMTextFieldDelegate *self,
WMNotification *notif);
void (*didChange)(struct WMTextFieldDelegate *self, WMTextFieldSpecialEventType reason);
void (*didChange)(struct WMTextFieldDelegate *self,
WMNotification *notif);
void (*didEndEditing)(struct WMTextFieldDelegate *self, WMTextMovementType reason);
void (*didEndEditing)(struct WMTextFieldDelegate *self,
WMNotification *notif);
Bool (*shouldBeginEditing)(struct WMTextFieldDelegate *self,
WMTextField *tPtr);
+4
View File
@@ -378,6 +378,10 @@ void W_InitNotificationCenter(void);
void W_ReleaseNotificationCenter(void);
void W_FlushASAPNotificationQueue(void);
void W_FlushIdleNotificationQueue(void);
/* ---[ selection.c ]----------------------------------------------------- */
+179 -30
View File
@@ -173,7 +173,7 @@ typedef struct {
typedef int WMArrayIterator;
typedef int WMBagIterator;
typedef void *WMBagIterator;
typedef void WMNotificationObserverAction(void *observerData,
@@ -240,14 +240,11 @@ char* wexpandpath(const char *path);
int wcopy_file(const char *toPath, const char *srcFile, const char *destFile);
/* You must free the returned string! */
char* wgethomedir(void);
/* don't free the returned string */
const char* wgethomedir(void);
/* ---[ WINGs/proplist.c ]------------------------------------------------ */
/*
* Creates the directory path and all its parents.
*/
int wmkdirhier(const char *path);
int wrmdirhier(const char *path);
@@ -271,9 +268,14 @@ char* wstrconcat(const char *str1, const char *str2);
* so always assign the returned address to avoid dangling pointers. */
char* wstrappend(char *dst, const char *src);
size_t wstrlcpy(char *, const char *, size_t);
size_t wstrlcat(char *, const char *, size_t);
void wtokensplit(char *command, char ***argv, int *argc);
char* wtokennext(char *word, char **next);
char* wtokenjoin(char **list, int count);
void wtokenfree(char **tokens, int count);
@@ -387,7 +389,7 @@ extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
/* keys are strings, but they are not copied */
/* ---[ wutil-rs/src/array.rs ]--------------------------------------------------- */
/* ---[ WINGs/array.c ]--------------------------------------------------- */
/*
* WMArray use an array to store the elements.
@@ -409,22 +411,29 @@ WMArray* WMCreateArrayWithDestructor(int initialSize, WMFreeDataProc *destructor
WMArray* WMCreateArrayWithArray(WMArray *array);
#define WMDuplicateArray(array) WMCreateArrayWithArray(array)
void WMEmptyArray(WMArray *array);
void WMFreeArray(WMArray *array);
int WMGetArrayItemCount(WMArray *array);
/* appends other to array. other remains unchanged */
void WMAppendArray(WMArray *array, WMArray *other);
/* add will place the element at the end of the array */
void WMAddToArray(WMArray *array, void *item);
/* insert will increment the index of elements after it by 1 */
void WMInsertInArray(WMArray *array, int index, void *item);
/* set returns the old item WITHOUT calling the
/* replace and set will return the old item WITHOUT calling the
* destructor on it even if its available. Free the returned item yourself.
*/
void* WMSetInArray(WMArray *array, int index, void *item);
void* WMReplaceInArray(WMArray *array, int index, void *item);
#define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
/* delete and remove will remove the elements and cause the elements
* after them to decrement their indexes by 1. Also will call the
@@ -432,21 +441,20 @@ void* WMSetInArray(WMArray *array, int index, void *item);
*/
int WMDeleteFromArray(WMArray *array, int index);
int WMRemoveFromArray(WMArray *array, void *item);
#define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
int WMRemoveFromArrayMatching(WMArray *array, WMMatchDataProc *match, void *cdata);
void* WMGetFromArray(WMArray *array, int index);
#define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
/* pop will return the last element from the array, also removing it
* from the array. The destructor is NOT called, even if available.
* Free the returned element if needed by yourself
*/
void* WMPopFromArray(WMArray *array);
/* Like WMFindInArray(array, NULL, item) */
int WMGetFirstInArray(WMArray *array, void *item);
int WMFindInArray(WMArray *array, WMMatchDataProc *match, void *cdata);
int WMCountInArray(WMArray *array, void *item);
@@ -460,6 +468,8 @@ void WMSortArray(WMArray *array, WMCompareDataProc *comparer);
void WMMapArray(WMArray *array, void (*function)(void*, void*), void *data);
WMArray* WMGetSubarrayWithRange(WMArray* array, WMRange aRange);
void* WMArrayFirst(WMArray *array, WMArrayIterator *iter);
void* WMArrayLast(WMArray *array, WMArrayIterator *iter);
@@ -479,7 +489,7 @@ void* WMArrayPrevious(WMArray *array, WMArrayIterator *iter);
for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
var = WMArrayPrevious(array, &(i)))
/* ---[ wutil-rs/src/bag.rs ]------------------------------------------------- */
/* ---[ WINGs/bagtree.c ]------------------------------------------------- */
/*
* Tree bags use a red-black tree for storage.
@@ -494,16 +504,58 @@ void* WMArrayPrevious(WMArray *array, WMArrayIterator *iter);
* Slow for storing small numbers of elements
*/
#define WMCreateBag(size) WMCreateTreeBag()
#define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
WMBag* WMCreateTreeBag(void);
WMBag* WMCreateTreeBagWithDestructor(WMFreeDataProc *destructor);
int WMGetBagItemCount(WMBag *bag);
void WMAppendBag(WMBag *bag, WMBag *other);
void WMPutInBag(WMBag *bag, void *item);
/* insert will increment the index of elements after it by 1 */
void WMInsertInBag(WMBag *bag, int index, void *item);
/* erase will remove the element from the bag,
* but will keep the index of the other elements unchanged */
int WMEraseFromBag(WMBag *bag, int index);
/* delete and remove will remove the elements and cause the elements
* after them to decrement their indexes by 1 */
int WMDeleteFromBag(WMBag *bag, int index);
int WMRemoveFromBag(WMBag *bag, void *item);
void* WMGetFromBag(WMBag *bag, int index);
void WMSetInBag(WMBag *bag, int index, void *item);
void* WMReplaceInBag(WMBag *bag, int index, void *item);
#define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
/* comparer must return:
* < 0 if a < b
* > 0 if a > b
* = 0 if a = b
*/
void WMSortBag(WMBag *bag, WMCompareDataProc *comparer);
void WMEmptyBag(WMBag *bag);
void WMFreeBag(WMBag *bag);
void WMMapBag(WMBag *bag, void (*function)(void*, void*), void *data);
int WMGetFirstInBag(WMBag *bag, void *item);
int WMCountInBag(WMBag *bag, void *item);
int WMFindInBag(WMBag *bag, WMMatchDataProc *match, void *cdata);
void* WMBagFirst(WMBag *bag, WMBagIterator *ptr);
void* WMBagLast(WMBag *bag, WMBagIterator *ptr);
@@ -515,11 +567,16 @@ void* WMBagPrevious(WMBag *bag, WMBagIterator *ptr);
void* WMBagIteratorAtIndex(WMBag *bag, int index, WMBagIterator *ptr);
int WMBagIndexForIterator(WMBag *bag, WMBagIterator ptr);
/* The following macro assumes that the bag doesn't change in the for loop */
/* The following 2 macros assume that the bag doesn't change in the for loop */
#define WM_ITERATE_BAG(bag, var, i) \
for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
var = WMBagNext(bag, &(i)))
#define WM_ETARETI_BAG(bag, var, i) \
for (var = WMBagLast(bag, &(i)); (i) >= 0; \
for (var = WMBagLast(bag, &(i)); (i) != NULL; \
var = WMBagPrevious(bag, &(i)))
@@ -536,16 +593,37 @@ WMData* WMCreateDataWithLength(unsigned length);
WMData* WMCreateDataWithBytes(const void *bytes, unsigned length);
/* destructor is a function called to free the data when releasing the data
* object, or NULL if no freeing of data is necesary. */
WMData* WMCreateDataWithBytesNoCopy(void *bytes, unsigned length,
WMFreeDataProc *destructor);
WMData* WMCreateDataWithData(WMData *aData);
WMData* WMRetainData(WMData *aData);
void WMReleaseData(WMData *aData);
/* Adjusting capacity */
void WMSetDataCapacity(WMData *aData, unsigned capacity);
void WMSetDataLength(WMData *aData, unsigned length);
void WMIncreaseDataLengthBy(WMData *aData, unsigned extraLength);
/* Accessing data */
const void* WMDataBytes(WMData *aData);
void WMGetDataBytes(WMData *aData, void *buffer);
void WMGetDataBytesWithLength(WMData *aData, void *buffer, unsigned length);
void WMGetDataBytesWithRange(WMData *aData, void *buffer, WMRange aRange);
WMData* WMGetSubdataWithRange(WMData *aData, WMRange aRange);
/* Testing data */
Bool WMIsDataEqualToData(WMData *aData, WMData *anotherData);
@@ -560,6 +638,10 @@ void WMAppendData(WMData *aData, WMData *anotherData);
/* Modifying data */
void WMReplaceDataBytesInRange(WMData *aData, WMRange aRange, const void *bytes);
void WMResetDataBytesInRange(WMData *aData, WMRange aRange);
void WMSetData(WMData *aData, WMData *anotherData);
@@ -568,12 +650,14 @@ void WMSetDataFormat(WMData *aData, unsigned format);
unsigned WMGetDataFormat(WMData *aData);
/* Storing data */
/* ---[ wutil-rs/src/tree.rs ]---------------------------------------------------- */
/* ---[ WINGs/tree.c ]---------------------------------------------------- */
/* Generic Tree and TreeNode */
WMTreeNode* WMCreateTreeNode(void *data);
WMTreeNode* WMCreateTreeNodeWithDestructor(void *data, WMFreeDataProc *destructor);
WMTreeNode* WMInsertItemInTree(WMTreeNode *parent, int index, void *item);
#define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
@@ -582,23 +666,48 @@ WMTreeNode* WMInsertNodeInTree(WMTreeNode *parent, int index, WMTreeNode *aNode)
#define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
void WMDestroyTreeNode(WMTreeNode *aNode);
void WMDeleteLeafForTreeNode(WMTreeNode *aNode, int index);
void WMRemoveLeafForTreeNode(WMTreeNode *aNode, void *leaf);
void* WMReplaceDataForTreeNode(WMTreeNode *aNode, void *newData);
void* WMGetDataForTreeNode(WMTreeNode *aNode);
int WMGetTreeNodeDepth(WMTreeNode *aNode);
WMTreeNode* WMGetParentForTreeNode(WMTreeNode *aNode);
/* Sort only the leaves of the passed node */
void WMSortLeavesForTreeNode(WMTreeNode *aNode, WMCompareDataProc *comparer);
/* Sort all tree recursively starting from the passed node */
void WMSortTree(WMTreeNode *aNode, int (*comparer)(const WMTreeNode *a, const WMTreeNode *b));
void WMSortTree(WMTreeNode *aNode, WMCompareDataProc *comparer);
/* Returns the first node which matches node's data with cdata by 'match' */
WMTreeNode* WMFindInTree(WMTreeNode *aTree, WMMatchDataProc *match, void *cdata);
/* Returns the first node where node's data matches cdata by 'match' and node is
* at most `limit' depths down from `aTree'. */
WMTreeNode *WMFindInTreeWithDepthLimit(WMTreeNode * aTree, int (*match)(const WMTreeNode *item, const void *cdata), void *cdata, int limit);
WMTreeNode *WMFindInTreeWithDepthLimit(WMTreeNode * aTree, WMMatchDataProc * match, void *cdata, int limit);
/* Returns first tree node that has data == cdata */
#define WMGetFirstInTree(aTree, cdata) WMFindInTree(aTree, NULL, cdata)
/* Walk every node of aNode with `walk' */
void WMTreeWalk(WMTreeNode *aNode, WMTreeWalkProc * walk, void *data);
void WMTreeWalk(WMTreeNode *aNode, WMTreeWalkProc * walk, void *data, Bool DepthFirst);
/* ---[ WINGs/notification.c ]---------------------------------------------------- */
/* ---[ WINGs/data.c ]---------------------------------------------------- */
WMNotification* WMCreateNotification(const char *name, void *object, void *clientData);
void WMReleaseNotification(WMNotification *notification);
WMNotification* WMRetainNotification(WMNotification *notification);
void* WMGetNotificationClientData(WMNotification *notification);
void* WMGetNotificationObject(WMNotification *notification);
@@ -609,27 +718,52 @@ const char* WMGetNotificationName(WMNotification *notification);
void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
void *observer, const char *name, void *object);
void WMPostNotification(WMNotification *notification);
void WMRemoveNotificationObserver(void *observer);
void WMRemoveNotificationObserverWithName(void *observer, const char *name,
void *object);
void WMPostNotificationName(const char *name, void *object, void *clientData);
/* Property Lists handling */
WMNotificationQueue* WMGetDefaultNotificationQueue(void);
WMNotificationQueue* WMCreateNotificationQueue(void);
void WMDequeueNotificationMatching(WMNotificationQueue *queue,
WMNotification *notification,
unsigned mask);
void WMEnqueueNotification(WMNotificationQueue *queue,
WMNotification *notification,
WMPostingStyle postingStyle);
void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
WMNotification *notification,
WMPostingStyle postingStyle,
unsigned coalesceMask);
/* ---[ WINGs/proplist.c ]------------------------------------------------ */
WMPropList* WMCreatePLArray(WMPropList *elem, ...);
/* Property Lists handling */
/* ---[ wutil-rs/src/prop_list.rs ]--------------------------------------- */
void WMPLSetCaseSensitive(Bool caseSensitive);
WMPropList* WMCreatePLString(const char *str);
WMPropList* WMCreatePLArrayFromSlice(WMPropList *elems, unsigned int length);
WMPropList* WMCreatePLData(WMData *data);
WMPropList* WMCreateEmptyPLArray();
WMPropList* WMCreatePLDataWithBytes(const unsigned char *bytes, unsigned int length);
WMPropList* WMCreatePLDictionary(WMPropList *key, WMPropList *value);
WMPropList* WMCreatePLDataWithBytesNoCopy(unsigned char *bytes,
unsigned int length,
WMFreeDataProc *destructor);
WMPropList* WMCreateEmptyPLDictionary();
WMPropList* WMCreatePLArray(WMPropList *elem, ...);
WMPropList* WMCreatePLDictionary(WMPropList *key, WMPropList *value, ...);
WMPropList* WMRetainPropList(WMPropList *plist);
@@ -667,6 +801,8 @@ int WMGetPropListItemCount(WMPropList *plist);
Bool WMIsPLString(WMPropList *plist);
Bool WMIsPLData(WMPropList *plist);
Bool WMIsPLArray(WMPropList *plist);
Bool WMIsPLDictionary(WMPropList *plist);
@@ -676,6 +812,14 @@ Bool WMIsPropListEqualTo(WMPropList *plist, WMPropList *other);
/* Returns a reference. Do not free it! */
char* WMGetFromPLString(WMPropList *plist);
/* Returns a reference. Do not free it! */
WMData* WMGetFromPLData(WMPropList *plist);
/* Returns a reference. Do not free it! */
const unsigned char* WMGetPLDataBytes(WMPropList *plist);
int WMGetPLDataLength(WMPropList *plist);
/* Returns a reference. */
WMPropList* WMGetFromPLArray(WMPropList *plist, int index);
@@ -683,9 +827,14 @@ WMPropList* WMGetFromPLArray(WMPropList *plist, int index);
WMPropList* WMGetFromPLDictionary(WMPropList *plist, WMPropList *key);
/* Returns a PropList array with all the dictionary keys. Release it when
* you're done. */
* you're done. Keys in array are retained from the original dictionary
* not copied and need NOT to be released individually. */
WMPropList* WMGetPLDictionaryKeys(WMPropList *plist);
/* Creates only the first level deep object. All the elements inside are
* retained from the original */
WMPropList* WMShallowCopyPropList(WMPropList *plist);
/* Makes a completely separate replica of the original proplist */
WMPropList* WMDeepCopyPropList(WMPropList *plist);
+363
View File
@@ -0,0 +1,363 @@
/*
* Dynamically Resized Array
*
* Authors: Alfredo K. Kojima <kojima@windowmaker.info>
* Dan Pascu <dan@windowmaker.info>
*
* This code is released to the Public Domain, but
* proper credit is always appreciated :)
*/
#include <stdlib.h>
#include <string.h>
#include "WUtil.h"
#define INITIAL_SIZE 8
#define RESIZE_INCREMENT 8
typedef struct W_Array {
void **items; /* the array data */
int itemCount; /* # of items in array */
int allocSize; /* allocated size of array */
WMFreeDataProc *destructor; /* the destructor to free elements */
} W_Array;
WMArray *WMCreateArray(int initialSize)
{
return WMCreateArrayWithDestructor(initialSize, NULL);
}
WMArray *WMCreateArrayWithDestructor(int initialSize, WMFreeDataProc * destructor)
{
WMArray *array;
array = wmalloc(sizeof(WMArray));
if (initialSize <= 0) {
initialSize = INITIAL_SIZE;
}
array->items = wmalloc(sizeof(void *) * initialSize);
array->itemCount = 0;
array->allocSize = initialSize;
array->destructor = destructor;
return array;
}
WMArray *WMCreateArrayWithArray(WMArray * array)
{
WMArray *newArray;
newArray = wmalloc(sizeof(WMArray));
newArray->items = wmalloc(sizeof(void *) * array->allocSize);
memcpy(newArray->items, array->items, sizeof(void *) * array->itemCount);
newArray->itemCount = array->itemCount;
newArray->allocSize = array->allocSize;
newArray->destructor = NULL;
return newArray;
}
void WMEmptyArray(WMArray * array)
{
if (array->destructor) {
while (array->itemCount > 0) {
array->itemCount--;
array->destructor(array->items[array->itemCount]);
}
}
/*memset(array->items, 0, array->itemCount * sizeof(void*)); */
array->itemCount = 0;
}
void WMFreeArray(WMArray * array)
{
if (array == NULL)
return;
WMEmptyArray(array);
wfree(array->items);
wfree(array);
}
int WMGetArrayItemCount(WMArray * array)
{
if (array == NULL)
return 0;
return array->itemCount;
}
void WMAppendArray(WMArray * array, WMArray * other)
{
if (array == NULL || other == NULL)
return;
if (other->itemCount == 0)
return;
if (array->itemCount + other->itemCount > array->allocSize) {
array->allocSize += other->allocSize;
array->items = wrealloc(array->items, sizeof(void *) * array->allocSize);
}
memcpy(array->items + array->itemCount, other->items, sizeof(void *) * other->itemCount);
array->itemCount += other->itemCount;
}
void WMAddToArray(WMArray * array, void *item)
{
if (array == NULL)
return;
if (array->itemCount >= array->allocSize) {
array->allocSize += RESIZE_INCREMENT;
array->items = wrealloc(array->items, sizeof(void *) * array->allocSize);
}
array->items[array->itemCount] = item;
array->itemCount++;
}
void WMInsertInArray(WMArray * array, int index, void *item)
{
if (array == NULL)
return;
wassertr(index >= 0 && index <= array->itemCount);
if (array->itemCount >= array->allocSize) {
array->allocSize += RESIZE_INCREMENT;
array->items = wrealloc(array->items, sizeof(void *) * array->allocSize);
}
if (index < array->itemCount) {
memmove(array->items + index + 1, array->items + index,
sizeof(void *) * (array->itemCount - index));
}
array->items[index] = item;
array->itemCount++;
}
void *WMReplaceInArray(WMArray * array, int index, void *item)
{
void *old;
if (array == NULL)
return NULL;
wassertrv(index >= 0 && index <= array->itemCount, NULL);
/* is it really useful to perform append if index == array->itemCount ? -Dan */
if (index == array->itemCount) {
WMAddToArray(array, item);
return NULL;
}
old = array->items[index];
array->items[index] = item;
return old;
}
int WMDeleteFromArray(WMArray * array, int index)
{
if (array == NULL)
return 0;
wassertrv(index >= 0 && index < array->itemCount, 0);
if (array->destructor) {
array->destructor(array->items[index]);
}
if (index < array->itemCount - 1) {
memmove(array->items + index, array->items + index + 1,
sizeof(void *) * (array->itemCount - index - 1));
}
array->itemCount--;
return 1;
}
int WMRemoveFromArrayMatching(WMArray * array, WMMatchDataProc * match, void *cdata)
{
int i;
if (array == NULL)
return 1;
if (match != NULL) {
for (i = 0; i < array->itemCount; i++) {
if ((*match) (array->items[i], cdata)) {
WMDeleteFromArray(array, i);
return 1;
}
}
} else {
for (i = 0; i < array->itemCount; i++) {
if (array->items[i] == cdata) {
WMDeleteFromArray(array, i);
return 1;
}
}
}
return 0;
}
void *WMGetFromArray(WMArray * array, int index)
{
if (index < 0 || array == NULL || index >= array->itemCount)
return NULL;
return array->items[index];
}
void *WMPopFromArray(WMArray * array)
{
if (array == NULL || array->itemCount <= 0)
return NULL;
array->itemCount--;
return array->items[array->itemCount];
}
int WMFindInArray(WMArray * array, WMMatchDataProc * match, void *cdata)
{
int i;
if (array == NULL)
return WANotFound;
if (match != NULL) {
for (i = 0; i < array->itemCount; i++) {
if ((*match) (array->items[i], cdata))
return i;
}
} else {
for (i = 0; i < array->itemCount; i++) {
if (array->items[i] == cdata)
return i;
}
}
return WANotFound;
}
int WMCountInArray(WMArray * array, void *item)
{
int i, count;
if (array == NULL)
return 0;
for (i = 0, count = 0; i < array->itemCount; i++) {
if (array->items[i] == item)
count++;
}
return count;
}
void WMSortArray(WMArray * array, WMCompareDataProc * comparer)
{
if (array == NULL)
return;
if (array->itemCount > 1) { /* Don't sort empty or single element arrays */
qsort(array->items, array->itemCount, sizeof(void *), comparer);
}
}
void WMMapArray(WMArray * array, void (*function) (void *, void *), void *data)
{
int i;
if (array == NULL)
return;
for (i = 0; i < array->itemCount; i++) {
(*function) (array->items[i], data);
}
}
WMArray *WMGetSubarrayWithRange(WMArray * array, WMRange aRange)
{
WMArray *newArray;
if (aRange.count <= 0 || array == NULL)
return WMCreateArray(0);
if (aRange.position < 0)
aRange.position = 0;
if (aRange.position >= array->itemCount)
aRange.position = array->itemCount - 1;
if (aRange.position + aRange.count > array->itemCount)
aRange.count = array->itemCount - aRange.position;
newArray = WMCreateArray(aRange.count);
memcpy(newArray->items, array->items + aRange.position, sizeof(void *) * aRange.count);
newArray->itemCount = aRange.count;
return newArray;
}
void *WMArrayFirst(WMArray * array, WMArrayIterator * iter)
{
if (array == NULL || array->itemCount == 0) {
*iter = WANotFound;
return NULL;
} else {
*iter = 0;
return array->items[0];
}
}
void *WMArrayLast(WMArray * array, WMArrayIterator * iter)
{
if (array == NULL || array->itemCount == 0) {
*iter = WANotFound;
return NULL;
} else {
*iter = array->itemCount - 1;
return array->items[*iter];
}
}
void *WMArrayNext(WMArray * array, WMArrayIterator * iter)
{
if (array == NULL) {
*iter = WANotFound;
return NULL;
}
if (*iter >= 0 && *iter < array->itemCount - 1) {
return array->items[++(*iter)];
} else {
*iter = WANotFound;
return NULL;
}
}
void *WMArrayPrevious(WMArray * array, WMArrayIterator * iter)
{
if (array == NULL) {
*iter = WANotFound;
return NULL;
}
if (*iter > 0 && *iter < array->itemCount) {
return array->items[--(*iter)];
} else {
*iter = WANotFound;
return NULL;
}
}
+745
View File
@@ -0,0 +1,745 @@
#include <stdlib.h>
#include <string.h>
#include "WUtil.h"
typedef struct W_Node {
struct W_Node *parent;
struct W_Node *left;
struct W_Node *right;
int color;
void *data;
int index;
} W_Node;
typedef struct W_Bag {
W_Node *root;
W_Node *nil; /* sentinel */
int count;
void (*destructor) (void *item);
} W_Bag;
#define IS_LEFT(node) (node == node->parent->left)
#define IS_RIGHT(node) (node == node->parent->right)
static void leftRotate(W_Bag * tree, W_Node * node)
{
W_Node *node2;
node2 = node->right;
node->right = node2->left;
node2->left->parent = node;
node2->parent = node->parent;
if (node->parent == tree->nil) {
tree->root = node2;
} else {
if (IS_LEFT(node)) {
node->parent->left = node2;
} else {
node->parent->right = node2;
}
}
node2->left = node;
node->parent = node2;
}
static void rightRotate(W_Bag * tree, W_Node * node)
{
W_Node *node2;
node2 = node->left;
node->left = node2->right;
node2->right->parent = node;
node2->parent = node->parent;
if (node->parent == tree->nil) {
tree->root = node2;
} else {
if (IS_LEFT(node)) {
node->parent->left = node2;
} else {
node->parent->right = node2;
}
}
node2->right = node;
node->parent = node2;
}
static void treeInsert(W_Bag * tree, W_Node * node)
{
W_Node *y = tree->nil;
W_Node *x = tree->root;
while (x != tree->nil) {
y = x;
if (node->index <= x->index)
x = x->left;
else
x = x->right;
}
node->parent = y;
if (y == tree->nil)
tree->root = node;
else if (node->index <= y->index)
y->left = node;
else
y->right = node;
}
static void rbTreeInsert(W_Bag * tree, W_Node * node)
{
W_Node *y;
treeInsert(tree, node);
node->color = 'R';
while (node != tree->root && node->parent->color == 'R') {
if (IS_LEFT(node->parent)) {
y = node->parent->parent->right;
if (y->color == 'R') {
node->parent->color = 'B';
y->color = 'B';
node->parent->parent->color = 'R';
node = node->parent->parent;
} else {
if (IS_RIGHT(node)) {
node = node->parent;
leftRotate(tree, node);
}
node->parent->color = 'B';
node->parent->parent->color = 'R';
rightRotate(tree, node->parent->parent);
}
} else {
y = node->parent->parent->left;
if (y->color == 'R') {
node->parent->color = 'B';
y->color = 'B';
node->parent->parent->color = 'R';
node = node->parent->parent;
} else {
if (IS_LEFT(node)) {
node = node->parent;
rightRotate(tree, node);
}
node->parent->color = 'B';
node->parent->parent->color = 'R';
leftRotate(tree, node->parent->parent);
}
}
}
tree->root->color = 'B';
}
static void rbDeleteFixup(W_Bag * tree, W_Node * node)
{
W_Node *w;
while (node != tree->root && node->color == 'B') {
if (IS_LEFT(node)) {
w = node->parent->right;
if (w->color == 'R') {
w->color = 'B';
node->parent->color = 'R';
leftRotate(tree, node->parent);
w = node->parent->right;
}
if (w->left->color == 'B' && w->right->color == 'B') {
w->color = 'R';
node = node->parent;
} else {
if (w->right->color == 'B') {
w->left->color = 'B';
w->color = 'R';
rightRotate(tree, w);
w = node->parent->right;
}
w->color = node->parent->color;
node->parent->color = 'B';
w->right->color = 'B';
leftRotate(tree, node->parent);
node = tree->root;
}
} else {
w = node->parent->left;
if (w->color == 'R') {
w->color = 'B';
node->parent->color = 'R';
rightRotate(tree, node->parent);
w = node->parent->left;
}
if (w->left->color == 'B' && w->right->color == 'B') {
w->color = 'R';
node = node->parent;
} else {
if (w->left->color == 'B') {
w->right->color = 'B';
w->color = 'R';
leftRotate(tree, w);
w = node->parent->left;
}
w->color = node->parent->color;
node->parent->color = 'B';
w->left->color = 'B';
rightRotate(tree, node->parent);
node = tree->root;
}
}
}
node->color = 'B';
}
static W_Node *treeMinimum(W_Node * node, W_Node * nil)
{
while (node->left != nil)
node = node->left;
return node;
}
static W_Node *treeMaximum(W_Node * node, W_Node * nil)
{
while (node->right != nil)
node = node->right;
return node;
}
static W_Node *treeSuccessor(W_Node * node, W_Node * nil)
{
W_Node *y;
if (node->right != nil) {
return treeMinimum(node->right, nil);
}
y = node->parent;
while (y != nil && node == y->right) {
node = y;
y = y->parent;
}
return y;
}
static W_Node *treePredecessor(W_Node * node, W_Node * nil)
{
W_Node *y;
if (node->left != nil) {
return treeMaximum(node->left, nil);
}
y = node->parent;
while (y != nil && node == y->left) {
node = y;
y = y->parent;
}
return y;
}
static W_Node *rbTreeDelete(W_Bag * tree, W_Node * node)
{
W_Node *nil = tree->nil;
W_Node *x, *y;
if (node->left == nil || node->right == nil) {
y = node;
} else {
y = treeSuccessor(node, nil);
}
if (y->left != nil) {
x = y->left;
} else {
x = y->right;
}
x->parent = y->parent;
if (y->parent == nil) {
tree->root = x;
} else {
if (IS_LEFT(y)) {
y->parent->left = x;
} else {
y->parent->right = x;
}
}
if (y != node) {
node->index = y->index;
node->data = y->data;
}
if (y->color == 'B') {
rbDeleteFixup(tree, x);
}
return y;
}
static W_Node *treeSearch(W_Node * root, W_Node * nil, int index)
{
if (root == nil || root->index == index) {
return root;
}
if (index < root->index) {
return treeSearch(root->left, nil, index);
} else {
return treeSearch(root->right, nil, index);
}
}
static W_Node *treeFind(W_Node * root, W_Node * nil, void *data)
{
W_Node *tmp;
if (root == nil || root->data == data)
return root;
tmp = treeFind(root->left, nil, data);
if (tmp != nil)
return tmp;
tmp = treeFind(root->right, nil, data);
return tmp;
}
#if 0
static char buf[512];
static void printNodes(W_Node * node, W_Node * nil, int depth)
{
if (node == nil) {
return;
}
printNodes(node->left, nil, depth + 1);
memset(buf, ' ', depth * 2);
buf[depth * 2] = 0;
if (IS_LEFT(node))
printf("%s/(%2i\n", buf, node->index);
else
printf("%s\\(%2i\n", buf, node->index);
printNodes(node->right, nil, depth + 1);
}
void PrintTree(WMBag * bag)
{
W_TreeBag *tree = (W_TreeBag *) bag->data;
printNodes(tree->root, tree->nil, 0);
}
#endif
WMBag *WMCreateTreeBag(void)
{
return WMCreateTreeBagWithDestructor(NULL);
}
WMBag *WMCreateTreeBagWithDestructor(WMFreeDataProc * destructor)
{
WMBag *bag;
bag = wmalloc(sizeof(WMBag));
bag->nil = wmalloc(sizeof(W_Node));
bag->nil->left = bag->nil->right = bag->nil->parent = bag->nil;
bag->nil->index = WBNotFound;
bag->root = bag->nil;
bag->destructor = destructor;
return bag;
}
int WMGetBagItemCount(WMBag * self)
{
return self->count;
}
void WMAppendBag(WMBag * self, WMBag * bag)
{
WMBagIterator ptr;
void *data;
for (data = WMBagFirst(bag, &ptr); data != NULL; data = WMBagNext(bag, &ptr)) {
WMPutInBag(self, data);
}
}
void WMPutInBag(WMBag * self, void *item)
{
W_Node *ptr;
ptr = wmalloc(sizeof(W_Node));
ptr->data = item;
ptr->index = self->count;
ptr->left = self->nil;
ptr->right = self->nil;
ptr->parent = self->nil;
rbTreeInsert(self, ptr);
self->count++;
}
void WMInsertInBag(WMBag * self, int index, void *item)
{
W_Node *ptr;
ptr = wmalloc(sizeof(W_Node));
ptr->data = item;
ptr->index = index;
ptr->left = self->nil;
ptr->right = self->nil;
ptr->parent = self->nil;
rbTreeInsert(self, ptr);
while ((ptr = treeSuccessor(ptr, self->nil)) != self->nil) {
ptr->index++;
}
self->count++;
}
static int treeDeleteNode(WMBag * self, W_Node *ptr)
{
if (ptr != self->nil) {
W_Node *tmp;
self->count--;
tmp = treeSuccessor(ptr, self->nil);
while (tmp != self->nil) {
tmp->index--;
tmp = treeSuccessor(tmp, self->nil);
}
ptr = rbTreeDelete(self, ptr);
if (self->destructor)
self->destructor(ptr->data);
wfree(ptr);
return 1;
}
return 0;
}
int WMRemoveFromBag(WMBag * self, void *item)
{
W_Node *ptr = treeFind(self->root, self->nil, item);
return treeDeleteNode(self, ptr);
}
int WMEraseFromBag(WMBag * self, int index)
{
W_Node *ptr = treeSearch(self->root, self->nil, index);
if (ptr != self->nil) {
self->count--;
ptr = rbTreeDelete(self, ptr);
if (self->destructor)
self->destructor(ptr->data);
wfree(ptr);
wassertrv(self->count == 0 || self->root->index >= 0, 1);
return 1;
} else {
return 0;
}
}
int WMDeleteFromBag(WMBag * self, int index)
{
W_Node *ptr = treeSearch(self->root, self->nil, index);
return treeDeleteNode(self, ptr);
}
void *WMGetFromBag(WMBag * self, int index)
{
W_Node *node;
node = treeSearch(self->root, self->nil, index);
if (node != self->nil)
return node->data;
else
return NULL;
}
int WMGetFirstInBag(WMBag * self, void *item)
{
W_Node *node;
node = treeFind(self->root, self->nil, item);
if (node != self->nil)
return node->index;
else
return WBNotFound;
}
static int treeCount(W_Node * root, W_Node * nil, void *item)
{
int count = 0;
if (root == nil)
return 0;
if (root->data == item)
count++;
if (root->left != nil)
count += treeCount(root->left, nil, item);
if (root->right != nil)
count += treeCount(root->right, nil, item);
return count;
}
int WMCountInBag(WMBag * self, void *item)
{
return treeCount(self->root, self->nil, item);
}
void *WMReplaceInBag(WMBag * self, int index, void *item)
{
W_Node *ptr = treeSearch(self->root, self->nil, index);
void *old = NULL;
if (item == NULL) {
self->count--;
ptr = rbTreeDelete(self, ptr);
if (self->destructor)
self->destructor(ptr->data);
wfree(ptr);
} else if (ptr != self->nil) {
old = ptr->data;
ptr->data = item;
} else {
W_Node *ptr;
ptr = wmalloc(sizeof(W_Node));
ptr->data = item;
ptr->index = index;
ptr->left = self->nil;
ptr->right = self->nil;
ptr->parent = self->nil;
rbTreeInsert(self, ptr);
self->count++;
}
return old;
}
void WMSortBag(WMBag * self, WMCompareDataProc * comparer)
{
void **items;
W_Node *tmp;
int i;
if (self->count == 0)
return;
items = wmalloc(sizeof(void *) * self->count);
i = 0;
tmp = treeMinimum(self->root, self->nil);
while (tmp != self->nil) {
items[i++] = tmp->data;
tmp = treeSuccessor(tmp, self->nil);
}
qsort(&items[0], self->count, sizeof(void *), comparer);
i = 0;
tmp = treeMinimum(self->root, self->nil);
while (tmp != self->nil) {
tmp->index = i;
tmp->data = items[i++];
tmp = treeSuccessor(tmp, self->nil);
}
wfree(items);
}
static void deleteTree(WMBag * self, W_Node * node)
{
if (node == self->nil)
return;
deleteTree(self, node->left);
if (self->destructor)
self->destructor(node->data);
deleteTree(self, node->right);
wfree(node);
}
void WMEmptyBag(WMBag * self)
{
deleteTree(self, self->root);
self->root = self->nil;
self->count = 0;
}
void WMFreeBag(WMBag * self)
{
WMEmptyBag(self);
wfree(self->nil);
wfree(self);
}
static void mapTree(W_Bag * tree, W_Node * node, void (*function) (void *, void *), void *data)
{
if (node == tree->nil)
return;
mapTree(tree, node->left, function, data);
(*function) (node->data, data);
mapTree(tree, node->right, function, data);
}
void WMMapBag(WMBag * self, void (*function) (void *, void *), void *data)
{
mapTree(self, self->root, function, data);
}
static int findInTree(W_Bag * tree, W_Node * node, WMMatchDataProc * function, void *cdata)
{
int index;
if (node == tree->nil)
return WBNotFound;
index = findInTree(tree, node->left, function, cdata);
if (index != WBNotFound)
return index;
if ((*function) (node->data, cdata)) {
return node->index;
}
return findInTree(tree, node->right, function, cdata);
}
int WMFindInBag(WMBag * self, WMMatchDataProc * match, void *cdata)
{
return findInTree(self, self->root, match, cdata);
}
void *WMBagFirst(WMBag * self, WMBagIterator * ptr)
{
W_Node *node;
node = treeMinimum(self->root, self->nil);
if (node == self->nil) {
*ptr = NULL;
return NULL;
} else {
*ptr = node;
return node->data;
}
}
void *WMBagLast(WMBag * self, WMBagIterator * ptr)
{
W_Node *node;
node = treeMaximum(self->root, self->nil);
if (node == self->nil) {
*ptr = NULL;
return NULL;
} else {
*ptr = node;
return node->data;
}
}
void *WMBagNext(WMBag * self, WMBagIterator * ptr)
{
W_Node *node;
if (*ptr == NULL)
return NULL;
node = treeSuccessor(*ptr, self->nil);
if (node == self->nil) {
*ptr = NULL;
return NULL;
} else {
*ptr = node;
return node->data;
}
}
void *WMBagPrevious(WMBag * self, WMBagIterator * ptr)
{
W_Node *node;
if (*ptr == NULL)
return NULL;
node = treePredecessor(*ptr, self->nil);
if (node == self->nil) {
*ptr = NULL;
return NULL;
} else {
*ptr = node;
return node->data;
}
}
void *WMBagIteratorAtIndex(WMBag * self, int index, WMBagIterator * ptr)
{
W_Node *node;
node = treeSearch(self->root, self->nil, index);
if (node == self->nil) {
*ptr = NULL;
return NULL;
} else {
*ptr = node;
return node->data;
}
}
int WMBagIndexForIterator(WMBag * bag, WMBagIterator ptr)
{
/* Parameter not used, but tell the compiler that it is ok */
(void) bag;
return ((W_Node *) ptr)->index;
}
+289
View File
@@ -0,0 +1,289 @@
/*
* WINGs WMData function library
*
* Copyright (c) 1999-2003 Dan Pascu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <string.h>
#include "WUtil.h"
typedef struct W_Data {
unsigned length; /* How many bytes we have */
unsigned capacity; /* How many bytes it can hold */
unsigned growth; /* How much to grow */
void *bytes; /* Actual data */
unsigned retainCount;
WMFreeDataProc *destructor;
int format; /* 0, 8, 16 or 32 */
} W_Data;
/* Creating and destroying data objects */
WMData *WMCreateDataWithCapacity(unsigned capacity)
{
WMData *aData;
aData = (WMData *) wmalloc(sizeof(WMData));
if (capacity > 0)
aData->bytes = wmalloc(capacity);
else
aData->bytes = NULL;
aData->capacity = capacity;
aData->growth = capacity / 2 > 0 ? capacity / 2 : 1;
aData->length = 0;
aData->retainCount = 1;
aData->format = 0;
aData->destructor = wfree;
return aData;
}
WMData *WMCreateDataWithLength(unsigned length)
{
WMData *aData;
aData = WMCreateDataWithCapacity(length);
if (length > 0) {
aData->length = length;
}
return aData;
}
WMData *WMCreateDataWithBytes(const void *bytes, unsigned length)
{
WMData *aData;
aData = WMCreateDataWithCapacity(length);
aData->length = length;
memcpy(aData->bytes, bytes, length);
return aData;
}
WMData *WMCreateDataWithBytesNoCopy(void *bytes, unsigned length, WMFreeDataProc * destructor)
{
WMData *aData;
aData = (WMData *) wmalloc(sizeof(WMData));
aData->length = length;
aData->capacity = length;
aData->growth = length / 2 > 0 ? length / 2 : 1;
aData->bytes = bytes;
aData->retainCount = 1;
aData->format = 0;
aData->destructor = destructor;
return aData;
}
WMData *WMCreateDataWithData(WMData * aData)
{
WMData *newData;
if (aData->length > 0) {
newData = WMCreateDataWithBytes(aData->bytes, aData->length);
} else {
newData = WMCreateDataWithCapacity(0);
}
newData->format = aData->format;
return newData;
}
WMData *WMRetainData(WMData * aData)
{
aData->retainCount++;
return aData;
}
void WMReleaseData(WMData * aData)
{
aData->retainCount--;
if (aData->retainCount > 0)
return;
if (aData->bytes != NULL && aData->destructor != NULL) {
aData->destructor(aData->bytes);
}
wfree(aData);
}
/* Adjusting capacity */
void WMSetDataCapacity(WMData * aData, unsigned capacity)
{
if (aData->capacity != capacity) {
aData->bytes = wrealloc(aData->bytes, capacity);
aData->capacity = capacity;
aData->growth = capacity / 2 > 0 ? capacity / 2 : 1;
}
if (aData->length > capacity) {
aData->length = capacity;
}
}
void WMSetDataLength(WMData * aData, unsigned length)
{
if (length > aData->capacity) {
WMSetDataCapacity(aData, length);
}
if (length > aData->length) {
memset((unsigned char *)aData->bytes + aData->length, 0, length - aData->length);
}
aData->length = length;
}
void WMSetDataFormat(WMData * aData, unsigned format)
{
aData->format = format;
}
void WMIncreaseDataLengthBy(WMData * aData, unsigned extraLength)
{
WMSetDataLength(aData, aData->length + extraLength);
}
/* Accessing data */
const void *WMDataBytes(WMData * aData)
{
return aData->bytes;
}
void WMGetDataBytes(WMData * aData, void *buffer)
{
wassertr(aData->length > 0);
memcpy(buffer, aData->bytes, aData->length);
}
unsigned WMGetDataFormat(WMData * aData)
{
return aData->format;
}
void WMGetDataBytesWithLength(WMData * aData, void *buffer, unsigned length)
{
wassertr(aData->length > 0);
wassertr(length <= aData->length);
memcpy(buffer, aData->bytes, length);
}
void WMGetDataBytesWithRange(WMData * aData, void *buffer, WMRange aRange)
{
wassertr(aRange.position < aData->length);
wassertr(aRange.count <= aData->length - aRange.position);
memcpy(buffer, (unsigned char *)aData->bytes + aRange.position, aRange.count);
}
WMData *WMGetSubdataWithRange(WMData * aData, WMRange aRange)
{
void *buffer;
WMData *newData;
if (aRange.count <= 0)
return WMCreateDataWithCapacity(0);
buffer = wmalloc(aRange.count);
WMGetDataBytesWithRange(aData, buffer, aRange);
newData = WMCreateDataWithBytesNoCopy(buffer, aRange.count, wfree);
newData->format = aData->format;
return newData;
}
/* Testing data */
Bool WMIsDataEqualToData(WMData * aData, WMData * anotherData)
{
if (aData->length != anotherData->length)
return False;
else if (!aData->bytes && !anotherData->bytes) /* both are empty */
return True;
else if (!aData->bytes || !anotherData->bytes) /* one of them is empty */
return False;
return (memcmp(aData->bytes, anotherData->bytes, aData->length) == 0);
}
unsigned WMGetDataLength(WMData * aData)
{
return aData->length;
}
/* Adding data */
void WMAppendDataBytes(WMData * aData, const void *bytes, unsigned length)
{
unsigned oldLength = aData->length;
unsigned newLength = oldLength + length;
if (newLength > aData->capacity) {
unsigned nextCapacity = aData->capacity + aData->growth;
unsigned nextGrowth = aData->capacity ? aData->capacity : 1;
while (nextCapacity < newLength) {
unsigned tmp = nextCapacity + nextGrowth;
nextGrowth = nextCapacity;
nextCapacity = tmp;
}
WMSetDataCapacity(aData, nextCapacity);
aData->growth = nextGrowth;
}
memcpy((unsigned char *)aData->bytes + oldLength, bytes, length);
aData->length = newLength;
}
void WMAppendData(WMData * aData, WMData * anotherData)
{
if (anotherData->length > 0)
WMAppendDataBytes(aData, anotherData->bytes, anotherData->length);
}
/* Modifying data */
void WMReplaceDataBytesInRange(WMData * aData, WMRange aRange, const void *bytes)
{
wassertr(aRange.position < aData->length);
wassertr(aRange.count <= aData->length - aRange.position);
memcpy((unsigned char *)aData->bytes + aRange.position, bytes, aRange.count);
}
void WMResetDataBytesInRange(WMData * aData, WMRange aRange)
{
wassertr(aRange.position < aData->length);
wassertr(aRange.count <= aData->length - aRange.position);
memset((unsigned char *)aData->bytes + aRange.position, 0, aRange.count);
}
void WMSetData(WMData * aData, WMData * anotherData)
{
unsigned length = anotherData->length;
WMSetDataCapacity(aData, length);
if (length > 0)
memcpy(aData->bytes, anotherData->bytes, length);
aData->length = length;
}
/* Storing data */
+1 -1
View File
@@ -498,7 +498,7 @@ static void registerDescriptionList(WMScreen * scr, WMView * view, WMArray * ope
for (i = 0; i < count; i++) {
text = WMGetDragOperationItemText(WMGetFromArray(operationArray, i));
strlcpy(textListItem, text, size);
wstrlcpy(textListItem, text, size);
/* to next text offset */
textListItem = &(textListItem[strlen(textListItem) + 1]);
+429 -2
View File
@@ -34,6 +34,331 @@
#include <pwd.h>
#include <limits.h>
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
const char *wgethomedir(void)
{
static char *home = NULL;
char *tmp;
struct passwd *user;
if (home)
return home;
tmp = GETENV("HOME");
if (tmp) {
home = wstrdup(tmp);
return home;
}
user = getpwuid(getuid());
if (!user) {
werror(_("could not get password entry for UID %i"), getuid());
home = "/";
return home;
}
if (!user->pw_dir)
home = "/";
else
home = wstrdup(user->pw_dir);
return home;
}
/*
* Return the home directory for the specified used
*
* If user not found, returns NULL, otherwise always returns a path that is
* statically stored.
*
* Please note you must use the path before any other call to 'getpw*' or it
* may be erased. This is a design choice to avoid duplication considering
* the use case for this function.
*/
static const char *getuserhomedir(const char *username)
{
static const char default_home[] = "/";
struct passwd *user;
user = getpwnam(username);
if (!user) {
werror(_("could not get password entry for user %s"), username);
return NULL;
}
if (!user->pw_dir)
return default_home;
else
return user->pw_dir;
}
char *wexpandpath(const char *path)
{
const char *origpath = path;
char buffer2[PATH_MAX + 2];
char buffer[PATH_MAX + 2];
int i;
memset(buffer, 0, PATH_MAX + 2);
if (*path == '~') {
const char *home;
path++;
if (*path == '/' || *path == 0) {
home = wgethomedir();
if (strlen(home) > PATH_MAX ||
wstrlcpy(buffer, home, sizeof(buffer)) >= sizeof(buffer))
goto error;
} else {
int j;
j = 0;
while (*path != 0 && *path != '/') {
if (j > PATH_MAX)
goto error;
buffer2[j++] = *path;
buffer2[j] = 0;
path++;
}
home = getuserhomedir(buffer2);
if (!home || wstrlcat(buffer, home, sizeof(buffer)) >= sizeof(buffer))
goto error;
}
}
i = strlen(buffer);
while (*path != 0 && i <= PATH_MAX) {
char *tmp;
if (*path == '$') {
int j;
path++;
/* expand $(HOME) or $HOME style environment variables */
if (*path == '(') {
path++;
j = 0;
while (*path != 0 && *path != ')') {
if (j > PATH_MAX)
goto error;
buffer2[j++] = *(path++);
}
buffer2[j] = 0;
if (*path == ')') {
path++;
tmp = getenv(buffer2);
} else {
tmp = NULL;
}
if (!tmp) {
if ((i += strlen(buffer2) + 2) > PATH_MAX)
goto error;
buffer[i] = 0;
if (wstrlcat(buffer, "$(", sizeof(buffer)) >= sizeof(buffer) ||
wstrlcat(buffer, buffer2, sizeof(buffer)) >= sizeof(buffer))
goto error;
if (*(path-1)==')') {
if (++i > PATH_MAX ||
wstrlcat(buffer, ")", sizeof(buffer)) >= sizeof(buffer))
goto error;
}
} else {
if ((i += strlen(tmp)) > PATH_MAX ||
wstrlcat(buffer, tmp, sizeof(buffer)) >= sizeof(buffer))
goto error;
}
} else {
j = 0;
while (*path != 0 && *path != '/') {
if (j > PATH_MAX)
goto error;
buffer2[j++] = *(path++);
}
buffer2[j] = 0;
tmp = getenv(buffer2);
if (!tmp) {
if ((i += strlen(buffer2) + 1) > PATH_MAX ||
wstrlcat(buffer, "$", sizeof(buffer)) >= sizeof(buffer) ||
wstrlcat(buffer, buffer2, sizeof(buffer)) >= sizeof(buffer))
goto error;
} else {
if ((i += strlen(tmp)) > PATH_MAX ||
wstrlcat(buffer, tmp, sizeof(buffer)) >= sizeof(buffer))
goto error;
}
}
} else {
buffer[i++] = *path;
path++;
}
}
if (*path!=0)
goto error;
return wstrdup(buffer);
error:
errno = ENAMETOOLONG;
werror(_("could not expand %s"), origpath);
return NULL;
}
/* return address of next char != tok or end of string whichever comes first */
static const char *skipchar(const char *string, char tok)
{
while (*string != 0 && *string == tok)
string++;
return string;
}
/* return address of next char == tok or end of string whichever comes first */
static const char *nextchar(const char *string, char tok)
{
while (*string != 0 && *string != tok)
string++;
return string;
}
/*
*----------------------------------------------------------------------
* findfile--
* Finds a file in a : separated list of paths. ~ expansion is also
* done.
*
* Returns:
* The complete path for the file (in a newly allocated string) or
* NULL if the file was not found.
*
* Side effects:
* A new string is allocated. It must be freed later.
*
*----------------------------------------------------------------------
*/
char *wfindfile(const char *paths, const char *file)
{
char *path;
const char *tmp, *tmp2;
int len, flen;
char *fullpath;
if (!file)
return NULL;
if (*file == '/' || *file == '~' || *file == '$' || !paths || *paths == 0) {
if (access(file, F_OK) < 0) {
fullpath = wexpandpath(file);
if (!fullpath)
return NULL;
if (access(fullpath, F_OK) < 0) {
wfree(fullpath);
return NULL;
} else {
return fullpath;
}
} else {
return wstrdup(file);
}
}
flen = strlen(file);
tmp = paths;
while (*tmp) {
tmp = skipchar(tmp, ':');
if (*tmp == 0)
break;
tmp2 = nextchar(tmp, ':');
len = tmp2 - tmp;
path = wmalloc(len + flen + 2);
path = memcpy(path, tmp, len);
path[len] = 0;
if (path[len - 1] != '/' &&
wstrlcat(path, "/", len + flen + 2) >= len + flen + 2) {
wfree(path);
return NULL;
}
if (wstrlcat(path, file, len + flen + 2) >= len + flen + 2) {
wfree(path);
return NULL;
}
fullpath = wexpandpath(path);
wfree(path);
if (fullpath) {
if (access(fullpath, F_OK) == 0) {
return fullpath;
}
wfree(fullpath);
}
tmp = tmp2;
}
return NULL;
}
char *wfindfileinlist(char *const *path_list, const char *file)
{
int i;
char *path;
int len, flen;
char *fullpath;
if (!file)
return NULL;
if (*file == '/' || *file == '~' || !path_list) {
if (access(file, F_OK) < 0) {
fullpath = wexpandpath(file);
if (!fullpath)
return NULL;
if (access(fullpath, F_OK) < 0) {
wfree(fullpath);
return NULL;
} else {
return fullpath;
}
} else {
return wstrdup(file);
}
}
flen = strlen(file);
for (i = 0; path_list[i] != NULL; i++) {
len = strlen(path_list[i]);
path = wmalloc(len + flen + 2);
path = memcpy(path, path_list[i], len);
path[len] = 0;
if (wstrlcat(path, "/", len + flen + 2) >= len + flen + 2 ||
wstrlcat(path, file, len + flen + 2) >= len + flen + 2) {
wfree(path);
return NULL;
}
/* expand tilde */
fullpath = wexpandpath(path);
wfree(path);
if (fullpath) {
/* check if file exists */
if (access(fullpath, F_OK) == 0) {
return fullpath;
}
wfree(fullpath);
}
}
return NULL;
}
char *wfindfileinarray(WMPropList *array, const char *file)
{
@@ -76,8 +401,8 @@ char *wfindfileinarray(WMPropList *array, const char *file)
path = wmalloc(len + flen + 2);
path = memcpy(path, p, len);
path[len] = 0;
if (strlcat(path, "/", len + flen + 2) >= len + flen + 2 ||
strlcat(path, file, len + flen + 2) >= len + flen + 2) {
if (wstrlcat(path, "/", len + flen + 2) >= len + flen + 2 ||
wstrlcat(path, file, len + flen + 2) >= len + flen + 2) {
wfree(path);
return NULL;
}
@@ -94,3 +419,105 @@ char *wfindfileinarray(WMPropList *array, const char *file)
}
return NULL;
}
int wcopy_file(const char *dest_dir, const char *src_file, const char *dest_file)
{
char *path_dst;
int fd_src, fd_dst;
struct stat stat_src;
mode_t permission_dst;
const size_t buffer_size = 2 * 1024 * 1024; /* 4MB is a decent start choice to allow the OS to take advantage of modern disk's performance */
char *buffer; /* The buffer is not created on the stack to avoid possible stack overflow as our buffer is big */
try_again_src:
fd_src = open(src_file, O_RDONLY | O_NOFOLLOW);
if (fd_src == -1) {
if (errno == EINTR)
goto try_again_src;
werror(_("Could not open input file \"%s\": %s"), src_file, strerror(errno));
return -1;
}
/* Only accept to copy regular files */
if (fstat(fd_src, &stat_src) != 0 || !S_ISREG(stat_src.st_mode)) {
close(fd_src);
return -1;
}
path_dst = wstrconcat(dest_dir, dest_file);
try_again_dst:
fd_dst = open(path_dst, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd_dst == -1) {
if (errno == EINTR)
goto try_again_dst;
werror(_("Could not create target file \"%s\": %s"), path_dst, strerror(errno));
wfree(path_dst);
close(fd_src);
return -1;
}
buffer = malloc(buffer_size); /* Don't use wmalloc to avoid the memset(0) we don't need */
if (buffer == NULL) {
werror(_("could not allocate memory for the copy buffer"));
close(fd_dst);
goto cleanup_and_return_failure;
}
for (;;) {
ssize_t size_data;
const char *write_ptr;
size_t write_remain;
try_again_read:
size_data = read(fd_src, buffer, buffer_size);
if (size_data == 0)
break; /* End of File have been reached */
if (size_data < 0) {
if (errno == EINTR)
goto try_again_read;
werror(_("could not read from file \"%s\": %s"), src_file, strerror(errno));
close(fd_dst);
goto cleanup_and_return_failure;
}
write_ptr = buffer;
write_remain = size_data;
while (write_remain > 0) {
ssize_t write_done;
try_again_write:
write_done = write(fd_dst, write_ptr, write_remain);
if (write_done < 0) {
if (errno == EINTR)
goto try_again_write;
werror(_("could not write data to file \"%s\": %s"), path_dst, strerror(errno));
close(fd_dst);
goto cleanup_and_return_failure;
}
write_ptr += write_done;
write_remain -= write_done;
}
}
/* Keep only the permission-related part of the field: */
permission_dst = stat_src.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
if (fchmod(fd_dst, permission_dst) != 0)
wwarning(_("could not set permission 0%03o on file \"%s\": %s"),
permission_dst, path_dst, strerror(errno));
if (close(fd_dst) != 0) {
werror(_("could not close the file \"%s\": %s"), path_dst, strerror(errno));
cleanup_and_return_failure:
free(buffer);
close(fd_src);
unlink(path_dst);
wfree(path_dst);
return -1;
}
free(buffer);
wfree(path_dst);
close(fd_src);
return 0;
}
+17 -5
View File
@@ -126,7 +126,7 @@ WMHandlerID WMAddTimerHandler(int milliseconds, WMCallback * callback, void *cda
{
TimerHandler *handler;
handler = wmalloc(sizeof(TimerHandler));
handler = malloc(sizeof(TimerHandler));
if (!handler)
return NULL;
@@ -214,7 +214,7 @@ WMHandlerID WMAddIdleHandler(WMCallback * callback, void *cdata)
{
IdleHandler *handler;
handler = wmalloc(sizeof(IdleHandler));
handler = malloc(sizeof(IdleHandler));
if (!handler)
return NULL;
@@ -274,11 +274,12 @@ Bool W_CheckIdleHandlers(void)
WMArrayIterator iter;
if (!idleHandler || WMGetArrayItemCount(idleHandler) == 0) {
W_FlushIdleNotificationQueue();
/* make sure an observer in queue didn't added an idle handler */
return (idleHandler != NULL && WMGetArrayItemCount(idleHandler) > 0);
}
handlerCopy = WMCreateArrayWithArray(idleHandler);
handlerCopy = WMDuplicateArray(idleHandler);
WM_ITERATE_ARRAY(handlerCopy, handler, iter) {
/* check if the handler still exist or was removed by a callback */
@@ -291,6 +292,8 @@ Bool W_CheckIdleHandlers(void)
WMFreeArray(handlerCopy);
W_FlushIdleNotificationQueue();
/* this is not necesarrily False, because one handler can re-add itself */
return (WMGetArrayItemCount(idleHandler) > 0);
}
@@ -301,6 +304,7 @@ void W_CheckTimerHandlers(void)
struct timeval now;
if (!timerHandler) {
W_FlushASAPNotificationQueue();
return;
}
@@ -327,6 +331,8 @@ void W_CheckTimerHandlers(void)
wfree(handler);
}
}
W_FlushASAPNotificationQueue();
}
/*
@@ -378,6 +384,7 @@ Bool W_HandleInputEvents(Bool waitForInput, int inputfd)
nfds = 0;
if (!extrafd && nfds == 0) {
W_FlushASAPNotificationQueue();
return False;
}
@@ -422,7 +429,7 @@ Bool W_HandleInputEvents(Bool waitForInput, int inputfd)
count = poll(fds, nfds + extrafd, timeout);
if (count > 0 && nfds > 0) {
WMArray *handlerCopy = WMCreateArrayWithArray(inputHandler);
WMArray *handlerCopy = WMDuplicateArray(inputHandler);
int mask;
/* use WM_ITERATE_ARRAY() here */
@@ -454,6 +461,8 @@ Bool W_HandleInputEvents(Bool waitForInput, int inputfd)
wfree(fds);
W_FlushASAPNotificationQueue();
return (count > 0);
#else
#ifdef HAVE_SELECT
@@ -470,6 +479,7 @@ Bool W_HandleInputEvents(Bool waitForInput, int inputfd)
nfds = 0;
if (inputfd < 0 && nfds == 0) {
W_FlushASAPNotificationQueue();
return False;
}
@@ -517,7 +527,7 @@ Bool W_HandleInputEvents(Bool waitForInput, int inputfd)
count = select(1 + maxfd, &rset, &wset, &eset, timeoutPtr);
if (count > 0 && nfds > 0) {
WMArray *handlerCopy = WMCreateArrayWithArray(inputHandler);
WMArray *handlerCopy = WMDuplicateArray(inputHandler);
int mask;
/* use WM_ITERATE_ARRAY() here */
@@ -546,6 +556,8 @@ Bool W_HandleInputEvents(Bool waitForInput, int inputfd)
WMFreeArray(handlerCopy);
}
W_FlushASAPNotificationQueue();
return (count > 0);
#else /* not HAVE_SELECT, not HAVE_POLL */
# error Neither select nor poll. You lose.
+1 -3
View File
@@ -536,14 +536,12 @@ found_end_define_fname:
while (*src != '\0') {
idx = 0;
if (*src == '~') {
char *home_head = wgethomedir();
char *home = home_head;;
const char *home = wgethomedir();
while (*home != '\0') {
if (idx < sizeof(buffer) - 2)
buffer[idx++] = *home;
home++;
}
wfree(home_head);
src++;
}
+2 -2
View File
@@ -652,7 +652,7 @@ static void mpm_get_hostname(WParserMacro *this, WMenuParser parser)
return;
}
}
strlcpy((char *) this->value, h, sizeof(this->value) );
wstrlcpy((char *) this->value, h, sizeof(this->value) );
}
/* Name of the current user */
@@ -677,7 +677,7 @@ static void mpm_get_user_name(WParserMacro *this, WMenuParser parser)
user = pw_user->pw_name;
if (user == NULL) goto error_no_username;
}
strlcpy((char *) this->value, user, sizeof(this->value) );
wstrlcpy((char *) this->value, user, sizeof(this->value) );
}
/* Number id of the user under which we are running */
+482
View File
@@ -0,0 +1,482 @@
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "WUtil.h"
#include "WINGsP.h"
typedef struct W_Notification {
const char *name;
void *object;
void *clientData;
int refCount;
} Notification;
const char *WMGetNotificationName(WMNotification * notification)
{
return notification->name;
}
void *WMGetNotificationObject(WMNotification * notification)
{
return notification->object;
}
void *WMGetNotificationClientData(WMNotification * notification)
{
return notification->clientData;
}
WMNotification *WMCreateNotification(const char *name, void *object, void *clientData)
{
Notification *nPtr;
nPtr = wmalloc(sizeof(Notification));
nPtr->name = name;
nPtr->object = object;
nPtr->clientData = clientData;
nPtr->refCount = 1;
return nPtr;
}
void WMReleaseNotification(WMNotification * notification)
{
notification->refCount--;
if (notification->refCount < 1) {
wfree(notification);
}
}
WMNotification *WMRetainNotification(WMNotification * notification)
{
notification->refCount++;
return notification;
}
/***************** Notification Center *****************/
typedef struct NotificationObserver {
WMNotificationObserverAction *observerAction;
void *observer;
const char *name;
void *object;
struct NotificationObserver *prev; /* for tables */
struct NotificationObserver *next;
struct NotificationObserver *nextAction; /* for observerTable */
} NotificationObserver;
typedef struct W_NotificationCenter {
WMHashTable *nameTable; /* names -> observer lists */
WMHashTable *objectTable; /* object -> observer lists */
NotificationObserver *nilList; /* obervers that catch everything */
WMHashTable *observerTable; /* observer -> NotificationObserver */
} NotificationCenter;
/* default (and only) center */
static NotificationCenter *notificationCenter = NULL;
void W_InitNotificationCenter(void)
{
notificationCenter = wmalloc(sizeof(NotificationCenter));
notificationCenter->nameTable = WMCreateStringHashTable();
notificationCenter->objectTable = WMCreateIdentityHashTable();
notificationCenter->nilList = NULL;
notificationCenter->observerTable = WMCreateIdentityHashTable();
}
void W_ReleaseNotificationCenter(void)
{
if (notificationCenter) {
if (notificationCenter->nameTable)
WMFreeHashTable(notificationCenter->nameTable);
if (notificationCenter->objectTable)
WMFreeHashTable(notificationCenter->objectTable);
if (notificationCenter->observerTable)
WMFreeHashTable(notificationCenter->observerTable);
wfree(notificationCenter);
notificationCenter = NULL;
}
}
void
WMAddNotificationObserver(WMNotificationObserverAction * observerAction,
void *observer, const char *name, void *object)
{
NotificationObserver *oRec, *rec;
oRec = wmalloc(sizeof(NotificationObserver));
oRec->observerAction = observerAction;
oRec->observer = observer;
oRec->name = name;
oRec->object = object;
oRec->next = NULL;
oRec->prev = NULL;
/* put this action in the list of actions for this observer */
rec = (NotificationObserver *) WMHashInsert(notificationCenter->observerTable, observer, oRec);
if (rec) {
/* if this is not the first action for the observer */
oRec->nextAction = rec;
} else {
oRec->nextAction = NULL;
}
if (!name && !object) {
/* catch-all */
oRec->next = notificationCenter->nilList;
if (notificationCenter->nilList) {
notificationCenter->nilList->prev = oRec;
}
notificationCenter->nilList = oRec;
} else if (!name) {
/* any message coming from object */
rec = (NotificationObserver *) WMHashInsert(notificationCenter->objectTable, object, oRec);
oRec->next = rec;
if (rec) {
rec->prev = oRec;
}
} else {
/* name && (object || !object) */
rec = (NotificationObserver *) WMHashInsert(notificationCenter->nameTable, name, oRec);
oRec->next = rec;
if (rec) {
rec->prev = oRec;
}
}
}
void WMPostNotification(WMNotification * notification)
{
NotificationObserver *orec, *tmp;
WMRetainNotification(notification);
/* tell the observers that want to know about a particular message */
orec = (NotificationObserver *) WMHashGet(notificationCenter->nameTable, notification->name);
while (orec) {
tmp = orec->next;
if (!orec->object || !notification->object || orec->object == notification->object) {
/* tell the observer */
if (orec->observerAction) {
(*orec->observerAction) (orec->observer, notification);
}
}
orec = tmp;
}
/* tell the observers that want to know about an object */
orec = (NotificationObserver *) WMHashGet(notificationCenter->objectTable, notification->object);
while (orec) {
tmp = orec->next;
/* tell the observer */
if (orec->observerAction) {
(*orec->observerAction) (orec->observer, notification);
}
orec = tmp;
}
/* tell the catch all observers */
orec = notificationCenter->nilList;
while (orec) {
tmp = orec->next;
/* tell the observer */
if (orec->observerAction) {
(*orec->observerAction) (orec->observer, notification);
}
orec = tmp;
}
WMReleaseNotification(notification);
}
void WMRemoveNotificationObserver(void *observer)
{
NotificationObserver *orec, *tmp, *rec;
/* get the list of actions the observer is doing */
orec = (NotificationObserver *) WMHashGet(notificationCenter->observerTable, observer);
/*
* FOREACH orec IN actionlist for observer
* DO
* remove from respective lists/tables
* free
* END
*/
while (orec) {
tmp = orec->nextAction;
if (!orec->name && !orec->object) {
/* catch-all */
if (notificationCenter->nilList == orec)
notificationCenter->nilList = orec->next;
} else if (!orec->name) {
/* any message coming from object */
rec = (NotificationObserver *) WMHashGet(notificationCenter->objectTable, orec->object);
if (rec == orec) {
/* replace table entry */
if (orec->next) {
WMHashInsert(notificationCenter->objectTable, orec->object, orec->next);
} else {
WMHashRemove(notificationCenter->objectTable, orec->object);
}
}
} else {
/* name && (object || !object) */
rec = (NotificationObserver *) WMHashGet(notificationCenter->nameTable, orec->name);
if (rec == orec) {
/* replace table entry */
if (orec->next) {
WMHashInsert(notificationCenter->nameTable, orec->name, orec->next);
} else {
WMHashRemove(notificationCenter->nameTable, orec->name);
}
}
}
if (orec->prev)
orec->prev->next = orec->next;
if (orec->next)
orec->next->prev = orec->prev;
wfree(orec);
orec = tmp;
}
WMHashRemove(notificationCenter->observerTable, observer);
}
void WMRemoveNotificationObserverWithName(void *observer, const char *name, void *object)
{
NotificationObserver *orec, *tmp, *rec;
NotificationObserver *newList = NULL;
/* get the list of actions the observer is doing */
orec = (NotificationObserver *) WMHashGet(notificationCenter->observerTable, observer);
WMHashRemove(notificationCenter->observerTable, observer);
/* rebuild the list of actions for the observer */
while (orec) {
tmp = orec->nextAction;
if (orec->name == name && orec->object == object) {
if (!name && !object) {
if (notificationCenter->nilList == orec)
notificationCenter->nilList = orec->next;
} else if (!name) {
rec =
(NotificationObserver *) WMHashGet(notificationCenter->objectTable,
orec->object);
if (rec == orec) {
assert(rec->prev == NULL);
/* replace table entry */
if (orec->next) {
WMHashInsert(notificationCenter->objectTable,
orec->object, orec->next);
} else {
WMHashRemove(notificationCenter->objectTable, orec->object);
}
}
} else {
rec = (NotificationObserver *) WMHashGet(notificationCenter->nameTable,
orec->name);
if (rec == orec) {
assert(rec->prev == NULL);
/* replace table entry */
if (orec->next) {
WMHashInsert(notificationCenter->nameTable,
orec->name, orec->next);
} else {
WMHashRemove(notificationCenter->nameTable, orec->name);
}
}
}
if (orec->prev)
orec->prev->next = orec->next;
if (orec->next)
orec->next->prev = orec->prev;
wfree(orec);
} else {
/* append this action in the new action list */
orec->nextAction = NULL;
if (!newList) {
newList = orec;
} else {
NotificationObserver *p;
p = newList;
while (p->nextAction) {
p = p->nextAction;
}
p->nextAction = orec;
}
}
orec = tmp;
}
/* reinsert the list to the table */
if (newList) {
WMHashInsert(notificationCenter->observerTable, observer, newList);
}
}
void WMPostNotificationName(const char *name, void *object, void *clientData)
{
WMNotification *notification;
notification = WMCreateNotification(name, object, clientData);
WMPostNotification(notification);
WMReleaseNotification(notification);
}
/**************** Notification Queues ****************/
typedef struct W_NotificationQueue {
WMArray *asapQueue;
WMArray *idleQueue;
struct W_NotificationQueue *next;
} NotificationQueue;
static WMNotificationQueue *notificationQueueList = NULL;
/* default queue */
static WMNotificationQueue *notificationQueue = NULL;
WMNotificationQueue *WMGetDefaultNotificationQueue(void)
{
if (!notificationQueue)
notificationQueue = WMCreateNotificationQueue();
return notificationQueue;
}
WMNotificationQueue *WMCreateNotificationQueue(void)
{
NotificationQueue *queue;
queue = wmalloc(sizeof(NotificationQueue));
queue->asapQueue = WMCreateArrayWithDestructor(8, (WMFreeDataProc *) WMReleaseNotification);
queue->idleQueue = WMCreateArrayWithDestructor(8, (WMFreeDataProc *) WMReleaseNotification);
queue->next = notificationQueueList;
notificationQueueList = queue;
return queue;
}
void WMEnqueueNotification(WMNotificationQueue * queue, WMNotification * notification, WMPostingStyle postingStyle)
{
WMEnqueueCoalesceNotification(queue, notification, postingStyle, WNCOnName | WNCOnSender);
}
#define NOTIF ((WMNotification*)cdata)
#define ITEM ((WMNotification*)item)
static int matchSenderAndName(const void *item, const void *cdata)
{
return (NOTIF->object == ITEM->object && strcmp(NOTIF->name, ITEM->name) == 0);
}
static int matchSender(const void *item, const void *cdata)
{
return (NOTIF->object == ITEM->object);
}
static int matchName(const void *item, const void *cdata)
{
return (strcmp(NOTIF->name, ITEM->name) == 0);
}
#undef NOTIF
#undef ITEM
void WMDequeueNotificationMatching(WMNotificationQueue * queue, WMNotification * notification, unsigned mask)
{
WMMatchDataProc *matchFunc;
if ((mask & WNCOnName) && (mask & WNCOnSender))
matchFunc = matchSenderAndName;
else if (mask & WNCOnName)
matchFunc = matchName;
else if (mask & WNCOnSender)
matchFunc = matchSender;
else
return;
WMRemoveFromArrayMatching(queue->asapQueue, matchFunc, notification);
WMRemoveFromArrayMatching(queue->idleQueue, matchFunc, notification);
}
void
WMEnqueueCoalesceNotification(WMNotificationQueue * queue,
WMNotification * notification, WMPostingStyle postingStyle, unsigned coalesceMask)
{
if (coalesceMask != WNCNone)
WMDequeueNotificationMatching(queue, notification, coalesceMask);
switch (postingStyle) {
case WMPostNow:
WMPostNotification(notification);
WMReleaseNotification(notification);
break;
case WMPostASAP:
WMAddToArray(queue->asapQueue, notification);
break;
case WMPostWhenIdle:
WMAddToArray(queue->idleQueue, notification);
break;
}
}
void W_FlushASAPNotificationQueue(void)
{
WMNotificationQueue *queue = notificationQueueList;
while (queue) {
while (WMGetArrayItemCount(queue->asapQueue)) {
WMPostNotification(WMGetFromArray(queue->asapQueue, 0));
WMDeleteFromArray(queue->asapQueue, 0);
}
queue = queue->next;
}
}
void W_FlushIdleNotificationQueue(void)
{
WMNotificationQueue *queue = notificationQueueList;
while (queue) {
while (WMGetArrayItemCount(queue->idleQueue)) {
WMPostNotification(WMGetFromArray(queue->idleQueue, 0));
WMDeleteFromArray(queue->idleQueue, 0);
}
queue = queue->next;
}
}
+1840 -6
View File
File diff suppressed because it is too large Load Diff
+3 -4
View File
@@ -237,7 +237,7 @@ static void handleRequestEvent(XEvent * event)
}
/* delete handlers */
copy = WMCreateArrayWithArray(selHandlers);
copy = WMDuplicateArray(selHandlers);
WM_ITERATE_ARRAY(copy, handler, iter) {
if (handler && handler->flags.delete_pending) {
WMDeleteSelectionHandler(handler->view, handler->selection, handler->timestamp);
@@ -261,9 +261,8 @@ static WMData *getSelectionData(Display * dpy, Window win, Atom where)
bpi = bits / 8;
wdata = WMCreateDataWithBytes(data, len * bpi);
wdata = WMCreateDataWithBytesNoCopy(data, len * bpi, (void *) XFree);
WMSetDataFormat(wdata, bits);
XFree(data);
return wdata;
}
@@ -301,7 +300,7 @@ static void handleNotifyEvent(XEvent * event)
}
/* delete callbacks */
copy = WMCreateArrayWithArray(selCallbacks);
copy = WMDuplicateArray(selCallbacks);
WM_ITERATE_ARRAY(copy, handler, iter) {
if (handler && handler->flags.delete_pending) {
WMDeleteSelectionCallback(handler->view, handler->selection, handler->timestamp);
+425
View File
@@ -0,0 +1,425 @@
/*
* Until FreeBSD gets their act together;
* http://www.mail-archive.com/freebsd-hackers@freebsd.org/msg69469.html
*/
#if defined( FREEBSD )
# undef _XOPEN_SOURCE
#endif
#include "wconfig.h"
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <ctype.h>
#ifdef HAVE_BSD_STRING_H
#include <bsd/string.h>
#endif
#include "WUtil.h"
#define PRC_ALPHA 0
#define PRC_BLANK 1
#define PRC_ESCAPE 2
#define PRC_DQUOTE 3
#define PRC_EOS 4
#define PRC_SQUOTE 5
typedef struct {
short nstate;
short output;
} DFA;
static DFA mtable[9][6] = {
{{3, 1}, {0, 0}, {4, 0}, {1, 0}, {8, 0}, {6, 0}},
{{1, 1}, {1, 1}, {2, 0}, {3, 0}, {5, 0}, {1, 1}},
{{1, 1}, {1, 1}, {1, 1}, {1, 1}, {5, 0}, {1, 1}},
{{3, 1}, {5, 0}, {4, 0}, {1, 0}, {5, 0}, {6, 0}},
{{3, 1}, {3, 1}, {3, 1}, {3, 1}, {5, 0}, {3, 1}},
{{-1, -1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* final state */
{{6, 1}, {6, 1}, {7, 0}, {6, 1}, {5, 0}, {3, 0}},
{{6, 1}, {6, 1}, {6, 1}, {6, 1}, {5, 0}, {6, 1}},
{{-1, -1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* final state */
};
char *wtokennext(char *word, char **next)
{
char *ptr;
char *ret, *t;
int state, ctype;
t = ret = wmalloc(strlen(word) + 1);
ptr = word;
state = 0;
while (1) {
if (*ptr == 0)
ctype = PRC_EOS;
else if (*ptr == '\\')
ctype = PRC_ESCAPE;
else if (*ptr == '"')
ctype = PRC_DQUOTE;
else if (*ptr == '\'')
ctype = PRC_SQUOTE;
else if (*ptr == ' ' || *ptr == '\t')
ctype = PRC_BLANK;
else
ctype = PRC_ALPHA;
if (mtable[state][ctype].output) {
*t = *ptr;
t++;
*t = 0;
}
state = mtable[state][ctype].nstate;
ptr++;
if (mtable[state][0].output < 0) {
break;
}
}
if (*ret == 0) {
wfree(ret);
ret = NULL;
}
if (ctype == PRC_EOS)
*next = NULL;
else
*next = ptr;
return ret;
}
/* separate a string in tokens, taking " and ' into account */
void wtokensplit(char *command, char ***argv, int *argc)
{
char *token, *line;
int count;
count = 0;
line = command;
do {
token = wtokennext(line, &line);
if (token) {
if (count == 0)
*argv = wmalloc(sizeof(**argv));
else
*argv = wrealloc(*argv, (count + 1) * sizeof(**argv));
(*argv)[count++] = token;
}
} while (token != NULL && line != NULL);
*argc = count;
}
char *wtokenjoin(char **list, int count)
{
int i, j;
char *flat_string, *wspace;
j = 0;
for (i = 0; i < count; i++) {
if (list[i] != NULL && list[i][0] != 0) {
j += strlen(list[i]);
if (strpbrk(list[i], " \t"))
j += 2;
}
}
flat_string = wmalloc(j + count + 1);
for (i = 0; i < count; i++) {
if (list[i] != NULL && list[i][0] != 0) {
if (i > 0 &&
wstrlcat(flat_string, " ", j + count + 1) >= j + count + 1)
goto error;
wspace = strpbrk(list[i], " \t");
if (wspace &&
wstrlcat(flat_string, "\"", j + count + 1) >= j + count + 1)
goto error;
if (wstrlcat(flat_string, list[i], j + count + 1) >= j + count + 1)
goto error;
if (wspace &&
wstrlcat(flat_string, "\"", j + count + 1) >= j + count + 1)
goto error;
}
}
return flat_string;
error:
wfree(flat_string);
return NULL;
}
void wtokenfree(char **tokens, int count)
{
while (count--)
wfree(tokens[count]);
wfree(tokens);
}
char *wtrimspace(const char *s)
{
const char *t;
if (s == NULL)
return NULL;
while (isspace(*s) && *s)
s++;
t = s + strlen(s) - 1;
while (t > s && isspace(*t))
t--;
return wstrndup(s, t - s + 1);
}
char *wstrdup(const char *str)
{
assert(str != NULL);
return strcpy(wmalloc(strlen(str) + 1), str);
}
char *wstrndup(const char *str, size_t len)
{
char *copy;
assert(str != NULL);
len = WMIN(len, strlen(str));
copy = strncpy(wmalloc(len + 1), str, len);
copy[len] = 0;
return copy;
}
char *wstrconcat(const char *str1, const char *str2)
{
char *str;
size_t slen, slen1;
if (!str1 && str2)
return wstrdup(str2);
else if (str1 && !str2)
return wstrdup(str1);
else if (!str1 && !str2)
return NULL;
slen1 = strlen(str1);
slen = slen1 + strlen(str2) + 1;
str = wmalloc(slen);
strcpy(str, str1);
strcpy(str + slen1, str2);
return str;
}
char *wstrappend(char *dst, const char *src)
{
size_t slen;
if (!src || *src == 0)
return dst;
else if (!dst)
return wstrdup(src);
slen = strlen(dst) + strlen(src) + 1;
dst = wrealloc(dst, slen);
strcat(dst, src);
return dst;
}
#ifdef HAVE_STRLCAT
size_t
wstrlcat(char *dst, const char *src, size_t siz)
{
return strlcat(dst, src, siz);
}
#else
/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
* If retval >= siz, truncation occurred.
*/
size_t
wstrlcat(char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;
size_t n = siz;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0')
d++;
dlen = d - dst;
n = siz - dlen;
if (n == 0)
return(dlen + strlen(s));
while (*s != '\0') {
if (n != 1) {
*d++ = *s;
n--;
}
s++;
}
*d = '\0';
return(dlen + (s - src)); /* count does not include NUL */
}
#endif /* HAVE_STRLCAT */
#ifdef HAVE_STRLCPY
size_t
wstrlcpy(char *dst, const char *src, size_t siz)
{
return strlcpy(dst, src, siz);
}
#else
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t
wstrlcpy(char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;
size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0) {
while (--n != 0) {
if ((*d++ = *s++) == '\0')
break;
}
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return(s - src - 1); /* count does not include NUL */
}
#endif /* HAVE_STRLCPY */
/* transform `s' so that the result is safe to pass to the shell as an argument.
* returns a newly allocated string.
* with very heavy inspirations from NetBSD's shquote(3).
*/
char *wshellquote(const char *s)
{
char *p, *r, *last, *ret;
size_t slen;
int needs_quoting;
if (!s)
return NULL;
needs_quoting = !*s; /* the empty string does need quoting */
/* do not quote if consists only of the following characters */
for (p = (char *)s; *p && !needs_quoting; p++) {
needs_quoting = !(isalnum(*p) || (*p == '+') || (*p == '/') ||
(*p == '.') || (*p == ',') || (*p == '-'));
}
if (!needs_quoting)
return wstrdup(s);
for (slen = 0, p = (char *)s; *p; p++) /* count space needed (worst case) */
slen += *p == '\'' ? 4 : 1; /* every single ' becomes ''\' */
slen += 2 /* leading + trailing "'" */ + 1 /* NULL */;
ret = r = wmalloc(slen);
p = (char *)s;
last = p;
if (*p != '\'') /* if string doesn't already begin with "'" */
*r++ ='\''; /* start putting it in quotes */
while (*p) {
last = p;
if (*p == '\'') { /* turn each ' into ''\' */
if (p != s) /* except if it's the first ', in which case */
*r++ = '\''; /* only escape it */
*r++ = '\\';
*r++ = '\'';
while (*++p && *p == '\'') { /* keep turning each consecutive 's into \' */
*r++ = '\\';
*r++ = '\'';
}
if (*p) /* if more input follows, terminate */
*r++ = '\''; /* what we have so far */
} else {
*r++ = *p++;
}
}
if (*last != '\'') /* if the last one isn't already a ' */
*r++ = '\''; /* terminate the whole shebang */
*r = '\0';
return ret; /* technically, we lose (but not leak) a couple of */
/* bytes (twice the number of consecutive 's in the */
/* input or so), but since these are relatively rare */
/* and short-lived strings, not sure if a trip to */
/* wstrdup+wfree worths the gain. */
}
+255
View File
@@ -0,0 +1,255 @@
#include <string.h>
#include "WUtil.h"
typedef struct W_TreeNode {
void *data;
/*unsigned int uflags:16; */
WMArray *leaves;
int depth;
struct W_TreeNode *parent;
WMFreeDataProc *destructor;
} W_TreeNode;
static void destroyNode(void *data)
{
WMTreeNode *aNode = (WMTreeNode *) data;
if (aNode->destructor) {
(*aNode->destructor) (aNode->data);
}
if (aNode->leaves) {
WMFreeArray(aNode->leaves);
}
wfree(aNode);
}
WMTreeNode *WMCreateTreeNode(void *data)
{
return WMCreateTreeNodeWithDestructor(data, NULL);
}
WMTreeNode *WMCreateTreeNodeWithDestructor(void *data, WMFreeDataProc * destructor)
{
WMTreeNode *aNode;
aNode = (WMTreeNode *) wmalloc(sizeof(W_TreeNode));
aNode->destructor = destructor;
aNode->data = data;
aNode->parent = NULL;
aNode->depth = 0;
aNode->leaves = NULL;
/*aNode->leaves = WMCreateArrayWithDestructor(1, destroyNode); */
return aNode;
}
WMTreeNode *WMInsertItemInTree(WMTreeNode * parent, int index, void *item)
{
WMTreeNode *aNode;
wassertrv(parent != NULL, NULL);
aNode = WMCreateTreeNodeWithDestructor(item, parent->destructor);
aNode->parent = parent;
aNode->depth = parent->depth + 1;
if (!parent->leaves) {
parent->leaves = WMCreateArrayWithDestructor(1, destroyNode);
}
if (index < 0) {
WMAddToArray(parent->leaves, aNode);
} else {
WMInsertInArray(parent->leaves, index, aNode);
}
return aNode;
}
static void updateNodeDepth(WMTreeNode * aNode, int depth)
{
int i;
aNode->depth = depth;
if (aNode->leaves) {
for (i = 0; i < WMGetArrayItemCount(aNode->leaves); i++) {
updateNodeDepth(WMGetFromArray(aNode->leaves, i), depth + 1);
}
}
}
WMTreeNode *WMInsertNodeInTree(WMTreeNode * parent, int index, WMTreeNode * aNode)
{
wassertrv(parent != NULL, NULL);
wassertrv(aNode != NULL, NULL);
aNode->parent = parent;
updateNodeDepth(aNode, parent->depth + 1);
if (!parent->leaves) {
parent->leaves = WMCreateArrayWithDestructor(1, destroyNode);
}
if (index < 0) {
WMAddToArray(parent->leaves, aNode);
} else {
WMInsertInArray(parent->leaves, index, aNode);
}
return aNode;
}
void WMDestroyTreeNode(WMTreeNode * aNode)
{
wassertr(aNode != NULL);
if (aNode->parent && aNode->parent->leaves) {
WMRemoveFromArray(aNode->parent->leaves, aNode);
} else {
destroyNode(aNode);
}
}
void WMDeleteLeafForTreeNode(WMTreeNode * aNode, int index)
{
wassertr(aNode != NULL);
wassertr(aNode->leaves != NULL);
WMDeleteFromArray(aNode->leaves, index);
}
static int sameData(const void *item, const void *data)
{
return (((WMTreeNode *) item)->data == data);
}
void WMRemoveLeafForTreeNode(WMTreeNode * aNode, void *leaf)
{
int index;
wassertr(aNode != NULL);
wassertr(aNode->leaves != NULL);
index = WMFindInArray(aNode->leaves, sameData, leaf);
if (index != WANotFound) {
WMDeleteFromArray(aNode->leaves, index);
}
}
void *WMReplaceDataForTreeNode(WMTreeNode * aNode, void *newData)
{
void *old;
wassertrv(aNode != NULL, NULL);
old = aNode->data;
aNode->data = newData;
return old;
}
void *WMGetDataForTreeNode(WMTreeNode * aNode)
{
return aNode->data;
}
int WMGetTreeNodeDepth(WMTreeNode * aNode)
{
return aNode->depth;
}
WMTreeNode *WMGetParentForTreeNode(WMTreeNode * aNode)
{
return aNode->parent;
}
void WMSortLeavesForTreeNode(WMTreeNode * aNode, WMCompareDataProc * comparer)
{
wassertr(aNode != NULL);
if (aNode->leaves) {
WMSortArray(aNode->leaves, comparer);
}
}
static void sortLeavesForNode(WMTreeNode * aNode, WMCompareDataProc * comparer)
{
int i;
if (!aNode->leaves)
return;
WMSortArray(aNode->leaves, comparer);
for (i = 0; i < WMGetArrayItemCount(aNode->leaves); i++) {
sortLeavesForNode(WMGetFromArray(aNode->leaves, i), comparer);
}
}
void WMSortTree(WMTreeNode * aNode, WMCompareDataProc * comparer)
{
wassertr(aNode != NULL);
sortLeavesForNode(aNode, comparer);
}
static WMTreeNode *findNodeInTree(WMTreeNode * aNode, WMMatchDataProc * match, void *cdata, int limit)
{
if (match == NULL && aNode->data == cdata)
return aNode;
else if (match && (*match) (aNode->data, cdata))
return aNode;
if (aNode->leaves && limit != 0) {
WMTreeNode *leaf;
int i;
for (i = 0; i < WMGetArrayItemCount(aNode->leaves); i++) {
leaf = findNodeInTree(WMGetFromArray(aNode->leaves, i),
match, cdata, limit > 0 ? limit - 1 : limit);
if (leaf)
return leaf;
}
}
return NULL;
}
WMTreeNode *WMFindInTree(WMTreeNode * aTree, WMMatchDataProc * match, void *cdata)
{
wassertrv(aTree != NULL, NULL);
return findNodeInTree(aTree, match, cdata, -1);
}
WMTreeNode *WMFindInTreeWithDepthLimit(WMTreeNode * aTree, WMMatchDataProc * match, void *cdata, int limit)
{
wassertrv(aTree != NULL, NULL);
wassertrv(limit >= 0, NULL);
return findNodeInTree(aTree, match, cdata, limit);
}
void WMTreeWalk(WMTreeNode * aNode, WMTreeWalkProc * walk, void *data, Bool DepthFirst)
{
int i;
WMTreeNode *leaf;
wassertr(aNode != NULL);
if (DepthFirst)
(*walk)(aNode, data);
if (aNode->leaves) {
for (i = 0; i < WMGetArrayItemCount(aNode->leaves); i++) {
leaf = (WMTreeNode *)WMGetFromArray(aNode->leaves, i);
WMTreeWalk(leaf, walk, data, DepthFirst);
}
}
if (!DepthFirst)
(*walk)(aNode, data);
}
+36 -2
View File
@@ -46,6 +46,40 @@ static void synchronizeUserDefaults(void *foo);
#define UD_SYNC_INTERVAL 2000
#endif
const char *wusergnusteppath(void)
{
static const char subdir[] = "/" GSUSER_SUBDIR;
static char *path = NULL;
char *gspath;
const char *h;
int pathlen;
if (path)
/* Value have been already computed, re-use it */
return path;
gspath = GETENV("WMAKER_USER_ROOT");
if (gspath) {
gspath = wexpandpath(gspath);
if (gspath) {
path = gspath;
return path;
}
wwarning(_("variable WMAKER_USER_ROOT defined with invalid path, not used"));
}
h = wgethomedir();
if (!h)
return NULL;
pathlen = strlen(h);
path = wmalloc(pathlen + sizeof(subdir));
strcpy(path, h);
strcpy(path + pathlen, subdir);
return path;
}
const char *wuserdatapath(void)
{
static char *path = NULL;
@@ -297,7 +331,7 @@ WMUserDefaults *WMGetStandardUserDefaults(void)
/* terminate list */
defaults->searchList[2] = NULL;
defaults->searchListArray = WMCreateEmptyPLArray();
defaults->searchListArray = WMCreatePLArray(NULL, NULL);
i = 0;
while (defaults->searchList[i]) {
@@ -370,7 +404,7 @@ WMUserDefaults *WMGetDefaultsFromPath(const char *path)
/* terminate list */
defaults->searchList[1] = NULL;
defaults->searchListArray = WMCreateEmptyPLArray();
defaults->searchListArray = WMCreatePLArray(NULL, NULL);
i = 0;
while (defaults->searchList[i]) {
+11 -8
View File
@@ -44,6 +44,9 @@ void WMInitializeApplication(const char *applicationName, int *argc, char **argv
WMApplication.argv[i] = wstrdup(argv[i]);
}
WMApplication.argv[i] = NULL;
/* initialize notification center */
W_InitNotificationCenter();
}
void WMReleaseApplication(void) {
@@ -57,7 +60,7 @@ void WMReleaseApplication(void) {
*/
w_save_defaults_changes();
W_ClearNotificationCenter();
W_ReleaseNotificationCenter();
if (WMApplication.applicationName) {
wfree(WMApplication.applicationName);
@@ -98,21 +101,21 @@ static char *checkFile(const char *path, const char *folder, const char *ext, co
slen = strlen(path) + strlen(resource) + 1 + extralen;
ret = wmalloc(slen);
if (strlcpy(ret, path, slen) >= slen)
if (wstrlcpy(ret, path, slen) >= slen)
goto error;
if (folder &&
(strlcat(ret, "/", slen) >= slen ||
strlcat(ret, folder, slen) >= slen))
(wstrlcat(ret, "/", slen) >= slen ||
wstrlcat(ret, folder, slen) >= slen))
goto error;
if (ext &&
(strlcat(ret, "/", slen) >= slen ||
strlcat(ret, ext, slen) >= slen))
(wstrlcat(ret, "/", slen) >= slen ||
wstrlcat(ret, ext, slen) >= slen))
goto error;
if (strlcat(ret, "/", slen) >= slen ||
strlcat(ret, resource, slen) >= slen)
if (wstrlcat(ret, "/", slen) >= slen ||
wstrlcat(ret, resource, slen) >= slen)
goto error;
if (access(ret, F_OK) != 0)
+9 -9
View File
@@ -314,7 +314,7 @@ static void removeColumn(WMBrowser * bPtr, int column)
wfree(bPtr->titles[i]);
bPtr->titles[i] = NULL;
}
WMRemoveNotificationObserver(bPtr->columns[i]);
WMRemoveNotificationObserverWithName(bPtr, WMListSelectionDidChangeNotification, bPtr->columns[i]);
WMDestroyWidget(bPtr->columns[i]);
bPtr->columns[i] = NULL;
}
@@ -720,14 +720,14 @@ char *WMGetBrowserPathToColumn(WMBrowser * bPtr, int column)
path = wmalloc(slen);
/* ignore first `/' */
for (i = 0; i <= column; i++) {
if (strlcat(path, bPtr->pathSeparator, slen) >= slen)
if (wstrlcat(path, bPtr->pathSeparator, slen) >= slen)
goto error;
item = WMGetListSelectedItem(bPtr->columns[i]);
if (!item)
break;
if (strlcat(path, item->text, slen) >= slen)
if (wstrlcat(path, item->text, slen) >= slen)
goto error;
}
@@ -782,7 +782,7 @@ WMArray *WMGetBrowserPaths(WMBrowser * bPtr)
path = wmalloc(slen);
/* ignore first `/' */
for (i = 0; i <= column; i++) {
strlcat(path, bPtr->pathSeparator, slen);
wstrlcat(path, bPtr->pathSeparator, slen);
if (i == column) {
item = lastItem;
} else {
@@ -790,7 +790,7 @@ WMArray *WMGetBrowserPaths(WMBrowser * bPtr)
}
if (!item)
break;
strlcat(path, item->text, slen);
wstrlcat(path, item->text, slen);
}
WMAddToArray(paths, path);
}
@@ -1130,25 +1130,25 @@ static char *createTruncatedString(WMFont * font, const char *text, int *textLen
if (width >= 3 * dLen) {
int tmpTextLen = *textLen;
if (strlcpy(textBuf, text, slen) >= slen)
if (wstrlcpy(textBuf, text, slen) >= slen)
goto error;
while (tmpTextLen && (WMWidthOfString(font, textBuf, tmpTextLen) + 3 * dLen > width))
tmpTextLen--;
if (strlcpy(textBuf + tmpTextLen, "...", slen) >= slen)
if (wstrlcpy(textBuf + tmpTextLen, "...", slen) >= slen)
goto error;
*textLen = tmpTextLen + 3;
} else if (width >= 2 * dLen) {
if (strlcpy(textBuf, "..", slen) >= slen)
if (wstrlcpy(textBuf, "..", slen) >= slen)
goto error;
*textLen = 2;
} else if (width >= dLen) {
if (strlcpy(textBuf, ".", slen) >= slen)
if (wstrlcpy(textBuf, ".", slen) >= slen)
goto error;
*textLen = 1;
+3 -6
View File
@@ -2994,13 +2994,10 @@ static void customPaletteMenuNewFromFile(W_ColorPanel * panel)
int i;
RImage *tmpImg = NULL;
if ((!panel->lastBrowseDir) || (strcmp(panel->lastBrowseDir, "\0") == 0)) {
char *homedir = wgethomedir();
spath = wexpandpath(homedir);
wfree(homedir);
} else {
if ((!panel->lastBrowseDir) || (strcmp(panel->lastBrowseDir, "\0") == 0))
spath = wexpandpath(wgethomedir());
else
spath = wexpandpath(panel->lastBrowseDir);
}
browseP = WMGetOpenPanel(scr);
WMSetFilePanelCanChooseDirectories(browseP, 0);
+10 -8
View File
@@ -513,12 +513,12 @@ static void listDirectoryOnColumn(WMFilePanel * panel, int column, const char *p
if (strcmp(dentry->d_name, ".") == 0 || strcmp(dentry->d_name, "..") == 0)
continue;
if (strlcpy(pbuf, path, sizeof(pbuf)) >= sizeof(pbuf))
if (wstrlcpy(pbuf, path, sizeof(pbuf)) >= sizeof(pbuf))
goto out;
if (strcmp(path, "/") != 0 &&
strlcat(pbuf, "/", sizeof(pbuf)) >= sizeof(pbuf))
wstrlcat(pbuf, "/", sizeof(pbuf)) >= sizeof(pbuf))
goto out;
if (strlcat(pbuf, dentry->d_name, sizeof(pbuf)) >= sizeof(pbuf))
if (wstrlcat(pbuf, dentry->d_name, sizeof(pbuf)) >= sizeof(pbuf))
goto out;
if (stat(pbuf, &stat_buf) != 0) {
@@ -626,11 +626,11 @@ static void createDir(WMWidget *widget, void *p_panel)
file = wmalloc(slen);
if (directory &&
(strlcat(file, directory, slen) >= slen ||
strlcat(file, "/", slen) >= slen))
(wstrlcat(file, directory, slen) >= slen ||
wstrlcat(file, "/", slen) >= slen))
goto out;
if (strlcat(file, dirName, slen) >= slen)
if (wstrlcat(file, dirName, slen) >= slen)
goto out;
if (mkdir(file, 00777) != 0) {
@@ -761,15 +761,17 @@ static void goFloppy(WMWidget *widget, void *p_panel)
static void goHome(WMWidget *widget, void *p_panel)
{
WMFilePanel *panel = p_panel;
char *home;
const char *home;
/* Parameter not used, but tell the compiler that it is ok */
(void) widget;
/* home is statically allocated. Don't free it! */
home = wgethomedir();
if (!home)
return;
WMSetFilePanelDirectory(panel, home);
wfree(home);
}
static void handleEvents(XEvent * event, void *data)
+3 -9
View File
@@ -51,15 +51,12 @@ static char *xlfdToFcName(const char *xlfd)
{
FcPattern *pattern;
char *fname;
char *result;
pattern = xlfdToFcPattern(xlfd);
fname = (char *)FcNameUnparse(pattern);
result = wstrdup(fname);
free(fname);
FcPatternDestroy(pattern);
return result;
return fname;
}
static Bool hasProperty(FcPattern * pattern, const char *property)
@@ -95,7 +92,6 @@ static Bool hasPropertyWithStringValue(FcPattern * pattern, const char *object,
static char *makeFontOfSize(const char *font, int size, const char *fallback)
{
FcPattern *pattern;
char *name;
char *result;
if (font[0] == '-') {
@@ -119,9 +115,7 @@ static char *makeFontOfSize(const char *font, int size, const char *fallback)
/*FcPatternPrint(pattern); */
name = (char *)FcNameUnparse(pattern);
result = wstrdup(name);
free(name);
result = (char *)FcNameUnparse(pattern);
FcPatternDestroy(pattern);
return result;
@@ -427,7 +421,7 @@ WMFont *WMCopyFontWithStyle(WMScreen * scrPtr, WMFont * font, WMFontStyle style)
name = (char *)FcNameUnparse(pattern);
copy = WMCreateFont(scrPtr, name);
FcPatternDestroy(pattern);
free(name);
wfree(name);
return copy;
}
+3 -3
View File
@@ -558,7 +558,7 @@ static void listFamilies(WMScreen * scr, WMFontPanel * panel)
WMListItem *item;
WM_ITERATE_ARRAY(array, fam, i) {
strlcpy(buffer, fam->name, sizeof(buffer));
wstrlcpy(buffer, fam->name, sizeof(buffer));
item = WMAddListItem(panel->famLs, buffer);
item->clientData = fam;
@@ -640,7 +640,7 @@ static void familyClick(WMWidget * w, void *data)
int top = 0;
WMListItem *fitem;
strlcpy(buffer, face->typeface, sizeof(buffer));
wstrlcpy(buffer, face->typeface, sizeof(buffer));
if (strcasecmp(face->typeface, "Roman") == 0)
top = 1;
if (strcasecmp(face->typeface, "Regular") == 0)
@@ -773,7 +773,7 @@ static void setFontPanelFontName(FontPanel * panel, const char *family, const ch
int top = 0;
WMListItem *fitem;
strlcpy(buffer, face->typeface, sizeof(buffer));
wstrlcpy(buffer, face->typeface, sizeof(buffer));
if (strcasecmp(face->typeface, "Roman") == 0)
top = 1;
if (top)
+2 -1
View File
@@ -610,9 +610,10 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
assert(W_ApplicationInitialized());
}
scrPtr = wmalloc(sizeof(W_Screen));
scrPtr = malloc(sizeof(W_Screen));
if (!scrPtr)
return NULL;
memset(scrPtr, 0, sizeof(W_Screen));
scrPtr->aflags.hasAppIcon = 1;
+10
View File
@@ -166,6 +166,16 @@ typedef struct W_Text {
WMArray *xdndDestinationTypes;
} Text;
/* not used */
#if 0
#define NOTIFY(T,C,N,A) {\
WMNotification *notif = WMCreateNotification(N,T,A);\
if ((T)->delegate && (T)->delegate->C)\
(*(T)->delegate->C)((T)->delegate,notif);\
WMPostNotification(notif);\
WMReleaseNotification(notif);}
#endif
#define TYPETEXT 0
#if 0
+32 -41
View File
@@ -68,6 +68,12 @@ typedef struct W_TextField {
} flags;
} TextField;
#define NOTIFY(T,C,N,A) { WMNotification *notif = WMCreateNotification(N,T,A);\
if ((T)->delegate && (T)->delegate->C)\
(*(T)->delegate->C)((T)->delegate,notif);\
WMPostNotification(notif);\
WMReleaseNotification(notif);}
#define MIN_TEXT_BUFFER 2
#define TEXT_BUFFER_INCR 8
@@ -398,7 +404,7 @@ void WMInsertTextFieldText(WMTextField * tPtr, const char *text, int position)
if (position < 0 || position >= tPtr->textLen) {
/* append the text at the end */
strlcat(tPtr->text, text, tPtr->bufferSize);
wstrlcat(tPtr->text, text, tPtr->bufferSize);
tPtr->textLen += len;
tPtr->cursorPosition += len;
incrToFit(tPtr);
@@ -467,7 +473,7 @@ void WMSetTextFieldText(WMTextField * tPtr, const char *text)
tPtr->bufferSize = tPtr->textLen + TEXT_BUFFER_INCR;
tPtr->text = wrealloc(tPtr->text, tPtr->bufferSize);
}
strlcpy(tPtr->text, text, tPtr->bufferSize);
wstrlcpy(tPtr->text, text, tPtr->bufferSize);
}
tPtr->cursorPosition = tPtr->selection.position = tPtr->textLen;
@@ -900,10 +906,7 @@ static void handleEvents(XEvent * event, void *data)
paintTextField(tPtr);
if (tPtr->delegate && tPtr->delegate->didBeginEditing) {
(*tPtr->delegate->didBeginEditing)(tPtr->delegate, 0);
}
WMPostNotificationName(WMTextDidBeginEditingNotification, tPtr, NULL);
NOTIFY(tPtr, didBeginEditing, WMTextDidBeginEditingNotification, NULL);
tPtr->flags.notIllegalMovement = 0;
break;
@@ -918,10 +921,8 @@ static void handleEvents(XEvent * event, void *data)
paintTextField(tPtr);
if (!tPtr->flags.notIllegalMovement) {
if (tPtr->delegate && tPtr->delegate->didEndEditing) {
(*tPtr->delegate->didEndEditing)(tPtr->delegate, WMIllegalTextMovement);
}
WMPostNotificationName(WMTextDidEndEditingNotification, tPtr, (void *)WMIllegalTextMovement);
NOTIFY(tPtr, didEndEditing, WMTextDidEndEditingNotification,
(void *)WMIllegalTextMovement);
}
break;
@@ -942,8 +943,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
char buffer[64];
KeySym ksym;
const char *textEvent = NULL;
WMTextMovementType movement_type;
WMTextFieldSpecialEventType special_field_event_type;
void *data = NULL;
int count, refresh = 0;
int control_pressed = 0;
int cancelSelection = 1;
@@ -975,14 +975,14 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
tPtr->view->prevFocusChain);
tPtr->flags.notIllegalMovement = 1;
}
movement_type = WMBacktabTextMovement;
data = (void *)WMBacktabTextMovement;
} else {
if (tPtr->view->nextFocusChain) {
W_SetFocusOfTopLevel(W_TopLevelOfView(tPtr->view),
tPtr->view->nextFocusChain);
tPtr->flags.notIllegalMovement = 1;
}
movement_type = WMTabTextMovement;
data = (void *)WMTabTextMovement;
}
textEvent = WMTextDidEndEditingNotification;
@@ -994,7 +994,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
case XK_Escape:
if (!modified) {
movement_type = WMEscapeTextMovement;
data = (void *)WMEscapeTextMovement;
textEvent = WMTextDidEndEditingNotification;
relay = False;
@@ -1008,7 +1008,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
/* FALLTHRU */
case XK_Return:
if (!modified) {
movement_type = WMReturnTextMovement;
data = (void *)WMReturnTextMovement;
textEvent = WMTextDidEndEditingNotification;
relay = False;
@@ -1165,7 +1165,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
if (!modified) {
if (tPtr->selection.count) {
WMDeleteTextFieldRange(tPtr, tPtr->selection);
special_field_event_type = WMDeleteTextEvent;
data = (void *)WMDeleteTextEvent;
textEvent = WMTextDidChangeNotification;
} else if (tPtr->cursorPosition > 0) {
int i = oneUTF8CharBackward(&tPtr->text[tPtr->cursorPosition],
@@ -1174,7 +1174,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
range.position = tPtr->cursorPosition + i;
range.count = -i;
WMDeleteTextFieldRange(tPtr, range);
special_field_event_type = WMDeleteTextEvent;
data = (void *)WMDeleteTextEvent;
textEvent = WMTextDidChangeNotification;
}
@@ -1197,7 +1197,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
if (!modified) {
if (tPtr->selection.count) {
WMDeleteTextFieldRange(tPtr, tPtr->selection);
special_field_event_type = WMDeleteTextEvent;
data = (void *)WMDeleteTextEvent;
textEvent = WMTextDidChangeNotification;
} else if (tPtr->cursorPosition < tPtr->textLen) {
WMRange range;
@@ -1205,7 +1205,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
range.count = oneUTF8CharForward(&tPtr->text[tPtr->cursorPosition],
tPtr->textLen - tPtr->cursorPosition);
WMDeleteTextFieldRange(tPtr, range);
special_field_event_type = WMDeleteTextEvent;
data = (void *)WMDeleteTextEvent;
textEvent = WMTextDidChangeNotification;
}
@@ -1220,7 +1220,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
if (tPtr->selection.count)
WMDeleteTextFieldRange(tPtr, tPtr->selection);
WMInsertTextFieldText(tPtr, buffer, tPtr->cursorPosition);
special_field_event_type = WMInsertTextEvent;
data = (void *)WMInsertTextEvent;
textEvent = WMTextDidChangeNotification;
relay = False;
@@ -1255,22 +1255,21 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
/*printf("(%d,%d)\n", tPtr->selection.position, tPtr->selection.count); */
if (textEvent) {
WMNotification *notif = WMCreateNotification(textEvent, tPtr, data);
if (tPtr->delegate) {
if (textEvent == WMTextDidBeginEditingNotification && tPtr->delegate->didBeginEditing)
(*tPtr->delegate->didBeginEditing) (tPtr->delegate, movement_type);
(*tPtr->delegate->didBeginEditing) (tPtr->delegate, notif);
else if (textEvent == WMTextDidEndEditingNotification && tPtr->delegate->didEndEditing)
(*tPtr->delegate->didEndEditing) (tPtr->delegate, movement_type);
(*tPtr->delegate->didEndEditing) (tPtr->delegate, notif);
else if (textEvent == WMTextDidChangeNotification && tPtr->delegate->didChange)
(*tPtr->delegate->didChange) (tPtr->delegate, special_field_event_type);
(*tPtr->delegate->didChange) (tPtr->delegate, notif);
}
if (textEvent == WMTextDidBeginEditingNotification || textEvent == WMTextDidEndEditingNotification) {
WMPostNotificationName(textEvent, tPtr, (void *)movement_type);
} else if (textEvent == WMTextDidChangeNotification) {
WMPostNotificationName(textEvent, tPtr, (void *)special_field_event_type);
}
WMPostNotification(notif);
WMReleaseNotification(notif);
}
if (refresh)
@@ -1346,10 +1345,7 @@ static void pasteText(WMView * view, Atom selection, Atom target, Time timestamp
str = (char *)WMDataBytes(data);
WMInsertTextFieldText(tPtr, str, tPtr->cursorPosition);
if (tPtr->delegate && tPtr->delegate->didChange) {
(*tPtr->delegate->didChange)(tPtr->delegate, WMInsertTextEvent);
}
WMPostNotificationName(WMTextDidChangeNotification, tPtr, (void *)WMInsertTextEvent);
NOTIFY(tPtr, didChange, WMTextDidChangeNotification, (void *)WMInsertTextEvent);
} else {
int n;
@@ -1359,10 +1355,7 @@ static void pasteText(WMView * view, Atom selection, Atom target, Time timestamp
str[n] = 0;
WMInsertTextFieldText(tPtr, str, tPtr->cursorPosition);
XFree(str);
if (tPtr->delegate && tPtr->delegate->didChange) {
(*tPtr->delegate->didChange)(tPtr->delegate, WMInsertTextEvent);
}
WMPostNotificationName(WMTextDidChangeNotification, tPtr, (void *)WMInsertTextEvent);
NOTIFY(tPtr, didChange, WMTextDidChangeNotification, (void *)WMInsertTextEvent);
}
}
}
@@ -1484,10 +1477,8 @@ static void handleTextFieldActionEvents(XEvent * event, void *data)
text[n] = 0;
WMInsertTextFieldText(tPtr, text, tPtr->cursorPosition);
XFree(text);
if (tPtr->delegate && tPtr->delegate->didChange) {
(*tPtr->delegate->didChange)(tPtr->delegate, WMInsertTextEvent);
}
WMPostNotificationName(WMTextDidChangeNotification, tPtr, (void *)WMInsertTextEvent);
NOTIFY(tPtr, didChange, WMTextDidChangeNotification,
(void *)WMInsertTextEvent);
}
} else {
tPtr->flags.waitingSelection = 1;
+4 -8
View File
@@ -1110,7 +1110,7 @@ static void deleteTexture(WMWidget * w, void *data)
static void extractTexture(WMWidget * w, void *data)
{
_Panel *panel = (_Panel *) data;
char *path, *homedir;
char *path;
WMOpenPanel *opanel;
WMScreen *scr = WMWidgetScreen(w);
@@ -1118,17 +1118,13 @@ static void extractTexture(WMWidget * w, void *data)
WMSetFilePanelCanChooseDirectories(opanel, False);
WMSetFilePanelCanChooseFiles(opanel, True);
homedir = wgethomedir();
if (WMRunModalFilePanelForDirectory(opanel, panel->parent, homedir, _("Select File"), NULL)) {
if (WMRunModalFilePanelForDirectory(opanel, panel->parent, wgethomedir(), _("Select File"), NULL)) {
path = WMGetFilePanelFileName(opanel);
OpenExtractPanelFor(panel);
wfree(path);
}
if (homedir) {
wfree(homedir);
}
}
static void changePage(WMWidget * w, void *data)
@@ -2228,7 +2224,7 @@ static void prepareForClose(_Panel * panel)
WMUserDefaults *udb = WMGetStandardUserDefaults();
int i;
textureList = WMCreateEmptyPLArray();
textureList = WMCreatePLArray(NULL, NULL);
/* store list of textures */
for (i = 8; i < WMGetListNumberOfRows(panel->texLs); i++) {
@@ -2250,7 +2246,7 @@ static void prepareForClose(_Panel * panel)
WMReleasePropList(textureList);
/* store list of colors */
textureList = WMCreateEmptyPLArray();
textureList = WMCreatePLArray(NULL, NULL);
for (i = 0; i < wlengthof(sample_colors); i++) {
WMColor *color;
char *str;
+1 -1
View File
@@ -129,7 +129,7 @@ static void autoDelayChanged(void *observerData, WMNotification *notification)
}
char *value = WMGetTextFieldText(anAutoDelayT);
adjustButtonSelectionBasedOnValue(panel, row, value);
wfree(value);
free(value);
return;
}
}
+1 -1
View File
@@ -138,7 +138,7 @@ static void storeData(_Panel * panel)
if (sscanf(str, "%i", &i) != 1)
i = 0;
SetIntegerForKey(i, "RaiseDelay");
wfree(str);
free(str);
SetBoolForKey(WMGetButtonSelected(panel->ignB), "IgnoreFocusClick");
SetBoolForKey(WMGetButtonSelected(panel->newB), "AutoFocus");
+1 -5
View File
@@ -288,7 +288,6 @@ static char *getSelectedFont(_Panel * panel, FcChar8 * curfont)
WMListItem *item;
FcPattern *pat;
char *name;
char *result;
if (curfont)
pat = FcNameParse(curfont);
@@ -322,12 +321,9 @@ static char *getSelectedFont(_Panel * panel, FcChar8 * curfont)
}
name = (char *)FcNameUnparse(pat);
result = wstrdup(name);
free(name);
FcPatternDestroy(pat);
return result;
return name;
}
static void updateSampleFont(_Panel * panel)
+2 -2
View File
@@ -147,11 +147,11 @@ static void storeData(_Panel * panel)
if (sscanf(str, "%i", &i) != 1)
i = 0;
SetIntegerForKey(i, "HotCornerDelay");
wfree(str);
free(str);
SetIntegerForKey(WMGetSliderValue(panel->hceS), "HotCornerEdge");
list = WMCreateEmptyPLArray();
list = WMCreatePLArray(NULL, NULL);
for (i = 0; i < sizeof(panel->hcactionsT) / sizeof(WMTextField *); i++) {
str = WMGetTextFieldText(panel->hcactionsT[i]);
if (strlen(str) == 0)
+1 -1
View File
@@ -365,7 +365,7 @@ char *capture_shortcut(Display *dpy, Bool *capturing, Bool convert_case)
if ((numlock_mask != Mod5Mask) && (ev.xkey.state & Mod5Mask))
strcat(buffer, "Mod5+");
strlcat(buffer, key, sizeof(buffer));
wstrlcat(buffer, key, sizeof(buffer));
return wstrdup(buffer);
}
+1
View File
@@ -67,6 +67,7 @@ WPrefs_DEPENDENCIES = $(top_builddir)/WINGs/libWINGs.la
WPrefs_LDADD = \
$(top_builddir)/wutil-rs/target/debug/libwutil_rs.a\
$(top_builddir)/wings-rs/target/debug/libwings_rs.la\
$(top_builddir)/WINGs/libWINGs.la\
$(top_builddir)/WINGs/libWUtil.la\
$(top_builddir)/wrlib/libwraster.la \
+2 -2
View File
@@ -203,7 +203,7 @@ static void storeData(_Panel * panel)
int i;
char *p;
list = WMCreateEmptyPLArray();
list = WMCreatePLArray(NULL, NULL);
for (i = 0; i < WMGetListNumberOfRows(panel->icoL); i++) {
p = WMGetListItem(panel->icoL, i)->text;
tmp = WMCreatePLString(p);
@@ -211,7 +211,7 @@ static void storeData(_Panel * panel)
}
SetObjectForKey(list, "IconPath");
list = WMCreateEmptyPLArray();
list = WMCreatePLArray(NULL, NULL);
for (i = 0; i < WMGetListNumberOfRows(panel->pixL); i++) {
p = WMGetListItem(panel->pixL, i)->text;
tmp = WMCreatePLString(p);
+1 -1
View File
@@ -627,7 +627,7 @@ static void browseImageCallback(WMWidget *w, void *data)
WMSetFilePanelCanChooseFiles(opanel, True);
if (!ipath)
ipath = wgethomedir();
ipath = wstrdup(wgethomedir());
if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath, _("Open Image"), NULL)) {
char *path, *fullpath;
+2 -2
View File
@@ -705,10 +705,10 @@ static void loadConfigurations(WMScreen * scr, WMWindow * mainw)
}
if (!db) {
db = WMCreateEmptyPLDictionary();
db = WMCreatePLDictionary(NULL, NULL);
}
if (!gdb) {
gdb = WMCreateEmptyPLDictionary();
gdb = WMCreatePLDictionary(NULL, NULL);
}
GlobalDB = gdb;
+4 -1
View File
@@ -824,15 +824,18 @@ static void stopEditItem(WEditMenu * menu, Bool apply)
menu->flags.isEditing = 0;
}
static void textEndedEditing(struct WMTextFieldDelegate *self, WMTextMovementType reason)
static void textEndedEditing(struct WMTextFieldDelegate *self, WMNotification * notif)
{
WEditMenu *menu = (WEditMenu *) self->data;
uintptr_t reason;
int i;
WEditMenuItem *item;
if (!menu->flags.isEditing)
return;
reason = (uintptr_t)WMGetNotificationClientData(notif);
switch (reason) {
case WMEscapeTextMovement:
stopEditItem(menu, False);
+1 -6
View File
@@ -145,12 +145,7 @@ int main(int argc, char **argv)
exit(0);
}
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
Initialize(scr);
+33 -2
View File
@@ -54,12 +54,10 @@ AC_CHECK_PROG(CARGO, [cargo], [yes], [no])
AS_IF(test x$CARGO = xno,
AC_MSG_ERROR([cargo is required. Please set the CARGO environment variable or install the Rust toolchain from https://www.rust-lang.org/])
)
AC_SUBST(CARGO, [cargo])
AC_CHECK_PROG(RUSTC, [rustc], [yes], [no])
AS_IF(test x$RUSTC = xno,
AC_MSG_ERROR([rustc is required. Please set the RUSTC environment variable or install the Rust toolchain from https://www.rust-lang.org/])
)
AC_SUBST(RUSTC, [rustc])
dnl libtool library versioning
dnl ==========================
@@ -391,6 +389,39 @@ dnl the flag 'O_NOFOLLOW' for 'open' is used in WINGs
WM_FUNC_OPEN_NOFOLLOW
dnl Check for strlcat/strlcpy
dnl =========================
m4_divert_push([INIT_PREPARE])dnl
AC_ARG_WITH([libbsd],
[AS_HELP_STRING([--without-libbsd], [do not use libbsd for strlcat and strlcpy [default=check]])],
[AS_IF([test "x$with_libbsd" != "xno"],
[with_libbsd=bsd],
[with_libbsd=]
)],
[with_libbsd=bsd])
m4_divert_pop([INIT_PREPARE])dnl
tmp_libs=$LIBS
AC_SEARCH_LIBS([strlcat],[$with_libbsd],
[AC_DEFINE(HAVE_STRLCAT, 1, [Define if strlcat is available])],
[],
[]
)
AC_SEARCH_LIBS([strlcpy],[$with_libbsd],
[AC_DEFINE(HAVE_STRLCAT, 1, [Define if strlcpy is available])],
[],
[]
)
LIBS=$tmp_libs
LIBBSD=
AS_IF([test "x$ac_cv_search_strlcat" = "x-lbsd" -o "x$ac_cv_search_strlcpy" = "x-lbsd"],
[LIBBSD=-lbsd
AC_CHECK_HEADERS([bsd/string.h])]
)
AC_SUBST(LIBBSD)
dnl Check for OpenBSD kernel memory interface - kvm(3)
dnl ==================================================
AS_IF([test "x$WM_OSDEP" = "xbsd"],
+1 -1
View File
@@ -1360,7 +1360,7 @@ static void wApplicationSaveIconPathFor(const char *iconPath, const char *wm_ins
val = WMGetFromPLDictionary(adict, iconk);
} else {
/* no dictionary for app, so create one */
adict = WMCreateEmptyPLDictionary();
adict = WMCreatePLDictionary(NULL, NULL);
WMPutInPLDictionary(dict, key, adict);
WMReleasePropList(adict);
val = NULL;
+6 -6
View File
@@ -94,7 +94,7 @@ static WMenu *parseMenuCommand(WScreen * scr, Window win, char **slist, int coun
wwarning(_("appmenu: bad menu entry \"%s\" in window %lx"), slist[*index], win);
return NULL;
}
if (strlcpy(title, &slist[*index][pos], sizeof(title)) >= sizeof(title)) {
if (wstrlcpy(title, &slist[*index][pos], sizeof(title)) >= sizeof(title)) {
wwarning(_("appmenu: menu command size exceeded in window %lx"), win);
return NULL;
}
@@ -127,7 +127,7 @@ static WMenu *parseMenuCommand(WScreen * scr, Window win, char **slist, int coun
slist[*index], win);
return NULL;
}
strlcpy(title, &slist[*index][pos], sizeof(title));
wstrlcpy(title, &slist[*index][pos], sizeof(title));
rtext[0] = 0;
} else {
if (sscanf(slist[*index], "%i %i %i %i %s %n",
@@ -137,9 +137,9 @@ static WMenu *parseMenuCommand(WScreen * scr, Window win, char **slist, int coun
slist[*index], win);
return NULL;
}
strlcpy(title, &slist[*index][pos], sizeof(title));
wstrlcpy(title, &slist[*index][pos], sizeof(title));
}
data = wmalloc(sizeof(WAppMenuData));
data = malloc(sizeof(WAppMenuData));
if (data == NULL) {
wwarning(_("appmenu: out of memory creating menu for window %lx"), win);
wMenuDestroy(menu, True);
@@ -152,7 +152,7 @@ static WMenu *parseMenuCommand(WScreen * scr, Window win, char **slist, int coun
if (!entry) {
wMenuDestroy(menu, True);
wwarning(_("appmenu: out of memory creating menu for window %lx"), win);
wfree(data);
free(data);
return NULL;
}
if (rtext[0] != 0)
@@ -174,7 +174,7 @@ static WMenu *parseMenuCommand(WScreen * scr, Window win, char **slist, int coun
return NULL;
}
strlcpy(title, &slist[*index][pos], sizeof(title));
wstrlcpy(title, &slist[*index][pos], sizeof(title));
*index += 1;
submenu = parseMenuCommand(scr, win, slist, count, index);
+2 -2
View File
@@ -307,7 +307,7 @@ void wClientCheckProperty(WWindow * wwin, XPropertyEvent * event)
wWindowUpdateName(wwin, tmp);
}
if (tmp)
wfree(tmp);
XFree(tmp);
}
break;
@@ -616,7 +616,7 @@ void wClientCheckProperty(WWindow * wwin, XPropertyEvent * event)
wWindowUpdateGNUstepAttr(wwin, attr);
wfree(attr);
XFree(attr);
} else {
wNETWMCheckClientHintChange(wwin, event);
}
+2 -7
View File
@@ -862,12 +862,7 @@ static void initDefaults(void)
unsigned int i;
WDefaultEntry *entry;
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
for (i = 0; i < wlengthof(optionList); i++) {
entry = &optionList[i];
@@ -2205,7 +2200,7 @@ static int getKeybind(WScreen * scr, WDefaultEntry * entry, WMPropList * value,
return True;
}
strlcpy(buf, val, MAX_SHORTCUT_LENGTH);
wstrlcpy(buf, val, MAX_SHORTCUT_LENGTH);
b = (char *)buf;
+36 -7
View File
@@ -39,6 +39,10 @@
#include <time.h>
#include <sys/utsname.h>
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#include <signal.h>
#ifdef __FreeBSD__
#include <sys/signal.h>
@@ -246,7 +250,7 @@ static void SaveHistory(WMArray * history, const char *filename)
int i;
WMPropList *plhistory;
plhistory = WMCreateEmptyPLArray();
plhistory = WMCreatePLArray(NULL);
for (i = 0; i < WMGetArrayItemCount(history); ++i)
WMAddToPLArray(plhistory, WMCreatePLString(WMGetFromArray(history, i)));
@@ -363,7 +367,7 @@ static void handleHistoryKeyPress(XEvent * event, void *clientData)
case XK_Up:
if (p->histpos < WMGetArrayItemCount(p->history) - 1) {
if (p->histpos == 0)
wfree(WMSetInArray(p->history, 0, WMGetTextFieldText(p->panel->text)));
wfree(WMReplaceInArray(p->history, 0, WMGetTextFieldText(p->panel->text)));
p->histpos++;
WMSetTextFieldText(p->panel->text, WMGetFromArray(p->history, p->histpos));
}
@@ -464,7 +468,7 @@ int wAdvancedInputDialog(WScreen *scr, const char *title, const char *message, c
if (p->panel->result == WAPRDefault) {
result = WMGetTextFieldText(p->panel->text);
wfree(WMSetInArray(p->history, 0, wstrdup(result)));
wfree(WMReplaceInArray(p->history, 0, wstrdup(result)));
SaveHistory(p->history, filename);
} else
result = NULL;
@@ -605,9 +609,9 @@ static void listPixmaps(WScreen *scr, WMList *lPtr, const char *path)
if (strcmp(dentry->d_name, ".") == 0 || strcmp(dentry->d_name, "..") == 0)
continue;
if (strlcpy(pbuf, apath, sizeof(pbuf)) >= sizeof(pbuf) ||
strlcat(pbuf, "/", sizeof(pbuf)) >= sizeof(pbuf) ||
strlcat(pbuf, dentry->d_name, sizeof(pbuf)) >= sizeof(pbuf)) {
if (wstrlcpy(pbuf, apath, sizeof(pbuf)) >= sizeof(pbuf) ||
wstrlcat(pbuf, "/", sizeof(pbuf)) >= sizeof(pbuf) ||
wstrlcat(pbuf, dentry->d_name, sizeof(pbuf)) >= sizeof(pbuf)) {
wwarning(_("full path for file \"%s\" in \"%s\" is longer than %d bytes, skipped"),
dentry->d_name, path, (int) (sizeof(pbuf) - 1) );
continue;
@@ -1357,7 +1361,7 @@ void wShowInfoPanel(WScreen *scr)
char *posn = getPrettyOSName();
if (posn) {
snprintf(buffer, sizeof(buffer), _("Running on: %s (%s)\n"), posn, uts.machine);
wfree(posn);
free(posn);
}
else
snprintf(buffer, sizeof(buffer), _("Running on: %s (%s)\n"), uts.sysname, uts.machine);
@@ -1389,6 +1393,31 @@ void wShowInfoPanel(WScreen *scr)
break;
}
#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO2)
{
struct mallinfo2 ma = mallinfo2();
snprintf(buffer, sizeof(buffer),
#ifdef DEBUG
_("Total memory allocated: %lu kB (in use: %lu kB, %lu free chunks)\n"),
#else
_("Total memory allocated: %lu kB (in use: %lu kB)\n"),
#endif
(ma.arena + ma.hblkhd) / 1024,
(ma.uordblks + ma.hblkhd) / 1024
#ifdef DEBUG
/*
* This information is representative of the memory
* fragmentation. In ideal case it should be 1, but
* that is never possible
*/
, ma.ordblks
#endif
);
strbuf = wstrappend(strbuf, buffer);
}
#endif
strbuf = wstrappend(strbuf, _("Image formats: "));
strl = RSupportedFileFormats();
separator = NULL;
+16 -16
View File
@@ -1603,13 +1603,11 @@ static WMPropList *make_icon_state(WAppIcon *btn)
snprintf(buffer, sizeof(buffer), "%hi,%hi", wAppIconGetXIndex(btn), wAppIconGetYIndex(btn));
position = WMCreatePLString(buffer);
node = WMCreatePLDictionary(dCommand, command);
WMPutInPLDictionary(node, dName, name);
WMPutInPLDictionary(node, dAutoLaunch, autolaunch);
WMPutInPLDictionary(node, dLock, lock);
WMPutInPLDictionary(node, dForced, forced);
WMPutInPLDictionary(node, dBuggyApplication, buggy);
WMPutInPLDictionary(node, dPosition, position);
node = WMCreatePLDictionary(dCommand, command,
dName, name,
dAutoLaunch, autolaunch,
dLock, lock,
dForced, forced, dBuggyApplication, buggy, dPosition, position, NULL);
WMReleasePropList(command);
WMReleasePropList(name);
WMReleasePropList(position);
@@ -1644,7 +1642,7 @@ static WMPropList *dockSaveState(WDock *dock)
WMPropList *value, *key;
char buffer[256];
list = WMCreateEmptyPLArray();
list = WMCreatePLArray(NULL);
for (i = (dock->type == WM_DOCK ? 0 : 1); i < dock->max_icons; i++) {
WAppIcon *btn = dock->icon_array[i];
@@ -1659,7 +1657,7 @@ static WMPropList *dockSaveState(WDock *dock)
}
}
dock_state = WMCreatePLDictionary(dApplications, list);
dock_state = WMCreatePLDictionary(dApplications, list, NULL);
if (dock->type == WM_DOCK) {
snprintf(buffer, sizeof(buffer), "Applications%i", dock->screen_ptr->scr_height);
@@ -3196,7 +3194,7 @@ static pid_t execCommand(WAppIcon *btn, const char *command, WSavedState *state)
setsid();
#endif
args = wmalloc(sizeof(char *) * (argc + 1));
args = malloc(sizeof(char *) * (argc + 1));
if (!args)
exit(111);
@@ -3340,8 +3338,8 @@ void wDockTrackWindowLaunch(WDock *dock, Window window)
char *command = NULL;
if (!PropGetWMClass(window, &wm_class, &wm_instance)) {
wfree(wm_class);
wfree(wm_instance);
free(wm_class);
free(wm_instance);
return;
}
@@ -3421,8 +3419,10 @@ void wDockTrackWindowLaunch(WDock *dock, Window window)
if (command)
wfree(command);
wfree(wm_class);
wfree(wm_instance);
if (wm_class)
free(wm_class);
if (wm_instance)
free(wm_instance);
}
void wClipUpdateForWorkspaceChange(WScreen *scr, int workspace)
@@ -5072,7 +5072,7 @@ static WMPropList *drawerSaveState(WDock *drawer)
ai = drawer->icon_array[0];
/* Store its name */
pstr = WMCreatePLString(wAppIconGetWmInstance(ai));
drawer_state = WMCreatePLDictionary(dName, pstr);
drawer_state = WMCreatePLDictionary(dName, pstr, NULL); /* we need this final NULL */
WMReleasePropList(pstr);
/* Store its position */
@@ -5114,7 +5114,7 @@ void wDrawersSaveState(WScreen *scr)
make_keys();
all_drawers = WMCreateEmptyPLArray();
all_drawers = WMCreatePLArray(NULL);
for (i=0, dc = scr->drawers;
i < scr->drawer_count;
i++, dc = dc->next) {
+5 -5
View File
@@ -141,7 +141,7 @@ WMagicNumber wAddDeathHandler(pid_t pid, WDeathHandler * callback, void *cdata)
{
DeathHandler *handler;
handler = wmalloc(sizeof(DeathHandler));
handler = malloc(sizeof(DeathHandler));
if (!handler)
return 0;
@@ -150,7 +150,7 @@ WMagicNumber wAddDeathHandler(pid_t pid, WDeathHandler * callback, void *cdata)
handler->client_data = cdata;
if (!deathHandlers)
deathHandlers = WMCreateArrayWithDestructor(8, wfree);
deathHandlers = WMCreateArrayWithDestructor(8, free);
WMAddToArray(deathHandlers, handler);
@@ -164,7 +164,7 @@ static void wdelete_death_handler(WMagicNumber id)
if (!handler || !deathHandlers)
return;
/* array destructor will call wfree(handler) */
/* array destructor will call free(handler) */
WMRemoveFromArray(deathHandlers, handler);
}
@@ -1796,7 +1796,7 @@ static void handleKeyPress(XEvent * event)
}
if (wwin->flags.selected && scr->selected_windows) {
scr->shortcutWindows[widx] = WMCreateArrayWithArray(scr->selected_windows);
scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
/*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
} else {
@@ -1816,7 +1816,7 @@ static void handleKeyPress(XEvent * event)
if (scr->shortcutWindows[widx]) {
WMFreeArray(scr->shortcutWindows[widx]);
}
scr->shortcutWindows[widx] = WMCreateArrayWithArray(scr->selected_windows);
scr->shortcutWindows[widx] = WMDuplicateArray(scr->selected_windows);
}
}
+1 -1
View File
@@ -40,7 +40,7 @@ WGeometryView *WCreateGeometryView(WMScreen * scr)
widgetClass = W_RegisterUserWidget();
}
gview = wmalloc(sizeof(WGeometryView));
gview = malloc(sizeof(WGeometryView));
if (!gview) {
return NULL;
}
+4 -4
View File
@@ -131,7 +131,7 @@ static void setWVisualID(int screen, int val)
/* no array at all, alloc space for screen + 1 entries
* and init with default value */
wVisualID_len = screen + 1;
wVisualID = (int *)wmalloc(wVisualID_len * sizeof(int));
wVisualID = (int *)malloc(wVisualID_len * sizeof(int));
for (i = 0; i < wVisualID_len; i++) {
wVisualID[i] = -1;
}
@@ -156,7 +156,7 @@ static void setWVisualID(int screen, int val)
*/
static int initWVisualID(const char *user_str)
{
char *mystr = wstrdup(user_str);
char *mystr = strdup(user_str);
int cur_in_pos = 0;
int cur_out_pos = 0;
int cur_screen = 0;
@@ -191,7 +191,7 @@ static int initWVisualID(const char *user_str)
cur_in_pos++;
}
wfree(mystr);
free(mystr);
if (cur_screen == 0||error_found != 0)
return 1;
@@ -383,7 +383,7 @@ Bool RelaunchWindow(WWindow *wwin)
setsid();
#endif
/* argv is not null-terminated */
char **a = (char **) wmalloc(argc + 1);
char **a = (char **) malloc(argc + 1);
if (! a) {
werror("out of memory trying to relaunch the application");
Exit(-1);
+2 -3
View File
@@ -2309,8 +2309,7 @@ static void saveMenuInfo(WMPropList * dict, WMenu * menu, WMPropList * key)
snprintf(buffer, sizeof(buffer), "%i,%i", menu->frame_x, menu->frame_y);
value = WMCreatePLString(buffer);
list = WMCreateEmptyPLArray();
WMAddToPLArray(list, value);
list = WMCreatePLArray(value, NULL);
if (menu->flags.lowered)
WMAddToPLArray(list, WMCreatePLString("lowered"));
WMPutInPLDictionary(dict, key, list);
@@ -2323,7 +2322,7 @@ void wMenuSaveState(WScreen * scr)
WMPropList *menus, *key;
int save_menus = 0;
menus = WMCreateEmptyPLDictionary();
menus = WMCreatePLDictionary(NULL, NULL);
if (scr->switch_menu && scr->switch_menu->flags.buttoned) {
key = WMCreatePLString("SwitchMenu");
+6 -6
View File
@@ -520,7 +520,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline)
len = strlen(cmdline);
olen = len + 1;
out = wmalloc(olen);
out = malloc(olen);
if (!out) {
wwarning(_("out of memory during expansion of \"%s\""), cmdline);
return NULL;
@@ -573,7 +573,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline)
(unsigned int)scr->focused_window->client_win);
slen = strlen(tmpbuf);
olen += slen;
nout = wrealloc(out, olen);
nout = realloc(out, olen);
if (!nout) {
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%w", cmdline);
goto error;
@@ -590,7 +590,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline)
snprintf(tmpbuf, sizeof(tmpbuf), "0x%x", (unsigned int)scr->current_workspace + 1);
slen = strlen(tmpbuf);
olen += slen;
nout = wrealloc(out, olen);
nout = realloc(out, olen);
if (!nout) {
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%W", cmdline);
goto error;
@@ -607,7 +607,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline)
if (user_input) {
slen = strlen(user_input);
olen += slen;
nout = wrealloc(out, olen);
nout = realloc(out, olen);
if (!nout) {
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%a", cmdline);
goto error;
@@ -630,7 +630,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline)
}
slen = strlen(scr->xdestring);
olen += slen;
nout = wrealloc(out, olen);
nout = realloc(out, olen);
if (!nout) {
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%d", cmdline);
goto error;
@@ -651,7 +651,7 @@ char *ExpandOptions(WScreen *scr, const char *cmdline)
}
slen = strlen(selection);
olen += slen;
nout = wrealloc(out, olen);
nout = realloc(out, olen);
if (!nout) {
wwarning(_("out of memory during expansion of '%s' for command \"%s\""), "%s", cmdline);
goto error;
+6 -6
View File
@@ -54,13 +54,13 @@ int PropGetWMClass(Window window, char **wm_class, char **wm_instance)
class_hint = XAllocClassHint();
if (XGetClassHint(dpy, window, class_hint) == 0) {
*wm_class = wstrdup("default");
*wm_instance = wstrdup("default");
*wm_class = strdup("default");
*wm_instance = strdup("default");
XFree(class_hint);
return False;
}
*wm_instance = wstrdup(class_hint->res_name);
*wm_class = wstrdup(class_hint->res_class);
*wm_instance = strdup(class_hint->res_name);
*wm_class = strdup(class_hint->res_class);
XFree(class_hint->res_name);
XFree(class_hint->res_class);
@@ -133,7 +133,7 @@ int PropGetGNUstepWMAttr(Window window, GNUstepWMAttributes ** attr)
if (!data)
return False;
*attr = wmalloc(sizeof(GNUstepWMAttributes));
*attr = malloc(sizeof(GNUstepWMAttributes));
if (!*attr) {
XFree(data);
return False;
@@ -183,7 +183,7 @@ void PropSetIconTileHint(WScreen * scr, RImage * image)
imageAtom = XInternAtom(dpy, "_RGBA_IMAGE", False);
}
tmp = wmalloc(image->width * image->height * 4 + 4);
tmp = malloc(image->width * image->height * 4 + 4);
if (!tmp) {
wwarning("could not allocate memory to set _WINDOWMAKER_ICON_TILE hint");
return;
+5 -5
View File
@@ -406,7 +406,7 @@ static Bool addShortcut(const char *file, const char *shortcutDefinition, WMenu
ptr = wmalloc(sizeof(Shortcut));
strlcpy(buf, shortcutDefinition, MAX_SHORTCUT_LENGTH);
wstrlcpy(buf, shortcutDefinition, MAX_SHORTCUT_LENGTH);
b = (char *)buf;
/* get modifiers */
@@ -1243,7 +1243,7 @@ static WMenu *readMenuDirectory(WScreen *scr, const char *title, char **path, co
if (dentry->d_name[0] == '.')
continue;
buffer = wmalloc(strlen(path[i]) + strlen(dentry->d_name) + 4);
buffer = malloc(strlen(path[i]) + strlen(dentry->d_name) + 4);
if (!buffer) {
werror(_("out of memory while constructing directory menu %s"), path[i]);
break;
@@ -1288,7 +1288,7 @@ static WMenu *readMenuDirectory(WScreen *scr, const char *title, char **path, co
}
}
}
wfree(buffer);
free(buffer);
}
closedir(dir);
@@ -1315,7 +1315,7 @@ static WMenu *readMenuDirectory(WScreen *scr, const char *title, char **path, co
length += 7;
if (command)
length += strlen(command) + 6;
buffer = wmalloc(length);
buffer = malloc(length);
if (!buffer) {
werror(_("out of memory while constructing directory menu %s"), path[data->index]);
break;
@@ -1353,7 +1353,7 @@ static WMenu *readMenuDirectory(WScreen *scr, const char *title, char **path, co
if (command)
length += strlen(command);
buffer = wmalloc(length);
buffer = malloc(length);
if (!buffer) {
werror(_("out of memory while constructing directory menu %s"), path[data->index]);
break;
+3 -6
View File
@@ -968,6 +968,8 @@ void wScreenSaveState(WScreen * scr)
old_state = scr->session_state;
scr->session_state = WMCreatePLDictionary(NULL, NULL);
WMPLSetCaseSensitive(True);
/* save dock state to file */
if (!wPreferences.flags.nodock) {
wDockSaveState(scr, old_state);
@@ -1007,13 +1009,8 @@ void wScreenSaveState(WScreen * scr)
WMPutInPLDictionary(scr->session_state, dWorkspace, foo);
}
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* clean up */
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
wMenuSaveState(scr);
+18 -25
View File
@@ -241,15 +241,14 @@ static WMPropList *makeWindowState(WWindow * wwin, WApplication * wapp)
snprintf(buffer, sizeof(buffer), "%u", mask);
shortcut = WMCreatePLString(buffer);
win_state = WMCreatePLDictionary(sName, name);
WMPutInPLDictionary(win_state, sCommand, cmd);
WMPutInPLDictionary(win_state, sWorkspace, workspace);
WMPutInPLDictionary(win_state, sShaded, shaded);
WMPutInPLDictionary(win_state, sMiniaturized, miniaturized);
WMPutInPLDictionary(win_state, sMaximized, maximized);
WMPutInPLDictionary(win_state, sHidden, hidden);
WMPutInPLDictionary(win_state, sShortcutMask, shortcut);
WMPutInPLDictionary(win_state, sGeometry, geometry);
win_state = WMCreatePLDictionary(sName, name,
sCommand, cmd,
sWorkspace, workspace,
sShaded, shaded,
sMiniaturized, miniaturized,
sMaximized, maximized,
sHidden, hidden,
sShortcutMask, shortcut, sGeometry, geometry, NULL);
WMReleasePropList(name);
WMReleasePropList(cmd);
@@ -290,9 +289,9 @@ static WMPropList *makeWindowState(WWindow * wwin, WApplication * wapp)
}
if (instance)
wfree(instance);
free(instance);
if (class)
wfree(class);
free(class);
if (command)
wfree(command);
@@ -314,7 +313,7 @@ void wSessionSaveState(WScreen * scr)
return;
}
list = WMCreateEmptyPLArray();
list = WMCreatePLArray(NULL);
wapp_list = WMCreateArray(16);
@@ -383,7 +382,7 @@ static pid_t execCommand(WScreen *scr, char *command)
SetupEnvironment(scr);
args = wmalloc(sizeof(char *) * (argc + 1));
args = malloc(sizeof(char *) * (argc + 1));
if (!args)
exit(111);
for (i = 0; i < argc; i++) {
@@ -488,6 +487,8 @@ void wSessionRestoreState(WScreen *scr)
if (!scr->session_state)
return;
WMPLSetCaseSensitive(True);
apps = WMGetFromPLDictionary(scr->session_state, sApplications);
if (!apps)
return;
@@ -578,13 +579,8 @@ void wSessionRestoreState(WScreen *scr)
if (class)
wfree(class);
}
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* clean up */
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
}
void wSessionRestoreLastWorkspace(WScreen * scr)
@@ -598,6 +594,8 @@ void wSessionRestoreLastWorkspace(WScreen * scr)
if (!scr->session_state)
return;
WMPLSetCaseSensitive(True);
wks = WMGetFromPLDictionary(scr->session_state, sWorkspace);
if (!wks || !WMIsPLString(wks))
return;
@@ -607,13 +605,8 @@ void wSessionRestoreLastWorkspace(WScreen * scr)
if (!value)
return;
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* clean up */
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
/* Get the workspace number for the workspace name */
w = wGetWorkspaceNumber(scr, value);
+5 -6
View File
@@ -109,16 +109,16 @@ void Shutdown(WShutdownMode mode)
}
}
static void restoreWindows(WMBag * bag, WMBagIterator *iter)
static void restoreWindows(WMBag * bag, WMBagIterator iter)
{
WCoreWindow *next;
WCoreWindow *core;
WWindow *wwin;
if (*iter < 0) {
core = WMBagFirst(bag, iter);
if (iter == NULL) {
core = WMBagFirst(bag, &iter);
} else {
core = WMBagNext(bag, iter);
core = WMBagNext(bag, &iter);
}
if (core == NULL)
@@ -168,8 +168,7 @@ void RestoreDesktop(WScreen * scr)
wDestroyInspectorPanels();
/* reparent windows back to the root window, keeping the stacking order */
WMBagIterator iter = -1;
restoreWindows(scr->stacking_list, &iter);
restoreWindows(scr->stacking_list, NULL);
XUngrabServer(dpy);
XSetInputFocus(dpy, PointerRoot, RevertToParent, CurrentTime);
+2 -2
View File
@@ -244,7 +244,7 @@ reinit:
wApplicationSetBouncing(data->wapp, 0);
WMDeleteTimerHandler(data->timer);
wApplicationDestroy(data->wapp);
wfree(data);
free(data);
}
static int bounceDirection(WAppIcon *aicon)
@@ -324,7 +324,7 @@ void wAppBounce(WApplication *wapp)
wApplicationIncrementRefcount(wapp);
wApplicationSetBouncing(wapp, 1);
AppBouncerData *data = (AppBouncerData *)wmalloc(sizeof(AppBouncerData));
AppBouncerData *data = (AppBouncerData *)malloc(sizeof(AppBouncerData));
data->wapp = wapp;
data->count = data->pow = 0;
data->dir = bounceDirection(wApplicationGetAppIcon(wapp));
+3 -2
View File
@@ -132,7 +132,7 @@ static void changeImage(WSwitchPanel *panel, int idecks, int selected, Bool dim,
if (flags == desired && !force)
return;
WMSetInArray(panel->flags, idecks, (void *) (uintptr_t) desired);
WMReplaceInArray(panel->flags, idecks, (void *) (uintptr_t) desired);
if (!panel->bg && !panel->tile && !selected)
WMSetFrameRelief(icon, WRFlat);
@@ -357,7 +357,8 @@ static void drawTitle(WSwitchPanel *panel, int idecks, const char *title)
WMSetLabelText(panel->label, ntitle);
}
wfree(ntitle);
if (ntitle)
free(ntitle);
}
static WMArray *makeWindowListArray(WScreen *scr, int include_unmapped, Bool class_only)
+17 -32
View File
@@ -174,18 +174,15 @@ static WMPropList *get_value_from_instanceclass(const char *value)
key = WMCreatePLString(value);
WMPLSetCaseSensitive(True);
if (w_global.domain.window_attr->dictionary)
val = key ? WMGetFromPLDictionary(w_global.domain.window_attr->dictionary, key) : NULL;
if (key)
WMReleasePropList(key);
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
return val;
}
@@ -222,6 +219,8 @@ void wDefaultFillAttributes(const char *instance, const char *class,
dn = get_value_from_instanceclass(instance);
dc = get_value_from_instanceclass(class);
WMPLSetCaseSensitive(True);
if ((w_global.domain.window_attr->dictionary) && (useGlobalDefault))
da = WMGetFromPLDictionary(w_global.domain.window_attr->dictionary, AnyWindow);
@@ -312,13 +311,8 @@ void wDefaultFillAttributes(const char *instance, const char *class,
APPLY_VAL(value, no_language_button, ANoLanguageButton);
#endif
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* clean up */
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
}
static WMPropList *get_generic_value(const char *instance, const char *class,
@@ -328,6 +322,8 @@ static WMPropList *get_generic_value(const char *instance, const char *class,
value = NULL;
WMPLSetCaseSensitive(True);
/* Search the icon name using class and instance */
if (class && instance) {
char *buffer;
@@ -375,12 +371,7 @@ static WMPropList *get_generic_value(const char *instance, const char *class,
value = WMGetFromPLDictionary(dict, option);
}
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
return value;
}
@@ -554,13 +545,15 @@ void wDefaultChangeIcon(const char *instance, const char *class, const char *fil
int same = 0;
if (!dict) {
dict = WMCreateEmptyPLDictionary();
dict = WMCreatePLDictionary(NULL, NULL);
if (dict)
db->dictionary = dict;
else
return;
}
WMPLSetCaseSensitive(True);
if (instance && class) {
char *buffer;
@@ -577,7 +570,7 @@ void wDefaultChangeIcon(const char *instance, const char *class, const char *fil
if (file) {
value = WMCreatePLString(file);
icon_value = WMCreatePLDictionary(AIcon, value);
icon_value = WMCreatePLDictionary(AIcon, value, NULL);
WMReleasePropList(value);
def_win = WMGetFromPLDictionary(dict, AnyWindow);
@@ -607,12 +600,7 @@ void wDefaultChangeIcon(const char *instance, const char *class, const char *fil
if (icon_value)
WMReleasePropList(icon_value);
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
}
void wDefaultPurgeInfo(const char *instance, const char *class)
@@ -624,6 +612,8 @@ void wDefaultPurgeInfo(const char *instance, const char *class)
init_wdefaults();
}
WMPLSetCaseSensitive(True);
buffer = wmalloc(strlen(class) + strlen(instance) + 2);
sprintf(buffer, "%s.%s", instance, class);
key = WMCreatePLString(buffer);
@@ -641,12 +631,7 @@ void wDefaultPurgeInfo(const char *instance, const char *class)
wfree(buffer);
WMReleasePropList(key);
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
}
/* --------------------------- Local ----------------------- */
+9 -9
View File
@@ -283,10 +283,10 @@ void wWindowDestroy(WWindow *wwin)
XFree(wwin->wm_hints);
if (wwin->wm_instance)
wfree(wwin->wm_instance);
XFree(wwin->wm_instance);
if (wwin->wm_class)
wfree(wwin->wm_class);
XFree(wwin->wm_class);
if (wwin->wm_gnustep_attr)
wfree(wwin->wm_gnustep_attr);
@@ -950,10 +950,10 @@ WWindow *wManageWindow(WScreen *scr, Window window)
}
if (instance)
wfree(instance);
free(instance);
if (class)
wfree(class);
free(class);
#undef ADEQUATE
}
@@ -1413,7 +1413,7 @@ WWindow *wManageWindow(WScreen *scr, Window window)
/* Update name must come after WApplication stuff is done */
wWindowUpdateName(wwin, title);
if (title)
wfree(title);
XFree(title);
XUngrabServer(dpy);
@@ -2602,7 +2602,7 @@ void wWindowSetShape(WWindow * wwin)
if (!rects)
goto alt_code;
urec = wmalloc(sizeof(XRectangle) * (count + 2));
urec = malloc(sizeof(XRectangle) * (count + 2));
if (!urec) {
XFree(rects);
goto alt_code;
@@ -2779,7 +2779,7 @@ WMagicNumber wWindowAddSavedState(const char *instance, const char *class,
{
WWindowState *wstate;
wstate = wmalloc(sizeof(WWindowState));
wstate = malloc(sizeof(WWindowState));
if (!wstate)
return NULL;
@@ -2841,9 +2841,9 @@ WMagicNumber wWindowGetSavedState(Window win)
if (command)
wfree(command);
if (instance)
wfree(instance);
free(instance);
if (class)
wfree(class);
free(class);
return wstate;
}
+1 -1
View File
@@ -346,7 +346,7 @@ static void makeShortcutCommand(WMenu * menu, WMenuEntry * entry)
}
if (wwin->flags.selected && scr->selected_windows) {
scr->shortcutWindows[index] = WMCreateArrayWithArray(scr->selected_windows);
scr->shortcutWindows[index] = WMDuplicateArray(scr->selected_windows);
/*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
WMInsertInArray(scr->shortcutWindows[index], 0, wwin); */
} else {
+6 -9
View File
@@ -597,7 +597,7 @@ static void saveSettings(WMWidget *button, void *client_data)
dict = db->dictionary;
if (!dict) {
dict = WMCreateEmptyPLDictionary();
dict = WMCreatePLDictionary(NULL, NULL);
if (dict) {
db->dictionary = dict;
} else {
@@ -609,8 +609,10 @@ static void saveSettings(WMWidget *button, void *client_data)
if (showIconFor(WMWidgetScreen(button), panel, NULL, NULL, USE_TEXT_FIELD) < 0)
return;
winDic = WMCreateEmptyPLDictionary();
appDic = WMCreateEmptyPLDictionary();
WMPLSetCaseSensitive(True);
winDic = WMCreatePLDictionary(NULL, NULL);
appDic = WMCreatePLDictionary(NULL, NULL);
/* Save the icon info */
/* The flag "Ignore client suplied icon is not selected" */
@@ -707,13 +709,8 @@ static void saveSettings(WMWidget *button, void *client_data)
UpdateDomainFile(db);
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* clean up */
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
}
static void applySettings(WMWidget *button, void *client_data)
+3 -3
View File
@@ -797,7 +797,7 @@ void wWorkspaceMenuUpdate(WScreen * scr, WMenu * menu)
i = scr->workspace_count - (menu->entry_no - MC_WORKSPACE1);
ws = menu->entry_no - MC_WORKSPACE1;
while (i > 0) {
strlcpy(title, scr->workspaces[ws]->name, MAX_WORKSPACENAME_WIDTH);
wstrlcpy(title, scr->workspaces[ws]->name, MAX_WORKSPACENAME_WIDTH);
entry = wMenuAddCallback(menu, title, switchWSCommand, (void *)ws);
entry->flags.indicator = 1;
@@ -852,10 +852,10 @@ void wWorkspaceSaveState(WScreen * scr, WMPropList * old_state)
make_keys();
old_wks_state = WMGetFromPLDictionary(old_state, dWorkspaces);
parr = WMCreateEmptyPLArray();
parr = WMCreatePLArray(NULL);
for (i = 0; i < scr->workspace_count; i++) {
pstr = WMCreatePLString(scr->workspaces[i]->name);
wks_state = WMCreatePLDictionary(dName, pstr);
wks_state = WMCreatePLDictionary(dName, pstr, NULL);
WMReleasePropList(pstr);
if (!wPreferences.flags.noclip) {
pstr = wClipSaveWorkspaceState(scr, i);
+2 -2
View File
@@ -256,7 +256,7 @@ static void wXDNDGetTypeList(Display *dpy, Window window)
return;
}
typelist = wmalloc((count + 1) * sizeof(Atom));
typelist = malloc((count + 1) * sizeof(Atom));
a = (Atom *) data;
for (i = 0; i < count; i++) {
typelist[i] = a[i];
@@ -267,7 +267,7 @@ static void wXDNDGetTypeList(Display *dpy, Window window)
}
typelist[count] = 0;
XFree(data);
wfree(typelist);
free(typelist);
}
Bool wXDNDProcessClientMessage(XClientMessageEvent *event)
-94
View File
@@ -1,94 +0,0 @@
#!/bin/sh
set -e
project_base="$(dirname $0)"
export WMAKER_USER_ROOT="$HOME/tmp/GNUstep"
gs_base="$WMAKER_USER_ROOT"
gs_defaults="$gs_base/Defaults"
gs_system_defaults="$project_base"/WindowMaker/Defaults
wm_base="$gs_base/Library/WindowMaker"
wm_backgrounds="$wm_base/Backgrounds"
wm_iconsets="$wm_base/IconSets"
wm_pixmaps="$wm_base/Pixmaps"
gs_icons="$gs_base/Library/Icons"
wm_style="$wm_base/Style"
wm_styles="$wm_base/Styles"
wm_themes="$wm_base/Themes"
WindowMaker="$project_base/src/.libs/wmaker"
convertfonts="$project_base/util/convertfonts"
make_dir_if_needed ()
{
if [ ! -d "$1" ] ; then
install -m 0755 -d "$1"
fi
}
rename_dir_if_possible ()
{
if [ ! -d "$2" ] ; then
if [ -d "$1" ] ; then
mv "$1" "$2"
fi
fi
}
copy_defaults_if_needed ()
{
file="$gs_defaults/$1"
system_file="$gs_system_defaults/$1"
if [ ! -f "$file" ] ; then
install -m 0644 "$system_file" "$file"
fi
}
make_dir_if_needed "$gs_defaults"
make_dir_if_needed "$wm_base"
make_dir_if_needed "$wm_backgrounds"
make_dir_if_needed "$wm_iconsets"
make_dir_if_needed "$wm_pixmaps"
make_dir_if_needed "$gs_icons"
rename_dir_if_possible "$wm_style" "$wm_styles"
make_dir_if_needed "$wm_styles"
make_dir_if_needed "$wm_themes"
export LD_LIBRARY_PATH="$project_base/wrlib/.libs:$project_base/WINGs/.libs:$LD_LIBRARY_PATH"
copy_defaults_if_needed WindowMaker
copy_defaults_if_needed WMRootMenu
copy_defaults_if_needed WMState
#copy_defaults_if_needed WMWindowAttributes
if [ -x $convertfonts -a ! -e "$wm_base/.fonts_converted" ] ; then
# --keep-xlfd is used in order to preserve the original information
$convertfonts --keep-xlfd "$gs_defaults/WindowMaker"
if [ -f "$gs_defaults/WMGLOBAL" ] ; then
$convertfonts --keep-xlfd "$gs_defaults/WMGLOBAL"
fi
find "$wm_styles" -mindepth 1 -maxdepth 1 -type f -print0 |
xargs -0 -r -n 1 $convertfonts --keep-xlfd
touch "$wm_base/.fonts_converted"
fi
if [ -n "$1" -a -x "$WindowMaker$1" ] ; then
WindowMaker="$WindowMaker$1"
shift
fi
for i in $(seq 5 10) ; do
if [ "x$DISPLAY" != "x:$i" ] ; then
xephyr_display=":$i"
break
fi
done
echo "Running Xephyr on display $xephyr_display"
Xephyr -screen 640x480 "$xephyr_display" &
xephyr_pid=$!
DISPLAY="$xephyr_display" gdb \
--directory "$project_base" \
--quiet \
--args "$WindowMaker" -display "$xephyr_display" --for-real "$@"
kill $xephyr_pid
+7 -32
View File
@@ -18,51 +18,31 @@ AM_CPPFLAGS = \
liblist= @LIBRARY_SEARCH_PATH@ @INTLIBS@
wdwrite_LDADD = \
$(top_builddir)/WINGs/libWUtil.la \
$(top_builddir)/wutil-rs/target/debug/libwutil_rs.a \
$(liblist)
wdwrite_LDADD = $(top_builddir)/WINGs/libWUtil.la $(liblist)
wdread_LDADD = \
$(top_builddir)/WINGs/libWUtil.la \
$(top_builddir)/wutil-rs/target/debug/libwutil_rs.a \
$(liblist)
wdread_LDADD = $(top_builddir)/WINGs/libWUtil.la $(liblist)
wxcopy_LDADD = @XLFLAGS@ @XLIBS@ \
$(top_builddir)/wutil-rs/target/debug/libwutil_rs.a
wxcopy_LDADD = @XLFLAGS@ @XLIBS@
wxpaste_LDADD = @XLFLAGS@ @XLIBS@
getstyle_LDADD = \
$(top_builddir)/WINGs/libWUtil.la \
$(top_builddir)/wutil-rs/target/debug/libwutil_rs.a \
$(liblist)
getstyle_LDADD = $(top_builddir)/WINGs/libWUtil.la $(liblist)
getstyle_SOURCES = getstyle.c fontconv.c common.h
setstyle_LDADD = \
$(top_builddir)/WINGs/libWUtil.la \
$(top_builddir)/wutil-rs/target/debug/libwutil_rs.a \
@XLFLAGS@ @XLIBS@ $(liblist)
setstyle_SOURCES = setstyle.c fontconv.c common.h
convertfonts_LDADD = \
$(top_builddir)/WINGs/libWUtil.la \
$(top_builddir)/wutil-rs/target/debug/libwutil_rs.a \
$(liblist)
convertfonts_LDADD = $(top_builddir)/WINGs/libWUtil.la $(liblist)
convertfonts_SOURCES = convertfonts.c fontconv.c common.h
seticons_LDADD= \
$(top_builddir)/WINGs/libWUtil.la \
$(top_builddir)/wutil-rs/target/debug/libwutil_rs.a \
$(liblist)
seticons_LDADD= $(top_builddir)/WINGs/libWUtil.la $(liblist)
geticonset_LDADD= \
$(top_builddir)/WINGs/libWUtil.la \
$(top_builddir)/wutil-rs/target/debug/libwutil_rs.a \
$(liblist)
geticonset_LDADD= $(top_builddir)/WINGs/libWUtil.la $(liblist)
wmagnify_LDADD = \
$(top_builddir)/WINGs/libWINGs.la \
@@ -72,20 +52,17 @@ wmagnify_LDADD = \
wmsetbg_LDADD = \
$(top_builddir)/WINGs/libWINGs.la \
$(top_builddir)/wutil-rs/target/debug/libwutil_rs.a \
$(top_builddir)/WINGs/libWUtil.la \
$(top_builddir)/wrlib/libwraster.la \
@XLFLAGS@ @LIBXINERAMA@ @XLIBS@ @INTLIBS@
wmgenmenu_LDADD = \
$(top_builddir)/WINGs/libWUtil.la \
$(top_builddir)/wutil-rs/target/debug/libwutil_rs.a \
@INTLIBS@
wmgenmenu_SOURCES = wmgenmenu.c wmgenmenu.h
wmmenugen_LDADD = \
$(top_builddir)/wutil-rs/target/debug/libwutil_rs.a \
$(top_builddir)/WINGs/libWUtil.la \
@INTLIBS@
@@ -98,8 +75,6 @@ wmiv_CFLAGS = @PANGO_CFLAGS@ @PTHREAD_CFLAGS@
wmiv_LDADD = \
$(top_builddir)/wrlib/libwraster.la \
$(top_builddir)/WINGs/libWINGs.la \
$(top_builddir)/WINGs/libWUtil.la \
$(top_builddir)/wutil-rs/target/debug/libwutil_rs.a \
@XLFLAGS@ @XLIBS@ @GFXLIBS@ \
@PANGO_LIBS@ @PTHREAD_LIBS@ @LIBEXIF@
+1 -6
View File
@@ -131,12 +131,7 @@ int main(int argc, char **argv)
/* this contradicts big time with getstyle */
setlocale(LC_ALL, "");
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
style = WMReadPropListFromFile(file);
if (!style) {
+1 -1
View File
@@ -109,7 +109,7 @@ int main(int argc, char **argv)
if (window_attrs && WMIsPLDictionary(window_attrs)) {
icon_value = WMGetFromPLDictionary(window_attrs, icon_key);
if (icon_value) {
icondic = WMCreatePLDictionary(icon_key, icon_value);
icondic = WMCreatePLDictionary(icon_key, icon_value, NULL);
WMPutInPLDictionary(iconset, window_name, icondic);
}
}
+5 -10
View File
@@ -242,7 +242,7 @@ static void makeThemePack(WMPropList * style, const char *themeName)
WMDeleteFromPLArray(value, 1);
WMInsertInPLArray(value, 1, WMCreatePLString(newPath));
wfree(newPath);
free(newPath);
} else {
findCopyFile(themeDir, WMGetFromPLString(file));
}
@@ -262,7 +262,7 @@ static void makeThemePack(WMPropList * style, const char *themeName)
WMDeleteFromPLArray(value, 1);
WMInsertInPLArray(value, 1, WMCreatePLString(newPath));
wfree(newPath);
free(newPath);
} else {
findCopyFile(themeDir, WMGetFromPLString(file));
}
@@ -277,7 +277,7 @@ static void makeThemePack(WMPropList * style, const char *themeName)
WMDeleteFromPLArray(value, 2);
WMInsertInPLArray(value, 2, WMCreatePLString(newPath));
wfree(newPath);
free(newPath);
} else {
findCopyFile(themeDir, WMGetFromPLString(file));
}
@@ -337,12 +337,7 @@ int main(int argc, char **argv)
return 1;
}
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
path = wdefaultspathfordomain("WindowMaker");
@@ -362,7 +357,7 @@ int main(int argc, char **argv)
prop = val;
}
style = WMCreateEmptyPLDictionary();
style = WMCreatePLDictionary(NULL, NULL);
for (i = 0; options[i] != NULL; i++) {
key = WMCreatePLString(options[i]);
+2 -7
View File
@@ -427,12 +427,7 @@ int main(int argc, char **argv)
file = argv[0];
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
path = wdefaultspathfordomain("WindowMaker");
@@ -470,7 +465,7 @@ int main(int argc, char **argv)
}
buf[strlen(buf) - 6 /* strlen("/style") */] = '\0';
homedir = wgethomedir();
homedir = wstrdup(wgethomedir());
if (strlen(homedir) > 1 && /* this is insane, wgethomedir() returns `/' on error */
strncmp(homedir, buf, strlen(homedir)) == 0) {
/* theme pack is under ${HOME}; exchange ${HOME} part
+1 -1
View File
@@ -103,7 +103,7 @@ int main(int argc, char **argv)
dict = WMReadPropListFromFile(path);
if (!dict) {
dict = WMCreatePLDictionary(key, value);
dict = WMCreatePLDictionary(key, value, NULL);
} else {
WMPutInPLDictionary(dict, key, value);
}
+9 -9
View File
@@ -202,7 +202,7 @@ int change_title(XTextProperty *prop, char *filename)
XSetWMName(dpy, win, prop);
if (prop->value)
XFree(prop->value);
wfree(combined_title);
free(combined_title);
return EXIT_SUCCESS;
}
@@ -596,8 +596,8 @@ int linked_list_add(linked_list_t *list, const void *data)
{
link_t *link;
/* wmalloc zeros the buffer it returns, so the "next" is zero. */
link = wmalloc(sizeof(link_t));
/* calloc sets the "next" field to zero. */
link = calloc(1, sizeof(link_t));
if (!link) {
fprintf(stderr, "Error: memory allocation failed\n");
return EXIT_FAILURE;
@@ -627,8 +627,8 @@ void linked_list_free(linked_list_t *list)
/* Store the next value so that we don't access freed memory. */
next = link->next;
if (link->data)
wfree((char *)link->data);
wfree(link);
free((char *)link->data);
free(link);
}
}
@@ -651,7 +651,7 @@ link_t *connect_dir(char *dirpath, linked_list_t *li)
/* maybe it's a file */
struct stat stDirInfo;
if (lstat(dirpath, &stDirInfo) == 0) {
linked_list_add(li, wstrdup(dirpath));
linked_list_add(li, strdup(dirpath));
return li->first;
} else {
return NULL;
@@ -664,11 +664,11 @@ link_t *connect_dir(char *dirpath, linked_list_t *li)
else
snprintf(path, PATH_MAX, "%s%c%s", dirpath, FILE_SEPARATOR, dir[idx]->d_name);
wfree(dir[idx]);
free(dir[idx]);
if ((lstat(path, &stDirInfo) == 0) && !S_ISDIR(stDirInfo.st_mode))
linked_list_add(li, wstrdup(path));
linked_list_add(li, strdup(path));
}
wfree(dir);
free(dir);
return li->first;
}
+8 -8
View File
@@ -35,8 +35,8 @@
static void addWMMenuEntryCallback(WMMenuEntry *aEntry);
static void assemblePLMenuFunc(WMTreeNode *aNode, void *data);
static int dirParseFunc(const char *filename, const struct stat *st, int tflags, struct FTW *ftw);
static int menuSortFunc(const WMTreeNode *left, const WMTreeNode *right);
static int nodeFindSubMenuByNameFunc(const WMTreeNode *tree, const void *cdata);
static int menuSortFunc(const void *left, const void *right);
static int nodeFindSubMenuByNameFunc(const void *item, const void *cdata);
static WMTreeNode *findPositionInMenu(const char *submenu);
@@ -178,7 +178,7 @@ int main(int argc, char **argv)
}
WMSortTree(menu, menuSortFunc);
WMTreeWalk(menu, assemblePLMenuFunc, previousDepth);
WMTreeWalk(menu, assemblePLMenuFunc, previousDepth, True);
i = WMGetArrayItemCount(plMenuNodes);
if (i > 2) { /* more than one submenu unprocessed is almost certainly an error */
@@ -324,13 +324,13 @@ static void assemblePLMenuFunc(WMTreeNode *aNode, void *data)
/* sort the menu tree; callback for WMSortTree()
*/
static int menuSortFunc(const WMTreeNode *left, const WMTreeNode *right)
static int menuSortFunc(const void *left, const void *right)
{
WMMenuEntry *leftwm;
WMMenuEntry *rightwm;
leftwm = (WMMenuEntry *)WMGetDataForTreeNode(left);
rightwm = (WMMenuEntry *)WMGetDataForTreeNode(right);
leftwm = (WMMenuEntry *)WMGetDataForTreeNode(*(WMTreeNode **)left);
rightwm = (WMMenuEntry *)WMGetDataForTreeNode(*(WMTreeNode **)right);
/* submenus first */
if (!leftwm->CmdLine && rightwm->CmdLine)
@@ -380,11 +380,11 @@ static WMTreeNode *findPositionInMenu(const char *submenu)
/* find node where Name = cdata and node is a submenu
*/
static int nodeFindSubMenuByNameFunc(const WMTreeNode *tree, const void *cdata)
static int nodeFindSubMenuByNameFunc(const void *item, const void *cdata)
{
WMMenuEntry *wm;
wm = (WMMenuEntry *)WMGetDataForTreeNode(tree);
wm = (WMMenuEntry *)item;
if (wm->CmdLine) /* if it has a cmdline, it can't be a submenu */
return 0;
+1 -1
View File
@@ -121,7 +121,7 @@ void parse_locale(const char *what, char **language, char **country, char **enco
*language = wstrdup(e);
out:
wfree(e);
free(e);
return;
}
+4 -4
View File
@@ -398,7 +398,7 @@ static BackgroundTexture *parseTexture(RContext * rc, char *text)
RGradientStyle gtype;
int iwidth, iheight;
colors = wmalloc(sizeof(RColor *) * (count - 1));
colors = malloc(sizeof(RColor *) * (count - 1));
if (!colors) {
wwarning("out of memory while parsing texture");
goto error;
@@ -425,7 +425,7 @@ static BackgroundTexture *parseTexture(RContext * rc, char *text)
wfree(colors);
goto error;
}
if (!(colors[i - 2] = wmalloc(sizeof(RColor)))) {
if (!(colors[i - 2] = malloc(sizeof(RColor)))) {
wwarning("out of memory while parsing texture");
for (j = 0; colors[j] != NULL; j++)
@@ -1199,14 +1199,14 @@ static void changeTextureForWorkspace(const char *domain, char *texture, int wor
array = getValueForKey("WindowMaker", "WorkspaceSpecificBack");
if (!array) {
array = WMCreateEmptyPLArray();
array = WMCreatePLArray(NULL, NULL);
}
j = WMGetPropListItemCount(array);
if (workspace >= j) {
WMPropList *empty;
empty = WMCreateEmptyPLArray();
empty = WMCreatePLArray(NULL, NULL);
while (j++ < workspace - 1) {
WMAddToPLArray(array, empty);
+7 -4
View File
@@ -26,8 +26,6 @@
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <WINGs/WUtil.h>
#include "../src/wconfig.h"
#define LINESIZE (4*1024)
@@ -199,7 +197,7 @@ int main(int argc, char **argv)
break;
}
if (buf_len == 0) {
nbuf = wmalloc(buf_len = l + nl + 1);
nbuf = malloc(buf_len = l + nl + 1);
} else if (buf_len < l + nl + 1) {
/*
* To avoid terrible performance on big input buffers,
@@ -207,7 +205,12 @@ int main(int argc, char **argv)
* current line.
*/
buf_len = 2 * buf_len + nl + 1;
nbuf = wrealloc(buf, buf_len);
/* some realloc implementations don't do malloc if buf==NULL */
if (buf == NULL) {
nbuf = malloc(buf_len);
} else {
nbuf = realloc(buf, buf_len);
}
} else {
nbuf = buf;
}
+1 -2
View File
@@ -6,8 +6,7 @@ lib_LTLIBRARIES = libWMaker.la
include_HEADERS = WMaker.h
AM_CPPFLAGS = $(DFLAGS) @XCFLAGS@ \
-I$(top_srcdir)/WINGs -I$(top_builddir)/WINGs
AM_CPPFLAGS = $(DFLAGS) @XCFLAGS@
libWMaker_la_LIBADD = @XLFLAGS@ @XLIBS@
+5 -7
View File
@@ -24,8 +24,6 @@
#include <stdlib.h>
#include <string.h>
#include <WINGs/WUtil.h>
#include "WMaker.h"
#include "app.h"
@@ -33,7 +31,7 @@ WMAppContext *WMAppCreateWithMain(Display * display, int screen_number, Window m
{
wmAppContext *ctx;
ctx = wmalloc(sizeof(wmAppContext));
ctx = malloc(sizeof(wmAppContext));
if (!ctx)
return NULL;
@@ -41,9 +39,9 @@ WMAppContext *WMAppCreateWithMain(Display * display, int screen_number, Window m
ctx->screen_number = screen_number;
ctx->our_leader_hint = False;
ctx->main_window = main_window;
ctx->windows = wmalloc(sizeof(Window));
ctx->windows = malloc(sizeof(Window));
if (!ctx->windows) {
wfree(ctx);
free(ctx);
return NULL;
}
ctx->win_count = 1;
@@ -60,13 +58,13 @@ int WMAppAddWindow(WMAppContext * app, Window window)
{
Window *win;
win = wmalloc(sizeof(Window) * (app->win_count + 1));
win = malloc(sizeof(Window) * (app->win_count + 1));
if (!win)
return False;
memcpy(win, app->windows, sizeof(Window) * app->win_count);
wfree(app->windows);
free(app->windows);
win[app->win_count] = window;
app->windows = win;
+14 -16
View File
@@ -26,8 +26,6 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <WINGs/WUtil.h>
#include "WMaker.h"
#include "app.h"
#include "menu.h"
@@ -39,7 +37,7 @@ WMMenu *WMMenuCreate(WMAppContext * app, char *title)
if (strlen(title) > 255)
return NULL;
menu = wmalloc(sizeof(wmMenu));
menu = malloc(sizeof(wmMenu));
if (!menu)
return NULL;
@@ -52,12 +50,12 @@ WMMenu *WMMenuCreate(WMAppContext * app, char *title)
menu->realized = False;
menu->code = app->last_menu_tag++;
menu->entryline = wmalloc(strlen(title) + 32);
menu->entryline2 = wmalloc(32);
menu->entryline = malloc(strlen(title) + 32);
menu->entryline2 = malloc(32);
if (!menu->entryline || !menu->entryline2) {
if (menu->entryline)
wfree(menu->entryline);
wfree(menu);
free(menu->entryline);
free(menu);
return NULL;
}
sprintf(menu->entryline, "%i %i %s", wmBeginMenu, menu->code, title);
@@ -79,13 +77,13 @@ WMMenuAddItem(WMMenu * menu, char *text, WMMenuAction action,
if (strlen(text) > 255)
return -1;
entry = wmalloc(sizeof(wmMenuEntry));
entry = malloc(sizeof(wmMenuEntry));
if (!entry)
return -1;
entry->entryline = wmalloc(strlen(text) + 100);
entry->entryline = malloc(strlen(text) + 100);
if (!entry->entryline) {
wfree(entry);
free(entry);
return -1;
}
@@ -127,13 +125,13 @@ int WMMenuAddSubmenu(WMMenu * menu, char *text, WMMenu * submenu)
if (strlen(text) > 255)
return -1;
entry = wmalloc(sizeof(wmMenuEntry));
entry = malloc(sizeof(wmMenuEntry));
if (!entry)
return -1;
entry->entryline = wmalloc(strlen(text) + 100);
entry->entryline = malloc(strlen(text) + 100);
if (!entry->entryline) {
wfree(entry);
free(entry);
return -1;
}
@@ -219,7 +217,7 @@ int WMRealizeMenus(WMAppContext * app)
return True;
count++;
slist = wmalloc(count * sizeof(char *));
slist = malloc(count * sizeof(char *));
if (!slist) {
return False;
}
@@ -229,10 +227,10 @@ int WMRealizeMenus(WMAppContext * app)
addItems(slist, &i, app->main_menu);
if (!XStringListToTextProperty(slist, i, &text_prop)) {
wfree(slist);
free(slist);
return False;
}
wfree(slist);
free(slist);
XSetTextProperty(app->dpy, app->main_window, &text_prop, getatom(app->dpy));
XFree(text_prop.value);
+1 -2
View File
@@ -82,8 +82,7 @@ libwraster_la_SOURCES += load_magick.c
endif
AM_CFLAGS = @MAGICKFLAGS@
AM_CPPFLAGS = $(DFLAGS) @HEADER_SEARCH_PATH@ \
-I$(top_srcdir)/WINGs -I$(top_builddir)/WINGs
AM_CPPFLAGS = $(DFLAGS) @HEADER_SEARCH_PATH@
libwraster_la_LIBADD = @LIBRARY_SEARCH_PATH@ @GFXLIBS@ @MAGICKLIBS@ @XLIBS@ @LIBXMU@ -lm
+15 -17
View File
@@ -37,8 +37,6 @@
#include <math.h>
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "scale.h"
#include "wr_i18n.h"
@@ -106,17 +104,17 @@ static Bool allocateStandardPseudoColor(RContext * ctx, XStandardColormap * stdc
return False;
}
ctx->colors = wmalloc(sizeof(XColor) * ctx->ncolors);
ctx->colors = malloc(sizeof(XColor) * ctx->ncolors);
if (!ctx->colors) {
RErrorCode = RERR_NOMEMORY;
return False;
}
ctx->pixels = wmalloc(sizeof(unsigned long) * ctx->ncolors);
ctx->pixels = malloc(sizeof(unsigned long) * ctx->ncolors);
if (!ctx->pixels) {
wfree(ctx->colors);
free(ctx->colors);
ctx->colors = NULL;
RErrorCode = RERR_NOMEMORY;
@@ -248,15 +246,15 @@ static Bool allocatePseudoColor(RContext *ctx)
assert(cpc >= 2 && ncolors <= (1 << ctx->depth));
colors = wmalloc(sizeof(XColor) * ncolors);
colors = malloc(sizeof(XColor) * ncolors);
if (!colors) {
RErrorCode = RERR_NOMEMORY;
return False;
}
ctx->pixels = wmalloc(sizeof(unsigned long) * ncolors);
ctx->pixels = malloc(sizeof(unsigned long) * ncolors);
if (!ctx->pixels) {
wfree(colors);
free(colors);
RErrorCode = RERR_NOMEMORY;
return False;
}
@@ -345,7 +343,7 @@ static XColor *allocateGrayScale(RContext * ctx)
ctx->attribs->render_mode = RBestMatchRendering;
}
colors = wmalloc(sizeof(XColor) * ncolors);
colors = malloc(sizeof(XColor) * ncolors);
if (!colors) {
RErrorCode = RERR_NOMEMORY;
return False;
@@ -528,7 +526,7 @@ RContext *RCreateContext(Display * dpy, int screen_number, const RContextAttribu
RContext *context;
XGCValues gcv;
context = wmalloc(sizeof(RContext));
context = malloc(sizeof(RContext));
if (!context) {
RErrorCode = RERR_NOMEMORY;
return NULL;
@@ -539,9 +537,9 @@ RContext *RCreateContext(Display * dpy, int screen_number, const RContextAttribu
context->screen_number = screen_number;
context->attribs = wmalloc(sizeof(RContextAttributes));
context->attribs = malloc(sizeof(RContextAttributes));
if (!context->attribs) {
wfree(context);
free(context);
RErrorCode = RERR_NOMEMORY;
return NULL;
}
@@ -570,7 +568,7 @@ RContext *RCreateContext(Display * dpy, int screen_number, const RContextAttribu
templ.visualid = context->attribs->visualid;
vinfo = XGetVisualInfo(context->dpy, VisualIDMask | VisualScreenMask, &templ, &nret);
if (!vinfo || nret == 0) {
wfree(context);
free(context);
RErrorCode = RERR_BADVISUALID;
return NULL;
}
@@ -617,13 +615,13 @@ RContext *RCreateContext(Display * dpy, int screen_number, const RContextAttribu
if (context->vclass == PseudoColor || context->vclass == StaticColor) {
if (!setupPseudoColorColormap(context)) {
wfree(context);
free(context);
return NULL;
}
} else if (context->vclass == GrayScale || context->vclass == StaticGray) {
context->colors = allocateGrayScale(context);
if (!context->colors) {
wfree(context);
free(context);
return NULL;
}
} else if (context->vclass == TrueColor) {
@@ -670,9 +668,9 @@ void RDestroyContext(RContext *context)
if ((context->attribs->flags & RC_VisualID) &&
!(context->attribs->flags & RC_DefaultVisual))
XDestroyWindow(context->dpy, context->drawable);
wfree(context->attribs);
free(context->attribs);
}
wfree(context);
free(context);
}
}
+21 -23
View File
@@ -33,15 +33,13 @@
#include <string.h>
#include <assert.h>
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "convert.h"
#include "xutil.h"
#include "wr_i18n.h"
#define NFREE(n) wfree(n)
#define NFREE(n) if (n) free(n)
#define HAS_ALPHA(I) ((I)->format == RRGBAFormat)
@@ -72,7 +70,7 @@ static void release_conversion_table(void)
RConversionTable *tmp_to_delete = tmp;
tmp = tmp->next;
wfree(tmp_to_delete);
free(tmp_to_delete);
}
conversionTable = NULL;
}
@@ -85,7 +83,7 @@ static void release_std_conversion_table(void)
RStdConversionTable *tmp_to_delete = tmp;
tmp = tmp->next;
wfree(tmp_to_delete);
free(tmp_to_delete);
}
stdConversionTable = NULL;
}
@@ -110,7 +108,7 @@ static unsigned short *computeTable(unsigned short mask)
if (tmp)
return tmp->table;
tmp = (RConversionTable *) wmalloc(sizeof(RConversionTable));
tmp = (RConversionTable *) malloc(sizeof(RConversionTable));
if (tmp == NULL)
return NULL;
@@ -137,7 +135,7 @@ static unsigned int *computeStdTable(unsigned int mult, unsigned int max)
if (tmp)
return tmp->table;
tmp = (RStdConversionTable *) wmalloc(sizeof(RStdConversionTable));
tmp = (RStdConversionTable *) malloc(sizeof(RStdConversionTable));
if (tmp == NULL)
return NULL;
@@ -374,8 +372,8 @@ static RXImage *image2TrueColor(RContext * ctx, RImage * image)
signed char *nerr;
int ch = (HAS_ALPHA(image) ? 4 : 3);
err = wmalloc(ch * (image->width + 2));
nerr = wmalloc(ch * (image->width + 2));
err = malloc(ch * (image->width + 2));
nerr = malloc(ch * (image->width + 2));
if (!err || !nerr) {
NFREE(err);
NFREE(nerr);
@@ -389,8 +387,8 @@ static RXImage *image2TrueColor(RContext * ctx, RImage * image)
convertTrueColor_generic(ximg, image, err, nerr,
rtable, gtable, btable, dr, dg, db, roffs, goffs, boffs);
wfree(err);
wfree(nerr);
free(err);
free(nerr);
}
}
@@ -542,8 +540,8 @@ static RXImage *image2PseudoColor(RContext * ctx, RImage * image)
#ifdef WRLIB_DEBUG
fprintf(stderr, "pseudo color dithering with %d colors per channel\n", cpc);
#endif
err = wmalloc(4 * (image->width + 3));
nerr = wmalloc(4 * (image->width + 3));
err = malloc(4 * (image->width + 3));
nerr = malloc(4 * (image->width + 3));
if (!err || !nerr) {
NFREE(err);
NFREE(nerr);
@@ -557,8 +555,8 @@ static RXImage *image2PseudoColor(RContext * ctx, RImage * image)
convertPseudoColor_to_8(ximg, image, err + 4, nerr + 4,
rtable, gtable, btable, dr, dg, db, ctx->pixels, cpc);
wfree(err);
wfree(nerr);
free(err);
free(nerr);
}
return ximg;
@@ -620,8 +618,8 @@ static RXImage *image2StandardPseudoColor(RContext * ctx, RImage * image)
fprintf(stderr, "pseudo color dithering with %d colors per channel\n",
ctx->attribs->colors_per_channel);
#endif
err = (short *)wmalloc(3 * (image->width + 2) * sizeof(short));
nerr = (short *)wmalloc(3 * (image->width + 2) * sizeof(short));
err = (short *)malloc(3 * (image->width + 2) * sizeof(short));
nerr = (short *)malloc(3 * (image->width + 2) * sizeof(short));
if (!err || !nerr) {
NFREE(err);
NFREE(nerr);
@@ -709,8 +707,8 @@ static RXImage *image2StandardPseudoColor(RContext * ctx, RImage * image)
ofs += ximg->image->bytes_per_line - image->width;
}
wfree(err);
wfree(nerr);
free(err);
free(nerr);
}
ximg->image->data = (char *)data;
@@ -775,8 +773,8 @@ static RXImage *image2GrayScale(RContext * ctx, RImage * image)
#ifdef WRLIB_DEBUG
fprintf(stderr, "grayscale dither with %d colors per channel\n", cpc);
#endif
gerr = (short *)wmalloc((image->width + 2) * sizeof(short));
ngerr = (short *)wmalloc((image->width + 2) * sizeof(short));
gerr = (short *)malloc((image->width + 2) * sizeof(short));
ngerr = (short *)malloc((image->width + 2) * sizeof(short));
if (!gerr || !ngerr) {
NFREE(gerr);
NFREE(ngerr);
@@ -832,8 +830,8 @@ static RXImage *image2GrayScale(RContext * ctx, RImage * image)
gerr = ngerr;
ngerr = terr;
}
wfree(gerr);
wfree(ngerr);
free(gerr);
free(ngerr);
}
ximg->image->data = (char *)data;
+2 -4
View File
@@ -26,8 +26,6 @@
#include <string.h>
#include <X11/Xlib.h>
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "wr_i18n.h"
@@ -48,7 +46,7 @@ int RBlurImage(RImage * image)
unsigned char *pptr = NULL, *tmpp;
int ch = image->format == RRGBAFormat ? 4 : 3;
pptr = wmalloc(image->width * ch);
pptr = malloc(image->width * ch);
if (!pptr) {
RErrorCode = RERR_NOMEMORY;
return False;
@@ -140,7 +138,7 @@ int RBlurImage(RImage * image)
}
}
wfree(tmpp);
free(tmpp);
return True;
}
+9 -9
View File
@@ -34,8 +34,6 @@
#include <time.h>
#include <assert.h>
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "imgformat.h"
#include "wr_i18n.h"
@@ -127,7 +125,7 @@ static void init_cache(void)
RImageCacheMaxImage = IMAGE_CACHE_MAXIMUM_MAXPIXELS;
if (RImageCacheSize > 0) {
RImageCache = wmalloc(sizeof(RCachedImage) * RImageCacheSize);
RImageCache = malloc(sizeof(RCachedImage) * RImageCacheSize);
if (RImageCache == NULL) {
fprintf(stderr, _("wrlib: out of memory for image cache\n"));
return;
@@ -144,10 +142,10 @@ void RReleaseCache(void)
for (i = 0; i < RImageCacheSize; i++) {
if (RImageCache[i].file) {
RReleaseImage(RImageCache[i].image);
wfree(RImageCache[i].file);
free(RImageCache[i].file);
}
}
wfree(RImageCache);
free(RImageCache);
RImageCache = NULL;
RImageCacheSize = -1;
}
@@ -175,7 +173,7 @@ RImage *RLoadImage(RContext *context, const char *file, int index)
return RCloneImage(RImageCache[i].image);
} else {
wfree(RImageCache[i].file);
free(RImageCache[i].file);
RImageCache[i].file = NULL;
RReleaseImage(RImageCache[i].image);
}
@@ -256,7 +254,8 @@ RImage *RLoadImage(RContext *context, const char *file, int index)
for (i = 0; i < RImageCacheSize; i++) {
if (!RImageCache[i].file) {
RImageCache[i].file = wstrdup(file);
RImageCache[i].file = malloc(strlen(file) + 1);
strcpy(RImageCache[i].file, file);
RImageCache[i].image = RCloneImage(image);
RImageCache[i].last_modif = st.st_mtime;
RImageCache[i].last_use = time(NULL);
@@ -272,9 +271,10 @@ RImage *RLoadImage(RContext *context, const char *file, int index)
/* if no slot available, dump least recently used one */
if (!done) {
wfree(RImageCache[oldest_idx].file);
free(RImageCache[oldest_idx].file);
RReleaseImage(RImageCache[oldest_idx].image);
RImageCache[oldest_idx].file = wstrdup(file);
RImageCache[oldest_idx].file = malloc(strlen(file) + 1);
strcpy(RImageCache[oldest_idx].file, file);
RImageCache[oldest_idx].image = RCloneImage(image);
RImageCache[oldest_idx].last_modif = st.st_mtime;
RImageCache[oldest_idx].last_use = time(NULL);
+2 -4
View File
@@ -28,8 +28,6 @@
#include <gif_lib.h>
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "imgformat.h"
#include "wr_i18n.h"
@@ -129,7 +127,7 @@ RImage *RLoadGIF(const char *file, int index)
}
}
buffer = wmalloc(width * sizeof(GifPixelType));
buffer = malloc(width * sizeof(GifPixelType));
if (!buffer) {
RErrorCode = RERR_NOMEMORY;
goto bye;
@@ -221,7 +219,7 @@ RImage *RLoadGIF(const char *file, int index)
did_not_get_any_errors:
if (buffer)
wfree(buffer);
free(buffer);
if (gif)
#if (USE_GIF == 5) && (GIFLIB_MINOR >= 1)
+2 -4
View File
@@ -35,8 +35,6 @@
#include <stdnoreturn.h>
#endif
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "imgformat.h"
#include "wr_i18n.h"
@@ -121,7 +119,7 @@ static RImage *do_read_jpeg_file(struct jpeg_decompress_struct *cinfo, const cha
goto abort_and_release_resources;
}
buffer[0] = (JSAMPROW) wmalloc(cinfo->image_width * cinfo->num_components);
buffer[0] = (JSAMPROW) malloc(cinfo->image_width * cinfo->num_components);
if (!buffer[0]) {
RErrorCode = RERR_NOMEMORY;
goto abort_and_release_resources;
@@ -169,7 +167,7 @@ static RImage *do_read_jpeg_file(struct jpeg_decompress_struct *cinfo, const cha
jpeg_destroy_decompress(cinfo);
fclose(file);
if (buffer[0])
wfree(buffer[0]);
free(buffer[0]);
return image;
}
+6 -8
View File
@@ -28,8 +28,6 @@
#include <png.h>
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "imgformat.h"
#include "wr_i18n.h"
@@ -167,7 +165,7 @@ RImage *RLoadPNG(RContext *context, const char *file)
image->background.blue = bkcolor->blue >> 8;
}
png_rows = wmalloc(height * sizeof(png_bytep));
png_rows = calloc(height, sizeof(png_bytep));
if (!png_rows) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
@@ -176,7 +174,7 @@ RImage *RLoadPNG(RContext *context, const char *file)
return NULL;
}
for (y = 0; y < height; y++) {
png_rows[y] = wmalloc(png_get_rowbytes(png, pinfo));
png_rows[y] = malloc(png_get_rowbytes(png, pinfo));
if (!png_rows[y]) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
@@ -184,8 +182,8 @@ RImage *RLoadPNG(RContext *context, const char *file)
png_destroy_read_struct(&png, &pinfo, &einfo);
while (y-- > 0)
if (png_rows[y])
wfree(png_rows[y]);
wfree(png_rows);
free(png_rows[y]);
free(png_rows);
return NULL;
}
}
@@ -216,7 +214,7 @@ RImage *RLoadPNG(RContext *context, const char *file)
}
for (y = 0; y < height; y++)
if (png_rows[y])
wfree(png_rows[y]);
wfree(png_rows);
free(png_rows[y]);
free(png_rows);
return image;
}
+3 -5
View File
@@ -29,8 +29,6 @@
#include <string.h>
#include <limits.h>
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "imgformat.h"
#include "wr_i18n.h"
@@ -163,7 +161,7 @@ static RImage *load_graymap(FILE *file, int w, int h, int max, int raw, const ch
if (raw == '5') {
char *buf;
buf = wmalloc(w + 1);
buf = malloc(w + 1);
if (!buf) {
RErrorCode = RERR_NOMEMORY;
RReleaseImage(image);
@@ -171,7 +169,7 @@ static RImage *load_graymap(FILE *file, int w, int h, int max, int raw, const ch
}
for (y = 0; y < h; y++) {
if (!fread(buf, w, 1, file)) {
wfree(buf);
free(buf);
RErrorCode = RERR_BADIMAGEFILE;
RReleaseImage(image);
return NULL;
@@ -183,7 +181,7 @@ static RImage *load_graymap(FILE *file, int w, int h, int max, int raw, const ch
*(ptr++) = buf[x];
}
}
wfree(buf);
free(buf);
}
}
}
+6 -8
View File
@@ -29,8 +29,6 @@
#include <webp/decode.h>
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "imgformat.h"
#include "wr_i18n.h"
@@ -112,7 +110,7 @@ RImage *RLoadWEBP(const char *file_name)
return NULL;
}
raw_data = (uint8_t *) wmalloc(raw_data_size);
raw_data = (uint8_t *) malloc(raw_data_size);
if (!raw_data) {
RErrorCode = RERR_NOMEMORY;
@@ -126,7 +124,7 @@ RImage *RLoadWEBP(const char *file_name)
if (r != raw_data_size) {
RErrorCode = RERR_READ;
wfree(raw_data);
free(raw_data);
return NULL;
}
@@ -135,7 +133,7 @@ RImage *RLoadWEBP(const char *file_name)
fprintf(stderr, _("wrlib: could not get features from WebP file \"%s\", %s\n"),
file_name, webp_message_from_status(status));
RErrorCode = RERR_BADIMAGEFILE;
wfree(raw_data);
free(raw_data);
return NULL;
}
@@ -143,7 +141,7 @@ RImage *RLoadWEBP(const char *file_name)
image = RCreateImage(features.width, features.height, True);
if (!image) {
RErrorCode = RERR_NOMEMORY;
wfree(raw_data);
free(raw_data);
return NULL;
}
ret = WebPDecodeRGBAInto(raw_data, raw_data_size, image->data,
@@ -153,7 +151,7 @@ RImage *RLoadWEBP(const char *file_name)
image = RCreateImage(features.width, features.height, False);
if (!image) {
RErrorCode = RERR_NOMEMORY;
wfree(raw_data);
free(raw_data);
return NULL;
}
ret = WebPDecodeRGBInto(raw_data, raw_data_size, image->data,
@@ -161,7 +159,7 @@ RImage *RLoadWEBP(const char *file_name)
features.width * 3);
}
wfree(raw_data);
free(raw_data);
if (!ret) {
fprintf(stderr, _("wrlib: failed to decode WebP from file \"%s\"\n"), file_name);
+3 -5
View File
@@ -29,8 +29,6 @@
#include <string.h>
#include <X11/xpm.h>
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "imgformat.h"
#include "wr_i18n.h"
@@ -61,11 +59,11 @@ static RImage *create_rimage_from_xpm(RContext *context, XpmImage xpm)
/* make color table */
for (i = 0; i < 4; i++) {
color_table[i] = wmalloc(xpm.ncolors * sizeof(unsigned char));
color_table[i] = malloc(xpm.ncolors * sizeof(unsigned char));
if (!color_table[i]) {
for (i = i - 1; i >= 0; i--) {
if (color_table[i])
wfree(color_table[i]);
free(color_table[i]);
}
RReleaseImage(image);
RErrorCode = RERR_NOMEMORY;
@@ -125,7 +123,7 @@ static RImage *create_rimage_from_xpm(RContext *context, XpmImage xpm)
*(data++) = color_table[3][*p];
}
for (i = 0; i < 4; i++)
wfree(color_table[i]);
free(color_table[i]);
return image;
}
+21 -21
View File
@@ -59,15 +59,15 @@ static void free_color_symbol_table(unsigned char *color_table[],
unsigned short *symbol_table)
{
if (color_table[0])
wfree(color_table[0]);
free(color_table[0]);
if (color_table[1])
wfree(color_table[1]);
free(color_table[1]);
if (color_table[2])
wfree(color_table[2]);
free(color_table[2]);
if (color_table[3])
wfree(color_table[3]);
free(color_table[3]);
if (symbol_table)
wfree(symbol_table);
free(symbol_table);
}
RImage *RGetImageFromXPMData(RContext * context, char **data)
@@ -95,11 +95,11 @@ RImage *RGetImageFromXPMData(RContext * context, char **data)
if (csize != 1 && csize != 2)
goto bad_format;
color_table[0] = wmalloc(ccount);
color_table[1] = wmalloc(ccount);
color_table[2] = wmalloc(ccount);
color_table[3] = wmalloc(ccount);
symbol_table = wmalloc(ccount * sizeof(unsigned short));
color_table[0] = malloc(ccount);
color_table[1] = malloc(ccount);
color_table[2] = malloc(ccount);
color_table[3] = malloc(ccount);
symbol_table = malloc(ccount * sizeof(unsigned short));
bsize = csize * w + 16;
@@ -283,14 +283,14 @@ RImage *RLoadXPM(RContext * context, const char *file)
if (csize != 1 && csize != 2)
goto bad_format;
color_table[0] = wmalloc(ccount);
color_table[1] = wmalloc(ccount);
color_table[2] = wmalloc(ccount);
color_table[3] = wmalloc(ccount);
symbol_table = wmalloc(ccount * sizeof(unsigned short));
color_table[0] = malloc(ccount);
color_table[1] = malloc(ccount);
color_table[2] = malloc(ccount);
color_table[3] = malloc(ccount);
symbol_table = malloc(ccount * sizeof(unsigned short));
bsize = csize * w + 16;
buffer = wmalloc(bsize);
buffer = malloc(bsize);
if (!color_table[0] || !color_table[1] || !color_table[2] ||
!color_table[3] || !symbol_table || !bsize || !buffer) {
@@ -298,7 +298,7 @@ RImage *RLoadXPM(RContext * context, const char *file)
fclose(f);
free_color_symbol_table(color_table, symbol_table);
if (buffer)
wfree(buffer);
free(buffer);
return NULL;
}
@@ -355,7 +355,7 @@ RImage *RLoadXPM(RContext * context, const char *file)
fclose(f);
free_color_symbol_table(color_table, symbol_table);
if (buffer)
wfree(buffer);
free(buffer);
return NULL;
}
@@ -434,7 +434,7 @@ RImage *RLoadXPM(RContext * context, const char *file)
fclose(f);
free_color_symbol_table(color_table, symbol_table);
if (buffer)
wfree(buffer);
free(buffer);
return image;
bad_format:
@@ -442,7 +442,7 @@ RImage *RLoadXPM(RContext * context, const char *file)
fclose(f);
free_color_symbol_table(color_table, symbol_table);
if (buffer)
wfree(buffer);
free(buffer);
if (image)
RReleaseImage(image);
return NULL;
@@ -452,7 +452,7 @@ RImage *RLoadXPM(RContext * context, const char *file)
fclose(f);
free_color_symbol_table(color_table, symbol_table);
if (buffer)
wfree(buffer);
free(buffer);
if (image)
RReleaseImage(image);
return NULL;
+5 -7
View File
@@ -27,8 +27,6 @@
#include <string.h>
#include <X11/Xlib.h>
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "wr_i18n.h"
@@ -55,7 +53,7 @@ RImage *RCreateImage(unsigned width, unsigned height, int alpha)
return NULL;
}
image = wmalloc(sizeof(RImage));
image = malloc(sizeof(RImage));
if (!image) {
RErrorCode = RERR_NOMEMORY;
return NULL;
@@ -70,10 +68,10 @@ RImage *RCreateImage(unsigned width, unsigned height, int alpha)
/* the +4 is to give extra bytes at the end of the buffer,
* so that we can optimize image conversion for MMX(tm).. see convert.c
*/
image->data = wmalloc(width * height * (alpha ? 4 : 3) + 4);
image->data = malloc(width * height * (alpha ? 4 : 3) + 4);
if (!image->data) {
RErrorCode = RERR_NOMEMORY;
wfree(image);
free(image);
image = NULL;
}
@@ -96,8 +94,8 @@ void RReleaseImage(RImage * image)
image->refCount--;
if (image->refCount < 1) {
wfree(image->data);
wfree(image);
free(image->data);
free(image);
}
}
+2 -4
View File
@@ -29,8 +29,6 @@
#include <errno.h>
#include <jpeglib.h>
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "imgformat.h"
#include "wr_i18n.h"
@@ -61,7 +59,7 @@ Bool RSaveJPEG(RImage *img, const char *filename, char *title)
img_depth = 3;
/* collect separate RGB values to a buffer */
buffer = wmalloc(sizeof(char) * 3 * img->width * img->height);
buffer = malloc(sizeof(char) * 3 * img->width * img->height);
for (y = 0; y < img->height; y++) {
for (x = 0; x < img->width; x++) {
RGetPixel(img, x, y, &pixel);
@@ -99,7 +97,7 @@ Bool RSaveJPEG(RImage *img, const char *filename, char *title)
jpeg_finish_compress(&cinfo);
/* Clean */
wfree(buffer);
free(buffer);
fclose(file);
return True;
+2 -4
View File
@@ -29,8 +29,6 @@
#include <errno.h>
#include <png.h>
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "imgformat.h"
#include "wr_i18n.h"
@@ -97,7 +95,7 @@ Bool RSavePNG(RImage *img, const char *filename, char *title)
png_write_info(png_ptr, png_info_ptr);
/* Allocate memory for one row (3 bytes per pixel - RGB) */
png_row = (png_bytep) wmalloc(3 * width * sizeof(png_byte));
png_row = (png_bytep) malloc(3 * width * sizeof(png_byte));
/* Write image data */
for (y = 0; y < height; y++) {
@@ -123,7 +121,7 @@ Bool RSavePNG(RImage *img, const char *filename, char *title)
if (png_ptr != NULL)
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
if (png_row != NULL)
wfree(png_row);
free(png_row);
return True;
}
+2 -4
View File
@@ -28,8 +28,6 @@
#include <assert.h>
#include <errno.h>
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "imgformat.h"
#include "wr_i18n.h"
@@ -97,7 +95,7 @@ static Bool addcolor(XPMColor ** list, unsigned r, unsigned g, unsigned b, int *
if (tmpc)
return True;
newc = wmalloc(sizeof(XPMColor));
newc = malloc(sizeof(XPMColor));
if (!newc) {
@@ -151,7 +149,7 @@ static void freecolormap(XPMColor * colormap)
while (colormap) {
tmp = colormap->next;
wfree(colormap);
free(colormap);
colormap = tmp;
}
}
+13 -15
View File
@@ -29,8 +29,6 @@
#include <math.h>
#include <assert.h>
#include <WINGs/WUtil.h>
#include "wraster.h"
#include "scale.h"
#include "wr_i18n.h"
@@ -297,7 +295,7 @@ typedef struct {
/* clamp the input to the specified range */
#define CLAMP(v,l,h) ((v)<(l) ? (l) : (v) > (h) ? (h) : v)
/* return of wmalloc is not checked if NULL in the function below! */
/* return of calloc is not checked if NULL in the function below! */
RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
{
CLIST *contrib; /* array of contribution lists */
@@ -321,13 +319,13 @@ RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
yscale = (double)new_height / (double)src->height;
/* pre-calculate filter contributions for a row */
contrib = (CLIST *) wmalloc(new_width * sizeof(CLIST));
contrib = (CLIST *) calloc(new_width, sizeof(CLIST));
if (xscale < 1.0) {
width = fwidth / xscale;
fscale = 1.0 / xscale;
for (i = 0; i < new_width; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *) wmalloc(ceil(width * 2 + 1) * sizeof(CONTRIB));
contrib[i].p = (CONTRIB *) calloc((int) ceil(width * 2 + 1), sizeof(CONTRIB));
center = (double)i / xscale;
left = ceil(center - width);
right = floor(center + width);
@@ -350,7 +348,7 @@ RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
for (i = 0; i < new_width; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *) wmalloc(ceil(fwidth * 2 + 1) * sizeof(CONTRIB));
contrib[i].p = (CONTRIB *) calloc((int) ceil(fwidth * 2 + 1), sizeof(CONTRIB));
center = (double)i / xscale;
left = ceil(center - fwidth);
right = floor(center + fwidth);
@@ -397,18 +395,18 @@ RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
/* free the memory allocated for horizontal filter weights */
for (i = 0; i < new_width; ++i) {
wfree(contrib[i].p);
free(contrib[i].p);
}
wfree(contrib);
free(contrib);
/* pre-calculate filter contributions for a column */
contrib = (CLIST *) wmalloc(dst->height * sizeof(CLIST));
contrib = (CLIST *) calloc(dst->height, sizeof(CLIST));
if (yscale < 1.0) {
width = fwidth / yscale;
fscale = 1.0 / yscale;
for (i = 0; i < dst->height; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *) wmalloc(ceil(width * 2 + 1) * sizeof(CONTRIB));
contrib[i].p = (CONTRIB *) calloc((int) ceil(width * 2 + 1), sizeof(CONTRIB));
center = (double)i / yscale;
left = ceil(center - width);
right = floor(center + width);
@@ -430,7 +428,7 @@ RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
} else {
for (i = 0; i < dst->height; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *) wmalloc(ceil(fwidth * 2 + 1) * sizeof(CONTRIB));
contrib[i].p = (CONTRIB *) calloc((int) ceil(fwidth * 2 + 1), sizeof(CONTRIB));
center = (double)i / yscale;
left = ceil(center - fwidth);
right = floor(center + fwidth);
@@ -452,7 +450,7 @@ RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
}
/* apply filter to zoom vertically from tmp to dst */
sp = wmalloc(tmp->height * 3);
sp = malloc(tmp->height * 3);
for (k = 0; k < new_width; ++k) {
CONTRIB *pp;
@@ -487,13 +485,13 @@ RImage *RSmoothScaleImage(RImage * src, unsigned new_width, unsigned new_height)
p += new_width * 3;
}
}
wfree(sp);
free(sp);
/* free the memory allocated for vertical filter weights */
for (i = 0; i < dst->height; ++i) {
wfree(contrib[i].p);
free(contrib[i].p);
}
wfree(contrib);
free(contrib);
RReleaseImage(tmp);
+6 -6
View File
@@ -38,7 +38,7 @@ int main(int argc, char **argv)
else
ProgName++;
color_name = (char **)wmalloc(sizeof(char *) * argc);
color_name = (char **)malloc(sizeof(char *) * argc);
if (color_name == NULL) {
fprintf(stderr, "Cannot allocate memory!\n");
exit(1);
@@ -106,13 +106,13 @@ int main(int argc, char **argv)
exit(1);
}
colors = wmalloc(sizeof(RColor *) * (ncolors + 1));
colors = malloc(sizeof(RColor *) * (ncolors + 1));
for (i = 0; i < ncolors; i++) {
if (!XParseColor(dpy, ctx->cmap, color_name[i], &color)) {
printf("could not parse color \"%s\"\n", color_name[i]);
exit(1);
} else {
colors[i] = wmalloc(sizeof(RColor));
colors[i] = malloc(sizeof(RColor));
colors[i]->red = color.red >> 8;
colors[i]->green = color.green >> 8;
colors[i]->blue = color.blue >> 8;
@@ -149,10 +149,10 @@ int main(int argc, char **argv)
getchar();
wfree(color_name);
free(color_name);
for (i = 0; i < ncolors + 1; i++)
wfree(colors[i]);
wfree(colors);
free(colors[i]);
free(colors);
RDestroyContext(ctx);
RShutdown();
+11 -13
View File
@@ -31,8 +31,6 @@
#include <assert.h>
#include <WINGs/WUtil.h>
#ifdef USE_XSHM
#include <sys/ipc.h>
#include <sys/shm.h>
@@ -65,7 +63,7 @@ RXImage *RCreateXImage(RContext * context, int depth, unsigned width, unsigned h
RXImage *rximg;
Visual *visual = context->visual;
rximg = wmalloc(sizeof(RXImage));
rximg = malloc(sizeof(RXImage));
if (!rximg) {
RErrorCode = RERR_NOMEMORY;
return NULL;
@@ -73,14 +71,14 @@ RXImage *RCreateXImage(RContext * context, int depth, unsigned width, unsigned h
#ifndef USE_XSHM
rximg->image = XCreateImage(context->dpy, visual, depth, ZPixmap, 0, NULL, width, height, 8, 0);
if (!rximg->image) {
wfree(rximg);
free(rximg);
RErrorCode = RERR_XERROR;
return NULL;
}
rximg->image->data = wmalloc(rximg->image->bytes_per_line * height);
rximg->image->data = malloc(rximg->image->bytes_per_line * height);
if (!rximg->image->data) {
XDestroyImage(rximg->image);
wfree(rximg);
free(rximg);
RErrorCode = RERR_NOMEMORY;
return NULL;
}
@@ -92,14 +90,14 @@ RXImage *RCreateXImage(RContext * context, int depth, unsigned width, unsigned h
rximg->is_shared = 0;
rximg->image = XCreateImage(context->dpy, visual, depth, ZPixmap, 0, NULL, width, height, 8, 0);
if (!rximg->image) {
wfree(rximg);
free(rximg);
RErrorCode = RERR_XERROR;
return NULL;
}
rximg->image->data = wmalloc(rximg->image->bytes_per_line * height);
rximg->image->data = malloc(rximg->image->bytes_per_line * height);
if (!rximg->image->data) {
XDestroyImage(rximg->image);
wfree(rximg);
free(rximg);
RErrorCode = RERR_NOMEMORY;
return NULL;
}
@@ -175,7 +173,7 @@ void RDestroyXImage(RContext * context, RXImage * rximage)
XDestroyImage(rximage->image);
}
#endif
wfree(rximage);
free(rximage);
}
static unsigned getDepth(Display * dpy, Drawable d)
@@ -207,7 +205,7 @@ RXImage *RGetXImage(RContext * context, Drawable d, int x, int y, unsigned width
}
}
if (!ximg) {
ximg = wmalloc(sizeof(RXImage));
ximg = malloc(sizeof(RXImage));
if (!ximg) {
RErrorCode = RERR_NOMEMORY;
return NULL;
@@ -216,7 +214,7 @@ RXImage *RGetXImage(RContext * context, Drawable d, int x, int y, unsigned width
ximg->image = XGetImage(context->dpy, d, x, y, width, height, AllPlanes, ZPixmap);
}
#else /* !USE_XSHM */
ximg = wmalloc(sizeof(RXImage));
ximg = malloc(sizeof(RXImage));
if (!ximg) {
RErrorCode = RERR_NOMEMORY;
return NULL;
@@ -226,7 +224,7 @@ RXImage *RGetXImage(RContext * context, Drawable d, int x, int y, unsigned width
#endif /* !USE_XSHM */
if (ximg->image == NULL) {
wfree(ximg);
free(ximg);
return NULL;
}
+1 -6
View File
@@ -6,12 +6,7 @@ edition = "2024"
[lib]
crate-type = ["staticlib"]
[build-dependencies]
cc = "1.0"
[dependencies]
atomic-write-file = "0.3"
hashbrown = "0.16.0"
nom = "8.0"
nom-language = "0.1"
libc = "0.2.175"
x11 = "2.21.0"
+1 -11
View File
@@ -1,19 +1,9 @@
AUTOMAKE_OPTIONS =
RUST_SOURCES = \
src/array.rs \
src/bag.rs \
src/data.rs \
src/defines.c \
src/defines.rs \
src/find_file.rs \
src/hash_table.rs \
src/lib.rs \
src/memory.rs \
src/notification.rs \
src/prop_list.rs \
src/string.rs
src/tree.rs
src/memory.rs
RUST_EXTRA = \
Cargo.lock \

Some files were not shown because too many files have changed in this diff Show More