cmcsave.c revision 550
/*
* Copyright 1990 Sun Microsystems, Inc. All rights reserved.
* Use subject to license terms.
*
* 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,
* to whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* 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
* OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Except as contained in this notice, the name of a copyright holder
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
* of the copyright holder.
*
*/
#pragma ident "@(#)cmcsave.c 35.4 08/09/30 CMAP_COMPACT SMI"
#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 void
{
badaccess_error = 1;
else
}
/*
** 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;
int 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 ()
{
register int scr_num;
FILE *f;
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) {
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 */
}
}