diff --git a/src/main.c b/src/main.c index a06a515..844052c 100644 --- a/src/main.c +++ b/src/main.c @@ -289,6 +289,8 @@ int main(int argc, char *argv[]) { goto vault_creation; } else { goto note_selection; + debug("[BYPASS] %s does exist. Going to note selection"); + } } @@ -356,11 +358,13 @@ note_selection: char *noteSelected; // if we set to bypass the note selector if (bypassSelectionNote) { - // (TODO LATER) Add shouldDebug info + debug("We are bypassing note selection."); noteSelected = bypassSelectionNoteValue; if (isStringInArray(noteSelected, (const char **)filesArray, filesCount)) {// we just give filesCount and not filesCount + extraOptions to avoid matching with an extra options. + debug("The note specified with -n or --note does exist. Opening it."); goto open_note; } else { // if the specified note doesn't exist. We creat it + debug("The note specified with -n or --note doesn't exist. Creating it."); goto note_creation; } } diff --git a/src/notes.c b/src/notes.c index d0b0746..80462c9 100644 --- a/src/notes.c +++ b/src/notes.c @@ -1,5 +1,6 @@ #include "notes.h" +// (TODO LATER) Check if it isn't a know media file like .jpg, etc. more generally only text, code or markdown file should be accepted. maybe se if it is in utf8? char **getJournalsFromVault(char *pathToVault, char *vault, char *journalRegex, int *count, int shouldDebug) { debug("Searching %s for journals", vault); // originally from https://www.geeksforgeeks.org/c/c-program-list-files-sub-directories-directory/ @@ -184,6 +185,8 @@ char *updateJournal(char *path, char *journal, char *timeFormat, int shouldDebug altDebug("└------------------------------\n"); // free's some used memory closedir(dividedJournalDirectory); + qsort(entryArray + 1, entryCount - 1, sizeof(const char *), reverseCompareString); // sorts the journals entries alphabetically. // the + 1 - 1 is to not sort "Create new entry for the journal" which is the first element + // we must now select to create new entry or to enter in old one char *selectedOption = ncursesSelect(entryArray, "Create new entry or acces old entry (Use arrows or WASD, Enter to select):", 1, entryCount -1, " ", " ", "", shouldDebug); // the "Create new entry for the journal %s" will be the only options. All other will be extraOptions. This is made so that "Create [...] %s" will always be on top debug("Selected option from journal entry selection: %s", selectedOption); diff --git a/src/utils.c b/src/utils.c index dbda7ff..216daa7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -8,6 +8,11 @@ int compareString(const void *a, const void *b) { const char *str2 = *(const char **)b; return strcmp(str1, str2); // strcmp returns <0, 0, >0 } +int reverseCompareString(const void *a, const void *b) { + const char *str1 = *(const char **)a; + const char *str2 = *(const char **)b; + return -1*strcmp(str1, str2); +} void getCurrentTime(int *hour, int *minute, int *second) { time_t now = time(NULL); // Get current time in seconds since epoch diff --git a/src/utils.h b/src/utils.h index 43713eb..38233fa 100644 --- a/src/utils.h +++ b/src/utils.h @@ -37,6 +37,9 @@ extern const int numEditors; // number of supported editors //compares two strings alphabetically. //this function is used for qsort int compareString(const void *a, const void *b); +// compares two strings in reversed alphabetical order +// this function is used for qsort +int reverseCompareString(const void *a, const void *b); // this basically checks all the dirs from your path for the editor. This is a safety check. // If the executable from an editor is not the editor name (for example neovim and nvim), you must handle at the start of the function. int doesEditorExist(char *editorToCheck, int debug);