Sophie

Sophie

distrib > Mageia > 5 > i586 > by-pkgid > e1725d895f66444b16e4a9dfd04598d7 > files > 2

cgit-0.12-1.2.mga5.src.rpm

From 90d781d4163bb20b61856739e2a558b7653b44a4 Mon Sep 17 00:00:00 2001
From: Colin Guthrie <colin@mageia.org>
Date: Tue, 16 Apr 2013 12:29:10 +0100
Subject: [PATCH] ui-repolist: Add a very simple 'pretty' print option for
 sections extracted from paths.

The basic principle is to title case latin characters and replace
anything else with a single whitespace.
---
 html.c        | 33 +++++++++++++++++++++++++++++++++
 html.h        |  1 +
 ui-repolist.c |  5 ++++-
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/html.c b/html.c
index d89df3a..e44eea0 100644
--- a/html.c
+++ b/html.c
@@ -121,6 +121,39 @@ void html_vtxtf(const char *format, va_list ap)
 	strbuf_release(&buf);
 }
 
+void html_title_txt(const char *txt)
+{
+	const char *t = txt;
+	int titlify = 1;
+	int started = 0;
+	while(t && *t){
+		int c = *t;
+		if ((c>='A' && c<='Z') || (c>='0' && c<='9')) {
+			started = 1;
+			html_raw(t, 1);
+			titlify = 0;
+		} else if (c>='a' && c<='z') {
+			started = 1;
+			if (!titlify) {
+				html_raw(t, 1);
+			} else {
+				c -= 32;
+				html_raw((const char*)&c, 1);
+			}
+			titlify = 0;
+		} else if (c=='/') {
+			started = 1;
+			html(" &raquo; ");
+			titlify = 1;
+		} else if (started && !titlify) {
+			started = 1;
+			html_raw(" ", 1);
+			titlify = 1;
+		}
+		t++;
+	}
+}
+
 void html_txt(const char *txt)
 {
 	const char *t = txt;
diff --git a/html.h b/html.h
index c72e845..26b0104 100644
--- a/html.h
+++ b/html.h
@@ -18,6 +18,7 @@ extern void html_vtxtf(const char *format, va_list ap);
 __attribute__((format (printf,1,2)))
 extern void html_attrf(const char *format,...);
 
+extern void html_title_txt(const char *txt);
 extern void html_txt(const char *txt);
 extern void html_ntxt(int len, const char *txt);
 extern void html_attr(const char *txt);
diff --git a/ui-repolist.c b/ui-repolist.c
index 6010a39..ad9d682 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -322,7 +322,10 @@ void cgit_print_repolist(void)
 		     strcmp(section, last_section)))) {
 			htmlf("<tr class='nohover'><td colspan='%d' class='reposection'>",
 			      columns);
-			html_txt(section);
+			if (ctx.cfg.section_from_path)
+				html_title_txt(section);
+			else
+				html_txt(section);
 			html("</td></tr>");
 			last_section = section;
 		}
-- 
2.7.0