mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 12:28:22 +01:00
Changed formula for getting the number of elements in a static array
When using the formula [sizeof(array) / sizeof( x )] to get the number of element in a static array, it is better to use array[0] for 'x' instead of the base type of array: - in case the base type would change someday; - if the compiler were deciding to insert padding somewhere
This commit is contained in:
committed by
Carlos R. Mafra
parent
e17a197bc4
commit
7f6699ffca
@@ -428,7 +428,7 @@ static void addSizeToTypeface(Typeface * face, int size)
|
|||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
for (j = 0; j < sizeof(scalableFontSizes) / sizeof(int); j++) {
|
for (j = 0; j < sizeof(scalableFontSizes) / sizeof(scalableFontSizes[0]); j++) {
|
||||||
size = scalableFontSizes[j];
|
size = scalableFontSizes[j];
|
||||||
|
|
||||||
if (!WMCountInArray(face->sizes, (void *)(uintptr_t) size)) {
|
if (!WMCountInArray(face->sizes, (void *)(uintptr_t) size)) {
|
||||||
|
|||||||
@@ -552,7 +552,7 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
|
|||||||
"_NET_WM_ICON_NAME",
|
"_NET_WM_ICON_NAME",
|
||||||
"_NET_WM_ICON",
|
"_NET_WM_ICON",
|
||||||
};
|
};
|
||||||
Atom atoms[sizeof(atomNames) / sizeof(char *)];
|
Atom atoms[sizeof(atomNames) / sizeof(atomNames[0])];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
@@ -803,9 +803,9 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_XINTERNATOMS
|
#ifdef HAVE_XINTERNATOMS
|
||||||
XInternAtoms(display, atomNames, sizeof(atomNames) / sizeof(char *), False, atoms);
|
XInternAtoms(display, atomNames, sizeof(atomNames) / sizeof(atomNames[0]), False, atoms);
|
||||||
#else
|
#else
|
||||||
for (i = 0; i < sizeof(atomNames) / sizeof(char *); i++) {
|
for (i = 0; i < sizeof(atomNames) / sizeof(atomNames[0]); i++) {
|
||||||
atoms[i] = XInternAtom(display, atomNames[i], False);
|
atoms[i] = XInternAtom(display, atomNames[i], False);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1102,7 +1102,7 @@ static void previewClick(XEvent * event, void *clientData)
|
|||||||
|
|
||||||
switch (panel->oldTabItem) {
|
switch (panel->oldTabItem) {
|
||||||
case 0:
|
case 0:
|
||||||
for (i = 0; i < sizeof(previewPositions) / sizeof(WMRect); i++) {
|
for (i = 0; i < sizeof(previewPositions) / sizeof(previewPositions[0]); i++) {
|
||||||
if (event->xbutton.x >= previewPositions[i].pos.x
|
if (event->xbutton.x >= previewPositions[i].pos.x
|
||||||
&& event->xbutton.y >= previewPositions[i].pos.y
|
&& event->xbutton.y >= previewPositions[i].pos.y
|
||||||
&& event->xbutton.x < previewPositions[i].pos.x
|
&& event->xbutton.x < previewPositions[i].pos.x
|
||||||
|
|||||||
@@ -608,13 +608,13 @@ static void createPanel(Panel * p)
|
|||||||
WMResizeWidget(panel->wheelP, 135, 20);
|
WMResizeWidget(panel->wheelP, 135, 20);
|
||||||
WMMoveWidget(panel->wheelP, 95, 129);
|
WMMoveWidget(panel->wheelP, 95, 129);
|
||||||
|
|
||||||
for (i = 0; i < sizeof(buttonActions) / sizeof(char *); i++) {
|
for (i = 0; i < sizeof(buttonActions) / sizeof(buttonActions[0]); i++) {
|
||||||
WMAddPopUpButtonItem(panel->button1P, buttonActions[i]);
|
WMAddPopUpButtonItem(panel->button1P, buttonActions[i]);
|
||||||
WMAddPopUpButtonItem(panel->button2P, buttonActions[i]);
|
WMAddPopUpButtonItem(panel->button2P, buttonActions[i]);
|
||||||
WMAddPopUpButtonItem(panel->button3P, buttonActions[i]);
|
WMAddPopUpButtonItem(panel->button3P, buttonActions[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < sizeof(wheelActions) / sizeof(char *); i++) {
|
for (i = 0; i < sizeof(wheelActions) / sizeof(wheelActions[0]); i++) {
|
||||||
WMAddPopUpButtonItem(panel->wheelP, wheelActions[i]);
|
WMAddPopUpButtonItem(panel->wheelP, wheelActions[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ static void showData(_Panel * panel)
|
|||||||
str = "center";
|
str = "center";
|
||||||
|
|
||||||
idx = 1; /* center */
|
idx = 1; /* center */
|
||||||
for (i = 0; i < sizeof(WSNamePositions) / sizeof(char *); i++) {
|
for (i = 0; i < sizeof(WSNamePositions) / sizeof(WSNamePositions[0]); i++) {
|
||||||
if (strcasecmp(WSNamePositions[i], str) == 0) {
|
if (strcasecmp(WSNamePositions[i], str) == 0) {
|
||||||
idx = i;
|
idx = i;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -760,7 +760,7 @@ static void initDefaults()
|
|||||||
|
|
||||||
WMPLSetCaseSensitive(False);
|
WMPLSetCaseSensitive(False);
|
||||||
|
|
||||||
for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
|
for (i = 0; i < sizeof(optionList) / sizeof(optionList[0]); i++) {
|
||||||
entry = &optionList[i];
|
entry = &optionList[i];
|
||||||
|
|
||||||
entry->plkey = WMCreatePLString(entry->key);
|
entry->plkey = WMCreatePLString(entry->key);
|
||||||
@@ -770,7 +770,7 @@ static void initDefaults()
|
|||||||
entry->plvalue = NULL;
|
entry->plvalue = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
|
for (i = 0; i < sizeof(staticOptionList) / sizeof(staticOptionList[0]); i++) {
|
||||||
entry = &staticOptionList[i];
|
entry = &staticOptionList[i];
|
||||||
|
|
||||||
entry->plkey = WMCreatePLString(entry->key);
|
entry->plkey = WMCreatePLString(entry->key);
|
||||||
@@ -925,7 +925,7 @@ void wReadStaticDefaults(WMPropList * dict)
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
void *tdata;
|
void *tdata;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(staticOptionList) / sizeof(WDefaultEntry); i++) {
|
for (i = 0; i < sizeof(staticOptionList) / sizeof(staticOptionList[0]); i++) {
|
||||||
entry = &staticOptionList[i];
|
entry = &staticOptionList[i];
|
||||||
|
|
||||||
if (dict)
|
if (dict)
|
||||||
@@ -1079,7 +1079,7 @@ void wReadDefaults(WScreen * scr, WMPropList * new_dict)
|
|||||||
|
|
||||||
needs_refresh = 0;
|
needs_refresh = 0;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(optionList) / sizeof(WDefaultEntry); i++) {
|
for (i = 0; i < sizeof(optionList) / sizeof(optionList[0]); i++) {
|
||||||
entry = &optionList[i];
|
entry = &optionList[i];
|
||||||
|
|
||||||
if (new_dict)
|
if (new_dict)
|
||||||
|
|||||||
@@ -482,7 +482,7 @@ void StartUp(Bool defaultScreenOnly)
|
|||||||
#ifdef HAVE_XRANDR
|
#ifdef HAVE_XRANDR
|
||||||
int dummy;
|
int dummy;
|
||||||
#endif
|
#endif
|
||||||
Atom atom[sizeof(atomNames) / sizeof(char *)];
|
Atom atom[sizeof(atomNames) / sizeof(atomNames[0])];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ignore CapsLock in modifiers
|
* Ignore CapsLock in modifiers
|
||||||
@@ -505,12 +505,12 @@ void StartUp(Bool defaultScreenOnly)
|
|||||||
/* _XA_VERSION = XInternAtom(dpy, "VERSION", False); */
|
/* _XA_VERSION = XInternAtom(dpy, "VERSION", False); */
|
||||||
|
|
||||||
#ifdef HAVE_XINTERNATOMS
|
#ifdef HAVE_XINTERNATOMS
|
||||||
XInternAtoms(dpy, atomNames, sizeof(atomNames) / sizeof(char *), False, atom);
|
XInternAtoms(dpy, atomNames, sizeof(atomNames) / sizeof(atomNames[0]), False, atom);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < sizeof(atomNames) / sizeof(char *); i++)
|
for (i = 0; i < sizeof(atomNames) / sizeof(atomNames[0]); i++)
|
||||||
atom[i] = XInternAtom(dpy, atomNames[i], False);
|
atom[i] = XInternAtom(dpy, atomNames[i], False);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ static atomitem_t atomNames[] = {
|
|||||||
{"UTF8_STRING", &utf8_string},
|
{"UTF8_STRING", &utf8_string},
|
||||||
};
|
};
|
||||||
|
|
||||||
#define atomNr (sizeof(atomNames)/sizeof(atomitem_t))
|
#define atomNr (sizeof(atomNames)/sizeof(atomNames[0]))
|
||||||
|
|
||||||
#define _NET_WM_STATE_REMOVE 0
|
#define _NET_WM_STATE_REMOVE 0
|
||||||
#define _NET_WM_STATE_ADD 1
|
#define _NET_WM_STATE_ADD 1
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ void FormatXError(Display * dpy, XErrorEvent * error, char *buffer, int size)
|
|||||||
if (i > size - 100)
|
if (i > size - 100)
|
||||||
return;
|
return;
|
||||||
buffer += i;
|
buffer += i;
|
||||||
if (error->request_code >= sizeof(requestCodes) / sizeof(char *)) {
|
if (error->request_code >= sizeof(requestCodes) / sizeof(requestCodes[0])) {
|
||||||
sprintf(buffer, "\n Request code: %i\n", error->request_code);
|
sprintf(buffer, "\n Request code: %i\n", error->request_code);
|
||||||
} else {
|
} else {
|
||||||
sprintf(buffer, "\n Request code: %i %s\n", error->request_code,
|
sprintf(buffer, "\n Request code: %i %s\n", error->request_code,
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ static char *mapWeightToName(str * weight)
|
|||||||
if (weight->len == 0)
|
if (weight->len == 0)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
for (i = 0; i < sizeof(normalNames) / sizeof(char *); i++) {
|
for (i = 0; i < sizeof(normalNames) / sizeof(normalNames[0]); i++) {
|
||||||
if (strlen(normalNames[i]) == weight->len && strncmp(normalNames[i], weight->str, weight->len)) {
|
if (strlen(normalNames[i]) == weight->len && strncmp(normalNames[i], weight->str, weight->len)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user