151522Sache/* 251522Sache * Copyright (C) 1999 by Andrey A. Chernov, Moscow, Russia. 351522Sache * (C) 18 Sep 1999, Alex G. Bulushev (bag@demos.su) 451522Sache * All rights reserved. 551522Sache * 651522Sache * Redistribution and use in source and binary forms, with or without 751522Sache * modification, are permitted provided that the following conditions 851522Sache * are met: 951522Sache * 1. Redistributions of source code must retain the above copyright 1051522Sache * notice, this list of conditions and the following disclaimer. 1151522Sache * 2. Redistributions in binary form must reproduce the above copyright 1251522Sache * notice, this list of conditions and the following disclaimer in the 1351522Sache * documentation and/or other materials provided with the distribution. 1451522Sache * 1551522Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND 1651522Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1751522Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1851522Sache * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 1951522Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2051522Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2151522Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2251522Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2351522Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2451522Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2551522Sache * SUCH DAMAGE. 2651522Sache */ 2751522Sache 28117609Sgad#include "lp.cdefs.h" /* A cross-platform version of <sys/cdefs.h> */ 29117609Sgad__FBSDID("$FreeBSD$"); 30117609Sgad 3151522Sache/* 3251522Sache * KOI8-R -> CP855 conversion filter (Russian character sets) 3351522Sache */ 3451522Sache 3551522Sache#include <sys/types.h> 3651522Sache#include <signal.h> 3751522Sache#include <stdio.h> 38116076Simp#include <stdlib.h> 3951522Sache#include <unistd.h> 4051522Sache 4151522Sacheint length = 66; 4251522Sacheint lines; 4351522Sache 4451522Sacheunsigned char koi2855 [] = { 4551522Sache0xc4, 0xb3, 0xda, 0xbf, 0xc0, 0xd9, 0xc3, 0xb4, 4651522Sache0xc2, 0xc1, 0xc5, 0xdf, 0xdc, 0xdb, 0xdb, 0xdb, 4751522Sache0xb0, 0xb1, 0xb2, 0xda, 0xfe, 0x2e, 0xad, 0x3d, 4851522Sache0xae, 0xaf, 0xff, 0xd9, 0xcf, 0x32, 0x2e, 0x25, 4951522Sache0xcd, 0xba, 0xc9, 0x84, 0xc9, 0xc9, 0xbb, 0xbb, 5051522Sache0xbb, 0xc8, 0xc8, 0xc8, 0xbc, 0xbc, 0xbc, 0xcc, 5151522Sache0xcc, 0xcc, 0xb9, 0x85, 0xb9, 0xb9, 0xcb, 0xcb, 5251522Sache0xcb, 0xca, 0xca, 0xca, 0xce, 0xce, 0xce, 0x43, 5351522Sache0x9c, 0xa0, 0xa2, 0xa4, 0xa6, 0xa8, 0xaa, 0xac, 5451522Sache0xb5, 0xb7, 0xbd, 0xc6, 0xd0, 0xd2, 0xd4, 0xd6, 5551522Sache0xd8, 0xde, 0xe1, 0xe3, 0xe5, 0xe7, 0xe9, 0xeb, 5651522Sache0xed, 0xf1, 0xf3, 0xf5, 0xf7, 0xf9, 0xfb, 0x9e, 5751522Sache0x9d, 0xa1, 0xa3, 0xa5, 0xa7, 0xa9, 0xab, 0xad, 5851522Sache0xb6, 0xb8, 0xbe, 0xc7, 0xd1, 0xd3, 0xd5, 0xd7, 5951522Sache0xdd, 0xe0, 0xe2, 0xe4, 0xe6, 0xe8, 0xea, 0xec, 6051522Sache0xee, 0xf2, 0xf4, 0xf6, 0xf8, 0xfa, 0xfc, 0x9f 6151522Sache}; 6251522Sache 6351522Sacheint main(int argc, char *argv[]) 6451522Sache{ 6551522Sache int c, i; 6651522Sache char *cp; 6751522Sache 6851522Sache while (--argc) { 6951522Sache if (*(cp = *++argv) == '-') { 7051522Sache switch (*++cp) { 7151522Sache case 'l': 7251522Sache if ((i = atoi(++cp)) > 0) 7351522Sache length = i; 7451522Sache break; 7551522Sache } 7651522Sache } 7751522Sache } 7851522Sache 7951522Sache while ((c = getchar()) != EOF) { 8051522Sache if (c == '\031') { 8151522Sache if ((c = getchar()) == '\1') { 8251522Sache lines = 0; 8351522Sache fflush(stdout); 8451522Sache kill(getpid(), SIGSTOP); 8551522Sache continue; 8651522Sache } else { 8751522Sache ungetc(c, stdin); 8851522Sache c = '\031'; 8951522Sache } 9051522Sache } else if (c & 0x80) { 9151522Sache putchar(koi2855[c & 0x7F]); 9251522Sache continue; 9351522Sache } else if (c == '\n') 9451522Sache lines++; 9551522Sache else if (c == '\f') 9651522Sache lines = length; 9751522Sache putchar(c); 9851522Sache if (lines >= length) { 9951522Sache lines = 0; 10051522Sache fflush(stdout); 10151522Sache } 10251522Sache } 10351522Sache return 0; 10451522Sache} 105