summaryrefslogtreecommitdiff
path: root/src/menus.c
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2020-06-18 18:34:59 -0400
committerThomas E. Dickey <dickey@invisible-island.net>2020-06-18 18:34:59 -0400
commita9d6701d977700b18e31a70cc7982431bc702095 (patch)
treeeb24677e90094a95c1461243b56e83309a47742b /src/menus.c
parentd2b4f0598086d4dd5caf3cdc218d0f97c37229ac (diff)
fix the cppcheck style- and format-warnings
also bump version to 1.0.11.1, reflecting ongoing work since release Signed-off-by: Thomas E. Dickey <dickey@invisible-island.net>
Diffstat (limited to 'src/menus.c')
-rw-r--r--src/menus.c83
1 files changed, 50 insertions, 33 deletions
diff --git a/src/menus.c b/src/menus.c
index 8b1cb00..a0e5c0f 100644
--- a/src/menus.c
+++ b/src/menus.c
@@ -133,7 +133,7 @@ void
InitMenus(void)
{
int i, j, k;
- FuncKey *key, *tmp;
+ FuncKey *key;
for (i = 0; i < MAX_BUTTONS + 1; i++)
for (j = 0; j < NUM_CONTEXTS; j++)
@@ -147,8 +147,9 @@ InitMenus(void)
if (FirstScreen) {
for (key = Scr->FuncKeyRoot.next; key != NULL;) {
+ FuncKey *tmp = key;
+
free(key->name);
- tmp = key;
key = key->next;
free(tmp);
}
@@ -216,7 +217,7 @@ CreateTitleButton(const char *name, int func, const char *action,
if (!tb) {
fprintf(stderr,
- "%s: unable to allocate %ld bytes for title button\n",
+ "%s: unable to allocate %lu bytes for title button\n",
ProgramName, (unsigned long) sizeof(TitleButton));
return 0;
}
@@ -366,7 +367,6 @@ PaintEntry(MenuRoot *mr, MenuItem *mi, int exposure)
text_y = y_offset + Scr->MenuFont.y;
if (mi->func != F_TITLE) {
- int x, y;
if (mi->state) {
XSetForeground(dpy, Scr->NormalGC, mi->hi_back);
@@ -401,6 +401,8 @@ PaintEntry(MenuRoot *mr, MenuItem *mi, int exposure)
}
if (mi->func == F_MENU) {
+ int x, y;
+
/* create the pull right pixmap if needed */
if (Scr->pullPm == None) {
Scr->pullPm = CreateMenuIcon(Scr->MenuFont.height,
@@ -414,8 +416,6 @@ PaintEntry(MenuRoot *mr, MenuItem *mi, int exposure)
}
}
else {
- int y;
-
XSetForeground(dpy, Scr->NormalGC, mi->back);
/* fill the rectangle with the title background color */
@@ -423,6 +423,8 @@ PaintEntry(MenuRoot *mr, MenuItem *mi, int exposure)
(unsigned) mr->width, (unsigned) Scr->EntryHeight);
{
+ int y;
+
XSetForeground(dpy, Scr->NormalGC, mi->fore);
/* now draw the dividing lines */
if (y_offset)
@@ -658,8 +660,8 @@ AddToMenu(MenuRoot *menu, const char *item, const char *action,
int width;
#ifdef DEBUG_MENUS
- fprintf(stderr, "adding menu item=\"%s\", action=%s, sub=%d, f=%d\n",
- item, action, sub, func);
+ fprintf(stderr, "adding menu item=\"%s\", action=%s, sub=%p, f=%d\n",
+ item, action ? action : "<null>", sub, func);
#endif
tmp = malloc(sizeof(MenuItem));
@@ -731,18 +733,17 @@ MakeMenu(MenuRoot *mr)
XColor f1, f2, f3;
XColor b1, b2, b3;
XColor save_fore, save_back;
- int num, i;
- int fred, fgreen, fblue;
- int bred, bgreen, bblue;
- int width;
- unsigned long valuemask;
+ int i;
XSetWindowAttributes attributes;
Colormap cmap = Scr->TwmRoot.cmaps.cwins[0]->colormap->c;
Scr->EntryHeight = Scr->MenuFont.height + 4;
- /* lets first size the window accordingly */
+ /* let's first size the window accordingly */
if (mr->mapped == NEVER_MAPPED) {
+ int width;
+ unsigned long valuemask;
+
if (mr->pull == TRUE) {
mr->width = (short) (mr->width + (16 + 10));
}
@@ -837,7 +838,12 @@ MakeMenu(MenuRoot *mr)
return;
start = mr->first;
+
while (TRUE) {
+ int num;
+ int fred, fgreen, fblue;
+ int bred, bgreen, bblue;
+
for (; start != NULL; start = start->next) {
if (start->user_colors)
break;
@@ -915,10 +921,8 @@ MakeMenu(MenuRoot *mr)
Bool
PopUpMenu(MenuRoot *menu, int x, int y, Bool center)
{
- int WindowNameCount;
TwmWindow **WindowNames;
TwmWindow *tmp_win2, *tmp_win3;
- int i;
int (*compar)(const char *, const char *) =
(Scr->CaseSensitive ? strcmp : XmuCompareISOLatin1);
@@ -929,6 +933,7 @@ PopUpMenu(MenuRoot *menu, int x, int y, Bool center)
if (menu == Scr->Windows) {
TwmWindow *tmp_win;
+ int WindowNameCount;
/* this is the twm windows menu, let's go ahead and build it */
@@ -945,10 +950,14 @@ PopUpMenu(MenuRoot *menu, int x, int y, Bool center)
for (tmp_win = Scr->TwmRoot.next, WindowNameCount = 0;
tmp_win != NULL; tmp_win = tmp_win->next)
WindowNameCount++;
+
if (WindowNameCount != 0) {
+ int i;
+
WindowNames =
malloc(sizeof(TwmWindow *) * (size_t) WindowNameCount);
WindowNames[0] = Scr->TwmRoot.next;
+
for (tmp_win = Scr->TwmRoot.next->next, WindowNameCount = 1;
tmp_win != NULL; tmp_win = tmp_win->next, WindowNameCount++) {
tmp_win2 = tmp_win;
@@ -1687,7 +1696,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
}
if (ConstMoveDir != MOVE_NONE) {
- int xl, yt, xr, yb, w2, h;
+ int xl, yt, w2, h;
xl = ConstMoveX;
yt = ConstMoveY;
@@ -1695,8 +1704,8 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
h = (int) ((unsigned) DragHeight + 2 * JunkBW);
if (Scr->DontMoveOff && MoveFunction != F_FORCEMOVE) {
- xr = xl + w2;
- yb = yt + h;
+ int xr = xl + w2;
+ int yb = yt + h;
if (xl < 0)
xl = 0;
@@ -1719,7 +1728,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
}
}
else if (DragWindow != None) {
- int xl, yt, xr, yb, w2, h;
+ int xl, yt, w2, h;
if (!menuFromFrameOrWindowOrTitlebar) {
xl = (int) ((unsigned) eventp->xmotion.x_root -
@@ -1735,8 +1744,8 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
h = (int) ((unsigned) DragHeight + 2 * JunkBW);
if (Scr->DontMoveOff && MoveFunction != F_FORCEMOVE) {
- xr = xl + w2;
- yb = yt + h;
+ int xr = xl + w2;
+ int yb = yt + h;
if (xl < 0)
xl = 0;
@@ -1994,7 +2003,6 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_WARPNEXT:
{
register TwmWindow *t;
- static TwmWindow *savedwarp = NULL;
TwmWindow *of, *l, *n;
int c = 0;
@@ -2019,9 +2027,12 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
if (t == of)
c++;
- if (bwin(t) || c >= 2)
+ if (bwin(t) || c >= 2) {
Bell(XkbBI_MinorError, 0, None);
+ }
else {
+ static TwmWindow *savedwarp = NULL;
+
if (of && of == savedwarp) {
Iconify(of, 0, 0);
savedwarp = NULL;
@@ -2301,7 +2312,7 @@ Execute(const char *s)
static char *exec_display;
char *ds = DisplayString(dpy);
- char *colon, *dot1;
+ char *colon;
char *oldDisplay = NULL;
char *value;
Bool restorevar = False;
@@ -2321,6 +2332,8 @@ Execute(const char *s)
char *update = malloc(need);
if (update != NULL) {
+ char *dot1;
+
strcpy(update, display_eqls);
strcat(update, ds);
colon = strrchr(update, ':');
@@ -2529,7 +2542,7 @@ Iconify(TwmWindow *tmp_win, int def_x, int def_y)
static void
Identify(TwmWindow *t)
{
- int i, n, twidth, width, height;
+ int i, n, width, height;
int x, y;
unsigned int wwidth, wheight, bw, depth;
Window junk;
@@ -2552,9 +2565,9 @@ Identify(TwmWindow *t)
"Class.res_class = \"%s\"", t->class.res_class);
Info[n++][0] = '\0';
snprintf(Info[n++], INFO_SIZE,
- "Geometry/root = %dx%d+%d+%d", wwidth, wheight, x, y);
- snprintf(Info[n++], INFO_SIZE, "Border width = %d", bw);
- snprintf(Info[n++], INFO_SIZE, "Depth = %d", depth);
+ "Geometry/root = %ux%u+%d+%d", wwidth, wheight, x, y);
+ snprintf(Info[n++], INFO_SIZE, "Border width = %u", bw);
+ snprintf(Info[n++], INFO_SIZE, "Depth = %u", depth);
if (HasSync) {
int priority;
@@ -2570,8 +2583,9 @@ Identify(TwmWindow *t)
height = n * (Scr->DefaultFont.height + 2);
width = 1;
for (i = 0; i < n; i++) {
- twidth = MyFont_TextWidth(&Scr->DefaultFont, Info[i],
- (int) strlen(Info[i]));
+ int twidth = MyFont_TextWidth(&Scr->DefaultFont, Info[i],
+ (int) strlen(Info[i]));
+
if (twidth > width)
width = twidth;
}
@@ -2685,7 +2699,6 @@ WarpToScreen(int n, int inc)
static void
BumpWindowColormap(TwmWindow *tmp, int inc)
{
- int i, j, previously_installed;
ColormapWindow **cwins;
if (!tmp)
@@ -2695,6 +2708,9 @@ BumpWindowColormap(TwmWindow *tmp, int inc)
cwins =
malloc(sizeof(ColormapWindow *) * (size_t) tmp->cmaps.number_cwins);
if (cwins) {
+ int i;
+ int previously_installed;
+
/* SUPPRESS 560 */
if ((previously_installed = (Scr->cmapInfo.cmaps == &tmp->cmaps &&
tmp->cmaps.number_cwins))) {
@@ -2703,7 +2719,8 @@ BumpWindowColormap(TwmWindow *tmp, int inc)
}
for (i = 0; i < tmp->cmaps.number_cwins; i++) {
- j = i - inc;
+ int j = i - inc;
+
if (j >= tmp->cmaps.number_cwins)
j -= tmp->cmaps.number_cwins;
else if (j < 0)