summaryrefslogtreecommitdiff
path: root/src/search.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/search.c')
-rw-r--r--src/search.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/search.c b/src/search.c
index bb2cc0e..070801a 100644
--- a/src/search.c
+++ b/src/search.c
@@ -79,30 +79,36 @@ int main(void) {
79 //*/ 79 //*/
80 80
81 struct dirent **nodes = NULL; 81 struct dirent **nodes = NULL;
82 int n = 0;
83 82
84 struct nodelist *scanner = nodelist_init(NULL), *holder = nodelist_init(NULL), *hstart = holder; 83 struct nodelist *scanner = nodelist_init(NULL), *holder = NULL, *start = scanner;
85 if(scanner == NULL)
86 error(-1, errno, "shit brokey");
87 scanner->fullpath = realpath("./", NULL); 84 scanner->fullpath = realpath("./", NULL);
88 scanner->type = NODELIST_TYPE__FOLDER; 85 scanner->type = NODELIST_TYPE__FOLDER;
89 86
90 n = scandir(scanner->fullpath, &nodes, foldersort, alphasort); 87 for(; scanner != NULL; scanner = scanner->next) {
91 if(n > 0) { 88 if(chdir(scanner->fullpath) < 0) {
92 for(int i = 0; i < n; i++) { 89 error(0, errno, "Couldn't change to dir \"%s\". Skipping scan of that folder", scanner->fullpath);
93 holder->fullpath = realpath(nodes[i]->d_name, NULL); 90 continue;
94 holder->type = NODELIST_TYPE__FOLDER;
95 holder->next = nodelist_init(NULL);
96 holder = holder->next;
97 } 91 }
98 } else
99 error(-1, 0, "Couldn't open folder");
100 92
101 nodelist_append(scanner, hstart); 93 int n = scandir(scanner->fullpath, &nodes, foldersort, alphasort);
94 if(n >= 0) {
95 for(int i = 0; i < n; i++) {
96 holder = nodelist_init(NULL);
97 holder->fullpath = realpath(nodes[i]->d_name, NULL);
98 holder->type = NODELIST_TYPE__FOLDER;
99 nodelist_append(scanner, holder); // Yeah this is slow but idk rn
100 }
101 } else
102 error(-1, errno, "Couldn't open dir \"%s\"", scanner->fullpath);
103
104 }
105
106 for(struct nodelist *p = start; p != NULL; p = p->next) {
107 if(p->fullpath != NULL)
108 printf("%s\n", p->fullpath);
109 }
102 110
103 printf("Scanned paths:\n"); 111 nodelist_delete(start);
104 for(struct nodelist *p = scanner; p->next != NULL; p = p->next) // Because of how holder is populated, checking p->next for being null makes sure printf doesn't try to do anything dumb like printing a null string
105 printf("%s\n", p->fullpath);
106 112
107 return 0; 113 return 0;
108} 114}