mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-20 04:48:06 +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:
|
||||
|
||||
@@ -236,8 +236,20 @@ void *wretain(void *ptr);
|
||||
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
if (!str1)
|
||||
return wstrdup(str2);
|
||||
else if (!str2)
|
||||
return wstrdup(str1);
|
||||
|
||||
str = wmalloc(strlen(dst)+strlen(src)+1);
|
||||
strcpy(str, dst);
|
||||
strcat(str, src);
|
||||
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