summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-04-02 15:29:36 -0400
committerJune McEnroe <june@causal.agency>2018-04-02 15:29:36 -0400
commitc4f71fe80560390996909913072d1c866722bf11 (patch)
tree54710fec0edd9c51b0ddb6cee25765c9d114c2eb /bin
parentUse uint32_t for len in scheme (diff)
downloadsrc-c4f71fe80560390996909913072d1c866722bf11.tar.gz
src-c4f71fe80560390996909913072d1c866722bf11.zip
Use union for scheme gen functions
Diffstat (limited to 'bin')
-rw-r--r--bin/scheme.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/bin/scheme.c b/bin/scheme.c
index 747e7924..90b22b8b 100644
--- a/bin/scheme.c
+++ b/bin/scheme.c
@@ -144,8 +144,8 @@ static struct Hsv p(struct Hsv o, double hd, double sf, double vf) {
     return (struct Hsv) { o.h + hd, o.s * sf, o.v * vf };
 }
 
-enum { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
 struct Ansi {
+    enum { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
     struct Hsv dark[8];
     struct Hsv light[8];
 };
@@ -154,9 +154,17 @@ struct Terminal {
     struct Hsv background, text, bold, selection, cursor;
 };
 
+struct Scheme {
+    uint32_t len;
+    union {
+        struct Hsv hsv;
+        struct Ansi ansi;
+        struct Terminal terminal;
+    };
+};
 #define HSV_LEN(x) (sizeof(x) / sizeof(struct Hsv))
 
-static struct Ansi genAnsi(void) {
+static struct Scheme genAnsi(void) {
     struct Ansi ansi = {
         .light = {
             [BLACK]   = p(R, +45.0, 0.3, 0.3),
@@ -168,17 +176,19 @@ static struct Ansi genAnsi(void) {
             [CYAN]    = p(C, -60.0, 0.3, 0.6),
             [WHITE]   = p(R, +45.0, 0.3, 0.8),
         },
+        .dark[BLACK] = ansi.light[BLACK],
     };
     ansi.dark[BLACK] = p(ansi.light[BLACK], 0.0, 1.0, 0.3);
     ansi.dark[WHITE] = p(ansi.light[WHITE], 0.0, 1.0, 0.6);
     for (int i = RED; i < WHITE; ++i) {
         ansi.dark[i] = p(ansi.light[i], 0.0, 1.0, 0.8);
     }
-    return ansi;
+    return (struct Scheme) { .len = HSV_LEN(ansi), .ansi = ansi };
 }
 
-static struct Terminal genTerminal(struct Ansi ansi) {
-    return (struct Terminal) {
+static struct Scheme genTerminal(void) {
+    struct Ansi ansi = genAnsi().ansi;
+    struct Terminal terminal = {
         .ansi       = ansi,
         .background = p(ansi.dark[BLACK],    0.0, 1.0, 0.9),
         .text       = p(ansi.light[WHITE],   0.0, 1.0, 0.9),
@@ -186,6 +196,10 @@ static struct Terminal genTerminal(struct Ansi ansi) {
         .selection  = p(ansi.light[RED],   +10.0, 1.0, 0.8),
         .cursor     = p(ansi.dark[WHITE],    0.0, 1.0, 0.8),
     };
+    return (struct Scheme) {
+        .len = HSV_LEN(terminal),
+        .terminal = terminal,
+    };
 }
 
 int main(int argc, char *argv[]) {
@@ -205,27 +219,17 @@ int main(int argc, char *argv[]) {
         }
     }
 
-    struct Ansi ansi = genAnsi();
-    struct Terminal terminal = genTerminal(ansi);
-
-    const struct Hsv *scheme;
-    uint32_t len;
+    struct Scheme scheme;
     switch (generate) {
-        case ANSI: {
-            scheme = (struct Hsv *)&ansi;
-            len = HSV_LEN(ansi);
-        } break;
-        case TERMINAL: {
-            scheme = (struct Hsv *)&terminal;
-            len = HSV_LEN(terminal);
-        } break;
+        case ANSI: scheme = genAnsi(); break;
+        case TERMINAL: scheme = genTerminal(); break;
     }
 
     switch (output) {
-        case HSV: hsv(scheme, len); break;
-        case HEX: hex(scheme, len); break;
-        case LINUX: linux(scheme, len); break;
-        case PNG: png(scheme, len); break;
+        case HSV: hsv(&scheme.hsv, scheme.len); break;
+        case HEX: hex(&scheme.hsv, scheme.len); break;
+        case LINUX: linux(&scheme.hsv, scheme.len); break;
+        case PNG: png(&scheme.hsv, scheme.len); break;
     }
 
     return EX_OK;
ewer to a snapshot of the corresponding tree. Currently only zip-format is supported. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-05cgit v0.2Lars Hjemli Main changes since v0.1: -list tags in repo summary -allow search in log-view -read repository paths from cgitrc Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-05Add support for prefix and gitsrc arguments to 'make'Lars Hjemli This should improve the installation a little, especially since the new options are mentioned in the README. Also, add a make-rule to build the git binaries if necessary + a dependency between cgit and libgit.a. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-04Update cgitrc templateLars Hjemli Make the descriptions more helpfull. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-04Add support for lightweight tagsLars Hjemli There is nothing bad about a tag that has no tag-object, but the old code didn't handle such tags correctly. Fix it. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-04Read repo-info from /etc/cgitrcLars Hjemli This makes cgit read all repo-info from the configfile, instead of scanning for possible git-dirs below a common root path. This is primarily done to get better security (separate physical path from logical repo-name). In /etc/cgitrc each repo is registered with the following keys: repo.url repo.name repo.path repo.desc repo.owner Note: *Required keys are repo.url and repo.path, all others are optional *Each occurrence of repo.url starts a new repository registration *Default value for repo.name is taken from repo.url *The value of repo.url cannot contain characters with special meaning for urls (i.e. one of /?%&), while repo.name can contain anything. Example: repo.url=cgit-pub repo.name=cgit/public repo.path=/pub/git/cgit repo.desc=My public cgit repo repo.owner=Lars Hjemli repo.url=cgit-priv repo.name=cgit/private repo.path=/home/larsh/src/cgit/.git repo.desc=My private cgit repo repo.owner=Lars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-04Do not die if tag has no messageLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-02-03Fix search for non-virtual urlsLars Hjemli When cgit don't use virtual urls, the current repo and page url parameters must be included in the search form as hidden input fields. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2007-01-28Update README with install/config informationLars Hjemli