/* uint/graphic/ascart.c librock_CHISEL _summary ASCII art reading/manipulation Copyright (c) 2001-2002, Forrest J. Cavalier III, doing business as Mib Software, Saylorsburg Pennsylvania USA Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifdef librock_NOTLIBROCK /**************************************************************/ /* ABOUT THIS FILE: GUIDE TO QUICK REUSE WITHOUT REWORK This file uses many preprocessor conditional blocks and features to publish http://www.mibsoftware.com/librock/ You can disable those features with little or no editing, and reuse this file: 1. At compile time, enable this conditional block by defining the preprocessor symbol librock_NOTLIBROCK, either with a compiler command line parameter, or as a #define in a source file which then #includes this source file. 2. Define any preprocessor symbols in this block (if any) appropriately for your machine and compilation environment. 3. Copy and use the declarations from this block in your source files as appropriate. This file is originally from the librock library, which is Free (libre), free (no cost), rock-stable API, and works on gcc/MSVC/Windows/Linux/BSD/more. Get originals, updates, license certificates, more, at http://www.mibsoftware.com/librock/ (Change log appears at end of this file.) */ #define librock_ISOLATED #define librock_PTR #define librock_CONST const /**************************************************************/ #endif #ifndef librock_ISOLATED /**************************************************************/ #define librock_IMPLEMENT_ascart #include #include /**************************************************************/ #endif #ifdef librock_IMPL_LIDESC #ifndef librock_NOIMPL_LIDESC_ascart /**************************************************************/ #include /* librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45 */ void *librock_LIDESC_ascart[] = { "\n" __FILE__ librock_LIDESC_librock "\n", 0 }; /**************************************************************/ #endif #endif #ifndef librock_WRAP /**************************************************************/ #define librock_body_bits_from_ASCIIart librock_bits_from_ASCIIart /* For librock_WRAP section */ /**************************************************************/ #endif #ifndef librock_NOIMPL_bits_from_ASCIIart /**************************************************************/ #define librock_FNTYPE_bits_from_ASCIIart fnv_S_s_i void librock_body_bits_from_ASCIIart(char librock_PTR * pdest, librock_CONST char librock_PTR * psrc, int cnt) {/* Copyright 1998-2001, Forrest J. Cavalier III d-b-a Mib Software Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block. License, originals, details: http://www.mibsoftware.com/librock/ */ #ifdef librock_MANUAL_bits_from_ASCIIart /* librock_bits_from_ASCIIart - Store 1's and 0's into a bit vector for each non-space in a string. */ /**/ #include void librock_bits_from_ASCIIart(char librock_PTR * pdest, /* Destination bit vector */ const char librock_PTR * psrc, int cnt /* Number of characters at psrc */ ); /* Create a bit vector based on the contents of a string. For every ASCII space (' '), store a 0, otherwise store a 1 into the bits of a char[], with the 0x80 position treated as the first bit. The caller has to manage the storage at pdest and psrc. Typical use would be to convert an ASCII-art (e.g. picture drawn with a text editor) into a bitmap. */ #ifdef librock_TYPICAL_USE_bits_from_ASCIIart char dest; librock_bits_from_ASCIIart(&dest," A X XX ",8); printf("%02x\n",dest); #endif /* // No external calls. */ /* Copyright 1998-2002 Forrest J. Cavalier III, http://www.mibsoftware.com Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block. License text in librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45 */ #endif /* MANUAL */ /*-------------------------------------------*/ int mask = 0x80; while(cnt > 0) { if (*psrc > ' ') { *pdest |= mask; } else { *pdest &= ~mask; } mask >>= 1; if (!mask) { mask = 0x80; pdest++; } if (*psrc) { psrc++; } cnt--; } } /* ASCIIarttobits */ /**************************************************************/ #endif /* NOIMP section */ /* $Log: ascart.c,v $ Revision 1.8 2002/08/01 16:52:38 forrest@mibsoftware.com rights=#1 Updated TYPICAL_USE section. Added NOTLIBROCK section. Moved CVS log to end. Changed LIDESC MD5 to HC. Revision 1.7 2002/04/09 03:19:46 forrest@mibsoftware.com rights=#1 Fix FNTYPE. Update Man page. Revision 1.6 2002/04/06 04:02:25 forrest@mibsoftware.com rights=#1 FNTYPE decls for test. Revision 1.5 2002/02/06 13:59:13 forrest@mibsoftware.com rights=#1 Standardized chg log Revision 1.4 2002/01/30 16:08:35 forrest@mibsoftware.com rights=#1 Renamed some .h files Revision 1.3 2002/01/29 04:40:36 forrest@mibsoftware.com rights=#1 Remove tab Revision 1.2 2002/01/26 16:19:25 forrest@mibsoftware.com rights=#1 Prep for publication. Revision 1.1 2001/10/18 20:46:54 forrest@mibsoftware.com rights=#1 Initial commit rights#1 Copyright (c) Forrest J Cavalier III d-b-a Mib Software rights#1 License text in librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45 */