/* -*- C -*- */

/* frag.c */

/*
 * Author: Nikita Danilov <NikitaDanilov@yahoo.COM>
 * Keywords: fragmentation, file, block number
 *
 * This file is part of frag.
 *
 * Frag 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, or (at your option)
 * any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.  If not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 */

#include <stdio.h>
#include <errno.h>
#include <string.h>

typedef enum { ok = 0, argc } ret_t;
int main( int argc , char **argv )
{
  ret_t result;

  if( argc == 1 )
	{
	  int blocks;
	  int gaps;
	  int last_block;
	  int block;

	  gaps = 0;
	  for( blocks = 0; scanf( "%i", &block ) == 1 ; ++blocks )
		{
		  if( ( blocks > 0 ) && 
			  ( block != last_block + 1 ) &&
			  ( ( block != 0 ) || ( last_block != 0 ) ) )
			{
			  ++gaps;
			}
		  last_block = block;
		}
	  if( blocks > 0 )
		{
		  printf( "%f %i of %i\n", 
				  ( ( double ) gaps ) / ( ( double ) blocks ), gaps, blocks );
		}
	  result = ok;
	}
  else
	{
	  fprintf( stderr, 
			   "usage: %s\n"
			   "\n\tCalculates fragmentation of the input stream of numbers"
			   "\n\tCompiled from " __FILE__ " at " __DATE__ "\n\n", argv[ 0 ] );
	  result = argc;
	}
  return result;
}

