aboutsummaryrefslogtreecommitdiff
path: root/mailsplit.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-10-06 14:25:52 -0700
committerJunio C Hamano <junkio@cox.net>2005-10-06 14:25:52 -0700
commite11fc02066435b0f370d639e665ec70680e876a6 (patch)
tree891524ecdc9ceabc3b70d3544674a95aaf860cb8 /mailsplit.c
parent655c7470e2ea7f25f22703b6654d7570e1567a39 (diff)
downloadgit-e11fc02066435b0f370d639e665ec70680e876a6.tar.gz
git-e11fc02066435b0f370d639e665ec70680e876a6.tar.xz
mailsplit: -d<prec>
Instead of the default 4 digits with leading zeros, different precision can be specified for the generated filenames. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'mailsplit.c')
-rw-r--r--mailsplit.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/mailsplit.c b/mailsplit.c
index 7afea1aac..bd7c611bb 100644
--- a/mailsplit.c
+++ b/mailsplit.c
@@ -17,7 +17,7 @@
static int usage(void)
{
- fprintf(stderr, "mailsplit <mbox> <directory>\n");
+ fprintf(stderr, "git-mailsplit [-d<prec>] <mbox> <directory>\n");
exit(1);
}
@@ -96,11 +96,17 @@ corrupt:
int main(int argc, char **argv)
{
- int fd, nr;
+ int fd, nr, nr_prec = 4;
struct stat st;
unsigned long size;
void *map;
+ if (argc == 4 && !strncmp(argv[1], "-d", 2)) {
+ nr_prec = strtol(argv[1] + 2, NULL, 10);
+ if (nr_prec < 3 || 10 <= nr_prec)
+ usage();
+ argc--; argv++;
+ }
if (argc != 3)
usage();
fd = open(argv[1], O_RDONLY);
@@ -127,7 +133,7 @@ int main(int argc, char **argv)
char name[10];
unsigned long len = parse_email(map, size);
assert(len <= size);
- sprintf(name, "%04d", ++nr);
+ sprintf(name, "%0*d", nr_prec, ++nr);
fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666);
if (fd < 0) {
perror(name);
@@ -141,5 +147,6 @@ int main(int argc, char **argv)
map += len;
size -= len;
} while (size > 0);
+ printf("%d\n", nr);
return 0;
}