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

WPrefs: replaced NULL terminated lists by 'wlengthof' usages

When a list has a fixed size, it is better to use the size of the list
instead of an end-of-list mark because it avoid unnecessary memory usage
and ease compiler's optimisation task.

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2014-07-04 23:28:43 +02:00
committed by Carlos R. Mafra
parent 0d66ba5735
commit 2c9e500b88

View File

@@ -95,16 +95,15 @@ static const struct {
const char *option; const char *option;
const char *label; const char *label;
} fontOptions[] = { } fontOptions[] = {
{ { "WindowTitleFont", N_("Window Title") },
"WindowTitleFont", N_("Window Title")}, { { "MenuTitleFont", N_("Menu Title") },
"MenuTitleFont", N_("Menu Title")}, { { "MenuTextFont", N_("Menu Text") },
"MenuTextFont", N_("Menu Text")}, { { "IconTitleFont", N_("Icon Title") },
"IconTitleFont", N_("Icon Title")}, { { "ClipTitleFont", N_("Clip Title") },
"ClipTitleFont", N_("Clip Title")}, { { "LargeDisplayFont", N_("Desktop Caption") },
"LargeDisplayFont", N_("Desktop Caption")}, { { "SystemFont", N_("System Font") },
"SystemFont", N_("System Font")}, { { "BoldSystemFont", N_("Bold System Font")}
"BoldSystemFont", N_("Bold System Font")}, { };
NULL, NULL},};
static const char *standardSizes[] = { static const char *standardSizes[] = {
"6", "6",
@@ -134,48 +133,39 @@ static const struct {
int weight; int weight;
const char *name; const char *name;
} fontWeights[] = { } fontWeights[] = {
{ { FC_WEIGHT_THIN, "Thin" },
FC_WEIGHT_THIN, "Thin"}, { { FC_WEIGHT_EXTRALIGHT, "ExtraLight" },
FC_WEIGHT_EXTRALIGHT, "ExtraLight"}, { { FC_WEIGHT_LIGHT, "Light" },
FC_WEIGHT_LIGHT, "Light"}, { { FC_WEIGHT_NORMAL, "Normal" },
FC_WEIGHT_NORMAL, "Normal"}, { { FC_WEIGHT_MEDIUM, "" },
FC_WEIGHT_MEDIUM, ""}, /*"medium"}, */ { FC_WEIGHT_DEMIBOLD, "DemiBold" },
{ { FC_WEIGHT_BOLD, "Bold" },
FC_WEIGHT_DEMIBOLD, "DemiBold"}, { { FC_WEIGHT_EXTRABOLD, "ExtraBold" },
FC_WEIGHT_BOLD, "Bold"}, { { FC_WEIGHT_BLACK, "Black" }
FC_WEIGHT_EXTRABOLD, "ExtraBold"}, {
FC_WEIGHT_BLACK, "Black"}, {
0, NULL}
}; };
static const struct { static const struct {
int slant; int slant;
const char *name; const char *name;
} fontSlants[] = { } fontSlants[] = {
{ { FC_SLANT_ROMAN, "" },
FC_SLANT_ROMAN, ""}, /*"Roman"}, */ { FC_SLANT_ITALIC, "Italic" },
{ { FC_SLANT_OBLIQUE, "Oblique" }
FC_SLANT_ITALIC, "Italic"}, {
FC_SLANT_OBLIQUE, "Oblique"}, {
0, NULL}
}; };
static const struct { static const struct {
int width; int width;
const char *name; const char *name;
} fontWidths[] = { } fontWidths[] = {
{ { FC_WIDTH_ULTRACONDENSED, "UltraCondensed" },
FC_WIDTH_ULTRACONDENSED, "UltraCondensed"}, { { FC_WIDTH_EXTRACONDENSED, "ExtraCondensed" },
FC_WIDTH_EXTRACONDENSED, "ExtraCondensed"}, { { FC_WIDTH_CONDENSED, "Condensed" },
FC_WIDTH_CONDENSED, "Condensed"}, { { FC_WIDTH_SEMICONDENSED, "SemiCondensed" },
FC_WIDTH_SEMICONDENSED, "SemiCondensed"}, { { FC_WIDTH_NORMAL, "" },
FC_WIDTH_NORMAL, ""}, /*"normal"}, */ { FC_WIDTH_SEMIEXPANDED, "SemiExpanded" },
{ { FC_WIDTH_EXPANDED, "Expanded" },
FC_WIDTH_SEMIEXPANDED, "SemiExpanded"}, { { FC_WIDTH_EXTRAEXPANDED, "ExtraExpanded" },
FC_WIDTH_EXPANDED, "Expanded"}, { { FC_WIDTH_ULTRAEXPANDED, "UltraExpanded" },
FC_WIDTH_EXTRAEXPANDED, "ExtraExpanded"}, {
FC_WIDTH_ULTRAEXPANDED, "UltraExpanded"}, {
0, NULL}
}; };
static int compare_family(const void *a, const void *b) static int compare_family(const void *a, const void *b)
@@ -376,17 +366,17 @@ static void selectedFamily(WMWidget * w, void *data)
const char *weight = "", *slant = "", *width = ""; const char *weight = "", *slant = "", *width = "";
WMListItem *item; WMListItem *item;
for (j = 0; fontWeights[j].name; j++) for (j = 0; j < wlengthof(fontWeights); j++)
if (fontWeights[j].weight == family->styles[i].weight) { if (fontWeights[j].weight == family->styles[i].weight) {
weight = fontWeights[j].name; weight = fontWeights[j].name;
break; break;
} }
for (j = 0; fontWidths[j].name; j++) for (j = 0; j < wlengthof(fontWidths); j++)
if (fontWidths[j].width == family->styles[i].width) { if (fontWidths[j].width == family->styles[i].width) {
width = fontWidths[j].name; width = fontWidths[j].name;
break; break;
} }
for (j = 0; fontSlants[j].name; j++) for (j = 0; j < wlengthof(fontSlants); j++)
if (fontSlants[j].slant == family->styles[i].slant) { if (fontSlants[j].slant == family->styles[i].slant) {
slant = fontSlants[j].name; slant = fontSlants[j].name;
break; break;
@@ -666,9 +656,8 @@ static void createPanel(Panel * p)
WMSetBoxHorizontal(vbox, False); WMSetBoxHorizontal(vbox, False);
panel->optionP = WMCreatePopUpButton(vbox); panel->optionP = WMCreatePopUpButton(vbox);
WMAddBoxSubviewAtEnd(vbox, WMWidgetView(panel->optionP), False, True, 20, 0, 8); WMAddBoxSubviewAtEnd(vbox, WMWidgetView(panel->optionP), False, True, 20, 0, 8);
for (i = 0; fontOptions[i].option; i++) { for (i = 0; i < wlengthof(fontOptions); i++)
WMAddPopUpButtonItem(panel->optionP, _(fontOptions[i].label)); WMAddPopUpButtonItem(panel->optionP, _(fontOptions[i].label));
}
WMSetPopUpButtonAction(panel->optionP, selectedOption, panel); WMSetPopUpButtonAction(panel->optionP, selectedOption, panel);
label = WMCreateLabel(hbox); label = WMCreateLabel(hbox);