[PATCH 2/5] Un-boolify codebase and refactor config.def.h

From: FRIGN <dev_AT_frign.de>
Date: Mon, 22 Dec 2014 14:31:33 +0100

Continue the work done in sbase/ubase and other suckless projects.

Also, there's no need for vim-indent-comments or spelling errors.
Instead, increase readability with some alignments.
---
 config.def.h | 26 ++++++++++++--------------
 dmenu.c      | 27 +++++++++++++--------------
 draw.c       | 10 +++++-----
 draw.h       |  4 ++--
 stest.c      |  9 ++++-----
 5 files changed, 36 insertions(+), 40 deletions(-)
diff --git a/config.def.h b/config.def.h
index c2a23fa..79e55ef 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -1,17 +1,15 @@
 /* See LICENSE file for copyright and license details. */
-/* vim: expandtab
- */
-/* Default settings; can be overrided by command line. */
+/* Default settings; can be overridden by command line arguments. */
 
-static Bool topbar = True;                  /* -b  option; if False, dmenu appears at bottom */
-static const char *font = NULL;             /* -fn option; default X11 font or font set      */
-static const char *prompt = NULL;           /* -p  option; prompt to the elft of input field */
-static const char *normbgcolor = "#222222"; /* -nb option; normal background                 */
-static const char *normfgcolor = "#bbbbbb"; /* -nf option; normal foreground                 */
-static const char *selbgcolor  = "#005577"; /* -sb option; selected background               */
-static const char *selfgcolor  = "#eeeeee"; /* -sf option; selected foreground               */
-static const char *outbgcolor  = "#00ffff";
-static const char *outfgcolor  = "#000000";
-/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
-static unsigned int lines = 0;
+static int          topbar       = 1;          /* -b  option; if 0, dmenu appears at bottom     */
+static const char   *font        = NULL;       /* -fn option; default X11 font or font set      */
+static const char   *prompt      = NULL;       /* -p  option; prompt to the elft of input field */
+static const char   *normbgcolor = "#222222";  /* -nb option; normal background                 */
+static const char   *normfgcolor = "#bbbbbb";  /* -nf option; normal foreground                 */
+static const char   *selbgcolor  = "#005577";  /* -sb option; selected background               */
+static const char   *selfgcolor  = "#eeeeee";  /* -sf option; selected foreground               */
+static const char   *outbgcolor  = "#00ffff";
+static const char   *outfgcolor  = "#000000";
 
+/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
+static unsigned int lines        = 0;
diff --git a/dmenu.c b/dmenu.c
index 2d0a513..c723c06 100644
--- a/dmenu.c
+++ b/dmenu.c
_AT_@ -23,7 +23,7 @@ typedef struct Item Item;
 struct Item {
 	char *text;
 	Item *left, *right;
-	Bool out;
+	int out;
 };
 
 static long estrtol(const char *s, int base);
_AT_@ -88,8 +88,7 @@ estrtol(const char *s, int base)
 
 int
 main(int argc, char *argv[]) {
-	Bool fast = False;
-	int i;
+	int fast = 0, i;
 
 	for(i = 1; i < argc; i++)
 		/* these options take no arguments */
_AT_@ -98,9 +97,9 @@ main(int argc, char *argv[]) {
 			exit(EXIT_SUCCESS);
 		}
 		else if(!strcmp(argv[i], "-b"))   /* appears at the bottom of the screen */
-			topbar = False;
+			topbar = 0;
 		else if(!strcmp(argv[i], "-f"))   /* grabs keyboard before reading stdin */
-			fast = True;
+			fast = 1;
 		else if(!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
 			fstrncmp = strncasecmp;
 			fstrstr = cistrstr;
_AT_@ -191,7 +190,7 @@ drawmenu(void) {
 	dc->x = 0;
 	dc->y = 0;
 	dc->h = bh;
-	drawrect(dc, 0, 0, mw, mh, True, BG(dc, normcol));
+	drawrect(dc, 0, 0, mw, mh, 1, BG(dc, normcol));
 
 	if(prompt && *prompt) {
 		dc->w = promptw;
_AT_@ -202,7 +201,7 @@ drawmenu(void) {
 	dc->w = (lines > 0 || !matches) ? mw - dc->x : inputw;
 	drawtext(dc, text, normcol);
 	if((curpos = textnw(dc, text, cursor) + dc->h/2 - 2) < dc->w)
-		drawrect(dc, curpos, 2, 1, dc->h - 4, True, FG(dc, normcol));
+		drawrect(dc, curpos, 2, 1, dc->h - 4, 1, FG(dc, normcol));
 
 	if(lines > 0) {
 		/* draw vertical list */
_AT_@ -239,7 +238,7 @@ grabkeyboard(void) {
 
 	/* try to grab keyboard, we may have to wait for another process to ungrab */
 	for(i = 0; i < 1000; i++) {
-		if(XGrabKeyboard(dc->dpy, DefaultRootWindow(dc->dpy), True,
+		if(XGrabKeyboard(dc->dpy, DefaultRootWindow(dc->dpy), 1,
 		                 GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess)
 			return;
 		usleep(1000);
_AT_@ -396,7 +395,7 @@ keypress(XKeyEvent *ev) {
 		if(!(ev->state & ControlMask))
 			exit(EXIT_SUCCESS);
 		if(sel)
-			sel->out = True;
+			sel->out = 1;
 		break;
 	case XK_Right:
 		if(text[cursor] != '\0') {
_AT_@ -495,7 +494,7 @@ paste(void) {
 	Atom da;
 
 	/* we have been given the current selection, now insert it into input */
-	XGetWindowProperty(dc->dpy, win, utf8, 0, (sizeof text / 4) + 1, False,
+	XGetWindowProperty(dc->dpy, win, utf8, 0, (sizeof text / 4) + 1, 0,
 	                   utf8, &da, &di, &dl, &dl, (unsigned char **)&p);
 	insert(p, (q = strchr(p, '\n')) ? q-p : (ssize_t)strlen(p));
 	XFree(p);
_AT_@ -516,7 +515,7 @@ readstdin(void) {
 			*p = '\0';
 		if(!(items[i].text = strdup(buf)))
 			eprintf("cannot strdup %u bytes:", strlen(buf)+1);
-		items[i].out = False;
+		items[i].out = 0;
 		if(strlen(items[i].text) > max)
 			max = strlen(maxstr = items[i].text);
 	}
_AT_@ -571,8 +570,8 @@ setup(void) {
 	outcol[ColBG]  = getcolor(dc, outbgcolor);
 	outcol[ColFG]  = getcolor(dc, outfgcolor);
 
-	clip = XInternAtom(dc->dpy, "CLIPBOARD",   False);
-	utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);
+	clip = XInternAtom(dc->dpy, "CLIPBOARD",   0);
+	utf8 = XInternAtom(dc->dpy, "UTF8_STRING", 0);
 
 	/* calculate menu geometry */
 	bh = dc->font.height + 2;
_AT_@ -625,7 +624,7 @@ setup(void) {
 	match();
 
 	/* create menu window */
-	swa.override_redirect = True;
+	swa.override_redirect = 1;
 	swa.background_pixel = normcol[ColBG];
 	swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
 	win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0,
diff --git a/draw.c b/draw.c
index 76f0c54..ad770f6 100644
--- a/draw.c
+++ b/draw.c
_AT_@ -11,10 +11,10 @@
 #define MIN(a, b)  ((a) < (b) ? (a) : (b))
 #define DEFAULTFN  "fixed"
 
-static Bool loadfont(DC *dc, const char *fontstr);
+static int loadfont(DC *dc, const char *fontstr);
 
 void
-drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color) {
+drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, int fill, unsigned long color) {
 	XSetForeground(dc->dpy, dc->gc, color);
 	if(fill)
 		XFillRectangle(dc->dpy, dc->canvas, dc->gc, dc->x + x, dc->y + y, w, h);
_AT_@ -35,7 +35,7 @@ drawtext(DC *dc, const char *text, unsigned long col[ColLast]) {
 	if(mn < n)
 		for(n = MAX(mn-3, 0); n < mn; buf[n++] = '.');
 
-	drawrect(dc, 0, 0, dc->w, dc->h, True, BG(dc, col));
+	drawrect(dc, 0, 0, dc->w, dc->h, 1, BG(dc, col));
 	drawtextn(dc, buf, mn, col);
 }
 
_AT_@ -118,14 +118,14 @@ initfont(DC *dc, const char *fontstr) {
 	dc->font.height = dc->font.ascent + dc->font.descent;
 }
 
-Bool
+int
 loadfont(DC *dc, const char *fontstr) {
 	char *def, **missing, **names;
 	int i, n;
 	XFontStruct **xfonts;
 
 	if(!*fontstr)
-		return False;
+		return 0;
 	if((dc->font.set = XCreateFontSet(dc->dpy, fontstr, &missing, &n, &def))) {
 		n = XFontsOfFontSet(dc->font.set, &xfonts, &names);
 		for(i = 0; i < n; i++) {
diff --git a/draw.h b/draw.h
index 43a57bf..a6ef9de 100644
--- a/draw.h
+++ b/draw.h
_AT_@ -7,7 +7,7 @@ enum { ColBG, ColFG, ColBorder, ColLast };
 
 typedef struct {
 	int x, y, w, h;
-	Bool invert;
+	int invert;
 	Display *dpy;
 	GC gc;
 	Pixmap canvas;
_AT_@ -21,7 +21,7 @@ typedef struct {
 	} font;
 } DC;  /* draw context */
 
-void drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color);
+void drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, int fill, unsigned long color);
 void drawtext(DC *dc, const char *text, unsigned long col[ColLast]);
 void drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]);
 void eprintf(const char *fmt, ...);
diff --git a/stest.c b/stest.c
index 8fac42a..886d418 100644
--- a/stest.c
+++ b/stest.c
_AT_@ -1,6 +1,5 @@
 /* See LICENSE file for copyright and license details. */
 #include <dirent.h>
-#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
_AT_@ -11,8 +10,8 @@
 
 static void test(const char *, const char *);
 
-static bool match = false;
-static bool flag[26];
+static int match = 0;
+static int flag[26];
 static struct stat old, new;
 
 int
_AT_@ -30,7 +29,7 @@ main(int argc, char *argv[]) {
 				perror(optarg);
 			break;
 		default:  /* miscellaneous operators */
-			FLAG(opt) = true;
+			FLAG(opt) = 1;
 			break;
 		case '?': /* error: unknown flag */
 			fprintf(stderr, "usage: %s [-abcdefghlpqrsuvwx] [-n file] [-o file] [file...]\n", argv[0]);
_AT_@ -78,7 +77,7 @@ test(const char *path, const char *name) {
 	&& (!FLAG('x') || access(path, X_OK) == 0)) != FLAG('v')) {   /* executable        */
 		if(FLAG('q'))
 			exit(0);
-		match = true;
+		match = 1;
 		puts(name);
 	}
 }
-- 
1.8.5.5
--Multipart=_Mon__22_Dec_2014_18_40_59_+0100_ph7wbDS_mXmI_UXb
Content-Type: text/x-diff;
 name="0003-Add-monitor-number-as-configurable-option.patch"
Content-Disposition: attachment;
 filename="0003-Add-monitor-number-as-configurable-option.patch"
Content-Transfer-Encoding: 7bit
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Mon Dec 22 2014 - 19:00:04 CET