#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#include "extern.h"

filcont(mail)
   int mail;
   { char fno[5],fjunle[9],fdate[9],ftime[6],fhiscall[9];
     char fday[14],rday[14],fwd_flg[2],jyo_flg[2];
     int  tflg = 0;
     int  numb,i;
          
     strcpy(rday,lastdate); strcat(rday,lasttime);
     if ( mail ) fp2 = fopen(MAIL_HDR,"r");
          else   fp2 = fopen(HDR_FIL,"r");
     while(1)
       { if ( fgets(fbuff,255,fp2) == NULL ) break;

         if ( ! isdigit(*(fbuff)) ) continue;
         substr(fbuff,0,4,fno);
         substr(fbuff,4,1,jyo_flg);
         substr(fbuff,5,8,fjunle);
         substr(fbuff,55,8,fdate);
         substr(fbuff,63,5,ftime);
         substr(fbuff,75,1,fwd_flg);
         substr(fbuff,89,8,fhiscall);
         strcpy(fday,fdate);strcat(fday,ftime);
         if ( strcmp(fday,rday) < 0 ) continue;
         if ( ! strcmp(fhiscall,hiscall) ) continue;

         for ( i = 0 ; i <= JUNLE_MAX ; i++ )
             { if ( jtbl[i][0] == NULL )        continue;
               if ( strcmp(fjunle,jtbl[i]) == NULL )
				  { if ( jflg[i] == '0' )
								{ i = 999; }
					break;	
				  }
             }
		 if ( i == 999 ) continue;
		 if ( strcmp(fjunle,"CUG     ") == NULL ) continue;
         if ( mail && strcmp(jyo_flg," ") )   continue;
         if ( mail && strcmp(fwd_flg,"F") )   continue;
                                             
         tflg = 1; sndcnt++;
         fp1 = fopen(forward_fil,"a");
         fputs(fbuff,fp1);
         numb = atoi(fno);
		 makfname("MSG",numb,fname);
         filmak(fdate,ftime);
         if ( strncmp(fjunle,"PDS",3) == NULL )
            { fputs(pdsstr,fp1);
			  makfname("PDS",numb,fname);
              filmak(fdate,ftime); }
         if ( strncmp(fjunle,"DAT",3) == NULL )
            { fputs(pdsstr,fp1);
			  makfname("DAT",numb,fname);
              filmak(fdate,ftime); }
         if ( mail ) fputs(mlstr,fp1);
              else   fputs(filstr,fp1);
         fclose(fp1);
        }
      fclose(fp2);
      return(tflg);
      }
