shithub: neatpost

Download patch

ref: ae31390de112361acbd73725f0e82b5a0358f38e
parent: ef9ceb0ace1203b8167a418e55fa9654d119cd0d
author: Ali Gholami Rudi <ali@rudi.ir>
date: Wed Mar 12 15:56:56 EDT 2014

dev: allow mounting fonts after S position

--- a/dev.c
+++ b/dev.c
@@ -14,7 +14,7 @@
 /* mounted fonts */
 static char fn_name[NFONTS][FNLEN];	/* font names */
 static struct font *fn_font[NFONTS];	/* font structs */
-static int fn_n;			/* number of mounted fonts */
+static int fn_n;			/* number of device fonts */
 
 static void skipline(FILE* filp)
 {
@@ -28,6 +28,8 @@
 {
 	char path[PATHLEN];
 	struct font *fn;
+	if (pos >= NFONTS)
+		return -1;
 	sprintf(path, "%s/dev%s/%s", dev_dir, dev_dev, name);
 	fn = font_open(path);
 	if (!fn)
@@ -97,7 +99,7 @@
 void dev_close(void)
 {
 	int i;
-	for (i = 0; i < fn_n; i++) {
+	for (i = 0; i < NFONTS; i++) {
 		if (fn_font[i])
 			font_close(fn_font[i]);
 		fn_font[i] = NULL;
@@ -111,7 +113,7 @@
 	g = font_find(fn_font[fn], c);
 	if (g)
 		return g;
-	for (i = 0; i < fn_n; i++)
+	for (i = 0; i < NFONTS; i++)
 		if (fn_font[i] && fn_font[i]->special)
 			if ((g = font_find(fn_font[i], c)))
 				return g;
@@ -131,7 +133,7 @@
 /* return the font struct at pos */
 struct font *dev_font(int pos)
 {
-	return pos >= 0 && pos < fn_n ? fn_font[pos] : NULL;
+	return pos >= 0 && pos < NFONTS ? fn_font[pos] : NULL;
 }
 
 int charwid(int wid, int sz)
@@ -143,7 +145,7 @@
 int dev_fontid(struct font *fn)
 {
 	int i;
-	for (i = 0; i < fn_n; i++)
+	for (i = 0; i < NFONTS; i++)
 		if (fn_font[i] == fn)
 			return i;
 	return 0;