[PATCH] swap

From: Strake <strake888_AT_gmail.com>
Date: Tue, 30 Apr 2013 23:53:04 -0500

---
 st.c | 38 ++++++++++----------------------------
 1 file changed, 10 insertions(+), 28 deletions(-)
diff --git a/st.c b/st.c
index 5251e70..8cf3483 100644
--- a/st.c
+++ b/st.c
_AT_@ -72,6 +72,7 @@ char *argv0;
 #define DEFAULT(a, b)     (a) = (a) ? (a) : (b)
 #define BETWEEN(x, a, b)  ((a) <= (x) && (x) <= (b))
 #define LIMIT(x, a, b)    (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
+#define SWAP(t, x, y)     { t __SWAP_TEMPORARY; __SWAP_TEMPORARY =
(x); (x) = (y); (y) = __SWAP_TEMPORARY; }
 #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg ||
(a).bg != (b).bg)
 #define IS_SET(flag) ((term.mode & (flag)) != 0)
 #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 +
(t1.tv_usec-t2.tv_usec)/1000)
_AT_@ -1358,10 +1359,7 @@ tnew(int col, int row) {
 void
 tswapscreen(void) {
-	Line *tmp = term.line;
-
-	term.line = term.alt;
-	term.alt = tmp;
+	SWAP(Line *, term.line, term.alt);
 	term.mode ^= MODE_ALTSCREEN;
 	tfulldirt();
 }
_AT_@ -1369,16 +1367,13 @@ tswapscreen(void) {
 void
 tscrolldown(int orig, int n) {
 	int i;
-	Line temp;
 	LIMIT(n, 0, term.bot-orig+1);
 	tclearregion(0, term.bot-n+1, term.col-1, term.bot);
 	for(i = term.bot; i >= orig+n; i--) {
-		temp = term.line[i];
-		term.line[i] = term.line[i-n];
-		term.line[i-n] = temp;
+		SWAP(Line, term.line[i], term.line[i-n]);
 		term.dirty[i] = 1;
 		term.dirty[i-n] = 1;
_AT_@ -1390,15 +1385,12 @@ tscrolldown(int orig, int n) {
 void
 tscrollup(int orig, int n) {
 	int i;
-	Line temp;
 	LIMIT(n, 0, term.bot-orig+1);
 	tclearregion(0, orig, term.col-1, orig+n-1);
 	for(i = orig; i <= term.bot-n; i++) {
-		 temp = term.line[i];
-		 term.line[i] = term.line[i+n];
-		 term.line[i+n] = temp;
+		 SWAP(Line, term.line[i], term.line[i+n]);
 		 term.dirty[i] = 1;
 		 term.dirty[i+n] = 1;
_AT_@ -1531,12 +1523,12 @@ tsetchar(char *c, Glyph *attr, int x, int y) {
 void
 tclearregion(int x1, int y1, int x2, int y2) {
-	int x, y, temp;
+	int x, y;
 	if(x1 > x2)
-		temp = x1, x1 = x2, x2 = temp;
+		SWAP(int, x1, x2);
 	if(y1 > y2)
-		temp = y1, y1 = y2, y2 = temp;
+		SWAP(int, y1, y2);
 	LIMIT(x1, 0, term.col-1);
 	LIMIT(x2, 0, term.col-1);
_AT_@ -1711,15 +1703,9 @@ tsetattr(int *attr, int l) {
 void
 tsetscroll(int t, int b) {
-	int temp;
-
 	LIMIT(t, 0, term.row-1);
 	LIMIT(b, 0, term.row-1);
-	if(t > b) {
-		temp = t;
-		t = b;
-		b = temp;
-	}
+	if(t > b) SWAP(int, b, t);
 	term.top = t;
 	term.bot = b;
 }
_AT_@ -2886,7 +2872,7 @@ xdraws(char *s, Glyph base, int x, int y, int
charlen, int bytelen) {
 	FcPattern *fcpattern, *fontpattern;
 	FcFontSet *fcsets[] = { NULL };
 	FcCharSet *fccharset;
-	Colour *fg, *bg, *temp, revfg, revbg;
+	Colour *fg, *bg, revfg, revbg;
 	XRenderColor colfg, colbg;
 	Rectangle r;
_AT_@ -2954,11 +2940,7 @@ xdraws(char *s, Glyph base, int x, int y, int
charlen, int bytelen) {
 		}
 	}
-	if(base.mode & ATTR_REVERSE) {
-		temp = fg;
-		fg = bg;
-		bg = temp;
-	}
+	if(base.mode & ATTR_REVERSE) SWAP(Colour *, fg, bg);
 	if(base.mode & ATTR_BLINK && term.mode & MODE_BLINK)
 		fg = bg;
-- 
1.7.11.1
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Sun May 05 2013 - 16:24:03 CEST