scat: make 64-bit safe

This commit is contained in:
Russ Cox 2009-04-30 11:35:25 -07:00
parent 122fda5913
commit 347aa646fc
6 changed files with 57 additions and 55 deletions

View file

@ -4,7 +4,7 @@
#include "sky.h" #include "sky.h"
static void dodecode(Biobuf*, Pix*, int, int, uchar*); static void dodecode(Biobuf*, Pix*, int, int, uchar*);
static long getlong(uchar*); static int32 getlong(uchar*);
int debug; int debug;
Img* Img*
@ -107,7 +107,7 @@ dodecode(Biobuf *infile, Pix *a, int nx, int ny, uchar *nbitplanes)
} }
static static
long getlong(uchar *p) int32 getlong(uchar *p)
{ {
return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]; return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
} }

View file

@ -35,7 +35,7 @@ radec(int p, int *rah, int *ram, int *deg)
(*deg)++; (*deg)++;
} }
long int32
patcha(Angle ra, Angle dec) patcha(Angle ra, Angle dec)
{ {
ra = DEG(ra); ra = DEG(ra);
@ -61,7 +61,7 @@ char round[91]={ /* extra 0 is to offset the array */
/* 90 */ /* 90 */
}; };
long int32
patch(int rah, int ram, int deg) patch(int rah, int ram, int deg)
{ {
int ra, dec; int ra, dec;

View file

@ -90,7 +90,7 @@ struct Header
float xi; float xi;
float eta; float eta;
}; };
typedef long Type; typedef int32 Type;
typedef struct Image Image; typedef struct Image Image;
struct Image struct Image

View file

@ -10,8 +10,8 @@
#include "sky.h" #include "sky.h"
/* convert to milliarcsec */ /* convert to milliarcsec */
static long c = MILLIARCSEC; /* 1 degree */ static int32 c = MILLIARCSEC; /* 1 degree */
static long m5 = 1250*60*60; /* 5 minutes of ra */ static int32 m5 = 1250*60*60; /* 5 minutes of ra */
DAngle ramin; DAngle ramin;
DAngle ramax; DAngle ramax;
@ -40,8 +40,8 @@ Image *cometcolor;
Planetrec *planet; Planetrec *planet;
long mapx0, mapy0; int32 mapx0, mapy0;
long mapra, mapdec; int32 mapra, mapdec;
double mylat, mylon, mysid; double mylat, mylon, mysid;
double mapscale; double mapscale;
double maps; double maps;
@ -235,7 +235,7 @@ heavens(double zlatdeg, double zlondeg, double clatdeg, double clondeg))(struct
} }
int int
maptoxy(long ra, long dec, double *x, double *y) maptoxy(int32 ra, int32 dec, double *x, double *y)
{ {
double lat, lon; double lat, lon;
struct place pl; struct place pl;
@ -255,7 +255,7 @@ maptoxy(long ra, long dec, double *x, double *y)
/* end of 'heavens' section */ /* end of 'heavens' section */
int int
setmap(long ramin, long ramax, long decmin, long decmax, Rectangle r, int zenithup) setmap(int32 ramin, int32 ramax, int32 decmin, int32 decmax, Rectangle r, int zenithup)
{ {
int c; int c;
double minx, maxx, miny, maxy; double minx, maxx, miny, maxy;
@ -298,7 +298,7 @@ setmap(long ramin, long ramax, long decmin, long decmax, Rectangle r, int zenith
} }
Point Point
map(long ra, long dec) map(int32 ra, int32 dec)
{ {
double x, y; double x, y;
Point p; Point p;
@ -456,7 +456,7 @@ tolast(char *name)
} }
int int
bbox(long extrara, long extradec, int quantize) bbox(int32 extrara, int32 extradec, int quantize)
{ {
int i; int i;
Record *r; Record *r;
@ -566,7 +566,7 @@ inbbox(DAngle ra, DAngle dec)
} }
int int
gridra(long mapdec) gridra(int32 mapdec)
{ {
mapdec = abs(mapdec)+c/2; mapdec = abs(mapdec)+c/2;
mapdec /= c; mapdec /= c;
@ -586,7 +586,7 @@ plot(char *flags)
{ {
int i, j, k; int i, j, k;
char *t; char *t;
long x, y; int32 x, y;
int ra, dec; int ra, dec;
int m; int m;
Point p, pts[10]; Point p, pts[10];

View file

@ -26,9 +26,9 @@ char ngctype[NNGCrec];
Mindexrec mindex[NMrec]; Mindexrec mindex[NMrec];
Namerec name[NName]; Namerec name[NName];
Bayerec bayer[NBayer]; Bayerec bayer[NBayer];
long con[MAXcon]; int32 con[MAXcon];
ushort conindex[Ncon+1]; ushort conindex[Ncon+1];
long patchaddr[Npatch+1]; int32 patchaddr[Npatch+1];
Record *rec; Record *rec;
Record *orec; Record *orec;
@ -46,10 +46,10 @@ int condb;
int conindexdb; int conindexdb;
int patchdb; int patchdb;
char parsed[3]; char parsed[3];
long nrec; int32 nrec;
long nreca; int32 nreca;
long norec; int32 norec;
long noreca; int32 noreca;
Biobuf bin; Biobuf bin;
Biobuf bout; Biobuf bout;
@ -132,7 +132,7 @@ eopen(char *s)
void void
Eread(int f, char *name, void *addr, long n) Eread(int f, char *name, void *addr, int32 n)
{ {
if(read(f, addr, n) != n){ /* BUG! */ if(read(f, addr, n) != n){ /* BUG! */
fprint(2, "scat: read error on %s\n", name); fprint(2, "scat: read error on %s\n", name);
@ -156,17 +156,17 @@ skipstr(char *s, char *t)
return skipbl(s); return skipbl(s);
} }
/* produce little-endian long at address l */ /* produce little-endian int32 at address l */
long int32
Long(long *l) Long(int32 *l)
{ {
uchar *p; uchar *p;
p = (uchar*)l; p = (uchar*)l;
return (long)p[0]|((long)p[1]<<8)|((long)p[2]<<16)|((long)p[3]<<24); return (int32)p[0]|((int32)p[1]<<8)|((int32)p[2]<<16)|((int32)p[3]<<24);
} }
/* produce little-endian long at address l */ /* produce little-endian int32 at address l */
int int
Short(short *s) Short(short *s)
{ {
@ -254,7 +254,7 @@ void
patchopen(void) patchopen(void)
{ {
Biobuf *b; Biobuf *b;
long l, m; int32 l, m;
char buf[100]; char buf[100];
if(patchdb == 0){ if(patchdb == 0){
@ -309,10 +309,10 @@ lowercase(char *s)
} }
int int
loadngc(long index) loadngc(int32 index)
{ {
static int failed; static int failed;
long j; int32 j;
ngcopen(); ngcopen();
j = (index-1)*sizeof(NGCrec); j = (index-1)*sizeof(NGCrec);
@ -343,9 +343,9 @@ loadngc(long index)
} }
int int
loadabell(long index) loadabell(int32 index)
{ {
long j; int32 j;
abellopen(); abellopen();
j = index-1; j = index-1;
@ -408,7 +408,7 @@ loadplanet(int index, Record *r)
} }
int int
loadpatch(long index) loadpatch(int32 index)
{ {
int i; int i;
@ -446,7 +446,7 @@ flatten(void)
{ {
int i, j, notflat; int i, j, notflat;
Record *or; Record *or;
long key; int32 key;
loop: loop:
copy(); copy();
@ -759,7 +759,7 @@ coords(int deg)
int i; int i;
int x, y; int x, y;
Record *or; Record *or;
long dec, ra, ndec, nra; int32 dec, ra, ndec, nra;
int rdeg; int rdeg;
flatten(); flatten();
@ -807,7 +807,7 @@ coords(int deg)
int i; int i;
int x, y, xx; int x, y, xx;
Record *or; Record *or;
long min, circle; int32 min, circle;
double factor; double factor;
flatten(); flatten();
@ -853,11 +853,11 @@ void
pplate(char *flags) pplate(char *flags)
{ {
int i; int i;
long c; int32 c;
int na, rah, ram, d1, d2; int na, rah, ram, d1, d2;
double r0; double r0;
int ra, dec; int ra, dec;
long ramin, ramax, decmin, decmax; /* all in degrees */ int32 ramin, ramax, decmin, decmax; /* all in degrees */
Record *r; Record *r;
int folded; int folded;
Angle racenter, deccenter, rasize, decsize, a[4]; Angle racenter, deccenter, rasize, decsize, a[4];
@ -1006,7 +1006,7 @@ lookup(char *s, int doreset)
char *starts, *inputline=s, *t, *u; char *starts, *inputline=s, *t, *u;
Record *r; Record *r;
Rune c; Rune c;
long n; int32 n;
double x; double x;
Angle ra; Angle ra;
@ -1526,7 +1526,7 @@ prrec(Record *r)
Abellrec *a; Abellrec *a;
Planetrec *p; Planetrec *p;
int i, rah, ram, dec, nn; int i, rah, ram, dec, nn;
long key; int32 key;
if(r) switch(r->type){ if(r) switch(r->type){
default: default:

View file

@ -1,3 +1,5 @@
typedef s32int int32;
#define DIR "#9/sky" #define DIR "#9/sky"
/* /*
* This code reflects many years of changes. There remain residues * This code reflects many years of changes. There remain residues
@ -135,9 +137,9 @@ enum
#define NPlanet 20 #define NPlanet 20
typedef float Angle; /* in radians */ typedef float Angle; /* in radians */
typedef long DAngle; /* on disk: in units of milliarcsec */ typedef int32 DAngle; /* on disk: in units of milliarcsec */
typedef short Mag; /* multiplied by 10 */ typedef short Mag; /* multiplied by 10 */
typedef long Key; /* known to be 4 bytes, unfortunately */ typedef int32 Key; /* known to be 4 bytes, unfortunately */
/* /*
* All integers are stored in little-endian order. * All integers are stored in little-endian order.
@ -203,7 +205,7 @@ struct SAOrec{
char compid[2]; char compid[2];
char hdcode; char hdcode;
char pad1; char pad1;
long hd; /* HD catalog number */ int32 hd; /* HD catalog number */
char name[3]; /* name[0]=alpha name[1]=2 name[3]=ori */ char name[3]; /* name[0]=alpha name[1]=2 name[3]=ori */
char nname; /* number of prose names */ char nname; /* number of prose names */
/* 36 bytes to here */ /* 36 bytes to here */
@ -218,7 +220,7 @@ struct Mindexrec{ /* code knows the bit patterns in here; this is a long */
typedef struct Bayerec Bayerec; typedef struct Bayerec Bayerec;
struct Bayerec{ struct Bayerec{
long sao; int32 sao;
char name[3]; char name[3];
char pad; char pad;
}; };
@ -234,22 +236,22 @@ struct Namedrec{
typedef struct Namerec Namerec; typedef struct Namerec Namerec;
struct Namerec{ struct Namerec{
long sao; int32 sao;
long ngc; int32 ngc;
long abell; int32 abell;
char name[36]; /* null terminated */ char name[36]; /* null terminated */
}; };
typedef struct Patchrec Patchrec; typedef struct Patchrec Patchrec;
struct Patchrec{ struct Patchrec{
int nkey; int nkey;
long key[60]; int32 key[60];
}; };
typedef struct Record Record; typedef struct Record Record;
struct Record{ struct Record{
Type type; Type type;
long index; int32 index;
union{ union{
SAOrec sao; SAOrec sao;
NGCrec ngc; NGCrec ngc;
@ -287,7 +289,7 @@ struct Header
float xi; float xi;
float eta; float eta;
}; };
typedef long Pix; typedef int32 Pix;
typedef struct Img Img; typedef struct Img Img;
struct Img struct Img
@ -340,7 +342,7 @@ extern char *progname;
extern char *desctab[][2]; extern char *desctab[][2];
extern Name names[]; extern Name names[];
extern Record *rec; extern Record *rec;
extern long nrec; extern int32 nrec;
extern Planetrec *planet; extern Planetrec *planet;
/* for bbox: */ /* for bbox: */
extern int folded; extern int folded;
@ -365,8 +367,8 @@ extern int equal(char*, char*);
extern int parsename(char*); extern int parsename(char*);
extern void radec(int, int*, int*, int*); extern void radec(int, int*, int*, int*);
extern int btag(short); extern int btag(short);
extern long patcha(Angle, Angle); extern int32 patcha(Angle, Angle);
extern long patch(int, int, int); extern int32 patch(int, int, int);
extern char*hms(Angle); extern char*hms(Angle);
extern char*dms(Angle); extern char*dms(Angle);
extern char*ms(Angle); extern char*ms(Angle);
@ -374,7 +376,7 @@ extern char*hm(Angle);
extern char*dm(Angle); extern char*dm(Angle);
extern char*deg(Angle); extern char*deg(Angle);
extern char*hm5(Angle); extern char*hm5(Angle);
extern long dangle(Angle); extern int32 dangle(Angle);
extern Angle angle(DAngle); extern Angle angle(DAngle);
extern void prdesc(char*, char*(*)[2], short*); extern void prdesc(char*, char*(*)[2], short*);
extern double xsqrt(double); extern double xsqrt(double);
@ -406,7 +408,7 @@ extern void astro(char*, int);
extern char* alpha(char*, char*); extern char* alpha(char*, char*);
extern char* skipbl(char*); extern char* skipbl(char*);
extern void flatten(void); extern void flatten(void);
extern int bbox(long, long, int); extern int bbox(int32, int32, int);
extern int inbbox(DAngle, DAngle); extern int inbbox(DAngle, DAngle);
extern char* nameof(Record*); extern char* nameof(Record*);