Files
nethack/win/X11/Window.c
PatR 9de8b03c03 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.
2015-05-06 00:59:15 -07:00

182 lines
5.9 KiB
C

/* NetHack 3.5 Window.c $NHDT-Date: 1430899134 2015/05/06 07:58:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */
/* NetHack 3.5 Window.c $Date: 2009/05/06 10:55:43 $ $Revision: 1.4 $ */
/* SCCS Id: @(#)Window.c 3.5 1993/02/02 */
/* Copyright (c) Dean Luick, 1992 */
/* NetHack may be freely redistributed. See license for details. */
/*
* Data structures and support routines for the Window widget. This is a
* drawing canvas with 16 colors and one font.
*/
#ifndef SYSV
#define PRESERVE_NO_SYSV /* X11 include files may define SYSV */
#endif
#ifdef MSDOS /* from compiler */
#define SHORT_FILENAMES
#endif
#ifdef SHORT_FILENAMES
#include <X11/IntrinsP.h>
#else
#include <X11/IntrinsicP.h>
#endif
#include <X11/StringDefs.h>
#ifdef PRESERVE_NO_SYSV
# ifdef SYSV
# undef SYSV
# endif
# undef PRESERVE_NO_SYSV
#endif
#include "xwindowp.h"
#include "config.h"
#include "lint.h"
static XtResource resources[] = {
#define offset(field) XtOffset(WindowWidget, window.field)
/* {name, class, type, size, offset, default_type, default_addr}, */
{ nhStr(XtNrows), nhStr(XtCRows), XtRDimension, sizeof(Dimension),
offset(rows), XtRImmediate, (XtPointer) 21},
{ nhStr(XtNcolumns), nhStr(XtCColumns), XtRDimension, sizeof(Dimension),
offset(columns), XtRImmediate, (XtPointer) 80},
{ nhStr(XtNforeground), XtCForeground, XtRPixel, sizeof(Pixel),
offset(foreground), XtRString, (XtPointer) XtDefaultForeground },
{ nhStr(XtNblack), XtCColor, XtRPixel, sizeof(Pixel),
offset(black), XtRString, (XtPointer) "black"},
{ nhStr(XtNred), XtCColor, XtRPixel, sizeof(Pixel),
offset(red), XtRString, (XtPointer) "red" },
{ nhStr(XtNgreen), XtCColor, XtRPixel, sizeof(Pixel),
offset(green), XtRString, (XtPointer) "pale green" },
{ nhStr(XtNbrown), XtCColor, XtRPixel, sizeof(Pixel),
offset(brown), XtRString, (XtPointer) "brown" },
{ nhStr(XtNblue), XtCColor, XtRPixel, sizeof(Pixel),
offset(blue), XtRString, (XtPointer) "blue" },
{ nhStr(XtNmagenta), XtCColor, XtRPixel, sizeof(Pixel),
offset(magenta), XtRString, (XtPointer) "magenta" },
{ nhStr(XtNcyan), XtCColor, XtRPixel, sizeof(Pixel),
offset(cyan), XtRString, (XtPointer) "light cyan" },
{ nhStr(XtNgray), XtCColor, XtRPixel, sizeof(Pixel),
offset(gray), XtRString, (XtPointer) "gray" },
{ nhStr(XtNorange), XtCColor, XtRPixel, sizeof(Pixel),
offset(orange), XtRString, (XtPointer) "orange" },
{ nhStr(XtNbright_green), XtCColor, XtRPixel, sizeof(Pixel),
offset(bright_green), XtRString, (XtPointer) "green" },
{ nhStr(XtNyellow), XtCColor, XtRPixel, sizeof(Pixel),
offset(yellow), XtRString, (XtPointer) "yellow" },
{ nhStr(XtNbright_blue), XtCColor, XtRPixel, sizeof(Pixel),
offset(bright_blue), XtRString, (XtPointer) "royal blue" },
{ nhStr(XtNbright_magenta), XtCColor, XtRPixel, sizeof(Pixel),
offset(bright_magenta), XtRString, (XtPointer) "violet" },
{ nhStr(XtNbright_cyan), XtCColor, XtRPixel, sizeof(Pixel),
offset(bright_cyan), XtRString, (XtPointer) "cyan" },
{ nhStr(XtNwhite), XtCColor, XtRPixel, sizeof(Pixel),
offset(white), XtRString, (XtPointer) "white" },
{ nhStr(XtNfont), XtCFont, XtRFontStruct, sizeof(XFontStruct *),
offset(font), XtRString, (XtPointer) XtDefaultFont },
{ nhStr(XtNexposeCallback), XtCCallback, XtRCallback, sizeof(XtCallbackList),
offset(expose_callback), XtRCallback, (char *)0 },
{ nhStr(XtNcallback), XtCCallback, XtRCallback, sizeof(XtCallbackList),
offset(input_callback), XtRCallback, (char *)0 },
{ nhStr(XtNresizeCallback), XtCCallback, XtRCallback, sizeof(XtCallbackList),
offset(resize_callback), XtRCallback, (char *)0 },
#undef offset
};
/* ARGSUSED */
static void no_op(w, event, params, num_params)
Widget w; /* unused */
XEvent *event; /* unused */
String *params; /* unused */
Cardinal *num_params; /* unused */
{
nhUse(w);
nhUse(event);
nhUse(params);
nhUse(num_params);
return;
}
static XtActionsRec actions[] =
{
{ nhStr("no-op"), no_op },
};
static char translations[] =
"<BtnDown>: input() \
";
/* ARGSUSED */
static void Redisplay(w, event, region)
Widget w;
XEvent *event;
Region region; /* unused */
{
nhUse(region);
/* This isn't correct - we need to call the callback with region. */
XtCallCallbacks(w, XtNexposeCallback, (caddr_t) event);
}
/* ARGSUSED */
static void Resize(w)
Widget w;
{
XtCallCallbacks(w, XtNresizeCallback, (caddr_t) 0);
}
WindowClassRec windowClassRec = {
{ /* core fields */
/* superclass */ (WidgetClass) &widgetClassRec,
/* class_name */ nhStr("Window"),
/* widget_size */ sizeof(WindowRec),
/* class_initialize */ 0,
/* class_part_initialize */ 0,
/* class_inited */ FALSE,
/* initialize */ 0,
/* initialize_hook */ 0,
/* realize */ XtInheritRealize,
/* actions */ actions,
/* num_actions */ XtNumber(actions),
/* resources */ resources,
/* num_resources */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure */ TRUE,
/* compress_enterleave */ TRUE,
/* visible_interest */ FALSE,
/* destroy */ 0,
/* resize */ Resize,
/* expose */ Redisplay,
/* set_values */ 0,
/* set_values_hook */ 0,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ 0,
/* accept_focus */ 0,
/* version */ XtVersion,
/* callback_private */ 0,
/* tm_table */ translations,
/* query_geometry */ XtInheritQueryGeometry,
/* display_accelerator */ XtInheritDisplayAccelerator,
/* extension */ 0
},
{ /* window fields */
/* empty */ 0
}
};
WidgetClass windowWidgetClass = (WidgetClass)&windowClassRec;
Font
WindowFont(w) Widget w; { return ((WindowWidget)w)->window.font->fid; }
XFontStruct *
WindowFontStruct(w) Widget w; { return ((WindowWidget)w)->window.font; }