diff options
author | Ian C <ianc@noddybox.co.uk> | 2007-03-04 18:35:36 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2007-03-04 18:35:36 +0000 |
commit | 954af9179665457b40453a0417ddf5b3949a0449 (patch) | |
tree | e3772817de5c79e29b602ebe47fe0129793f1470 /mb.c | |
parent | 892e6e107dbf2386831bd00e7f1c2a0bbe8b2cbb (diff) |
This commit was generated by cvs2svn to compensate for changes in r2,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'mb.c')
-rw-r--r-- | mb.c | 66 |
1 files changed, 66 insertions, 0 deletions
@@ -0,0 +1,66 @@ +/* Mangle a berkley mbox +*/ +#include <stdlib.h> +#include <stdio.h> + +void Process(FILE *fp, const char *p); + +int main(int argc, char *argv[]) +{ + int f; + + if (argc==1) + Process(stdin,"stdin"); + else + for(f=1;f<argc;f++) + Process(fopen(argv[f],"r"),argv[f]); + + return EXIT_SUCCESS; +} + + +void Quit(const char *p) +{ + perror(p); + exit(EXIT_FAILURE); +} + + +void Process(FILE *fp, const char *p) +{ + FILE *out=NULL; + char buff[1024]; + char fn[80]; + int n=1; + + printf("Processing : %s\n",p); + + if (!fp) + Quit("fopen"); + + sprintf(fn,"%s.dir",p); + + if (mkdir(fn,0777)==-1) + Quit("mkdir"); + + while(fgets(buff,sizeof buff,fp)) + { + if (strncmp(buff,"From ",5)==0) + { + if (out) + fclose(out); + + sprintf(fn,"%s.dir/%d.txt",p,n++); + + printf("Creating : %s\n",fn); + + if (!(out=fopen(fn,"w"))) + Quit("fopen"); + } + + fprintf(out,"%s",buff); + } + + fclose(out); + fclose(fp); +} |