| 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 | // TX display functions for HEX and ASCII data structures |
|---|
| 34 | // file-logging facilities |
|---|
| 35 | // |
|---|
| 36 | // Author: J. van Wijk |
|---|
| 37 | // |
|---|
| 38 | // JvW 24-07-2005 Initial version, split off from TXCON.C |
|---|
| 39 | |
|---|
| 40 | #include <txlib.h> |
|---|
| 41 | |
|---|
| 42 | /*****************************************************************************/ |
|---|
| 43 | // Make ascii-dump of data area on TxPrint output |
|---|
| 44 | /*****************************************************************************/ |
|---|
| 45 | void TxDisplAscDump |
|---|
| 46 | ( |
|---|
| 47 | char *lead, // IN leading string |
|---|
| 48 | char *data, // IN data area |
|---|
| 49 | ULONG size // IN size to dump |
|---|
| 50 | ) |
|---|
| 51 | { |
|---|
| 52 | char *s; |
|---|
| 53 | ULONG i; |
|---|
| 54 | |
|---|
| 55 | if ((data != NULL) && (size != 0) && (!TxAbort())) |
|---|
| 56 | { |
|---|
| 57 | TxPrint("%s", lead); |
|---|
| 58 | for (s=data, i=0; i<size && (*s != 0x1a) && !TxAbort(); s++, i++) |
|---|
| 59 | { |
|---|
| 60 | TxPrint("%c", *s); |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | } // end 'TxDisplAscDump' |
|---|
| 64 | /*---------------------------------------------------------------------------*/ |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | /*****************************************************************************/ |
|---|
| 68 | // Make hex-dump of data area on TxPrint output |
|---|
| 69 | /*****************************************************************************/ |
|---|
| 70 | void TxDisplHexDump |
|---|
| 71 | ( |
|---|
| 72 | char *data, // IN data area |
|---|
| 73 | ULONG size // IN size to dump |
|---|
| 74 | ) |
|---|
| 75 | { |
|---|
| 76 | TxDisplayHex( "", data, size, 0); |
|---|
| 77 | } // end 'TxDisplHexDump' |
|---|
| 78 | /*---------------------------------------------------------------------------*/ |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | /*****************************************************************************/ |
|---|
| 82 | // Make hex-dump of based data area on TxPrint output, with leading text |
|---|
| 83 | /*****************************************************************************/ |
|---|
| 84 | void TxDisplayHex |
|---|
| 85 | ( |
|---|
| 86 | char *lead, // IN leading text |
|---|
| 87 | char *data, // IN data area |
|---|
| 88 | ULONG size, // IN size to dump |
|---|
| 89 | ULONG base // IN base for display |
|---|
| 90 | ) |
|---|
| 91 | { |
|---|
| 92 | char *s; |
|---|
| 93 | char c; |
|---|
| 94 | ULONG i; |
|---|
| 95 | ULONG n = 0; |
|---|
| 96 | TXTM ascii; // ascii part buffer |
|---|
| 97 | TXTM line; // accumulating buffer |
|---|
| 98 | TXTS hex; // temporary hex buffer |
|---|
| 99 | |
|---|
| 100 | if ((data != NULL) && (size != 0)) |
|---|
| 101 | { |
|---|
| 102 | TxPrint("%s", lead); |
|---|
| 103 | for (s=data, i=0; i < size && !TxAbort(); s++, i++) |
|---|
| 104 | for (s=data, i=0; i < size; s++, i++) |
|---|
| 105 | { |
|---|
| 106 | n = i % 16; |
|---|
| 107 | switch (n) |
|---|
| 108 | { |
|---|
| 109 | case 0: |
|---|
| 110 | if (i) |
|---|
| 111 | { |
|---|
| 112 | TxPrint("%s %s[%s%s%s]%s\n", line, CNC, CNN, ascii, CNC, CNN); |
|---|
| 113 | } |
|---|
| 114 | memset(ascii, 0, TXMAXTM); |
|---|
| 115 | if (i && (i % 1024) == 0) // every 64 lines a formfeed |
|---|
| 116 | { |
|---|
| 117 | TxPrint("Byte offset: %s%lu%s\n", CBG, i, CNN); |
|---|
| 118 | } |
|---|
| 119 | sprintf( line, "%s-%05.5lX-%s ", CBZ, i + base, CNN); |
|---|
| 120 | break; |
|---|
| 121 | |
|---|
| 122 | case 8: |
|---|
| 123 | strcat( line, " "); |
|---|
| 124 | break; |
|---|
| 125 | |
|---|
| 126 | default: |
|---|
| 127 | break; |
|---|
| 128 | } |
|---|
| 129 | c = *s; |
|---|
| 130 | ascii[n] = TxPrintable(c); |
|---|
| 131 | sprintf( hex, " %02.2x", (int) c & 0xff); |
|---|
| 132 | strcat( line, hex); |
|---|
| 133 | } |
|---|
| 134 | if (n < 8) |
|---|
| 135 | { |
|---|
| 136 | strcat( line, " "); // middle column |
|---|
| 137 | } |
|---|
| 138 | for (; n < 15; n++) |
|---|
| 139 | { |
|---|
| 140 | strcat( line, " "); // fill rest with spaces |
|---|
| 141 | } |
|---|
| 142 | TxPrint( "%s %s[%s%s%s]%s\n", // ascii on last line |
|---|
| 143 | line, CNC, CNN, ascii, CNC, CNN); |
|---|
| 144 | } |
|---|
| 145 | } // end 'TxDisplayHex' |
|---|
| 146 | /*---------------------------------------------------------------------------*/ |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | /*****************************************************************************/ |
|---|
| 150 | // Return ascii printable character, conservative small reange |
|---|
| 151 | /*****************************************************************************/ |
|---|
| 152 | char TxPrintable // RET printable character |
|---|
| 153 | ( |
|---|
| 154 | char c // IN character |
|---|
| 155 | ) |
|---|
| 156 | { |
|---|
| 157 | if (isprint(c)) |
|---|
| 158 | { |
|---|
| 159 | return (c); |
|---|
| 160 | } |
|---|
| 161 | else |
|---|
| 162 | { |
|---|
| 163 | return ('.'); |
|---|
| 164 | } |
|---|
| 165 | } // end 'TxPrintable' |
|---|
| 166 | /*---------------------------------------------------------------------------*/ |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | /*****************************************************************************/ |
|---|
| 170 | // Return ascii printable character, widest safe range |
|---|
| 171 | /*****************************************************************************/ |
|---|
| 172 | char TxPrintSafe // RET printable character |
|---|
| 173 | ( |
|---|
| 174 | char c // IN character |
|---|
| 175 | ) |
|---|
| 176 | { |
|---|
| 177 | if ((c!=0x00) && (c!=0x07) && (c!=0x08) && (c!=0x09) && |
|---|
| 178 | (c!=0x0a) && (c!=0x0c) && (c!=0x0d) && (c!=0x1a) && (c!=0x1b)) |
|---|
| 179 | { |
|---|
| 180 | return (c); |
|---|
| 181 | } |
|---|
| 182 | else |
|---|
| 183 | { |
|---|
| 184 | return ('ú'); |
|---|
| 185 | } |
|---|
| 186 | } // end 'TxPrintSafe' |
|---|
| 187 | /*---------------------------------------------------------------------------*/ |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | /*****************************************************************************/ |
|---|
| 191 | // Output textual info in array of char-pointers, add newlines in-between |
|---|
| 192 | /*****************************************************************************/ |
|---|
| 193 | void TxShowTxt |
|---|
| 194 | ( |
|---|
| 195 | char *txt[] // IN text to display |
|---|
| 196 | ) |
|---|
| 197 | { |
|---|
| 198 | char **s; |
|---|
| 199 | |
|---|
| 200 | for (s = txt; s && (*s != NULL); s++) |
|---|
| 201 | { |
|---|
| 202 | TxPrint( "%s%s", (s!= txt) ? "\n": "", *s); |
|---|
| 203 | } |
|---|
| 204 | } // end 'TxShowTxt' |
|---|
| 205 | /*---------------------------------------------------------------------------*/ |
|---|