aboutsummaryrefslogtreecommitdiff
path: root/src/Utility/Utility.c
blob: b4ad91dae06eab3324b61da037767b09ec0ca2c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "Utility.h"
#include <beaker.h>
#include <stdlib.h>
#include <string.h>

int hex_to_int(char c) {
  if (c >= '0' && c <= '9')
    return c - '0';
  if (c >= 'a' && c <= 'f')
    return c - 'a' + 10;
  if (c >= 'A' && c <= 'F')
    return c - 'A' + 10;
  return -1;
}

char *get_theme(const char *default_theme) {
  char *cookie = get_cookie("theme");
  if (cookie &&
      (strcmp(cookie, "light") == 0 ||
       strcmp(cookie, "dark") == 0)) {
    return cookie;
  }
  free(cookie);
  return strdup(default_theme);
}