home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
ascendMar8.tar
/
UMass
/
Triangulate
/
include
/
util.h
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-13
|
5KB
|
203 lines
/* @(#)rh_util.h 3.15 12/21/94 */
/*
* This is a general utilities macro file, used for both c and c++
* applications.
*/
#ifndef _standard_rih_utils_file
#define _standard_rih_utils_file
#ifdef __cplusplus
//---------------------------------------------------------------------
//
// This is the C++ version.
//
//---------------------------------------------------------------------
#include <stdio.h>
#include "bail_out.s"
typedef short BOOLEAN;
/* External declarations */
#include <stdlib.h>
#include <string.h>
#include <alloca.h>
#include <malloc.h>
#include <math.h>
/* Maximum and minimum */
#ifndef DEFINED_MAX_MIN
# define TRUE 1
# define FALSE 0
#ifndef MAXINT
const int MAXINT = 2147483647;
#endif
#ifndef maxint
const int maxint = 2147483647;
#endif
inline int rhMax(int a, int b) { return (a>b ? a : b); }
inline double rhMax(double a, double b) { return (a>b ? a : b); }
inline int rhMin(int a, int b) { return (a>b ? b : a); }
inline double rhMin(double a, double b) { return (a>b ? b : a); }
inline int rhAbs (int a) { return (a>0 ? a : -a); }
inline double rhAbs (double a) { return (a>0.0 ? a : -a); }
#endif
// Allocation stuff
inline void ABORT ()
{
fprintf(stderr,"ERROR ***Out of space.***\n");
bail_out(1);
}
inline char *MALLOC(size_t len)
{
register char *zztchar = new char[len];
// register char *zztchar = (char *)malloc(len);
if (zztchar == (char *)0) ABORT();
return zztchar;
}
#define REALLOC(arr,arr_size) \
if ((arr_size *= 2, arr = realloc(arr,arr_size*sizeof(*arr)))== 0) \
ABORT()
#define TESTALLOC(arr,arr_size,arr_count) \
if(arr_count>=arr_size) REALLOC(arr,arr_size)
#define NEW(p) ((p *)MALLOC(sizeof(p)))
//
// String routines.
//
inline char * COPY(char *str)
{
return (str ? strcpy(MALLOC(strlen(str)+1),str) : (char *)0);
}
/* Macro for opening files */
#undef FOPEN
inline FILE *FOPEN (char *fname, char *amode)
{
register FILE *zztFILE=fopen((fname),(amode));
if (zztFILE ==0)
{
fprintf (stderr, "Unable to open file %s for %s.\n",
(fname),
((amode)[0]=='r')
? "read"
:((amode)[0]=='w'||(amode)[0]=='a' ?"write":"(bad mode)")
);
perror (fname);
bail_out(1);
}
return zztFILE;
}
#else
/*---------------------------------------------------------------------
//
// This is the standard C version.
//
//---------------------------------------------------------------------*/
#include <stdio.h>
#define TRUE 1
#define FALSE 0
typedef short BOOLEAN;
#ifndef MAXINT
# define MAXINT 2147483647
#endif
#ifndef maxint
# define maxint 2147483647
#endif
/* External declarations */
#include <string.h>
#include <malloc.h>
#include <math.h>
#include "bail_out.s"
extern char *mktemp();
/* Temporary variables used in macros */
static char *zztchar;
static FILE *zztFILE;
/* Maximum and minimum */
#define rhMax(a,b) ((a)>(b) ? (a) : (b))
#define rhMin(a,b) ((a)>(b) ? (b) : (a))
#define rhAbs(a) ((a)>0 ? (a) : -(a))
#define PI 3.141592654
/* Macro nefinitions */
#define MALLOC(len) \
(((zztchar=malloc((unsigned)len))==0)? \
(fprintf(stderr,"ERROR ***Out of space.***\n"), \
bail_out(1),(char *)0):zztchar)
#define NEW(p) ((p *)MALLOC(sizeof(p)))
#define STRCAT(str1,str2) \
(strcat(strcpy(MALLOC(strlen(str1)+strlen(str2)+1),str1),str2))
#define COPY(str) (str?strcpy(MALLOC(strlen(str)+1),str):0)
#define ABORT {fprintf(stderr,"ERROR ***Out of space.***\n"); bail_out(1);}
#define REALLOC(arr,arr_size) \
if ((arr_size *= 2, arr = realloc(arr,arr_size*sizeof(*arr)))== 0) \
ABORT
#if 0
/* No longer in use, and causes problems with definition of calloc */
extern char *calloc();
#define CALLOC(arr,arr_size) \
if ((arr_size = 16, arr = calloc(arr_size, sizeof(*arr))) == 0) ABORT
#endif
#define TESTALLOC(arr,arr_size,arr_count) \
if(arr_count>=arr_size) REALLOC(arr,arr_size)
/* Macro for opening files */
#define FOPEN(fname,amode) \
((zztFILE=fopen((fname),(amode)))==0 \
? (FILE *)((fprintf (stderr, \
"Unable to open file %s for %s.\n", (fname), \
((amode)[0]=='r') \
?"read" \
:((amode)[0]=='w'||(amode)[0]=='a' ?"write":"(bad mode)")),\
perror (fname), \
bail_out(1))) \
: zztFILE)
#endif
/*---------------------------------------------------------------------
//
// Common to both
//
//---------------------------------------------------------------------*/
/* Include allocation routines as well */
#include "alloc.h"
#include "concat.s"
#endif