/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#include "vchhdr.h"
**
** Written by Kiem-Phong Vo
*/
#if __STD_C
static ssize_t rlcode(ssize_t nsym, ssize_t* clen, ssize_t cmax, Vcchar_t* rle, ssize_t rlsz, int encode)
#else
int encode;
#endif
{
if(encode)
{ for(k = 0; k < nsym; k = n)
{ d = clen[k];
for(n = k+1; n < nsym; ++n)
if(clen[n] != d)
break;
if((r = n-k) >= 3)
*rl++ = d;
}
else for(r = k; r < n; ++r)
}
}
else
clen[k++] = d;
if(r > 0)
return -1;
}
else if(d <= cmax)
clen[k++] = d;
else return -1;
}
return -1;
}
}
#if __STD_C
#else
#endif
{
Vcbit_t b;
return -1;
/* # of bits used to output the code table for this coding */
/* run-length-encode the code table in the alphabet [0...maxs+2] */
return -1;
}
for(k = 0; k < nl; ++k)
{ if((n + cs) > VC_BITSIZE)
}
}
#if __STD_C
#else
#endif
{
Vcbit_t b;
return -1;
/* # of bits used to output the code table for this coding */
/* The length of the rle sequence should have been coded with vcioputu()
** so it could be decoded by simply using vciogetu(). However, an older
** and buggy version used vcioputc() and could not handle values >= 256.
** The below loop tries to detect and handle those old cases.
*/
for(i = 0; i < 2; i += 1)
if(i == 0) /* try the current coding first */
continue; /* likely old data */
}
else /* could be the old buggy coding */
}
for(k = 0; k < nl; ++k) /* read the rle sequence */
}
/* now see if clen[] can be reconstructed */
}
}
return -1;
}