fi ls spacing

This commit is contained in:
Murphy 2023-04-28 13:11:56 -04:00
parent 3b53b4c96d
commit 5b710c02b4

View file

@ -52,7 +52,11 @@ struct FileListInfo {
static DIR* get_directory(char* path) {
DIR* d = opendir(path);
if (d == NULL) {
printf("\x1b[0merror: failed to open directory '%s': %s\n", path, strerror(errno));
if (errno == ENOTDIR) {
printf("\x1b[0m%s is a a file\n", path);
} else {
printf("\x1b[0merror: failed to open directory '%s': %s\n", path, strerror(errno));
}
}
return d;
}
@ -267,13 +271,14 @@ static void push_file(
(*size)++;
}
static void recurse_directory(char* path, struct Flags* flags) {
static bool recurse_directory(char* path, struct Flags* flags) {
DIR* d;
struct dirent* file;
bool first = true;
d = get_directory(path);
if (d == NULL) return;
if (d == NULL) return false;
int capacity = 8;
int size = 0;
@ -300,7 +305,7 @@ static void recurse_directory(char* path, struct Flags* flags) {
closedir(d);
d = get_directory(path);
if (d == NULL) return;
if (d == NULL) return false;
while((file = readdir(d)) != NULL) {
if (file->d_type != DT_DIR) continue;
@ -312,16 +317,17 @@ static void recurse_directory(char* path, struct Flags* flags) {
}
closedir(d);
return true;
}
static void list_directory(char* path, struct Flags* flags) {
static bool list_directory(char* path, struct Flags* flags) {
if (flags->recurse) {
recurse_directory(path, flags);
return;
return recurse_directory(path, flags);
}
DIR* d = get_directory(path);
if (d == NULL) return;
if (d == NULL) return false;
int capacity = 8;
int size = 0;
@ -340,6 +346,7 @@ static void list_directory(char* path, struct Flags* flags) {
free(files);
closedir(d);
return true;
}
static void help() {
@ -403,10 +410,9 @@ COMMAND(ls) {
if (titled && !flags.recurse) {
printf("\n%s%s:%s\n", DIR_COLOR, argv[i], FILE_COLOR);
}
list_directory(argv[i], &flags);
if (titled && !flags.recurse) printf("\n");
if (list_directory(argv[i], &flags) && i + 1 != argc)
if (titled && !flags.recurse) printf("\n");
}
if (!flags.more_info) printf("\n");
return EXIT_SUCCESS;
}