mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 12:28:22 +01:00
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 <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
a3b6b62049
commit
be022d9623
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
18
src/wmspec.c
18
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user