The function getnameforicon() is splitted in two:
getnameforicon + get_cached_pixmap_folder
to do a better understanding and clean code.
---
src/icon.c | 52 +++++++++++++++++++++++++++-------------------------
1 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/src/icon.c b/src/icon.c
index e8382bb..98df353 100644
--- a/src/icon.c
+++ b/src/icon.c
@@ -398,30 +398,14 @@ Bool wIconChangeImageFile(WIcon * icon, char *file)
return !error;
}
-static char *getnameforicon(WWindow * wwin)
+/* This function returns the user folder for cached pixmaps */
+static char * get_cached_pixmap_folder(void)
{
- char *prefix, *suffix;
- char *path;
+ char *prefix, *path;
int len;
- if (wwin->wm_class && wwin->wm_instance) {
- int len = strlen(wwin->wm_class) + strlen(wwin->wm_instance) +
2;
- suffix = wmalloc(len);
- snprintf(suffix, len, "%s.%s", wwin->wm_instance,
wwin->wm_class);
- } else if (wwin->wm_class) {
- int len = strlen(wwin->wm_class) + 1;
- suffix = wmalloc(len);
- snprintf(suffix, len, "%s", wwin->wm_class);
- } else if (wwin->wm_instance) {
- int len = strlen(wwin->wm_instance) + 1;
- suffix = wmalloc(len);
- snprintf(suffix, len, "%s", wwin->wm_instance);
- } else {
- return NULL;
- }
-
prefix = wusergnusteppath();
- len = strlen(prefix) + 64 + strlen(suffix);
+ len = strlen(prefix) + 64;
path = wmalloc(len + 1);
snprintf(path, len, "%s/Library/WindowMaker", prefix);
@@ -429,23 +413,41 @@ static char *getnameforicon(WWindow * wwin)
if (mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR)) {
werror(_("could not create directory %s"), path);
wfree(path);
- wfree(suffix);
return NULL;
}
}
+
strcat(path, "/CachedPixmaps");
if (access(path, F_OK) != 0) {
if (mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
werror(_("could not create directory %s"), path);
wfree(path);
- wfree(suffix);
return NULL;
}
}
- strcat(path, "/");
- strcat(path, suffix);
- strcat(path, ".xpm");
+ return path;
+}
+
+static char *getnameforicon(WWindow * wwin)
+{
+ char *prefix, *suffix, *path;
+ int len;
+
+ if (!wwin->wm_class && !wwin->wm_instance)
+ return NULL;
+
+ prefix = get_cached_pixmap_folder();
+ if (!prefix)
+ return NULL;
+
+ suffix = StrConcatDot(wwin->wm_instance, wwin->wm_class, False);
+
+ len = strlen(prefix) + strlen(suffix) + 6;
+ path = wmalloc(len);
+ snprintf(path, len, "%s/%s.xpm", prefix, suffix);
+
+ wfree(prefix);
wfree(suffix);
return path;
--
1.7.9.1
>From 2558637a10965769daa1904ea22d521c7dacd719 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 13:54:22 +0200
Subject: [PATCH 15/16] WindowMaker: getnameforicon() function splitted
The function getnameforicon() is splitted in two:
getnameforicon + get_cached_pixmap_folder
to do a better understanding and clean code.
---
src/icon.c | 52 +++++++++++++++++++++++++++-------------------------
1 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/src/icon.c b/src/icon.c
index e8382bb..98df353 100644
--- a/src/icon.c
+++ b/src/icon.c
@@ -398,30 +398,14 @@ Bool wIconChangeImageFile(WIcon * icon, char *file)
return !error;
}
-static char *getnameforicon(WWindow * wwin)
+/* This function returns the user folder for cached pixmaps */
+static char * get_cached_pixmap_folder(void)
{
- char *prefix, *suffix;
- char *path;
+ char *prefix, *path;
int len;
- if (wwin->wm_class && wwin->wm_instance) {
- int len = strlen(wwin->wm_class) + strlen(wwin->wm_instance) + 2;
- suffix = wmalloc(len);
- snprintf(suffix, len, "%s.%s", wwin->wm_instance, wwin->wm_class);
- } else if (wwin->wm_class) {
- int len = strlen(wwin->wm_class) + 1;
- suffix = wmalloc(len);
- snprintf(suffix, len, "%s", wwin->wm_class);
- } else if (wwin->wm_instance) {
- int len = strlen(wwin->wm_instance) + 1;
- suffix = wmalloc(len);
- snprintf(suffix, len, "%s", wwin->wm_instance);
- } else {
- return NULL;
- }
-
prefix = wusergnusteppath();
- len = strlen(prefix) + 64 + strlen(suffix);
+ len = strlen(prefix) + 64;
path = wmalloc(len + 1);
snprintf(path, len, "%s/Library/WindowMaker", prefix);
@@ -429,23 +413,41 @@ static char *getnameforicon(WWindow * wwin)
if (mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR)) {
werror(_("could not create directory %s"), path);
wfree(path);
- wfree(suffix);
return NULL;
}
}
+
strcat(path, "/CachedPixmaps");
if (access(path, F_OK) != 0) {
if (mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
werror(_("could not create directory %s"), path);
wfree(path);
- wfree(suffix);
return NULL;
}
}
- strcat(path, "/");
- strcat(path, suffix);
- strcat(path, ".xpm");
+ return path;
+}
+
+static char *getnameforicon(WWindow * wwin)
+{
+ char *prefix, *suffix, *path;
+ int len;
+
+ if (!wwin->wm_class && !wwin->wm_instance)
+ return NULL;
+
+ prefix = get_cached_pixmap_folder();
+ if (!prefix)
+ return NULL;
+
+ suffix = StrConcatDot(wwin->wm_instance, wwin->wm_class, False);
+
+ len = strlen(prefix) + strlen(suffix) + 6;
+ path = wmalloc(len);
+ snprintf(path, len, "%s/%s.xpm", prefix, suffix);
+
+ wfree(prefix);
wfree(suffix);
return path;
--
1.7.9.1