133088Sache/* 233088Sache * Copyright (C) 1993-98 by Andrey A. Chernov, Moscow, Russia. 333088Sache * All rights reserved. 433088Sache * 533088Sache * Redistribution and use in source and binary forms, with or without 633088Sache * modification, are permitted provided that the following conditions 733088Sache * are met: 833088Sache * 1. Redistributions of source code must retain the above copyright 933088Sache * notice, this list of conditions and the following disclaimer. 1033088Sache * 2. Redistributions in binary form must reproduce the above copyright 1133088Sache * notice, this list of conditions and the following disclaimer in the 1233088Sache * documentation and/or other materials provided with the distribution. 1333088Sache * 1433088Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND 1533088Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1633088Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1733088Sache * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 1833088Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1933088Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2033088Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2133088Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2233088Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2333088Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2433088Sache * SUCH DAMAGE. 2533088Sache */ 2633088Sache 27117609Sgad#include "lp.cdefs.h" /* A cross-platform version of <sys/cdefs.h> */ 28117609Sgad__FBSDID("$FreeBSD: releng/11.0/usr.sbin/lpr/filters.ru/koi2alt/koi2alt.c 117609 2003-07-15 07:01:01Z gad $"); 29117609Sgad 3033088Sache/* 3133088Sache * KOI8-R -> CP866 conversion filter (Russian character sets) 3233088Sache */ 3333088Sache 3433088Sache#include <sys/types.h> 3533088Sache#include <signal.h> 3633088Sache#include <stdio.h> 37116075Simp#include <stdlib.h> 3833088Sache#include <unistd.h> 3933088Sache 4033088Sacheint length = 66; 4133088Sacheint lines; 4233088Sache 4333088Sachechar *koi2alt[] = { 4433088Sache/* 0 1 2 3 4 5 6 7 */ 4533088Sache/* 8 9 A B C D E F */ 4633088Sache/* 8 */ "\xc4","\xb3","\xda","\xbf","\xc0","\xd9","\xc3","\xb4", 4733088Sache "\xc2","\xc1","\xc5","\xdf","\xdc","\xdb","\xdd","\xde", 4833088Sache/* 9 */ "\xb0","\xb1","\xb2","\xb3","\xfe","\xf9","\xfb","-\b~", 4933088Sache "<\b_",">\b_","\xff","\xb3","\xf8","2\b-","\xfa",":\b-", 5033088Sache/* A */ "\xcd","\xba","\xd5","\xf1","\xd6","\xc9","\xb8","\xb7", 5133088Sache "\xbb","\xd4","\xd3","\xc8","\xbe","\xbd","\xbc","\xc6", 5233088Sache/* B */ "\xc7","\xcc","\xb5","\xf0","\xb6","\xb9","\xd1","\xd2", 5333088Sache "\xcb","\xcf","\xd0","\xca","\xd8","\xd7","\xce","c\b_", 5433088Sache/* C */ "\xee","\xa0","\xa1","\xe6","\xa4","\xa5","\xe4","\xa3", 5533088Sache "\xe5","\xa8","\xa9","\xaa","\xab","\xac","\xad","\xae", 5633088Sache/* D */ "\xaf","\xef","\xe0","\xe1","\xe2","\xe3","\xa6","\xa2", 5733088Sache "\xec","\xeb","\xa7","\xe8","\xed","\xe9","\xe7","\xea", 5833088Sache/* E */ "\x9e","\x80","\x81","\x96","\x84","\x85","\x94","\x83", 5933088Sache "\x95","\x88","\x89","\x8a","\x8b","\x8c","\x8d","\x8e", 6033088Sache/* F */ "\x8f","\x9f","\x90","\x91","\x92","\x93","\x86","\x82", 6133088Sache "\x9c","\x9b","\x87","\x98","\x9d","\x99","\x97","\x9a" 6233088Sache}; 6333088Sache 6433088Sacheint main(int argc, char *argv[]) 6533088Sache{ 6633088Sache int c, i; 6733088Sache char *cp; 6833088Sache 6933088Sache while (--argc) { 7033088Sache if (*(cp = *++argv) == '-') { 7133088Sache switch (*++cp) { 7233088Sache case 'l': 7333088Sache if ((i = atoi(++cp)) > 0) 7433088Sache length = i; 7533088Sache break; 7633088Sache } 7733088Sache } 7833088Sache } 7933088Sache 8033088Sache while ((c = getchar()) != EOF) { 8133088Sache if (c == '\031') { 8233088Sache if ((c = getchar()) == '\1') { 8333088Sache lines = 0; 8433088Sache fflush(stdout); 8533088Sache kill(getpid(), SIGSTOP); 8633088Sache continue; 8733088Sache } else { 8833088Sache ungetc(c, stdin); 8933088Sache c = '\031'; 9033088Sache } 9133088Sache } else if (c & 0x80) { 9233088Sache fputs(koi2alt[c & 0x7F], stdout); 9333088Sache continue; 9433088Sache } else if (c == '\n') 9533088Sache lines++; 9633088Sache else if (c == '\f') 9733088Sache lines = length; 9833088Sache putchar(c); 9933088Sache if (lines >= length) { 10033088Sache lines = 0; 10133088Sache fflush(stdout); 10233088Sache } 10333088Sache } 10433088Sache return 0; 10533088Sache} 106