Drop main() prototype. Syncs with NetBSD-8
[minix.git] / external / bsd / less / dist / scrsize.c
blob80214a584ae38fee503ec92dce3e1f7d6ef615ef
1 /* $NetBSD: scrsize.c,v 1.3 2013/09/04 19:44:21 tron Exp $ */
3 /*
4 * Copyright (C) 1984-2012 Mark Nudelman
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Less License, as specified in the README file.
9 * For more information, see the README file.
13 * This program is used to determine the screen dimensions on OS/2 systems.
14 * Adapted from code written by Kyosuke Tokoro (NBG01720@nifty.ne.jp).
18 * When I wrote this routine, I consulted some part of the source code
19 * of the xwininfo utility by X Consortium.
21 * Copyright (c) 1987, X Consortium
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated documentation files (the "Software"), to
25 * deal in the Software without restriction, including without limitation the
26 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
27 * sell copies of the Software, and to permit persons to whom the Software is
28 * furnished to do so, subject to the following conditions:
30 * The above copyright notice and this permission notice shall be included in
31 * all copies or substantial portions of the Software.
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
37 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
38 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 * Except as contained in this notice, the name of the X Consortium shall not
41 * be used in advertising or otherwise to promote the sale, use or other
42 * dealings in this Software without prior written authorization from the X
43 * Consortium.
45 #include <X11/Xlib.h>
46 #include <X11/Xutil.h>
47 #include <stdlib.h>
48 #include <stdio.h>
50 static int get_winsize(dpy, window, p_width, p_height)
51 Display *dpy;
52 Window window;
53 int *p_width;
54 int *p_height;
56 XWindowAttributes win_attributes;
57 XSizeHints hints;
58 long longjunk;
60 if (!XGetWindowAttributes(dpy, window, &win_attributes))
61 return 1;
62 if (!XGetWMNormalHints(dpy, window, &hints, &longjunk))
63 return 1;
64 if (!(hints.flags & PResizeInc))
65 return 1;
66 if (hints.width_inc == 0 || hints.height_inc == 0)
67 return 1;
68 if (!(hints.flags & (PBaseSize|PMinSize)))
69 return 1;
70 if (hints.flags & PBaseSize)
72 win_attributes.width -= hints.base_width;
73 win_attributes.height -= hints.base_height;
74 } else
76 win_attributes.width -= hints.min_width;
77 win_attributes.height -= hints.min_height;
79 *p_width = win_attributes.width / hints.width_inc;
80 *p_height = win_attributes.height / hints.height_inc;
81 return 0;
84 int main(argc, argv)
85 int argc;
86 char *argv[];
88 char *cp;
89 Display *dpy;
90 int size[2];
92 _scrsize(size);
93 cp = getenv("WINDOWID");
94 if (cp != NULL)
96 dpy = XOpenDisplay(NULL);
97 if (dpy != NULL)
99 get_winsize(dpy, (Window) atol(cp), &size[0], &size[1]);
100 XCloseDisplay(dpy);
103 printf("%i %i\n", size[0], size[1]);
104 return (0);