The function EscapeWM_CLASS is splited now, using the new
static function escape_word(). This new function includes
the code called twice by EscapeWM_CLASS.

EscapeWM_CLASS uses now StrConcatDot to simplify the code.
---
 src/misc.c |   73 +++++++++++++++++++++++++----------------------------------
 1 files changed, 31 insertions(+), 42 deletions(-)

diff --git a/src/misc.c b/src/misc.c
index 9fbc746..0946946 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -877,57 +877,46 @@ char *GetShortcutString(char *text)
        return buffer;
 }
 
-char *EscapeWM_CLASS(char *name, char *class)
+static char * escape_word(char *word)
 {
-       char *ret;
-       char *ename = NULL, *eclass = NULL;
+       char *eword;
        int i, j, l;
 
+       l = strlen(word);
+       eword = wmalloc(l * 2 + 1);
+       j = 0;
+       for (i = 0; i < l; i++) {
+               if ((word[i] == '\\') || (word[i] == '.'))
+                       eword[j++] = '\\';
+
+               eword[j++] = word[i];
+       }
+       eword[j] = 0;
+
+       return(eword);
+}
+
+char *EscapeWM_CLASS(char *name, char *class)
+{
+       char *ret = NULL, *ename = NULL, *eclass = NULL;
+
        if (!name && !class)
                return NULL;
 
-       if (name) {
-               l = strlen(name);
-               ename = wmalloc(l * 2 + 1);
-               j = 0;
-               for (i = 0; i < l; i++) {
-                       if (name[i] == '\\') {
-                               ename[j++] = '\\';
-                       } else if (name[i] == '.') {
-                               ename[j++] = '\\';
-                       }
-                       ename[j++] = name[i];
-               }
-               ename[j] = 0;
-       }
-       if (class) {
-               l = strlen(class);
-               eclass = wmalloc(l * 2 + 1);
-               j = 0;
-               for (i = 0; i < l; i++) {
-                       if (class[i] == '\\') {
-                               eclass[j++] = '\\';
-                       } else if (class[i] == '.') {
-                               eclass[j++] = '\\';
-                       }
-                       eclass[j++] = class[i];
-               }
-               eclass[j] = 0;
-       }
+       if (name)
+               ename = escape_word(name);
 
-       if (ename && eclass) {
-               int len = strlen(ename) + strlen(eclass) + 4;
-               ret = wmalloc(len);
-               snprintf(ret, len, "%s.%s", ename, eclass);
-               wfree(ename);
-               wfree(eclass);
-       } else if (ename) {
-               ret = wstrdup(ename);
+       if (class)
+               eclass = escape_word(class);
+
+       if (ename || eclass)
+               ret = StrConcatDot(ename, eclass, False);
+
+       if (ename)
                wfree(ename);
-       } else {
-               ret = wstrdup(eclass);
+
+       if (eclass)
                wfree(eclass);
-       }
 
        return ret;
 }
-- 
1.7.9.1

>From 8c50f88a103b9332d0f5817b94bcd1033a0b3615 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 12:01:28 +0200
Subject: [PATCH 10/16] WindowMaker: EscapeWM_CLASS splitted

The function EscapeWM_CLASS is splited now, using the new
static function escape_word(). This new function includes
the code called twice by EscapeWM_CLASS.

EscapeWM_CLASS uses now StrConcatDot to simplify the code.
---
 src/misc.c |   73 +++++++++++++++++++++++++----------------------------------
 1 files changed, 31 insertions(+), 42 deletions(-)

diff --git a/src/misc.c b/src/misc.c
index 9fbc746..0946946 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -877,57 +877,46 @@ char *GetShortcutString(char *text)
 	return buffer;
 }
 
-char *EscapeWM_CLASS(char *name, char *class)
+static char * escape_word(char *word)
 {
-	char *ret;
-	char *ename = NULL, *eclass = NULL;
+	char *eword;
 	int i, j, l;
 
+	l = strlen(word);
+	eword = wmalloc(l * 2 + 1);
+	j = 0;
+	for (i = 0; i < l; i++) {
+		if ((word[i] == '\\') || (word[i] == '.'))
+			eword[j++] = '\\';
+
+		eword[j++] = word[i];
+	}
+	eword[j] = 0;
+
+	return(eword);
+}
+
+char *EscapeWM_CLASS(char *name, char *class)
+{
+	char *ret = NULL, *ename = NULL, *eclass = NULL;
+
 	if (!name && !class)
 		return NULL;
 
-	if (name) {
-		l = strlen(name);
-		ename = wmalloc(l * 2 + 1);
-		j = 0;
-		for (i = 0; i < l; i++) {
-			if (name[i] == '\\') {
-				ename[j++] = '\\';
-			} else if (name[i] == '.') {
-				ename[j++] = '\\';
-			}
-			ename[j++] = name[i];
-		}
-		ename[j] = 0;
-	}
-	if (class) {
-		l = strlen(class);
-		eclass = wmalloc(l * 2 + 1);
-		j = 0;
-		for (i = 0; i < l; i++) {
-			if (class[i] == '\\') {
-				eclass[j++] = '\\';
-			} else if (class[i] == '.') {
-				eclass[j++] = '\\';
-			}
-			eclass[j++] = class[i];
-		}
-		eclass[j] = 0;
-	}
+	if (name)
+		ename = escape_word(name);
 
-	if (ename && eclass) {
-		int len = strlen(ename) + strlen(eclass) + 4;
-		ret = wmalloc(len);
-		snprintf(ret, len, "%s.%s", ename, eclass);
-		wfree(ename);
-		wfree(eclass);
-	} else if (ename) {
-		ret = wstrdup(ename);
+	if (class)
+		eclass = escape_word(class);
+
+	if (ename || eclass)
+		ret = StrConcatDot(ename, eclass, False);
+
+	if (ename)
 		wfree(ename);
-	} else {
-		ret = wstrdup(eclass);
+
+	if (eclass)
 		wfree(eclass);
-	}
 
 	return ret;
 }
-- 
1.7.9.1

Reply via email to