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