/*************FILE NAME CREATION**********************************/
#include "descript.h"
#include "flag.h"

void filename(char name1[], char name2[], char cln1[], char path [], int route, char ini_file[])
// name1, name2, cln1 - output parameters
{
 char fno[80], temp[80], route_path[90], name_route[4];
 char command[180]; /*DOS command*/
 FILE *ffiot;

 name_route[0]=ini_file[5];
 name_route[1]=ini_file[6]; 
 name_route[2]=ini_file[7]; 
 name_route[3]='\0'; 
 
 strcpy(temp,path);
 strcat(temp,"tmp.dat");

 ffiot=fopen(temp, "w+");
 fprintf(ffiot,"%03i_",route);
 fseek(ffiot,0,0);
 fgets(fno,10,ffiot);
 fclose(ffiot);
 remove(temp);

 strncat(strcpy(route_path,path),fno,3);
 if (LINUX_flag==1) strcat(route_path,"/tmp.dat");
 if (LINUX_flag!=1) strcat(route_path,"\\tmp.dat");
 
 if ((ffiot=fopen(route_path,"w+"))==0)
/*************Create directory mmm*************************/
 {
  if (LINUX_flag==1) strncat(strcat(strcat(strcat(strcpy(command,"mkdir "),path),name_route),"_"),fno,3);
  if (LINUX_flag!=1) strncat(strcat(strcpy(command,"md "),path),fno,3);
  system(command);
/**********************************************************/

/*************Create directory Cln1************************/
  if (LINUX_flag==1) strcat(command,"/Cln1");
  if (LINUX_flag!=1) strcat(command,"\\Cln1");
  system(command);
/**********************************************************/
 }
 if (LINUX_flag==1) strcat(strncat(strcat(strcat(strcpy(name1,path),name_route),"_"),fno,3),"/Cln1/");
 if (LINUX_flag!=1) strcat(strncat(strcpy(name1,path),fno,3),"\\Cln1\\");
 strcat(strncat(strcat(strcat(strcat(name1,name_route),"_"),fno),ini_file,5),"_cln1Er.log");

 if (LINUX_flag==1) strcat(strncat(strcat(strcat(strcpy(name2,path),name_route),"_"),fno,3),"/Cln1/");
 if (LINUX_flag!=1) strcat(strncat(strcpy(name2,path),fno,3),"\\Cln1\\");
 strcat(strncat(strcat(strcat(strcat(name2,name_route),"_"),fno),ini_file,5),"_mis_cln1.dat");

 if (LINUX_flag==1) strcat(strncat(strcat(strcat(strcpy(cln1,path),name_route),"_"),fno,3),"/Cln1/");
 if (LINUX_flag!=1) strcat(strncat(strcpy(cln1,path),fno,3),"\\Cln1\\");
 strcat(strncat(strcat(strcat(strcat(cln1,name_route),"_"),fno),ini_file,5),"_cln1.pam");
 if (ffiot!=0) {fclose(ffiot); remove(route_path);}
}