/* tools.c 
	vi:ts=3 sw=3:
 */

/* standard routines for use in tracker. Used to be in main.c
 */

/* $Id: tools.c,v 4.14 1995/09/05 19:21:31 espie Exp espie $
 * $Log: tools.c,v $
 * Revision 4.14  1995/09/05 19:21:31  espie
 * *** empty log message ***
 *
 * Revision 4.13  1995/09/03 13:40:22  espie
 * Added time functions.
 *
 * Revision 4.12  1995/02/21 21:13:16  espie
 * Cleaned up source. Moved minor pieces of code around.
 *
 * Revision 4.11  1995/02/21  17:54:32  espie
 * Internal problem: buggy RCS. Fixed logs.
 *
 */
     

#include "defs.h"
#include "extern.h"
     
ID("$Id: tools.c,v 4.14 1995/09/05 19:21:31 espie Exp espie $")


/* v = read_env(name, default): read the scalar value v in the environment, 
 * supply default value.
 */
int read_env(name, def)
char *name;
int def;
   {
   char *var;
   int value;

   var = getenv(name);
   if (!var)
      return def;
   if (sscanf(var, "%d", &value) == 1)
      return value;
   else
      return def;
   }

/* TIME_SCALE is one microsecond. Hence an unsigned long is enough
 * for a little over one hour */
#define TIME_SCALE 1000000

char *time2string(buffer, t)
char *buffer;
unsigned long t;
   {
   int s;

	t +=  TIME_SCALE/2;
	t /= TIME_SCALE;
   s = t % 60;
   t /= 60;
   sprintf(buffer, "%3d:%02d", (int)t, s);
   return buffer;
   }

unsigned long ratio2time(n, p)
int n;
int p;
	{
	return (unsigned long)n * TIME_SCALE / (unsigned long)p;
	}
