Subversion Repositories QNX 8.QNX8 IFS tool

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /* ucl_util.c -- utilities for the UCL library
  2.  
  3.    This file is part of the UCL data compression library.
  4.  
  5.    Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
  6.    All Rights Reserved.
  7.  
  8.    The UCL library is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU General Public License as
  10.    published by the Free Software Foundation; either version 2 of
  11.    the License, or (at your option) any later version.
  12.  
  13.    The UCL library is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with the UCL library; see the file COPYING.
  20.    If not, write to the Free Software Foundation, Inc.,
  21.    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22.  
  23.    Markus F.X.J. Oberhumer
  24.    <markus@oberhumer.com>
  25.    http://www.oberhumer.com/opensource/ucl/
  26.  */
  27.  
  28.  
  29. #include "ucl_conf.h"
  30.  
  31.  
  32. /***********************************************************************
  33. //
  34. ************************************************************************/
  35.  
  36. UCL_PUBLIC(ucl_bool)
  37. ucl_assert(int expr)
  38. {
  39.     return (expr) ? 1 : 0;
  40. }
  41.  
  42.  
  43. /***********************************************************************
  44. //
  45. ************************************************************************/
  46.  
  47. /* If you use the UCL library in a product, you *must* keep this
  48.  * copyright string in the executable of your product.
  49. .*/
  50.  
  51. static const char __ucl_copyright[] =
  52.     "\r\n\n"
  53.     "UCL data compression library.\n"
  54.     "$Copyright: UCL (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Markus Franz Xaver Johannes Oberhumer\n"
  55.     "<markus@oberhumer.com>\n"
  56.     "http://www.oberhumer.com $\n\n"
  57.     "$Id: UCL version: v" UCL_VERSION_STRING ", " UCL_VERSION_DATE " $\n"
  58.     "$Built: " __DATE__ " " __TIME__ " $\n"
  59.     "$Info: " ACC_INFO_OS
  60. #if defined(ACC_INFO_OS_POSIX)
  61.     "/" ACC_INFO_OS_POSIX
  62. #endif
  63.     " " ACC_INFO_ARCH
  64. #if defined(ACC_INFO_ENDIAN)
  65.     "/" ACC_INFO_ENDIAN
  66. #endif
  67.     " " ACC_INFO_MM
  68.     " " ACC_INFO_CC
  69. #if defined(ACC_INFO_CCVER)
  70.     " " ACC_INFO_CCVER
  71. #endif
  72.     " $\n";
  73.  
  74. UCL_PUBLIC(const ucl_bytep)
  75. ucl_copyright(void)
  76. {
  77. #if (ACC_OS_DOS16 && ACC_CC_TURBOC)
  78.     return (ucl_voidp) __ucl_copyright;
  79. #else
  80.     return (const ucl_bytep) __ucl_copyright;
  81. #endif
  82. }
  83.  
  84. UCL_PUBLIC(ucl_uint32)
  85. ucl_version(void)
  86. {
  87.     return UCL_VERSION;
  88. }
  89.  
  90. UCL_PUBLIC(const char *)
  91. ucl_version_string(void)
  92. {
  93.     return UCL_VERSION_STRING;
  94. }
  95.  
  96. UCL_PUBLIC(const char *)
  97. ucl_version_date(void)
  98. {
  99.     return UCL_VERSION_DATE;
  100. }
  101.  
  102. UCL_PUBLIC(const ucl_charp)
  103. _ucl_version_string(void)
  104. {
  105.     return UCL_VERSION_STRING;
  106. }
  107.  
  108. UCL_PUBLIC(const ucl_charp)
  109. _ucl_version_date(void)
  110. {
  111.     return UCL_VERSION_DATE;
  112. }
  113.  
  114.  
  115. /***********************************************************************
  116. // adler32 checksum
  117. // adapted from free code by Mark Adler <madler@alumni.caltech.edu>
  118. // see http://www.cdrom.com/pub/infozip/zlib/
  119. ************************************************************************/
  120.  
  121. #define UCL_BASE 65521u /* largest prime smaller than 65536 */
  122. #define UCL_NMAX 5552
  123. /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
  124.  
  125. #define UCL_DO1(buf,i)  {s1 += buf[i]; s2 += s1;}
  126. #define UCL_DO2(buf,i)  UCL_DO1(buf,i); UCL_DO1(buf,i+1);
  127. #define UCL_DO4(buf,i)  UCL_DO2(buf,i); UCL_DO2(buf,i+2);
  128. #define UCL_DO8(buf,i)  UCL_DO4(buf,i); UCL_DO4(buf,i+4);
  129. #define UCL_DO16(buf,i) UCL_DO8(buf,i); UCL_DO8(buf,i+8);
  130.  
  131. UCL_PUBLIC(ucl_uint32)
  132. ucl_adler32(ucl_uint32 adler, const ucl_bytep buf, ucl_uint len)
  133. {
  134.     ucl_uint32 s1 = adler & 0xffff;
  135.     ucl_uint32 s2 = (adler >> 16) & 0xffff;
  136.     int k;
  137.  
  138.     if (buf == NULL)
  139.         return 1;
  140.  
  141.     while (len > 0)
  142.     {
  143.         k = len < UCL_NMAX ? (int) len : UCL_NMAX;
  144.         len -= k;
  145.         if (k >= 16) do
  146.         {
  147.             UCL_DO16(buf,0);
  148.             buf += 16;
  149.             k -= 16;
  150.         } while (k >= 16);
  151.         if (k != 0) do
  152.         {
  153.             s1 += *buf++;
  154.             s2 += s1;
  155.         } while (--k > 0);
  156.         s1 %= UCL_BASE;
  157.         s2 %= UCL_BASE;
  158.     }
  159.     return (s2 << 16) | s1;
  160. }
  161.  
  162.  
  163. /*
  164. vi:ts=4:et
  165. */
  166.