/*
   * Copyright (C) 2001-2003, CompHEP Collaboration
   *-----------------------------------------------------
   * $Id: files.c,v 1.10 2003/06/19 07:06:38 kryukov Exp $
   *
   * $Log: files.c,v $
   * Revision 1.10  2003/06/19 07:06:38  kryukov
   * Move global variable 'version' from file.c to lbl.c
   *
 */
#include "chep_crt/include/chep_crt.h"

#include "os.h"
#include "syst2.h"
#include "files.h"

char *outputDir = "";
longstr pathtocomphep;
longstr pathtolhapdf;

void 
copyfile (char *namefrom, char *nameto)
{

  FILE *filefrom;
  FILE *fileto;
  const int _blocksize = 1024;
  char s[_blocksize];
  int size;
  filefrom = fopen (namefrom, "rb");
  fileto = fopen (nameto, "wb");
  if ((filefrom == NULL) || (fileto == NULL))
    return;

  do
    {
      size = fread (s, 1, _blocksize, filefrom);
      fwrite (s, 1, size, fileto);
    }
  while (size == _blocksize && size != 0);

  fclose (fileto);
  fclose (filefrom);
  return;
}

void 
nextFileName (char *f_name, char *firstname, char *ext)
{
  int tabnum = 0;
  midstr lname;
  FILE *f;

  for (;;)
    {
      tabnum++;
      sprintf (f_name, "%s%s%d", outputDir, firstname, tabnum);
      sprintf (lname, "%s%s", f_name, ext);
      f = fopen (lname, "r");
      if (f)
	fclose (f);
      else
	return;
    }
}
