/*
*
* cmap_alloc.c 1.x
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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.
*/
#include <stdio.h>
#include <stdlib.h>
char *prog_name;
int num_cmaps;
int num_visuals;
static void alloc_cmaps_for_screen();
static void alloc_cmap_for_visual();
static void create_colormap();
static char *visual_class_name();
static void parse_cmdline();
static int string_to_depth();
static int string_to_visual();
static void usage();
int
int argc;
char **argv;
{
int screen;
/* Take care of command line options */
/* Try to open the display */
exit(0);
}
/* Handle all necessary screens */
if (all_screens)
else
/* If we created any colormaps, we need to ensure
* that they live after the program exits.
*/
if (created_colormap)
return (1);
}
static void
int screen;
{
int v;
if (verbose)
/* Find out if any colormaps already exist in the property */
num_cmaps = 0;
/* Find the available visuals on the screen */
/* Only try the specified visual */
v = 0;
while (!vinfo && (v < num_visuals))
vinfo = &available_visuals[v];
else
v++;
if (vinfo)
exit(0);
} else
}
/* Try all visuals of visual_class with any depth */
else if (visual_class != All) {
for (v = 0; v < num_visuals; v++)
}
/* Try all visuals of depth and any dynamic class */
for (v = 0; v < num_visuals; v++)
}
/* Try all visuals */
else
for (v = 0; v < num_visuals; v++)
}
static void
int screen;
{
int c = 0;
if (verbose)
(void)printf(" Creating a colormap for the %s %d bit visual...",
/* Check to see if one already exists */
(allocated_cmaps[c].red_max == 0) &&
(allocated_cmaps[c].red_mult == 0) &&
(allocated_cmaps[c].green_max == 0) &&
(allocated_cmaps[c].green_mult == 0) &&
(allocated_cmaps[c].blue_max == 0) &&
(allocated_cmaps[c].blue_mult == 0))
std_cmap = &allocated_cmaps[c];
else
c++;
(void)printf("one already exists\n");
/* Create the colormap */
/* append it to the property on the root window */
10);
if (verbose)
}
}
static void
{
/* Allocate black from the colormap */
/* Fill out the standard colormap information */
std_colormap->red_max = 0;
std_colormap->red_mult = 0;
std_colormap->green_max = 0;
std_colormap->green_mult = 0;
std_colormap->blue_max = 0;
std_colormap->blue_mult = 0;
/* We don't want anybody pulling the colormap out from
* under running clients, so set the killid to 0.
*/
std_colormap->killid = 0;
}
static char *
int class;
{
char *name;
switch (class) {
case StaticGray:
name = "StaticGray";
break;
case GrayScale:
name = "GrayScale";
break;
case StaticColor:
name = "StaticColor";
break;
case PseudoColor:
name = "PseudoColor";
break;
case TrueColor:
name = "TrueColor";
break;
case DirectColor:
name = "DirectColor";
break;
default:
name = "";
break;
}
return name;
}
static void
int argc;
char **argv;
{
if (argc)
else
usage();
all_screens = True;
usage();
}
} else
usage();
if (visual_class == All) {
usage();
} else if (!DYNAMIC_VISUAL(visual_class)) {
exit(0);
}
} else
usage();
usage();
else {
usage();
}
option++;
}
}
static int
char *str;
{
int depth;
return depth;
}
static int
char *str;
{
int visual_class;
else
visual_class = All;
return visual_class;
}
static void
usage()
{
exit(0);
}