diff options
| -rw-r--r-- | src/extractors/bilibili.c | 12 | ||||
| -rw-r--r-- | src/extractors/extractor.c | 8 | ||||
| -rw-r--r-- | src/extractors/haokan.c | 4 | ||||
| -rw-r--r-- | src/extractors/youku.c | 14 | ||||
| -rw-r--r-- | src/logger.c | 4 | ||||
| -rw-r--r-- | src/main.c | 2 | ||||
| -rw-r--r-- | src/process_url.c | 17 | ||||
| -rw-r--r-- | src/process_url.h | 7 | ||||
| -rw-r--r-- | src/status.h | 1 | ||||
| -rw-r--r-- | src/style.h | 254 | ||||
| -rw-r--r-- | src/ui.c | 7 | ||||
| -rw-r--r-- | src/utils/types.c | 6 | ||||
| -rw-r--r-- | src/utils/utils.c | 7 | ||||
| -rw-r--r-- | src/utils/utils.h | 5 | 
14 files changed, 167 insertions, 181 deletions
| diff --git a/src/extractors/bilibili.c b/src/extractors/bilibili.c index 6112bef..6bddee5 100644 --- a/src/extractors/bilibili.c +++ b/src/extractors/bilibili.c @@ -345,7 +345,7 @@ static const char *id2quality_desc(int id) {  static void multipage_cleanup(Multipage *multipage_struct) {    for (unsigned short i = 0; i < multipage_struct->sections.n; i++) { -    // free_and_nullify(multipage_struct->sections[i].episodes); +    // FREE_AND_NULLIFY(multipage_struct->sections[i].episodes);      Multi_episode_data *section = get_element(&multipage_struct->sections, i);      free_array(§ion->episodes);    } @@ -381,7 +381,7 @@ static int download(Bilibili_options *bilibili_options) {    get(bilibili_options->api, &resp);    if (get_dash(resp, &dash)) {      LOG("Bilibili", "Get dash failed."); -    free_and_nullify(resp); +    FREE_AND_NULLIFY(resp);      dash_cleanup(&dash);      return 1;    }; @@ -429,7 +429,7 @@ static int download(Bilibili_options *bilibili_options) {      set_str_element(&callback_struct, 2, audiofn);      add_url(audio->baseUrl, NULL, audiofn, &bilibili_merge, &callback_struct);    } -  free_and_nullify(resp); +  FREE_AND_NULLIFY(resp);    dash_cleanup(&dash);    return 0;  } @@ -478,18 +478,18 @@ void bilibili_extract(struct options *options) {    DEBUG_PRINT("title: %s\n", bilibili_options.title);    if (generate_api(&bilibili_options, 127)) { -    free_and_nullify(bilibili_options.api); +    FREE_AND_NULLIFY(bilibili_options.api);      multipage_cleanup(&multipage_struct);      return;    }    DEBUG_PRINT("Generated API: %s\n", bilibili_options.api);    if (download(&bilibili_options)) { -    free_and_nullify(bilibili_options.api); +    FREE_AND_NULLIFY(bilibili_options.api);      multipage_cleanup(&multipage_struct);      return;    } -  free_and_nullify(bilibili_options.api); +  FREE_AND_NULLIFY(bilibili_options.api);    multipage_cleanup(&multipage_struct);  } diff --git a/src/extractors/extractor.c b/src/extractors/extractor.c index c38c1f2..06d52a5 100644 --- a/src/extractors/extractor.c +++ b/src/extractors/extractor.c @@ -12,10 +12,10 @@ Site_map site_map = {{{"www.bilibili.com", SITE_BILIBILI},                       3};  void options_cleanup(Options *options) { -  free_and_nullify(options->URL); -  free_and_nullify(options->path); -  free_and_nullify(options->query); -  free_and_nullify(options->pagedata); +  FREE_AND_NULLIFY(options->URL); +  FREE_AND_NULLIFY(options->path); +  FREE_AND_NULLIFY(options->query); +  FREE_AND_NULLIFY(options->pagedata);  }  int extract(void *v) { diff --git a/src/extractors/haokan.c b/src/extractors/haokan.c index f289c3e..b3e943d 100644 --- a/src/extractors/haokan.c +++ b/src/extractors/haokan.c @@ -38,8 +38,8 @@ void haokan_extract(Options *options) {      end:        free_str_array(&results); -      free_and_nullify(filename); -      free_and_nullify(videoURL); +      FREE_AND_NULLIFY(filename); +      FREE_AND_NULLIFY(videoURL);        return;      }      free_str_array(&results); diff --git a/src/extractors/youku.c b/src/extractors/youku.c index e8fa0a5..091141d 100644 --- a/src/extractors/youku.c +++ b/src/extractors/youku.c @@ -67,9 +67,9 @@ static int parse_jsondata(cJSON *json, Youku_data *youku_data) {  }  static void youku_options_cleanup(Youku_options *youku_options) { -  free_and_nullify(youku_options->vid); -  free_and_nullify(youku_options->utid); -  free_and_nullify(youku_options->api); +  FREE_AND_NULLIFY(youku_options->vid); +  FREE_AND_NULLIFY(youku_options->utid); +  FREE_AND_NULLIFY(youku_options->api);    cJSON_Delete(youku_options->json);  } @@ -147,13 +147,13 @@ void youku_extract(Options *options) {    char *resp = NULL;    if (get(youku_options.api, &resp)) {      LOG("Youku", "Get API data failed.\n"); -    free_and_nullify(resp); +    FREE_AND_NULLIFY(resp);      goto end;    }    // DEBUG_PRINT("resp: %s\n", resp);    youku_options.json = cJSON_Parse(resp); -  free_and_nullify(resp); +  FREE_AND_NULLIFY(resp);    Youku_data youku_data = {0};    if (parse_jsondata(youku_options.json, &youku_data)) {      LOG("Youku", "Parse jsondata failed.\n"); @@ -170,8 +170,8 @@ void youku_extract(Options *options) {            youku_data.height);    set_str_element(&callback_struct, 1, filename);    add_url(youku_data.m3u8_url, NULL, m3u8fn, youku_convert, &callback_struct); -  free_and_nullify(m3u8fn); -  free_and_nullify(filename); +  FREE_AND_NULLIFY(m3u8fn); +  FREE_AND_NULLIFY(filename);  end:    free_str_array(&results); diff --git a/src/logger.c b/src/logger.c index 0fef20a..e5d17b8 100644 --- a/src/logger.c +++ b/src/logger.c @@ -6,9 +6,7 @@  static struct logger logger = {0}; -struct logger *setup_logger(void) { -  return &logger; -} +struct logger *setup_logger(void) { return &logger; }  void append_log(const char *fmt, ...) {    va_list ap1; @@ -6,8 +6,8 @@  #include <stdio.h>  #include <stdlib.h> -#include "toml.h"  #include "nfd.h" +#include "toml.h"  #define MAX_VERTEX_BUFFER 512 * 1024  #define MAX_ELEMENT_BUFFER 128 * 1024  #define NK_INCLUDE_FIXED_TYPES diff --git a/src/process_url.c b/src/process_url.c index c1d8d38..00bc696 100644 --- a/src/process_url.c +++ b/src/process_url.c @@ -1,4 +1,5 @@  #include "constants.h" +#include "status.h"  #include <curl/curl.h>  #include <curl/easy.h>  #include <curl/header.h> @@ -231,7 +232,7 @@ static int parse_url(const char *URL, const char *outdir, char *fn) {    } else {      curl_c->outfn = malloc(strlen(outdir) + strlen(fn) + 2);      gen_fullpathfn(curl_c->outfn, outdir, fn); -    free_and_nullify(fn); +    FREE_AND_NULLIFY(fn);    }    DEBUG_PRINT("File will be saved as: %s\n", curl_c->outfn);    DEBUG_PRINT("Got regular URL: %s\n", curl_c->URL); @@ -389,9 +390,8 @@ static int merge_and_cleanup(curl_conf_t *curl_c) {    // Reset stat    curl_c->success_thrd = 0;    curl_c->total_thrd = 0; -  free_and_nullify(curl_c->URL); -  free_and_nullify(curl_c->outfn); -  free_and_nullify(curl_c); +  FREE_AND_NULLIFY(curl_c->URL); +  FREE_AND_NULLIFY(curl_c->outfn);    return 0;  } @@ -460,7 +460,7 @@ static char *callback_struct_convert_fullpath(char **p_filename) {    char *tmp = malloc(strlen(outdir_g) + strlen(*p_filename) + 2);    replace_illegal_char(*p_filename);    gen_fullpathfn(tmp, outdir_g, *p_filename); -  free_and_nullify(*p_filename); +  FREE_AND_NULLIFY(*p_filename);    return tmp;  } @@ -469,7 +469,7 @@ void add_cookie(char **p_cookie) {    if (cookie_g) {      char *tmp = malloc(strlen(cookie_g) + strlen(cookie) + 3);      sprintf(tmp, "%s; %s", cookie_g, cookie); -    free_and_nullify(cookie_g); +    FREE_AND_NULLIFY(cookie_g);      cookie_g = tmp;    } else {      cookie_g = cookie; @@ -506,7 +506,7 @@ void curl_cleanup(status_t *stat) {      cnd_destroy(&cnd);    }    free_queue(&dl_queue); -  free_and_nullify(cookie_g); +  FREE_AND_NULLIFY(cookie_g);    curl_url_cleanup(h);    curl_global_cleanup();  } @@ -544,6 +544,7 @@ void poll_status(status_t *stat) {          thrd_join(tid[i], &r);        }        merge_and_cleanup(curl_conf); +      FREE_AND_NULLIFY(curl_conf);        // Perform the callback        if (is_empty_queue(&dl_queue) && callback_g && !corrupted) {          thrd_t cb_thrd; @@ -568,7 +569,7 @@ int get(const char *URL, char **pdstr) {    CURLcode res = logerr(curl_easy_perform(curl));    *pdstr = malloc(pagedata.len + 1);    strcpy(*pdstr, pagedata.string); -  free_and_nullify(pagedata.string); +  FREE_AND_NULLIFY(pagedata.string);    curl_easy_cleanup(curl);    return res;  } diff --git a/src/process_url.h b/src/process_url.h index 72a650f..76fe574 100644 --- a/src/process_url.h +++ b/src/process_url.h @@ -7,15 +7,12 @@  #include <stdbool.h>  #include "constants.h" -#include "utils/utils.h"  #include "status.h" +#include "utils/utils.h"  #define ERRTOSTRING(err) curl_easy_strerror(err)  #define logerr(X)                                                              \ -  _Generic((X), CURLcode                                                       \ -           : logerr_b, CURLHcode                                               \ -           : logerr_h, CURLUcode                                               \ -           : logerr_u)(X) +  _Generic((X), CURLcode: logerr_b, CURLHcode: logerr_h, CURLUcode: logerr_u)(X)  typedef struct curl_conf {    curl_off_t dlnow_per_thrd[MAX_THREAD]; diff --git a/src/status.h b/src/status.h index 5adfff5..e5dcf48 100644 --- a/src/status.h +++ b/src/status.h @@ -12,5 +12,4 @@ typedef struct status {    stat_type_t type;  } status_t; -  #endif diff --git a/src/style.h b/src/style.h index cb7387b..4767b54 100644 --- a/src/style.h +++ b/src/style.h @@ -1,133 +1,131 @@  /*   https://github.com/Immediate-Mode-UI/Nuklear/blob/b4b94b0486c0c43045d0176d03cce016190fe3ff/demo/common/style.c  */ -enum theme {THEME_BLACK, THEME_WHITE, THEME_RED, THEME_BLUE, THEME_DARK}; +enum theme { THEME_BLACK, THEME_WHITE, THEME_RED, THEME_BLUE, THEME_DARK }; -static void -set_style(struct nk_context *ctx, enum theme theme) -{ -    struct nk_color table[NK_COLOR_COUNT]; -    if (theme == THEME_WHITE) { -        table[NK_COLOR_TEXT] = nk_rgba(70, 70, 70, 255); -        table[NK_COLOR_WINDOW] = nk_rgba(175, 175, 175, 255); -        table[NK_COLOR_HEADER] = nk_rgba(175, 175, 175, 255); -        table[NK_COLOR_BORDER] = nk_rgba(0, 0, 0, 255); -        table[NK_COLOR_BUTTON] = nk_rgba(185, 185, 185, 255); -        table[NK_COLOR_BUTTON_HOVER] = nk_rgba(170, 170, 170, 255); -        table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(160, 160, 160, 255); -        table[NK_COLOR_TOGGLE] = nk_rgba(150, 150, 150, 255); -        table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(120, 120, 120, 255); -        table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(175, 175, 175, 255); -        table[NK_COLOR_SELECT] = nk_rgba(190, 190, 190, 255); -        table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(175, 175, 175, 255); -        table[NK_COLOR_SLIDER] = nk_rgba(190, 190, 190, 255); -        table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(80, 80, 80, 255); -        table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(70, 70, 70, 255); -        table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(60, 60, 60, 255); -        table[NK_COLOR_PROPERTY] = nk_rgba(175, 175, 175, 255); -        table[NK_COLOR_EDIT] = nk_rgba(150, 150, 150, 255); -        table[NK_COLOR_EDIT_CURSOR] = nk_rgba(0, 0, 0, 255); -        table[NK_COLOR_COMBO] = nk_rgba(175, 175, 175, 255); -        table[NK_COLOR_CHART] = nk_rgba(160, 160, 160, 255); -        table[NK_COLOR_CHART_COLOR] = nk_rgba(45, 45, 45, 255); -        table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255); -        table[NK_COLOR_SCROLLBAR] = nk_rgba(180, 180, 180, 255); -        table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(140, 140, 140, 255); -        table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(150, 150, 150, 255); -        table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(160, 160, 160, 255); -        table[NK_COLOR_TAB_HEADER] = nk_rgba(180, 180, 180, 255); -        nk_style_from_table(ctx, table); -    } else if (theme == THEME_RED) { -        table[NK_COLOR_TEXT] = nk_rgba(190, 190, 190, 255); -        table[NK_COLOR_WINDOW] = nk_rgba(30, 33, 40, 215); -        table[NK_COLOR_HEADER] = nk_rgba(181, 45, 69, 220); -        table[NK_COLOR_BORDER] = nk_rgba(51, 55, 67, 255); -        table[NK_COLOR_BUTTON] = nk_rgba(181, 45, 69, 255); -        table[NK_COLOR_BUTTON_HOVER] = nk_rgba(190, 50, 70, 255); -        table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(195, 55, 75, 255); -        table[NK_COLOR_TOGGLE] = nk_rgba(51, 55, 67, 255); -        table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 60, 60, 255); -        table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(181, 45, 69, 255); -        table[NK_COLOR_SELECT] = nk_rgba(51, 55, 67, 255); -        table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(181, 45, 69, 255); -        table[NK_COLOR_SLIDER] = nk_rgba(51, 55, 67, 255); -        table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(181, 45, 69, 255); -        table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(186, 50, 74, 255); -        table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(191, 55, 79, 255); -        table[NK_COLOR_PROPERTY] = nk_rgba(51, 55, 67, 255); -        table[NK_COLOR_EDIT] = nk_rgba(51, 55, 67, 225); -        table[NK_COLOR_EDIT_CURSOR] = nk_rgba(190, 190, 190, 255); -        table[NK_COLOR_COMBO] = nk_rgba(51, 55, 67, 255); -        table[NK_COLOR_CHART] = nk_rgba(51, 55, 67, 255); -        table[NK_COLOR_CHART_COLOR] = nk_rgba(170, 40, 60, 255); -        table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255); -        table[NK_COLOR_SCROLLBAR] = nk_rgba(30, 33, 40, 255); -        table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255); -        table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255); -        table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255); -        table[NK_COLOR_TAB_HEADER] = nk_rgba(181, 45, 69, 220); -        nk_style_from_table(ctx, table); -    } else if (theme == THEME_BLUE) { -        table[NK_COLOR_TEXT] = nk_rgba(20, 20, 20, 255); -        table[NK_COLOR_WINDOW] = nk_rgba(202, 212, 214, 215); -        table[NK_COLOR_HEADER] = nk_rgba(137, 182, 224, 220); -        table[NK_COLOR_BORDER] = nk_rgba(140, 159, 173, 255); -        table[NK_COLOR_BUTTON] = nk_rgba(137, 182, 224, 255); -        table[NK_COLOR_BUTTON_HOVER] = nk_rgba(142, 187, 229, 255); -        table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(147, 192, 234, 255); -        table[NK_COLOR_TOGGLE] = nk_rgba(177, 210, 210, 255); -        table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(182, 215, 215, 255); -        table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(137, 182, 224, 255); -        table[NK_COLOR_SELECT] = nk_rgba(177, 210, 210, 255); -        table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(137, 182, 224, 255); -        table[NK_COLOR_SLIDER] = nk_rgba(177, 210, 210, 255); -        table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(137, 182, 224, 245); -        table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(142, 188, 229, 255); -        table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(147, 193, 234, 255); -        table[NK_COLOR_PROPERTY] = nk_rgba(210, 210, 210, 255); -        table[NK_COLOR_EDIT] = nk_rgba(210, 210, 210, 225); -        table[NK_COLOR_EDIT_CURSOR] = nk_rgba(20, 20, 20, 255); -        table[NK_COLOR_COMBO] = nk_rgba(210, 210, 210, 255); -        table[NK_COLOR_CHART] = nk_rgba(210, 210, 210, 255); -        table[NK_COLOR_CHART_COLOR] = nk_rgba(137, 182, 224, 255); -        table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255); -        table[NK_COLOR_SCROLLBAR] = nk_rgba(190, 200, 200, 255); -        table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255); -        table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255); -        table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255); -        table[NK_COLOR_TAB_HEADER] = nk_rgba(156, 193, 220, 255); -        nk_style_from_table(ctx, table); -    } else if (theme == THEME_DARK) { -        table[NK_COLOR_TEXT] = nk_rgba(210, 210, 210, 255); -        table[NK_COLOR_WINDOW] = nk_rgba(57, 67, 71, 215); -        table[NK_COLOR_HEADER] = nk_rgba(51, 51, 56, 220); -        table[NK_COLOR_BORDER] = nk_rgba(46, 46, 46, 255); -        table[NK_COLOR_BUTTON] = nk_rgba(48, 83, 111, 255); -        table[NK_COLOR_BUTTON_HOVER] = nk_rgba(58, 93, 121, 255); -        table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(63, 98, 126, 255); -        table[NK_COLOR_TOGGLE] = nk_rgba(50, 58, 61, 255); -        table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 53, 56, 255); -        table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(48, 83, 111, 255); -        table[NK_COLOR_SELECT] = nk_rgba(57, 67, 61, 255); -        table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(48, 83, 111, 255); -        table[NK_COLOR_SLIDER] = nk_rgba(50, 58, 61, 255); -        table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(48, 83, 111, 245); -        table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255); -        table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255); -        table[NK_COLOR_PROPERTY] = nk_rgba(50, 58, 61, 255); -        table[NK_COLOR_EDIT] = nk_rgba(50, 58, 61, 225); -        table[NK_COLOR_EDIT_CURSOR] = nk_rgba(210, 210, 210, 255); -        table[NK_COLOR_COMBO] = nk_rgba(50, 58, 61, 255); -        table[NK_COLOR_CHART] = nk_rgba(50, 58, 61, 255); -        table[NK_COLOR_CHART_COLOR] = nk_rgba(48, 83, 111, 255); -        table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba(255, 0, 0, 255); -        table[NK_COLOR_SCROLLBAR] = nk_rgba(50, 58, 61, 255); -        table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(48, 83, 111, 255); -        table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255); -        table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255); -        table[NK_COLOR_TAB_HEADER] = nk_rgba(48, 83, 111, 255); -        nk_style_from_table(ctx, table); -    } else { -        nk_style_default(ctx); -    } +static void set_style(struct nk_context *ctx, enum theme theme) { +  struct nk_color table[NK_COLOR_COUNT]; +  if (theme == THEME_WHITE) { +    table[NK_COLOR_TEXT] = nk_rgba(70, 70, 70, 255); +    table[NK_COLOR_WINDOW] = nk_rgba(175, 175, 175, 255); +    table[NK_COLOR_HEADER] = nk_rgba(175, 175, 175, 255); +    table[NK_COLOR_BORDER] = nk_rgba(0, 0, 0, 255); +    table[NK_COLOR_BUTTON] = nk_rgba(185, 185, 185, 255); +    table[NK_COLOR_BUTTON_HOVER] = nk_rgba(170, 170, 170, 255); +    table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(160, 160, 160, 255); +    table[NK_COLOR_TOGGLE] = nk_rgba(150, 150, 150, 255); +    table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(120, 120, 120, 255); +    table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(175, 175, 175, 255); +    table[NK_COLOR_SELECT] = nk_rgba(190, 190, 190, 255); +    table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(175, 175, 175, 255); +    table[NK_COLOR_SLIDER] = nk_rgba(190, 190, 190, 255); +    table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(80, 80, 80, 255); +    table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(70, 70, 70, 255); +    table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(60, 60, 60, 255); +    table[NK_COLOR_PROPERTY] = nk_rgba(175, 175, 175, 255); +    table[NK_COLOR_EDIT] = nk_rgba(150, 150, 150, 255); +    table[NK_COLOR_EDIT_CURSOR] = nk_rgba(0, 0, 0, 255); +    table[NK_COLOR_COMBO] = nk_rgba(175, 175, 175, 255); +    table[NK_COLOR_CHART] = nk_rgba(160, 160, 160, 255); +    table[NK_COLOR_CHART_COLOR] = nk_rgba(45, 45, 45, 255); +    table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba(255, 0, 0, 255); +    table[NK_COLOR_SCROLLBAR] = nk_rgba(180, 180, 180, 255); +    table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(140, 140, 140, 255); +    table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(150, 150, 150, 255); +    table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(160, 160, 160, 255); +    table[NK_COLOR_TAB_HEADER] = nk_rgba(180, 180, 180, 255); +    nk_style_from_table(ctx, table); +  } else if (theme == THEME_RED) { +    table[NK_COLOR_TEXT] = nk_rgba(190, 190, 190, 255); +    table[NK_COLOR_WINDOW] = nk_rgba(30, 33, 40, 215); +    table[NK_COLOR_HEADER] = nk_rgba(181, 45, 69, 220); +    table[NK_COLOR_BORDER] = nk_rgba(51, 55, 67, 255); +    table[NK_COLOR_BUTTON] = nk_rgba(181, 45, 69, 255); +    table[NK_COLOR_BUTTON_HOVER] = nk_rgba(190, 50, 70, 255); +    table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(195, 55, 75, 255); +    table[NK_COLOR_TOGGLE] = nk_rgba(51, 55, 67, 255); +    table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 60, 60, 255); +    table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(181, 45, 69, 255); +    table[NK_COLOR_SELECT] = nk_rgba(51, 55, 67, 255); +    table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(181, 45, 69, 255); +    table[NK_COLOR_SLIDER] = nk_rgba(51, 55, 67, 255); +    table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(181, 45, 69, 255); +    table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(186, 50, 74, 255); +    table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(191, 55, 79, 255); +    table[NK_COLOR_PROPERTY] = nk_rgba(51, 55, 67, 255); +    table[NK_COLOR_EDIT] = nk_rgba(51, 55, 67, 225); +    table[NK_COLOR_EDIT_CURSOR] = nk_rgba(190, 190, 190, 255); +    table[NK_COLOR_COMBO] = nk_rgba(51, 55, 67, 255); +    table[NK_COLOR_CHART] = nk_rgba(51, 55, 67, 255); +    table[NK_COLOR_CHART_COLOR] = nk_rgba(170, 40, 60, 255); +    table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba(255, 0, 0, 255); +    table[NK_COLOR_SCROLLBAR] = nk_rgba(30, 33, 40, 255); +    table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255); +    table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255); +    table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255); +    table[NK_COLOR_TAB_HEADER] = nk_rgba(181, 45, 69, 220); +    nk_style_from_table(ctx, table); +  } else if (theme == THEME_BLUE) { +    table[NK_COLOR_TEXT] = nk_rgba(20, 20, 20, 255); +    table[NK_COLOR_WINDOW] = nk_rgba(202, 212, 214, 215); +    table[NK_COLOR_HEADER] = nk_rgba(137, 182, 224, 220); +    table[NK_COLOR_BORDER] = nk_rgba(140, 159, 173, 255); +    table[NK_COLOR_BUTTON] = nk_rgba(137, 182, 224, 255); +    table[NK_COLOR_BUTTON_HOVER] = nk_rgba(142, 187, 229, 255); +    table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(147, 192, 234, 255); +    table[NK_COLOR_TOGGLE] = nk_rgba(177, 210, 210, 255); +    table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(182, 215, 215, 255); +    table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(137, 182, 224, 255); +    table[NK_COLOR_SELECT] = nk_rgba(177, 210, 210, 255); +    table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(137, 182, 224, 255); +    table[NK_COLOR_SLIDER] = nk_rgba(177, 210, 210, 255); +    table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(137, 182, 224, 245); +    table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(142, 188, 229, 255); +    table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(147, 193, 234, 255); +    table[NK_COLOR_PROPERTY] = nk_rgba(210, 210, 210, 255); +    table[NK_COLOR_EDIT] = nk_rgba(210, 210, 210, 225); +    table[NK_COLOR_EDIT_CURSOR] = nk_rgba(20, 20, 20, 255); +    table[NK_COLOR_COMBO] = nk_rgba(210, 210, 210, 255); +    table[NK_COLOR_CHART] = nk_rgba(210, 210, 210, 255); +    table[NK_COLOR_CHART_COLOR] = nk_rgba(137, 182, 224, 255); +    table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba(255, 0, 0, 255); +    table[NK_COLOR_SCROLLBAR] = nk_rgba(190, 200, 200, 255); +    table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255); +    table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255); +    table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255); +    table[NK_COLOR_TAB_HEADER] = nk_rgba(156, 193, 220, 255); +    nk_style_from_table(ctx, table); +  } else if (theme == THEME_DARK) { +    table[NK_COLOR_TEXT] = nk_rgba(210, 210, 210, 255); +    table[NK_COLOR_WINDOW] = nk_rgba(57, 67, 71, 215); +    table[NK_COLOR_HEADER] = nk_rgba(51, 51, 56, 220); +    table[NK_COLOR_BORDER] = nk_rgba(46, 46, 46, 255); +    table[NK_COLOR_BUTTON] = nk_rgba(48, 83, 111, 255); +    table[NK_COLOR_BUTTON_HOVER] = nk_rgba(58, 93, 121, 255); +    table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(63, 98, 126, 255); +    table[NK_COLOR_TOGGLE] = nk_rgba(50, 58, 61, 255); +    table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 53, 56, 255); +    table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(48, 83, 111, 255); +    table[NK_COLOR_SELECT] = nk_rgba(57, 67, 61, 255); +    table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(48, 83, 111, 255); +    table[NK_COLOR_SLIDER] = nk_rgba(50, 58, 61, 255); +    table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(48, 83, 111, 245); +    table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255); +    table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255); +    table[NK_COLOR_PROPERTY] = nk_rgba(50, 58, 61, 255); +    table[NK_COLOR_EDIT] = nk_rgba(50, 58, 61, 225); +    table[NK_COLOR_EDIT_CURSOR] = nk_rgba(210, 210, 210, 255); +    table[NK_COLOR_COMBO] = nk_rgba(50, 58, 61, 255); +    table[NK_COLOR_CHART] = nk_rgba(50, 58, 61, 255); +    table[NK_COLOR_CHART_COLOR] = nk_rgba(48, 83, 111, 255); +    table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba(255, 0, 0, 255); +    table[NK_COLOR_SCROLLBAR] = nk_rgba(50, 58, 61, 255); +    table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(48, 83, 111, 255); +    table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255); +    table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255); +    table[NK_COLOR_TAB_HEADER] = nk_rgba(48, 83, 111, 255); +    nk_style_from_table(ctx, table); +  } else { +    nk_style_default(ctx); +  }  } @@ -4,15 +4,16 @@  #include <stdlib.h>  #include <string.h> +#include "nfd.h"  #include "nuklear.h"  #include "process_url.h" -#include "nfd.h"  #include "constants.h"  #include "logger.h"  #include "ui.h"  #include "utils/size_info.h"  #include "utils/time_info.h" +#include "utils/utils.h"  static nk_size pct;  static bool show_app_about; @@ -42,8 +43,8 @@ void load_ui(struct ui_struct *ui) {        sprintf(status_string, "%s/%s, %hhu%%", cur_ts, total_ts,                (unsigned char)pct); -      free_and_nullify(cur_ts); -      free_and_nullify(total_ts); +      FREE_AND_NULLIFY(cur_ts); +      FREE_AND_NULLIFY(total_ts);      }    }    if (ui->stat->is_done) { diff --git a/src/utils/types.c b/src/utils/types.c index e414f92..b9aab7b 100644 --- a/src/utils/types.c +++ b/src/utils/types.c @@ -15,7 +15,7 @@ generic_array_t create_array(size_t elem_size, size_t n) {  }  void free_array(generic_array_t *array) { -  free_and_nullify(array->data); +  FREE_AND_NULLIFY(array->data);    array->n = 0;  } @@ -54,7 +54,7 @@ void free_str_array(str_array_t *array) {    for (size_t i = 0; i < array->n; i++) {      free(array->str[i]);    } -  free_and_nullify(array->str); +  FREE_AND_NULLIFY(array->str);    array->n = 0;  } @@ -116,7 +116,7 @@ data_t dequeue(queue_t *queue) {    node_t *temp = queue->front;    data_t data = temp->data;    queue->front = temp->next; -  free_and_nullify(temp); +  FREE_AND_NULLIFY(temp);    if (queue->front == NULL) {      queue->rear = NULL; diff --git a/src/utils/utils.c b/src/utils/utils.c index ae60eee..7b94ff3 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -169,10 +169,3 @@ int repchr(char *str, char t, char r) {    }    return c;  } - -void free_and_nullify(void *p) { -  if (p) { -    free(p); -    p = NULL; -  } -} diff --git a/src/utils/utils.h b/src/utils/utils.h index 5a26cf2..3b44f3f 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -4,6 +4,8 @@  #include <stddef.h>  #include "types.h" +#define FREE_AND_NULLIFY(x) do{if(x)free(x); x = NULL;}while(0) +  int regex_match(const char *, str_array_t, str_array_t *);  int substitute_str(const char *subject, const char *pattern, @@ -13,7 +15,4 @@ const char *mimeType2ext(const char *mimeType);  int repchr(char *str, char t, char r); -/* NOTICE: pass a pointer-to-pointer to free the original pointer. */ -void free_and_nullify(void *p); -  #endif | 
