diff options
-rw-r--r-- | src/note_list.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/note_list.c b/src/note_list.c index 2e1740a..0376508 100644 --- a/src/note_list.c +++ b/src/note_list.c @@ -53,20 +53,16 @@ void note_list_new(note_list_t* list, char* path, char* ext) { // The start index of the extension in the current filename int ext_start = strlen(ent->d_name) - ext_len; - // If the current file's extension matches the list extension + // If the current file's extension matches the list extension... if(strncmp(&ent->d_name[ext_start], ext, ext_len) == 0) { - // Allocate space in the array for the filename (all the way up to the - // period starting the extension) - list->names[i] = malloc(sizeof(char) * ext_start); + // Allocate space for the entire filename (we'll strip the extension off + // as needed later). This will make calculating path lengths much + // simpler. + list->names[i] = malloc(sizeof(char) * strlen(ent->d_name)); - // Copy the temp filename into the struct - // As previously mentioned, we want to copy minus one char (the period) - // so we have room for the null byte char. - strncpy(list->names[i], ent->d_name, ext_start); + // Copy the filename into the struct + strcpy(list->names[i], ent->d_name); - // Insert null byte char one before the extension (the period) - list->names[i][ext_start - 1] = '\0'; - i++; } } @@ -176,8 +172,6 @@ int note_list_edit(note_list_t* list, char* editor, char* note_name) { strcpy(path, list->path); strcat(path, "/"); strcat(path, list->names[id]); - strcat(path, "."); - strcat(path, list->extension); note_t note; note_new(¬e, path); @@ -226,15 +220,14 @@ int note_list_cat_note(note_list_t* list, char* note_name) { int id = note_list_get_note_id(list, note_name); if(id != -1) { // Construct the full note path - char path[strlen(list->path) + strlen(list->names[id]) + strlen(list->extension) + 3]; + char path[strlen(list->path) + strlen(list->names[id]) + 3]; strcpy(path, list->path); strcat(path, "/"); strcat(path, list->names[id]); - strcat(path, "."); - strcat(path, list->extension); - // TODO + note_t note; note_new(¬e, path); + // Read in the note's contents note_cat(¬e); } else { |