summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xstdcmap.c369
-rw-r--r--xstdcmap.man110
2 files changed, 479 insertions, 0 deletions
diff --git a/xstdcmap.c b/xstdcmap.c
new file mode 100644
index 0000000..726b610
--- /dev/null
+++ b/xstdcmap.c
@@ -0,0 +1,369 @@
+/*
+ * $Xorg: xstdcmap.c,v 1.5 2001/02/09 02:06:01 xorgcvs Exp $
+ *
+ *
+Copyright 1989, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+ * *
+ * Author: Donna Converse, MIT X Consortium
+ */
+
+#include <stdio.h>
+#include <X11/Xos.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xresource.h>
+#include <X11/Xatom.h>
+#include <X11/Xmu/StdCmap.h>
+
+extern void exit();
+
+#define REPLACE 1
+#define DO_NOT_REPLACE 0
+#define RETAIN 1
+#define DO_NOT_RETAIN 0
+
+static char *display_name = NULL;
+static char *program_name = NULL;
+static Bool all = 0;
+static Bool help = 0;
+static Bool verbose = 0;
+static Display *dpy = NULL;
+
+typedef struct
+{
+ Bool create;
+ Bool delete;
+ Atom property;
+ char *name;
+ char *nickname;
+} colormap_property;
+
+static colormap_property propertyTable[]=
+{
+{0, 0, XA_RGB_DEFAULT_MAP, "RGB_DEFAULT_MAP", "default"},
+{0, 0, XA_RGB_BEST_MAP, "RGB_BEST_MAP", "best"},
+{0, 0, XA_RGB_GRAY_MAP, "RGB_GRAY_MAP", "gray"},
+{0, 0, XA_RGB_RED_MAP, "RGB_RED_MAP", "red"},
+{0, 0, XA_RGB_GREEN_MAP, "RGB_GREEN_MAP", "green"},
+{0, 0, XA_RGB_BLUE_MAP, "RGB_BLUE_MAP", "blue"},
+};
+#define NPROPERTIES (sizeof propertyTable / sizeof propertyTable[0])
+
+#define DEFAULT 0
+#define BEST 1
+#define GRAY 2
+#define RED 3
+#define GREEN 4
+#define BLUE 5
+
+static char *usage_message[]=
+{
+" -all make all standard colormaps for the display",
+" -best make the RGB_BEST_MAP",
+" -blue make the RGB_BLUE_MAP",
+" -default make the RGB_DEFAULT_MAP",
+" -delete name remove a standard colormap",
+" -display dpy X server to use",
+" -gray make the RGB_GRAY_MAP",
+" -green make the RGB_GREEN_MAP",
+" -red make the RGB_RED_MAP",
+" -verbose turn on logging",
+"",
+NULL };
+
+static XrmOptionDescRec optionTable[]=
+{
+{"-all", ".all", XrmoptionNoArg, (caddr_t) "on"},
+{"-best", ".best", XrmoptionNoArg, (caddr_t) "on"},
+{"-blue", ".blue", XrmoptionNoArg, (caddr_t) "on"},
+{"-default", ".default", XrmoptionNoArg, (caddr_t) "on"},
+{"-delete", ".delete", XrmoptionSepArg, (caddr_t) NULL},
+{"-display", ".display", XrmoptionSepArg, (caddr_t) NULL},
+{"-gray", ".gray", XrmoptionNoArg, (caddr_t) "on"},
+{"-green", ".green", XrmoptionNoArg, (caddr_t) "on"},
+{"-help", ".help", XrmoptionNoArg, (caddr_t) "on"},
+{"-red", ".red", XrmoptionNoArg, (caddr_t) "on"},
+{"-verbose", ".verbose", XrmoptionNoArg, (caddr_t) "on"},
+};
+#define NOPTIONS (sizeof optionTable / sizeof optionTable[0])
+
+static void parse(argc, argv)
+ int argc;
+ char **argv;
+{
+ XrmDatabase database = NULL;
+ char *type;
+ XrmValue value;
+ char option[512];
+
+ if (argc == 1)
+ usage(0);
+
+ XrmInitialize();
+ XrmParseCommand(&database, optionTable, NOPTIONS, program_name, &argc,
+ argv);
+ if (--argc)
+ usage(1);
+
+ (void) sprintf(option, "%s%s", program_name, ".all");
+ if (XrmGetResource(database, option, (char *) NULL, &type, &value))
+ all++;
+
+ (void) sprintf(option, "%s%s", program_name, ".best");
+ if (XrmGetResource(database, option, (char *) NULL, &type, &value))
+ propertyTable[BEST].create++;
+
+ (void) sprintf(option, "%s%s", program_name, ".blue");
+ if (XrmGetResource(database, option, (char *) NULL, &type, &value))
+ propertyTable[BLUE].create++;
+
+ (void) sprintf(option, "%s%s", program_name, ".default");
+ if (XrmGetResource(database, option, (char *) NULL, &type, &value))
+ propertyTable[DEFAULT].create++;
+
+ (void) sprintf(option, "%s%s", program_name, ".delete");
+ if (XrmGetResource(database, option, (char *) NULL, &type, &value)) {
+ register int i;
+ for (i=0; i < NPROPERTIES; i++) {
+ if (strcmp((char *) value.addr, propertyTable[i].nickname) == 0) {
+ propertyTable[i].delete++;
+ break;
+ }
+ if (strcmp((char *) value.addr, "all") == 0)
+ propertyTable[i].delete++;
+ }
+ }
+
+ (void) sprintf(option, "%s%s", program_name, ".display");
+ if (XrmGetResource(database, option, (char *) NULL, &type, &value))
+ display_name = value.addr;
+
+ (void) sprintf(option, "%s%s", program_name, ".gray");
+ if (XrmGetResource(database, option, (char *) NULL, &type, &value))
+ propertyTable[GRAY].create++;
+
+ (void) sprintf(option, "%s%s", program_name, ".green");
+ if (XrmGetResource(database, option, (char *) NULL, &type, &value))
+ propertyTable[GREEN].create++;
+
+ (void) sprintf(option, "%s%s", program_name, ".help");
+ if (XrmGetResource(database, option, (char *) NULL, &type, &value))
+ help++;
+
+ (void) sprintf(option, "%s%s", program_name, ".red");
+ if (XrmGetResource(database, option, (char *) NULL, &type, &value))
+ propertyTable[RED].create++;
+
+ (void) sprintf(option, "%s%s", program_name, ".verbose");
+ if (XrmGetResource(database, option, (char *) NULL, &type, &value))
+ verbose++;
+}
+
+Exit(status)
+ Status status;
+{
+ if (dpy)
+ XCloseDisplay(dpy);
+ exit(status);
+}
+
+usage(status)
+ Status status;
+{
+ register char **i;
+ (void) fprintf(stderr, "usage: %s [-options]\n\n", program_name);
+ (void) fprintf(stderr, "where options include:\n");
+ for (i = usage_message; *i != NULL; i++)
+ (void) fprintf(stderr, "%s\n", *i);
+ Exit(status);
+}
+
+/* Determine the visual of greatest depth in a given visual class.
+ * If no such visual exists, return NULL.
+ */
+static XVisualInfo *getDeepestVisual(visual_class, vinfo, nvisuals)
+ int visual_class; /* specifies the desired visual class */
+ XVisualInfo *vinfo; /* specifies all visuals for a screen */
+ int nvisuals; /* specifies number of visuals in the list */
+{
+ register int i;
+ unsigned int maxdepth = 0;
+ XVisualInfo *v = NULL;
+
+ for (i=0; i < nvisuals; i++, vinfo++)
+ if (vinfo->class == visual_class && vinfo->depth > maxdepth)
+ {
+ maxdepth = vinfo->depth;
+ v = vinfo;
+ }
+ return(v);
+}
+
+/* Determine the ``best'' visual of the screen for a standard colormap
+ * property. Return NULL if no visual is appropriate.
+ */
+static XVisualInfo *getBestVisual(property, vinfo, nvisuals)
+ Atom property; /* specifies the standard colormap */
+ XVisualInfo *vinfo; /* specifies all visuals of the screen */
+ int nvisuals; /* specifies number of visuals of screen */
+{
+ XVisualInfo *v1 = NULL, *v2 = NULL;
+
+ if (vinfo == NULL) /* unexpected: a screen with no visuals */
+ return v1;
+ v1 = getDeepestVisual(DirectColor, vinfo, nvisuals);
+ v2 = getDeepestVisual(PseudoColor, vinfo, nvisuals);
+ if (v2 && (!v1 || (v2->colormap_size >=
+ ((v1->red_mask | v1->green_mask | v1->blue_mask) + 1))))
+ return v2;
+ else if (v1)
+ return v1;
+ if (property == XA_RGB_BEST_MAP)
+ if (((v1 = getDeepestVisual(TrueColor, vinfo, nvisuals)) != NULL) ||
+ ((v1 = getDeepestVisual(StaticColor, vinfo, nvisuals)) != NULL))
+ return v1;
+ if (property == XA_RGB_GRAY_MAP)
+ if (((v1 = getDeepestVisual(GrayScale, vinfo, nvisuals)) != NULL) ||
+ ((v1 = getDeepestVisual(StaticGray, vinfo, nvisuals)) != NULL))
+ return v1;
+ if (property == XA_RGB_DEFAULT_MAP)
+ for (v1 = vinfo; v1->visual != DefaultVisual(dpy, v1->screen); v1++)
+ ;
+ return v1;
+
+}
+
+static char *visualStringFromClass(class)
+ int class;
+{
+ switch (class) {
+ case PseudoColor: return "PseudoColor";
+ case DirectColor: return "DirectColor";
+ case GrayScale: return "GrayScale";
+ case StaticColor: return "StaticColor";
+ case TrueColor: return "TrueColor";
+ case StaticGray: return "StaticGray";
+ }
+ return "unknown visual class";
+}
+
+static int doIndividualColormaps()
+{
+ int i, screen, nvisuals;
+ Status status;
+ XVisualInfo *vinfo = NULL, *v = NULL, template;
+
+ screen = DefaultScreen(dpy);
+ template.screen = screen;
+ vinfo = XGetVisualInfo(dpy, VisualScreenMask, &template, &nvisuals);
+
+ /* check for individual standard colormap requests */
+ for (i=0; i < NPROPERTIES; i++) {
+
+ if (propertyTable[i].delete) {
+ XmuDeleteStandardColormap(dpy, screen, propertyTable[i].property);
+ if (verbose)
+ fprintf(stderr, "%s: %s was deleted or did not exist.\n",
+ program_name, propertyTable[i].name);
+ }
+
+ if (! propertyTable[i].create)
+ continue;
+
+ /* which visual is best for this property? */
+ v = getBestVisual(propertyTable[i].property, vinfo, nvisuals);
+ if (v == NULL) {
+ if (verbose)
+ (void) fprintf(stderr,
+ "%s: no visual appropriate for %s on screen %d.\n",
+ program_name, propertyTable[i].name, screen);
+ continue;
+ }
+
+
+ if (verbose)
+ (void) fprintf(stderr,
+ "%s: making %s on a %s visual of depth %u.\n",
+ program_name, propertyTable[i].name,
+ visualStringFromClass(v->class), v->depth);
+
+ status = XmuLookupStandardColormap(dpy, screen, v->visualid,
+ v->depth,
+ propertyTable[i].property,
+ DO_NOT_REPLACE, RETAIN);
+ if (verbose)
+ (void) fprintf(stderr,
+ "%s: %s standard colormap %s.\n", program_name,
+ propertyTable[i].name, (status)
+ ? "was created or already exists"
+ : "cannot be defined");
+ if (!status)
+ break;
+ }
+ XFree((char *) vinfo);
+ return status;
+}
+
+/* Bare bones standard colormap generation utility */
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ Status status = 0;
+
+ if ((program_name = strrchr(*argv, '/')))
+ program_name++;
+ else
+ program_name = *argv;
+
+ parse(argc, argv);
+
+ if ((dpy = XOpenDisplay(display_name)) == NULL) {
+ (void) fprintf(stderr, "%s: cannot open display \"%s\".\n",
+ program_name, XDisplayName(display_name));
+ exit(1);
+ }
+
+ if (help) {
+ usage(0);
+ Exit(0);
+ }
+
+ if (all) {
+ if (verbose)
+ (void) fprintf(stderr,
+ "%s: making all appropriate standard colormaps...",
+ program_name);
+ status = XmuAllStandardColormaps(dpy);
+ if (verbose)
+ (void) fprintf(stderr,
+ "\n%s!\n", (status) ? "success" : "failure");
+ }
+ else {
+ status = doIndividualColormaps();
+ if (!status && verbose)
+ (void) fprintf(stderr,
+ "Not all new colormap definitions will be retained.\n");
+ }
+ Exit((status == 0) ? 1 : 0);
+}
diff --git a/xstdcmap.man b/xstdcmap.man
new file mode 100644
index 0000000..57219fe
--- /dev/null
+++ b/xstdcmap.man
@@ -0,0 +1,110 @@
+.\" $Xorg: xstdcmap.man,v 1.4 2001/02/09 02:06:01 xorgcvs Exp $
+.\" Copyright 1989, 1994, 1998 The Open Group
+.\"
+.\" Permission to use, copy, modify, distribute, and sell this software and its
+.\" documentation for any purpose is hereby granted without fee, provided that
+.\" the above copyright notice appear in all copies and that both that
+.\" copyright notice and this permission notice appear in supporting
+.\" documentation.
+.\"
+.\" The above copyright notice and this permission notice shall be included
+.\" in all copies or substantial portions of the Software.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+.\" IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+.\" OTHER DEALINGS IN THE SOFTWARE.
+.\"
+.\" Except as contained in this notice, the name of The Open Group shall
+.\" not be used in advertising or otherwise to promote the sale, use or
+.\" other dealings in this Software without prior written authorization
+.\" from The Open Group.
+.de EX \"Begin example
+.ne 5
+.if n .sp 1
+.if t .sp .5
+.nf
+.in +.5i
+..
+.de EE
+.fi
+.in -.5i
+.if n .sp 1
+.if t .sp .5
+..
+.TH XSTDCMAP 1 "Release 6.4" "X Version 11"
+.SH NAME
+xstdcmap - X standard colormap utility
+.SH SYNOPSIS
+.B xstdcmap
+[-all] [-best] [-blue] [-default] [-delete \fImap\fP] [-display \fIdisplay\fP]
+[-gray] [-green] [-help] [-red] [-verbose]
+.SH DESCRIPTION
+.PP
+The \fIxstdcmap\fP utility can be used to selectively define standard colormap
+properties. It is intended to be run from a user's X startup script to
+create standard colormap definitions in order to facilitate sharing of
+scarce colormap resources among clients. Where at all possible, colormaps
+are created with read-only allocations.
+.SH OPTIONS
+.PP
+The following options may be used with \fIxstdcmap\fP:
+.TP 8
+.B \-all
+This option indicates that all six standard colormap properties should be
+defined on each screen of the display. Not all screens will support
+visuals under which all six standard colormap properties are meaningful.
+\fIxstdcmap\fP will determine the best
+allocations and visuals for the colormap properties of a screen. Any
+previously existing standard colormap properties will be replaced.
+.TP 8
+.B \-best
+This option indicates that the RGB_BEST_MAP should be defined.
+.TP 8
+.B \-blue
+This option indicates that the RGB_BLUE_MAP should be defined.
+.TP 8
+.B \-default
+This option indicates that the RGB_DEFAULT_MAP should be defined.
+.TP 8
+.B \-delete \fImap\fP
+This option specifies that a specific standard colormap property, or
+all such properties, should be removed.
+\fImap\fP may be one of: default, best, red, green, blue, gray, or all.
+.TP 8
+.B \-display \fIdisplay\fP
+This option specifies the host and display to use; see \fIX(1)\fP.
+.TP 8
+.B \-gray
+This option indicates that the RGB_GRAY_MAP should be defined.
+.TP 8
+.B \-green
+This option indicates that the RGB_GREEN_MAP should be defined.
+.TP 8
+.B \-help
+This option indicates that a brief description of the command line arguments
+should be printed on the standard error. This will be done whenever an
+unhandled argument is given to
+.I xstdcmap.
+.TP 8
+.B \-red
+This option indicates that the RGB_RED_MAP should be defined.
+.TP 8
+.B \-verbose
+This option indicates that \fIxstdcmap\fP should
+print logging information as it parses its input and defines the
+standard colormap properties.
+.SH ENVIRONMENT
+.PP
+.TP 8
+.B DISPLAY
+to get default host and display number.
+.SH SEE ALSO
+X(1)
+.SH AUTHOR
+Donna Converse, MIT X Consortium
+
+