2019-05-13 01:20:31 +10:00
|
|
|
#include <stdio.h>
|
2019-12-12 12:57:23 +11:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2019-05-13 01:20:31 +10:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <string.h>
|
2019-06-03 06:22:07 +10:00
|
|
|
#include <fnmatch.h>
|
2019-07-12 11:21:54 +10:00
|
|
|
#include <libgen.h>
|
2019-06-03 06:35:41 +10:00
|
|
|
#include <sys/stat.h>
|
2019-05-13 01:20:31 +10:00
|
|
|
|
2020-01-01 05:57:52 +11:00
|
|
|
#include "cfs.h"
|
2019-05-13 01:20:31 +10:00
|
|
|
|
2019-12-12 12:57:23 +11:00
|
|
|
void usage()
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: cfspack [-p pattern] [/path/to/dir...]\n");
|
|
|
|
}
|
|
|
|
|
2019-05-13 01:20:31 +10:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2019-12-12 12:57:23 +11:00
|
|
|
int patterncount = 0;
|
|
|
|
char **patterns = malloc(sizeof(char**));
|
|
|
|
patterns[0] = NULL;
|
|
|
|
while (1) {
|
|
|
|
int c = getopt(argc, argv, "p:");
|
|
|
|
if (c < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (c) {
|
|
|
|
case 'p':
|
|
|
|
patterns[patterncount] = optarg;
|
|
|
|
patterncount++;
|
|
|
|
patterns = realloc(patterns, sizeof(char**)*(patterncount+1));
|
|
|
|
patterns[patterncount] = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
return 1;
|
|
|
|
}
|
2019-05-13 01:20:31 +10:00
|
|
|
}
|
2019-12-12 12:57:23 +11:00
|
|
|
int res = 0;
|
|
|
|
for (int i=optind; i<argc; i++) {
|
|
|
|
if (is_regular_file(argv[i])) {
|
|
|
|
// special case: just one file
|
|
|
|
res = spitblock(argv[i], basename(argv[i]));
|
|
|
|
} else {
|
|
|
|
res = spitdir(argv[i], "", patterns);
|
|
|
|
}
|
2019-06-03 06:22:07 +10:00
|
|
|
}
|
2019-12-12 12:57:23 +11:00
|
|
|
if (res == 0) {
|
|
|
|
spitempty();
|
2019-06-03 06:35:41 +10:00
|
|
|
}
|
2019-12-12 12:57:23 +11:00
|
|
|
free(patterns);
|
|
|
|
return res;
|
2019-05-13 01:20:31 +10:00
|
|
|
}
|
|
|
|
|