refactoring via defines.h

This commit is contained in:
nova
2025-03-01 13:13:16 +01:00
parent 26d3dc9bc8
commit 1c69f60037
3 changed files with 23 additions and 27 deletions

View File

@ -3,9 +3,9 @@
#include <dirent.h>
#include <stdlib.h>
#include <unistd.h>
#include "defines.h"
extern unsigned int settings;
extern unsigned long longest_name;
extern char **content_l;
extern char **content_m;
extern char **content_r;
@ -13,24 +13,19 @@ extern char *path;
void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name){
DIR *dir = opendir(path);
*longest_name = 256; //magic number originates out of readdir(), unless i implement my own name size function, thisll do
unsigned long index = 1; //always makes the array at least 1 big, used for metadata like the amount of files
if (dir) {
unsigned long index = 1; //always makes the array at least 1 big, used for metadata like the amount of files
struct dirent *entry;
while ( entry=readdir(dir) ) {
if (entry->d_name[0] != '.' && !(settings & 1)) { //bit 0 = show_hidden_files
while ( (entry=readdir(dir)) ) {
if (entry->d_name[0] != '.' && !(settings & SETTINGS_HIDDEN_FILES)) {
index++;
if ((unsigned long)sizeof(entry->d_name) > *longest_name) {
*longest_name = sizeof(entry->d_name);
}
} else if (settings & 1){ //bit 0 = show_hidden_files
} else if (settings & SETTINGS_HIDDEN_FILES){
index++;
if ((unsigned long*)sizeof(entry->d_name) > (unsigned long*)longest_name) {
longest_name = (unsigned long*)sizeof(entry->d_name);
}
}
}
*file_count = index;
}
*file_count = index;
closedir(dir);
}
@ -41,11 +36,11 @@ void get_dir_content(char *path, unsigned long file_count, unsigned long longest
if (dir) {
int index = 1; //skip index 0 as it is used for metadata like file count
struct dirent *entry;
while ( entry=readdir(dir) ) {
if (entry->d_name[0] != '.' && !(settings & 1)) { //bit 0 = show_hidden_files
while ( (entry=readdir(dir)) ) {
if (entry->d_name[0] != '.' && !(settings & SETTINGS_HIDDEN_FILES)) {
strcpy(dir_content[index], entry->d_name);
index++;
} else if (settings & 1){ //bit 0 = show_hidden_files
} else if (settings & SETTINGS_HIDDEN_FILES) {
strcpy(dir_content[index], entry->d_name);
index++;
}