1
0
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:
dan
2000-11-02 02:51:53 +00:00
parent 2bd2b72af9
commit a81a0685ef
4 changed files with 97 additions and 72 deletions

View File

@@ -43,10 +43,17 @@ changes since wmaker 0.62.1:
- added WMScrollerDidScrollNotification to scroller - added WMScrollerDidScrollNotification to scroller
- added WMGetScrollViewVisibleRect() - added WMGetScrollViewVisibleRect()
- fixed a mem leak in the browser code. - fixed a mem leak in the browser code.
- renamed wstrappend() to wstrconcat(). Be sure to rename all occurences of - renamed wstrappend() to wstrconcat(). wstrconcat(str1, str2) concatenates
wstrappend() in your own code with wstrconcat(), else weird things may str1 with str2 and returns that in a newly malloc'ed string.
happen, because a new wstrappend() with different semantics is to be Be sure to rename wstrappend with wstrconcat in your code too, else
implemented! 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: changes since wmaker 0.62.0:

View File

@@ -236,8 +236,20 @@ 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); void wtokensplit(char *command, char ***argv, int *argc);

View File

@@ -76,7 +76,8 @@ static int Aborting=0; /* if we're in the middle of an emergency exit */
static WMHashTable *table = NULL; static WMHashTable *table = NULL;
void *wmalloc(size_t size) void*
wmalloc(size_t size)
{ {
void *tmp; 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; void *nptr;
@@ -228,19 +230,35 @@ wstrdup(char *str)
char* char*
wstrconcat(char *dst, char *src) wstrconcat(char *str1, char *str2)
{ {
char *str; char *str;
if (!dst) if (!str1)
return wstrdup(src); return wstrdup(str2);
else if (!src) else if (!str2)
return wstrdup(dst); return wstrdup(str1);
str = wmalloc(strlen(dst)+strlen(src)+1); str = wmalloc(strlen(str1)+strlen(str2)+1);
strcpy(str, dst); strcpy(str, str1);
strcat(str, src); strcat(str, str2);
return str; 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;
}

View File

@@ -1023,18 +1023,6 @@ keysymToString(KeySym keysym, unsigned int state)
} }
#endif #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* char*
GetShortcutString(char *text) GetShortcutString(char *text)
@@ -1061,39 +1049,39 @@ GetShortcutString(char *text)
modmask |= mod; modmask |= mod;
if (strcasecmp(text, "Meta")==0) { if (strcasecmp(text, "Meta")==0) {
buffer = appendrealloc(buffer, "M+"); buffer = wstrappend(buffer, "M+");
} else if (strcasecmp(text, "Alt")==0) { } else if (strcasecmp(text, "Alt")==0) {
buffer = appendrealloc(buffer, "A+"); buffer = wstrappend(buffer, "A+");
} else if (strcasecmp(text, "Shift")==0) { } else if (strcasecmp(text, "Shift")==0) {
buffer = appendrealloc(buffer, "Sh+"); buffer = wstrappend(buffer, "Sh+");
} else if (strcasecmp(text, "Mod1")==0) { } else if (strcasecmp(text, "Mod1")==0) {
buffer = appendrealloc(buffer, "M1+"); buffer = wstrappend(buffer, "M1+");
} else if (strcasecmp(text, "Mod2")==0) { } else if (strcasecmp(text, "Mod2")==0) {
buffer = appendrealloc(buffer, "M2+"); buffer = wstrappend(buffer, "M2+");
} else if (strcasecmp(text, "Mod3")==0) { } else if (strcasecmp(text, "Mod3")==0) {
buffer = appendrealloc(buffer, "M3+"); buffer = wstrappend(buffer, "M3+");
} else if (strcasecmp(text, "Mod4")==0) { } else if (strcasecmp(text, "Mod4")==0) {
buffer = appendrealloc(buffer, "M4+"); buffer = wstrappend(buffer, "M4+");
} else if (strcasecmp(text, "Mod5")==0) { } else if (strcasecmp(text, "Mod5")==0) {
buffer = appendrealloc(buffer, "M5+"); buffer = wstrappend(buffer, "M5+");
} else if (strcasecmp(text, "Control")==0) { } else if (strcasecmp(text, "Control")==0) {
control = 1; control = 1;
} else { } else {
buffer = appendrealloc(buffer, text); buffer = wstrappend(buffer, text);
} }
text = k+1; text = k+1;
} }
if (control) { if (control) {
buffer = appendrealloc(buffer, "^"); buffer = wstrappend(buffer, "^");
} }
buffer = appendrealloc(buffer, text); buffer = wstrappend(buffer, text);
/* get key */ /* get key */
/* ksym = XStringToKeysym(text); /* ksym = XStringToKeysym(text);
tmp = keysymToString(ksym, modmask); tmp = keysymToString(ksym, modmask);
puts(tmp); puts(tmp);
buffer = wstrconcat(buffer, tmp); buffer = wstrappend(buffer, tmp);
*/ */
wfree(tmp); wfree(tmp);