summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@iohq.net>2015-02-25 11:13:52 -0700
committerAaron Ball <nullspoon@iohq.net>2015-02-25 11:13:52 -0700
commit31d811a29587e93fe8efceefd1426c303b5c6117 (patch)
treea71fef31ce40db505bb36dc12292870a149b1afc
parentc6acb00c71c7a09cb5a29fc0d48ab1052d5689b4 (diff)
downloadnoteless-31d811a29587e93fe8efceefd1426c303b5c6117.tar.gz
noteless-31d811a29587e93fe8efceefd1426c303b5c6117.tar.xz
Changed note_list note names to include extensions
Was storing the filename sans extension and period. That was however making path construction for accessing actual note files fairly complex (strlen(path) + strlen(note name) + strlen(extension) + path_delim_space);). This way, rather than needing to always append the extension, we will just strip the extension off when needed - a situation that occures much less frequently.
-rw-r--r--src/note_list.c27
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(&note, 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(&note, path);
+
// Read in the note's contents
note_cat(&note);
} else {

Generated by cgit