Skip to content

Commit

Permalink
mailsplit: -d<prec>
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Oct 6, 2005
1 parent 655c747 commit e11fc02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion git-applymbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ case "$continue" in
'')
rm -rf .dotest
mkdir .dotest
git-mailsplit "$1" .dotest || exit 1
num_msgs=$(git-mailsplit "$1" .dotest) || exit 1
echo "$num_msgs patch(es) to process."
shift
esac

Expand Down
13 changes: 10 additions & 3 deletions mailsplit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -96,11 +96,17 @@ static int parse_email(const void *map, unsigned long size)

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);
Expand All @@ -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);
Expand All @@ -141,5 +147,6 @@ int main(int argc, char **argv)
map += len;
size -= len;
} while (size > 0);
printf("%d\n", nr);
return 0;
}

0 comments on commit e11fc02

Please sign in to comment.