/*
 * Copyright 1988, 1989, 1990, 1991 Massachusetts Institute of Technology
 */
#include"xpointer.h"
#include<stdio.h>

setmap()
{
  extern Display *dpy;
  extern int screen;
  extern short DEBUG;
  extern Colormap cmap;
  extern Visual *visual;
  extern XColor background, foreground, nonhighlight, 
  highlight, mousecolor, border, green, red, orange, black;
  extern char *back_string, *fore_string, *nonhigh_string,
  *high_string, *mouse_string, *border_string,
  *left_string, *right_string, *video_string,
  *fill_string, *font_string, *geom_string,
  *prog_string;

  long pixels[256], planes;
  int status, nplanes;

  visual = DefaultVisual(dpy, screen);
  if (visual->class != PseudoColor) {
    if (DEBUG) 
      printf("Screen doesn't have PseudoColor as default...continuing.\n");
    visual->class = PseudoColor;
  }

  cmap = DefaultColormap(dpy, screen);

  if (DEBUG) printf("Created colormap.\n");

/*  status = XAllocColorCells( dpy, cmap, 0, &planes, 0, pixels, 10);*/

  background.pixel = pixels[0];
  if (!back_string) back_string = XGetDefault(dpy, prog_string, "BackGround");
  if (back_string) {
    status = XParseColor(dpy, cmap, back_string, &background);
  }
  if (!back_string || !status) {
    background.red = background.blue = background.green = 30000;
    background.flags = DoRed | DoGreen | DoBlue;
  }

  foreground.pixel = pixels[1];
  if (!fore_string) fore_string = XGetDefault(dpy, prog_string, "ForeGround");
  if (fore_string) {
    status = XParseColor(dpy, cmap, fore_string, &foreground);
  }
  if (!fore_string || !status) {
    foreground.red = foreground.blue = foreground.green = 40000;
    foreground.flags = DoRed | DoGreen | DoBlue;
  }

  nonhighlight.pixel = pixels[2];
  if (!nonhigh_string) 
    nonhigh_string = XGetDefault(dpy, prog_string, "NonHighLight");
  if (nonhigh_string) {
    status = XParseColor(dpy, cmap, nonhigh_string, &nonhighlight);
  }
  if (!nonhigh_string || !status) {
    nonhighlight.red = nonhighlight.blue = nonhighlight.green = 20000;
    nonhighlight.flags = DoRed | DoGreen | DoBlue;
  }

  mousecolor.pixel = pixels[3];
  if (!mouse_string)
    mouse_string = XGetDefault(dpy, prog_string, "MouseColor");
  if (mouse_string) {
    status = XParseColor(dpy, cmap, mouse_string, &mousecolor);
  }
  if (!mouse_string || !status) {
    mousecolor.red = mousecolor.blue = mousecolor.green = 55535;
    mousecolor.flags = DoRed | DoGreen | DoBlue;
  }

  border.pixel = pixels[4];
  if (!border_string)
    border_string = XGetDefault(dpy, prog_string, "BorderColor");
  if (border_string) {
    status = XParseColor(dpy, cmap, border_string, &border);
  }
  if (!border_string || !status) {
    border.red = border.blue = border.green = 65535;
    border.flags = DoRed | DoGreen | DoBlue;
  }

  highlight.pixel = pixels[5];
  if (!high_string)
    high_string = XGetDefault(dpy, prog_string, "HighLightColor");
  if (high_string) {
    status = XParseColor(dpy, cmap, high_string, &highlight);
  }
  if (!high_string || !status) {
    highlight.red = highlight.blue = highlight.green = 65535;
    highlight.flags = DoRed | DoGreen | DoBlue;
  }

  green.pixel = pixels[6];
  if (!left_string)
    left_string = XGetDefault(dpy, prog_string, "LeftColor");
  if (left_string)
    status = XParseColor(dpy, cmap, left_string, &green);
  if (!left_string || !status) {
    green.red = green.blue = 00000;
    green.green = 65535;
    green.flags = DoRed | DoGreen | DoBlue;
  }

  red.pixel = pixels[7];
  if (!video_string)
    video_string = XGetDefault(dpy, prog_string, "VideoColor");
  if (video_string)
    status = XParseColor(dpy, cmap, video_string, &red);
  if (!video_string || !status) {
    red.red = 65535;
    red.blue = red.green = 0;
    red.flags = DoRed | DoGreen | DoBlue;
  }

  orange.pixel = pixels[8];
  if (!right_string)
    right_string = XGetDefault(dpy, prog_string, "RightColor");
  if (right_string)
    status = XParseColor(dpy, cmap, right_string, &orange);
  if (!right_string || !status) {
    orange.red = 234*256;
    orange.blue = 80*256;
    orange.green = 207*256;
    orange.flags = DoRed | DoGreen | DoBlue;
  }

  black.pixel = pixels[9];
  if (!fill_string)
    fill_string = XGetDefault(dpy, prog_string, "FillColor");
  if (fill_string)
    status = XParseColor(dpy, cmap, fill_string, &black);
  if (!fill_string || !status) {
    black.red = black.green = black.blue = 0;
    black.flags = DoRed | DoGreen | DoBlue;
  }

  XAllocColor( dpy, cmap, &background);
  XAllocColor( dpy, cmap, &foreground);
  XAllocColor( dpy, cmap, &nonhighlight);
  XAllocColor( dpy, cmap, &mousecolor);
  XAllocColor( dpy, cmap, &border);
  XAllocColor( dpy, cmap, &highlight);
  XAllocColor( dpy, cmap, &red);
  XAllocColor( dpy, cmap, &green);
  XAllocColor( dpy, cmap, &orange);
  XAllocColor( dpy, cmap, &black);
}

