2017-04-25 14:41:48 +02:00
|
|
|
/*
|
|
|
|
|
* magic.h --
|
|
|
|
|
*
|
|
|
|
|
* Global definitions for all MAGIC modules
|
|
|
|
|
*
|
2020-05-23 23:13:14 +02:00
|
|
|
* *********************************************************************
|
|
|
|
|
* * Copyright (C) 1985, 1990 Regents of the University of California. *
|
|
|
|
|
* * Permission to use, copy, modify, and distribute this *
|
|
|
|
|
* * software and its documentation for any purpose and without *
|
|
|
|
|
* * fee is hereby granted, provided that the above copyright *
|
|
|
|
|
* * notice appear in all copies. The University of California *
|
|
|
|
|
* * makes no representations about the suitability of this *
|
|
|
|
|
* * software for any purpose. It is provided "as is" without *
|
|
|
|
|
* * express or implied warranty. Export of this software outside *
|
|
|
|
|
* * of the United States of America may require an export license. *
|
2017-04-25 14:41:48 +02:00
|
|
|
* *********************************************************************
|
|
|
|
|
*
|
|
|
|
|
* rcsid="$Header"
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef _MAGIC_H
|
|
|
|
|
#define _MAGIC_H
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2022-11-02 22:12:46 +01:00
|
|
|
#ifdef HAVE_ZLIB
|
|
|
|
|
#include <zlib.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-04-25 14:41:48 +02:00
|
|
|
/* ------------------- Universal pointer typecast --------------------- */
|
|
|
|
|
|
|
|
|
|
/* Set default value for backwards compatibility with non-autoconf make */
|
|
|
|
|
#ifndef SIZEOF_VOID_P
|
|
|
|
|
#define SIZEOF_VOID_P SIZEOF_UNSIGNED_INT
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-09-30 00:00:00 +02:00
|
|
|
#if SIZEOF_VOID_P == SIZEOF_UNSIGNED_LONG
|
2017-04-25 14:41:48 +02:00
|
|
|
typedef unsigned long pointertype;
|
|
|
|
|
typedef signed long spointertype;
|
2024-09-30 00:00:00 +02:00
|
|
|
#elif SIZEOF_VOID_P == SIZEOF_UNSIGNED_INT
|
|
|
|
|
typedef unsigned int pointertype;
|
|
|
|
|
typedef signed int spointertype;
|
2017-04-25 14:41:48 +02:00
|
|
|
#else
|
|
|
|
|
ERROR: Cannot compile without knowing the size of a pointer. See utils/magic.h
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
typedef int64_t dlong;
|
|
|
|
|
#define DLONG_MAX INT64_MAX
|
|
|
|
|
#define DLONG_MIN INT64_MIN
|
2024-10-02 07:59:00 +02:00
|
|
|
#if (defined(__x86_64__) && !defined(_WIN64))
|
|
|
|
|
/* gcc x86_64 defines int64_t as 'long int' on LP64 */
|
|
|
|
|
#define DLONG_PREFIX "l"
|
|
|
|
|
#else
|
|
|
|
|
/* for 32bit and 64bit LLP64 (_WIN64) systems */
|
2017-04-25 14:41:48 +02:00
|
|
|
#define DLONG_PREFIX "ll"
|
2024-10-02 07:59:00 +02:00
|
|
|
#endif
|
2017-04-25 14:41:48 +02:00
|
|
|
|
|
|
|
|
/* --------------------- Universal pointer type ----------------------- */
|
|
|
|
|
|
|
|
|
|
#ifndef _CLIENTDATA
|
|
|
|
|
typedef pointertype ClientData;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* --------------------------- Booleans ------------------------------- */
|
|
|
|
|
|
|
|
|
|
typedef unsigned char bool;
|
|
|
|
|
|
|
|
|
|
#ifndef TRUE
|
|
|
|
|
#define TRUE ((bool)1)
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef FALSE
|
|
|
|
|
#define FALSE ((bool)0)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* ----------------------- Simple functions --------------------------- */
|
|
|
|
|
|
|
|
|
|
#ifndef MAX
|
|
|
|
|
#define MAX(a,b) (((a) < (b)) ? (b) : (a))
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef MIN
|
|
|
|
|
#define MIN(a,b) (((a) > (b)) ? (b) : (a))
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define ABS(x) (((x) >= 0) ? (x) : -(x))
|
|
|
|
|
#define ABSDIFF(x,y) (((x) < (y)) ? (y) - (x) : (x) - (y))
|
|
|
|
|
#define ODD(i) (i&1)
|
|
|
|
|
#define EVEN(i) (!(i&1))
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
|
/* Round to nearest integer---use c99 functions if available from the */
|
|
|
|
|
/* math library (checked by "configure"), otherwise use the macro */
|
|
|
|
|
/* definitions below. */
|
|
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_ROUND
|
|
|
|
|
#define round(a) (((a) < 0) ? (int)((a) - 0.5) : (int)((a) + 0.5))
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_ROUNDF
|
|
|
|
|
#define roundf(x) ((float)((int)((float)(x) + ((x < 0) ? -0.5 : 0.5))))
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* -------------------------- Search paths ---------------------------- */
|
|
|
|
|
|
|
|
|
|
extern char *CellLibPath; /* Path for finding cells. */
|
|
|
|
|
extern char *SysLibPath; /* Path for finding system
|
|
|
|
|
* files like color maps, styles, etc.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* --------------------- Debugging and assertions --------------------- */
|
|
|
|
|
|
|
|
|
|
/* To enable assertions, undefine NDEBUG in file defs.mak */
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#define ASSERT(p, where) assert(p) /* "where" is ignored */
|
|
|
|
|
|
|
|
|
|
/* ------------------------ Malloc/free ------------------------------- */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Magic has its own versions of malloc() and free(), called mallocMagic()
|
|
|
|
|
* and freeMagic(). Magic procedures should ONLY use these procedures.
|
|
|
|
|
* Just for the sake of robustness, though, we define malloc and free
|
|
|
|
|
* here to error strings.
|
|
|
|
|
*/
|
|
|
|
|
#define malloc You_should_use_the_Magic_procedure_mallocMagic_instead
|
|
|
|
|
#define free You_should_use_the_Magic_procedure_freeMagic_instead
|
|
|
|
|
#define calloc You_should_use_the_Magic_procedure_callocMagic_instead
|
|
|
|
|
|
|
|
|
|
/* ---------- Flag for global variables (for readability) ------------- */
|
|
|
|
|
|
|
|
|
|
#define global /* Nothing */
|
|
|
|
|
|
|
|
|
|
/* ------------ Globally-used strings. -------------------------------- */
|
|
|
|
|
|
|
|
|
|
extern char *MagicVersion;
|
|
|
|
|
extern char *MagicRevision;
|
|
|
|
|
extern char *MagicCompileTime;
|
|
|
|
|
extern char AbortMessage[];
|
|
|
|
|
|
2022-11-02 22:12:46 +01:00
|
|
|
/* ------------ zlib (compression) support -------------------------------- */
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_ZLIB
|
|
|
|
|
#define FOPEN gzopen
|
|
|
|
|
#define FCLOSE gzclose
|
|
|
|
|
#define FGETC gzgetc
|
2024-10-08 09:01:17 +02:00
|
|
|
#define magicFREAD(a,b,c,d) gzread(d,a,b*c)
|
2022-11-02 22:12:46 +01:00
|
|
|
#define FEOF gzeof
|
|
|
|
|
#define FSEEK gzseek
|
|
|
|
|
#define FTELL gztell
|
|
|
|
|
#define REWIND gzrewind
|
|
|
|
|
#define FILETYPE gzFile
|
|
|
|
|
#define OFFTYPE z_off_t
|
|
|
|
|
#else
|
|
|
|
|
#define FOPEN fopen
|
|
|
|
|
#define FCLOSE fclose
|
|
|
|
|
#define FGETC getc
|
2024-10-08 09:01:17 +02:00
|
|
|
#define magicFREAD fread
|
2022-11-02 22:12:46 +01:00
|
|
|
#define FEOF feof
|
|
|
|
|
#define FSEEK fseek
|
|
|
|
|
#define FTELL ftello
|
|
|
|
|
#define REWIND rewind
|
|
|
|
|
#define FILETYPE FILE *
|
|
|
|
|
#define OFFTYPE off_t
|
|
|
|
|
#define PaZOpen PaOpen
|
|
|
|
|
#define PaLockZOpen PaLockOpen
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-10-03 23:35:26 +02:00
|
|
|
/* ------------ modern compiler support -------------------------------- */
|
|
|
|
|
|
|
|
|
|
#if defined(__GNUC__) || defined(__clang__)
|
|
|
|
|
#define ATTR_FORMAT_PRINTF_1 __attribute__((format (printf,1,2)))
|
|
|
|
|
#define ATTR_FORMAT_PRINTF_2 __attribute__((format (printf,2,3)))
|
2024-10-04 12:19:10 +02:00
|
|
|
#define __unused__(x) x __attribute__((unused))
|
2024-10-03 23:35:26 +02:00
|
|
|
#else
|
|
|
|
|
#define ATTR_FORMAT_PRINTF_1 /* */
|
|
|
|
|
#define ATTR_FORMAT_PRINTF_2 /* */
|
2024-10-04 12:19:10 +02:00
|
|
|
#define __unused__(x) x
|
2024-10-03 23:35:26 +02:00
|
|
|
#endif
|
|
|
|
|
|
2017-04-25 14:41:48 +02:00
|
|
|
/* ---------------- Start of Machine Configuration Section ----------------- */
|
|
|
|
|
|
|
|
|
|
/* ------- Configuration: Handle Missing Routines/Definitions ------- */
|
|
|
|
|
|
|
|
|
|
/* System V is missing some BSDisms. */
|
|
|
|
|
#ifdef SYSV
|
|
|
|
|
# ifndef bcopy
|
|
|
|
|
# define bcopy(a, b, c) memcpy(b, a, c)
|
|
|
|
|
# endif
|
|
|
|
|
# ifndef bzero
|
|
|
|
|
# define bzero(a, b) memset(a, 0, b)
|
|
|
|
|
# endif
|
|
|
|
|
# ifndef bcmp
|
|
|
|
|
# define bcmp(a, b, c) memcmp(b, a, c)
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Some machines need vfprintf(). (A temporary MIPS bug?) (see txOutput.c) */
|
|
|
|
|
#if (defined(MIPSEB) && defined(SYSTYPE_BSD43)) || ibm032
|
|
|
|
|
# define NEED_VFPRINTF
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Some machines expect signal handlers to return an "int". But most machines
|
|
|
|
|
* expect them to return a "void". If your machine expects an "int", put in
|
|
|
|
|
* an "ifdef" below.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#if (defined(MIPSEB) && defined(SYSTYPE_BSD43)) || ibm032
|
|
|
|
|
# define SIG_RETURNS_INT
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Linux
|
|
|
|
|
*/
|
|
|
|
|
#ifdef linux
|
|
|
|
|
#define sigvec sigaction
|
|
|
|
|
#define sv_handler sa_handler
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
2020-05-23 23:13:14 +02:00
|
|
|
* Irix
|
2017-04-25 14:41:48 +02:00
|
|
|
*/
|
|
|
|
|
#ifdef sgi
|
|
|
|
|
#define vfork fork
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Select system call
|
|
|
|
|
*
|
2020-05-23 23:13:14 +02:00
|
|
|
* Note: Errors here may be caused by not including <sys/types.h>
|
2017-04-25 14:41:48 +02:00
|
|
|
* before "magic.h" (deprecated; more modern usage is <sys/select.h>
|
|
|
|
|
*/
|
|
|
|
|
#include <sys/select.h>
|
|
|
|
|
#ifndef FD_SET
|
|
|
|
|
#define fd_set int
|
|
|
|
|
#define FD_SET(n, p) ((*(p)) |= (1 << (n)))
|
|
|
|
|
#define FD_CLR(n, p) ((*(p)) &= ~(1 << (n)))
|
|
|
|
|
#define FD_ISSET(n, p) ((*(p)) & (1 << (n)))
|
|
|
|
|
#define FD_ZERO(p) (*(p) = 0)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Handling of VA_COPY. These variables are set by the configuration
|
|
|
|
|
* script. Some systems define va_copy, some define __va_copy, and
|
|
|
|
|
* some don't define it at all. It is assumed that systems which do
|
|
|
|
|
* not define it at all allow arguments to be copied with "=".
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_VA_COPY
|
|
|
|
|
#ifdef HAVE___VA_COPY
|
|
|
|
|
#define va_copy(a, b) __va_copy(a, b)
|
|
|
|
|
#else
|
|
|
|
|
#define va_copy(a, b) a = b
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* ------------------ End of Machine Configuration Section ----------------- */
|
|
|
|
|
|
|
|
|
|
#endif /* _MAGIC_H */
|