From f2454ebf3d01d5f279e037c2b4e354d2ee6a12ea Mon Sep 17 00:00:00 2001 From: garhve Date: Thu, 15 Dec 2022 09:40:15 +0800 Subject: basically working --- c/tree/main.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) (limited to 'c/tree/main.c') diff --git a/c/tree/main.c b/c/tree/main.c index 86d2c30..b4b3374 100644 --- a/c/tree/main.c +++ b/c/tree/main.c @@ -6,32 +6,18 @@ #include "tree.h" -bool checkdir(const char * dir) +void printChild(const regfile * head) { - struct stat st; - stat(dir,&st); - - return S_ISDIR(st.st_mode); -} - -void printChild(const char * cur) -{ - DIR * d = opendir(cur); - - struct dirent * dir; - - if (!d) - error("Failed to open directory"); - - while ((dir = readdir(d))) { - //if (dir->d_name[1] == '.' || strcmp(".",dir->d_name) == 0) - if (dir->d_name[1] == '.' || dir->d_name[0] == '.' && dir->d_name[1] == '\0') - continue; - printf("%s\n", dir->d_name); - - if (checkdir(dir->d_name) == true) { - printChild(dir->d_name); - } + regfile * scan = head->next; + + while (scan != NULL) { + printf("%s\tlevel: %d\tname length: %u\tfile or dir: ",scan->node->text, + scan->node->level, scan->node->len); + if (scan->node->fod) + printf("dir\n"); + else + printf("file\n"); + scan = scan->next; } } @@ -41,6 +27,8 @@ int main() getfile(&head,"."); + printChild(&head); + empty(&head); return 0; -- cgit v1.2.3-70-g09d2