view admin/alloc-colors.c @ 87315:34b619baa980

Replace all instances of string-to-int with string-to-number, insert-string with insert, and read-input with read-string. (top-level): No need to require imenu, reporter, dinotrace, vc, font-lock when compiling. Always require compile. Relegate remaining compatibility cruft to XEmacs. Don't require font-lock. (verilog-version): Remove superfluous concat. (dinotrace-unannotate-all, zmacs-activate-region) (customize-apropos): No need to define. (verilog-regexp-opt): On Emacs, just make it an alias for regexp-opt. (verilog-font-lock-keywords, verilog-font-lock-keywords-1) (verilog-font-lock-keywords-2, verilog-font-lock-keywords-3) (verilog-startup-message-displayed): These are variables, not constants. (verilog-batch-execute-func, verilog-auto-inst) (verilog-auto-inst-param): Use mapc rather than mapcar. (sigs-in, sigs-inout, sigs-out): Define for compiler rather than actually defining. (verilog-modi-get-decls, verilog-modi-get-sub-decls) (verilog-modi-get-outputs, verilog-modi-get-inouts) (verilog-modi-get-inputs, verilog-modi-get-wires) (verilog-modi-get-regs, verilog-modi-get-assigns) (verilog-modi-get-consts, verilog-modi-get-gparams) (verilog-modi-get-sub-outputs, verilog-modi-get-sub-inouts) (verilog-modi-get-sub-inputs): Move inline functions earlier in the file. (sigs-in, sigs-out): Don't declare multiple times. (got-sig, got-rvalue, uses-delayed): Define for compiler with just `defvar'. (verilog-auto): Call dinotrace-unannotate-all only if bound. (verilog-module-inside-filename-p): No need to wrap fboundp test in condition-case. (reporter-submit-bug-report): Autoload it. (verilog-mark-defun): Call zmacs-activate-region only if bound. (verilog-font-customize): Call customize-apropos only if bound. (verilog-getopt-flags, verilog-auto-reeval-locals): Use make-local-variable rather than make-variable-buffer-local. (verilog-company, verilog-project, verilog-modi-cache-list): Move make-variable-buffer-local calls to top-level. (font-lock-defaults-alist): Don't define it. (verilog-need-fld): Remove. (verilog-font-lock-init): Don't set font-lock-defaults-alist. (verilog-mode): Only call make-local-hook on XEmacs. Set font-lock-defaults rather than using verilog-font-lock-init.
author Glenn Morris <rgm@gnu.org>
date Tue, 18 Dec 2007 02:32:29 +0000
parents 450fa81c5930
children cde444d03b82 f55f9811f5d7
line wrap: on
line source

/* Allocate X colors.  Used for testing with dense colormaps.
   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
     Free Software Foundation, Inc.

This file is part of GNU Emacs.

GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING.  If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.  */

#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>

void
fatal (const char *fmt, ...)
{
  va_list ap;

  va_start (ap, fmt);
  vfprintf (stderr, fmt, ap);
  fputc ('\n', stderr);
  va_end (ap);
  exit (1);
}

void
usage (const char *progname)
{
  fprintf (stderr, "Usage %s options\n", progname);
  fprintf (stderr, "-n NCOLORS  allcoate NCOLORS colors\n");
  exit (1);
}

int
main (int argc, char **argv)
{
  Display *dpy;
  int opt, ncolors = 0, i;
  XColor *allocated;
  int nallocated;
  XColor color;
  Colormap cmap;

  while ((opt = getopt (argc, argv, "n:")) != EOF)
    switch (opt)
      {
      case 'n':
	ncolors = atoi (optarg);
	break;

      case '?':
	usage (argv[0]);
      }

  if (ncolors == 0)
    usage (argv[0]);

  dpy = XOpenDisplay ("");
  if (dpy == NULL)
    fatal ("Cannot open display");
  cmap = DefaultColormap (dpy, 0);

  allocated = malloc (ncolors * sizeof *allocated);
  nallocated = 0;
  memset (&color, 0, sizeof color);

  while (nallocated < ncolors
	 && color.red < 65536)
    {
      allocated[nallocated] = color;
      if (XAllocColor (dpy, cmap, &allocated[nallocated]))
	{
	  for (i = 0; i < nallocated; ++i)
	    if (allocated[i].red == allocated[nallocated].red
		&& allocated[i].green == allocated[nallocated].green
		&& allocated[i].blue == allocated[nallocated].blue)
	      break;

	  if (i == nallocated)
	    {
	      printf ("allocated %d/%d/%d\n",
		      allocated[nallocated].red,
		      allocated[nallocated].green,
		      allocated[nallocated].blue);
	      ++nallocated;
	    }
	}

      ++color.red;
      ++color.green;
      ++color.blue;
    }

  fprintf (stderr, "Waiting.  Press ^C to stop.\n");
  while (1)
    sleep (10);

  XCloseDisplay (dpy);
  return 0;
}

/* arch-tag: f1be90ac-5b70-43c2-835e-5a6432a25145
   (do not change this comment) */