home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 February / PCO_0299.ISO / filesbbs / dos / indigo01.exe / SHORTTAG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-21  |  1.7 KB  |  51 lines

  1. // This program is free software; you can redistribute it and/or modify it
  2. // under the terms of the GNU General Public License as published by the Free
  3. // Software Foundation; either version 2 of the License, or (at your option)
  4. // any later version.
  5.  
  6. // You should have received a copy of the GNU General Public License along
  7. // with this program; if not, write to the Free Software Foundation, Inc., 675
  8. // Mass Ave, Cambridge, MA 02139, USA.
  9.  
  10. // shorttag.cpp
  11. // Truncate an echotag so that it fits the Blue Wave .inf record.
  12.  
  13. #include "crc32.h"
  14. #include "shorttag.h"
  15. #include "datatyp.h"
  16. #include <string.h>
  17. #include <stdio.h>
  18.  
  19. // makeShortTag
  20. // Truncate an echotag so that it fits the Blue Wave .inf record. Since
  21. // there might be clashes if we just chopped it off, we calculate a
  22. // crc value on the tag, and include it as characters.
  23. const char *makeShortTag(const char *longTag)
  24. {
  25.     // Initialize our short tag.
  26.     static char crctag[21] = " ";
  27.  
  28.     // If the tag is already short enough, don't do anything with it.
  29.     if (strlen(longTag) < 21)
  30.         return longTag;
  31.  
  32.     // Calculate the CRC32 value of the echotag.
  33.     UINT32 tagcrc = 0xffffffff;
  34.     const char *c_p;
  35.     char *c2_p;
  36.     for (c_p = longTag; *c_p; c_p ++)
  37.         tagcrc = UPDC32(*c_p, tagcrc);
  38.  
  39.     // Convert the CRC32 value to printable characters.
  40.     for (c2_p = &crctag[1]; tagcrc; tagcrc >>= 6)
  41.         *(c2_p ++) = (tagcrc & 0x3F) + '!';
  42.     // And then put what of the echotag that fits after it. This should
  43.     // make the tags unique.
  44.     for (c_p = longTag; c2_p < &crctag[20];)
  45.         *(c2_p ++) = *(c_p ++);
  46.     *c2_p = 0;
  47.  
  48.     // Return the truncated tag.
  49.     return crctag;
  50. }
  51.