Fossil SCM
Minor tweaks to the hash color test page.
Commit
19799565b7a8c9ff0a10a6e927fe0dc8165cf0c9727efd865c2defe9440aa037
Parent
016f6c5ec510865…
2 files changed
+14
-5
+1
-2
+14
-5
| --- src/color.c | ||
| +++ src/color.c | ||
| @@ -20,19 +20,30 @@ | ||
| 20 | 20 | ** |
| 21 | 21 | */ |
| 22 | 22 | #include "config.h" |
| 23 | 23 | #include <string.h> |
| 24 | 24 | #include "color.h" |
| 25 | + | |
| 26 | +/* | |
| 27 | +** Compute a hash on a branch or user name | |
| 28 | +*/ | |
| 29 | +static unsigned int hash_of_name(const char *z){ | |
| 30 | + unsigned int h = 0; | |
| 31 | + int i; | |
| 32 | + for(i=0; z[i]; i++ ){ | |
| 33 | + h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i]; | |
| 34 | + } | |
| 35 | + return h; | |
| 36 | +} | |
| 25 | 37 | |
| 26 | 38 | /* |
| 27 | 39 | ** Hash a string and use the hash to determine a background color. |
| 28 | 40 | ** |
| 29 | 41 | ** This value returned is in static space and is overwritten with |
| 30 | 42 | ** each subsequent call. |
| 31 | 43 | */ |
| 32 | 44 | char *hash_color(const char *z){ |
| 33 | - int i; /* Loop counter */ | |
| 34 | 45 | unsigned int h = 0; /* Hash on the branch name */ |
| 35 | 46 | int r, g, b; /* Values for red, green, and blue */ |
| 36 | 47 | int h1, h2, h3, h4; /* Elements of the hash value */ |
| 37 | 48 | int mx, mn; /* Components of HSV */ |
| 38 | 49 | static char zColor[10]; /* The resulting color */ |
| @@ -45,13 +56,11 @@ | ||
| 45 | 56 | }else{ |
| 46 | 57 | ix[0] = 0xf8; |
| 47 | 58 | ix[1] = 0x20; |
| 48 | 59 | } |
| 49 | 60 | } |
| 50 | - for(i=0; z[i]; i++ ){ | |
| 51 | - h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i]; | |
| 52 | - } | |
| 61 | + h = hash_of_name(z); | |
| 53 | 62 | h1 = h % 6; h /= 6; |
| 54 | 63 | h3 = h % 10; h /= 10; |
| 55 | 64 | h4 = h % 10; h /= 10; |
| 56 | 65 | mx = ix[0] - h3; |
| 57 | 66 | mn = mx - h4 - ix[1]; |
| @@ -154,11 +163,11 @@ | ||
| 154 | 163 | for(i=cnt=0; i<10; i++){ |
| 155 | 164 | sqlite3_snprintf(sizeof(zNm),zNm,"b%d",i); |
| 156 | 165 | zBr = P(zNm); |
| 157 | 166 | if( zBr && zBr[0] ){ |
| 158 | 167 | @ <p style='border:1px solid;background-color:%s(hash_color(zBr));'> |
| 159 | - @ %h(zBr) - %s(hash_color(zBr)) - | |
| 168 | + @ %h(zBr) - hash 0x%x(hash_of_name(zBr)) - color %s(hash_color(zBr)) - | |
| 160 | 169 | @ Omnes nos quasi oves erravimus unusquisque in viam |
| 161 | 170 | @ suam declinavit.</p> |
| 162 | 171 | cnt++; |
| 163 | 172 | } |
| 164 | 173 | } |
| 165 | 174 |
| --- src/color.c | |
| +++ src/color.c | |
| @@ -20,19 +20,30 @@ | |
| 20 | ** |
| 21 | */ |
| 22 | #include "config.h" |
| 23 | #include <string.h> |
| 24 | #include "color.h" |
| 25 | |
| 26 | /* |
| 27 | ** Hash a string and use the hash to determine a background color. |
| 28 | ** |
| 29 | ** This value returned is in static space and is overwritten with |
| 30 | ** each subsequent call. |
| 31 | */ |
| 32 | char *hash_color(const char *z){ |
| 33 | int i; /* Loop counter */ |
| 34 | unsigned int h = 0; /* Hash on the branch name */ |
| 35 | int r, g, b; /* Values for red, green, and blue */ |
| 36 | int h1, h2, h3, h4; /* Elements of the hash value */ |
| 37 | int mx, mn; /* Components of HSV */ |
| 38 | static char zColor[10]; /* The resulting color */ |
| @@ -45,13 +56,11 @@ | |
| 45 | }else{ |
| 46 | ix[0] = 0xf8; |
| 47 | ix[1] = 0x20; |
| 48 | } |
| 49 | } |
| 50 | for(i=0; z[i]; i++ ){ |
| 51 | h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i]; |
| 52 | } |
| 53 | h1 = h % 6; h /= 6; |
| 54 | h3 = h % 10; h /= 10; |
| 55 | h4 = h % 10; h /= 10; |
| 56 | mx = ix[0] - h3; |
| 57 | mn = mx - h4 - ix[1]; |
| @@ -154,11 +163,11 @@ | |
| 154 | for(i=cnt=0; i<10; i++){ |
| 155 | sqlite3_snprintf(sizeof(zNm),zNm,"b%d",i); |
| 156 | zBr = P(zNm); |
| 157 | if( zBr && zBr[0] ){ |
| 158 | @ <p style='border:1px solid;background-color:%s(hash_color(zBr));'> |
| 159 | @ %h(zBr) - %s(hash_color(zBr)) - |
| 160 | @ Omnes nos quasi oves erravimus unusquisque in viam |
| 161 | @ suam declinavit.</p> |
| 162 | cnt++; |
| 163 | } |
| 164 | } |
| 165 |
| --- src/color.c | |
| +++ src/color.c | |
| @@ -20,19 +20,30 @@ | |
| 20 | ** |
| 21 | */ |
| 22 | #include "config.h" |
| 23 | #include <string.h> |
| 24 | #include "color.h" |
| 25 | |
| 26 | /* |
| 27 | ** Compute a hash on a branch or user name |
| 28 | */ |
| 29 | static unsigned int hash_of_name(const char *z){ |
| 30 | unsigned int h = 0; |
| 31 | int i; |
| 32 | for(i=0; z[i]; i++ ){ |
| 33 | h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[i]; |
| 34 | } |
| 35 | return h; |
| 36 | } |
| 37 | |
| 38 | /* |
| 39 | ** Hash a string and use the hash to determine a background color. |
| 40 | ** |
| 41 | ** This value returned is in static space and is overwritten with |
| 42 | ** each subsequent call. |
| 43 | */ |
| 44 | char *hash_color(const char *z){ |
| 45 | unsigned int h = 0; /* Hash on the branch name */ |
| 46 | int r, g, b; /* Values for red, green, and blue */ |
| 47 | int h1, h2, h3, h4; /* Elements of the hash value */ |
| 48 | int mx, mn; /* Components of HSV */ |
| 49 | static char zColor[10]; /* The resulting color */ |
| @@ -45,13 +56,11 @@ | |
| 56 | }else{ |
| 57 | ix[0] = 0xf8; |
| 58 | ix[1] = 0x20; |
| 59 | } |
| 60 | } |
| 61 | h = hash_of_name(z); |
| 62 | h1 = h % 6; h /= 6; |
| 63 | h3 = h % 10; h /= 10; |
| 64 | h4 = h % 10; h /= 10; |
| 65 | mx = ix[0] - h3; |
| 66 | mn = mx - h4 - ix[1]; |
| @@ -154,11 +163,11 @@ | |
| 163 | for(i=cnt=0; i<10; i++){ |
| 164 | sqlite3_snprintf(sizeof(zNm),zNm,"b%d",i); |
| 165 | zBr = P(zNm); |
| 166 | if( zBr && zBr[0] ){ |
| 167 | @ <p style='border:1px solid;background-color:%s(hash_color(zBr));'> |
| 168 | @ %h(zBr) - hash 0x%x(hash_of_name(zBr)) - color %s(hash_color(zBr)) - |
| 169 | @ Omnes nos quasi oves erravimus unusquisque in viam |
| 170 | @ suam declinavit.</p> |
| 171 | cnt++; |
| 172 | } |
| 173 | } |
| 174 |
+1
-2
| --- src/sitemap.c | ||
| +++ src/sitemap.c | ||
| @@ -327,12 +327,11 @@ | ||
| 327 | 327 | if( g.perm.Read ){ |
| 328 | 328 | @ <li>%z(href("%R/test-rename-list"))List of file renames</a></li> |
| 329 | 329 | } |
| 330 | 330 | @ <li>%z(href("%R/test-builtin-files"))List of built-in files</a></li> |
| 331 | 331 | @ <li>%z(href("%R/mimetype_list"))List of MIME types</a></li> |
| 332 | - @ <li>%z(href("%R/hash-color-test"))Page to experiment with the automatic | |
| 333 | - @ colors assigned to branch names</a> | |
| 332 | + @ <li>%z(href("%R/hash-color-test"))Hash color test</a> | |
| 334 | 333 | if( g.perm.Admin ){ |
| 335 | 334 | @ <li>%z(href("%R/test-backlinks"))List of backlinks</a></li> |
| 336 | 335 | @ <li>%z(href("%R/test-backlink-timeline"))Backlink timeline</a></li> |
| 337 | 336 | @ <li>%z(href("%R/phantoms"))List of phantom artifacts</a></li> |
| 338 | 337 | @ <li>%z(href("%R/test-warning"))Error Log test page</a></li> |
| 339 | 338 |
| --- src/sitemap.c | |
| +++ src/sitemap.c | |
| @@ -327,12 +327,11 @@ | |
| 327 | if( g.perm.Read ){ |
| 328 | @ <li>%z(href("%R/test-rename-list"))List of file renames</a></li> |
| 329 | } |
| 330 | @ <li>%z(href("%R/test-builtin-files"))List of built-in files</a></li> |
| 331 | @ <li>%z(href("%R/mimetype_list"))List of MIME types</a></li> |
| 332 | @ <li>%z(href("%R/hash-color-test"))Page to experiment with the automatic |
| 333 | @ colors assigned to branch names</a> |
| 334 | if( g.perm.Admin ){ |
| 335 | @ <li>%z(href("%R/test-backlinks"))List of backlinks</a></li> |
| 336 | @ <li>%z(href("%R/test-backlink-timeline"))Backlink timeline</a></li> |
| 337 | @ <li>%z(href("%R/phantoms"))List of phantom artifacts</a></li> |
| 338 | @ <li>%z(href("%R/test-warning"))Error Log test page</a></li> |
| 339 |
| --- src/sitemap.c | |
| +++ src/sitemap.c | |
| @@ -327,12 +327,11 @@ | |
| 327 | if( g.perm.Read ){ |
| 328 | @ <li>%z(href("%R/test-rename-list"))List of file renames</a></li> |
| 329 | } |
| 330 | @ <li>%z(href("%R/test-builtin-files"))List of built-in files</a></li> |
| 331 | @ <li>%z(href("%R/mimetype_list"))List of MIME types</a></li> |
| 332 | @ <li>%z(href("%R/hash-color-test"))Hash color test</a> |
| 333 | if( g.perm.Admin ){ |
| 334 | @ <li>%z(href("%R/test-backlinks"))List of backlinks</a></li> |
| 335 | @ <li>%z(href("%R/test-backlink-timeline"))Backlink timeline</a></li> |
| 336 | @ <li>%z(href("%R/phantoms"))List of phantom artifacts</a></li> |
| 337 | @ <li>%z(href("%R/test-warning"))Error Log test page</a></li> |
| 338 |