code: 9ferno

Download patch

ref: 4ee2765c5a3ab2087cbdba63f117b7e1f591bf12
parent: e8c5c6689fe0924c2a285910fa2cf6af02302023
author: joe9 <joe9mail@gmail.com>
date: Sat Jul 3 00:31:32 EDT 2021

replace SHORT macros with 16INT macros

--- a/include/draw.h
+++ b/include/draw.h
@@ -147,14 +147,14 @@
 	Ncomp	= 12,
 } Drawop;
 
-extern	char*	chantostr(char*, ulong);
-extern	ulong	strtochan(char*);
-extern	int		chantodepth(ulong);
+extern	char*	chantostr(char*, u32int);
+extern	u32int	strtochan(char*);
+extern	int		chantodepth(u32int);
 
 struct	Point
 {
-	int	x;
-	int	y;
+	s32int	x;
+	s32int	y;
 };
 
 struct Rectangle
@@ -168,7 +168,7 @@
 struct Screen
 {
 	Display	*display;	/* display holding data */
-	int	id;		/* id of system-held Screen */
+	s32int	id;		/* id of system-held Screen */
 	Image	*image;		/* unused; for reference only */
 	Image	*fill;		/* color to paint behind windows */
 };
@@ -184,20 +184,20 @@
 struct Display
 {
 	void*	qlock;
-	int		locking;	/*program is using lockdisplay */
-	int		dirno;
+	s32int		locking;	/*program is using lockdisplay */
+	s32int		dirno;
 	void	*datachan;
 	void	*refchan;
 	void	*ctlchan;
-	int		imageid;
-	int		local;
-	int		depth;
-	ulong	chan;
+	s32int		imageid;
+	s32int		local;
+	s32int		depth;
+	u32int	chan;
 	void		(*error)(Display*, char*);
 	char		*devdir;
 	char		*windir;
 	char		oldlabel[64];
-	ulong		dataqid;
+	u32int		dataqid;
 	Image		*white;
 	Image		*black;
 	Image		*image;
@@ -204,7 +204,7 @@
 	Image		*opaque;
 	Image		*transparent;
 	uchar		buf[Displaybufsize+1];	/* +1 for flush message */
-	int			bufsize;
+	s32int			bufsize;
 	uchar		*bufp;
 	Font		*defaultfont;
 	Subfont		*defaultsubfont;
@@ -217,12 +217,12 @@
 struct Image
 {
 	Display		*display;	/* display holding data */
-	int		id;		/* id of system-held Image */
+	s32int		id;		/* id of system-held Image */
 	Rectangle	r;		/* rectangle in data area, local coords */
 	Rectangle 	clipr;		/* clipping region */
-	int		depth;		/* number of bits per pixel */
-	ulong	chan;
-	int		repl;		/* flag: data replicates to tile clipr */
+	s32int		depth;		/* number of bits per pixel */
+	u32int	chan;
+	s32int		repl;		/* flag: data replicates to tile clipr */
 	Screen		*screen;	/* 0 if not a window */
 	Image		*next;	/* next in list of windows */
 	Reffn		reffn;
@@ -231,15 +231,15 @@
 
 struct RGB
 {
-	ulong	red;
-	ulong	green;
-	ulong	blue;
+	u32int	red;
+	u32int	green;
+	u32int	blue;
 };
 
 /*
  * Subfonts
  *
- * given char c, Subfont *f, Fontchar *i, and Point p, one says
+ * given char c, Subfont *f, Fontchar *i, and Pos32int p, one says
  *	i = f->info+c;
  *	draw(b, Rect(p.x+i->left, p.y+i->top,
  *		p.x+i->left+((i+1)->x-i->x), p.y+i->bottom),
@@ -250,7 +250,7 @@
 
 struct	Fontchar
 {
-	int		x;		/* left edge of bits */
+	s32int		x;		/* left edge of bits */
 	uchar		top;		/* first non-zero scan-line */
 	uchar		bottom;		/* last non-zero scan-line + 1 */
 	char		left;		/* offset of baseline */
@@ -260,12 +260,12 @@
 struct	Subfont
 {
 	char		*name;
-	short		n;		/* number of chars in font */
+	s16int		n;		/* number of chars in font */
 	uchar		height;		/* height of image */
 	char		ascent;		/* top of image to baseline */
 	Fontchar 	*info;		/* n+1 character descriptors */
 	Image		*bits;		/* of font */
-	int		ref;
+	s32int		ref;
 };
 
 enum
@@ -289,7 +289,7 @@
 {
 	Rune		min;	/* lowest rune value to be taken from subfont */
 	Rune		max;	/* highest rune value+1 to be taken from subfont */
-	int		offset;	/* position in subfont of character at min */
+	s32int		offset;	/* position in subfont of character at min */
 	char		*name;			/* stored in font */
 	char		*subfontname;		/* to access subfont */
 };
@@ -296,16 +296,16 @@
 
 struct Cacheinfo
 {
-	ushort		x;		/* left edge of bits */
+	u16int		x;		/* left edge of bits */
 	uchar		width;		/* width of baseline */
 	schar		left;		/* offset of baseline */
 	Rune		value;	/* value of character at this slot in cache */
-	ushort		age;
+	u16int		age;
 };
 
 struct Cachesubf
 {
-	ulong		age;	/* for replacement */
+	u32int		age;	/* for replacement */
 	Cachefont	*cf;	/* font info that owns us */
 	Subfont		*f;	/* attached subfont */
 };
@@ -314,14 +314,14 @@
 {
 	char		*name;
 	Display		*display;
-	short		height;	/* max height of image, interline spacing */
-	short		ascent;	/* top of image to baseline */
-	short		width;	/* widest so far; used in caching only */	
-	short		nsub;	/* number of subfonts */
-	ulong		age;	/* increasing counter; used for LRU */
-	int		maxdepth;	/* maximum depth of all loaded subfonts */
-	int		ncache;	/* size of cache */
-	int		nsubf;	/* size of subfont list */
+	s16int		height;	/* max height of image, interline spacing */
+	s16int		ascent;	/* top of image to baseline */
+	s16int		width;	/* widest so far; used in caching only */	
+	s16int		nsub;	/* number of subfonts */
+	u32int		age;	/* increasing counter; used for LRU */
+	s32int		maxdepth;	/* maximum depth of all loaded subfonts */
+	s32int		ncache;	/* size of cache */
+	s32int		nsubf;	/* size of subfont list */
 	Cacheinfo	*cache;
 	Cachesubf	*subf;
 	Cachefont	**sub;	/* as read from file */
@@ -334,8 +334,8 @@
 /*
  * Image management
  */
-extern Image*	_allocimage(Image*, Display*, Rectangle, ulong, int, ulong, int, int);
-extern Image*	allocimage(Display*, Rectangle, ulong, int, ulong);
+extern Image*	_allocimage(Image*, Display*, Rectangle, u32int, int, u32int, int, int);
+extern Image*	allocimage(Display*, Rectangle, u32int, int, u32int);
 extern uchar*	bufimage(Display*, int);
 extern int	bytesperline(Rectangle, int);
 extern void	closedisplay(Display*);
@@ -358,7 +358,7 @@
 extern int	writeimage(int, Image*, int);
 extern Image*	namedimage(Display*, char*);
 extern int	nameimage(Image*, char*, int);
-extern Image* allocimagemix(Display*, ulong, ulong);
+extern Image* allocimagemix(Display*, u32int, u32int);
 
 /*
  * Colors
@@ -365,18 +365,18 @@
  */
 extern	void	readcolmap(Display*, RGB*);
 extern	void	writecolmap(Display*, RGB*);
-extern	ulong	setalpha(ulong, uchar);
+extern	u32int	setalpha(u32int, uchar);
 
 /*
  * Windows
  */
 extern Screen*	allocscreen(Image*, Image*, int);
-extern Image*	_allocwindow(Image*, Screen*, Rectangle, int, ulong);
-extern Image*	allocwindow(Screen*, Rectangle, int, ulong);
+extern Image*	_allocwindow(Image*, Screen*, Rectangle, int, u32int);
+extern Image*	allocwindow(Screen*, Rectangle, int, u32int);
 extern void	bottomnwindows(Image**, int);
 extern void	bottomwindow(Image*);
 extern int	freescreen(Screen*);
-extern Screen*	publicscreen(Display*, int, ulong);
+extern Screen*	publicscreen(Display*, int, u32int);
 extern void	topnwindows(Image**, int);
 extern void	topwindow(Image*);
 extern int	originwindow(Image*, Point, Point);
@@ -384,8 +384,8 @@
 /*
  * Geometry
  */
-extern Point		Pt(int, int);
-extern Rectangle	Rect(int, int, int, int);
+extern Point		Pt(s32int, s32int);
+extern Rectangle	Rect(s32int, s32int, s32int, s32int);
 extern Rectangle	Rpt(Point, Point);
 extern Point		addpt(Point, Point);
 extern Point		subpt(Point, Point);
@@ -408,8 +408,8 @@
 extern int		rgb2cmap(int, int, int);
 extern int		cmap2rgb(int);
 extern int		cmap2rgba(int);
-extern void		icossin(int, int*, int*);
-extern void		icossin2(int, int, int*, int*);
+extern void		icossin(int, s32int*, s32int*);
+extern void		icossin2(s32int, s32int, s32int*, s32int*);
 
 /*
  * Graphics
@@ -512,10 +512,10 @@
 extern	int	_cursorfd;
 extern	int	_drawdebug;	/* set to 1 to see errors from flushimage */
 
-#define	BGSHORT(p)		(((p)[0]<<0) | ((p)[1]<<8))
-#define	BGLONG(p)		((BGSHORT(p)<<0) | (BGSHORT(p+2)<<16))
-#define	BPSHORT(p, v)		((p)[0]=(v), (p)[1]=((v)>>8))
-#define	BPLONG(p, v)		(BPSHORT(p, (v)), BPSHORT(p+2, (v)>>16))
+#define	BG16INT(p)		(((p)[0]<<0) | ((p)[1]<<8))
+#define	BG32INT(p)		((s32int)((BG16INT(p)<<0) | (BG16INT(p+2)<<16)))
+#define	BP16INT(p, v)		((p)[0]=(v), (p)[1]=((v)>>8))
+#define	BP32INT(p, v)		(BP16INT(p, ((s32int)v)), BP16INT(p+2, ((s32int)v)>>16))
 
 /*
  * Compressed image file parameters
@@ -529,7 +529,7 @@
 extern	int	_compblocksize(Rectangle, int);
 
 /* XXX backwards helps; should go */
-extern	ulong	drawld2chan[];
+extern	u32int	drawld2chan[];
 extern	void		drawsetdebug(int);
 
 /*
@@ -541,10 +541,16 @@
 /*
  * Macros to convert between C and Limbo types
  */
+/*
 #define	IRECT(r)	(*(Rectangle*)&(r))
 #define	DRECT(r)	(*(Draw_Rect*)&(r))
 #define	IPOINT(p)	(*(Point*)&(p))
 #define	DPOINT(p)	(*(Draw_Point*)&(p))
+*/
+#define	IRECT(r)	((Rectangle){IPOINT((r).min),IPOINT((r).max)})
+#define	DRECT(r)	((Draw_Rect){DPOINT((r).min),DPOINT((r).max)})
+#define	IPOINT(p)	((Point){(s32int)((p).x),(s32int)((p).y)})
+#define	DPOINT(p)	((Draw_Point){(p).x,(p).y})
 
 #define P2P(p1, p2)	(p1).x = (p2).x, (p1).y = (p2).y
 #define R2R(r1, r2)	(r1).min.x = (r2).min.x, (r1).min.y = (r2).min.y,\
--- a/libdraw/font.c
+++ b/libdraw/font.c
@@ -301,15 +301,15 @@
 	if(b == 0)
 		return 0;
 	b[0] = 'l';
-	BPLONG(b+1, f->cacheimage->id);
-	BPLONG(b+5, subf->f->bits->id);
-	BPSHORT(b+9, c-f->cache);
-	BPLONG(b+11, c->x);
-	BPLONG(b+15, top);
-	BPLONG(b+19, c->x+((fi+1)->x-fi->x));
-	BPLONG(b+23, bottom);
-	BPLONG(b+27, fi->x);
-	BPLONG(b+31, fi->top);
+	BP32INT(b+1, f->cacheimage->id);
+	BP32INT(b+5, subf->f->bits->id);
+	BP16INT(b+9, c-f->cache);
+	BP32INT(b+11, c->x);
+	BP32INT(b+15, top);
+	BP32INT(b+19, c->x+((fi+1)->x-fi->x));
+	BP32INT(b+23, bottom);
+	BP32INT(b+27, fi->x);
+	BP32INT(b+31, fi->top);
 	b[35] = fi->left;
 	b[36] = fi->width;
 	return 1;
@@ -369,8 +369,8 @@
 		goto Return;
 	}
 	b[0] = 'i';
-	BPLONG(b+1, new->id);
-	BPLONG(b+5, ncache);
+	BP32INT(b+1, new->id);
+	BP32INT(b+5, ncache);
 	b[9] = f->ascent;
 	if(flushimage(d, 0) < 0){
 		_drawprint(2, "resize: init failed: %r\n");
--- a/libdraw/poly.c
+++ b/libdraw/poly.c
@@ -49,14 +49,14 @@
 		return;
 	}
 	a[0] = cmd;
-	BPLONG(a+1, dst->id);
-	BPSHORT(a+5, np-1);
-	BPLONG(a+7, end0);
-	BPLONG(a+11, end1);
-	BPLONG(a+15, radius);
-	BPLONG(a+19, src->id);
-	BPLONG(a+23, sp->x);
-	BPLONG(a+27, sp->y);
+	BP32INT(a+1, dst->id);
+	BP16INT(a+5, np-1);
+	BP32INT(a+7, end0);
+	BP32INT(a+11, end1);
+	BP32INT(a+15, radius);
+	BP32INT(a+19, src->id);
+	BP32INT(a+23, sp->x);
+	BP32INT(a+27, sp->y);
 	memmove(a+31, t, u-t);
 	free(t);
 }
--- a/libdraw/string.c
+++ b/libdraw/string.c
@@ -95,28 +95,28 @@
 				b[0] = 'x';
 			else
 				b[0] = 's';
-			BPLONG(b+1, dst->id);
-			BPLONG(b+5, src->id);
-			BPLONG(b+9, f->cacheimage->id);
-			BPLONG(b+13, pt.x);
-			BPLONG(b+17, pt.y+f->ascent);
-			BPLONG(b+21, clipr.min.x);
-			BPLONG(b+25, clipr.min.y);
-			BPLONG(b+29, clipr.max.x);
-			BPLONG(b+33, clipr.max.y);
-			BPLONG(b+37, sp.x);
-			BPLONG(b+41, sp.y);
-			BPSHORT(b+45, n);
+			BP32INT(b+1, dst->id);
+			BP32INT(b+5, src->id);
+			BP32INT(b+9, f->cacheimage->id);
+			BP32INT(b+13, pt.x);
+			BP32INT(b+17, pt.y+f->ascent);
+			BP32INT(b+21, clipr.min.x);
+			BP32INT(b+25, clipr.min.y);
+			BP32INT(b+29, clipr.max.x);
+			BP32INT(b+33, clipr.max.y);
+			BP32INT(b+37, sp.x);
+			BP32INT(b+41, sp.y);
+			BP16INT(b+45, n);
 			b += 47;
 			if(bg){
-				BPLONG(b, bg->id);
-				BPLONG(b+4, bgp.x);
-				BPLONG(b+8, bgp.y);
+				BP32INT(b, bg->id);
+				BP32INT(b+4, bgp.x);
+				BP32INT(b+8, bgp.y);
 				b += 12;
 			}
 			ec = &cbuf[n];
 			for(c=cbuf; c<ec; c++, b+=2)
-				BPSHORT(b, *c);
+				BP16INT(b, *c);
 			pt.x += wid;
 			bgp.x += wid;
 			agefont(f);
--- a/libdraw/window.c
+++ b/libdraw/window.c
@@ -32,9 +32,9 @@
 		}
 		id = ++screenid;
 		a[0] = 'A';
-		BPLONG(a+1, id);
-		BPLONG(a+5, image->id);
-		BPLONG(a+9, fill->id);
+		BP32INT(a+1, id);
+		BP32INT(a+5, image->id);
+		BP32INT(a+9, fill->id);
 		a[13] = public;
 		if(flushimage(d, 0) != -1)
 			break;
@@ -49,7 +49,7 @@
 }
 
 Screen*
-publicscreen(Display *d, int id, ulong chan)
+publicscreen(Display *d, int id, u32int chan)
 {
 	uchar *a;
 	Screen *s;
@@ -64,8 +64,8 @@
 		return 0;
 	}
 	a[0] = 'S';
-	BPLONG(a+1, id);
-	BPLONG(a+5, chan);
+	BP32INT(a+1, id);
+	BP32INT(a+5, chan);
 	if(flushimage(d, 0) < 0)
 		goto Error;
 
@@ -89,7 +89,7 @@
 	if(a == 0)
 		return -1;
 	a[0] = 'F';
-	BPLONG(a+1, s->id);
+	BP32INT(a+1, s->id);
 	/*
 	 * flush(1) because screen is likely holding last reference to
 	 * window, and want it to disappear visually.
@@ -101,13 +101,13 @@
 }
 
 Image*
-allocwindow(Screen *s, Rectangle r, int ref, ulong val)
+allocwindow(Screen *s, Rectangle r, int ref, u32int val)
 {
 	return _allocwindow(nil, s, r, ref, val);
 }
 
 Image*
-_allocwindow(Image *i, Screen *s, Rectangle r, int ref, ulong val)
+_allocwindow(Image *i, Screen *s, Rectangle r, int ref, u32int val)
 {
 	Display *d;
 
@@ -149,9 +149,9 @@
 	}
 	b[0] = 't';
 	b[1] = top;
-	BPSHORT(b+2, n);
+	BP16INT(b+2, n);
 	for(i=0; i<n; i++)
-		BPLONG(b+4+4*i, w[i]->id);
+		BP32INT(b+4+4*i, w[i]->id);
 }
 
 void
@@ -189,11 +189,11 @@
 	if(b == nil)
 		return 0;
 	b[0] = 'o';
-	BPLONG(b+1, w->id);
-	BPLONG(b+5, log.x);
-	BPLONG(b+9, log.y);
-	BPLONG(b+13, scr.x);
-	BPLONG(b+17, scr.y);
+	BP32INT(b+1, w->id);
+	BP32INT(b+5, log.x);
+	BP32INT(b+9, log.y);
+	BP32INT(b+13, scr.x);
+	BP32INT(b+17, scr.y);
 	if(flushimage(w->display, 1) < 0)
 		return -1;
 	delta = subpt(log, w->r.min);