| 1 |
schorsch |
2.25 |
/* RCSid $Id: standard.h,v 2.24 2003/06/06 16:38:47 schorsch Exp $ */ |
| 2 |
greg |
1.1 |
/* |
| 3 |
|
|
* Miscellaneous definitions required by many routines. |
| 4 |
|
|
*/ |
| 5 |
schorsch |
2.23 |
#ifndef _RAD_STANDARD_H_ |
| 6 |
|
|
#define _RAD_STANDARD_H_ |
| 7 |
schorsch |
2.24 |
#ifdef __cplusplus |
| 8 |
|
|
extern "C" { |
| 9 |
|
|
#endif |
| 10 |
schorsch |
2.23 |
|
| 11 |
greg |
2.17 |
#include "copyright.h" |
| 12 |
greg |
2.16 |
|
| 13 |
greg |
1.1 |
#include <stdio.h> |
| 14 |
gwlarson |
2.12 |
#include <sys/types.h> |
| 15 |
greg |
2.2 |
#include <fcntl.h> |
| 16 |
greg |
1.1 |
#include <math.h> |
| 17 |
|
|
#include <errno.h> |
| 18 |
greg |
2.16 |
#include <stdlib.h> |
| 19 |
|
|
#include <string.h> |
| 20 |
|
|
|
| 21 |
schorsch |
2.23 |
#include "platform.h" |
| 22 |
greg |
1.5 |
#include "mat4.h" |
| 23 |
schorsch |
2.25 |
|
| 24 |
|
|
|
| 25 |
|
|
#ifndef NULL |
| 26 |
|
|
#define NULL 0 |
| 27 |
|
|
#endif |
| 28 |
schorsch |
2.23 |
|
| 29 |
greg |
1.5 |
/* regular transformation */ |
| 30 |
|
|
typedef struct { |
| 31 |
|
|
MAT4 xfm; /* transform matrix */ |
| 32 |
greg |
1.8 |
FLOAT sca; /* scalefactor */ |
| 33 |
greg |
1.5 |
} XF; |
| 34 |
|
|
/* complemetary tranformation */ |
| 35 |
|
|
typedef struct { |
| 36 |
|
|
XF f; /* forward */ |
| 37 |
|
|
XF b; /* backward */ |
| 38 |
|
|
} FULLXF; |
| 39 |
greg |
1.1 |
|
| 40 |
greg |
2.7 |
#ifndef PI |
| 41 |
greg |
2.2 |
#ifdef M_PI |
| 42 |
gregl |
2.11 |
#define PI ((double)M_PI) |
| 43 |
greg |
1.1 |
#else |
| 44 |
greg |
2.2 |
#define PI 3.14159265358979323846 |
| 45 |
greg |
2.7 |
#endif |
| 46 |
greg |
1.1 |
#endif |
| 47 |
greg |
1.2 |
|
| 48 |
greg |
2.2 |
#ifndef F_OK /* mode bits for access(2) call */ |
| 49 |
|
|
#define R_OK 4 /* readable */ |
| 50 |
|
|
#define W_OK 2 /* writable */ |
| 51 |
|
|
#define X_OK 1 /* executable */ |
| 52 |
|
|
#define F_OK 0 /* exists */ |
| 53 |
gwlarson |
2.13 |
#endif |
| 54 |
|
|
|
| 55 |
|
|
#ifndef int2 |
| 56 |
|
|
#define int2 short /* two-byte integer */ |
| 57 |
|
|
#endif |
| 58 |
|
|
#ifndef int4 |
| 59 |
|
|
#define int4 int /* four-byte integer */ |
| 60 |
greg |
1.2 |
#endif |
| 61 |
gregl |
2.9 |
|
| 62 |
greg |
1.1 |
/* error codes */ |
| 63 |
gregl |
2.10 |
#define WARNING 0 /* non-fatal error */ |
| 64 |
|
|
#define USER 1 /* fatal user-caused error */ |
| 65 |
|
|
#define SYSTEM 2 /* fatal system-related error */ |
| 66 |
|
|
#define INTERNAL 3 /* fatal program-related error */ |
| 67 |
|
|
#define CONSISTENCY 4 /* bad consistency check, abort */ |
| 68 |
|
|
#define COMMAND 5 /* interactive error */ |
| 69 |
|
|
#define NERRS 6 |
| 70 |
gregl |
2.9 |
/* error struct */ |
| 71 |
|
|
extern struct erract { |
| 72 |
|
|
char pre[16]; /* prefix message */ |
| 73 |
greg |
2.16 |
void (*pf)(); /* put function (resettable) */ |
| 74 |
gregl |
2.9 |
int ec; /* exit code (0 means non-fatal) */ |
| 75 |
|
|
} erract[NERRS]; /* list of error actions */ |
| 76 |
|
|
|
| 77 |
|
|
#define ERRACT_INIT { {"warning - ", wputs, 0}, \ |
| 78 |
|
|
{"fatal - ", eputs, 1}, \ |
| 79 |
|
|
{"system - ", eputs, 2}, \ |
| 80 |
greg |
2.16 |
{"internal - ", eputs, 3}, \ |
| 81 |
gregl |
2.9 |
{"consistency - ", eputs, -1}, \ |
| 82 |
|
|
{"", NULL, 0} } |
| 83 |
greg |
1.1 |
|
| 84 |
|
|
extern char errmsg[]; /* global buffer for error messages */ |
| 85 |
|
|
|
| 86 |
gwlarson |
2.14 |
#ifdef FASTMATH |
| 87 |
|
|
#define tcos cos |
| 88 |
|
|
#define tsin sin |
| 89 |
|
|
#define ttan tan |
| 90 |
|
|
#else |
| 91 |
|
|
extern double tcos(); /* table-based cosine approximation */ |
| 92 |
|
|
#define tsin(x) tcos((x)-(PI/2.)) |
| 93 |
|
|
#define ttan(x) (tsin(x)/tcos(x)) |
| 94 |
|
|
#endif |
| 95 |
|
|
/* custom version of assert(3) */ |
| 96 |
greg |
2.21 |
#define CHECK(be,et,em) if (be) error(et,em); else |
| 97 |
gwlarson |
2.14 |
#ifdef DEBUG |
| 98 |
|
|
#define DCHECK CHECK |
| 99 |
|
|
#else |
| 100 |
greg |
2.20 |
#define DCHECK(be,et,em) (void)0 |
| 101 |
gwlarson |
2.14 |
#endif |
| 102 |
greg |
1.3 |
/* memory operations */ |
| 103 |
greg |
2.2 |
#ifdef NOSTRUCTASS |
| 104 |
greg |
2.22 |
#define copystruct(d,s) bcopy((void *)(s),(void *)(d),sizeof(*(d))) |
| 105 |
greg |
1.9 |
#else |
| 106 |
greg |
2.2 |
#define copystruct(d,s) (*(d) = *(s)) |
| 107 |
greg |
1.3 |
#endif |
| 108 |
greg |
1.6 |
|
| 109 |
greg |
2.16 |
#ifndef BSD |
| 110 |
greg |
2.2 |
#define bcopy(s,d,n) (void)memcpy(d,s,n) |
| 111 |
|
|
#define bzero(d,n) (void)memset(d,0,n) |
| 112 |
|
|
#define bcmp(b1,b2,n) memcmp(b1,b2,n) |
| 113 |
|
|
#define index strchr |
| 114 |
|
|
#define rindex strrchr |
| 115 |
greg |
2.16 |
#endif |
| 116 |
gwlarson |
2.12 |
extern off_t lseek(); |
| 117 |
greg |
2.5 |
|
| 118 |
greg |
2.2 |
#ifdef MSDOS |
| 119 |
|
|
#define NIX 1 |
| 120 |
|
|
#endif |
| 121 |
|
|
#ifdef AMIGA |
| 122 |
|
|
#define NIX 1 |
| 123 |
|
|
#endif |
| 124 |
|
|
|
| 125 |
greg |
2.16 |
|
| 126 |
|
|
/* defined in badarg.c */ |
| 127 |
|
|
extern int badarg(int ac, char **av, char *fl); |
| 128 |
|
|
/* defined in bmalloc.c */ |
| 129 |
|
|
extern char *bmalloc(unsigned int n); |
| 130 |
|
|
extern void bfree(char *p, unsigned int n); |
| 131 |
|
|
/* defined in error.c */ |
| 132 |
|
|
extern void error(int etype, char *emsg); |
| 133 |
|
|
/* defined in expandarg.c */ |
| 134 |
|
|
extern int expandarg(int *acp, char ***avp, int n); |
| 135 |
|
|
/* defined in fdate.c */ |
| 136 |
|
|
extern time_t fdate(char *fname); |
| 137 |
|
|
extern int setfdate(char *fname, long ftim); |
| 138 |
|
|
/* defined in fgetline.c */ |
| 139 |
|
|
extern char *fgetline(char *s, int n, FILE *fp); |
| 140 |
|
|
/* defined in fgetval.c */ |
| 141 |
|
|
extern int fgetval(FILE *fp, int ty, char *vp); |
| 142 |
|
|
/* defined in fgetword.c */ |
| 143 |
|
|
extern char *fgetword(char *s, int n, FILE *fp); |
| 144 |
|
|
/* defined in fputword.c */ |
| 145 |
|
|
extern void fputword(char *s, FILE *fp); |
| 146 |
|
|
/* defined in fixargv0.c */ |
| 147 |
|
|
extern char *fixargv0(char *av0); |
| 148 |
|
|
/* defined in fropen.c */ |
| 149 |
|
|
extern FILE *frlibopen(char *fname); |
| 150 |
|
|
/* defined in getlibpath.c */ |
| 151 |
greg |
2.22 |
extern char *getrlibpath(void); |
| 152 |
greg |
2.16 |
/* defined in getpath.c */ |
| 153 |
|
|
extern char *getpath(char *fname, char *searchpath, int mode); |
| 154 |
|
|
/* defined in portio.c */ |
| 155 |
|
|
extern void putstr(char *s, FILE *fp); |
| 156 |
|
|
extern void putint(long i, int siz, FILE *fp); |
| 157 |
|
|
extern void putflt(double f, FILE *fp); |
| 158 |
|
|
extern char *getstr(char *s, FILE *fp); |
| 159 |
|
|
extern long getint(int siz, FILE *fp); |
| 160 |
|
|
extern double getflt(FILE *fp); |
| 161 |
|
|
/* defined in process.c */ |
| 162 |
|
|
extern int open_process(int pd[3], char *av[]); |
| 163 |
|
|
extern int process(int pd[3], char *recvbuf, char *sendbuf, |
| 164 |
|
|
int nbr, int nbs); |
| 165 |
|
|
extern int close_process(int pd[3]); |
| 166 |
|
|
extern int readbuf(int fd, char *bpos, int siz); |
| 167 |
|
|
extern int writebuf(int fd, char *bpos, int siz); |
| 168 |
|
|
/* defined in rexpr.c */ |
| 169 |
|
|
extern int ecompile(char *sp, int iflg, int wflag); |
| 170 |
greg |
2.19 |
extern char *expsave(void); |
| 171 |
greg |
2.16 |
extern void expset(char *ep); |
| 172 |
|
|
extern char *eindex(char *sp); |
| 173 |
|
|
/* defined in savestr.c */ |
| 174 |
|
|
extern char *savestr(char *str); |
| 175 |
|
|
extern void freestr(char *s); |
| 176 |
|
|
extern int shash(char *s); |
| 177 |
|
|
/* defined in savqstr.c */ |
| 178 |
|
|
extern char *savqstr(char *s); |
| 179 |
|
|
extern void freeqstr(char *s); |
| 180 |
|
|
/* defined in tcos.c */ |
| 181 |
|
|
extern double tcos(double x); |
| 182 |
|
|
/* defined in wordfile.c */ |
| 183 |
|
|
extern int wordfile(char **words, char *fname); |
| 184 |
|
|
extern int wordstring(char **avl, char *str); |
| 185 |
|
|
/* defined in words.c */ |
| 186 |
|
|
extern char *atos(char *rs, int nb, char *s); |
| 187 |
|
|
extern char *nextword(char *cp, int nb, char *s); |
| 188 |
|
|
extern char *sskip(char *s); |
| 189 |
|
|
extern char *sskip2(char *s, int n); |
| 190 |
|
|
extern char *iskip(char *s); |
| 191 |
|
|
extern char *fskip(char *s); |
| 192 |
|
|
extern int isint(char *s); |
| 193 |
|
|
extern int isintd(char *s, char *ds); |
| 194 |
|
|
extern int isflt(char *s); |
| 195 |
|
|
extern int isfltd(char *s, char *ds); |
| 196 |
|
|
/* defined in xf.c */ |
| 197 |
|
|
extern int xf(XF *ret, int ac, char *av[]); |
| 198 |
|
|
extern int invxf(XF *ret, int ac, char *av[]); |
| 199 |
|
|
extern int fullxf(FULLXF *fx, int ac, char *av[]); |
| 200 |
|
|
/* defined in zeroes.c */ |
| 201 |
|
|
extern int quadtratic(double *r, double a, double b, double c); |
| 202 |
greg |
2.18 |
/* defined in dircode.c */ |
| 203 |
|
|
extern int4 encodedir(FVECT dv); |
| 204 |
|
|
extern void decodedir(FVECT dv, int4 dc); |
| 205 |
|
|
extern double dir2diff(int4 dc1, int4 dc2); |
| 206 |
|
|
extern double fdir2diff(int4 dc1, FVECT v2); |
| 207 |
greg |
2.16 |
/* miscellaneous */ |
| 208 |
|
|
extern void eputs(char *s); |
| 209 |
|
|
extern void wputs(char *s); |
| 210 |
|
|
extern void quit(int code); |
| 211 |
|
|
|
| 212 |
schorsch |
2.23 |
|
| 213 |
schorsch |
2.24 |
#ifdef __cplusplus |
| 214 |
|
|
} |
| 215 |
|
|
#endif |
| 216 |
schorsch |
2.23 |
#endif /* _RAD_STANDARD_H_ */ |
| 217 |
schorsch |
2.24 |
|