gen.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (c) 2013-2014, Alberto Corona <alberto@0x1a.us>
  2. // All rights reserved. This file is part of yabs, distributed under the BSD
  3. // 3-Clause license. For full terms please see the LICENSE file.
  4. #ifndef _GEN_H
  5. #define _GEN_H
  6. #define MAKEFILE "Makefile"
  7. #define FS_NONE 0
  8. #define FS_RECURSIVE (1 << 0)
  9. #define FS_DEFAULT FS_RECURSIVE
  10. #define FS_FOLLOWLINK (1 << 1)
  11. #define FS_DOTFILES (1 << 2)
  12. #define FS_MATCHDIRS (1 << 3)
  13. #include <regex.h>
  14. #include <unistd.h>
  15. #include <sys/param.h>
  16. #include <fstream>
  17. #include <string>
  18. #include <vector>
  19. enum { FS_OK = 0,
  20. FS_BADPattern,
  21. FS_NAMETOOLONG,
  22. FS_BADIO,
  23. };
  24. class Generate
  25. {
  26. private:
  27. char cwd[MAXPATHLEN];
  28. char *current_dir = getcwd(cwd, MAXPATHLEN);
  29. std::vector<std::string> FileList;
  30. char *file_name;
  31. const char *default_makefile;
  32. int file_count = 0;
  33. FILE *makefile;
  34. FILE *new_config;
  35. public:
  36. Generate();
  37. ~Generate();
  38. char *GetCurrentDir();
  39. char *RelPathName(char *to_rel);
  40. int WriteMake();
  41. void Walk();
  42. void GenFileList(char *file_list);
  43. int GenBlankConfig(int force_opt);
  44. void CheckFiles();
  45. void PrintFileList();
  46. int CheckConfigExists();
  47. int CheckMake();
  48. int GenMakeFromTemplate();
  49. int WalkDir(const char *dir_name, const char *pattern, int spec);
  50. int WalkRecur(const char *dir_name, regex_t *expr, int spec);
  51. };
  52. #endif