Recently Written · git

sacc

Mirror of git://bitreich.org/sacc, the sacc gopher client from bitreich.org.

git clone https://github.com/equwal/sacc

Log | Files | Refs


commit 80db85ac77a36eb3f591ea7f38816b6339607821
Quentin Rameau <quinq@fifth.space>
2018-08-13 11:08:36 +0200

Let the user configure the displayed menu items

 common.h     | 21 +++++++++++++++++++++
 config.def.h | 22 ++++++++++++++++++++++
 sacc.c       | 37 ++++++++++++++++++-------------------
 ui_ti.c      |  2 +-
 ui_txt.c     |  2 +-
 5 files changed, 63 insertions(+), 21 deletions(-)
diff --git a/common.h b/common.h
index 675260c..8e71951 100644
--- a/common.h
+++ b/common.h
@@ -3,6 +3,27 @@
 typedef struct item Item;
 typedef struct dir Dir;
 
+enum {
+	TXT,
+	DIR,
+	CSO,
+	ERR,
+	MAC,
+	DOS,
+	UUE,
+	IND,
+	TLN,
+	BIN,
+	MIR,
+	IBM,
+	GIF,
+	IMG,
+	URL,
+	INF,
+	UNK,
+	BRK,
+};
+
 struct item {
 	char type;
 	char redtype;
diff --git a/config.def.h b/config.def.h
index 7861e53..10ffb6d 100644
--- a/config.def.h
+++ b/config.def.h
@@ -25,3 +25,25 @@ static char *plumber = "xdg-open";
 
 /* temporary directory template (must end with six 'X' characters) */
 static char tmpdir[] = "/tmp/sacc-XXXXXX";
+
+/* menu items strings */
+static char *typestr[] = {
+	[TXT] = "Txt+",
+	[DIR] = "Dir+",
+	[CSO] = "CSO|",
+	[ERR] = "Err|",
+	[MAC] = "Mac+",
+	[DOS] = "DOS+",
+	[UUE] = "UUE+",
+	[IND] = "Ind+",
+	[TLN] = "Tln|",
+	[BIN] = "Bin+",
+	[MIR] = "Mir+",
+	[IBM] = "IBM|",
+	[GIF] = "GIF+",
+	[IMG] = "Img+",
+	[URL] = "URL+",
+	[INF] = "   |",
+	[UNK] = " ? +",
+	[BRK] = "!  |", /* malformed entry */
+};
diff --git a/sacc.c b/sacc.c
index c05e671..2649257 100644
--- a/sacc.c
+++ b/sacc.c
@@ -19,7 +19,6 @@
 #include <sys/wait.h>
 
 #include "common.h"
-
 #include "config.h"
 
 static char *mainurl;
@@ -223,43 +222,43 @@ typedisplay(char t)
 {
 	switch (t) {
 	case '0':
-		return "Text+";
+		return typestr[TXT];
 	case '1':
-		return "Dir +";
+		return typestr[DIR];
 	case '2':
-		return "CSO |";
+		return typestr[CSO];
 	case '3':
-		return "Err |";
+		return typestr[ERR];
 	case '4':
-		return "Macf+";
+		return typestr[MAC];
 	case '5':
-		return "DOSf+";
+		return typestr[DOS];
 	case '6':
-		return "UUEf+";
+		return typestr[UUE];
 	case '7':
-		return "Find+";
+		return typestr[IND];
 	case '8':
-		return "Tlnt+";
+		return typestr[TLN];
 	case '9':
-		return "Binf+";
+		return typestr[BIN];
 	case '+':
-		return "Mirr+";
+		return typestr[MIR];
 	case 'T':
-		return "IBMt|";
+		return typestr[IBM];
 	case 'g':
-		return "GIF +";
+		return typestr[GIF];
 	case 'I':
-		return "Img +";
+		return typestr[IMG];
 	case 'h':
-		return "HTML+";
+		return typestr[URL];
 	case 'i':
-		return "    |";
+		return typestr[INF];
 	default:
 		/* "Characters '0' through 'Z' are reserved." (ASCII) */
 		if (t >= '0' && t <= 'Z')
-			return "!   |";
+			return typestr[BRK];
 		else
-			return "UNKN|";
+			return typestr[UNK];
 	}
 }
 
diff --git a/ui_ti.c b/ui_ti.c
index 82984bb..1194d76 100644
--- a/ui_ti.c
+++ b/ui_ti.c
@@ -7,8 +7,8 @@
 #include <unistd.h>
 #include <sys/types.h>
 
-#include "config.h"
 #include "common.h"
+#include "config.h"
 
 #define C(c) #c
 #define S(c) C(c)
diff --git a/ui_txt.c b/ui_txt.c
index 316bc1d..34167d5 100644
--- a/ui_txt.c
+++ b/ui_txt.c
@@ -103,7 +103,7 @@ printstatus(Item *item, char c)
               "%3lld%%%*c %s/%c%s [%c]: ";
 	if (snprintf(bufout, sizeof(bufout), fmt,
 	             (printoff + lines-1 >= nitems) ? 100 :
-	             (printoff + lines) * 100 / nitems, ndigits(nitems)+2, '|',
+	             (printoff + lines) * 100 / nitems, ndigits(nitems)+1, '|',
 	             item->host, item->type, item->selector, c, item->port)
 	    >= sizeof(bufout))
 		bufout[sizeof(bufout)-1] = '\0';