From be022d9623d9efa25b7c276ac00ed7245eb089da Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Fri, 8 Nov 2013 21:18:21 +0100 Subject: [PATCH] wmaker: Use the macro 'wlengthof' to get the number of element in an array The new macro 'wlengthof' from WUtil makes code easier to read than the previous [sizeof() / sizeof([0]) ] construct. Signed-off-by: Christophe CURIS --- src/defaults.c | 8 ++++---- src/startup.c | 6 +++--- src/winspector.c | 12 ++++++------ src/wmspec.c | 18 ++++++++---------- src/xutil.c | 2 +- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/defaults.c b/src/defaults.c index e0f608ac..5bf82672 100644 --- a/src/defaults.c +++ b/src/defaults.c @@ -772,7 +772,7 @@ static void initDefaults(void) WMPLSetCaseSensitive(False); - for (i = 0; i < sizeof(optionList) / sizeof(optionList[0]); i++) { + for (i = 0; i < wlengthof(optionList); i++) { entry = &optionList[i]; entry->plkey = WMCreatePLString(entry->key); @@ -782,7 +782,7 @@ static void initDefaults(void) entry->plvalue = NULL; } - for (i = 0; i < sizeof(staticOptionList) / sizeof(staticOptionList[0]); i++) { + for (i = 0; i < wlengthof(staticOptionList); i++) { entry = &staticOptionList[i]; entry->plkey = WMCreatePLString(entry->key); @@ -937,7 +937,7 @@ void wReadStaticDefaults(WMPropList * dict) unsigned int i; void *tdata; - for (i = 0; i < sizeof(staticOptionList) / sizeof(staticOptionList[0]); i++) { + for (i = 0; i < wlengthof(staticOptionList); i++) { entry = &staticOptionList[i]; if (dict) @@ -1094,7 +1094,7 @@ void wReadDefaults(WScreen * scr, WMPropList * new_dict) needs_refresh = 0; - for (i = 0; i < sizeof(optionList) / sizeof(optionList[0]); i++) { + for (i = 0; i < wlengthof(optionList); i++) { entry = &optionList[i]; if (new_dict) diff --git a/src/startup.c b/src/startup.c index 8971789e..3bd9f99a 100644 --- a/src/startup.c +++ b/src/startup.c @@ -415,7 +415,7 @@ void StartUp(Bool defaultScreenOnly) #ifdef HAVE_XRANDR int dummy; #endif - Atom atom[sizeof(atomNames) / sizeof(atomNames[0])]; + Atom atom[wlengthof(atomNames)]; /* * Ignore CapsLock in modifiers @@ -437,12 +437,12 @@ void StartUp(Bool defaultScreenOnly) /* _XA_VERSION = XInternAtom(dpy, "VERSION", False); */ #ifdef HAVE_XINTERNATOMS - XInternAtoms(dpy, atomNames, sizeof(atomNames) / sizeof(atomNames[0]), False, atom); + XInternAtoms(dpy, atomNames, wlengthof(atomNames), False, atom); #else { int i; - for (i = 0; i < sizeof(atomNames) / sizeof(atomNames[0]); i++) + for (i = 0; i < wlengthof(atomNames); i++) atom[i] = XInternAtom(dpy, atomNames[i], False); } #endif diff --git a/src/winspector.c b/src/winspector.c index bd564155..8cb49df5 100644 --- a/src/winspector.c +++ b/src/winspector.c @@ -831,7 +831,7 @@ static void revertSettings(WMWidget *button, void *client_data) wWindowSetupInitialAttributes(wwin, &level, &workspace); - for (i = 0; i < (sizeof(panel->attrChk) / sizeof(panel->attrChk[0])); i++) { + for (i = 0; i < wlengthof(panel->attrChk); i++) { int flag = 0; switch (i) { @@ -872,7 +872,7 @@ static void revertSettings(WMWidget *button, void *client_data) WMSetButtonSelected(panel->attrChk[i], flag); } - for (i = 0; i < (sizeof(panel->moreChk) / sizeof(panel->moreChk[0])); i++) { + for (i = 0; i < wlengthof(panel->moreChk); i++) { int flag = 0; switch (i) { @@ -918,7 +918,7 @@ static void revertSettings(WMWidget *button, void *client_data) WMSetButtonSelected(panel->moreChk[i], flag); } if (panel->appFrm && wapp) { - for (i = 0; i < (sizeof(panel->appChk) / sizeof(panel->appChk[0])); i++) { + for (i = 0; i < wlengthof(panel->appChk); i++) { int flag = 0; switch (i) { @@ -1318,7 +1318,7 @@ static void create_tab_window_attributes(WWindow *wwin, InspectorPanel *panel, i WMMoveWidget(panel->attrFrm, 15, 45); WMResizeWidget(panel->attrFrm, frame_width, 250); - for (i = 0; i < (sizeof(panel->attrChk) / sizeof(panel->attrChk[0])); i++) { + for (i = 0; i < wlengthof(panel->attrChk); i++) { switch (i) { case 0: caption = _("Disable titlebar"); @@ -1402,7 +1402,7 @@ static void create_tab_window_advanced(WWindow *wwin, InspectorPanel *panel, int WMMoveWidget(panel->moreFrm, 15, 45); WMResizeWidget(panel->moreFrm, frame_width, 265); - for (i = 0; i < (sizeof(panel->moreChk) / sizeof(panel->moreChk[0])); i++) { + for (i = 0; i < wlengthof(panel->moreChk); i++) { switch (i) { case 0: caption = _("Do not bind keyboard shortcuts"); @@ -1565,7 +1565,7 @@ static void create_tab_app_specific(WWindow *wwin, InspectorPanel *panel, int fr WMMoveWidget(panel->appFrm, 15, 50); WMResizeWidget(panel->appFrm, frame_width, 240); - for (i = 0; i < (sizeof(panel->appChk) / sizeof(panel->appChk[0])); i++) { + for (i = 0; i < wlengthof(panel->appChk); i++) { switch (i) { case 0: caption = _("Start hidden"); diff --git a/src/wmspec.c b/src/wmspec.c index 58c7f9fd..d6851d79 100644 --- a/src/wmspec.c +++ b/src/wmspec.c @@ -198,8 +198,6 @@ static atomitem_t atomNames[] = { {"UTF8_STRING", &utf8_string}, }; -#define atomNr (sizeof(atomNames)/sizeof(atomNames[0])) - #define _NET_WM_STATE_REMOVE 0 #define _NET_WM_STATE_ADD 1 #define _NET_WM_STATE_TOGGLE 2 @@ -235,7 +233,7 @@ typedef struct NetData { static void setSupportedHints(WScreen *scr) { - Atom atom[atomNr]; + Atom atom[wlengthof(atomNames)]; int i = 0; /* set supported hints list */ @@ -534,19 +532,19 @@ void wNETWMInitStuff(WScreen *scr) #ifdef HAVE_XINTERNATOMS { - Atom atoms[atomNr]; - char *names[atomNr]; + Atom atoms[wlengthof(atomNames)]; + char *names[wlengthof(atomNames)]; - for (i = 0; i < atomNr; ++i) + for (i = 0; i < wlengthof(atomNames); ++i) names[i] = atomNames[i].name; - XInternAtoms(dpy, &names[0], atomNr, False, atoms); - for (i = 0; i < atomNr; ++i) + XInternAtoms(dpy, &names[0], wlengthof(atomNames), False, atoms); + for (i = 0; i < wlengthof(atomNames); ++i) *atomNames[i].atom = atoms[i]; } #else - for (i = 0; i < atomNr; i++) + for (i = 0; i < wlengthof(atomNames); i++) *atomNames[i].atom = XInternAtom(dpy, atomNames[i].name, False); #endif @@ -585,7 +583,7 @@ void wNETWMCleanup(WScreen *scr) { int i; - for (i = 0; i < atomNr; i++) + for (i = 0; i < wlengthof(atomNames); i++) XDeleteProperty(dpy, scr->root_win, *atomNames[i].atom); } diff --git a/src/xutil.c b/src/xutil.c index 3d1e83ed..dbac37d4 100644 --- a/src/xutil.c +++ b/src/xutil.c @@ -168,7 +168,7 @@ void FormatXError(Display * dpy, XErrorEvent * error, char *buffer, int size) if (i > size - 100) return; buffer += i; - if (error->request_code >= sizeof(requestCodes) / sizeof(requestCodes[0])) { + if (error->request_code >= wlengthof(requestCodes)) { sprintf(buffer, "\n Request code: %i\n", error->request_code); } else { sprintf(buffer, "\n Request code: %i %s\n", error->request_code,