1295011Sandrew/* 2295011Sandrew * Copyright (C) 1999 by Andrey A. Chernov, Moscow, Russia. 3295011Sandrew * (C) 18 Sep 1999, Alex G. Bulushev (bag@demos.su) 4295011Sandrew * All rights reserved. 5295011Sandrew * 6295011Sandrew * Redistribution and use in source and binary forms, with or without 7295011Sandrew * modification, are permitted provided that the following conditions 8295011Sandrew * are met: 9295011Sandrew * 1. Redistributions of source code must retain the above copyright 10295011Sandrew * notice, this list of conditions and the following disclaimer. 11295011Sandrew * 2. Redistributions in binary form must reproduce the above copyright 12295011Sandrew * notice, this list of conditions and the following disclaimer in the 13295011Sandrew * documentation and/or other materials provided with the distribution. 14295011Sandrew * 15295011Sandrew * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND 16295011Sandrew * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17295011Sandrew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18295011Sandrew * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 19295011Sandrew * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20295011Sandrew * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21295011Sandrew * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22295011Sandrew * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23295011Sandrew * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24295011Sandrew * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25295011Sandrew * SUCH DAMAGE. 26295011Sandrew */ 27295011Sandrew 28295011Sandrew#include "lp.cdefs.h" /* A cross-platform version of <sys/cdefs.h> */ 29295011Sandrew__FBSDID("$FreeBSD: releng/11.0/usr.sbin/lpr/filters.ru/koi2855/koi2855.c 117609 2003-07-15 07:01:01Z gad $"); 30295011Sandrew 31295011Sandrew/* 32295011Sandrew * KOI8-R -> CP855 conversion filter (Russian character sets) 33295011Sandrew */ 34295011Sandrew 35295011Sandrew#include <sys/types.h> 36295011Sandrew#include <signal.h> 37295011Sandrew#include <stdio.h> 38295011Sandrew#include <stdlib.h> 39295011Sandrew#include <unistd.h> 40295011Sandrew 41295011Sandrewint length = 66; 42295011Sandrewint lines; 43295011Sandrew 44295011Sandrewunsigned char koi2855 [] = { 45295011Sandrew0xc4, 0xb3, 0xda, 0xbf, 0xc0, 0xd9, 0xc3, 0xb4, 46295011Sandrew0xc2, 0xc1, 0xc5, 0xdf, 0xdc, 0xdb, 0xdb, 0xdb, 47295011Sandrew0xb0, 0xb1, 0xb2, 0xda, 0xfe, 0x2e, 0xad, 0x3d, 48295011Sandrew0xae, 0xaf, 0xff, 0xd9, 0xcf, 0x32, 0x2e, 0x25, 49295011Sandrew0xcd, 0xba, 0xc9, 0x84, 0xc9, 0xc9, 0xbb, 0xbb, 50295011Sandrew0xbb, 0xc8, 0xc8, 0xc8, 0xbc, 0xbc, 0xbc, 0xcc, 51295011Sandrew0xcc, 0xcc, 0xb9, 0x85, 0xb9, 0xb9, 0xcb, 0xcb, 52295011Sandrew0xcb, 0xca, 0xca, 0xca, 0xce, 0xce, 0xce, 0x43, 53295011Sandrew0x9c, 0xa0, 0xa2, 0xa4, 0xa6, 0xa8, 0xaa, 0xac, 54295011Sandrew0xb5, 0xb7, 0xbd, 0xc6, 0xd0, 0xd2, 0xd4, 0xd6, 55295011Sandrew0xd8, 0xde, 0xe1, 0xe3, 0xe5, 0xe7, 0xe9, 0xeb, 56295011Sandrew0xed, 0xf1, 0xf3, 0xf5, 0xf7, 0xf9, 0xfb, 0x9e, 57295011Sandrew0x9d, 0xa1, 0xa3, 0xa5, 0xa7, 0xa9, 0xab, 0xad, 58295011Sandrew0xb6, 0xb8, 0xbe, 0xc7, 0xd1, 0xd3, 0xd5, 0xd7, 59295011Sandrew0xdd, 0xe0, 0xe2, 0xe4, 0xe6, 0xe8, 0xea, 0xec, 60295011Sandrew0xee, 0xf2, 0xf4, 0xf6, 0xf8, 0xfa, 0xfc, 0x9f 61295011Sandrew}; 62295011Sandrew 63295011Sandrewint main(int argc, char *argv[]) 64295011Sandrew{ 65295011Sandrew int c, i; 66295011Sandrew char *cp; 67295011Sandrew 68295011Sandrew while (--argc) { 69295011Sandrew if (*(cp = *++argv) == '-') { 70295011Sandrew switch (*++cp) { 71295011Sandrew case 'l': 72295011Sandrew if ((i = atoi(++cp)) > 0) 73295011Sandrew length = i; 74295011Sandrew break; 75295011Sandrew } 76295011Sandrew } 77295011Sandrew } 78295011Sandrew 79295011Sandrew while ((c = getchar()) != EOF) { 80295011Sandrew if (c == '\031') { 81295011Sandrew if ((c = getchar()) == '\1') { 82295011Sandrew lines = 0; 83295011Sandrew fflush(stdout); 84295011Sandrew kill(getpid(), SIGSTOP); 85295011Sandrew continue; 86295011Sandrew } else { 87295011Sandrew ungetc(c, stdin); 88295011Sandrew c = '\031'; 89295011Sandrew } 90295011Sandrew } else if (c & 0x80) { 91295011Sandrew putchar(koi2855[c & 0x7F]); 92295011Sandrew continue; 93295011Sandrew } else if (c == '\n') 94295011Sandrew lines++; 95295011Sandrew else if (c == '\f') 96295011Sandrew lines = length; 97295011Sandrew putchar(c); 98295011Sandrew if (lines >= length) { 99295011Sandrew lines = 0; 100295011Sandrew fflush(stdout); 101295011Sandrew } 102295011Sandrew } 103295011Sandrew return 0; 104295011Sandrew} 105295011Sandrew