[Dctrl-tools-devel] CVS dctrl-tools

CVS User ajk ajk at haydn.debian.org
Thu Jul 21 19:45:06 UTC 2005


Update of /cvsroot/dctrl-tools/dctrl-tools
In directory haydn:/tmp/cvs-serv30015

Modified Files:
	tbl-dctrl.1 tbl-dctrl.c 
Log Message:
UTF-8 magic

--- /cvsroot/dctrl-tools/dctrl-tools/tbl-dctrl.1	2005/07/21 18:15:09	1.1
+++ /cvsroot/dctrl-tools/dctrl-tools/tbl-dctrl.1	2005/07/21 19:45:06	1.2
@@ -157,8 +157,13 @@
 between two adjacent files.
 .SH "ENVIRONMENT VARIABLES"
 The standard locale environment, specifically its character set
-setting, affects the interpretation of input and output as character
+setting (which is affected by the environment variables LANG, LC_CTYPE and
+LC_ALL), affects the interpretation of input and output as character
 streams.
+.
+Additionally, if the locale character set is UTF-8, then pretty
+Unicode box drawing characters are used in drawing the table frame, if
+any is required.
 .SH "ASYNCHRONOUS EVENTS"
 Standard Unix signals have their usual meaning.
 .SH STDOUT
--- /cvsroot/dctrl-tools/dctrl-tools/tbl-dctrl.c	2005/07/21 09:53:18	1.1
+++ /cvsroot/dctrl-tools/dctrl-tools/tbl-dctrl.c	2005/07/21 19:45:06	1.2
@@ -17,6 +17,7 @@
  */
 
 #include <argp.h>
+#include <langinfo.h>
 #include <locale.h>
 #include <stdlib.h>
 #include "misc.h"
@@ -45,6 +46,7 @@
 #define MAX_COLUMNS 4096
 
 struct arguments {
+	_Bool assume_utf8;
 	char *delim; // NULL if not specced
 	/* True iff some column lengths are unknown and need to be
 	 * calculated. */
@@ -140,7 +142,10 @@
 	for (size_t i = 0; i < num_lines; i++) {
 		for (size_t j = 0; j < args->num_columns; j++) {
 			if (args->delim == NULL) {
-				fputs("| ", stdout);
+				fputs(args->assume_utf8 ? 
+				      j == 0 ? "\xe2\x94\x83 " : "\xe2\x94\x82 "
+				      : "| ",
+				      stdout);
 			} else if (j > 0) {
 				fputs(args->delim, stdout);
 			}
@@ -173,7 +178,9 @@
 			}
 			data[j].inx = k;
 		}
-		if (args->delim == NULL) fputs("|", stdout);
+		if (args->delim == NULL) fputs(args->assume_utf8 
+					       ? "\xe2\x94\x83" : "|",
+					       stdout);
 		putchar('\n');
 	}
 	for (size_t i = 0; i < args->num_columns; i++) free(data[i].wrapped);
@@ -183,14 +190,23 @@
 {
 	if (args->delim == NULL) {
 		for (size_t i = 0; i < args->num_columns; i++) {
-			putchar('+');
+			if (args->assume_utf8) {
+				if (i == 0) {
+					fputs("\xe2\x94\x8f", stdout);
+				} else {
+					fputs("\xe2\x94\xaf", stdout);
+				}
+			} else {
+				putchar('+');
+			}
 			for (size_t j = 0; 
 			     j < args->columns[i].column_width + 2;
 			     j++) {
-				putchar('=');
+				fputs(args->assume_utf8 ? "\xe2\x94\x81" : "=",
+				      stdout);
 			}
 		}
-		putchar('+');
+		fputs(args->assume_utf8 ? "\xe2\x94\x93" : "+", stdout);
 		putchar('\n');
 	}
 		
@@ -203,12 +219,23 @@
 
 	if (args->delim == NULL) {
 		for (size_t i = 0; i < args->num_columns; i++) {
-			putchar('+');
-			for (size_t j = 0; j < args->columns[i].column_width + 2; j++) {
-				putchar('-');
+			if (args->assume_utf8) {
+				if (i == 0) {
+					fputs("\xe2\x94\xa0", stdout);
+				} else {
+					fputs("\xe2\x94\xbc", stdout);
+				}
+			} else {
+				putchar('+');
+			}
+			for (size_t j = 0; j < args->columns[i].column_width + 2;
+			     j++) {
+				fputs(args->assume_utf8
+				      ? "\xe2\x94\x80" : "+",
+				      stdout);
 			}
 		}
-		putchar('+');
+		fputs(args->assume_utf8 ? "\xe2\x94\xa8" : "+", stdout);
 		putchar('\n');
 	}
 }
@@ -217,12 +244,20 @@
 {
 	if (args->delim != NULL) return;
 	for (size_t i = 0; i < args->num_columns; i++) {
-		putchar('+');
+		if (args->assume_utf8) {
+			if (i == 0) {
+				fputs("\xe2\x94\x97", stdout);
+			} else {
+				fputs("\xe2\x94\xb7", stdout);
+			}
+		} else {
+			putchar('+');
+		}
 		for (size_t j = 0; j < args->columns[i].column_width + 2; j++) {
-			putchar('=');
+			fputs(args->assume_utf8 ? "\xe2\x94\x81" : "=", stdout);
 		}
 	}
-	putchar('+');
+	fputs(args->assume_utf8 ? "\xe2\x94\x9b" : "+", stdout);
 	putchar('\n');
 }
 
@@ -342,6 +377,8 @@
 
 	static struct arguments args;
 
+	if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0) args.assume_utf8 = 1;
+
 	//keys_init(&args.keys);
 	msg_set_progname(argv[0]);
 	argp_parse (&argp, argc, argv, ARGP_IN_ORDER, 0, &args);




More information about the Dctrl-tools-devel mailing list