/***************************************************************************
                          file_parts.c  -  description
                             -------------------
    begin                : lun ago 26 2002
    copyright            : (C) 2002 by deabru
    email                : deabru@nubbis.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

 int sizetopart(double total_size, double partial_size)
 {
	 /* return number of parts */
	 int result;
	 
	 result = floor(total_size / partial_size);
	 if (((total_size / partial_size) - floor(total_size / partial_size)) > 0) result++;

	 return result;
 }


 double parttosize(double total, int parts)
 {
	 /* retun size of splited files */
	 double partial, last, result;
/*	 int control;*/

	 if(parts >1)
	 {
		 partial = floor( total / parts  );
		 last = total - partial*parts;
	 	 result = (partial + ceil(last/(parts - 1)));
	 }
	 else
	 {
		 result = total;
	 }
	 return result;
 }


 void rmextension(char file_with_extension[], char file_without_extension[])
 {
	 /* remove extension of name */
	 int i;

	 strcpy(file_without_extension,file_with_extension);
	 
	 i = strlen(file_with_extension) - 1;
	 while ( file_with_extension[i] != '.' && i >= 0) i--;

	 if (i >= 1 ) file_without_extension[i] = '\0';

	 return;
 }