Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 line
1.2KB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <dirent.h>
  5. #include <string.h>
  6. #include <fnmatch.h>
  7. #include <libgen.h>
  8. #include <sys/stat.h>
  9. #include "cfs.h"
  10. void usage()
  11. {
  12. fprintf(stderr, "Usage: cfspack [-p pattern] [/path/to/dir...]\n");
  13. }
  14. int main(int argc, char *argv[])
  15. {
  16. int patterncount = 0;
  17. char **patterns = malloc(sizeof(char**));
  18. patterns[0] = NULL;
  19. while (1) {
  20. int c = getopt(argc, argv, "p:");
  21. if (c < 0) {
  22. break;
  23. }
  24. switch (c) {
  25. case 'p':
  26. patterns[patterncount] = optarg;
  27. patterncount++;
  28. patterns = realloc(patterns, sizeof(char**)*(patterncount+1));
  29. patterns[patterncount] = NULL;
  30. break;
  31. default:
  32. usage();
  33. return 1;
  34. }
  35. }
  36. int res = 0;
  37. for (int i=optind; i<argc; i++) {
  38. if (is_regular_file(argv[i])) {
  39. // special case: just one file
  40. res = spitblock(argv[i], basename(argv[i]));
  41. } else {
  42. res = spitdir(argv[i], "", patterns);
  43. }
  44. }
  45. if (res == 0) {
  46. spitempty();
  47. }
  48. free(patterns);
  49. return res;
  50. }