A static site generator, written in C
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include "cms_util.h"
  4. #include "cms_err.h"
  5. #include "cms_files.h"
  6. int main(int argc, char** argv)
  7. {
  8. if (argc < 2)
  9. {
  10. fprintf(stderr, "Usage: %s <init|deinit|build>\n", argv[0]);
  11. return 1;
  12. }
  13. //Initiate
  14. if (strcmp(argv[1], "init") == 0)
  15. {
  16. if (argc != 3)
  17. {
  18. fprintf(stderr, "Usage: %s init <directory>\n", argv[0]);
  19. return 1;
  20. }
  21. char* dirname = argv[2];
  22. //Get the path of .cmsinited, which tells us
  23. //whether or not the directory is already inited
  24. char* initedPath = cms_util_path_join(dirname, CMS_FILE_INITED);
  25. //Panic if the directory is already initiated
  26. if (cms_util_file_exists(initedPath))
  27. cms_err_panic(CMS_ERR_INITED, NULL);
  28. //Copy files from resources
  29. cms_err err;
  30. err = cms_util_dir_copy_recursive(CMS_FILE_RESOURCES, dirname);
  31. if (err)
  32. cms_err_panic(err, dirname);
  33. //Create .cmsinited file
  34. err = cms_util_file_create(initedPath);
  35. if (err)
  36. cms_err_panic(err, initedPath);
  37. }
  38. //Build
  39. else if (strcmp(argv[1], "build") == 0)
  40. {
  41. if (argc != 3)
  42. {
  43. fprintf(stderr, "Usage: %s build <directory>\n", argv[0]);
  44. return 1;
  45. }
  46. char* dirname = argv[2];
  47. //Get the path of .cmsinited, which tells us
  48. //whether or not the directory is already inited
  49. char* initedPath = cms_util_path_join(dirname, CMS_FILE_INITED);
  50. //Panic if the directory isn't initiated
  51. if (!cms_util_file_exists(initedPath))
  52. cms_err_panic(CMS_ERR_NOTINITED, NULL);
  53. }
  54. }