1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-21 21:38:00 +01:00

wmaker: took as much assignation as possible outside 'if' statements

It is generally considered bad practice to place an assignation inside the
expression for an "if" statement because it is often a source of bug,
because of possible typos and because it makes reviewing code more
complicated.

This patch fixes as much cases as possible to make the code easier to read.

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2015-05-08 13:19:04 +02:00
committed by Carlos R. Mafra
parent e14fad1162
commit 1c1909d5fe
12 changed files with 88 additions and 47 deletions

View File

@@ -139,7 +139,8 @@ static WMenu *parseMenuCommand(WScreen * scr, Window win, char **slist, int coun
} }
wstrlcpy(title, &slist[*index][pos], sizeof(title)); wstrlcpy(title, &slist[*index][pos], sizeof(title));
} }
if (!(data = malloc(sizeof(WAppMenuData)))) { data = malloc(sizeof(WAppMenuData));
if (data == NULL) {
wwarning(_("appmenu: out of memory creating menu for window %lx"), win); wwarning(_("appmenu: out of memory creating menu for window %lx"), win);
wMenuDestroy(menu, True); wMenuDestroy(menu, True);
return NULL; return NULL;

View File

@@ -262,7 +262,8 @@ ScanFiles(const char *dir, const char *prefix, unsigned acceptmask, unsigned dec
char *fullfilename, *suffix; char *fullfilename, *suffix;
prefixlen = strlen(prefix); prefixlen = strlen(prefix);
if ((d = opendir(dir)) != NULL) { d = opendir(dir);
if (d != NULL) {
while ((de = readdir(d)) != NULL) { while ((de = readdir(d)) != NULL) {
if (strlen(de->d_name) > prefixlen && if (strlen(de->d_name) > prefixlen &&
!strncmp(prefix, de->d_name, prefixlen) && !strncmp(prefix, de->d_name, prefixlen) &&
@@ -298,12 +299,14 @@ static WMArray *GenerateVariants(const char *complete)
while (*complete == ' ') while (*complete == ' ')
++complete; ++complete;
if ((pos = strrchr(complete, ' ')) != NULL) { pos = strrchr(complete, ' ');
if (pos != NULL) {
complete = pos + 1; complete = pos + 1;
firstWord = False; firstWord = False;
} }
if ((pos = strrchr(complete, '/')) != NULL) { pos = strrchr(complete, '/');
if (pos != NULL) {
tmp = wstrndup((char *)complete, pos - complete + 1); tmp = wstrndup((char *)complete, pos - complete + 1);
if (*tmp == '~' && *(tmp + 1) == '/' && getenv("HOME")) { if (*tmp == '~' && *(tmp + 1) == '/' && getenv("HOME")) {
dir = wstrdup(getenv("HOME")); dir = wstrdup(getenv("HOME"));

View File

@@ -1530,7 +1530,8 @@ static WMPropList *dockSaveState(WDock *dock)
if (!btn || btn->attracted) if (!btn || btn->attracted)
continue; continue;
if ((icon_info = make_icon_state(dock->icon_array[i]))) { icon_info = make_icon_state(dock->icon_array[i]);
if (icon_info != NULL) {
WMAddToPLArray(list, icon_info); WMAddToPLArray(list, icon_info);
WMReleasePropList(icon_info); WMReleasePropList(icon_info);
} }
@@ -2042,7 +2043,9 @@ static WDock *findDock(WScreen *scr, XEvent *event, int *icon_pos)
int i; int i;
*icon_pos = -1; *icon_pos = -1;
if ((dock = scr->dock) != NULL) {
dock = scr->dock;
if (dock != NULL) {
for (i = 0; i < dock->max_icons; i++) { for (i = 0; i < dock->max_icons; i++) {
if (dock->icon_array[i] if (dock->icon_array[i]
&& dock->icon_array[i]->icon->core->window == event->xclient.window) { && dock->icon_array[i]->icon->core->window == event->xclient.window) {
@@ -2669,7 +2672,8 @@ Bool wDockSnapIcon(WDock *dock, WAppIcon *icon, int req_x, int req_y, int *ret_x
* it wants to be (ex_x) and slide them. */ * it wants to be (ex_x) and slide them. */
j = 0; j = 0;
for (i = 1; i < dock->max_icons; i++) { for (i = 1; i < dock->max_icons; i++) {
if ((aicon = dock->icon_array[ i ]) && aicon != icon && aicon = dock->icon_array[i];
if ((aicon != NULL) && (aicon != icon) &&
((ex_x <= aicon->xindex && aicon->xindex < index_of_hole) || ((ex_x <= aicon->xindex && aicon->xindex < index_of_hole) ||
(index_of_hole < aicon->xindex && aicon->xindex <= ex_x))) (index_of_hole < aicon->xindex && aicon->xindex <= ex_x)))
aicons_to_shift[ j++ ] = aicon; aicons_to_shift[ j++ ] = aicon;
@@ -3048,7 +3052,8 @@ static pid_t execCommand(WAppIcon *btn, const char *command, WSavedState *state)
return 0; return 0;
} }
if ((pid = fork()) == 0) { pid = fork();
if (pid == 0) {
char **args; char **args;
int i; int i;
@@ -3752,7 +3757,9 @@ static void handleDockMove(WDock *dock, WAppIcon *aicon, XEvent *event)
{ {
for (i = 0; i < dock->max_icons; i++) { for (i = 0; i < dock->max_icons; i++) {
int new_y, new_index, j, ok; int new_y, new_index, j, ok;
if ((tmpaicon = dock->icon_array[i]) == NULL)
tmpaicon = dock->icon_array[i];
if (tmpaicon == NULL)
continue; continue;
if (onScreen(scr, tmpaicon->x_pos, tmpaicon->y_pos)) if (onScreen(scr, tmpaicon->x_pos, tmpaicon->y_pos))
continue; continue;
@@ -3830,7 +3837,8 @@ static void handleDockMove(WDock *dock, WAppIcon *aicon, XEvent *event)
Window *wins[dock->icon_count]; Window *wins[dock->icon_count];
for (i = 0; i < dock->max_icons; i++) { for (i = 0; i < dock->max_icons; i++) {
if ((tmpaicon = dock->icon_array[i]) == NULL) tmpaicon = dock->icon_array[i];
if (tmpaicon == NULL)
continue; continue;
wins[ tmpaicon->xindex + (dock->on_right_side ? dock->icon_count - 1 : 0) ] = &tmpaicon->icon->core->window; wins[ tmpaicon->xindex + (dock->on_right_side ? dock->icon_count - 1 : 0) ] = &tmpaicon->icon->core->window;
} }
@@ -4420,7 +4428,8 @@ static void drawerDestroy(WDock *drawer)
if (drawer->icon_count == 2) { if (drawer->icon_count == 2) {
/* Drawer contains a single appicon: dock it where the drawer was */ /* Drawer contains a single appicon: dock it where the drawer was */
for (i = 1; i < drawer->max_icons; i++) { for (i = 1; i < drawer->max_icons; i++) {
if ((aicon = drawer->icon_array[i])) aicon = drawer->icon_array[i];
if (aicon != NULL)
break; break;
} }
@@ -4431,7 +4440,8 @@ static void drawerDestroy(WDock *drawer)
} else if (drawer->icon_count > 2) { } else if (drawer->icon_count > 2) {
icons = WMCreateArray(drawer->icon_count - 1); icons = WMCreateArray(drawer->icon_count - 1);
for (i = 1; i < drawer->max_icons; i++) { for (i = 1; i < drawer->max_icons; i++) {
if (!(aicon = drawer->icon_array[i])) aicon = drawer->icon_array[i];
if (aicon == NULL)
continue; continue;
WMAddToArray(icons, aicon); WMAddToArray(icons, aicon);
} }
@@ -4559,7 +4569,9 @@ static void swapDrawer(WDock *drawer, int new_x)
for (i = 0; i < drawer->max_icons; i++) { for (i = 0; i < drawer->max_icons; i++) {
WAppIcon *ai; WAppIcon *ai;
if ((ai = drawer->icon_array[i]) == NULL)
ai = drawer->icon_array[i];
if (ai == NULL)
continue; continue;
ai->xindex *= -1; /* so A B C becomes C B A */ ai->xindex *= -1; /* so A B C becomes C B A */
ai->x_pos = new_x + ai->xindex * ICON_SIZE; ai->x_pos = new_x + ai->xindex * ICON_SIZE;

View File

@@ -582,7 +582,8 @@ static void handleMapRequest(XEvent * ev)
WScreen *scr = NULL; WScreen *scr = NULL;
Window window = ev->xmaprequest.window; Window window = ev->xmaprequest.window;
if ((wwin = wWindowFor(window))) { wwin = wWindowFor(window);
if (wwin != NULL) {
if (wwin->flags.shaded) { if (wwin->flags.shaded) {
wUnshadeWindow(wwin); wUnshadeWindow(wwin);
} }
@@ -931,7 +932,8 @@ static void handleConfigureRequest(XEvent * event)
{ {
WWindow *wwin; WWindow *wwin;
if (!(wwin = wWindowFor(event->xconfigurerequest.window))) { wwin = wWindowFor(event->xconfigurerequest.window);
if (wwin == NULL) {
/* /*
* Configure request for unmapped window * Configure request for unmapped window
*/ */

View File

@@ -103,7 +103,8 @@ int MonitorLoop(int argc, char **argv)
} }
do { do {
if ((exited = waitpid(-1, &status, 0)) < 0) { exited = waitpid(-1, &status, 0);
if (exited < 0) {
werror(_("Error during monitoring of Window Maker process.")); werror(_("Error during monitoring of Window Maker process."));
error = True; error = True;
break; break;

View File

@@ -102,17 +102,20 @@ Bool GetCommandForPid(int pid, char ***argv, int *argc)
#if defined( OPENBSD ) #if defined( OPENBSD )
/* kvm descriptor */ /* kvm descriptor */
if ((kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, kvmerr)) == NULL) kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, kvmerr);
if (kd == NULL)
return False; return False;
procs = 0; procs = 0;
/* the process we are interested in */ /* the process we are interested in */
if ((kp = kvm_getprocs(kd, KERN_PROC_PID, pid, sizeof(*kp), &procs)) == NULL || procs == 0) kp = kvm_getprocs(kd, KERN_PROC_PID, pid, sizeof(*kp), &procs);
if (kp == NULL || procs == 0)
/* if kvm_getprocs() bombs out or does not find the process */ /* if kvm_getprocs() bombs out or does not find the process */
return False; return False;
/* get its argv */ /* get its argv */
if ((nargv = kvm_getargv(kd, kp, 0)) == NULL) nargv = kvm_getargv(kd, kp, 0);
if (nargv == NULL)
return False; return False;
/* flatten nargv into args */ /* flatten nargv into args */

View File

@@ -38,7 +38,8 @@ Bool GetCommandForPid(int pid, char ***argv, int *argc)
while (1) { while (1) {
/* not switching this to stdio yet, as this does not need /* not switching this to stdio yet, as this does not need
* to be portable, and i'm lazy */ * to be portable, and i'm lazy */
if ((fd = open(buf, O_RDONLY)) != -1) fd = open(buf, O_RDONLY);
if (fd != -1)
break; break;
if (errno == EINTR) if (errno == EINTR)
continue; continue;
@@ -46,7 +47,8 @@ Bool GetCommandForPid(int pid, char ***argv, int *argc)
} }
while (1) { while (1) {
if ((count = read(fd, buf, sizeof(buf))) != -1) count = read(fd, buf, sizeof(buf));
if (count != -1)
break; break;
if (errno == EINTR) if (errno == EINTR)
continue; continue;

View File

@@ -841,16 +841,16 @@ void wScreenSaveState(WScreen * scr)
if (!wPreferences.flags.nodock) { if (!wPreferences.flags.nodock) {
wDockSaveState(scr, old_state); wDockSaveState(scr, old_state);
} else { } else {
if ((foo = WMGetFromPLDictionary(old_state, dDock)) != NULL) { foo = WMGetFromPLDictionary(old_state, dDock);
if (foo != NULL)
WMPutInPLDictionary(scr->session_state, dDock, foo); WMPutInPLDictionary(scr->session_state, dDock, foo);
}
} }
if (!wPreferences.flags.noclip) { if (!wPreferences.flags.noclip) {
wClipSaveState(scr); wClipSaveState(scr);
} else { } else {
if ((foo = WMGetFromPLDictionary(old_state, dClip)) != NULL) { foo = WMGetFromPLDictionary(old_state, dClip);
if (foo != NULL)
WMPutInPLDictionary(scr->session_state, dClip, foo); WMPutInPLDictionary(scr->session_state, dClip, foo);
}
} }
wWorkspaceSaveState(scr, old_state); wWorkspaceSaveState(scr, old_state);
@@ -858,21 +858,22 @@ void wScreenSaveState(WScreen * scr)
if (!wPreferences.flags.nodrawer) { if (!wPreferences.flags.nodrawer) {
wDrawersSaveState(scr); wDrawersSaveState(scr);
} else { } else {
if ((foo = WMGetFromPLDictionary(old_state, dDrawers)) != NULL) { foo = WMGetFromPLDictionary(old_state, dDrawers);
if (foo != NULL)
WMPutInPLDictionary(scr->session_state, dDrawers, foo); WMPutInPLDictionary(scr->session_state, dDrawers, foo);
}
} }
if (wPreferences.save_session_on_exit) { if (wPreferences.save_session_on_exit) {
wSessionSaveState(scr); wSessionSaveState(scr);
} else { } else {
if ((foo = WMGetFromPLDictionary(old_state, dApplications)) != NULL) { foo = WMGetFromPLDictionary(old_state, dApplications);
if (foo != NULL)
WMPutInPLDictionary(scr->session_state, dApplications, foo); WMPutInPLDictionary(scr->session_state, dApplications, foo);
}
if ((foo = WMGetFromPLDictionary(old_state, dWorkspace)) != NULL) { foo = WMGetFromPLDictionary(old_state, dWorkspace);
if (foo != NULL)
WMPutInPLDictionary(scr->session_state, dWorkspace, foo); WMPutInPLDictionary(scr->session_state, dWorkspace, foo);
}
} }
/* clean up */ /* clean up */

View File

@@ -128,9 +128,9 @@ static int getBool(WMPropList * value)
if (!WMIsPLString(value)) { if (!WMIsPLString(value)) {
return 0; return 0;
} }
if (!(val = WMGetFromPLString(value))) { val = WMGetFromPLString(value);
if (val == NULL)
return 0; return 0;
}
if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y')) if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y'))
|| strcasecmp(val, "YES") == 0) { || strcasecmp(val, "YES") == 0) {
@@ -299,7 +299,8 @@ void wSessionSaveState(WScreen * scr)
|| WFLAGP(wwin, shared_appicon)) || WFLAGP(wwin, shared_appicon))
&& !WFLAGP(wwin, dont_save_session)) { && !WFLAGP(wwin, dont_save_session)) {
/* A entry for this application was not yet saved. Save one. */ /* A entry for this application was not yet saved. Save one. */
if ((win_info = makeWindowState(wwin, wapp)) != NULL) { win_info = makeWindowState(wwin, wapp);
if (win_info != NULL) {
WMAddToPLArray(list, win_info); WMAddToPLArray(list, win_info);
WMReleasePropList(win_info); WMReleasePropList(win_info);
/* If we were succesful in saving the info for this window /* If we were succesful in saving the info for this window
@@ -346,7 +347,8 @@ static pid_t execCommand(WScreen *scr, char *command)
return 0; return 0;
} }
if ((pid = fork()) == 0) { pid = fork();
if (pid == 0) {
char **args; char **args;
int i; int i;
@@ -392,13 +394,21 @@ static WSavedState *getWindowState(WScreen * scr, WMPropList * win_state)
state->workspace--; state->workspace--;
} }
} }
if ((value = WMGetFromPLDictionary(win_state, sShaded)) != NULL)
value = WMGetFromPLDictionary(win_state, sShaded);
if (value != NULL)
state->shaded = getBool(value); state->shaded = getBool(value);
if ((value = WMGetFromPLDictionary(win_state, sMiniaturized)) != NULL)
value = WMGetFromPLDictionary(win_state, sMiniaturized);
if (value != NULL)
state->miniaturized = getBool(value); state->miniaturized = getBool(value);
if ((value = WMGetFromPLDictionary(win_state, sHidden)) != NULL)
value = WMGetFromPLDictionary(win_state, sHidden);
if (value != NULL)
state->hidden = getBool(value); state->hidden = getBool(value);
if ((value = WMGetFromPLDictionary(win_state, sShortcutMask)) != NULL) {
value = WMGetFromPLDictionary(win_state, sShortcutMask);
if (value != NULL) {
mask = getInt(value); mask = getInt(value);
state->window_shortcuts = mask; state->window_shortcuts = mask;
} }

View File

@@ -568,14 +568,16 @@ void wDefaultChangeIcon(const char *instance, const char *class, const char *fil
icon_value = WMCreatePLDictionary(AIcon, value, NULL); icon_value = WMCreatePLDictionary(AIcon, value, NULL);
WMReleasePropList(value); WMReleasePropList(value);
if ((def_win = WMGetFromPLDictionary(dict, AnyWindow)) != NULL) def_win = WMGetFromPLDictionary(dict, AnyWindow);
if (def_win != NULL)
def_icon = WMGetFromPLDictionary(def_win, AIcon); def_icon = WMGetFromPLDictionary(def_win, AIcon);
if (def_icon && !strcmp(WMGetFromPLString(def_icon), file)) if (def_icon && !strcmp(WMGetFromPLString(def_icon), file))
same = 1; same = 1;
} }
if ((attr = WMGetFromPLDictionary(dict, key)) != NULL) { attr = WMGetFromPLDictionary(dict, key);
if (attr != NULL) {
if (WMIsPLDictionary(attr)) { if (WMIsPLDictionary(attr)) {
if (icon_value != NULL && !same) if (icon_value != NULL && !same)
WMMergePLDictionaries(attr, icon_value, False); WMMergePLDictionaries(attr, icon_value, False);

View File

@@ -376,7 +376,8 @@ static int getBool(WMPropList *value)
if (!WMIsPLString(value)) if (!WMIsPLString(value))
return 0; return 0;
if (!(val = WMGetFromPLString(value))) val = WMGetFromPLString(value);
if (val == NULL)
return 0; return 0;
if ((val[1] == '\0' && if ((val[1] == '\0' &&
@@ -407,7 +408,8 @@ insertAttribute(WMPropList *dict, WMPropList *window, WMPropList *attr, WMPropLi
int update = 0, modified = 0; int update = 0, modified = 0;
if (!(flags & UPDATE_DEFAULTS) && dict) { if (!(flags & UPDATE_DEFAULTS) && dict) {
if ((def_win = WMGetFromPLDictionary(dict, AnyWindow)) != NULL) def_win = WMGetFromPLDictionary(dict, AnyWindow);
if (def_win != NULL)
def_value = WMGetFromPLDictionary(def_win, attr); def_value = WMGetFromPLDictionary(def_win, attr);
} }

View File

@@ -492,7 +492,8 @@ void wWorkspaceForceChange(WScreen * scr, int workspace)
wWorkspaceMenuUpdate(scr, scr->clip_ws_menu); wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
if ((tmp = scr->focused_window) != NULL) { tmp = scr->focused_window;
if (tmp != NULL) {
WWindow **toUnmap; WWindow **toUnmap;
int toUnmapSize, toUnmapCount; int toUnmapSize, toUnmapCount;
@@ -856,10 +857,11 @@ void wWorkspaceSaveState(WScreen * scr, WMPropList * old_state)
WMPutInPLDictionary(wks_state, dClip, pstr); WMPutInPLDictionary(wks_state, dClip, pstr);
WMReleasePropList(pstr); WMReleasePropList(pstr);
} else if (old_wks_state != NULL) { } else if (old_wks_state != NULL) {
if ((foo = WMGetFromPLArray(old_wks_state, i)) != NULL) { foo = WMGetFromPLArray(old_wks_state, i);
if ((bar = WMGetFromPLDictionary(foo, dClip)) != NULL) { if (foo != NULL) {
bar = WMGetFromPLDictionary(foo, dClip);
if (bar != NULL)
WMPutInPLDictionary(wks_state, dClip, bar); WMPutInPLDictionary(wks_state, dClip, bar);
}
} }
} }
WMAddToPLArray(parr, wks_state); WMAddToPLArray(parr, wks_state);