Thumbnail

rani/cscroll.git

Clone URL: https://git.buni.party/rani/cscroll.git

commit 0ff1d0ccbf1bba4e5f4534502aa0171c4cc33315 Author: Raniconduh <clagv.randomgames@gmail.com> Date: Tue Oct 12 09:19:11 2021 +0000 Symbolic links are now shown correctly and usable diff --git a/include/dir.h b/include/dir.h index c9015ab..b3d5ff7 100644 --- a/include/dir.h +++ b/include/dir.h @@ -246 +247 @@ enum file_type_t {  struct dir_entry_t {   char * name;   enum file_type_t file_type; + enum file_type_t under_link;   bool exec;   bool marked;  }; diff --git a/src/dir.c b/src/dir.c index 03bb073..fab2201 100644 --- a/src/dir.c +++ b/src/dir.c @@ -468 +467 @@ int list_dir(char * dir_path) {   struct stat * buf = malloc(sizeof(struct stat));   char * tmp_path = malloc(d_name_len + strlen(dir_path) + 2);   sprintf(tmp_path, "%s/%s", dir_path, d_name); - stat(tmp_path, buf); - free(tmp_path); + lstat(tmp_path, buf);     dir_entries = realloc(dir_entries, sizeof(struct dir_entry_t) * (n_dir_entries + 1));   dir_entry->name = malloc(d_name_len + 1); @@ -676 +6612 @@ int list_dir(char * dir_path) {   break;   case S_IFLNK:   dir_entry->file_type = FILE_LINK; + struct stat * buf2 = malloc(sizeof(struct stat)); + stat(tmp_path, buf2); + if ((buf2->st_mode & S_IFMT) == S_IFDIR) + dir_entry->under_link = FILE_DIR; + else dir_entry->under_link = FILE_UNKNOWN; + free(buf2);   break;   case S_IFIFO:   dir_entry->file_type = FILE_FIFO; @@ -836 +887 @@ int list_dir(char * dir_path) {   dir_entry->exec = (bool)(buf->st_mode & S_IXUSR);   else dir_entry->exec = false;   + free(tmp_path);   free(buf);     dir_entry->marked = false; diff --git a/src/io.c b/src/io.c index c0726f7..c1dc861 100644 --- a/src/io.c +++ b/src/io.c @@ -476 +477 @@ void terminate_curses(void) {  void curses_write_file(struct dir_entry_t * dir_entry, bool highlight) {   int cp = -1;   char f_ident; + char * u_text = "";     switch (dir_entry->file_type) {   case FILE_DIR: @@ -626 +638 @@ void curses_write_file(struct dir_entry_t * dir_entry, bool highlight) {   f_ident = '#';   break;   case FILE_LINK: + if (dir_entry->under_link == FILE_DIR) + u_text = "=> /";   cp = CYAN;   f_ident = '@';   break; @@ -787 +817 @@ void curses_write_file(struct dir_entry_t * dir_entry, bool highlight) {   break;   }   - if (dir_entry->exec) { + if (dir_entry->exec && dir_entry->file_type != FILE_LINK) {   cp = GREEN;   if (f_ident == NO_IDENT) f_ident = '*';   } else if (cp == -1) { @@ -937 +967 @@ void curses_write_file(struct dir_entry_t * dir_entry, bool highlight) {   attron(cp);   printw("%s", dir_entry->name);   attroff(cp); - printw("%c\n", f_ident); + printw("%c %s\n", f_ident, u_text);  }     diff --git a/src/main.c b/src/main.c index 158c332..04bac56 100644 --- a/src/main.c +++ b/src/main.c @@ -987 +989 @@ int main(int argc, char ** argv) {   case 'l':   case '\n':   if (!n_dir_entries) break; - if (dir_entries[cursor - 1]->file_type == FILE_DIR) { + // open directory or links that point to a directory + if (dir_entries[cursor - 1]->file_type == FILE_DIR || + dir_entries[cursor - 1]->under_link == FILE_DIR) {   enter_dir(dir_entries[cursor - 1]->name);   free_dir_entries();   list_dir(cwd);