mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 04:20:27 +01:00
- added a new version of wstrappend() with different behavior from the
old one (the one renamed to wstrconcat). The new wstrappend(dst, src) will modify and return dst, without creating a new string to hold the result, except if dst==NULL, in which case its equivalent to calling wstrdup(src)
This commit is contained in:
@@ -43,10 +43,17 @@ changes since wmaker 0.62.1:
|
||||
- added WMScrollerDidScrollNotification to scroller
|
||||
- added WMGetScrollViewVisibleRect()
|
||||
- fixed a mem leak in the browser code.
|
||||
- renamed wstrappend() to wstrconcat(). Be sure to rename all occurences of
|
||||
wstrappend() in your own code with wstrconcat(), else weird things may
|
||||
happen, because a new wstrappend() with different semantics is to be
|
||||
implemented!
|
||||
- renamed wstrappend() to wstrconcat(). wstrconcat(str1, str2) concatenates
|
||||
str1 with str2 and returns that in a newly malloc'ed string.
|
||||
Be sure to rename wstrappend with wstrconcat in your code too, else
|
||||
hazardous things can happen!
|
||||
- implemented a new wstrappend() function. wstrappend(dst, src) will append
|
||||
src to dst modifing dst and returning a pointer to it. No new string is
|
||||
generated, except if dst is NULL, in which case its the same as calling
|
||||
wstrdup(src).
|
||||
dst can ONLY be NULL or a dynamically allocated string (obtained from a
|
||||
call to malloc, realloc, wmalloc, wrealloc, ...). dst CANNOT be a static
|
||||
or a constant string!
|
||||
|
||||
|
||||
changes since wmaker 0.62.0:
|
||||
|
||||
@@ -204,57 +204,69 @@ typedef void WMNotificationObserverAction(void *observerData,
|
||||
|
||||
typedef void (waborthandler)(int);
|
||||
|
||||
waborthandler *wsetabort(waborthandler*);
|
||||
waborthandler* wsetabort(waborthandler*);
|
||||
|
||||
|
||||
/* don't free the returned string */
|
||||
char *wstrerror(int errnum);
|
||||
char* wstrerror(int errnum);
|
||||
|
||||
void wfatal(const char *msg, ...);
|
||||
void wwarning(const char *msg, ...);
|
||||
void wsyserror(const char *msg, ...);
|
||||
void wsyserrorwithcode(int error, const char *msg, ...);
|
||||
|
||||
char *wfindfile(char *paths, char *file);
|
||||
char* wfindfile(char *paths, char *file);
|
||||
|
||||
char *wfindfileinlist(char **path_list, char *file);
|
||||
char* wfindfileinlist(char **path_list, char *file);
|
||||
|
||||
char *wfindfileinarray(proplist_t array, char *file);
|
||||
|
||||
char *wexpandpath(char *path);
|
||||
char* wfindfileinarray(proplist_t array, char *file);
|
||||
|
||||
char* wexpandpath(char *path);
|
||||
|
||||
/* don't free the returned string */
|
||||
char *wgethomedir();
|
||||
char* wgethomedir();
|
||||
|
||||
void *wmalloc(size_t size);
|
||||
void *wrealloc(void *ptr, size_t newsize);
|
||||
void* wmalloc(size_t size);
|
||||
void* wrealloc(void *ptr, size_t newsize);
|
||||
void wfree(void *ptr);
|
||||
|
||||
|
||||
void wrelease(void *ptr);
|
||||
void *wretain(void *ptr);
|
||||
void* wretain(void *ptr);
|
||||
|
||||
char *wstrdup(char *str);
|
||||
char* wstrdup(char *str);
|
||||
|
||||
char *wstrconcat(char *dst, char *src);
|
||||
/* Concatenate str1 with str2 and return that in a newly malloc'ed string.
|
||||
* str1 and str2 can be any strings including static and constant strings.
|
||||
* str1 and str2 will not be modified.
|
||||
* Free the returned string when you're done with it. */
|
||||
char* wstrconcat(char *str1, char *str2);
|
||||
|
||||
/* This will append src to dst, and return dst. dst MUST be either NULL
|
||||
* or a string that was a result of a dynamic allocation (malloc, realloc
|
||||
* wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
|
||||
* Modifies dst (no new string is created except if dst==NULL in which case
|
||||
* it is equivalent to calling wstrdup(src) ).
|
||||
* The returned address may be different from the original address of dst,
|
||||
* so always assign the returned address to avoid dangling pointers. */
|
||||
char* wstrappend(char *dst, char *src);
|
||||
|
||||
|
||||
void wtokensplit(char *command, char ***argv, int *argc);
|
||||
|
||||
char *wtokennext(char *word, char **next);
|
||||
char* wtokennext(char *word, char **next);
|
||||
|
||||
char *wtokenjoin(char **list, int count);
|
||||
char* wtokenjoin(char **list, int count);
|
||||
|
||||
void wtokenfree(char **tokens, int count);
|
||||
|
||||
char *wtrimspace(char *s);
|
||||
char* wtrimspace(char *s);
|
||||
|
||||
|
||||
|
||||
char *wusergnusteppath();
|
||||
char* wusergnusteppath();
|
||||
|
||||
char *wdefaultspathfordomain(char *domain);
|
||||
char* wdefaultspathfordomain(char *domain);
|
||||
|
||||
void wusleep(unsigned int microsec);
|
||||
|
||||
@@ -275,24 +287,24 @@ void WHandleEvents();
|
||||
/*......................................................................*/
|
||||
|
||||
|
||||
WMHashTable *WMCreateHashTable(WMHashTableCallbacks callbacks);
|
||||
WMHashTable* WMCreateHashTable(WMHashTableCallbacks callbacks);
|
||||
|
||||
void WMFreeHashTable(WMHashTable *table);
|
||||
|
||||
void WMResetHashTable(WMHashTable *table);
|
||||
|
||||
void *WMHashGet(WMHashTable *table, const void *key);
|
||||
void* WMHashGet(WMHashTable *table, const void *key);
|
||||
|
||||
/* put data in table, replacing already existing data and returning
|
||||
* the old value */
|
||||
void *WMHashInsert(WMHashTable *table, void *key, void *data);
|
||||
void* WMHashInsert(WMHashTable *table, void *key, void *data);
|
||||
|
||||
void WMHashRemove(WMHashTable *table, const void *key);
|
||||
|
||||
/* warning: do not manipulate the table while using these functions */
|
||||
WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
|
||||
|
||||
void *WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
|
||||
void* WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
|
||||
|
||||
unsigned WMCountHashTable(WMHashTable *table);
|
||||
|
||||
@@ -558,17 +570,17 @@ unsigned WMGetDataFormat(WMData *aData);
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
WMNotification *WMCreateNotification(char *name, void *object, void *clientData);
|
||||
WMNotification* WMCreateNotification(char *name, void *object, void *clientData);
|
||||
|
||||
void WMReleaseNotification(WMNotification *notification);
|
||||
|
||||
WMNotification *WMRetainNotification(WMNotification *notification);
|
||||
WMNotification* WMRetainNotification(WMNotification *notification);
|
||||
|
||||
void *WMGetNotificationClientData(WMNotification *notification);
|
||||
void* WMGetNotificationClientData(WMNotification *notification);
|
||||
|
||||
void *WMGetNotificationObject(WMNotification *notification);
|
||||
void* WMGetNotificationObject(WMNotification *notification);
|
||||
|
||||
char *WMGetNotificationName(WMNotification *notification);
|
||||
char* WMGetNotificationName(WMNotification *notification);
|
||||
|
||||
|
||||
void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
|
||||
@@ -583,9 +595,9 @@ void WMRemoveNotificationObserverWithName(void *observer, char *name,
|
||||
|
||||
void WMPostNotificationName(char *name, void *object, void *clientData);
|
||||
|
||||
WMNotificationQueue *WMGetDefaultNotificationQueue(void);
|
||||
WMNotificationQueue* WMGetDefaultNotificationQueue(void);
|
||||
|
||||
WMNotificationQueue *WMCreateNotificationQueue(void);
|
||||
WMNotificationQueue* WMCreateNotificationQueue(void);
|
||||
|
||||
void WMDequeueNotificationMatching(WMNotificationQueue *queue,
|
||||
WMNotification *notification,
|
||||
@@ -603,9 +615,9 @@ void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
|
||||
|
||||
/*......................................................................*/
|
||||
|
||||
WMUserDefaults *WMGetStandardUserDefaults(void);
|
||||
WMUserDefaults* WMGetStandardUserDefaults(void);
|
||||
|
||||
WMUserDefaults *WMGetDefaultsFromPath(char *path);
|
||||
WMUserDefaults* WMGetDefaultsFromPath(char *path);
|
||||
|
||||
void WMSynchronizeUserDefaults(WMUserDefaults *database);
|
||||
|
||||
@@ -625,7 +637,7 @@ void WMSetUDObjectForKey(WMUserDefaults *database, proplist_t object,
|
||||
|
||||
void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
|
||||
|
||||
char *WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
|
||||
char* WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
|
||||
|
||||
int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
|
||||
|
||||
|
||||
@@ -76,7 +76,8 @@ static int Aborting=0; /* if we're in the middle of an emergency exit */
|
||||
static WMHashTable *table = NULL;
|
||||
|
||||
|
||||
void *wmalloc(size_t size)
|
||||
void*
|
||||
wmalloc(size_t size)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
@@ -110,7 +111,8 @@ void *wmalloc(size_t size)
|
||||
}
|
||||
|
||||
|
||||
void *wrealloc(void *ptr, size_t newsize)
|
||||
void*
|
||||
wrealloc(void *ptr, size_t newsize)
|
||||
{
|
||||
void *nptr;
|
||||
|
||||
@@ -228,19 +230,35 @@ wstrdup(char *str)
|
||||
|
||||
|
||||
char*
|
||||
wstrconcat(char *dst, char *src)
|
||||
wstrconcat(char *str1, char *str2)
|
||||
{
|
||||
char *str;
|
||||
|
||||
if (!dst)
|
||||
return wstrdup(src);
|
||||
else if (!src)
|
||||
return wstrdup(dst);
|
||||
|
||||
str = wmalloc(strlen(dst)+strlen(src)+1);
|
||||
strcpy(str, dst);
|
||||
strcat(str, src);
|
||||
|
||||
if (!str1)
|
||||
return wstrdup(str2);
|
||||
else if (!str2)
|
||||
return wstrdup(str1);
|
||||
|
||||
str = wmalloc(strlen(str1)+strlen(str2)+1);
|
||||
strcpy(str, str1);
|
||||
strcat(str, str2);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
wstrappend(char *dst, char *src)
|
||||
{
|
||||
if (!dst)
|
||||
return wstrdup(src);
|
||||
else if (!src || *src==0)
|
||||
return dst;
|
||||
|
||||
dst = wrealloc(dst, strlen(dst)+strlen(src)+1);
|
||||
strcat(dst, src);
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
36
src/misc.c
36
src/misc.c
@@ -1023,18 +1023,6 @@ keysymToString(KeySym keysym, unsigned int state)
|
||||
}
|
||||
#endif
|
||||
|
||||
static char *
|
||||
appendrealloc(char *a, char *b)
|
||||
{
|
||||
if (a == NULL)
|
||||
return wstrdup(b);
|
||||
else {
|
||||
char *c = wstrconcat(a, b);
|
||||
wfree(a);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
GetShortcutString(char *text)
|
||||
@@ -1061,39 +1049,39 @@ GetShortcutString(char *text)
|
||||
modmask |= mod;
|
||||
|
||||
if (strcasecmp(text, "Meta")==0) {
|
||||
buffer = appendrealloc(buffer, "M+");
|
||||
buffer = wstrappend(buffer, "M+");
|
||||
} else if (strcasecmp(text, "Alt")==0) {
|
||||
buffer = appendrealloc(buffer, "A+");
|
||||
buffer = wstrappend(buffer, "A+");
|
||||
} else if (strcasecmp(text, "Shift")==0) {
|
||||
buffer = appendrealloc(buffer, "Sh+");
|
||||
buffer = wstrappend(buffer, "Sh+");
|
||||
} else if (strcasecmp(text, "Mod1")==0) {
|
||||
buffer = appendrealloc(buffer, "M1+");
|
||||
buffer = wstrappend(buffer, "M1+");
|
||||
} else if (strcasecmp(text, "Mod2")==0) {
|
||||
buffer = appendrealloc(buffer, "M2+");
|
||||
buffer = wstrappend(buffer, "M2+");
|
||||
} else if (strcasecmp(text, "Mod3")==0) {
|
||||
buffer = appendrealloc(buffer, "M3+");
|
||||
buffer = wstrappend(buffer, "M3+");
|
||||
} else if (strcasecmp(text, "Mod4")==0) {
|
||||
buffer = appendrealloc(buffer, "M4+");
|
||||
buffer = wstrappend(buffer, "M4+");
|
||||
} else if (strcasecmp(text, "Mod5")==0) {
|
||||
buffer = appendrealloc(buffer, "M5+");
|
||||
buffer = wstrappend(buffer, "M5+");
|
||||
} else if (strcasecmp(text, "Control")==0) {
|
||||
control = 1;
|
||||
} else {
|
||||
buffer = appendrealloc(buffer, text);
|
||||
buffer = wstrappend(buffer, text);
|
||||
}
|
||||
text = k+1;
|
||||
}
|
||||
|
||||
if (control) {
|
||||
buffer = appendrealloc(buffer, "^");
|
||||
buffer = wstrappend(buffer, "^");
|
||||
}
|
||||
buffer = appendrealloc(buffer, text);
|
||||
buffer = wstrappend(buffer, text);
|
||||
|
||||
/* get key */
|
||||
/* ksym = XStringToKeysym(text);
|
||||
tmp = keysymToString(ksym, modmask);
|
||||
puts(tmp);
|
||||
buffer = wstrconcat(buffer, tmp);
|
||||
buffer = wstrappend(buffer, tmp);
|
||||
*/
|
||||
wfree(tmp);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user