/* split-mail.c -- split a MBOX file into several files: one per message */ /* Carlos Duarte , 991123 */ #include #include #include #define DEFAULT_PREFIX "xx" static int do_args(int first, int ac, char *av[]); #define ARG() \ s[1] ? (t=s+1, s+=strlen(s)-1, t) : ++i sizeof(name_pool)) { name = malloc(sz); if (!name) { fprintf(stderr, "unable to malloc space"); goto err; } } else name = name_pool; sprintf(name, "%s.%d", opts.prefix, opts.count); if (wf) { fclose(wf); wf=0; } } if (!name) continue; if (!wf) { wf = fopen(name, "w"); if (!wf) { fprintf(stderr, "unable to open %s for writing", name); goto err; } if (name != name_pool) free(name); } fputs(buf, wf); if (strchr(buf, '\n') == 0) { /* line bigger than sizeof buf, print remaining */ int c; while ((c = getc(rf)) != EOF) { putc(c, wf); if (c == '\n') break; } } } err: if (name && name != name_pool) free(name); if (wf) fclose(wf); if (rf != stdin) fclose(rf); } static int do_args(int ix, int argc, char *argv[]) { if (opts.prefix[0] == '\0') USAGE(); if (ix == argc) { do_split(0); } else { for (; ix