archive.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef ARCHIVE_H
  2. #define ARCHIVE_H
  3. #include <fcntl.h>
  4. #include <stdint.h>
  5. #include <interface99.h>
  6. #include "util.h"
  7. #define EXT(EXT) "." #EXT
  8. #define CREATE_RW (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
  9. struct Config {
  10. uint8_t verbose;
  11. uint8_t dry_run;
  12. char *out_dir;
  13. char *out_file;
  14. char *custom_ext;
  15. char *threads;
  16. char *memory_limit;
  17. char **files;
  18. int files_count;
  19. };
  20. #define SELF_CFG(S, C) \
  21. struct Config *C; \
  22. SAFE_ASSIGN(C, S)
  23. #define FUNC_ARGS void *self, char *const file //, const struct Config *cfg
  24. #define Match_IFACE vfunc(uint8_t, match, void *self, char *const file)
  25. interface(Match);
  26. #define List_IFACE vfunc(int, list, FUNC_ARGS)
  27. interface(List);
  28. #define Extract_IFACE vfunc(int, extract, FUNC_ARGS)
  29. interface(Extract);
  30. #define Create_IFACE vfunc(int, create, FUNC_ARGS)
  31. interface(Create);
  32. #define Archive_IFACE
  33. #define Archive_EXTENDS (Match, List, Extract, Create)
  34. interface(Archive);
  35. #define DEF_EXTRACTOR(NAME) \
  36. typedef struct { \
  37. char /* unused */ _; \
  38. } NAME; \
  39. declImplExtern(Archive, NAME)
  40. #define DEF_TAR_COMPRESSOR(NAME, PROG) \
  41. static int NAME##_list(void *self, char *const file) \
  42. { \
  43. return tar_compressor_list(#PROG, file, self, &NAME##_ctx); \
  44. } \
  45. impl(List, NAME); \
  46. static int NAME##_extract(void *self, char *const file) \
  47. { \
  48. return tar_compressor_extract(#PROG, \
  49. file, \
  50. self, \
  51. &NAME##_ctx); \
  52. } \
  53. impl(Extract, NAME); \
  54. static int NAME##_create(void *self, char *const file) \
  55. { \
  56. return tar_compressor_create(#PROG, file, self, &NAME##_ctx); \
  57. } \
  58. impl(Create, NAME)
  59. #endif /* ARCHIVE_H */