#include "lp.cdefs.h"
#include <sys/types.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int length = 66;
int lines;
char *koi2alt[] = {
"\xc4","\xb3","\xda","\xbf","\xc0","\xd9","\xc3","\xb4",
"\xc2","\xc1","\xc5","\xdf","\xdc","\xdb","\xdd","\xde",
"\xb0","\xb1","\xb2","\xb3","\xfe","\xf9","\xfb","-\b~",
"<\b_",">\b_","\xff","\xb3","\xf8","2\b-","\xfa",":\b-",
"\xcd","\xba","\xd5","\xf1","\xd6","\xc9","\xb8","\xb7",
"\xbb","\xd4","\xd3","\xc8","\xbe","\xbd","\xbc","\xc6",
"\xc7","\xcc","\xb5","\xf0","\xb6","\xb9","\xd1","\xd2",
"\xcb","\xcf","\xd0","\xca","\xd8","\xd7","\xce","c\b_",
"\xee","\xa0","\xa1","\xe6","\xa4","\xa5","\xe4","\xa3",
"\xe5","\xa8","\xa9","\xaa","\xab","\xac","\xad","\xae",
"\xaf","\xef","\xe0","\xe1","\xe2","\xe3","\xa6","\xa2",
"\xec","\xeb","\xa7","\xe8","\xed","\xe9","\xe7","\xea",
"\x9e","\x80","\x81","\x96","\x84","\x85","\x94","\x83",
"\x95","\x88","\x89","\x8a","\x8b","\x8c","\x8d","\x8e",
"\x8f","\x9f","\x90","\x91","\x92","\x93","\x86","\x82",
"\x9c","\x9b","\x87","\x98","\x9d","\x99","\x97","\x9a"
};
int main(int argc, char *argv[])
{
int c, i;
char *cp;
while (--argc) {
if (*(cp = *++argv) == '-') {
switch (*++cp) {
case 'l':
if ((i = atoi(++cp)) > 0)
length = i;
break;
}
}
}
while ((c = getchar()) != EOF) {
if (c == '\031') {
if ((c = getchar()) == '\1') {
lines = 0;
fflush(stdout);
kill(getpid(), SIGSTOP);
continue;
} else {
ungetc(c, stdin);
c = '\031';
}
} else if (c & 0x80) {
fputs(koi2alt[c & 0x7F], stdout);
continue;
} else if (c == '\n')
lines++;
else if (c == '\f')
lines = length;
putchar(c);
if (lines >= length) {
lines = 0;
fflush(stdout);
}
}
return 0;
}