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