|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef _TMACRO_H_
|
|
Toshihiro Shimizu |
890ddd |
#define _TMACRO_H_
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if defined(_WIN32) && !defined(WIN32)
|
|
Toshihiro Shimizu |
890ddd |
#define WIN32
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef WIN32
|
|
Toshihiro Shimizu |
890ddd |
#include <sys param.h=""></sys>
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
//#include "tmacroW.h"
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if defined(DBMALLOC) && !defined(WIN32)
|
|
Toshihiro Shimizu |
890ddd |
#include "dbmalloc.h"
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
#define TNZ_EXPORT_API __declspec(dllexport)
|
|
Toshihiro Shimizu |
890ddd |
#define TNZ_IMPORT_API __declspec(dllimport)
|
|
Toshihiro Shimizu |
890ddd |
#define TNZ_EXPORT_VAR __declspec(dllexport)
|
|
Toshihiro Shimizu |
890ddd |
#define TNZ_IMPORT_VAR __declspec(dllimport)
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define TNZ_EXPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define TNZ_IMPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define TNZ_EXPORT_VAR extern
|
|
Toshihiro Shimizu |
890ddd |
#define TNZ_IMPORT_VAR extern
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TRUE
|
|
Toshihiro Shimizu |
890ddd |
#define TRUE 1
|
|
Toshihiro Shimizu |
890ddd |
#define FALSE 0
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define NIL ((void *)0)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef int TBOOL;
|
|
Toshihiro Shimizu |
890ddd |
typedef signed char SCHAR;
|
|
Toshihiro Shimizu |
890ddd |
typedef unsigned char UCHAR;
|
|
Toshihiro Shimizu |
890ddd |
typedef unsigned short USHORT;
|
|
Toshihiro Shimizu |
890ddd |
typedef unsigned int UINT;
|
|
Toshihiro Shimizu |
890ddd |
typedef unsigned long ULONG;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define CASE \
|
|
Toshihiro Shimizu |
890ddd |
break; \
|
|
Toshihiro Shimizu |
890ddd |
case
|
|
Toshihiro Shimizu |
890ddd |
#define __OR case
|
|
Toshihiro Shimizu |
890ddd |
#define DEFAULT \
|
|
Toshihiro Shimizu |
890ddd |
break; \
|
|
Toshihiro Shimizu |
890ddd |
default
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef struct {
|
|
Toshihiro Shimizu |
890ddd |
int x0, y0, x1, y1;
|
|
Toshihiro Shimizu |
890ddd |
} TRECT;
|
|
Toshihiro Shimizu |
890ddd |
typedef struct {
|
|
Toshihiro Shimizu |
890ddd |
double x0, y0, x1, y1;
|
|
Toshihiro Shimizu |
890ddd |
} TDRECT;
|
|
Toshihiro Shimizu |
890ddd |
typedef struct {
|
|
Toshihiro Shimizu |
890ddd |
int x0, y0, x1, y1;
|
|
Toshihiro Shimizu |
890ddd |
} TLINE;
|
|
Toshihiro Shimizu |
890ddd |
typedef struct {
|
|
Toshihiro Shimizu |
890ddd |
double x0, y0, x1, y1;
|
|
Toshihiro Shimizu |
890ddd |
} TDLINE;
|
|
Toshihiro Shimizu |
890ddd |
typedef struct {
|
|
Toshihiro Shimizu |
890ddd |
int x, y;
|
|
Toshihiro Shimizu |
890ddd |
} TPOINT;
|
|
Toshihiro Shimizu |
890ddd |
typedef struct {
|
|
Toshihiro Shimizu |
890ddd |
double x, y;
|
|
Toshihiro Shimizu |
890ddd |
} TDPOINT;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define STR_EQ(s1, s2) (!strcmp((s1), (s2)))
|
|
Toshihiro Shimizu |
890ddd |
#define STR_NE(s1, s2) (strcmp((s1), (s2)))
|
|
Toshihiro Shimizu |
890ddd |
#define STR_GE(s1, s2) (strcmp((s1), (s2)) >= 0)
|
|
Toshihiro Shimizu |
890ddd |
#define STR_LE(s1, s2) (strcmp((s1), (s2)) <= 0)
|
|
Toshihiro Shimizu |
890ddd |
#define STR_GT(s1, s2) (strcmp((s1), (s2)) > 0)
|
|
Toshihiro Shimizu |
890ddd |
#define STR_LT(s1, s2) (strcmp((s1), (s2)) < 0)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define STRN_EQ(s1, s2, n) (!strncmp((s1), (s2), (n)))
|
|
Toshihiro Shimizu |
890ddd |
#define STRN_NE(s1, s2, n) (strncmp((s1), (s2), (n)))
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define STR_START(s1, s2) (!strncmp((s1), (s2), strlen(s2)))
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define FILESTR_EQ(s1, s2) (!tnz_filestrcmp((s1), (s2)))
|
|
Toshihiro Shimizu |
890ddd |
#define FILESTR_NE(s1, s2) (tnz_filestrcmp((s1), (s2)))
|
|
Toshihiro Shimizu |
890ddd |
#define FILESTR_GE(s1, s2) (tnz_filestrcmp((s1), (s2)) >= 0)
|
|
Toshihiro Shimizu |
890ddd |
#define FILESTR_LE(s1, s2) (tnz_filestrcmp((s1), (s2)) <= 0)
|
|
Toshihiro Shimizu |
890ddd |
#define FILESTR_GT(s1, s2) (tnz_filestrcmp((s1), (s2)) > 0)
|
|
Toshihiro Shimizu |
890ddd |
#define FILESTR_LT(s1, s2) (tnz_filestrcmp((s1), (s2)) < 0)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define FILESTRN_EQ(s1, s2, n) (!tnz_filestrncmp((s1), (s2), (n)))
|
|
Toshihiro Shimizu |
890ddd |
#define FILESTRN_NE(s1, s2, n) (tnz_filestrncmp((s1), (s2), (n)))
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef MIN
|
|
Toshihiro Shimizu |
890ddd |
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#ifndef MAX
|
|
Toshihiro Shimizu |
890ddd |
#define MAX(x, y) ((x) > (y) ? (x) : (y))
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define ROUND(x) ((int)(((int)(-0.9F) == 0 && (x) < 0.0F) ? ((x)-0.5F) : ((x) + 0.5F)))
|
|
Toshihiro Shimizu |
890ddd |
/* solo per argomenti positivi: */
|
|
Toshihiro Shimizu |
890ddd |
#define ROUNDP(x) ((int)((x) + 0.5F))
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* equivalenti a (int)floor() e (int)ceil() (ma piu' veloci)
|
|
Toshihiro Shimizu |
890ddd |
solo se la risoluzione dell'argomento e' inferiore ad 1 */
|
|
Toshihiro Shimizu |
890ddd |
#define FLOOR(x) ((int)(x) > (x) ? (int)(x)-1 : (int)(x))
|
|
Toshihiro Shimizu |
890ddd |
#define CEIL(x) ((int)(x) < (x) ? (int)(x) + 1 : (int)(x))
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define NOT_LESS_THAN(MIN, X) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
if ((X) < (MIN)) \
|
|
Toshihiro Shimizu |
890ddd |
(X) = (MIN); \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#define NOT_MORE_THAN(MAX, X) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
if ((X) > (MAX)) \
|
|
Toshihiro Shimizu |
890ddd |
(X) = (MAX); \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define CROP(X, MIN, MAX) (X < MIN ? MIN : (X > MAX ? MAX : X))
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef MAXINT
|
|
Toshihiro Shimizu |
890ddd |
#define MAXINT ((int)((~0U) >> 1))
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#ifndef MININT
|
|
Toshihiro Shimizu |
890ddd |
#define MININT (~MAXINT)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static const char *const TALLOC_MSG_ =
|
|
Toshihiro Shimizu |
890ddd |
"Out of memory allocating %d bytes (%s line %d)";
|
|
Toshihiro Shimizu |
890ddd |
static const char *const TREALLOC_MSG_ =
|
|
Toshihiro Shimizu |
890ddd |
"Out of memory reallocating %d bytes (%s line %d)";
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if defined(WIN32) && defined(_DEBUG)
|
|
Toshihiro Shimizu |
890ddd |
#define WIN32_DBG_NBFL_ , _NORMAL_BLOCK, __FILE__, __LINE__
|
|
Toshihiro Shimizu |
890ddd |
#define WIN32_DBG_NB_ , _NORMAL_BLOCK
|
|
Toshihiro Shimizu |
890ddd |
#define TMALLOC_FUN_ _malloc_dbg
|
|
Toshihiro Shimizu |
890ddd |
#define TCALLOC_FUN_ _calloc_dbg
|
|
Toshihiro Shimizu |
890ddd |
#define TREALLOC_FUN_ _realloc_dbg
|
|
Toshihiro Shimizu |
890ddd |
#define TFREE_FUN_ _free_dbg
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define WIN32_DBG_NBFL_
|
|
Toshihiro Shimizu |
890ddd |
#define WIN32_DBG_NB_
|
|
Toshihiro Shimizu |
890ddd |
#define TMALLOC_FUN_ malloc
|
|
Toshihiro Shimizu |
890ddd |
#define TCALLOC_FUN_ calloc
|
|
Toshihiro Shimizu |
890ddd |
#define TREALLOC_FUN_ realloc
|
|
Toshihiro Shimizu |
890ddd |
#define TFREE_FUN_ free
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define TMALLOC(ptr, elem) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
(ptr) = (void *)TMALLOC_FUN_((elem) * sizeof(*(ptr)) WIN32_DBG_NBFL_); \
|
|
Toshihiro Shimizu |
890ddd |
if (!ptr) \
|
|
Toshihiro Shimizu |
890ddd |
tmsg_error(TALLOC_MSG_, (int)((elem) * sizeof(*(ptr))), __FILE__, \
|
|
Toshihiro Shimizu |
890ddd |
__LINE__); \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#define TCALLOC(ptr, elem) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
(ptr) = (void *)TCALLOC_FUN_((elem), sizeof(*(ptr)) WIN32_DBG_NBFL_); \
|
|
Toshihiro Shimizu |
890ddd |
if (!ptr) \
|
|
Toshihiro Shimizu |
890ddd |
tmsg_error(TALLOC_MSG_, (int)((elem) * sizeof(*(ptr))), __FILE__, \
|
|
Toshihiro Shimizu |
890ddd |
__LINE__); \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#define TREALLOC(ptr, elem) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
if (ptr) \
|
|
Toshihiro Shimizu |
890ddd |
(ptr) = (void *)TREALLOC_FUN_((ptr), (elem) * sizeof(*(ptr)) \
|
|
Toshihiro Shimizu |
890ddd |
WIN32_DBG_NBFL_); \
|
|
Toshihiro Shimizu |
890ddd |
else \
|
|
Toshihiro Shimizu |
890ddd |
(ptr) = (void *)TMALLOC_FUN_((elem) * sizeof(*(ptr)) WIN32_DBG_NBFL_); \
|
|
Toshihiro Shimizu |
890ddd |
if (!ptr) \
|
|
Toshihiro Shimizu |
890ddd |
tmsg_error(TREALLOC_MSG_, (int)((elem) * sizeof(*(ptr))), __FILE__, \
|
|
Toshihiro Shimizu |
890ddd |
__LINE__); \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define TFREE(ptr) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
if (ptr) { \
|
|
Toshihiro Shimizu |
890ddd |
TFREE_FUN_((ptr)WIN32_DBG_NB_); \
|
|
Toshihiro Shimizu |
890ddd |
ptr = NIL; \
|
|
Toshihiro Shimizu |
890ddd |
} \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*---------------------------------------------------------------------------*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define STR_ASSIGN(DST, SRC) \
|
|
Toshihiro Shimizu |
890ddd |
{ \
|
|
Toshihiro Shimizu |
890ddd |
TFREE(DST); \
|
|
Toshihiro Shimizu |
890ddd |
DST = SRC ? strsave(SRC) : 0; \
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|