| 1 | // |
|---|
| 2 | // TxWin, Textmode Windowing Library |
|---|
| 3 | // |
|---|
| 4 | // Original code Copyright (c) 1995-2005 Fsys Software and Jan van Wijk |
|---|
| 5 | // |
|---|
| 6 | // ========================================================================== |
|---|
| 7 | // |
|---|
| 8 | // This file contains Original Code and/or Modifications of Original Code as |
|---|
| 9 | // defined in and that are subject to the GNU Lesser General Public License. |
|---|
| 10 | // You may not use this file except in compliance with the License. |
|---|
| 11 | // BY USING THIS FILE YOU AGREE TO ALL TERMS AND CONDITIONS OF THE LICENSE. |
|---|
| 12 | // A copy of the License is provided with the Original Code and Modifications, |
|---|
| 13 | // and is also available at http://www.dfsee.com/txwin/lgpl.htm |
|---|
| 14 | // |
|---|
| 15 | // This library is free software; you can redistribute it and/or modify |
|---|
| 16 | // it under the terms of the GNU Lesser General Public License as published |
|---|
| 17 | // by the Free Software Foundation; either version 2.1 of the License, |
|---|
| 18 | // or (at your option) any later version. |
|---|
| 19 | // |
|---|
| 20 | // This library is distributed in the hope that it will be useful, |
|---|
| 21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 23 | // See the GNU Lesser General Public License for more details. |
|---|
| 24 | // |
|---|
| 25 | // You should have received a copy of the GNU Lesser General Public License |
|---|
| 26 | // along with this library; (lgpl.htm) if not, write to the Free Software |
|---|
| 27 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 28 | // |
|---|
| 29 | // Questions on TxWin licensing can be directed to: txwin@fsys.nl |
|---|
| 30 | // |
|---|
| 31 | // ========================================================================== |
|---|
| 32 | // |
|---|
| 33 | // Generic TX utility functions |
|---|
| 34 | // |
|---|
| 35 | // Author: J. van Wijk |
|---|
| 36 | // |
|---|
| 37 | // JvW 13-06-2002 Initial version, split off from TXCON |
|---|
| 38 | |
|---|
| 39 | #include <txlib.h> |
|---|
| 40 | |
|---|
| 41 | static char txc_ascii7_t[] = // translate table 128..255 |
|---|
| 42 | |
|---|
| 43 | "CueaaaaceeeiiiAAEaAooouuyOUcLYPfaiounNao?[]24i<>-=*|++++++|+++++" |
|---|
| 44 | // 128 " |
|---|
| 45 | ¡¢£€¥Š§š©ª«¬®¯°±²³Žµ¶·ž¹º»ŒœŸ¿" |
|---|
| 46 | |
|---|
| 47 | "++++-++++++++=+++++++++++++*=||=abcpE_ut08OSmfeU=+GL[]:~o..vn2. "; |
|---|
| 48 | // 192 "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ" |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | /*****************************************************************************/ |
|---|
| 53 | // Test if area consists completely of the empty byte/character ==> is empty |
|---|
| 54 | /*****************************************************************************/ |
|---|
| 55 | BOOL TxAreaEmpty // RET area is empty |
|---|
| 56 | ( |
|---|
| 57 | char *area, // IN area to check |
|---|
| 58 | int size, // IN size of area, bytes |
|---|
| 59 | char empty // IN the empty char |
|---|
| 60 | ) |
|---|
| 61 | { |
|---|
| 62 | BOOL rc = TRUE; |
|---|
| 63 | |
|---|
| 64 | while (size--) |
|---|
| 65 | { |
|---|
| 66 | if (*area != empty) |
|---|
| 67 | { |
|---|
| 68 | rc = FALSE; |
|---|
| 69 | break; |
|---|
| 70 | } |
|---|
| 71 | area++; |
|---|
| 72 | } |
|---|
| 73 | return (rc); |
|---|
| 74 | } // end 'TxAreaEmpty' |
|---|
| 75 | /*---------------------------------------------------------------------------*/ |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | /*****************************************************************************/ |
|---|
| 79 | // Filter 8-bit ASCII, strip to 7-bit, translate, or replace by specified char |
|---|
| 80 | /*****************************************************************************/ |
|---|
| 81 | void TxAscii827 // translate 8-bit to 7-bit |
|---|
| 82 | ( |
|---|
| 83 | char *str, // INOUT string to convert |
|---|
| 84 | unsigned char new // IN new char, or 0x00 |
|---|
| 85 | ) |
|---|
| 86 | { |
|---|
| 87 | char ch; |
|---|
| 88 | |
|---|
| 89 | while ((ch = *str) != 0) |
|---|
| 90 | { |
|---|
| 91 | if ((ch & 0x80) != 0) // 8th bit is set |
|---|
| 92 | { |
|---|
| 93 | switch (new) |
|---|
| 94 | { |
|---|
| 95 | case TXASCII827_STRIP: |
|---|
| 96 | *str = (char)(ch & 0x7f); // simple strip off |
|---|
| 97 | break; |
|---|
| 98 | |
|---|
| 99 | case TXASCII827_TRANS: |
|---|
| 100 | *str = txc_ascii7_t[ch & 0x7f]; // translate using table |
|---|
| 101 | break; |
|---|
| 102 | |
|---|
| 103 | default: |
|---|
| 104 | *str = new; // replace by specified |
|---|
| 105 | break; |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | str++; |
|---|
| 109 | } |
|---|
| 110 | } // end 'TxAscii827' |
|---|
| 111 | /*---------------------------------------------------------------------------*/ |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | /*****************************************************************************/ |
|---|
| 115 | // Copy string to destination, replacing non printables, clip and terminate it |
|---|
| 116 | /*****************************************************************************/ |
|---|
| 117 | void TxCopy |
|---|
| 118 | ( |
|---|
| 119 | char *dest, // OUT destination string |
|---|
| 120 | char *source, // IN source string |
|---|
| 121 | int len // IN max length incl \0 |
|---|
| 122 | ) |
|---|
| 123 | { |
|---|
| 124 | if (len > 0) |
|---|
| 125 | { |
|---|
| 126 | while ((*source) && (--len)) |
|---|
| 127 | { |
|---|
| 128 | *dest++ = TxPrintable(*source++); |
|---|
| 129 | } |
|---|
| 130 | *dest = 0; |
|---|
| 131 | } |
|---|
| 132 | } // end 'TxCopy' |
|---|
| 133 | /*---------------------------------------------------------------------------*/ |
|---|