From 358b60baf92906ea4b092f92a6052a4346dce815 Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Thu, 18 Mar 2021 06:17:47 +0100 Subject: [PATCH] Introduce E_ARRAY_SIZE() and MOD_ITEMS() Just a bit tidier. --- src/aclass.c | 3 +-- src/backgrounds.c | 8 +++----- src/buttons.c | 6 ++---- src/config.c | 7 +++---- src/container.c | 8 +++----- src/cursors.c | 6 ++---- src/desktops.c | 8 +++----- src/ecompmgr.c | 8 +++----- src/emodule.h | 4 +++- src/events.c | 15 ++++++--------- src/ewmh.c | 4 ++-- src/focus.c | 6 ++---- src/fx.c | 8 +++----- src/glwin.c | 8 +++----- src/groups.c | 6 ++---- src/handlers.c | 4 ++-- src/hints.c | 6 ++---- src/iclass.c | 4 +--- src/ipc.c | 8 ++++---- src/lang.c | 5 ++--- src/magwin.c | 5 ++--- src/main.c | 4 ++-- src/menus.c | 10 ++++------ src/mod-misc.c | 7 +++---- src/pager.c | 6 ++---- src/settings.c | 7 +++---- src/slideout.c | 5 ++--- src/sound.c | 6 ++---- src/tclass.c | 6 ++---- src/theme.c | 6 ++---- src/tooltips.c | 5 ++--- src/util.h | 2 ++ src/warp.c | 5 ++--- src/windowmatch.c | 4 +--- src/xprop.c | 12 +++++------- 35 files changed, 88 insertions(+), 134 deletions(-) diff --git a/src/aclass.c b/src/aclass.c index 9cc56fb2..2223ff85 100644 --- a/src/aclass.c +++ b/src/aclass.c @@ -1243,7 +1243,6 @@ static const IpcItem AclassIpcArray[] = { " aclass list [name/all] List action class[es]\n" " aclass load [name] Reload action classes (default is bindings.cfg)\n"} }; -#define N_IPC_FUNCS (sizeof(AclassIpcArray)/sizeof(IpcItem)) /* * Module descriptor @@ -1253,7 +1252,7 @@ extern const EModule ModAclass; const EModule ModAclass = { "aclass", "ac", AclassSighan, - {N_IPC_FUNCS, AclassIpcArray}, + MOD_ITEMS(AclassIpcArray), {0, NULL} }; diff --git a/src/backgrounds.c b/src/backgrounds.c index 61a24a82..965b84ca 100644 --- a/src/backgrounds.c +++ b/src/backgrounds.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2020 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -2542,7 +2542,6 @@ static const IpcItem BackgroundsIpcArray[] = { IPC_BackgroundUse, "use_bg", NULL, "Deprecated - do not use", NULL} , }; -#define N_IPC_FUNCS (sizeof(BackgroundsIpcArray)/sizeof(IpcItem)) /* * Configuration items @@ -2553,7 +2552,6 @@ static const CfgItem BackgroundsCfgItems[] = { CFG_ITEM_BOOL(Conf.backgrounds, no_scan, 0), CFG_ITEM_INT(Conf.backgrounds, timeout, 240), }; -#define N_CFG_ITEMS (sizeof(BackgroundsCfgItems)/sizeof(CfgItem)) /* * Module descriptor @@ -2563,6 +2561,6 @@ extern const EModule ModBackgrounds; const EModule ModBackgrounds = { "backgrounds", "bg", BackgroundsSighan, - {N_IPC_FUNCS, BackgroundsIpcArray}, - {N_CFG_ITEMS, BackgroundsCfgItems} + MOD_ITEMS(BackgroundsIpcArray), + MOD_ITEMS(BackgroundsCfgItems) }; diff --git a/src/buttons.c b/src/buttons.c index 1fa2864c..947dc035 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2018 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -1082,13 +1082,11 @@ static const IpcItem ButtonsIpcArray[] = { "(removes all buttons)\n \"button_show buttons CONFIG*\" " "(removes all buttons with CONFIG in the start)\n"}, }; -#define N_IPC_FUNCS (sizeof(ButtonsIpcArray)/sizeof(IpcItem)) #if 0 static const CfgItem ButtonsCfgItems[] = { CFG_ITEM_BOOL(Conf.buttons, enable, 1), }; -#define N_CFG_ITEMS (sizeof(ButtonsCfgItems)/sizeof(CfgItem)) #endif /* @@ -1099,6 +1097,6 @@ extern const EModule ModButtons; const EModule ModButtons = { "buttons", "btn", ButtonsSighan, - {N_IPC_FUNCS, ButtonsIpcArray}, + MOD_ITEMS(ButtonsIpcArray), {0, NULL} }; diff --git a/src/config.c b/src/config.c index 57733b43..49c665ad 100644 --- a/src/config.c +++ b/src/config.c @@ -591,12 +591,12 @@ ThemeConfigLoad(void) "menustyles.cfg", }; Progressbar *p = NULL; - int i; + unsigned int i; /* Font mappings */ FontConfigLoad(); - for (i = 0; i < (int)(sizeof(config_files) / sizeof(char *)); i++) + for (i = 0; i < E_ARRAY_SIZE(config_files); i++) { if (!Mode.wm.restart && Conf.startup.animate) @@ -616,8 +616,7 @@ ThemeConfigLoad(void) ConfigFileLoad(config_files[i], Mode.theme.path, ConfigFileRead, 1); if (p) - ProgressbarSet(p, (i * 100) / - (int)(sizeof(config_files) / sizeof(char *))); + ProgressbarSet(p, (i * 100) / E_ARRAY_SIZE(config_files)); /* Hack - We are not running in the event loop here */ EobjsRepaint(); diff --git a/src/container.c b/src/container.c index 45388ca5..dfb1f255 100644 --- a/src/container.c +++ b/src/container.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2018 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -1995,7 +1995,6 @@ static const IpcItem ContainersIpcArray[] = { " iconbox new Create new iconbox\n" " iconbox cfg Configure iconboxes\n"} }; -#define N_IPC_FUNCS (sizeof(ContainersIpcArray)/sizeof(IpcItem)) /* * Configuration items @@ -2003,7 +2002,6 @@ static const IpcItem ContainersIpcArray[] = { static const CfgItem ContainersCfgItems[] = { CFG_ITEM_INT(Conf_containers, anim_time, 250), }; -#define N_CFG_ITEMS (sizeof(ContainersCfgItems)/sizeof(CfgItem)) /* * Module descriptor @@ -2013,6 +2011,6 @@ extern const EModule ModIconboxes; const EModule ModIconboxes = { "iconboxes", "ibox", ContainersSighan, - {N_IPC_FUNCS, ContainersIpcArray}, - {N_CFG_ITEMS, ContainersCfgItems} + MOD_ITEMS(ContainersIpcArray), + MOD_ITEMS(ContainersCfgItems) }; diff --git a/src/cursors.c b/src/cursors.c index 13dbd6b6..3b9c1cce 100644 --- a/src/cursors.c +++ b/src/cursors.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2018 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -421,7 +421,6 @@ static const IpcItem CursorIpcArray[] = { "Cursor functions", " cursor list Show all cursors\n"} }; -#define N_IPC_FUNCS (sizeof(CursorIpcArray)/sizeof(IpcItem)) /* * Module descriptor @@ -431,7 +430,6 @@ extern const EModule ModCursors; const EModule ModCursors = { "cursor", "csr", NULL, - {N_IPC_FUNCS, CursorIpcArray} - , + MOD_ITEMS(CursorIpcArray), {0, NULL} }; diff --git a/src/desktops.c b/src/desktops.c index 0f5e5655..effd0823 100644 --- a/src/desktops.c +++ b/src/desktops.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2019 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -2984,7 +2984,6 @@ static const IpcItem DesksIpcArray[] = { " area lmove
Move relative to current linear area\n"} , }; -#define N_IPC_FUNCS (sizeof(DesksIpcArray)/sizeof(IpcItem)) static void DesksCfgFuncCount(void *item __UNUSED__, const char *value) @@ -3039,7 +3038,6 @@ static const CfgItem DesksCfgItems[] = { CFG_ITEM_INT(Conf.desks, edge_flip_mode, EDGE_FLIP_ON), CFG_ITEM_INT(Conf.desks, edge_flip_resistance, 25), }; -#define N_CFG_ITEMS (sizeof(DesksCfgItems)/sizeof(CfgItem)) /* * Module descriptor @@ -3049,6 +3047,6 @@ extern const EModule ModDesktops; const EModule ModDesktops = { "desktops", "desk", DesksSighan, - {N_IPC_FUNCS, DesksIpcArray}, - {N_CFG_ITEMS, DesksCfgItems} + MOD_ITEMS(DesksIpcArray), + MOD_ITEMS(DesksCfgItems) }; diff --git a/src/ecompmgr.c b/src/ecompmgr.c index 1be7b56f..1c32f895 100644 --- a/src/ecompmgr.c +++ b/src/ecompmgr.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2020 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -2622,7 +2622,6 @@ static const IpcItem CompMgrIpcArray[] = { " cm stop Stop composite manager\n"} , }; -#define N_IPC_FUNCS (sizeof(CompMgrIpcArray)/sizeof(IpcItem)) static const CfgItem CompMgrCfgItems[] = { CFG_ITEM_BOOL(Conf_compmgr, enable, 0), @@ -2643,7 +2642,6 @@ static const CfgItem CompMgrCfgItems[] = { CFG_ITEM_INT(Conf_compmgr, override_redirect.mode, 1), CFG_ITEM_INT(Conf_compmgr, override_redirect.opacity, 90), }; -#define N_CFG_ITEMS (sizeof(CompMgrCfgItems)/sizeof(CfgItem)) /* * Module descriptor @@ -2653,8 +2651,8 @@ extern const EModule ModCompMgr; const EModule ModCompMgr = { "compmgr", "cm", ECompMgrSighan, - {N_IPC_FUNCS, CompMgrIpcArray}, - {N_CFG_ITEMS, CompMgrCfgItems} + MOD_ITEMS(CompMgrIpcArray), + MOD_ITEMS(CompMgrCfgItems) }; #endif /* USE_COMPOSITE */ diff --git a/src/emodule.h b/src/emodule.h index 07d0a950..0c7794fa 100644 --- a/src/emodule.h +++ b/src/emodule.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2010 Kim Woelders + * Copyright (C) 2003-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -34,6 +34,8 @@ typedef struct { CfgItemList cfg; } EModule; +#define MOD_ITEMS(x) { E_ARRAY_SIZE(x), x } + typedef enum { ESIGNAL_NONE, ESIGNAL_INIT, diff --git a/src/events.c b/src/events.c index 0cb891ce..16b49b94 100644 --- a/src/events.c +++ b/src/events.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2020 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -409,7 +409,7 @@ EventsInit(void) Mode.screen.fps = 60; /* If not randr or weirdness */ - for (i = 0; i < sizeof(Extensions) / sizeof(EServerExt); i++) + for (i = 0; i < E_ARRAY_SIZE(Extensions); i++) ExtQuery(Extensions + i); #if USE_COMPOSITE @@ -429,7 +429,7 @@ EventsGetExtensionName(int req) unsigned int i; EServerExtData *exd; - for (i = 0; i < sizeof(Extensions) / sizeof(EServerExt); i++) + for (i = 0; i < E_ARRAY_SIZE(Extensions); i++) { exd = ExtData + Extensions[i].ix; if (req == exd->major_op) @@ -1247,14 +1247,13 @@ static const char *const TxtEventNames[] = { "SelectionRequest", "SelectionNotify", "ColormapNotify", "ClientMessage", "MappingNotify" }; -#define N_EVENT_NAMES (sizeof(TxtEventNames)/sizeof(char*)) static const char * EventName(unsigned int type) { static char buf[16]; - if (type < N_EVENT_NAMES) + if (type < E_ARRAY_SIZE(TxtEventNames)) return TxtEventNames[type]; switch (type) @@ -1292,12 +1291,11 @@ EventName(unsigned int type) static const char *const TxtEventNotifyModeNames[] = { "NotifyNormal", "NotifyGrab", "NotifyUngrab", "NotifyWhileGrabbed" }; -#define N_EVENT_NOTIFY_MODE_NAMES (sizeof(TxtEventNotifyModeNames)/sizeof(char*)) static const char * EventNotifyModeName(unsigned int mode) { - if (mode < N_EVENT_NOTIFY_MODE_NAMES) + if (mode < E_ARRAY_SIZE(TxtEventNotifyModeNames)) return TxtEventNotifyModeNames[mode]; return "Unknown"; @@ -1308,12 +1306,11 @@ static const char *const TxtEventNotifyDetailNames[] = { "NotifyNonlinearVirtual", "NotifyPointer", "NotifyPointerRoot", "NotifyDetailNone" }; -#define N_EVENT_NOTIFY_DETAIL_NAMES (sizeof(TxtEventNotifyDetailNames)/sizeof(char*)) static const char * EventNotifyDetailName(unsigned int detail) { - if (detail < N_EVENT_NOTIFY_DETAIL_NAMES) + if (detail < E_ARRAY_SIZE(TxtEventNotifyDetailNames)) return TxtEventNotifyDetailNames[detail]; return "Unknown"; diff --git a/src/ewmh.c b/src/ewmh.c index d463d4d3..1dfea857 100644 --- a/src/ewmh.c +++ b/src/ewmh.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2020 Kim Woelders + * Copyright (C) 2003-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -386,7 +386,7 @@ void EWMH_SetWindowState(const EWin * ewin) { EX_Atom atom_list[64]; - int len = sizeof(atom_list) / sizeof(EX_Atom); + int len = E_ARRAY_SIZE(atom_list); int atom_count; atom_count = 0; diff --git a/src/focus.c b/src/focus.c index cd04b351..8fa87851 100644 --- a/src/focus.c +++ b/src/focus.c @@ -1207,7 +1207,6 @@ static const IpcItem FocusIpcArray[] = { " the last window does not lose the focus\n"} , }; -#define N_IPC_FUNCS (sizeof(FocusIpcArray)/sizeof(IpcItem)) static const CfgItem FocusCfgItems[] = { CFG_ITEM_INT(Conf.focus, mode, MODE_FOCUS_SLOPPY), @@ -1225,7 +1224,6 @@ static const CfgItem FocusCfgItems[] = { CFG_ITEM_BOOL(Conf, autoraise.enable, 0), CFG_ITEM_INT(Conf, autoraise.delay, 500), }; -#define N_CFG_ITEMS (sizeof(FocusCfgItems)/sizeof(CfgItem)) /* * Module descriptor @@ -1235,6 +1233,6 @@ extern const EModule ModFocus; const EModule ModFocus = { "focus", NULL, FocusSighan, - {N_IPC_FUNCS, FocusIpcArray}, - {N_CFG_ITEMS, FocusCfgItems} + MOD_ITEMS(FocusIpcArray), + MOD_ITEMS(FocusCfgItems) }; diff --git a/src/fx.c b/src/fx.c index c564c5f3..3ac59d3a 100644 --- a/src/fx.c +++ b/src/fx.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2015 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -333,7 +333,6 @@ static FXHandler fx_handlers[] = { {"ripples", FX_Ripple_Init, FX_Ripple_Ops, 0, 0}, {"waves", FX_Waves_Init, FX_Waves_Ops, 0, 0}, }; -#define N_FX_HANDLERS (sizeof(fx_handlers)/sizeof(FXHandler)) /****************************** Effect handlers *****************************/ @@ -387,7 +386,7 @@ FX_OpForEach(int op) { unsigned int i; - for (i = 0; i < N_FX_HANDLERS; i++) + for (i = 0; i < E_ARRAY_SIZE(fx_handlers); i++) FX_Op(&fx_handlers[i], op); } @@ -487,7 +486,6 @@ static const CfgItem FxCfgItems[] = { CFR_FUNC_BOOL(fx_handlers[0].enabled, ripples.enabled, 0, FxCfgFunc), CFR_FUNC_BOOL(fx_handlers[1].enabled, waves.enabled, 0, FxCfgFunc), }; -#define N_CFG_ITEMS (sizeof(FxCfgItems)/sizeof(CfgItem)) /* * Module descriptor @@ -498,5 +496,5 @@ const EModule ModEffects = { "effects", "fx", FxSighan, {0, NULL}, - {N_CFG_ITEMS, FxCfgItems} + MOD_ITEMS(FxCfgItems) }; diff --git a/src/glwin.c b/src/glwin.c index 826a6525..cdeb8ba9 100644 --- a/src/glwin.c +++ b/src/glwin.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2020 Kim Woelders + * Copyright (C) 2007-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -760,12 +760,10 @@ static const IpcItem GlwinIpcArray[] = { " glwin\n"} , }; -#define N_IPC_FUNCS (sizeof(GlwinIpcArray)/sizeof(IpcItem)) static const CfgItem GlwinCfgItems[] = { CFG_ITEM_INT(Conf_glwin, mode, 0), }; -#define N_CFG_ITEMS (sizeof(GlwinCfgItems)/sizeof(CfgItem)) /* * Module descriptor @@ -775,6 +773,6 @@ extern const EModule ModGlwin; const EModule ModGlwin = { "glwin", NULL, GlwinSighan, - {N_IPC_FUNCS, GlwinIpcArray}, - {N_CFG_ITEMS, GlwinCfgItems} + MOD_ITEMS(GlwinIpcArray), + MOD_ITEMS(GlwinCfgItems) }; diff --git a/src/groups.c b/src/groups.c index 431054f3..46a1a0c0 100644 --- a/src/groups.c +++ b/src/groups.c @@ -1430,7 +1430,6 @@ static const IpcItem GroupsIpcArray[] = { " group shade \n"} , }; -#define N_IPC_FUNCS (sizeof(GroupsIpcArray)/sizeof(IpcItem)) /* * Configuration items @@ -1445,13 +1444,12 @@ static const CfgItem GroupsCfgItems[] = { CFG_ITEM_BOOL(Conf_groups, dflt.shade, 1), CFG_ITEM_BOOL(Conf_groups, swapmove, 1), }; -#define N_CFG_ITEMS (sizeof(GroupsCfgItems)/sizeof(CfgItem)) extern const EModule ModGroups; const EModule ModGroups = { "groups", "grp", NULL, - {N_IPC_FUNCS, GroupsIpcArray}, - {N_CFG_ITEMS, GroupsCfgItems} + MOD_ITEMS(GroupsIpcArray), + MOD_ITEMS(GroupsCfgItems) }; diff --git a/src/handlers.c b/src/handlers.c index 9870582a..99ad237c 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2019 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -142,7 +142,7 @@ doSignalsSetup(int setup) sigemptyset(&sa.sa_mask); sigprocmask(SIG_SETMASK, &sa.sa_mask, (sigset_t *) NULL); - for (i = 0; i < sizeof(signals) / sizeof(int); i++) + for (i = 0; i < E_ARRAY_SIZE(signals); i++) { sig = signals[i]; if (Mode.wm.coredump && diff --git a/src/hints.c b/src/hints.c index 406f3403..d350b5e8 100644 --- a/src/hints.c +++ b/src/hints.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2020 Kim Woelders + * Copyright (C) 2003-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -40,8 +40,6 @@ static void EHintsSetDeskInfo(void); static void EHintsSetAreaInfo(void); -#define N_ITEMS(x) (sizeof(x)/sizeof(x[0])) - static const char *const atoms_misc_names[] = { /* Misc atoms */ "MANAGER", @@ -71,7 +69,7 @@ HintsInit(void) { EX_Window win; - ex_atoms_get(atoms_misc_names, N_ITEMS(atoms_misc_names), atoms_misc); + ex_atoms_get(atoms_misc_names, E_ARRAY_SIZE(atoms_misc_names), atoms_misc); win = XCreateSimpleWindow(disp, WinGetXwin(VROOT), -200, -200, 5, 5, 0, 0, 0); diff --git a/src/iclass.c b/src/iclass.c index 5abd1e63..ecd0e816 100644 --- a/src/iclass.c +++ b/src/iclass.c @@ -1305,7 +1305,6 @@ static const IpcItem ImageclassIpcArray[] = { NULL} , }; -#define N_IPC_FUNCS (sizeof(ImageclassIpcArray)/sizeof(IpcItem)) /* * Module descriptor @@ -1315,7 +1314,6 @@ extern const EModule ModImageclass; const EModule ModImageclass = { "imageclass", "ic", NULL, - {N_IPC_FUNCS, ImageclassIpcArray} - , + MOD_ITEMS(ImageclassIpcArray), {0, NULL} }; diff --git a/src/ipc.c b/src/ipc.c index 6f7bedca..ea5c3ad6 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2020 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -1446,13 +1446,13 @@ IPC_InsertKeys(const char *params, Client * c __UNUSED__) ev.window = win; for (i = 0; i < (int)strlen(s); i++) { - int j; + unsigned int j; ev.x = Mode.events.cx; ev.y = Mode.events.cy; ev.x_root = Mode.events.cx; ev.y_root = Mode.events.cy; - for (j = 0; j < (int)(sizeof(ks) / sizeof(struct _keyset)); j++) + for (j = 0; j < E_ARRAY_SIZE(ks); j++) { if (strncmp(ks[j].ch, &(s[i]), strlen(ks[j].ch))) continue; @@ -1723,7 +1723,7 @@ IPC_GetList(int *pnum) return ipc_item_list; } - num = sizeof(IPCArray) / sizeof(IpcItem); + num = E_ARRAY_SIZE(IPCArray); lst = EMALLOC(const IpcItem *, num); for (i = 0; i < num; i++) diff --git a/src/lang.c b/src/lang.c index 2754dd71..a20421b2 100644 --- a/src/lang.c +++ b/src/lang.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2018 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -447,7 +447,6 @@ static const CfgItem LocaleCfgItems[] = { CFG_FUNC_STR(Conf_locale, internal, LangCfgChange), CFG_ITEM_STR(Conf_locale, exported), }; -#define N_CFG_ITEMS (sizeof(LocaleCfgItems)/sizeof(CfgItem)) extern const EModule ModLocale; @@ -455,5 +454,5 @@ const EModule ModLocale = { "locale", NULL, NULL, {0, NULL}, - {N_CFG_ITEMS, LocaleCfgItems} + MOD_ITEMS(LocaleCfgItems) }; diff --git a/src/magwin.c b/src/magwin.c index 361e274e..4891cdea 100644 --- a/src/magwin.c +++ b/src/magwin.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2015 Kim Woelders + * Copyright (C) 2007-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -569,7 +569,6 @@ static const IpcItem MagwinIpcArray[] = { " mag [show|hide]\n"} , }; -#define N_IPC_FUNCS (sizeof(MagwinIpcArray)/sizeof(IpcItem)) /* * Module descriptor @@ -579,6 +578,6 @@ extern const EModule ModMagwin; const EModule ModMagwin = { "magwin", NULL, NULL, - {N_IPC_FUNCS, MagwinIpcArray}, + MOD_ITEMS(MagwinIpcArray), {0, NULL} }; diff --git a/src/main.c b/src/main.c index 4db29724..f09cb1ac 100644 --- a/src/main.c +++ b/src/main.c @@ -385,7 +385,7 @@ EoptGet(int argc, char **argv) eoptarg = NULL; eopt = NULL; - for (i = 0; i < sizeof(Eopts) / sizeof(EOpt); i++) + for (i = 0; i < E_ARRAY_SIZE(Eopts); i++) { eopt = &Eopts[i]; @@ -447,7 +447,7 @@ EoptHelp(void) char buf[256]; printf("e16 options:\n"); - for (i = 0; i < sizeof(Eopts) / sizeof(EOpt); i++) + for (i = 0; i < E_ARRAY_SIZE(Eopts); i++) { eopt = &Eopts[i]; if (!eopt->desc) diff --git a/src/menus.c b/src/menus.c index 00fc559f..aa442376 100644 --- a/src/menus.c +++ b/src/menus.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2020 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -1123,7 +1123,7 @@ static const char *const menu_aliases[] = { "ROOT_2", "enlightenment.menu", "WINOPS_MENU", "winops.menu", }; -#define N_MENU_ALIASES (sizeof(menu_aliases)/sizeof(char*)/2) +#define N_MENU_ALIASES (E_ARRAY_SIZE(menu_aliases)/2) static const char * _MenuCheckAlias(const char *name) @@ -2089,7 +2089,6 @@ static const IpcItem MenusIpcArray[] = { " menus show Show named menu\n"} , }; -#define N_IPC_FUNCS (sizeof(MenusIpcArray)/sizeof(IpcItem)) static const CfgItem MenusCfgItems[] = { CFG_ITEM_BOOL(Conf.menus, animate, 0), @@ -2104,7 +2103,6 @@ static const CfgItem MenusCfgItems[] = { CFG_ITEM_HEX(Conf.menus, key.escape, XK_Escape), CFG_ITEM_HEX(Conf.menus, key.ret, XK_Return), }; -#define N_CFG_ITEMS (sizeof(MenusCfgItems)/sizeof(CfgItem)) /* * Module descriptor @@ -2114,6 +2112,6 @@ extern const EModule ModMenus; const EModule ModMenus = { "menus", "menu", MenusSighan, - {N_IPC_FUNCS, MenusIpcArray}, - {N_CFG_ITEMS, MenusCfgItems} + MOD_ITEMS(MenusIpcArray), + MOD_ITEMS(MenusCfgItems) }; diff --git a/src/mod-misc.c b/src/mod-misc.c index 131d84d1..962ab068 100644 --- a/src/mod-misc.c +++ b/src/mod-misc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2020 Kim Woelders + * Copyright (C) 2003-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -100,7 +100,7 @@ const EModule *const p_modules[] = { &ModWarplist, &ModWindowMatch, }; -int n_modules = sizeof(p_modules) / sizeof(EModule *); +int n_modules = E_ARRAY_SIZE(p_modules); #if 0 static void @@ -219,14 +219,13 @@ static const CfgItem MiscCfgItems[] = { CFG_ITEM_BOOL(Conf, memory_paranoia, 1), CFG_ITEM_BOOL(Conf, save_under, 0), }; -#define N_CFG_ITEMS ((int)(sizeof(MiscCfgItems)/sizeof(CfgItem))) /* Stuff not elsewhere */ const EModule ModMisc = { "misc", NULL, NULL, {0, NULL}, - {N_CFG_ITEMS, MiscCfgItems} + MOD_ITEMS(MiscCfgItems) }; void diff --git a/src/pager.c b/src/pager.c index 462ea220..9c8538c3 100644 --- a/src/pager.c +++ b/src/pager.c @@ -2123,7 +2123,6 @@ static const IpcItem PagersIpcArray[] = { " pager zoom Toggle zooming in the pager\n"} , }; -#define N_IPC_FUNCS (sizeof(PagersIpcArray)/sizeof(IpcItem)) /* * Configuration items @@ -2139,7 +2138,6 @@ static const CfgItem PagersCfgItems[] = { CFG_ITEM_INT(Conf_pagers, win_button, 1), CFG_ITEM_INT(Conf_pagers, menu_button, 3), }; -#define N_CFG_ITEMS (sizeof(PagersCfgItems)/sizeof(CfgItem)) /* * Module descriptor @@ -2149,6 +2147,6 @@ extern const EModule ModPagers; const EModule ModPagers = { "pagers", "pg", PagersSighan, - {N_IPC_FUNCS, PagersIpcArray}, - {N_CFG_ITEMS, PagersCfgItems} + MOD_ITEMS(PagersIpcArray), + MOD_ITEMS(PagersCfgItems) }; diff --git a/src/settings.c b/src/settings.c index dfa34c08..1eda9a17 100644 --- a/src/settings.c +++ b/src/settings.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2020 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -711,7 +711,6 @@ static const DialogDef *const dialogs[] = { &DlgSession, &DlgMisc, }; -#define N_CFG_DLGS (sizeof(dialogs)/sizeof(DialogDef*)) static void CB_DlgSelect(Dialog * d, int val, void *data) @@ -746,7 +745,7 @@ _DlgFillConfiguration(Dialog * d, DItem * table, void *data __UNUSED__) buttons = DialogAddItem(table, DITEM_TABLE); content = DialogAddItem(table, DITEM_TABLE); - for (i = 0; i < N_CFG_DLGS; i++) + for (i = 0; i < E_ARRAY_SIZE(dialogs); i++) { di = DialogAddItem(buttons, DITEM_BUTTON); DialogItemSetPadding(di, 2, 2, 0, 0); @@ -780,7 +779,7 @@ IPC_Cfg(const char *params) return; } - for (i = 0; i < N_CFG_DLGS; i++) + for (i = 0; i < E_ARRAY_SIZE(dialogs); i++) { name = dialogs[i]->label; if (Estrcasecmp(params, name)) diff --git a/src/slideout.c b/src/slideout.c index 199e7960..89d5c16a 100644 --- a/src/slideout.c +++ b/src/slideout.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2020 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -500,7 +500,6 @@ static const IpcItem SlideoutsIpcArray[] = { { IPC_Slideout, "slideout", NULL, "Show slideout", NULL}, }; -#define N_IPC_FUNCS (sizeof(SlideoutsIpcArray)/sizeof(IpcItem)) /* * Module descriptor @@ -510,6 +509,6 @@ extern const EModule ModSlideouts; const EModule ModSlideouts = { "slideouts", "slideout", SlideoutsSighan, - {N_IPC_FUNCS, SlideoutsIpcArray}, + MOD_ITEMS(SlideoutsIpcArray), {0, NULL} }; diff --git a/src/sound.c b/src/sound.c index 49c30f02..deca5120 100644 --- a/src/sound.c +++ b/src/sound.c @@ -562,7 +562,6 @@ static const IpcItem SoundIpcArray[] = { " sound on Enable sounds\n" " sound play Play sounds\n"} }; -#define N_IPC_FUNCS (sizeof(SoundIpcArray)/sizeof(IpcItem)) static const CfgItem SoundCfgItems[] = { CFG_FUNC_BOOL(Conf_sound, enable, 0, _SoundEnableChange), @@ -570,7 +569,6 @@ static const CfgItem SoundCfgItems[] = { CFG_ITEM_HEX(Conf_sound, mask1, 0), CFG_ITEM_HEX(Conf_sound, mask2, 0), }; -#define N_CFG_ITEMS (sizeof(SoundCfgItems)/sizeof(CfgItem)) /* * Module descriptor @@ -580,8 +578,8 @@ extern const EModule ModSound; const EModule ModSound = { "sound", "audio", _SoundSighan, - {N_IPC_FUNCS, SoundIpcArray}, - {N_CFG_ITEMS, SoundCfgItems} + MOD_ITEMS(SoundIpcArray), + MOD_ITEMS(SoundCfgItems) }; #endif /* ENABLE_SOUND */ diff --git a/src/tclass.c b/src/tclass.c index 1d6d189a..a19af72e 100644 --- a/src/tclass.c +++ b/src/tclass.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2014 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -486,7 +486,6 @@ static const IpcItem TextclassIpcArray[] = { NULL} , }; -#define N_IPC_FUNCS (sizeof(TextclassIpcArray)/sizeof(IpcItem)) /* * Module descriptor @@ -496,7 +495,6 @@ extern const EModule ModTextclass; const EModule ModTextclass = { "textclass", "tc", NULL, - {N_IPC_FUNCS, TextclassIpcArray} - , + MOD_ITEMS(TextclassIpcArray), {0, NULL} }; diff --git a/src/theme.c b/src/theme.c index baedb572..b7421054 100644 --- a/src/theme.c +++ b/src/theme.c @@ -507,7 +507,6 @@ static const IpcItem ThemeIpcArray[] = { " theme use Switch to theme \n"} , }; -#define N_IPC_FUNCS (sizeof(ThemeIpcArray)/sizeof(IpcItem)) static const CfgItem ThemeCfgItems[] = { CFG_ITEM_STR(Conf.theme, name), @@ -516,7 +515,6 @@ static const CfgItem ThemeCfgItems[] = { CFG_ITEM_BOOL(Conf.theme, use_alt_font_cfg, 0), CFG_ITEM_STR(Conf.theme, font_cfg), }; -#define N_CFG_ITEMS (sizeof(ThemeCfgItems)/sizeof(CfgItem)) /* * Module descriptor @@ -526,6 +524,6 @@ extern const EModule ModTheme; const EModule ModTheme = { "theme", "th", NULL, - {N_IPC_FUNCS, ThemeIpcArray}, - {N_CFG_ITEMS, ThemeCfgItems} + MOD_ITEMS(ThemeIpcArray), + MOD_ITEMS(ThemeCfgItems) }; diff --git a/src/tooltips.c b/src/tooltips.c index 5fa94c9a..1b5afb67 100644 --- a/src/tooltips.c +++ b/src/tooltips.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2020 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -883,7 +883,6 @@ static const CfgItem TooltipsCfgItems[] = { CFG_ITEM_BOOL(Conf_tooltips, showroottooltip, 1), CFG_ITEM_INT(Conf_tooltips, delay, 1500), }; -#define N_CFG_ITEMS (sizeof(TooltipsCfgItems)/sizeof(CfgItem)) /* * Module descriptor @@ -894,5 +893,5 @@ const EModule ModTooltips = { "tooltips", "tt", TooltipsSighan, {0, NULL}, - {N_CFG_ITEMS, TooltipsCfgItems} + MOD_ITEMS(TooltipsCfgItems) }; diff --git a/src/util.h b/src/util.h index 2e1ed3c4..feb9b372 100644 --- a/src/util.h +++ b/src/util.h @@ -136,4 +136,6 @@ unsigned int GetTimeUs(void); void SleepUs(unsigned int tus); +#define E_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) + #endif /* _UTIL_H_ */ diff --git a/src/warp.c b/src/warp.c index 42789400..b2d4c18c 100644 --- a/src/warp.c +++ b/src/warp.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors - * Copyright (C) 2004-2020 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -552,7 +552,6 @@ static const CfgItem WarplistCfgItems[] = { CFG_ITEM_BOOL(Conf.warplist, show_shape, 0), CFG_ITEM_INT(Conf.warplist, icon_mode, EWIN_ICON_MODE_APP_IMG), }; -#define N_CFG_ITEMS (sizeof(WarplistCfgItems)/sizeof(CfgItem)) extern const EModule ModWarplist; @@ -560,5 +559,5 @@ const EModule ModWarplist = { "warplist", "warp", NULL, {0, NULL}, - {N_CFG_ITEMS, WarplistCfgItems} + MOD_ITEMS(WarplistCfgItems) }; diff --git a/src/windowmatch.c b/src/windowmatch.c index 4875fe3c..71651fce 100644 --- a/src/windowmatch.c +++ b/src/windowmatch.c @@ -977,7 +977,6 @@ static const IpcItem WindowMatchIpcArray[] = { " wmatch list List window matches\n"} , }; -#define N_IPC_FUNCS (sizeof(WindowMatchIpcArray)/sizeof(IpcItem)) /* * Module descriptor @@ -987,7 +986,6 @@ extern const EModule ModWindowMatch; const EModule ModWindowMatch = { "winmatch", NULL, WindowMatchSighan, - {N_IPC_FUNCS, WindowMatchIpcArray} - , + MOD_ITEMS(WindowMatchIpcArray), {0, NULL} }; diff --git a/src/xprop.c b/src/xprop.c index 33408515..cc754ac6 100644 --- a/src/xprop.c +++ b/src/xprop.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2019 Kim Woelders + * Copyright (C) 2004-2021 Kim Woelders * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -43,8 +43,6 @@ #define _ex_disp disp -#define N_ITEMS(x) (sizeof(x)/sizeof(x[0])) - /* * General stuff */ @@ -600,9 +598,9 @@ void ex_icccm_init(void) { #if DEBUG_CHECK - assert(CHECK_COUNT_ICCCM == N_ITEMS(atoms_icccm)); + assert(CHECK_COUNT_ICCCM == E_ARRAY_SIZE(atoms_icccm)); #endif - ex_atoms_get(atoms_icccm_names, N_ITEMS(atoms_icccm), atoms_icccm); + ex_atoms_get(atoms_icccm_names, E_ARRAY_SIZE(atoms_icccm), atoms_icccm); } static void @@ -822,9 +820,9 @@ void ex_netwm_init(void) { #if DEBUG_CHECK - assert(CHECK_COUNT_NETWM == N_ITEMS(atoms_netwm)); + assert(CHECK_COUNT_NETWM == E_ARRAY_SIZE(atoms_netwm)); #endif - ex_atoms_get(atoms_netwm_names, N_ITEMS(atoms_netwm), atoms_netwm); + ex_atoms_get(atoms_netwm_names, E_ARRAY_SIZE(atoms_netwm), atoms_netwm); } /*