| 1 |
gwlarson |
2.13 |
/* Copyright (c) 1998 Silicon Graphics, Inc. */
|
| 2 |
greg |
1.1 |
|
| 3 |
gregl |
2.9 |
/* SCCSid "$SunId$ SGI" */
|
| 4 |
greg |
1.1 |
|
| 5 |
|
|
/*
|
| 6 |
|
|
* Miscellaneous definitions required by many routines.
|
| 7 |
|
|
*/
|
| 8 |
|
|
|
| 9 |
|
|
#include <stdio.h>
|
| 10 |
|
|
|
| 11 |
gwlarson |
2.12 |
#include <sys/types.h>
|
| 12 |
|
|
|
| 13 |
greg |
2.2 |
#include <fcntl.h>
|
| 14 |
|
|
|
| 15 |
greg |
1.1 |
#include <math.h>
|
| 16 |
|
|
|
| 17 |
|
|
#include <errno.h>
|
| 18 |
|
|
|
| 19 |
greg |
1.5 |
#include "mat4.h"
|
| 20 |
|
|
/* regular transformation */
|
| 21 |
|
|
typedef struct {
|
| 22 |
|
|
MAT4 xfm; /* transform matrix */
|
| 23 |
greg |
1.8 |
FLOAT sca; /* scalefactor */
|
| 24 |
greg |
1.5 |
} XF;
|
| 25 |
|
|
/* complemetary tranformation */
|
| 26 |
|
|
typedef struct {
|
| 27 |
|
|
XF f; /* forward */
|
| 28 |
|
|
XF b; /* backward */
|
| 29 |
|
|
} FULLXF;
|
| 30 |
greg |
1.1 |
|
| 31 |
greg |
2.7 |
#ifndef PI
|
| 32 |
greg |
2.2 |
#ifdef M_PI
|
| 33 |
gregl |
2.11 |
#define PI ((double)M_PI)
|
| 34 |
greg |
1.1 |
#else
|
| 35 |
greg |
2.2 |
#define PI 3.14159265358979323846
|
| 36 |
greg |
2.7 |
#endif
|
| 37 |
greg |
1.1 |
#endif
|
| 38 |
greg |
1.2 |
|
| 39 |
greg |
2.2 |
#ifndef F_OK /* mode bits for access(2) call */
|
| 40 |
|
|
#define R_OK 4 /* readable */
|
| 41 |
|
|
#define W_OK 2 /* writable */
|
| 42 |
|
|
#define X_OK 1 /* executable */
|
| 43 |
|
|
#define F_OK 0 /* exists */
|
| 44 |
gwlarson |
2.13 |
#endif
|
| 45 |
|
|
|
| 46 |
|
|
#ifndef int2
|
| 47 |
|
|
#define int2 short /* two-byte integer */
|
| 48 |
|
|
#endif
|
| 49 |
|
|
#ifndef int4
|
| 50 |
|
|
#define int4 int /* four-byte integer */
|
| 51 |
greg |
1.2 |
#endif
|
| 52 |
gregl |
2.9 |
|
| 53 |
|
|
extern int eputs(), wputs(); /* standard error output functions */
|
| 54 |
|
|
|
| 55 |
greg |
1.1 |
/* error codes */
|
| 56 |
gregl |
2.10 |
#define WARNING 0 /* non-fatal error */
|
| 57 |
|
|
#define USER 1 /* fatal user-caused error */
|
| 58 |
|
|
#define SYSTEM 2 /* fatal system-related error */
|
| 59 |
|
|
#define INTERNAL 3 /* fatal program-related error */
|
| 60 |
|
|
#define CONSISTENCY 4 /* bad consistency check, abort */
|
| 61 |
|
|
#define COMMAND 5 /* interactive error */
|
| 62 |
|
|
#define NERRS 6
|
| 63 |
gregl |
2.9 |
/* error struct */
|
| 64 |
|
|
extern struct erract {
|
| 65 |
|
|
char pre[16]; /* prefix message */
|
| 66 |
|
|
int (*pf)(); /* put function (resettable) */
|
| 67 |
|
|
int ec; /* exit code (0 means non-fatal) */
|
| 68 |
|
|
} erract[NERRS]; /* list of error actions */
|
| 69 |
|
|
|
| 70 |
|
|
#define ERRACT_INIT { {"warning - ", wputs, 0}, \
|
| 71 |
|
|
{"fatal - ", eputs, 1}, \
|
| 72 |
|
|
{"system - ", eputs, 2}, \
|
| 73 |
|
|
{"internal - ", eputs, 1}, \
|
| 74 |
|
|
{"consistency - ", eputs, -1}, \
|
| 75 |
|
|
{"", NULL, 0} }
|
| 76 |
greg |
1.1 |
|
| 77 |
|
|
extern char errmsg[]; /* global buffer for error messages */
|
| 78 |
|
|
|
| 79 |
gwlarson |
2.14 |
#ifdef FASTMATH
|
| 80 |
|
|
#define tcos cos
|
| 81 |
|
|
#define tsin sin
|
| 82 |
|
|
#define ttan tan
|
| 83 |
|
|
#else
|
| 84 |
|
|
extern double tcos(); /* table-based cosine approximation */
|
| 85 |
|
|
#define tsin(x) tcos((x)-(PI/2.))
|
| 86 |
|
|
#define ttan(x) (tsin(x)/tcos(x))
|
| 87 |
|
|
#endif
|
| 88 |
|
|
/* custom version of assert(3) */
|
| 89 |
|
|
#define CHECK(be,et,em) ((be) ? error(et,em) : 0)
|
| 90 |
|
|
#ifdef DEBUG
|
| 91 |
|
|
#define DCHECK CHECK
|
| 92 |
|
|
#else
|
| 93 |
|
|
#define DCHECK(be,et,em) 0
|
| 94 |
|
|
#endif
|
| 95 |
greg |
1.3 |
/* memory operations */
|
| 96 |
greg |
2.2 |
#ifdef NOSTRUCTASS
|
| 97 |
|
|
#define copystruct(d,s) bcopy((char *)(s),(char *)(d),sizeof(*(d)))
|
| 98 |
greg |
1.9 |
#else
|
| 99 |
greg |
2.2 |
#define copystruct(d,s) (*(d) = *(s))
|
| 100 |
greg |
1.3 |
#endif
|
| 101 |
greg |
1.6 |
|
| 102 |
gwlarson |
2.14 |
#ifdef BSD
|
| 103 |
gwlarson |
2.12 |
extern long lseek();
|
| 104 |
|
|
#else
|
| 105 |
greg |
2.2 |
#define bcopy(s,d,n) (void)memcpy(d,s,n)
|
| 106 |
|
|
#define bzero(d,n) (void)memset(d,0,n)
|
| 107 |
|
|
#define bcmp(b1,b2,n) memcmp(b1,b2,n)
|
| 108 |
|
|
#define index strchr
|
| 109 |
|
|
#define rindex strrchr
|
| 110 |
gwlarson |
2.12 |
extern off_t lseek();
|
| 111 |
greg |
1.3 |
#endif
|
| 112 |
gwlarson |
2.12 |
extern long ftell();
|
| 113 |
greg |
1.3 |
|
| 114 |
greg |
2.8 |
extern char *sskip(), *sskip2();
|
| 115 |
greg |
1.4 |
extern char *getpath(), *getenv();
|
| 116 |
greg |
2.3 |
#ifndef malloc
|
| 117 |
greg |
1.1 |
extern char *malloc(), *calloc(), *realloc();
|
| 118 |
greg |
2.3 |
#endif
|
| 119 |
greg |
1.1 |
extern char *bmalloc(), *savestr(), *savqstr();
|
| 120 |
greg |
2.2 |
|
| 121 |
greg |
2.5 |
#ifdef DCL_ATOF
|
| 122 |
|
|
extern double atof();
|
| 123 |
|
|
#endif
|
| 124 |
|
|
|
| 125 |
greg |
2.2 |
#ifdef MSDOS
|
| 126 |
|
|
#define NIX 1
|
| 127 |
|
|
#endif
|
| 128 |
|
|
#ifdef AMIGA
|
| 129 |
|
|
#define NIX 1
|
| 130 |
|
|
#endif
|
| 131 |
|
|
|