Shinya Kitaoka 810553
#pragma once
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
Campbell Barton d869b5
#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
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
typedef struct { int x0, y0, x1, y1; } TRECT;
Shinya Kitaoka 120a6e
typedef struct { double x0, y0, x1, y1; } TDRECT;
Shinya Kitaoka 120a6e
typedef struct { int x0, y0, x1, y1; } TLINE;
Shinya Kitaoka 120a6e
typedef struct { double x0, y0, x1, y1; } TDLINE;
Shinya Kitaoka 120a6e
typedef struct { int x, y; } TPOINT;
Shinya Kitaoka 120a6e
typedef struct { double x, y; } 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
Shinya Kitaoka 120a6e
#define ROUND(x)                                                               \
Shinya Kitaoka 120a6e
  ((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
Shinya Kitaoka 120a6e
#define NOT_LESS_THAN(MIN, X)                                                  \
Shinya Kitaoka 120a6e
  {                                                                            \
Shinya Kitaoka 120a6e
    if ((X) < (MIN)) (X) = (MIN);                                              \
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
#define NOT_MORE_THAN(MAX, X)                                                  \
Shinya Kitaoka 120a6e
  {                                                                            \
Shinya Kitaoka 120a6e
    if ((X) > (MAX)) (X) = (MAX);                                              \
Shinya Kitaoka 120a6e
  }
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_ =
Shinya Kitaoka 120a6e
    "Out of memory allocating %d bytes (%s line %d)";
Toshihiro Shimizu 890ddd
static const char *const TREALLOC_MSG_ =
Shinya Kitaoka 120a6e
    "Out of memory reallocating %d bytes (%s line %d)";
Toshihiro Shimizu 890ddd
Campbell Barton d869b5
#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)                                                     \
Shinya Kitaoka 120a6e
  {                                                                            \
Shinya Kitaoka 120a6e
    (ptr) = (void *)TMALLOC_FUN_((elem) * sizeof(*(ptr)) WIN32_DBG_NBFL_);     \
Shinya Kitaoka 120a6e
    if (!ptr)                                                                  \
Shinya Kitaoka 120a6e
      tmsg_error(TALLOC_MSG_, (int)((elem) * sizeof(*(ptr))), __FILE__,        \
Shinya Kitaoka 120a6e
                 __LINE__);                                                    \
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
#define TCALLOC(ptr, elem)                                                     \
Shinya Kitaoka 120a6e
  {                                                                            \
Shinya Kitaoka 120a6e
    (ptr) = (void *)TCALLOC_FUN_((elem), sizeof(*(ptr)) WIN32_DBG_NBFL_);      \
Shinya Kitaoka 120a6e
    if (!ptr)                                                                  \
Shinya Kitaoka 120a6e
      tmsg_error(TALLOC_MSG_, (int)((elem) * sizeof(*(ptr))), __FILE__,        \
Shinya Kitaoka 120a6e
                 __LINE__);                                                    \
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
#define TREALLOC(ptr, elem)                                                    \
Shinya Kitaoka 120a6e
  {                                                                            \
Shinya Kitaoka 120a6e
    if (ptr)                                                                   \
Shinya Kitaoka 120a6e
      (ptr) = (void *)TREALLOC_FUN_((ptr),                                     \
Shinya Kitaoka 120a6e
                                    (elem) * sizeof(*(ptr)) WIN32_DBG_NBFL_);  \
Shinya Kitaoka 120a6e
    else                                                                       \
Shinya Kitaoka 120a6e
      (ptr) = (void *)TMALLOC_FUN_((elem) * sizeof(*(ptr)) WIN32_DBG_NBFL_);   \
Shinya Kitaoka 120a6e
    if (!ptr)                                                                  \
Shinya Kitaoka 120a6e
      tmsg_error(TREALLOC_MSG_, (int)((elem) * sizeof(*(ptr))), __FILE__,      \
Shinya Kitaoka 120a6e
                 __LINE__);                                                    \
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#define TFREE(ptr)                                                             \
Shinya Kitaoka 120a6e
  {                                                                            \
Shinya Kitaoka 120a6e
    if (ptr) {                                                                 \
Shinya Kitaoka 120a6e
      TFREE_FUN_((ptr)WIN32_DBG_NB_);                                          \
Shinya Kitaoka 120a6e
      ptr = NIL;                                                               \
Shinya Kitaoka 120a6e
    }                                                                          \
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#define STR_ASSIGN(DST, SRC)                                                   \
Shinya Kitaoka 120a6e
  {                                                                            \
Shinya Kitaoka 120a6e
    TFREE(DST);                                                                \
Shinya Kitaoka 120a6e
    DST = SRC ? strsave(SRC) : 0;                                              \
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif