#include <stdio.h>
#include <dos.h>
#include <aes.h>
#include <string.h>

void walk_dir(char *path,char *temp_name,int (*func)(char *,char *))
{
  static char inname[FMSIZE];
  char *p;
  int e;
  struct FILEINFO fileinfo;

  e = dfind(&fileinfo,path,0);
  while(e==0)
  {
      strcpy(inname,path);
      p=strrchr(inname,'\\');
      strcpy(p+1,fileinfo.name);
      if(func(inname,temp_name)!=0)
         break;
      e = dnext(&fileinfo);
  }
}

int fixeps(char *infile,char *outfile)
{
   static char buf[BUFSIZ];
#define CREATOR "%%Creator: "
#define ADOBE "Adobe Illustrator\n"
   FILE *fin,*fout;
   if((fin=fopen(infile,"r"))==NULL)
      return 0;
   if((fout=fopen(outfile,"w"))==NULL)
   {
      fclose(fin);
      return 0;
   }
   while(fgets(buf,BUFSIZ,fin))
   {
     if(strncmp(buf,CREATOR,strlen(CREATOR))==0)
     {
       fputs(CREATOR,fout);
       fputs(ADOBE,fout);
     }
     else
         fputs(buf,fout);
   }
   fclose(fin);
   fclose(fout);
   unlink(infile);
   rename(outfile,infile);
   return 0;
}

char *get_path(void)
{
     static char path[FMSIZE],name[FNSIZE];
     short button;
	 *name='\0';
     getcwd(path,FMSIZE);
     strcat(path,"\\*.EPS");
     fsel_input(path,name,&button);
     return button==1?path:NULL;
}

void main(void)
{
    static char temp_name[FNSIZE],temp_full[FMSIZE];
    char *p,*path;

    appl_init();
    tmpnam(temp_name);
	if(path = get_path())
	{
	    p =strrchr(strcpy(temp_full,path),'\\');
    	strcpy(p+1,temp_name);
    	walk_dir(path,temp_full,fixeps);
	}
    appl_exit();
}
