summaryrefslogtreecommitdiff
path: root/app/xwininfo/xwininfo.c
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@cvs.openbsd.org>2008-08-27 19:30:05 +0000
committerMatthieu Herrb <matthieu@cvs.openbsd.org>2008-08-27 19:30:05 +0000
commit11768cef4d667c23e1ede7f62449204e96a8bcec (patch)
tree33ee5c1e73601b49d2ea96ac485cf5a3ff12af7e /app/xwininfo/xwininfo.c
parent93c6ad16a956522203d13c16c0dc6e1c3c454a93 (diff)
xwininfo 1.0.4
Diffstat (limited to 'app/xwininfo/xwininfo.c')
-rw-r--r--app/xwininfo/xwininfo.c268
1 files changed, 142 insertions, 126 deletions
diff --git a/app/xwininfo/xwininfo.c b/app/xwininfo/xwininfo.c
index 1491c03ba..3f94b4276 100644
--- a/app/xwininfo/xwininfo.c
+++ b/app/xwininfo/xwininfo.c
@@ -1,4 +1,4 @@
-/* $XdotOrg: app/xwininfo/xwininfo.c,v 1.3 2006/03/10 02:37:18 alanc Exp $ */
+/* $XdotOrg: $ */
/* $Xorg: xwininfo.c,v 1.4 2001/02/09 02:06:04 xorgcvs Exp $ */
/*
@@ -45,12 +45,12 @@ of the copyright holder.
* 16-Jun-87
*/
+#include "config.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/Xos.h>
#include <X11/extensions/shape.h>
-#include <X11/Xmu/WinUtil.h>
#ifndef NO_I18N
#include <X11/Xlocale.h>
#endif
@@ -62,32 +62,49 @@ of the copyright holder.
typedef struct {
long code;
- char *name;
+ const char *name;
} binding;
-void scale_init(void);
-char *nscale(int, int, int, char *);
-char *xscale(int);
-char *yscale(int);
-char *bscale(int);
-int bad_window_handler(Display *, XErrorEvent *);
+static void scale_init(void);
+static char *nscale(int, int, int, char *, size_t);
+static char *xscale(int);
+static char *yscale(int);
+static char *bscale(int);
+static int bad_window_handler(Display *, XErrorEvent *);
int main(int, char **);
-char *LookupL(long, binding *);
-char *Lookup(int, binding *);
-void Display_Window_Id(Window, int);
-void Display_Stats_Info(Window);
-void Display_Bits_Info(Window);
-void Display_Event_Mask(long);
-void Display_Events_Info(Window);
-void Display_Tree_Info(Window, int);
-void display_tree_info_1(Window, int, int);
-void Display_Hints(XSizeHints *);
-void Display_Size_Hints(Window);
-void Display_Window_Shape(Window);
-void Display_WM_Info(Window);
+static const char *LookupL(long, const binding *);
+static const char *Lookup(int, const binding *);
+static void Display_Window_Id(Window, int);
+static void Display_Stats_Info(Window);
+static void Display_Bits_Info(Window);
+static void Display_Event_Mask(long);
+static void Display_Events_Info(Window);
+static void Display_Tree_Info(Window, int);
+static void display_tree_info_1(Window, int, int);
+static void Display_Hints(XSizeHints *);
+static void Display_Size_Hints(Window);
+static void Display_Window_Shape(Window);
+static void Display_WM_Info(Window);
static char *window_id_format = "0x%lx";
+#ifndef HAVE_STRLCAT
+static size_t strlcat(char *dst, const char *src, size_t dstsize)
+{
+ size_t sd = strlen(dst);
+ size_t ss = strlen(src);
+ size_t s = sd + ss;
+
+ if (s < dstsize) {
+ strcpy(dst + sd, src);
+ } else {
+ strncpy(dst + sd, src, dstsize-sd-1);
+ dst[dstsize] = '\0';
+ }
+ return s;
+}
+#endif
+
/*
* Report the syntax for calling xwininfo:
*/
@@ -151,12 +168,12 @@ usage(void)
*/
#define getdsp(var,fn) var = fn(dpy, DefaultScreen(dpy))
-int xp=0, xmm=0;
-int yp=0, ymm=0;
-int bp=0, bmm=0;
-int english = 0, metric = 0;
+static int xp=0, xmm=0;
+static int yp=0, ymm=0;
+static int bp=0, bmm=0;
+static int english = 0, metric = 0;
-void
+static void
scale_init(void)
{
getdsp(yp, DisplayHeight);
@@ -171,87 +188,95 @@ scale_init(void)
#define YARD (3*12)
#define FOOT (12)
-char *
-nscale(int n, int np, int nmm, char *nbuf)
+static char *
+nscale(int n, int np, int nmm, char *nbuf, size_t nbufsize)
{
- sprintf(nbuf, "%d", n);
- if(metric||english) {
- sprintf(nbuf+strlen(nbuf), " (");
- }
- if(metric) {
- sprintf(nbuf+strlen(nbuf),"%.2f mm%s", ((double) n)*nmm/np, english?"; ":"");
- }
- if(english) {
- double inch_frac;
- Bool printed_anything = False;
- int mi, yar, ft, inr;
-
- inch_frac = ((double) n)*(nmm/25.4)/np;
- inr = (int)inch_frac;
- inch_frac -= (double)inr;
- if(inr>=MILE) {
- mi = inr/MILE;
- inr %= MILE;
- sprintf(nbuf+strlen(nbuf), "%d %s(?!?)",
- mi, (mi==1)?"mile":"miles");
- printed_anything = True;
- }
- if(inr>=YARD) {
- yar = inr/YARD;
- inr %= YARD;
- if (printed_anything)
- sprintf(nbuf+strlen(nbuf), ", ");
- sprintf(nbuf+strlen(nbuf), "%d %s",
- yar, (yar==1)?"yard":"yards");
- printed_anything = True;
- }
- if(inr>=FOOT) {
- ft = inr/FOOT;
- inr %= FOOT;
- if (printed_anything)
- sprintf(nbuf+strlen(nbuf), ", ");
- sprintf(nbuf+strlen(nbuf), "%d %s",
- ft, (ft==1)?"foot":"feet");
- printed_anything = True;
- }
- if (!printed_anything || inch_frac != 0.0 || inr != 0) {
- if (printed_anything)
- sprintf(nbuf+strlen(nbuf), ", ");
- sprintf(nbuf+strlen(nbuf), "%.2f inches", inr+inch_frac);
+ int s;
+ snprintf(nbuf, nbufsize, "%d", n);
+
+ if (metric||english) {
+ s = strlcat(nbuf, " (", nbufsize);
+
+ if (metric) {
+ snprintf(nbuf+s, nbufsize-s, "%.2f mm%s",
+ ((double) n)*nmm/np, english ? "; " : "");
+ }
+ if (english) {
+ double inch_frac;
+ Bool printed_anything = False;
+ int mi, yar, ft, inr;
+
+ inch_frac = ((double) n)*(nmm/25.4)/np;
+ inr = (int)inch_frac;
+ inch_frac -= (double)inr;
+ if (inr >= MILE) {
+ mi = inr/MILE;
+ inr %= MILE;
+ s = strlen(nbuf);
+ snprintf(nbuf+s, nbufsize-s, "%d %s(?!?)",
+ mi, (mi==1) ? "mile" : "miles");
+ printed_anything = True;
+ }
+ if (inr >= YARD) {
+ yar = inr/YARD;
+ inr %= YARD;
+ if (printed_anything)
+ strlcat(nbuf, ", ", nbufsize);
+ s = strlen(nbuf);
+ snprintf(nbuf+s, nbufsize-s, "%d %s",
+ yar, (yar==1) ? "yard" : "yards");
+ printed_anything = True;
+ }
+ if (inr >= FOOT) {
+ ft = inr/FOOT;
+ inr %= FOOT;
+ if (printed_anything)
+ strlcat(nbuf, ", ", nbufsize);
+ s = strlen(nbuf);
+ snprintf(nbuf+s, nbufsize-s, "%d %s",
+ ft, (ft==1) ? "foot" : "feet");
+ printed_anything = True;
+ }
+ if (!printed_anything || inch_frac != 0.0 || inr != 0) {
+ if (printed_anything)
+ strlcat(nbuf, ", ", nbufsize);
+ s = strlen(nbuf);
+ snprintf(nbuf+s, nbufsize-s, "%.2f inches", inr+inch_frac);
+ }
+ }
+ strlcat (nbuf, ")", nbufsize);
}
- }
- if (english || metric) strcat (nbuf, ")");
- return(nbuf);
+ return(nbuf);
}
-char xbuf[BUFSIZ];
-char *
+static char xbuf[BUFSIZ];
+static char *
xscale(int x)
{
if(!xp) {
scale_init();
}
- return(nscale(x, xp, xmm, xbuf));
+ return(nscale(x, xp, xmm, xbuf, sizeof(xbuf)));
}
-char ybuf[BUFSIZ];
-char *
+static char ybuf[BUFSIZ];
+static char *
yscale(int y)
{
if(!yp) {
scale_init();
}
- return(nscale(y, yp, ymm, ybuf));
+ return(nscale(y, yp, ymm, ybuf, sizeof(ybuf)));
}
-char bbuf[BUFSIZ];
-char *
+static char bbuf[BUFSIZ];
+static char *
bscale(int b)
{
if(!bp) {
scale_init();
}
- return(nscale(b, bp, bmm, bbuf));
+ return(nscale(b, bp, bmm, bbuf, sizeof(bbuf)));
}
/* end of pixel to inch, metric converter */
@@ -260,12 +285,12 @@ bscale(int b)
to see if the -id the user specified is valid. */
/* ARGSUSED */
-int
+static int
bad_window_handler(Display *disp, XErrorEvent *err)
{
char badid[20];
- sprintf(badid, window_id_format, err->resourceid);
+ snprintf(badid, sizeof(badid), window_id_format, err->resourceid);
Fatal_Error("No such window with id %s.", badid);
exit (1);
return 0;
@@ -362,17 +387,7 @@ main(int argc, char **argv)
printf("xwininfo: Please select the window about which you\n");
printf(" would like information by clicking the\n");
printf(" mouse in that window.\n");
- window = Select_Window(dpy);
- if (window && !frame) {
- Window root;
- int dummyi;
- unsigned int dummy;
-
- if (XGetGeometry (dpy, window, &root, &dummyi, &dummyi,
- &dummy, &dummy, &dummy, &dummy) &&
- window != root)
- window = XmuClientWindow (dpy, window);
- }
+ window = Select_Window(dpy, !frame);
}
/*
@@ -422,12 +437,13 @@ main(int argc, char **argv)
*/
static char _lookup_buffer[100];
-char *
-LookupL(long code, binding *table)
+static const char *
+LookupL(long code, const binding *table)
{
- char *name;
+ const char *name;
- sprintf(_lookup_buffer, "unknown (code = %ld. = 0x%lx)", code, code);
+ snprintf(_lookup_buffer, sizeof(_lookup_buffer),
+ "unknown (code = %ld. = 0x%lx)", code, code);
name = _lookup_buffer;
while (table->name) {
@@ -441,8 +457,8 @@ LookupL(long code, binding *table)
return(name);
}
-char *
-Lookup(int code, binding *table)
+static const char *
+Lookup(int code, const binding *table)
{
return LookupL((long)code, table);
}
@@ -451,7 +467,7 @@ Lookup(int code, binding *table)
* Routine to display a window id in dec/hex with name if window has one
*/
-void
+static void
Display_Window_Id(Window window, Bool newline_wanted)
{
#ifdef NO_I18N
@@ -509,24 +525,24 @@ Display_Window_Id(Window window, Bool newline_wanted)
/*
* Display Stats on window
*/
-static binding _window_classes[] = {
+static const binding _window_classes[] = {
{ InputOutput, "InputOutput" },
{ InputOnly, "InputOnly" },
{ 0, 0 } };
-static binding _map_states[] = {
+static const binding _map_states[] = {
{ IsUnmapped, "IsUnMapped" },
{ IsUnviewable, "IsUnviewable" },
{ IsViewable, "IsViewable" },
{ 0, 0 } };
-static binding _backing_store_states[] = {
+static const binding _backing_store_states[] = {
{ NotUseful, "NotUseful" },
{ WhenMapped, "WhenMapped" },
{ Always, "Always" },
{ 0, 0 } };
-static binding _bit_gravity_states[] = {
+static const binding _bit_gravity_states[] = {
{ ForgetGravity, "ForgetGravity" },
{ NorthWestGravity, "NorthWestGravity" },
{ NorthGravity, "NorthGravity" },
@@ -540,7 +556,7 @@ static binding _bit_gravity_states[] = {
{ StaticGravity, "StaticGravity" },
{ 0, 0 }};
-static binding _window_gravity_states[] = {
+static const binding _window_gravity_states[] = {
{ UnmapGravity, "UnmapGravity" },
{ NorthWestGravity, "NorthWestGravity" },
{ NorthGravity, "NorthGravity" },
@@ -554,7 +570,7 @@ static binding _window_gravity_states[] = {
{ StaticGravity, "StaticGravity" },
{ 0, 0 }};
-static binding _visual_classes[] = {
+static const binding _visual_classes[] = {
{ StaticGray, "StaticGray" },
{ GrayScale, "GrayScale" },
{ StaticColor, "StaticColor" },
@@ -563,7 +579,7 @@ static binding _visual_classes[] = {
{ DirectColor, "DirectColor" },
{ 0, 0 }};
-void
+static void
Display_Stats_Info(Window window)
{
XWindowAttributes win_attributes;
@@ -730,7 +746,7 @@ Display_Stats_Info(Window window)
/*
* Display bits info:
*/
-static binding _gravities[] = {
+static const binding _gravities[] = {
{ UnmapGravity, "UnMapGravity" }, /* WARNING: both of these have*/
{ ForgetGravity, "ForgetGravity" }, /* the same value - see code */
{ NorthWestGravity, "NorthWestGravity" },
@@ -745,18 +761,18 @@ static binding _gravities[] = {
{ StaticGravity, "StaticGravity" },
{ 0, 0 } };
-static binding _backing_store_hint[] = {
+static const binding _backing_store_hint[] = {
{ NotUseful, "NotUseful" },
{ WhenMapped, "WhenMapped" },
{ Always, "Always" },
{ 0, 0 } };
-static binding _bool[] = {
+static const binding _bool[] = {
{ 0, "No" },
{ 1, "Yes" },
{ 0, 0 } };
-void
+static void
Display_Bits_Info(Window window)
{
XWindowAttributes win_attributes;
@@ -782,7 +798,7 @@ Display_Bits_Info(Window window)
/*
* Routine to display all events in an event mask
*/
-static binding _event_mask_names[] = {
+static const binding _event_mask_names[] = {
{ KeyPressMask, "KeyPress" },
{ KeyReleaseMask, "KeyRelease" },
{ ButtonPressMask, "ButtonPress" },
@@ -810,7 +826,7 @@ static binding _event_mask_names[] = {
{ OwnerGrabButtonMask, "OwnerGrabButton" },
{ 0, 0 } };
-void
+static void
Display_Event_Mask(long mask)
{
long bit, bit_mask;
@@ -825,7 +841,7 @@ Display_Event_Mask(long mask)
/*
* Display info on events
*/
-void
+static void
Display_Events_Info(Window window)
{
XWindowAttributes win_attributes;
@@ -854,7 +870,7 @@ Display_Events_Info(Window window)
* Display root, parent, and (recursively) children information
* recurse - true to show children information
*/
-void
+static void
Display_Tree_Info(Window window, int recurse)
{
display_tree_info_1(window, recurse, 0);
@@ -863,7 +879,7 @@ Display_Tree_Info(Window window, int recurse)
/*
* level - recursion level
*/
-void
+static void
display_tree_info_1(Window window, int recurse, int level)
{
int i, j;
@@ -935,7 +951,7 @@ display_tree_info_1(Window window, int recurse, int level)
/*
* Display a set of size hints
*/
-void
+static void
Display_Hints(XSizeHints *hints)
{
long flags;
@@ -1013,7 +1029,7 @@ Display_Hints(XSizeHints *hints)
/*
* Display Size Hints info
*/
-void
+static void
Display_Size_Hints(Window window)
{
XSizeHints *hints = XAllocSizeHints();
@@ -1039,7 +1055,7 @@ Display_Size_Hints(Window window)
}
-void
+static void
Display_Window_Shape (Window window)
{
Bool ws, bs;
@@ -1071,7 +1087,7 @@ Display_Window_Shape (Window window)
/*
* Display Window Manager Info
*/
-static binding _state_hints[] = {
+static const binding _state_hints[] = {
{ DontCareState, "Don't Care State" },
{ NormalState, "Normal State" },
{ ZoomState, "Zoomed State" },
@@ -1079,7 +1095,7 @@ static binding _state_hints[] = {
{ InactiveState, "Inactive State" },
{ 0, 0 } };
-void
+static void
Display_WM_Info(Window window)
{
XWMHints *wmhints;