shithub: puzzles

Download patch

ref: 798f949ca017f3a99b5d0ac90c4506bfcdcd4c48
parent: 0cfaa8fbd77ea39a6752e5df66dc6559a52585e4
author: sirjofri <sirjofri@sirjofri.de>
date: Mon May 27 09:14:03 EDT 2024

code cleanup

--- a/plan9.c
+++ b/plan9.c
@@ -111,7 +111,6 @@
 findfont(frontend *fe, int type, int size)
 {
 	Ft *n;
-	char buf[128];
 	for (int i = 0; i < fe->nfonts; i++) {
 		if (fe->fonts[i].type == type && fe->fonts[i].size == size)
 			return fe->fonts[i].font;
@@ -170,7 +169,8 @@
 }
 
 #ifdef DEBUGGING
-void debug_printf(const char *fmt, ...)
+void
+debug_printf(const char *fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
@@ -182,11 +182,12 @@
 void
 usage(void)
 {
-	fprint(2, "usage: %s [-ho] [--options]\n", argv0);
+	fprint(2, "usage: %s [-hl]\n", argv0);
 	exits(nil);
 }
 
-static void p9_draw_text(void *handle, int x, int y, int fonttype, int fontsize, int align, int color, const char *text)
+static void
+p9_draw_text(void *handle, int x, int y, int fonttype, int fontsize, int align, int color, const char *text)
 {
 	Font *f;
 	Point p, size;
@@ -282,7 +283,7 @@
 static void
 p9_unclip(void *handle)
 {
-	frontend *fe = (frontend*)handle;
+	USED(handle);
 	screen->clipr = screen->r;
 }
 
@@ -301,7 +302,7 @@
 static void
 p9_end_draw(void *handle)
 {
-	frontend *fe = (frontend*)handle;
+	USED(handle);
 	flushimage(display, 1);
 	LOG("end_draw");
 #ifdef PROFILE
@@ -338,15 +339,15 @@
 static void
 p9_blitter_save(void *handle, blitter *bl, int x, int y)
 {
-	frontend *fe = (frontend*)handle;
-	draw(bl->blimg, Rect(x, y, x + bl->blimg->r.max.x, y + bl->blimg->r.max.y), screen, nil, Pt(x, y)); // fix position
+	USED(handle);
+	draw(bl->blimg, Rect(x, y, x + bl->blimg->r.max.x, y + bl->blimg->r.max.y), screen, nil, Pt(x, y));
 }
 
 static void
 p9_blitter_load(void *handle, blitter *bl, int x, int y)
 {
-	frontend *fe = (frontend*)handle;
-	draw(screen, Rect(x, y, x + bl->blimg->r.max.x, y + bl->blimg->r.max.y), bl->blimg, nil, Pt(x, y)); // fix position
+	USED(handle);
+	draw(screen, Rect(x, y, x + bl->blimg->r.max.x, y + bl->blimg->r.max.y), bl->blimg, nil, Pt(x, y));
 }
 
 static const drawing_api p9_drawing = {
@@ -374,7 +375,8 @@
 #endif
 };
 
-static int rgb2col(int r, int g, int b)
+static int
+rgb2col(int r, int g, int b)
 {
 	return (r<<24) | (g<<16) | (b<<8) | 0xFF;
 }
@@ -396,7 +398,7 @@
 void
 initui(Controlset *cs, Channel *c)
 {
-	Control *b_game, *b_settings, *c_settings;
+	Control *b_game, *b_settings;
 	Point p;
 	
 	createrow(cs, "rowmain");
@@ -415,7 +417,7 @@
 	chanprint(cs->ctl, "b_settings align center");
 	chanprint(cs->ctl, "b_settings text settings");
 	chanprint(cs->ctl, "b_settings size %d %d 500 %d", p.x, p.y, p.y);
-	c_settings = createcolumn(cs, "c_settings");
+	createcolumn(cs, "c_settings");
 	chanprint(cs->ctl, "c_settings hide");
 	controlwire(b_settings, "event", c);
 	
@@ -493,7 +495,6 @@
 {
 	Rectangle rmenu, rarea, sarea;
 	int resizenop;
-	Control *ctl;
 	Point newsize;
 	Point offset;
 	
@@ -530,7 +531,7 @@
 		flushimage(display, 1);
 		break;
 	case SETTINGS:
-		chanprint(cs->ctl, "c_settings rect %R\nc_settings reveal\nc_settings show", fe->rect);
+		chanprint(cs->ctl, "c_settings rect %R\nc_settings reveal\nc_settings show", rarea);
 		break;
 	}
 	
@@ -537,86 +538,6 @@
 	LOG("resizecontrolset");
 }
 
-void
-printoptions(config_item *c)
-{
-	char *t;
-	char *s = nil, *cnames[16], *ckws[16];
-	int n = 0, m;
-	config_item *cfg = midend_get_config(fe->me, CFG_PREFS, &t);
-	
-	print("Options:\n");
-	while (cfg->type != C_END) {
-		switch (cfg->type) {
-		case C_STRING:
-			s = cfg->u.string.sval;
-			break;
-		case C_BOOLEAN:
-			s = cfg->u.boolean.bval ? "1" : "0";
-			break;
-		case C_CHOICES:
-			print("      Choices:\n");
-			n = getfields(cfg->u.choices.choicenames, cnames, 16, 1, ":");
-			m = getfields(cfg->u.choices.choicekws, ckws, 16, 1, ":");
-			assert(n == m && cfg->u.choices.selected < n);
-			s = ckws[cfg->u.choices.selected];
-			break;
-		}
-		print("--%s=%s\n      %s\n", cfg->kw, s, cfg->name);
-		if (cfg->type == C_CHOICES) {
-			print("      Choices:\n");
-			for (int i = 0; i < n; i++) {
-				print("      %s: %s\n", ckws[i], cnames[i]);
-			}
-		}
-		cfg++;
-	}
-}
-
-void
-parseoption(config_item *cfg, char *keyval)
-{
-	char *arg[2];
-	int n;
-	
-	n = getfields(keyval, arg, 2, 1, "=");
-	if (n != 2)
-		usage(); // exits
-	
-	while (cfg && cfg->type != C_END)
-		if (strcmp(cfg->kw, arg[0]) != 0)
-			cfg++;
-	
-	if (!cfg || cfg->type == C_END) {
-		fprint(2, "no valid option\n");
-		return;
-	}
-	
-	print("%s : %s\n", cfg->kw, cfg->name);
-	return;
-	
-	switch (cfg->type) {
-	case C_STRING:
-		cfg->u.string.sval = arg[1];
-		print("is string");
-		break;
-	case C_BOOLEAN:
-		n = atoi(arg[1]);
-		print("is boolean");
-		cfg->u.boolean.bval = n ? 1 : 0;
-		break;
-	case C_CHOICES:
-		// TODO
-		print("is choices");
-		fprint(2, "not implemented yet!\n");
-		break;
-	case C_END:
-	default:
-		print("not found");
-		break;
-	}
-}
-
 typedef struct Option Option;
 struct Option {
 	char *name;
@@ -668,7 +589,7 @@
 {
 	char buf[8];
 	Control *label, *entry;
-	int last;
+	int last = 0;
 	Option *o;
 	
 	for (o = options; o->name; o++) {
@@ -728,7 +649,7 @@
 {
 	char *t;
 	config_item *cfg;
-	Control *c, *info;
+	Control *c;
 	
 	/* assumptions: if b_savecfg exists, then l_cfginfo also exists */
 	
@@ -757,10 +678,9 @@
 	/* if already set up, early return */
 	if (c) {
 		goto Addbuttons;
-		return;
 	}
 	
-	info = createlabel(fe->cs, "l_cfginfo");
+	createlabel(fe->cs, "l_cfginfo");
 	chanprint(fe->cs->ctl, "l_cfginfo align centerleft");
 	chanprint(fe->cs->ctl, "l_cfginfo size 50 %d 500 %d", font->height, font->height);
 	
@@ -782,10 +702,8 @@
 void
 readoptions(void)
 {
-	char buf[128];
 	char *val;
 	config_item *cfg;
-	Control *c;
 	Option *o;
 	
 	for (int i = 0; i < nelem(configcats); i++) {
@@ -998,10 +916,7 @@
 {
 	int lastmouse;
 	char *s, *args[6];
-	int doprintoptions = 0;
 	char *wintitle;
-	config_item *cfg;
-	int changedprefs = 0;
 	float delta;
 	Mousectl *mousectl;
 	Mouse m;
@@ -1019,36 +934,16 @@
 	fe = new_window();
 	
 	wintitle = nil;
-	cfg = midend_get_config(fe->me, CFG_SETTINGS, &wintitle);
+	midend_get_config(fe->me, CFG_SETTINGS, &wintitle);
 	
 	ARGBEGIN{
 	case 'h':
 		usage();
 		break;
-	case 'o':
-		doprintoptions++;
-		break;
 	case 'l':
 		dolog++;
 		break;
-	case '-':
-		parseoption(cfg, ARGF());
-		changedprefs++;
-		break;
 	}ARGEND;
-	
-	if (changedprefs) {	
-		s = midend_set_config(fe->me, CFG_SETTINGS, cfg);
-		if (s) {
-			fprint(2, "error: %s\n", s);
-			exits("error");
-		}
-	}
-	
-	if (doprintoptions) {
-		printoptions(cfg);
-		exits(nil);
-	}
 	
 	atexit(doexit);