X11 lint suppression
Suppress close to 400 warnings generated by gcc on the win/X11/*.c code,
most due to -Wwrite-strings which makes string literals implicitly have
the 'const' attribute. (Since modifying a string literal results in
undefined behavior, that is an appropriate check to have enabled, but
it can be troublesome since string literals have type 'char *' and code
that uses them that way is correct provided it avoids modifying them.)
113 warning: initialization discards qualifiers from pointer target type
127 warning: assignment discards qualifiers from pointer target type
29 warning: passing argument discards qualifiers from pointer target type
109 warning: unused parameter
12 warning: comparison between signed and unsigned
The nhStr() hack casts to 'char *', explicitly removing 'const', for
situations where it isn't feasible to make code directly honor const.
The vast marjority of uses are for the second parameter to XtSetArg(),
which is a macro that actually performs an assignment with the second
argument rather than passing it in a function. It takes values like
'XtNtop', which doesn't need to be altered (although in many places I
changed that to nhStr(XtNtop) for uniformity with the surrounding code,
and 'XtNbottom', which does need to have the extra const stripping to
avoid a warning. Go figure.
The nhUse() hack actually uses its argument in a meaningless way if the
code is compiled with FORCE_ARG_USAGE defined. When GCC_WARN is defined,
FORCE_ARG_USAGE will be enabled if it hasn't been already. Example:
/*ARGUSED*/
int foo(arg)
int arg; /* not used */
{
+ nhUse(arg);
return 0;
}
The extra line will expand to ';' when FORCE_ARG_USAGE is not defined
or too
nhUse_dummy += (unsigned)arg;
when it is. I figured direct assignment might lead to a different
warning by some compilers in a situation like
nhUse(arg);
nhUse(otherarg);
where the first assignment would be clobbered by the second, and using
bitwise operations or safer '+= (arg != 0)' would most likely generate
more non-useful code. Some tweaking might turn out to be necessary.
This commit is contained in:
+25
-11
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.5 wintext.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.5 wintext.c $NHDT-Date: 1430899138 2015/05/06 07:58:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
|
||||
/* NetHack 3.5 wintext.c $Date: 2012/01/24 04:26:27 $ $Revision: 1.7 $ */
|
||||
/* SCCS Id: @(#)wintext.c 3.5 1996/04/05 */
|
||||
/* Copyright (c) Dean Luick, 1992 */
|
||||
@@ -66,6 +66,10 @@ delete_text(w, event, params, num_params)
|
||||
struct xwindow *wp;
|
||||
struct text_info_t *text_info;
|
||||
|
||||
nhUse(event);
|
||||
nhUse(params);
|
||||
nhUse(num_params);
|
||||
|
||||
wp = find_widget(w);
|
||||
text_info = wp->text_information;
|
||||
|
||||
@@ -94,6 +98,10 @@ dismiss_text(w, event, params, num_params)
|
||||
struct xwindow *wp;
|
||||
struct text_info_t *text_info;
|
||||
|
||||
nhUse(event);
|
||||
nhUse(params);
|
||||
nhUse(num_params);
|
||||
|
||||
wp = find_widget(w);
|
||||
text_info = wp->text_information;
|
||||
|
||||
@@ -142,6 +150,8 @@ add_to_text_window(wp, attr, str)
|
||||
struct text_info_t *text_info = wp->text_information;
|
||||
int width;
|
||||
|
||||
nhUse(attr);
|
||||
|
||||
append_text_buffer(&text_info->text, str, FALSE);
|
||||
|
||||
/* Calculate text width and save longest line */
|
||||
@@ -223,12 +233,12 @@ display_text_window(wp, blocking)
|
||||
/* if added before the window is displayed, so do it afterward. */
|
||||
num_args = 0;
|
||||
if (nlines < text_info->text.num_lines) { /* add vert scrollbar */
|
||||
XtSetArg(args[num_args], XtNscrollVertical, XawtextScrollAlways);
|
||||
num_args++;
|
||||
XtSetArg(args[num_args], nhStr(XtNscrollVertical),
|
||||
XawtextScrollAlways); num_args++;
|
||||
}
|
||||
if (width >= (Dimension) (XtScreen(wp->w)->width-20)) { /* too wide */
|
||||
XtSetArg(args[num_args], XtNscrollHorizontal, XawtextScrollAlways);
|
||||
num_args++;
|
||||
XtSetArg(args[num_args], nhStr(XtNscrollHorizontal),
|
||||
XawtextScrollAlways); num_args++;
|
||||
}
|
||||
if (num_args) XtSetValues(wp->w, args, num_args);
|
||||
|
||||
@@ -286,7 +296,7 @@ create_text_window(wp)
|
||||
args, num_args);
|
||||
|
||||
num_args = 0;
|
||||
XtSetArg(args[num_args], XtNdisplayCaret, False); num_args++;
|
||||
XtSetArg(args[num_args], nhStr(XtNdisplayCaret), False); num_args++;
|
||||
XtSetArg(args[num_args], XtNresize, XawtextResizeBoth); num_args++;
|
||||
XtSetArg(args[num_args], XtNtranslations,
|
||||
XtParseTranslationTable(text_translations)); num_args++;
|
||||
@@ -301,11 +311,15 @@ create_text_window(wp)
|
||||
|
||||
/* Get the font and margin information. */
|
||||
num_args = 0;
|
||||
XtSetArg(args[num_args], XtNfont, &text_info->fs); num_args++;
|
||||
XtSetArg(args[num_args], XtNtopMargin, &top_margin); num_args++;
|
||||
XtSetArg(args[num_args], XtNbottomMargin, &bottom_margin); num_args++;
|
||||
XtSetArg(args[num_args], XtNleftMargin, &left_margin); num_args++;
|
||||
XtSetArg(args[num_args], XtNrightMargin, &right_margin); num_args++;
|
||||
XtSetArg(args[num_args], XtNfont, &text_info->fs); num_args++;
|
||||
XtSetArg(args[num_args], nhStr(XtNtopMargin),
|
||||
&top_margin); num_args++;
|
||||
XtSetArg(args[num_args], nhStr(XtNbottomMargin),
|
||||
&bottom_margin); num_args++;
|
||||
XtSetArg(args[num_args], nhStr(XtNleftMargin),
|
||||
&left_margin); num_args++;
|
||||
XtSetArg(args[num_args], nhStr(XtNrightMargin),
|
||||
&right_margin); num_args++;
|
||||
XtGetValues(wp->w, args, num_args);
|
||||
|
||||
text_info->extra_width = left_margin + right_margin;
|
||||
|
||||
Reference in New Issue
Block a user