求助: Unix下.Z文件解压 的delphi 实现方法(100分)

  • 主题发起人 主题发起人 eagle_l
  • 开始时间 开始时间
E

eagle_l

Unregistered / Unconfirmed
GUEST, unregistred user!
以下是C++下面的解压部分代码,但小弟看不懂

int nextcode(INTCODE *codeptr, COMP_PARAMS *pparams)
/* Get the next code from input and put it in *codeptr.
* Return (TRUE) on success, or return (FALSE) on end-of-file.
* Adapted from COMPRESS V4.0.
*/
{
register INTCODE code;
//static int size;
//static UCHAR inbuf[MAXBITS];
register int shift;
UCHAR *bp;

/* If the next entry is a different bit-size than the preceeding one
* then we must adjust the size and scrap the old buffer.
*/
if (pparams->prevbits != pparams->bits) {
pparams->prevbits = pparams->bits;
pparams->size = 0;
}
/* If we can't read another code from the buffer, then refill it.
*/
if (pparams->size - (shift = pparams->offset) < pparams->bits) {
/* Read more input and convert size from # of bytes to # of bits */
if ((pparams->size = fread(pparams->inbuf, 1, pparams->bits, pparams->fp_zip) << 3) <= 0 || ferror(pparams->fp_zip))
return(NO);
pparams->offset = shift = 0;
}
/* Get to the first byte. */
bp = pparams->inbuf + (shift >> 3);
/* Get first part (low order bits) */
code = (*bp++ >> (shift &amp;= 7));
/* high order bits. */
code |= *bp++ << (shift = 8 - shift);
if ((shift += 8) < pparams->bits) code |= *bp << shift;
*codeptr = code &amp; pparams->highcode;
pparams->offset += pparams->bits;
return (TRUE);
}

int uncompress(COMP_PARAMS *pparams)
{
register int i;
register INTCODE code;
char sufxchar;
INTCODE savecode;
FLAG fulltable, cleartable;
static char *token= NULL; /* String buffer to build token */
static int maxtoklen = MAXTOKLEN;

exit_stat = OK;

/* Initialze the token buffer. */
if (token == NULL &amp;&amp; (token = (char*)malloc(maxtoklen)) == NULL) {
exit_stat = NOMEM;
return NOMEM;
}

if (alloc_tables(pparams->maxcode = ~(~(INTCODE)0 << pparams->maxbits),0, pparams)) /* exit_stat already set */
return NOMEM;

/* if not zcat or filter */
if(is_list &amp;&amp; !zcat_flg) { /* Open output file */
//if (freopen(ofname, WRITE_FILE_TYPE, pparams->fp_src) == NULL) {
// exit_stat = NOTOPENED;
//return NOTOPENED;
//}
//if (!quiet)
// fprintf(stderr, "%s: ",ifname);
//setvbuf(pparams->fp_src,xbuf,_IOFBF,XBUFSIZE);
}
cleartable = TRUE;
savecode = CLEAR;
pparams->offset = 0;
do {
if ((code = savecode) == CLEAR &amp;&amp; cleartable) {
pparams->highcode = ~(~(INTCODE)0 << (pparams->bits = INITBITS));
fulltable = FALSE;
pparams->nextfree = (cleartable = pparams->block_compress) == FALSE ? 256 : FIRSTFREE;
if (!nextcode(&amp;pparams->prefxcode, pparams))
break;
fputc((sufxchar = (char)pparams->prefxcode), pparams->fp_src);
continue;
}
i = 0;
if (code >= pparams->nextfree &amp;&amp; !fulltable) {
if (code != pparams->nextfree){
exit_stat = CODEBAD;
return CODEBAD ; /* Non-existant code */
}
/* Special case for sequence KwKwK (see text of article) */
code = pparams->prefxcode;
token[i++] = sufxchar;
}
/* Build the token string in reverse order by chasing down through
* successive prefix tokens of the current token. Then output it.
*/
while (code >= 256) {
# ifdef DEBUG
/* These are checks to ease paranoia. Prefix codes must decrease
* monotonically, otherwise we must have corrupt tables. We can
* also check that we haven't overrun the token buffer.
*/
if (code <= (INTCODE)prefix(code)){
exit_stat= TABLEBAD;
return TABLEBAD;
}
# endif
if (i >= maxtoklen) {
maxtoklen *= 2; /* double the size of the token buffer */
if ((token = (char *)realloc(token, maxtoklen)) == NULL) {
exit_stat = TOKTOOBIG;
return TOKTOOBIG;
}
}
token[i++] = suffix(code);
code = (INTCODE)prefix(code);
}
fputc(sufxchar = (char)code, pparams->fp_src);
while (--i >= 0)
fputc(token, pparams->fp_src);
if (ferror(pparams->fp_src)) {
exit_stat = WRITEERR;
return WRITEERR;
}
/* If table isn't full, add new token code to the table with
* codeprefix and codesuffix, and remember current code.
*/
if (!fulltable) {
code = pparams->nextfree;
assert(256 <= code &amp;&amp; code <= pparams->maxcode);
prefix(code) = (CODE)pparams->prefxcode;
suffix(code) = sufxchar;
pparams->prefxcode = savecode;
if (code++ == pparams->highcode) {
if (pparams->highcode >= pparams->maxcode) {
fulltable = TRUE;
--code;
}
else {
++pparams->bits;
pparams->highcode += code; /* pparams->nextfree == pparams->highcode + 1 */
}
}
pparams->nextfree = code;
}
} while (nextcode(&amp;savecode, pparams));
exit_stat = (ferror(pparams->fp_zip))? READERR : OK;
return exit_stat;
}

 
有哪位高手请帮帮忙啊
 
如果分数不够可以再加
 
delphi好像只在windows和linux(Kylix)两个平台下能用。
没听过unix下的delphi。
你说的不会是用object pascal重写上述代码吧
 
后退
顶部