aboutsummaryrefslogtreecommitdiffstats
path: root/tools/abcprintd.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2004-09-09 09:19:31 +0000
committerH. Peter Anvin <hpa@zytor.com>2004-09-09 09:19:31 +0000
commit74ce36dd7974a5b993737d6e6a553d9dabf469a0 (patch)
tree42111518fdcfe269312801e2b20cc0060f3b15db /tools/abcprintd.c
parentfdf95c0eed53e8fbc9dd84f13dae28b5ea514d4e (diff)
downloadabc80-74ce36dd7974a5b993737d6e6a553d9dabf469a0.tar.gz
abc80-74ce36dd7974a5b993737d6e6a553d9dabf469a0.tar.xz
abc80-74ce36dd7974a5b993737d6e6a553d9dabf469a0.zip
"Better" abcprintd which can do charset translation
Diffstat (limited to 'tools/abcprintd.c')
-rw-r--r--tools/abcprintd.c74
1 files changed, 64 insertions, 10 deletions
diff --git a/tools/abcprintd.c b/tools/abcprintd.c
index 279c8c5..28c1799 100644
--- a/tools/abcprintd.c
+++ b/tools/abcprintd.c
@@ -30,7 +30,14 @@
static int lpr_argc;
static const char **lpr_argv;
-static void print_setup(FILE **tfp)
+enum print_state {
+ ps_first, /* Brand new job */
+ ps_percent, /* Job started with %, might be ps */
+ ps_binary, /* Don't touch this */
+ ps_text /* It's text, OK to modify */
+};
+
+static void print_setup(FILE **tfp, enum print_state *psp)
{
FILE *tf = *tfp;
pid_t f;
@@ -60,6 +67,7 @@ static void print_setup(FILE **tfp)
perror("tmpfile");
exit(1);
}
+ *psp = ps_first;
}
static int open_port(const char *path)
@@ -107,11 +115,56 @@ static int open_port(const char *path)
return fd;
}
-static void output(int c, FILE *tf)
+static void output(int c, FILE *tf, enum print_state *psp)
{
- /* This is a separate function so we can put any needed data modifications
- in this file */
- fwrite(&c, 1, 1, tf);
+ 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\247"
+ "\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\267\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\37\377";
+
+ switch ( *psp ) {
+ case ps_first:
+ if ( c == 27 )
+ *psp = ps_binary;
+ else if ( c == '%' ) {
+ *psp = ps_percent;
+ return;
+ } else {
+ *psp = ps_text;
+ // fwrite(text_prefix, 1, sizeof text_prefix - 1, tf);
+ }
+ output(c, tf, psp);
+ break;
+
+ case ps_percent:
+ if ( c == '!' ) {
+ *psp = ps_binary;
+ } else {
+ *psp = ps_text;
+ // fwrite(text_prefix, 1, sizeof text_prefix - 1, tf);
+ }
+ output('%', tf, psp);
+ output(c, tf, psp);
+ break;
+
+ case ps_text:
+ putc(abc_to_latin1[(unsigned char)c], tf);
+ break;
+
+ case ps_binary:
+ putc(c, tf);
+ break;
+ }
}
#define BUF_SIZE 4096
@@ -127,8 +180,9 @@ int main(int argc, char *argv[])
} state;
char ibuf[BUF_SIZE], c;
int i, b;
+ enum print_state ps;
static const char *lpr_default_argv[] = {
- "enscript", "-B", "-Z", "-q", "-X", "asciise",
+ "enscript", "-B", "-Z", "-q", "-X", "latin1",
"--non-printable-format=space",
NULL
};
@@ -157,7 +211,7 @@ int main(int argc, char *argv[])
daemon(0,0);
- print_setup(&tf);
+ print_setup(&tf, &ps);
state = st_normal;
@@ -175,12 +229,12 @@ int main(int argc, char *argv[])
if ( c == '\xff' )
state = st_ff;
else
- output(c, tf);
+ output(c, tf, &ps);
break;
case st_ff:
if ( c != 0 ) {
- output(c, tf);
+ output(c, tf, &ps);
state = st_normal;
} else {
state = st_ff00;
@@ -189,7 +243,7 @@ int main(int argc, char *argv[])
case st_ff00:
if ( c == 0 )
- print_setup(&tf); /* BREAK received */
+ print_setup(&tf, &ps); /* BREAK received, end of job */
state = st_normal;
break;
}