///////////////////////////////////////////////////////////////////////////
//
// File: common.h
//
// Purpose:
//
// Authors:
//   txe  Travis Emmitt
//
// Modifications:
//   14-APR-1998  txe  Initial Version
//   15-APR-1998  txe  Added DEBUG()
//   17-APR-1998  txe  Added ERR and WARN macros
//   18-APR-1998  txe  Added LINE_LEN and SKIP_COMMENTS()
//   19-APR-1998  txe  Added PAUSE, added flush to ASSERT
//   20-APR-1998  txe  Ported to UNIX, moved DEBUG() macros to debug.h
//   21-APR-1998  txe  Added DELETE_ARRAY, BLANKS()
//   22-APR-1998  txe  Made random more robust, moved ASSERT() to debug.h
//
///////////////////////////////////////////////////////////////////////////

#ifndef COMMON_H
#define COMMON_H

#include <assert.h>	  	// for ASSERT() macro
#include <string.h>		// for WHITESPACE() macro
#include "debug.h"

#define MAX_LEN			50
#define LINE_LEN	     	200

#define MAX(a,b)      	  ((a) > (b) ? (a) : (b))
#define MIN(a,b)      	  ((a) < (b) ? (a) : (b))

#define ITERATE(type,a,b,A,B)   \
for (type a=0, b=0; a<A && b<B; b += (++a >= A), a = a % A)

static char blanks[51] = "                                                  ";
#define BLANKS(a) 	  &blanks[MAX(0,MIN(50,50-(a)))]

#define END(a)			  &(a)[strlen(a)]

#define WHITESPACE(a)	  ((a) &&  strchr (" \t\n\r", (a)))
#define BLACKSPACE(a)     ((a) && !strchr (" \t\n\r", (a)))

#define SKIP_COMMENTS(fp,line) {                \
  char *p;                                      \
  while (!feof (fp)) {                          \
	fgets (line, LINE_LEN, fp);             \
	DEBUG(4) << ":" << line;                \
	for (p = line; WHITESPACE (*p); p++);   \
	if (*p && !strchr ("/\n\r", *p)) break; \
  }                                             \
  DEBUG(4) << " ^^^\n";                         \
}

#define PAUSE { \
  char s[100];  \
  gets (s);     \
}

#ifdef UNIX
#define DELETE_ARRAY   	delete []
#else
#define DELETE_ARRAY   	delete
#endif

#define random(a)       (rand () % (int) MAX((a),1))
#define randomize(a)    srand ((unsigned int) (a))
#define F_random(a)     (((float) random (1000) / 1000) * (a))
#define R_random(a)     (F_random (2 * (a)) - (a))

#endif

////////////////////////////////////////////////////////////////////////////

