gen.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 ENTRY_P "int main"
  8. #define FS_NONE 0
  9. #define FS_RECURSIVE (1 << 0)
  10. #define FS_DEFAULT FS_RECURSIVE
  11. #define FS_FOLLOWLINK (1 << 1)
  12. #define FS_DOTFILES (1 << 2)
  13. #define FS_MATCHDIRS (1 << 3)
  14. #define DOC_START "---\n"
  15. #define DOC_END "...\n"
  16. #define BASEDIR getcwd(cwd, MAXPATHLEN)
  17. #define REL_BASEDIR strrchr(BASEDIR, '/') + 1
  18. #include <regex.h>
  19. #include <unistd.h>
  20. #include <sys/param.h>
  21. #include <fstream>
  22. #include <string>
  23. #include <vector>
  24. class Generate
  25. {
  26. private:
  27. enum { FS_OK = 0,
  28. FS_BADPattern,
  29. FS_NAMETOOLONG,
  30. FS_BADIO,
  31. };
  32. char cwd[MAXPATHLEN];
  33. char temp[512];
  34. char *current_dir;
  35. const char *default_makefile;
  36. std::string file_name;
  37. std::string rm_base;
  38. int file_count;
  39. int bin_num;
  40. FILE *makefile;
  41. FILE *new_config;
  42. FILE *src_file;
  43. public:
  44. Generate();
  45. ~Generate();
  46. std::vector<std::string> FileList;
  47. std::string RelPathName(std::string &to_rel);
  48. std::string GetRelBase();
  49. std::string ParseLang(std::string ext);
  50. char *GetCurrentDir();
  51. char *RemoveBase(char *to_rm);
  52. void Walk();
  53. void CheckFiles();
  54. void PrintFileList();
  55. int SearchForMain(const std::vector<std::string> &vect);
  56. int GenConfig(int force_opt);
  57. int CheckConfigExists();
  58. int CheckMake();
  59. int GenMakeFromTemplate();
  60. int WalkDir(std::string dir_name, const std::string pattern, int spec);
  61. int WalkRecur(std::string dir_name, regex_t *expr, int spec);
  62. };
  63. #endif