sources.c 696 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #define _XOPEN_SOURCE 700
  2. #include <ftw.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include "maje.h"
  6. static struct majefile *filelist = NULL;
  7. static int add_source(const char *path, const struct stat *st, int flags, struct FTW *ft)
  8. {
  9. (void)flags; (void)ft;
  10. if (path[0] == '.' && path[1] == '/') {
  11. path += 2;
  12. }
  13. if (strcmp(path + strlen(path) - 2, ".c") == 0) {
  14. filelist = insert_file(filelist, path, st);
  15. if (filelist == NULL) {
  16. return 1;
  17. }
  18. }
  19. return 0;
  20. }
  21. struct majefile * find_source_files(const char *dir)
  22. {
  23. nftw(dir, add_source, -1, 0);
  24. if (filelist == NULL) {
  25. return NULL;
  26. }
  27. while (filelist->prev != NULL) {
  28. filelist = filelist->prev;
  29. }
  30. return filelist;
  31. }