From 24bfa418612288c4847bcfe088aba05ce402d1d2 Mon Sep 17 00:00:00 2001 From: Tim Wiederhake Date: Sat, 20 Jan 2024 16:07:00 +0100 Subject: Rework dummy variable usage in do_string_keyword twm defines several "junk" variables to use with functions like XQueryPointer or XGetGeometry. In some instances, the returned values are actually used, which makes the code confusing and hard to reason about. Use dedicated variables in those cases. Signed-off-by: Tim Wiederhake --- src/parse.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/parse.c') diff --git a/src/parse.c b/src/parse.c index 48430b3..3a93806 100644 --- a/src/parse.c +++ b/src/parse.c @@ -747,6 +747,10 @@ do_single_keyword(int keyword) int do_string_keyword(int keyword, char *s) { + unsigned width = 0; + unsigned height = 0; + unsigned mask = 0; + switch (keyword) { case kws_UsePPosition: { @@ -797,20 +801,18 @@ do_string_keyword(int keyword, char *s) return 1; case kws_MaxWindowSize: - JunkMask = - (unsigned) XParseGeometry(s, &JunkX, &JunkY, &JunkWidth, - &JunkHeight); - if ((JunkMask & (WidthValue | HeightValue)) != + mask = (unsigned) XParseGeometry(s, &JunkX, &JunkY, &width, &height); + if ((mask & (WidthValue | HeightValue)) != (WidthValue | HeightValue)) { parseWarning("bad MaxWindowSize \"%s\"", s); return 0; } - if (JunkWidth <= 0 || JunkHeight <= 0) { + if (width <= 0 || height <= 0) { parseWarning("MaxWindowSize \"%s\" must be positive", s); return 0; } - Scr->MaxWindowWidth = (int) JunkWidth; - Scr->MaxWindowHeight = (int) JunkHeight; + Scr->MaxWindowWidth = (int) width; + Scr->MaxWindowHeight = (int) height; return 1; } -- cgit v1.2.3 From c5a63751f8b4eab72794e56365ead929023f2b94 Mon Sep 17 00:00:00 2001 From: Tim Wiederhake Date: Sat, 20 Jan 2024 16:07:00 +0100 Subject: Remove global variables JunkX, JunkY Replace with a local variable following the naming scheme from Identify() in src/menus.c. Signed-off-by: Tim Wiederhake --- src/parse.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/parse.c') diff --git a/src/parse.c b/src/parse.c index 3a93806..eae817e 100644 --- a/src/parse.c +++ b/src/parse.c @@ -750,6 +750,7 @@ do_string_keyword(int keyword, char *s) unsigned width = 0; unsigned height = 0; unsigned mask = 0; + int dummy = 0; switch (keyword) { case kws_UsePPosition: @@ -801,7 +802,7 @@ do_string_keyword(int keyword, char *s) return 1; case kws_MaxWindowSize: - mask = (unsigned) XParseGeometry(s, &JunkX, &JunkY, &width, &height); + mask = (unsigned) XParseGeometry(s, &dummy, &dummy, &width, &height); if ((mask & (WidthValue | HeightValue)) != (WidthValue | HeightValue)) { parseWarning("bad MaxWindowSize \"%s\"", s); -- cgit v1.2.3 From a0a4604cab350eb6a8bd3cc56cfb35d534fa344b Mon Sep 17 00:00:00 2001 From: Tim Wiederhake Date: Sat, 30 Dec 2023 20:49:48 +0100 Subject: Remove storage specifier 'register' 'register' is an optimization hint to the compiler that is generally not necessary and needlessly prevents using a c++ compiler to compile twm. Signed-off-by: Tim Wiederhake --- src/parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/parse.c') diff --git a/src/parse.c b/src/parse.c index eae817e..0ad806e 100644 --- a/src/parse.c +++ b/src/parse.c @@ -602,7 +602,7 @@ static int numkeywords = (sizeof(keytable) / sizeof(keytable[0])); int parse_keyword(char *s, int *nump) { - register int lower = 0, upper = numkeywords - 1; + int lower = 0, upper = numkeywords - 1; XmuCopyISOLatin1Lowered(s, s); while (lower <= upper) { -- cgit v1.2.3 From 365a94b62df6144ad016e587f3756d974b6e2018 Mon Sep 17 00:00:00 2001 From: Tim Wiederhake Date: Sat, 30 Dec 2023 20:49:48 +0100 Subject: Add explicit cast after memory allocation Still valid c, but now also valid c++. Signed-off-by: Tim Wiederhake --- src/parse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/parse.c') diff --git a/src/parse.c b/src/parse.c index 0ad806e..4ffc4aa 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1037,7 +1037,7 @@ do_var_savecolor(int key) Cptr cptrav, cpnew; if (!chead) { - chead = malloc(sizeof(Cnode)); + chead = (Cnode *) malloc(sizeof(Cnode)); chead->i = key; chead->next = NULL; } @@ -1046,7 +1046,7 @@ do_var_savecolor(int key) while (cptrav->next != NULL) { cptrav = cptrav->next; } - cpnew = malloc(sizeof(Cnode)); + cpnew = (Cnode *) malloc(sizeof(Cnode)); cpnew->i = key; cpnew->next = NULL; cptrav->next = cpnew; @@ -1155,7 +1155,7 @@ do_squeeze_entry(name_list ** list, char *name, int justify, int num, int denom) if (HasShape) { SqueezeInfo *sinfo; - sinfo = malloc(sizeof(SqueezeInfo)); + sinfo = (SqueezeInfo *) malloc(sizeof(SqueezeInfo)); if (!sinfo) { parseWarning("unable to allocate %lu bytes for squeeze info", -- cgit v1.2.3 From 4b01408715cd10e3bf02eb1e87531917a09c2645 Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Tue, 5 Mar 2024 03:43:57 -0500 Subject: include "gram.h" only from "parse.h" all of the users of (generated) gram.h rely upon (custom) parse.h, and the order of those headers affects portability. Signed-off-by: Thomas E. Dickey --- src/parse.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/parse.c') diff --git a/src/parse.c b/src/parse.c index 4ffc4aa..c659e53 100644 --- a/src/parse.c +++ b/src/parse.c @@ -66,7 +66,6 @@ in this Software without prior written authorization from The Open Group. #include "screen.h" #include "menus.h" #include "util.h" -#include "gram.h" #include "parse.h" #include -- cgit v1.2.3 From 451e1b036d3dd0fddcf54733b5616169ed5ad570 Mon Sep 17 00:00:00 2001 From: Tim Wiederhake Date: Sun, 3 Mar 2024 12:55:11 +0100 Subject: Provide defaults for externally defined symbols AM_CPPFLAGS defines several symbols that do not have to be there. By providing default values in twm.h, this list can be reduced in size while still allowing to override these values. Signed-off-by: Tim Wiederhake --- src/parse.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/parse.c') diff --git a/src/parse.c b/src/parse.c index c659e53..c841489 100644 --- a/src/parse.c +++ b/src/parse.c @@ -71,9 +71,6 @@ in this Software without prior written authorization from The Open Group. #include #include -#ifndef SYSTEM_INIT_FILE -#define SYSTEM_INIT_FILE "/usr/lib/X11/twm/system.twmrc" -#endif #define BUF_LEN 300 static FILE *twmrc; @@ -200,7 +197,7 @@ ParseTwmrc(char *filename) break; case 3: /* system.twmrc */ - cp = SYSTEM_INIT_FILE; + cp = DATADIR "/X11/twm/system.twmrc"; break; } -- cgit v1.2.3