diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 58 |
1 files changed, 18 insertions, 40 deletions
@@ -1,5 +1,5 @@ /** - * Copyright (C) 2016 Aaron Ball <nullspoon@oper.io> + * Copyright (C) 2021 Aaron Ball <nullspoon@oper.io> * * Noteless is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -79,35 +79,23 @@ void list_notes(note_list* list) { /** - * Sets up environment variables. + * Set up environment variables. * Handles loading in configuration defaults before loading the config file * values if one is present. */ -void config_setup(config_t* c) { - // Get the home dir - char home_path[strlen(getenv("HOME"))]; - strcpy(home_path, getenv("HOME")); +void config_setup(struct config *c) { + char cpath[1024]; + config_init(c); // Set default note path - char tmp_note_path[strlen(home_path) + 17]; - strcpy(tmp_note_path, home_path); - strcat(tmp_note_path, "/Documents/Notes"); - config_set(c, "note_path", tmp_note_path); - + sprintf(c->notepath, "%s/%s", getenv("HOME"), "/Documents/Notes"); + // Set the default note extension + strcpy(c->extension, "adoc"); // Set the default note extension - config_set(c, "extension", "mdown"); - - // Set editor default - char tmp_editor[128]; - get_user_editor(tmp_editor); - config_set(c, "editor", tmp_editor); - - // Assemble the path to the conf file - char conf_path[strlen(home_path) + 23]; - strcpy(conf_path, home_path); - strcat(conf_path, "/.config/noteless.conf"); - // Load the actual config file to override any defaults - config_load(c, conf_path); + strcpy(c->editor, "vim"); + + sprintf(cpath, "%s/.config/noteless.conf", getenv("HOME")); + config_read(c, cpath); } @@ -119,33 +107,25 @@ int main(int argc, char* argv []) { return 1; } - config_t c; + struct config c; note_list list; - - // - // Config setup - // - config_setup(&c); - note_list_new( - &list, - config_get(&c, "note_path"), - config_get(&c, "extension") - ); + config_setup(&c); + note_list_new(&list, c.notepath, c.extension); if(errno != 0) { return 1; } if(strcmp(argv[1], "ls") == 0 || strcmp(argv[1], "list") == 0) { list_notes(&list); } else if(strcmp(argv[1], "new") == 0) { - int create_status = note_list_create_note(&list, config_get(&c, "editor"), argv[2]); + int create_status = note_list_create_note(&list, c.editor, argv[2]); // Notify user that a note already exists by the specified name if(create_status == 1) { printf("A note by the name %s already exists.\n", argv[2]); return create_status; } } else if(strcmp(argv[1], "edit") == 0) { - return note_list_edit(&list, config_get(&c, "editor"), argv[2]); + return note_list_edit(&list, c.editor, argv[2]); } else if(strcmp(argv[1], "rm") == 0) { int rm_status = note_list_rm_note(&list, argv[2]); if(rm_status == 0) { @@ -163,7 +143,7 @@ int main(int argc, char* argv []) { } else if(strcmp(argv[1], "help") == 0) { get_help(); } else { - int err = note_list_edit(&list, config_get(&c, "editor"), argv[1]); + int err = note_list_edit(&list, c.editor, argv[1]); if(err == 1) { printf("%s is also not a valid command.\n", argv[1]); return 1; @@ -172,7 +152,5 @@ int main(int argc, char* argv []) { // Clean up note_list_free(&list); - config_free(&c); - return 0; } |