# HG changeset patch # User Sadrul Habib Chowdhury # Date 1179439489 0 # Node ID 3c42803872598127fade949f4e1b28ec3eb70963 # Parent 17117b8cfbb757f9cc078866b6bc0f193a513d8a Generate nicer HTML dumps. diff -r 17117b8cfbb7 -r 3c4280387259 finch/libgnt/gntwm.c --- a/finch/libgnt/gntwm.c Thu May 17 21:11:31 2007 +0000 +++ b/finch/libgnt/gntwm.c Thu May 17 22:04:49 2007 +0000 @@ -628,14 +628,40 @@ int x, y; chtype old = 0, now = 0; FILE *file = fopen("dump.html", "w"); + struct { + char ascii; + char *unicode; + } unis[] = { + {'q', "─"}, + {'t', "├"}, + {'u', "┤"}, + {'x', "│"}, + {'-', "↑"}, + {'.', "↓"}, + {'l', "┌"}, + {'k', "┐"}, + {'m', "└"}, + {'j', "┘"}, + {'a', "▒"}, + {'\0', NULL} + }; + fprintf(file, "\n \n\n\n"); fprintf(file, "
");
 	for (y = 0; y < getmaxy(stdscr); y++) {
 		for (x = 0; x < getmaxx(stdscr); x++) {
-			char ch;
+			char ch[2] = {0, 0}, *print;
+#ifdef NO_WIDECHAR
 			now = mvwinch(curscr, y, x);
-			ch = now & A_CHARTEXT;
-			now ^= ch;
+			ch[0] = now & A_CHARTEXT;
+			now ^= ch[0];
+#else
+			cchar_t wch;
+			char unicode[12];
+			mvwin_wch(curscr, y, x, &wch);
+			now = wch.attr;
+			ch[0] = (char)(wch.chars[0] & 0xff);
+#endif
 
 #define CHECK(attr, start, end) \
 			do \
@@ -688,48 +714,39 @@
 				fprintf(file, "",
 						bg.r, bg.g, bg.b, fg.r, fg.g, fg.b);
 			}
+			print = ch;
+#ifndef NO_WIDECHAR
+			if (wch.chars[0] > 255) {
+				snprintf(unicode, sizeof(unicode), "&#x%x;", wch.chars[0]);
+				print = unicode;
+			}
+#endif
 			if (now & A_ALTCHARSET)
 			{
-				switch (ch)
-				{
-					case 'q':
-						ch = '-'; break;
-					case 't':
-					case 'u':
-					case 'x':
-						ch = '|'; break;
-					case 'v':
-					case 'w':
-					case 'l':
-					case 'm':
-					case 'k':
-					case 'j':
-					case 'n':
-						ch = '+'; break;
-					case '-':
-						ch = '^'; break;
-					case '.':
-						ch = 'v'; break;
-					case 'a':
-						ch = '#'; break;
-					default:
-						ch = ' '; break;
+				int u;
+				for (u = 0; unis[u].ascii; u++) {
+					if (ch[0] == unis[u].ascii) {
+						print = unis[u].unicode;
+						break;
+					}
 				}
+				if (!unis[u].ascii)
+					print = " ";
 			}
-			if (ch == '&')
+			if (ch[0] == '&')
 				fprintf(file, "&");
-			else if (ch == '<')
+			else if (ch[0] == '<')
 				fprintf(file, "<");
-			else if (ch == '>')
+			else if (ch[0] == '>')
 				fprintf(file, ">");
 			else
-				fprintf(file, "%c", ch);
+				fprintf(file, "%s", print);
 			old = now;
 		}
 		fprintf(file, "\n");
 		old = 0;
 	}
-	fprintf(file, "
"); + fprintf(file, "\n"); fclose(file); return TRUE; }