see attached.

--Markus

>From 5b75bf7bc8dc082bd317195d132c789c6baf8779 Mon Sep 17 00:00:00 2001
From: Markus Teich <markus.te...@stusta.mhn.de>
Date: Sat, 22 Jun 2013 23:05:03 +0200
Subject: [PATCH 1/4] fix: do not need an extra variable for a single read

---
 st.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/st.c b/st.c
index 2811876..a5d6c87 100644
--- a/st.c
+++ b/st.c
@@ -3380,7 +3380,6 @@ numlock(const Arg *dummy) {
 
 char*
 kmap(KeySym k, uint state) {
-	uint mask;
 	Key *kp;
 	int i;
 
@@ -3395,12 +3394,10 @@ kmap(KeySym k, uint state) {
 	}
 
 	for(kp = key; kp < key + LEN(key); kp++) {
-		mask = kp->mask;
-
 		if(kp->k != k)
 			continue;
 
-		if(!match(mask, state))
+		if(!match(kp->mask, state))
 			continue;
 
 		if(kp->appkey > 0) {
-- 
1.8.2


>From c242cdb6f0289a88d2f4090678fc389952f2f850 Mon Sep 17 00:00:00 2001
From: Markus Teich <markus.te...@stusta.mhn.de>
Date: Sat, 22 Jun 2013 23:06:34 +0200
Subject: [PATCH 2/4] fix: compress logic expression in function match

---
 st.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/st.c b/st.c
index a5d6c87..2e45502 100644
--- a/st.c
+++ b/st.c
@@ -3364,13 +3364,9 @@ inline bool
 match(uint mask, uint state) {
 	state &= ~(ignoremod);
 
-	if(mask == XK_NO_MOD && state)
-		return false;
-	if(mask != XK_ANY_MOD && mask != XK_NO_MOD && !state)
-		return false;
-	if((state & mask) != state)
-		return false;
-	return true;
+	return (mask != XK_NO_MOD || !state)
+		&& (mask == XK_ANY_MOD || mask == XK_NO_MOD || state)
+		&& ((state & mask) == state);
 }
 
 void
-- 
1.8.2


>From 08d6311f945fb12fed99e2136dfec145e2134c96 Mon Sep 17 00:00:00 2001
From: Markus Teich <markus.te...@stusta.mhn.de>
Date: Sat, 22 Jun 2013 23:06:49 +0200
Subject: [PATCH 3/4] fix: consistent usage of bitmask operations on unicode
 functions

---
 st.c | 50 +++++++++++++++++++++++---------------------------
 1 file changed, 23 insertions(+), 27 deletions(-)

diff --git a/st.c b/st.c
index 2e45502..d4aa9a4 100644
--- a/st.c
+++ b/st.c
@@ -150,10 +150,6 @@ enum selection_snap {
 	SNAP_LINE = 2
 };
 
-/* bit macro */
-#undef B0
-enum { B0=1, B1=2, B2=4, B3=8, B4=16, B5=32, B6=64, B7=128 };
-
 typedef unsigned char uchar;
 typedef unsigned int uint;
 typedef unsigned long ulong;
@@ -527,17 +523,17 @@ utf8decode(char *s, long *u) {
 
 	rtn = 1;
 	c = *s;
-	if(~c & B7) { /* 0xxxxxxx */
+	if(~c & 0x80) { /* 0xxxxxxx */
 		*u = c;
 		return rtn;
-	} else if((c & (B7|B6|B5)) == (B7|B6)) { /* 110xxxxx */
-		*u = c&(B4|B3|B2|B1|B0);
+	} else if((c & 0xE0) == 0xC0) { /* 110xxxxx */
+		*u = c & 0x1F;
 		n = 1;
-	} else if((c & (B7|B6|B5|B4)) == (B7|B6|B5)) { /* 1110xxxx */
-		*u = c&(B3|B2|B1|B0);
+	} else if((c & 0xF0) == 0xE0) { /* 1110xxxx */
+		*u = c & 0x0F;
 		n = 2;
-	} else if((c & (B7|B6|B5|B4|B3)) == (B7|B6|B5|B4)) { /* 11110xxx */
-		*u = c & (B2|B1|B0);
+	} else if((c & 0xF8) == 0xF0) { /* 11110xxx */
+		*u = c & 0x07;
 		n = 3;
 	} else {
 		goto invalid;
@@ -545,10 +541,10 @@ utf8decode(char *s, long *u) {
 
 	for(i = n, ++s; i > 0; --i, ++rtn, ++s) {
 		c = *s;
-		if((c & (B7|B6)) != B7) /* 10xxxxxx */
+		if((c & 0xC0) != 0x80) /* 10xxxxxx */
 			goto invalid;
 		*u <<= 6;
-		*u |= c & (B5|B4|B3|B2|B1|B0);
+		*u |= c & 0x3F;
 	}
 
 	if((n == 1 && *u < 0x80) ||
@@ -577,20 +573,20 @@ utf8encode(long *u, char *s) {
 		*sp = uc; /* 0xxxxxxx */
 		return 1;
 	} else if(*u < 0x800) {
-		*sp = (uc >> 6) | (B7|B6); /* 110xxxxx */
+		*sp = (uc >> 6) | 0xC0; /* 110xxxxx */
 		n = 1;
 	} else if(uc < 0x10000) {
-		*sp = (uc >> 12) | (B7|B6|B5); /* 1110xxxx */
+		*sp = (uc >> 12) | 0xE0; /* 1110xxxx */
 		n = 2;
 	} else if(uc <= 0x10FFFF) {
-		*sp = (uc >> 18) | (B7|B6|B5|B4); /* 11110xxx */
+		*sp = (uc >> 18) | 0xF0; /* 11110xxx */
 		n = 3;
 	} else {
 		goto invalid;
 	}
 
 	for(i=n,++sp; i>0; --i,++sp)
-		*sp = ((uc >> 6*(i-1)) & (B5|B4|B3|B2|B1|B0)) | B7; /* 10xxxxxx */
+		*sp = ((uc >> 6*(i-1)) & 0x3F) | 0x80; /* 10xxxxxx */
 
 	return n+1;
 invalid:
@@ -613,16 +609,16 @@ isfullutf8(char *s, int b) {
 	c3 = (uchar *)++s;
 	if(b < 1) {
 		return 0;
-	} else if((*c1&(B7|B6|B5)) == (B7|B6) && b == 1) {
+	} else if((*c1 & 0xE0) == 0xC0 && b == 1) {
 		return 0;
-	} else if((*c1&(B7|B6|B5|B4)) == (B7|B6|B5) &&
+	} else if((*c1 & 0xF0) == 0xE0 &&
 	    ((b == 1) ||
-	    ((b == 2) && (*c2&(B7|B6)) == B7))) {
+	    ((b == 2) && (*c2 & 0xC0) == 0x80))) {
 		return 0;
-	} else if((*c1&(B7|B6|B5|B4|B3)) == (B7|B6|B5|B4) &&
+	} else if((*c1 & 0xF8) == 0xF0 &&
 	    ((b == 1) ||
-	    ((b == 2) && (*c2&(B7|B6)) == B7) ||
-	    ((b == 3) && (*c2&(B7|B6)) == B7 && (*c3&(B7|B6)) == B7))) {
+	    ((b == 2) && (*c2 & 0xC0) == 0x80) ||
+	    ((b == 3) && (*c2 & 0xC0) == 0x80 && (*c3 & 0xC0) == 0x80))) {
 		return 0;
 	} else {
 		return 1;
@@ -633,11 +629,11 @@ int
 utf8size(char *s) {
 	uchar c = *s;
 
-	if(~c&B7) {
+	if(~c & 0x80) {
 		return 1;
-	} else if((c&(B7|B6|B5)) == (B7|B6)) {
+	} else if((c & 0xE0) == 0xC0) {
 		return 2;
-	} else if((c&(B7|B6|B5|B4)) == (B7|B6|B5)) {
+	} else if((c & 0xF0) == 0xE0) {
 		return 3;
 	} else {
 		return 4;
@@ -3457,7 +3453,7 @@ kpress(XEvent *ev) {
 		if(len == 1 && e->state & Mod1Mask) {
 			if(IS_SET(MODE_8BIT)) {
 				if(*xstr < 0177) {
-					c = *xstr | B7;
+					c = *xstr | 0x80;
 					ret = utf8encode(&c, cp);
 					cp += ret;
 					len = 0;
-- 
1.8.2


>From a6554571b9aae89abb2870b80b8455fd30f5d6ca Mon Sep 17 00:00:00 2001
From: Markus Teich <markus.te...@stusta.mhn.de>
Date: Sat, 22 Jun 2013 23:07:00 +0200
Subject: [PATCH 4/4] fix: whitespace

---
 config.def.h |  22 +++++-----
 st.c         | 129 ++++++++++++++++++++++++++++++-----------------------------
 2 files changed, 76 insertions(+), 75 deletions(-)

diff --git a/config.def.h b/config.def.h
index 2de9a0a..e85f180 100644
--- a/config.def.h
+++ b/config.def.h
@@ -87,21 +87,21 @@ static unsigned int defaultunderline = 7;
 /* Internal mouse shortcuts. */
 /* Beware that overloading Button1 will disable the selection. */
 static Mousekey mshortcuts[] = {
-	/* keysym		mask		string */
-	{ Button4,		XK_ANY_MOD,	"\031"},
-	{ Button5,		XK_ANY_MOD,	"\005"},
+	/* keysym  mask        string */
+	{ Button4, XK_ANY_MOD, "\031"},
+	{ Button5, XK_ANY_MOD, "\005"},
 };
 
 /* Internal keyboard shortcuts. */
 #define MODKEY Mod1Mask
 
 static Shortcut shortcuts[] = {
-	/* modifier		key		function	argument */
-	{ MODKEY|ShiftMask,	XK_Prior,	xzoom,		{.i = +1} },
-	{ MODKEY|ShiftMask,	XK_Next,	xzoom,		{.i = -1} },
-	{ ShiftMask,		XK_Insert,	selpaste,	{.i =  0} },
-	{ MODKEY|ShiftMask,	XK_Insert,	clippaste,	{.i =  0} },
-	{ MODKEY,		XK_Num_Lock,	numlock,	{.i =  0} },
+	/* modifier         key          function   argument */
+	{ MODKEY|ShiftMask, XK_Prior,    xzoom,     {.i = +1} },
+	{ MODKEY|ShiftMask, XK_Next,     xzoom,     {.i = -1} },
+	{ ShiftMask,        XK_Insert,   selpaste,  {.i =  0} },
+	{ MODKEY|ShiftMask, XK_Insert,   clippaste, {.i =  0} },
+	{ MODKEY,           XK_Num_Lock, numlock,   {.i =  0} },
 };
 
 /*
@@ -160,7 +160,7 @@ static Key key[] = {
 	{ XK_KP_Right,      XK_ANY_MOD,     "\033[C",        0,   -1,    0},
 	{ XK_KP_Right,      XK_ANY_MOD,     "\033OC",        0,   +1,    0},
 	{ XK_KP_Prior,      ShiftMask,      "\033[5;2~",     0,    0,    0},
-	{ XK_KP_Prior,      XK_ANY_MOD,     "\033[5~",	     0,    0,    0},
+	{ XK_KP_Prior,      XK_ANY_MOD,     "\033[5~",       0,    0,    0},
 	{ XK_KP_Begin,      XK_ANY_MOD,     "\033[E",        0,    0,    0},
 	{ XK_KP_End,        ControlMask,    "\033[J",       -1,    0,    0},
 	{ XK_KP_End,        ControlMask,    "\033[1;5F",    +1,    0,    0},
@@ -213,7 +213,7 @@ static Key key[] = {
 	{ XK_Left,          ShiftMask,      "\033[1;2D",     0,    0,    0},
 	{ XK_Left,          ControlMask,    "\033[1;5D",     0,    0,    0},
 	{ XK_Left,          Mod1Mask,       "\033[1;3D",     0,    0,    0},
-	{ XK_Left,	    XK_ANY_MOD,     "\033[D",        0,   -1,    0},
+	{ XK_Left,          XK_ANY_MOD,     "\033[D",        0,   -1,    0},
 	{ XK_Left,          XK_ANY_MOD,     "\033OD",        0,   +1,    0},
 	{ XK_Right,         ShiftMask,      "\033[1;2C",     0,    0,    0},
 	{ XK_Right,         ControlMask,    "\033[1;5C",     0,    0,    0},
diff --git a/st.c b/st.c
index d4aa9a4..798cab5 100644
--- a/st.c
+++ b/st.c
@@ -98,37 +98,37 @@ enum cursor_movement {
 enum cursor_state {
 	CURSOR_DEFAULT  = 0,
 	CURSOR_WRAPNEXT = 1,
-	CURSOR_ORIGIN	= 2
+	CURSOR_ORIGIN   = 2
 };
 
 enum term_mode {
-	MODE_WRAP	 = 1,
+	MODE_WRAP        = 1,
 	MODE_INSERT      = 2,
 	MODE_APPKEYPAD   = 4,
 	MODE_ALTSCREEN   = 8,
-	MODE_CRLF	 = 16,
+	MODE_CRLF        = 16,
 	MODE_MOUSEBTN    = 32,
 	MODE_MOUSEMOTION = 64,
 	MODE_REVERSE     = 128,
 	MODE_KBDLOCK     = 256,
-	MODE_HIDE	 = 512,
-	MODE_ECHO	 = 1024,
-	MODE_APPCURSOR	 = 2048,
+	MODE_HIDE        = 512,
+	MODE_ECHO        = 1024,
+	MODE_APPCURSOR   = 2048,
 	MODE_MOUSESGR    = 4096,
-	MODE_8BIT	 = 8192,
-	MODE_BLINK	 = 16384,
-	MODE_FBLINK	 = 32768,
-	MODE_FOCUS	 = 65536,
-	MODE_MOUSEX10	 = 131072,
+	MODE_8BIT        = 8192,
+	MODE_BLINK       = 16384,
+	MODE_FBLINK      = 32768,
+	MODE_FOCUS       = 65536,
+	MODE_MOUSEX10    = 131072,
 	MODE_MOUSEMANY   = 262144,
 	MODE_MOUSE       = MODE_MOUSEBTN|MODE_MOUSEMOTION|MODE_MOUSEX10\
-			   |MODE_MOUSEMANY,
+	                  |MODE_MOUSEMANY,
 };
 
 enum escape_state {
 	ESC_START      = 1,
-	ESC_CSI	= 2,
-	ESC_STR	= 4, /* DSC, OSC, PM, APC */
+	ESC_CSI        = 2,
+	ESC_STR        = 4,  /* DSC, OSC, PM, APC */
 	ESC_ALTCHARSET = 8,
 	ESC_STR_END    = 16, /* a final string was encountered */
 	ESC_TEST       = 32, /* Enter in test mode */
@@ -156,16 +156,16 @@ typedef unsigned long ulong;
 typedef unsigned short ushort;
 
 typedef struct {
-	char c[UTF_SIZ];     /* character code */
-	uchar mode;  /* attribute flags */
-	ushort fg;   /* foreground  */
-	ushort bg;   /* background  */
+	char c[UTF_SIZ]; /* character code */
+	uchar mode;      /* attribute flags */
+	ushort fg;       /* foreground  */
+	ushort bg;       /* background  */
 } Glyph;
 
 typedef Glyph *Line;
 
 typedef struct {
-	Glyph attr;	 /* current char attributes */
+	Glyph attr; /* current char attributes */
 	int x;
 	int y;
 	char state;
@@ -175,36 +175,36 @@ typedef struct {
 /* ESC '[' [[ [<priv>] <arg> [;]] <mode>] */
 typedef struct {
 	char buf[ESC_BUF_SIZ]; /* raw string */
-	int len;	       /* raw string length */
+	int len;               /* raw string length */
 	char priv;
 	int arg[ESC_ARG_SIZ];
-	int narg;	       /* nb of args */
+	int narg;              /* nb of args */
 	char mode;
 } CSIEscape;
 
 /* STR Escape sequence structs */
 /* ESC type [[ [<priv>] <arg> [;]] <mode>] ESC '\' */
 typedef struct {
-	char type;	     /* ESC type ... */
+	char type;             /* ESC type ... */
 	char buf[STR_BUF_SIZ]; /* raw string */
-	int len;	       /* raw string length */
+	int len;               /* raw string length */
 	char *args[STR_ARG_SIZ];
-	int narg;	      /* nb of args */
+	int narg;              /* nb of args */
 } STREscape;
 
 /* Internal representation of the screen */
 typedef struct {
-	int row;	/* nb row */
-	int col;	/* nb col */
-	Line *line;	/* screen */
-	Line *alt;	/* alternate screen */
-	bool *dirty;	/* dirtyness of lines */
-	TCursor c;	/* cursor */
-	int top;	/* top    scroll limit */
-	int bot;	/* bottom scroll limit */
-	int mode;	/* terminal mode flags */
-	int esc;	/* escape state flags */
-	bool numlock;	/* lock numbers in keyboard */
+	int row;      /* nb row */
+	int col;      /* nb col */
+	Line *line;   /* screen */
+	Line *alt;    /* alternate screen */
+	bool *dirty;  /* dirtyness of lines */
+	TCursor c;    /* cursor */
+	int top;      /* top    scroll limit */
+	int bot;      /* bottom scroll limit */
+	int mode;     /* terminal mode flags */
+	int esc;      /* escape state flags */
+	bool numlock; /* lock numbers in keyboard */
 	bool *tabs;
 } Term;
 
@@ -241,9 +241,9 @@ typedef struct {
 	uint mask;
 	char s[ESC_BUF_SIZ];
 	/* three valued logic variables: 0 indifferent, 1 on, -1 off */
-	signed char appkey;		/* application keypad */
-	signed char appcursor;		/* application cursor */
-	signed char crlf;		/* crlf mode          */
+	signed char appkey;    /* application keypad */
+	signed char appcursor; /* application cursor */
+	signed char crlf;      /* crlf mode          */
 } Key;
 
 typedef struct {
@@ -1075,7 +1075,7 @@ selrequest(XEvent *e) {
 	}
 
 	/* all done, send a notification to the listener */
-	if(!XSendEvent(xsre->display, xsre->requestor, True, 0, (XEvent *) &xev))
+	if(!XSendEvent(xsre->display, xsre->requestor, True, 0, (XEvent*) &xev))
 		fprintf(stderr, "Error sending SelectionNotify event\n");
 }
 
@@ -1187,7 +1187,7 @@ sigchld(int a) {
 	int stat = 0;
 
 	if(waitpid(pid, &stat, 0) < 0)
-		die("Waiting for pid %hd failed: %s\n",	pid, SERRNO);
+		die("Waiting for pid %hd failed: %s\n", pid, SERRNO);
 
 	if(WIFEXITED(stat)) {
 		exit(WEXITSTATUS(stat));
@@ -1435,7 +1435,8 @@ selscroll(int orig, int n) {
 	if(sel.ob.x == -1)
 		return;
 
-	if(BETWEEN(sel.ob.y, orig, term.bot) || BETWEEN(sel.oe.y, orig, term.bot)) {
+	if(BETWEEN(sel.ob.y, orig, term.bot)
+	|| BETWEEN(sel.oe.y, orig, term.bot)) {
 		if((sel.ob.y += n) > term.bot || (sel.oe.y += n) < term.top) {
 			sel.ob.x = -1;
 			return;
@@ -1826,7 +1827,7 @@ tsetmode(bool priv, bool set, int *args, int narg) {
 					tclearregion(0, 0, term.col-1,
 							term.row-1);
 				}
-				if(set ^ alt)		/* set is always 1 or 0 */
+				if(set ^ alt) /* set is always 1 or 0 */
 					tswapscreen();
 				if(*args != 1049)
 					break;
@@ -2189,10 +2190,10 @@ techo(char *buf, int len) {
 	for(; len > 0; buf++, len--) {
 		char c = *buf;
 
-		if(c == '\033') {		/* escape */
+		if(c == '\033') { /* escape */
 			tputc("^", 1);
 			tputc("[", 1);
-		} else if(c < '\x20') {	/* control code */
+		} else if(c < '\x20') { /* control code */
 			if(c != '\n' && c != '\r' && c != '\t') {
 				c |= '\x40';
 				tputc("^", 1);
@@ -2263,31 +2264,31 @@ tputc(char *c, int len) {
 	 */
 	if(control) {
 		switch(ascii) {
-		case '\t':	/* HT */
+		case '\t':   /* HT */
 			tputtab(1);
 			return;
-		case '\b':	/* BS */
+		case '\b':   /* BS */
 			tmoveto(term.c.x-1, term.c.y);
 			return;
-		case '\r':	/* CR */
+		case '\r':   /* CR */
 			tmoveto(0, term.c.y);
 			return;
-		case '\f':	/* LF */
-		case '\v':	/* VT */
-		case '\n':	/* LF */
+		case '\f':   /* LF */
+		case '\v':   /* VT */
+		case '\n':   /* LF */
 			/* go to first col if the mode is set */
 			tnewline(IS_SET(MODE_CRLF));
 			return;
-		case '\a':	/* BEL */
+		case '\a':   /* BEL */
 			if(!(xw.state & WIN_FOCUSED))
 				xseturgency(1);
 			return;
-		case '\033':	/* ESC */
+		case '\033': /* ESC */
 			csireset();
 			term.esc = ESC_START;
 			return;
-		case '\016':	/* SO */
-		case '\017':	/* SI */
+		case '\016': /* SO */
+		case '\017': /* SI */
 			/*
 			 * Different charsets are hard to handle. Applications
 			 * should use the right alt charset escapes for the
@@ -2295,15 +2296,15 @@ tputc(char *c, int len) {
 			 * rest is incompatible history st should not support.
 			 */
 			return;
-		case '\032':	/* SUB */
-		case '\030':	/* CAN */
+		case '\032': /* SUB */
+		case '\030': /* CAN */
 			csireset();
 			return;
-		case '\005':	/* ENQ (IGNORED) */
-		case '\000':	/* NUL (IGNORED) */
-		case '\021':	/* XON (IGNORED) */
-		case '\023':	/* XOFF (IGNORED) */
-		case 0177:	/* DEL (IGNORED) */
+		case '\005': /* ENQ (IGNORED) */
+		case '\000': /* NUL (IGNORED) */
+		case '\021': /* XON (IGNORED) */
+		case '\023': /* XOFF (IGNORED) */
+		case 0177:   /* DEL (IGNORED) */
 			return;
 		}
 	} else if(term.esc & ESC_START) {
@@ -2968,9 +2969,9 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
 		}
 		/*
 		 * Those ranges will not be brightened:
-		 *	8 - 15 – bright system colors
-		 *	196 - 231 – highest 256 color cube
-		 *	252 - 255 – brightest colors in greyscale
+		 *    8 - 15 – bright system colors
+		 *    196 - 231 – highest 256 color cube
+		 *    252 - 255 – brightest colors in greyscale
 		 */
 		font = &dc.bfont;
 		frcflags = FRC_BOLD;
-- 
1.8.2


Reply via email to