StrConcatStr concats the first and second argument with a point.
The function char *StrConcatDot(char *a, char *b) is now
char *StrConcatDot(char *a, char *b, Bool alwayspoint).
This new argument will be used to simplify the code in next patches.
Now:
If alwayspoint is True, the point is added always,
If alwayspoint is False, the point is added only if first and second argument
exists
---
src/funcs.h | 2 +-
src/misc.c | 25 +++++++++++++++++++------
src/window.c | 2 +-
src/winspector.c | 8 +++-----
4 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/src/funcs.h b/src/funcs.h
index e827504..e320a07 100644
--- a/src/funcs.h
+++ b/src/funcs.h
@@ -79,7 +79,7 @@ int calcIntersectionArea(int x1, int y1, int w1, int h1,
char *MakeCPPArgs(char *path);
#endif
-char * StrConcatDot(char *a, char *b);
+char *StrConcatDot(char *a, char *b, Bool alwaysdot);
char * ExpandOptions(WScreen *scr, char *cmdline);
char * ShrinkString(WMFont *font, char *string, int width);
char * FindImage(char *paths, char *file);
diff --git a/src/misc.c b/src/misc.c
index fd283c2..9fbc746 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -1048,20 +1048,33 @@ Bool UpdateDomainFile(WDDomain * domain)
return result;
}
-char *StrConcatDot(char *a, char *b)
+/* Concats the first and second argument with a point.
+ * If alwayspoint is True, the point is added always,
+ * If alwayspoint is False, the point is added only
+ * if first and second argument exists
+ */
+char *StrConcatDot(char *a, char *b, Bool alwayspoint)
{
- int len;
+ int len, fail = 0;
char *str;
- if (!a)
+ if (!a) {
a = "";
- if (!b)
+ fail++;
+ }
+
+ if (!b) {
b = "";
+ fail++;
+ }
- len = strlen(a) + strlen(b) + 4;
+ len = strlen(a) + strlen(b) + 2 - fail + 1 ;
str = wmalloc(len);
- snprintf(str, len, "%s.%s", a, b);
+ if (!alwayspoint && fail > 0)
+ snprintf(str, len, "%s%s", a, b);
+ else
+ snprintf(str, len, "%s.%s", a, b);
return str;
}
diff --git a/src/window.c b/src/window.c
index f05be9e..bd02044 100644
--- a/src/window.c
+++ b/src/window.c
@@ -781,7 +781,7 @@ WWindow *wManageWindow(WScreen *scr, Window window)
/* // only enter here if PropGetWMClass() succeds */
PropGetWMClass(wwin->main_window, &class, &instance);
- buffer = StrConcatDot(instance, class);
+ buffer = StrConcatDot(instance, class, True);
index = WMFindInArray(scr->fakeGroupLeaders, matchIdentifier,
(void *)buffer);
if (index != WANotFound) {
diff --git a/src/winspector.c b/src/winspector.c
index 37ae0b2..1d74313 100644
--- a/src/winspector.c
+++ b/src/winspector.c
@@ -463,7 +463,7 @@ static void saveSettings(WMButton * button, InspectorPanel
* panel)
WDDomain *db = WDWindowAttributes;
WMPropList *dict = db->dictionary;
WMPropList *winDic, *appDic, *value, *key, *key2;
- char *icon_file;
+ char *icon_file, *buffer;
int flags = 0;
int different = 0, different2 = 0;
@@ -475,9 +475,7 @@ static void saveSettings(WMButton * button, InspectorPanel
* panel)
else if (WMGetButtonSelected(panel->clsRb) != 0)
key = WMCreatePLString(wwin->wm_class);
else if (WMGetButtonSelected(panel->bothRb) != 0) {
- char *buffer;
-
- buffer = StrConcatDot(wwin->wm_instance, wwin->wm_class);
+ buffer = StrConcatDot(wwin->wm_instance, wwin->wm_class, True);
key = WMCreatePLString(buffer);
wfree(buffer);
} else if (WMGetButtonSelected(panel->defaultRb) != 0) {
@@ -639,7 +637,7 @@ static void saveSettings(WMButton * button, InspectorPanel
* panel)
char *class = wapp->main_window_desc->wm_class;
char *buffer;
- buffer = StrConcatDot(instance, class);
+ buffer = StrConcatDot(instance, class, True);
key2 = WMCreatePLString(buffer);
wfree(buffer);
--
1.7.9.1
>From 8da82b5523c9429e825a074cd6ef37949e72d450 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20(kix)"?= <[email protected]>
Date: Sat, 14 Apr 2012 11:08:56 +0200
Subject: [PATCH 04/16] WindowMaker: StrConcatStr inclues new argument
StrConcatStr concats the first and second argument with a point.
The function char *StrConcatDot(char *a, char *b) is now
char *StrConcatDot(char *a, char *b, Bool alwayspoint).
This new argument will be used to simplify the code in next patches.
Now:
If alwayspoint is True, the point is added always,
If alwayspoint is False, the point is added only if first and second argument exists
---
src/funcs.h | 2 +-
src/misc.c | 25 +++++++++++++++++++------
src/window.c | 2 +-
src/winspector.c | 8 +++-----
4 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/src/funcs.h b/src/funcs.h
index e827504..e320a07 100644
--- a/src/funcs.h
+++ b/src/funcs.h
@@ -79,7 +79,7 @@ int calcIntersectionArea(int x1, int y1, int w1, int h1,
char *MakeCPPArgs(char *path);
#endif
-char * StrConcatDot(char *a, char *b);
+char *StrConcatDot(char *a, char *b, Bool alwaysdot);
char * ExpandOptions(WScreen *scr, char *cmdline);
char * ShrinkString(WMFont *font, char *string, int width);
char * FindImage(char *paths, char *file);
diff --git a/src/misc.c b/src/misc.c
index fd283c2..9fbc746 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -1048,20 +1048,33 @@ Bool UpdateDomainFile(WDDomain * domain)
return result;
}
-char *StrConcatDot(char *a, char *b)
+/* Concats the first and second argument with a point.
+ * If alwayspoint is True, the point is added always,
+ * If alwayspoint is False, the point is added only
+ * if first and second argument exists
+ */
+char *StrConcatDot(char *a, char *b, Bool alwayspoint)
{
- int len;
+ int len, fail = 0;
char *str;
- if (!a)
+ if (!a) {
a = "";
- if (!b)
+ fail++;
+ }
+
+ if (!b) {
b = "";
+ fail++;
+ }
- len = strlen(a) + strlen(b) + 4;
+ len = strlen(a) + strlen(b) + 2 - fail + 1 ;
str = wmalloc(len);
- snprintf(str, len, "%s.%s", a, b);
+ if (!alwayspoint && fail > 0)
+ snprintf(str, len, "%s%s", a, b);
+ else
+ snprintf(str, len, "%s.%s", a, b);
return str;
}
diff --git a/src/window.c b/src/window.c
index f05be9e..bd02044 100644
--- a/src/window.c
+++ b/src/window.c
@@ -781,7 +781,7 @@ WWindow *wManageWindow(WScreen *scr, Window window)
/* // only enter here if PropGetWMClass() succeds */
PropGetWMClass(wwin->main_window, &class, &instance);
- buffer = StrConcatDot(instance, class);
+ buffer = StrConcatDot(instance, class, True);
index = WMFindInArray(scr->fakeGroupLeaders, matchIdentifier, (void *)buffer);
if (index != WANotFound) {
diff --git a/src/winspector.c b/src/winspector.c
index 37ae0b2..1d74313 100644
--- a/src/winspector.c
+++ b/src/winspector.c
@@ -463,7 +463,7 @@ static void saveSettings(WMButton * button, InspectorPanel * panel)
WDDomain *db = WDWindowAttributes;
WMPropList *dict = db->dictionary;
WMPropList *winDic, *appDic, *value, *key, *key2;
- char *icon_file;
+ char *icon_file, *buffer;
int flags = 0;
int different = 0, different2 = 0;
@@ -475,9 +475,7 @@ static void saveSettings(WMButton * button, InspectorPanel * panel)
else if (WMGetButtonSelected(panel->clsRb) != 0)
key = WMCreatePLString(wwin->wm_class);
else if (WMGetButtonSelected(panel->bothRb) != 0) {
- char *buffer;
-
- buffer = StrConcatDot(wwin->wm_instance, wwin->wm_class);
+ buffer = StrConcatDot(wwin->wm_instance, wwin->wm_class, True);
key = WMCreatePLString(buffer);
wfree(buffer);
} else if (WMGetButtonSelected(panel->defaultRb) != 0) {
@@ -639,7 +637,7 @@ static void saveSettings(WMButton * button, InspectorPanel * panel)
char *class = wapp->main_window_desc->wm_class;
char *buffer;
- buffer = StrConcatDot(instance, class);
+ buffer = StrConcatDot(instance, class, True);
key2 = WMCreatePLString(buffer);
wfree(buffer);
--
1.7.9.1