From b614e1e994694d44aebaf23c4009079ca4021796 Mon Sep 17 00:00:00 2001 From: Tomas Rivera <137088692+Totorile1@users.noreply.github.com> Date: Sun, 29 Mar 2026 13:30:49 +0200 Subject: [PATCH] the code now list all the directories --- README.md | 4 +-- a.out | Bin 0 -> 16664 bytes config.json | 6 ++++ shell.nix | 2 ++ startup.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 2 deletions(-) create mode 100755 a.out create mode 100644 config.json create mode 100644 startup.c diff --git a/README.md b/README.md index 236f60a..0428bb6 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ some way to specify the browser things to do: -1. port vivify.vim to nixos - +1. port vivify.vim to nixos (got problems see `https://discourse.nixos.org/t/help-with-adding-a-vim-plugin-in-nixpkgs/76682`) +2. i'm gonna work on the TUI for now. diff --git a/a.out b/a.out new file mode 100755 index 0000000000000000000000000000000000000000..dd386a02cd2224ce6f4de4221659b75d188a2d38 GIT binary patch literal 16664 zcmeHOYj7LY6~0zpCM33b1VU0^36CZO$(G-S2IM>(nX!|QIJC6DMwV8#h%AZKI42}C*D8DpIQh+`LIplx!-6^YkU05yQD~N}VJ;eMnf#_vQORyT zt}12D`ciuuIfFF$U*ZSI0L0wsN3l70o>Ys2pDO2?+V6#mvmb?v{Dj}O7fZ^yrsBz* z<4N78ZR`x&-pxZcTskgpzlW5cn`_FCImdq8OIGaTw6{k2-K{Ega}_SZoZGtueljkq zKOe>TFt1hZc^!ua6@TXHaEiuMVyrQ1rA?!8li3l=c5d1{m~4)3>ByMP&B0jPcvHMH z)fH*m9EbIMo0Z<92b~Lv!sc%Pq+kbSBqq&9BFSVr z3W!D#)z^_oA_Z6MmI+04ETYE~sYo)h#Sn4JNG8!}Bqpnq6$`3Vikr;@dL7Ri#zsN) zU6oCzXz&S2iAwEaWnb^oWqNaq)VEj9<*oa118V^cQT-rBNh+-z-WN)EMO z-PL4v4R)nE&Dc;^u+xtr)1Mti_h<+_-!X#5#%b*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al 0 HcmV?d00001 diff --git a/config.json b/config.json new file mode 100644 index 0000000..f988c52 --- /dev/null +++ b/config.json @@ -0,0 +1,6 @@ +{ + "directory": "/home/tomasr/Documents/Notes/" + + + +} diff --git a/shell.nix b/shell.nix index f9a4a4a..3b317dd 100644 --- a/shell.nix +++ b/shell.nix @@ -3,5 +3,7 @@ pkgs.mkShell { buildInputs = [ pkgs.vivify + pkgs.cjson + pkgs.pkg-config ]; } diff --git a/startup.c b/startup.c new file mode 100644 index 0000000..45d39d2 --- /dev/null +++ b/startup.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include + +int main() { + // Read config file + FILE *f = fopen("./config.json", "r"); + if (!f) { + fprintf(stderr, "Could not open config.json\n"); + return 1; + } + + fseek(f, 0, SEEK_END); + long size = ftell(f); + rewind(f); + + char *data = malloc(size + 1); + size_t read_bytes = fread(data, 1, size, f); + if (read_bytes != size) { + fprintf(stderr, "Failed to read file\n"); + free(data); + fclose(f); + return 1; + } + data[size] = 0; + fclose(f); + + // Parse JSON + cJSON *json = cJSON_Parse(data); + if (!json) { + fprintf(stderr, "JSON parse error\n"); + free(data); + return 1; + } + + // Get "directory" + cJSON *dirJsonFormat = cJSON_GetObjectItem(json, "directory"); + + char *notesDirectoryString = NULL; + if (dirJsonFormat && cJSON_IsString(dirJsonFormat) && dirJsonFormat->valuestring != NULL) { + notesDirectoryString = strdup(dirJsonFormat->valuestring); // independent string + } else { + notesDirectoryString = "~/Documents/Notes/"; // default + } + + // (TODO LATER) it might be a good idea to check if these directories exist + // (TODO LATER) expand ~ as it does not work with opendir() + printf("Opening %s\n", notesDirectoryString); + + //--------------------------------------------------------------------------------------- + // https://www.geeksforgeeks.org/c/c-program-list-files-sub-directories-directory/ + struct dirent *notesDirectoryEntry; + DIR *notesDirectory = opendir(notesDirectoryString); + if (notesDirectory == NULL) // opendir returns NULL if couldn't open directory + { + printf("Could not open current directory" ); + return 1; + } + // Refer https://pubs.opengroup.org/onlinepubs/7990989775/xsh/readdir.html + // for readdir() + while ((notesDirectoryEntry = readdir(notesDirectory)) != NULL) + printf("%s\n", notesDirectoryEntry->d_name); + + + //-------------------------------------------------------------------------------------- + + // list all the directories (except hidden ones). They are like obsidian vaults + + // Cleanup + if (dirJsonFormat && notesDirectoryString != dirJsonFormat->valuestring) free(notesDirectoryString); // only free strdup + closedir(notesDirectory); + cJSON_Delete(json); + free(data); + + return 0; +}