-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
bin_PROGRAMS = wkline | ||
wkline_SOURCES = \ | ||
util/log.c \ | ||
src/load_config.c \ | ||
src/wkline.c \ | ||
src/widgets/desktops.c | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "load_config.h" | ||
|
||
#include <string.h> | ||
|
||
int | ||
load_config_file (wkline_config_t *config) { | ||
const char *user_config_file = g_build_filename(g_get_user_config_dir(), "wkline", "config.json", NULL); | ||
json_error_t err; | ||
json_t *json_config = json_load_file(user_config_file, 0, &err); | ||
|
||
if (! json_config) { | ||
fprintf(stderr, "\n***************************\nFailed to load config file!\n***************************\n\n%s\n\nPlease make sure that '%s' exists and contains valid JSON data.\n\n", err.text, user_config_file); | ||
exit(1); | ||
} | ||
|
||
config->height = json_integer_value(json_object_get(json_config, "height")); | ||
config->position = json_string_value(json_object_get(json_config, "position")) == "top" ? WKLINE_POSITION_TOP : WKLINE_POSITION_BOTTOM; | ||
strcpy(config->theme_uri, json_string_value(json_object_get(json_config, "theme_uri"))); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Lokaltog
Author
Owner
|
||
strcpy(config->background, json_string_value(json_object_get(json_config, "background"))); | ||
|
||
json_decref(json_config); | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <glib.h> | ||
#include <jansson.h> | ||
|
||
#define CONFIG_BUF_SIZE 256 | ||
|
||
enum wkline_position { | ||
WKLINE_POSITION_TOP, | ||
WKLINE_POSITION_BOTTOM | ||
}; | ||
|
||
typedef struct wkline_config_t { | ||
int height; | ||
enum wkline_position position; | ||
char theme_uri[CONFIG_BUF_SIZE]; | ||
char background[CONFIG_BUF_SIZE]; | ||
} wkline_config_t; |
This might be the cause of your issue here, the config->theme_url pointer needs to be allocated before something is assigned to it. Have a look at
strnprintf()
andstrncpy()
to help with getting/setting the size of the pointer, then callingmalloc()
, and finally setting the value as needed.