[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / utils / hp2ps / Shade.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "Main.h"
5 #include "Defines.h"
6 #include "Error.h"
7 #include "Utilities.h"
8
9 /* own stuff */
10 #include "Shade.h"
11
12 static struct shade {
13         char* ident;
14         floatish shade;
15 } *shademap;
16
17 static int shademapmax = 0;
18 static int shademapindex = 0;
19
20 /*
21  *      Set the shade to be used for "ident" to "shade".
22  */
23
24 void
25 ShadeFor(ident, shade)
26   char* ident; 
27   floatish shade;
28 {
29     if (! shademap) {
30         shademapmax = (nidents > TWENTY ? nidents : TWENTY) * 2;
31                  /* Assume nidents read is indication of the No of
32                     idents in the .aux file (*2 for good luck) */
33                  /* NB *2 is needed as .aux and .hp elements may differ */
34         shademap = xmalloc(shademapmax * sizeof(struct shade));
35     }
36
37     if (shademapindex < shademapmax) {
38         shademap[ shademapindex ].ident = copystring(ident);
39         shademap[ shademapindex ].shade = shade;
40         shademapindex++;
41     } else {
42         Disaster("shade map overflow");
43     }
44 }
45
46 /*
47  *      Get the shade to be used for "ident" if there is one. 
48  *      Otherwise, think of a new one.
49  */
50
51 static floatish ThinkOfAShade PROTO((void));    /* forward */
52
53 floatish
54 ShadeOf(ident)
55   char* ident;
56 {
57     int i;
58     floatish shade;
59
60     for (i = 0; i < shademapindex; i++) {
61         if (strcmp(shademap[i].ident, ident) == 0) {    /* got it */
62             return(shademap[i].shade);
63         }
64     }
65
66     shade = ThinkOfAShade();
67
68     ShadeFor(ident, shade);
69
70     return shade; 
71 }
72
73
74
75 #define N_SHADES 10 
76
77 static floatish shades[ N_SHADES ] = {
78     0.00000, 0.20000, 0.60000, 0.30000, 0.90000, 
79     0.40000, 1.00000, 0.70000, 0.50000,  0.80000
80 };
81
82 static floatish
83 ThinkOfAShade()
84 {
85     static int thisshade = 0;
86
87     floatish x;
88
89     x = shades[ thisshade ]; 
90     thisshade = (thisshade + 1) % N_SHADES;
91     return x; 
92 }