#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char **argv)
{
    FILE *fd, *fo = NULL;
    char *ptr;
    char buf[512];

    if (!argv[1]) exit(-1);
    fd = fopen(argv[1], "r");

    while (ptr=fgets(buf, 510, fd)) {
       if (strstr(ptr, "************")==ptr) {
	  ptr = fgets(buf, 510, fd);
          ptr = buf+strlen(buf)-1;
          while (ptr>=buf && isspace(*ptr)) { *ptr = '\0'; --ptr; }
	  if (fo) fclose(fo);
	  fo = fopen(buf, "w");
	  ptr=fgets(buf, 510, fd);
	  ptr=fgets(buf, 510, fd);
	  ptr=fgets(buf, 510, fd);
       }
       if (fo) fprintf(fo, buf);
    }
    if (fo) fclose(fo);
}
