From d1ab070dd1b7902356b74f192eb0fbecb6437b51 Mon Sep 17 00:00:00 2001 From: Aaron Ball Date: Tue, 31 Mar 2015 20:22:10 -0600 Subject: Implemented extension removal from list operations Was printing extensions, which are not required when interracting with the given note. This was a bit confusing, despite fuzzy name matching. This strips the extension from the file/note names when listening notes. --- src/common.c | 18 ++++++++++++++++++ src/common.h | 2 ++ src/main.c | 5 ++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/common.c b/src/common.c index e2ca4f4..65eb1ad 100644 --- a/src/common.c +++ b/src/common.c @@ -292,3 +292,21 @@ int str_contains_case_sensitive(char* str, char* term) { } return 0; } + +/** + * Removes the extension from the given string filename + * + * @param filename Filename/path to strip extension from + * + * @return int Result of the strip operation + */ +int strip_extension(char* filename) { + for(int i = strlen(filename); i > 0; i--) { + if(filename[i] == '.') { + filename[i] = '\0'; + return 0; + } + } + return -1; +} + diff --git a/src/common.h b/src/common.h index c462a80..5a3deea 100644 --- a/src/common.h +++ b/src/common.h @@ -38,4 +38,6 @@ int str_contains_case_sensitive(char*, char*); int str_contains_case_insensitive(char*, char*); +int strip_extension(char*); + #endif diff --git a/src/main.c b/src/main.c index 9ee10f9..f5558ff 100644 --- a/src/main.c +++ b/src/main.c @@ -54,7 +54,10 @@ void get_help() { void list_notes(note_list_t* list) { // List notes for(int i = 0; i < list->count; i++) { - printf("* %s\n", list->names[i]); + char name[128]; + strcpy(name, list->names[i]); + strip_extension(name); + printf("* %s\n", name); } } -- cgit v1.2.3