cmcsave.c revision 1515
/*
*
* 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>
#ifndef SYSV
#include <alloca.h>
#endif
#include "cmc.h"
#include "cmcutil.h"
#define CELL_IGNORE 0
#define CELL_READONLY 1
/*
** Handle I/O errors when opening display
*/
static int badaccess_error;
/*
** Handle X request errors.
** Just set a flag to let the routine making an X
** call know that the call resulted in a BadAccess error.
** Any other errors are processed normally.
*/
static int
{
badaccess_error = 1;
else
return 0;
}
/*
** Examines the given colormap to determine the number of
** read-only cells, their locations, and their color values.
**
** All non-read-only cells (privately allocated, unallocated
** or reserved) are ignored.
*/
static void
int *ncolors,
{
register int i, nalloc;
register int *p;
register XColor *c;
int totalpix;
unsigned long masks; /* NOTUSED */
int *pixtype;
/* start out assuming all are read-only */
/* allocate local scratch memory */
#ifdef SYSV
fatal_error("cannot allocate memory ");
fatal_error("cannot allocate memory ");
#else
fatal_error("cannot allocate memory on stack");
fatal_error("cannot allocate memory on stack");
#endif
*p = CELL_READONLY;
/*
** First, find the free cells by allocating them all private.
** We allocate by decreasing powers of 2 so the allocation
** time will be proportional to the number of display planes
** instead of the number of display cells.
**
** Mark the free cells we find. These allocations will
** be freed when the connection is closed.
*/
continue;
for (i=0; i<nalloc; i++) {
}
}
/*
**
** Get the Hardware color for the color of each allocated cell.
** This can only work if the returned color is a previously
** allocated r/o cell (we have all cells allocated).
*/
if(*p != CELL_IGNORE) {
/* Eliminate reserved cells */
badaccess_error = 0;
if (badaccess_error) {
(*ncolors)--;
} else {
badaccess_error = 0;
if (!badaccess_error) {
(*ncolors)--;
(*ncolors)--;
}
/* else if alloc succeeded, it must be read-only */
}
}
}
/* allocate the memory for the read-only cells */
fatal_error("not enough memory");
/*
** Get the color values for the read-only cells, ignoring private
*/
if (pixtype[i] != CELL_IGNORE) {
(c++)->pixel = i;
}
}
#ifdef SYSV
#endif
}
/*
** Examines the default colormap with the server grabbed
** to prevent changes during the examination process.
*/
static void
int *ncolors,
{
}
/*
** For each screen for which the default colormap is dynamic indexed
** record all read-only color cells in the default colormap.
*/
void
cmc_save (void)
{
register int scr_num;
FILE *f;
const char *filename;
/* Open display */
/* For some strange reason, colorscells_get_protected fails if not
run synchronously */
/* Open file to save in */
/* Save magic number and version */
cmc_header_write(f);
/* For each screen of display ... */
int ncolors;
/* Do nothing if default visual is not dynamic */
if (!dynamic_indexed_default_visual(screen)) {
if (warn_flag) {
warning("default visual for screen %d is not dynamic indexed",
scr_num);
}
continue;
}
/*
** Discover what read-only cells are in the default colormap.
**
** These will be considered the "workspace colors."
*/
/* Save read-only cells for screen in workspace color file */
}
}