aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2012-08-07 22:05:49 -0700
committerH. Peter Anvin <hpa@zytor.com>2012-08-07 22:05:49 -0700
commita68edf7d0af98c82c3a8a71f2a74f9c5d65a8cd6 (patch)
tree0afd4812931f1081723fa1398fe33a0e5dac8026
parent86129abfd8355ec9286a5a731a69b14944e0ddcd (diff)
downloadabc80-a68edf7d0af98c82c3a8a71f2a74f9c5d65a8cd6.tar.gz
abc80-a68edf7d0af98c82c3a8a71f2a74f9c5d65a8cd6.tar.xz
abc80-a68edf7d0af98c82c3a8a71f2a74f9c5d65a8cd6.zip
abcprintd: output wide characters, and use a Unicode table
This is 2012, we speak Unicode... if we don't, that is just broken.
-rw-r--r--tools/abcprintd.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/tools/abcprintd.c b/tools/abcprintd.c
index 7245071..c0c5eaf 100644
--- a/tools/abcprintd.c
+++ b/tools/abcprintd.c
@@ -27,6 +27,8 @@
#include <sys/wait.h>
#include <termios.h>
#include <unistd.h>
+#include <locale.h>
+#include <wchar.h>
#ifndef O_TEXT
# define O_TEXT 0
@@ -126,20 +128,22 @@ static int open_port(const char *path, speed_t speed)
static void output(int c, FILE *tf, enum print_state *psp)
{
- static const char abc_to_latin1[256] =
- "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017"
- "\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
- " !\"#\244%&\'()*+,-./0123456789:;<=>?"
- "\311ABCDEFGHIJKLMNOPQRSTUVWXYZ\304\326\305\334_"
- "\351abcdefghijklmnopqrstuvwxyz\344\366\345\374\267"
- "\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217"
- "\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237"
- "\240\241\242\243$\245\246\247\250\251\252\253\254\255\256\257"
- "\260\261\262\263\264\265\266\177\270\271\272\273\274\275\276\277"
- "\300\301\302\303[]\306\307\310@\312\313\314\315\316\317"
- "\320\321\322\323\324\325\\\327\330\331\332\333^\335\336\337"
- "\340\341\342\343{}\346\347\350`\352\353\354\355\356\357"
- "\360\361\362\363\364\365|\367\370\371\372\373~\375\376\377";
+ static const wchar_t abc_to_unicode[256] =
+ L"\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017"
+ L"\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
+ L" !\"#¤%&\'()*+,-./0123456789:;<=>?"
+ L"ÉABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÅÜ_"
+ L"éabcdefghijklmnopqrstuvwxyzäöåü\x25a0"
+ L"\x20ac\x25a1\x201a\x0192\x201e\x2026\x2020\x2021"
+ L"\x02c6\x2030\x0160\x2039\x0152\x2190\x107d\x2192"
+ L"\x2191\x2018\x2019\x201c\x201d\x2022\x2013\x2014"
+ L"\x02dc\x2122\x0161\x203a\x0153\x2193\x017e\x0178"
+ L"\240\241\242\243$\245\246\247\250\251\252\253\254\255\256\257"
+ L"\260\261\262\263\264\265\266\177\270\271\272\273\274\275\276\277"
+ L"\300\301\302\303[]\306\307\310@\312\313\314\315\316\317"
+ L"\320\321\322\323\324\325\\\327\330\331\332\333^\335\336\337"
+ L"\340\341\342\343{}\346\347\350`\352\353\354\355\356\357"
+ L"\360\361\362\363\364\365|\367\370\371\372\373~\375\376\377";
switch ( *psp ) {
case ps_first:
@@ -167,7 +171,7 @@ static void output(int c, FILE *tf, enum print_state *psp)
break;
case ps_text:
- putc(abc_to_latin1[(unsigned char)c], tf);
+ putwc(abc_to_unicode[(unsigned char)c], tf);
break;
case ps_binary:
@@ -194,17 +198,15 @@ int main(int argc, char *argv[])
unsigned char c;
int i, b;
enum print_state ps;
- static const char *lpr_default_argv[] = {
- "enscript", "-B", "-Z", "-q", "-X", "latin1",
- "--non-printable-format=space",
- NULL
- };
+ static const char *lpr_default_argv[] = { "lpr", NULL };
int o;
extern char *optarg;
extern int optind, opterr, optopt;
bool badopt = false;
speed_t speed = B115200;
+ setlocale(LC_ALL, "");
+
fileops = false;
while ((o = getopt(argc, argv, "d:")) != EOF) {