/* Copyright (C) 1996,1997,1998,1999 by Salvador E. Tropea (SET),
   see copyrigh file for details */
#include <tv.h> // Boolean typedef
#include <edmsg.h>
#include <stdio.h>
#include <unistd.h>

int DumpFileToMessage(char *file,char *from,
                       char *(*ParseFun)(char *buf,FileInfo &fI,char *&fileName),
                       int kill)
{
 FILE *f;
 char buf[1024];
 int l;
 FileInfo fInfo;
 char *fileName;
 int count=0;

 f=fopen(file,"rt");
 if (f)
   {
    fgets(buf,1000,f);
    if (!feof(f))
      {
       EdShowMessage(from);
       do
         {
          l=strlen(buf);
          if (buf[l-1]=='\n')
             buf[l-1]=0;
          if (ParseFun)
            {
             char *s=ParseFun(buf,fInfo,fileName);
             if (s)
               {
                EdShowMessage(s,fInfo,fileName);
                delete s;
                delete fileName;
                count++;
               }
            }
          else
             EdShowMessage(buf);
         }
       while (fgets(buf,1000,f));
      }
    fclose(f);
    if (kill)
       unlink(file);
   }
 return count;
}
