1 /* Allocate X colors. Used for testing with dense colormaps.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
29 fatal (const char *fmt
, ...)
34 vfprintf (stderr
, fmt
, ap
);
41 usage (const char *progname
)
43 fprintf (stderr
, "Usage %s options\n", progname
);
44 fprintf (stderr
, "-n NCOLORS allcoate NCOLORS colors\n");
49 main (int argc
, char **argv
)
52 int opt
, ncolors
= 0, i
;
58 while ((opt
= getopt (argc
, argv
, "n:")) != EOF
)
62 ncolors
= atoi (optarg
);
72 dpy
= XOpenDisplay ("");
74 fatal ("Cannot open display");
75 cmap
= DefaultColormap (dpy
, 0);
77 allocated
= malloc (ncolors
* sizeof *allocated
);
79 memset (&color
, 0, sizeof color
);
81 while (nallocated
< ncolors
84 allocated
[nallocated
] = color
;
85 if (XAllocColor (dpy
, cmap
, &allocated
[nallocated
]))
87 for (i
= 0; i
< nallocated
; ++i
)
88 if (allocated
[i
].red
== allocated
[nallocated
].red
89 && allocated
[i
].green
== allocated
[nallocated
].green
90 && allocated
[i
].blue
== allocated
[nallocated
].blue
)
95 printf ("allocated %d/%d/%d\n",
96 allocated
[nallocated
].red
,
97 allocated
[nallocated
].green
,
98 allocated
[nallocated
].blue
);
108 fprintf (stderr
, "Waiting. Press ^C to stop.\n");
116 /* arch-tag: f1be90ac-5b70-43c2-835e-5a6432a25145
117 (do not change this comment) */