home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / ms-0.07 / lib / parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-27  |  1.8 KB  |  76 lines

  1. /* parse.c -- parse a textual colour specification */
  2.    
  3. /*
  4.     This file is part of MandelSpawn, a network Mandelbrot program.
  5.  
  6.     Copyright (C) 1993 Andreas Gustafsson
  7.  
  8.     MandelSpawn is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License, version 1,
  10.     as published by the Free Software Foundation.
  11.  
  12.     MandelSpawn is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License,
  18.     version 1, along with this program; if not, write to the Free 
  19.     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #include <ctype.h>
  23. #include <string.h>
  24.  
  25. #include "color.h"
  26.  
  27. #include "colors.c"    /* machine-generated table */
  28.  
  29. int
  30. name_to_color(s, color)
  31.     char *s;
  32.     color_t *color;
  33. {
  34.     struct colordef *d;
  35.     char name[64];
  36.     char *p = name;
  37.  
  38.     if(strlen(s) > 63)
  39.     return 0;
  40.  
  41.     /* Convert to lowercase and strip spaces */
  42.     while(*s)
  43.     {
  44.     int c = *s++;
  45.     if(isupper(c))
  46.         c = tolower(c);
  47.     if(c != ' ')
  48.         *p++ = c;
  49.     }
  50.     *p++ = '\0';
  51.  
  52.     /* Handle shades of grey algorithmically to save table space */
  53.     if((strncmp(name, "grey", 4) || strncmp(name, "grey", 4)) &&
  54.        isdigit(name[4]))
  55.     {    
  56.     int comp;
  57.     double val = atoi(name+4) / 100.0;
  58.     for(comp=0; comp<3; comp++)
  59.         color->comps[comp] = val;
  60.     return 1;
  61.     }
  62.  
  63.     /* Search the table */
  64.     for(d = colordefs; d->name; d++)
  65.     if(!strcmp(name, d->name))
  66.     {
  67.         int comp;
  68.         for(comp=0; comp<3; comp++)
  69.         color->comps[comp] = d->comps[comp] / 255.0;
  70.         return 1;
  71.     }
  72.  
  73.     /* Not found */
  74.     return 0;
  75. }
  76.