/* * cuecat.c - cuecat translation * * Copyright (C) 2001 Nathan Laredo (laredo@gnu.org) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include static unsigned char xlate[88] = { /* 0x28 */ 0xff, 0xff, 0xff, 0x3e, 0xff, 0x3f, 0xff, 0xff, /* 0x30 */ 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, /* 0x38 */ 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40 */ 0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, /* 0x48 */ 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, /* 0x50 */ 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, /* 0x58 */ 0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60 */ 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, /* 0x68 */ 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, /* 0x70 */ 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, /* 0x78 */ 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff, }; static unsigned char inbuf[4096]; int main(int argc, char **argv) { int i, j, val, len, c; FILE *outfile = stdout, *infile = stdin; while (!feof(infile)) { fgets(inbuf, 4096, infile); len = strlen(inbuf); for (i = j = val = 0; i < len; i++) { c = (inbuf[i] > 0x28 && inbuf[i] < 0x7b) ? xlate[inbuf[i] - 0x28] : 0xff; if (c > 0x3f) { /* term/invalid character */ val <<= (4 - j) * 6; val ^= 0x434343; if (j > 1) fputc((val >> 16) & 0xff, outfile); if (j == 3) fputc((val >> 8) & 0xff, outfile); fputc('|', outfile); j = val = 0; continue; } val <<= 6; val |= c; if ((++j) > 3) { val ^= 0x434343; fputc((val >> 16) & 0xff, outfile); fputc((val >> 8) & 0xff, outfile); fputc(val & 0xff, outfile); j = val = 0; } } fputc('\n', outfile); fflush(outfile); } exit(0); }