commit 8d3f2f65ad58cff3e75f653293a137c886c37d16
Author: Raniconduh <clagv.randomgames@gmail.com>
Date: Mon Oct 04 21:51:01 2021 +0000
diff --git a/include/dir.h b/include/dir.h
index 088c307..68ba5a1 100644
--- a/include/dir.h
+++ b/include/dir.h
@@ -26 +28 @@
#define DIR_H
#endif
+#include <stdbool.h>
+
int list_dir(char *);
void free_dir_entries(void);
void cd_back(void);
@@ -314 +334 @@ extern struct dir_entry_t ** dir_entries;
// current working directory
extern char * cwd;
-
+extern bool show_dot_files;
diff --git a/src/dir.c b/src/dir.c
index bcd2c27..ea4c4d0 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -36 +37 @@
#include <string.h>
#include <sys/stat.h>
#include <stdio.h>
+#include <stdbool.h>
#include "dir.h"
@@ -116 +128 @@ char * cwd = NULL;
size_t n_dir_entries = 0;
struct dir_entry_t ** dir_entries = NULL;
+bool show_dot_files = false;
+
int list_dir(char * dir_path) {
struct dirent * d_entry;
DIR * dir = opendir(dir_path);
@@ -267 +2914 @@ int list_dir(char * dir_path) {
char * d_name = d_entry->d_name;
size_t d_name_len = strlen(d_name);
- if (!strcmp(d_name, ".") || !strcmp(d_name, "..")) continue;
+ if (!strcmp(d_name, ".") || !strcmp(d_name, "..")) {
+ free(dir_entry);
+ continue;
+ }
+ else if (!show_dot_files && d_name[0] == '.') {
+ free(dir_entry);
+ continue;
+ }
struct stat * buf = malloc(sizeof(struct stat));
char * tmp_path = malloc(d_name_len + strlen(dir_path) + 2);
diff --git a/src/main.c b/src/main.c
index 358a1f2..c5c05df 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1026 +10214 @@ int main(int argc, char ** argv) {
last_f = n_dir_entries - 1;
first_f = n_dir_entries > (unsigned)LINES - 6? n_dir_entries - LINES + 5 : -1;
break;
+ case '.':
+ show_dot_files = !show_dot_files;
+ free_dir_entries();
+ list_dir(cwd);
+ cursor = 1;
+ first_f = 0;
+ last_f = n_dir_entries > ((unsigned)LINES - 6) ? LINES - 6 : n_dir_entries;
+ break;
case 'q':
goto done;
default: