koi2alt.c revision 33088
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 2733088Sache/* 2833088Sache * KOI8-R -> CP866 conversion filter (Russian character sets) 2933088Sache */ 3033088Sache 3133088Sache#include <sys/types.h> 3233088Sache#include <signal.h> 3333088Sache#include <stdio.h> 3433088Sache#include <unistd.h> 3533088Sache 3633088Sacheint length = 66; 3733088Sacheint lines; 3833088Sache 3933088Sachechar *koi2alt[] = { 4033088Sache/* 0 1 2 3 4 5 6 7 */ 4133088Sache/* 8 9 A B C D E F */ 4233088Sache/* 8 */ "\xc4","\xb3","\xda","\xbf","\xc0","\xd9","\xc3","\xb4", 4333088Sache "\xc2","\xc1","\xc5","\xdf","\xdc","\xdb","\xdd","\xde", 4433088Sache/* 9 */ "\xb0","\xb1","\xb2","\xb3","\xfe","\xf9","\xfb","-\b~", 4533088Sache "<\b_",">\b_","\xff","\xb3","\xf8","2\b-","\xfa",":\b-", 4633088Sache/* A */ "\xcd","\xba","\xd5","\xf1","\xd6","\xc9","\xb8","\xb7", 4733088Sache "\xbb","\xd4","\xd3","\xc8","\xbe","\xbd","\xbc","\xc6", 4833088Sache/* B */ "\xc7","\xcc","\xb5","\xf0","\xb6","\xb9","\xd1","\xd2", 4933088Sache "\xcb","\xcf","\xd0","\xca","\xd8","\xd7","\xce","c\b_", 5033088Sache/* C */ "\xee","\xa0","\xa1","\xe6","\xa4","\xa5","\xe4","\xa3", 5133088Sache "\xe5","\xa8","\xa9","\xaa","\xab","\xac","\xad","\xae", 5233088Sache/* D */ "\xaf","\xef","\xe0","\xe1","\xe2","\xe3","\xa6","\xa2", 5333088Sache "\xec","\xeb","\xa7","\xe8","\xed","\xe9","\xe7","\xea", 5433088Sache/* E */ "\x9e","\x80","\x81","\x96","\x84","\x85","\x94","\x83", 5533088Sache "\x95","\x88","\x89","\x8a","\x8b","\x8c","\x8d","\x8e", 5633088Sache/* F */ "\x8f","\x9f","\x90","\x91","\x92","\x93","\x86","\x82", 5733088Sache "\x9c","\x9b","\x87","\x98","\x9d","\x99","\x97","\x9a" 5833088Sache}; 5933088Sache 6033088Sacheint main(int argc, char *argv[]) 6133088Sache{ 6233088Sache int c, i; 6333088Sache char *cp; 6433088Sache 6533088Sache while (--argc) { 6633088Sache if (*(cp = *++argv) == '-') { 6733088Sache switch (*++cp) { 6833088Sache case 'l': 6933088Sache if ((i = atoi(++cp)) > 0) 7033088Sache length = i; 7133088Sache break; 7233088Sache } 7333088Sache } 7433088Sache } 7533088Sache 7633088Sache while ((c = getchar()) != EOF) { 7733088Sache if (c == '\031') { 7833088Sache if ((c = getchar()) == '\1') { 7933088Sache lines = 0; 8033088Sache fflush(stdout); 8133088Sache kill(getpid(), SIGSTOP); 8233088Sache continue; 8333088Sache } else { 8433088Sache ungetc(c, stdin); 8533088Sache c = '\031'; 8633088Sache } 8733088Sache } else if (c & 0x80) { 8833088Sache fputs(koi2alt[c & 0x7F], stdout); 8933088Sache continue; 9033088Sache } else if (c == '\n') 9133088Sache lines++; 9233088Sache else if (c == '\f') 9333088Sache lines = length; 9433088Sache putchar(c); 9533088Sache if (lines >= length) { 9633088Sache lines = 0; 9733088Sache fflush(stdout); 9833088Sache } 9933088Sache } 10033088Sache return 0; 10133088Sache} 102