Changeset 137 in project


Ignore:
Timestamp:
01/20/06 12:08:15 (15 years ago)
Author:
felix winkelmann
Message:

z3 update, ajax-dep. on message-digest

Files:
2 added
17 edited

Legend:

Unmodified
Added
Removed
  • ajax/ajax.meta

    r1 r137  
    33((egg "ajax.egg")
    44 (synopsis "Using xmlHttpRequest with the Spiffy web-server")
    5  (needs md5 url spiffy)
     5 (needs message-digest md5 url spiffy)
    66 (category web)
    77 (license "MIT")
  • z3/makefile

    r108 r137  
    11#!/usr/bin/make
    22
    3 Z3_VERSION = 0.13
     3Z3_VERSION = 1.0
    44DATE = $(shell date +%Y-%m-%d)
    55
     
    3636TESTS = $(TESTSD)
    3737endif
    38 MAN3 = z3lib.3 z3flib.3
     38MAN3 = z3lib.3 z3dlib.3 z3flib.3
    3939MAN = $(MAN3)
    4040GENERATED = $(TARGETS) $(OBJECTS) $(TESTS) z3lib-$(Z3_VERSION).tar.gz
    4141TESTADD = makefile z3crc32.h z3liblib.h
    42 ALLSRC = COPYING $(TESTADD) $(SOURCES) $(HEADERS) $(addsuffix .c,$(TESTS)) \
     42LICENCE = COPYING BSD-LICENCE
     43ALLSRC = $(LICENCE) $(TESTADD) $(SOURCES) $(HEADERS) $(addsuffix .c,$(TESTS)) \
    4344        $(MAN)
    4445
  • z3/z3.scm

    r120 r137  
    5050};
    5151
    52 /*
    53  * initialise decompression
    54  * input:
    55  *    pending_bits, pending_nb: a number of bits pending from previous
    56  *      decoding activity, and its number. Initially 0.
    57  *    memory, memsize: memory reserved for the decompressor, memsize shall
    58  *      be and must not be less than Z3DD_MEMSIZE
    59  */
    6052struct z3dd_handle *z3d_decode_init(unsigned int pending_bits, int pending_nb, ___scheme_pointer memory, unsigned int memsize);
    61 
    62 /*
    63  * call z3d_decode repeatedly, until it returns NULL
    64  * input:
    65  *    code, codesize: a number of bytes that are available to decompress
    66 
    67  * output:
    68  *    error: error code, see z3error.h
    69  *    pending_bits, pending_nb: a number of bits finally pending
    70  *    taken: the number of bytes actually taken from code, in range 0..codesize
    71  *    data: a pointer to a number of bytes readily decompressed
    72  *    given: the number of bytes available at the data pointer
    73  * return:
    74  *    NULL upon error or at end of compression, whereupon taken, data and given
    75  *    are not valid
    76  */
    7753struct z3dd_handle *z3d_decode_relative(___scheme_pointer zh, ___out int *error,
    7854                        ___out unsigned int *pending_bits, ___out int *pending_nb,
     
    8056                        ___out unsigned int *index, ___out unsigned int *given);
    8157
    82 /*
    83  * initialise compression
    84  * input:
    85  *    memory, memsize: memory reserved for the compressor, memsize must not
    86  *      be less then Z3DE_MEMSIZE_MIN, (e.g. Z3DE_MEMSIZE_MIN + 65402)
    87  *    tellwhen: frequency for code size estimation and block close
    88  *      decision. 0 for none (i.e. full block usage always), minimum
    89  *      value is Z3DE_SLICE_MIN
    90  *    thrmin: threshold for block close decision, in range
    91  *      0..Z3DE_THRESHOLD_ONE (on behalf of rational range 0..1); a block
    92  *      will be closed when compression ratio is less than all previously
    93  *      determined ratios times thrmin/Z3DE_THRESHOLD_ONE (e.g. 127)
    94  *    thrmax: similar to thrmin, a block will be close, when compression ratio
    95  *      is greater than all previously determined ratios times
    96  *      Z3DE_THRESHOLD_ONE/thrmax (e.g. 153)
    97  *    initialgrant: for threshold comparision, all but the first slice are
    98  *      asumed to be incremented by this value to roughly compensate
    99  *      rfc 1951 block dynamic table size (e.g. 30)
    100  *    preferlonger: when non-zero, the compressor will try to find a longer
    101  *      match at n+1 and prefer it over a previous match at n
    102  */
    10358struct z3de_handle *z3d_encode_init(___scheme_pointer memory, unsigned int memsize,
    10459                        unsigned int tellwhen,
    10560                        int thrmin, int thrmax, int initialgrant,
    106                         ___bool preferlonger);
    107 
    108 /*
    109  * call z3d_encode repeatedly, until it returns NULL
    110  * input:
    111  *    data, datasize: a number of bytes that are available to compress
    112  *      datasize must be greater than 0 unless end of data is reached
    113  *    codesize: space available in code buffer
    114  * output:
    115  *    taken: number of bytes actually taken from data buffer,
    116  *      in range 0..datasize
    117  *    code: a number of compressed bytes are stored hereto
    118  *    given: the number of bytes stored into the code buffer,
    119  *      in range 0..codesize
    120  * return:
    121  *    NULL upon end of compression, whereupon all output variables are
    122  *    still valid
    123  */
     61                        ___bool preferlonger, ___bool limitlength3);
     62
    12463struct z3de_handle *z3d_encode(___scheme_pointer zh,
    12564                        ___scheme_pointer data, unsigned int datasize, ___out unsigned int *taken,
    12665                        ___scheme_pointer code, unsigned int codesize, ___out unsigned int *given);
    12766
    128 /*
    129  * initialise compression
    130  * input:
    131  *    filedescr: unix file descriptor, referring to a file previously opened
    132  *      for writing
    133  *    level: compression level desired, in range 1..9, or 0 for default
    134  *    mtime: time_t seconds since 1970/01/01 00:00:00
    135  *    os: operating system indicator byte, -1 when unknown
    136  *    xlen: number of bytes in field fextra, when given
    137  *    fextra: array of xlen bytes to be included in header, or NULL
    138  *    fname: zero terminated name string, or NULL
    139  *    fcomment: zero terminated comment string, or NULL
    140  * return:
    141  *    0 on success, negative on error (see errno.h)
    142  */
    14367___fixnum z3f_encode_init(int filedescr, ___scheme_pointer zh, ___fixnum level,
    14468                        long mtime, ___fixnum os,
     
    14670                        char *fname, char *fcomment);
    14771
    148 /*
    149  * insert header fields, when needed, where the parameters should be
    150  * those given to z3f_encode_init before and stay constant;
    151  * call this function repeated, as long as it returns -EAGAIN
    152  * return:
    153  *   0 on success,
    154  *   -EAGAIN when the function needs to be called again
    155  *   other negative codes on error (see errno.h)
    156  */
    15772___fixnum z3f_encode_header(___scheme_pointer zh, ___fixnum xlen, ___scheme_pointer fextra,
    15873                                              char *fname, char *fcomment);
    159 
    160 /*
    161  * write compressed data to file, compress according to rfc1952
    162  * input:
    163  *    data: a pointer to uncompressed data, to be compressed and written
    164  *    count: number of bytes available at data
    165  * return:
    166  *    number of bytes written from data buffer,
    167  *    0 on end of file,
    168  *    -EAGAIN when function needs to be called again,
    169  *    other negative codes on error (see errno.h)
    170  */
    17174___fixnum z3f_encode_write(___scheme_pointer zh, ___scheme_pointer data, long count);
    172 
    173 /*
    174  * initialise decompression
    175  * input:
    176  *    filedescr: unix file descriptor, referring to a file previously opened
    177  *      for reading
    178  * return:
    179  *    0 on success, negative on error (see errno.h)
    180  */
    18175___fixnum z3f_decode_init(___fixnum filedescr, ___scheme_pointer zh);
    182 
    183 /*
    184  * read compressed data from file, decompress according to rfc1952
    185  * input:
    186  *    count: space available in read buffer, in bytes
    187  * output:
    188  *    data: a pointer where to store decompressed bytes, not more than count
    189  * return:
    190  *    number of bytes read into data buffer,
    191  *    0 on end of file,
    192  *    -EAGAIN when function needs to be called again,
    193  *    other negative codes on error (see errno.h)
    194  */
    19576___fixnum z3f_decode_read(___scheme_pointer zh, ___scheme_pointer data, long count);
    19677<#
     
    20081(define-foreign-variable Z3DE_MEMSIZE_MIN int)
    20182(define-foreign-variable Z3DE_THRESHOLD_ONE int)
     83(define-foreign-variable Z3BE_MEMSIZE_EXTRA3 int)
    20284
    20385(define errors
     
    252134                        (buffer (make-string 4096))
    253135                        (buffer-size (string-length buffer))
    254                         (memsize (+ Z3DE_MEMSIZE_MIN 65402)) ;???
     136                        (memsize (+ Z3DE_MEMSIZE_MIN 65402 Z3BE_MEMSIZE_EXTRA3)) ;???
    255137                        (tellwhen Z3DE_SLICE_MIN)
    256                         (thrmin 127)
    257                         (thrmax 153)
    258                         (initialgrant 30)
     138                        (thrmin 77)
     139                        (thrmax 77)
     140                        (initialgrant 13)
    259141                        preferlonger)
    260142  (let ((buffer (make-string memsize)))
    261     (unless (z3d_encode_init buffer memsize tellwhen thrmin thrmax initialgrant preferlonger)
     143    (unless (z3d_encode_init buffer memsize tellwhen thrmin thrmax initialgrant preferlonger #t)
    262144      (z3:error 'z3:encode-init z3:error-none "initialization failed"))
    263145    (make-z3:handle buffer (make-string 4096) #t) ) )
  • z3/z3betest.c

    r108 r137  
    66#endif
    77
    8 #include "z3blib.c"
    9 #include "z3crc32.h"
    10 
    118#include <unistd.h>
    129#include <stdio.h>
    1310#include <time.h>
     11
     12#include "z3blib.c"
     13#include "z3crc32.h"
    1414
    1515#undef D
     
    2424  char data[4096];
    2525  char code[4096];
    26   char mem[Z3BE_MEMSIZE_MIN];
     26  char mem[Z3BE_MEMSIZE_MIN + Z3BE_MEMSIZE_EXTRA3];
    2727  unsigned long crctab[256];
    2828  gen_crc32_table(&crctab[0]);
     
    5050    i += w;
    5151  } while (i < 10);
    52   zh = z3be_start(&mem[0], sizeof(mem), 1);
     52  zh = z3be_start(&mem[0], sizeof(mem), 1, 1);
    5353#ifdef D
    5454  fprintf(stderr, "z3be_start(%p, %d): %p\n", &mem[0], sizeof(mem), zh);
  • z3/z3blib.c

    r108 r137  
    11/*
    2  * z3lib (c)1993,2000,2005/GPL Oskar Schirmer, schirmer@scara.com
     2 * z3lib (c)1993,2000,2005,2006/GPL,BSD Oskar Schirmer, schirmer@scara.com
    33 * combined huffman/lz compression library
    44 * now rfc1951 conformant
     
    1111
    1212// #define D(x) x
    13 #define DE(X)
    14 //#define DD
     13#define DE(x)
    1514
    1615#ifndef D
     
    2423#ifndef Z3LIB_DECODE_ONLY
    2524#define z3be_data(zh,i) z3relref(__u8, (zh)->data)[((__s32)(i))]
     25#define z3be_histogram3(zh,bits,code) \
     26        z3relref(__u32, (zh)->histogram3)[((bits)<<8)+(code)]
     27#define z3be_distances3(zh,dist) z3be_histogram3(zh,Z3BE_REF3TOOLARGE_MAX,dist)
    2628
    2729struct z3be_handle *z3be_start(void *memory, unsigned int memsize,
    28                         int preferlonger)
     30                        int preferlonger, int limitlength3)
    2931{
    3032  struct z3be_handle *zh;
    3133  unsigned int size;
    32   if ((memory == NULL) || (memsize < Z3BE_MEMSIZE_MIN)) {
     34  if ((memory == NULL)
     35   || (memsize < (limitlength3 ?
     36        (Z3BE_MEMSIZE_MIN + Z3BE_MEMSIZE_EXTRA3) : Z3BE_MEMSIZE_MIN))) {
    3337    return NULL;
    3438  }
     
    3741  if (size > (1UL << 23)) {
    3842    size = (1UL << 23);
     43  }
     44  if (limitlength3) {
     45    size -= Z3BE_MEMSIZE_EXTRA3;
     46    z3relrefset(zh->histogram3, zh->mem[size]);
     47    memset(&zh->mem[size], 0, Z3BE_MEMSIZE_EXTRA3);
     48  } else {
     49    zh->histogram3 = NULL;
    3950  }
    4051  zh->limitwp = zh->dsize = size/2;
     
    152163}
    153164
    154 static void z3be_histogram_reference(struct z3be_histogram *h, __u32 length,
    155                                         __u32 distance)
    156 {
    157   h->literal[z3be_class_length(length)] += 1;
    158   h->distance[z3be_class_distance(distance)] += 1;
     165static void z3be_histogram_ref3(struct z3be_handle *zh, __u32 distclass,
     166                                        __u8 *data)
     167{
     168  __u32 c;
     169  if (distclass >= (Z3B_NBDISTANCECODES - 2 * Z3BE_REF3TOOLARGE_MAX)) {
     170    c = distclass - (Z3B_NBDISTANCECODES - 2 * Z3BE_REF3TOOLARGE_MAX);
     171    z3be_distances3(zh, c) += 1;
     172    c /= 2;
     173    z3be_histogram3(zh, c, data[0]) += 1;
     174    z3be_histogram3(zh, c, data[1]) += 1;
     175    z3be_histogram3(zh, c, data[2]) += 1;
     176  }
     177}
     178
     179static void z3be_histogram_reference(struct z3be_handle *zh, __u32 length,
     180                                        __u32 distance, __u8 *data)
     181{
     182  __u32 c;
     183  zh->histogram.literal[z3be_class_length(length)] += 1;
     184  c = z3be_class_distance(distance);
     185  zh->histogram.distance[c] += 1;
     186  if ((zh->histogram3 != NULL)
     187   && (length == 3)) {
     188    z3be_histogram_ref3(zh, c, data);
     189  }
    159190}
    160191
     
    168199DE({int x=0;do{if(z3be_data(zh,i+x)!=z3be_data(zh,zh->match+x))fprintf(stderr,"reference ERROR 3: data[%d+%d]=%02x,data[%d+%d]=%02x\n",i,x,z3be_data(zh,i+x),zh->match,x,z3be_data(zh,zh->match+x));}while(++x<len);})
    169200D(fprintf(stderr, "  REF: th=%lu, i=%lu, distance=%lu, length=%lu, data=%02x %02x %02x\n", tabhash, i, l, len, z3be_data(zh, i), z3be_data(zh, i+1), z3be_data(zh, i+2));)
    170   z3be_histogram_reference(&zh->histogram, len, l);
     201  z3be_histogram_reference(zh, len, l, &z3be_data(zh, i));
    171202  zh->mem[i] = (__u8)(l >> 8); /* >=0, mark as reference */
    172203  zh->mem[i+1] = (__u8)l;
     
    230261      }
    231262      h = zh->hashforw[z3b_moddictbits(i + zh->dshift)];
    232 #ifdef DD
    233 if (h < 0) h = 1;
    234 #endif
    235263      if (h < 0) {
    236264        j = Z3B_LZMINLENGTH - h;
     
    330358                }
    331359                h = zh->hashforw[z3b_moddictbits(i + zh->dshift)];
    332 #ifdef DD
    333 if (h < 0) h = 1;
    334 #endif
    335360                if (h < 0) {
    336361                  if ((Z3B_LZMINLENGTH - h) > lr) {
     
    539564  n = 0;
    540565  do {
     566D(fprintf(stderr,"dynh sortindex histo[%3d]:%7d\n",n,histo[n]);)
    541567    iold[n] = n;
    542568  } while (++n < num);
     
    777803}
    778804
    779 __u32 z3be_tell(struct z3be_handle *zh, struct z3be_weighing *weighing,
    780                         __u32 *inpipe)
     805static __u32 z3be_tell_dynamic(struct z3be_handle *zh,
     806                        struct z3be_weighing *weighing, __u32 ref3toolarge)
    781807{
    782808  __u32 n;
    783   if (zh->state == z3be_state_end) {
    784     zh->state = z3be_state_init;
    785   }
    786   weighing->wpos = zh->ipos;
    787809  weighing->histogram = zh->histogram;
    788 D(fprintf(stderr, "TELL wpos=%d, len(nc)=%d\n", weighing->wpos, 8*(weighing->wpos+5));)
    789   weighing->len[Z3B_BTYPE_NC] = 8 * (weighing->wpos + 5);
    790   weighing->len[Z3B_BTYPE_FIXED] = z3be_tell_fixed(&zh->histogram);
    791   z3be_dynamic_histogram(zh, &zh->histogram.literal[0],
     810  weighing->limit3 = ((1 << 7) << ref3toolarge);
     811  while (ref3toolarge < Z3BE_REF3TOOLARGE_MAX) {
     812    n = 0;
     813    do {
     814D(if(z3be_histogram3(zh,ref3toolarge,n)!=0)fprintf(stderr,"TELL DYN(%d) lit[%3d]:%6d + %d\n",ref3toolarge,n,weighing->histogram.literal[n],z3be_histogram3(zh,ref3toolarge,n));)
     815      weighing->histogram.literal[n] += z3be_histogram3(zh, ref3toolarge, n);
     816    } while (++n < (1 << 8));
     817    n = z3be_distances3(zh, 2 * ref3toolarge);
     818    weighing->histogram.distance[2 * ref3toolarge
     819                + (Z3B_NBDISTANCECODES - 2 * Z3BE_REF3TOOLARGE_MAX)] -= n;
     820    weighing->histogram.literal[Z3B_CODEENDOFBLOCK+1] -= n;
     821    n = z3be_distances3(zh, 2 * ref3toolarge + 1);
     822    weighing->histogram.literal[Z3B_CODEENDOFBLOCK+1] -= n;
     823    weighing->histogram.distance[2 * ref3toolarge + 1
     824                + (Z3B_NBDISTANCECODES - 2 * Z3BE_REF3TOOLARGE_MAX)] -= n;
     825    ref3toolarge += 1;
     826  }
     827  z3be_dynamic_histogram(zh, &weighing->histogram.literal[0],
    792828                &weighing->codelen_ll[0], Z3B_NBCODES, 15);
    793   z3be_dynamic_histogram(zh, &zh->histogram.distance[0],
     829  z3be_dynamic_histogram(zh, &weighing->histogram.distance[0],
    794830                &weighing->codelen_dc[0], Z3B_NBDISTANCECODES, 15);
    795831  memset(&zh->temp_tell_clcnt[0], 0, sizeof(zh->temp_tell_clcnt));
     
    810846  n += z3be_dynamic_amount(&zh->temp_tell_clcnt[0],
    811847                &weighing->codelen_clc[0], &z3be_extrabits_clc[0]);
    812   n += z3be_dynamic_amount(&zh->histogram.literal[0],
     848  n += z3be_dynamic_amount(&weighing->histogram.literal[0],
    813849                &weighing->codelen_ll[0], &z3be_extrabits_ll[0]);
    814   n += z3be_dynamic_amount(&zh->histogram.distance[0],
     850  n += z3be_dynamic_amount(&weighing->histogram.distance[0],
    815851                &weighing->codelen_dc[0], &z3be_extrabits_dc[0]);
     852  return n;
     853}
     854
     855__u32 z3be_tell(struct z3be_handle *zh, struct z3be_weighing *weighing,
     856                        __u32 *inpipe)
     857{
     858  __u32 n, c, nb, cb;
     859  if (zh->state == z3be_state_end) {
     860    zh->state = z3be_state_init;
     861  }
     862  weighing->wpos = zh->ipos;
     863D(fprintf(stderr, "TELL wpos=%d, len(nc)=%d\n", weighing->wpos, 8*(weighing->wpos+5));)
     864  weighing->len[Z3B_BTYPE_NC] = 8 * (weighing->wpos + 5);
     865  weighing->len[Z3B_BTYPE_FIXED] = z3be_tell_fixed(&zh->histogram);
     866  if (zh->histogram3 != NULL) {
     867    c = cb = 0;
     868    nb = (__u32)-1;
     869    do {
     870      n = z3be_tell_dynamic(zh, weighing, c);
     871D(fprintf(stderr, "TELL_DYN(%lu) = %lu\n", c, n);)
     872      if (n < nb) {
     873        nb = n;
     874        cb = c;
     875      }
     876    } while (++c <= Z3BE_REF3TOOLARGE_MAX);
     877    if (cb < Z3BE_REF3TOOLARGE_MAX) {
     878      n = z3be_tell_dynamic(zh, weighing, cb);
     879      weighing->histogram = zh->histogram;
     880    }
     881  } else {
     882    n = z3be_tell_dynamic(zh, weighing, Z3BE_REF3TOOLARGE_MAX);
     883  }
    816884  weighing->len[Z3B_BTYPE_DYNAMIC] = n;
    817885D(fprintf(stderr, "TELL len(dyn)=%d\n", n);)
     
    880948{
    881949  __u32 i;
     950  __u8 l;
    882951  if (wpos < zh->dpos) {
    883952    z3lib_memmoveleft(&zh->mem[0], &zh->mem[wpos], zh->dpos - wpos);
     
    888957  i = 0;
    889958  do {
     959DE(if(zh->histogram.literal[i]<histogram->literal[i])fprintf(stderr,"GETLAST ERROR MINUS/L[%3d] %d < %d\n",i,zh->histogram.literal[i],histogram->literal[i]);)
    890960    zh->histogram.literal[i] -= histogram->literal[i];
    891961  } while (++i < Z3B_NBCODES);
    892962  i = 0;
    893963  do {
     964DE(if(zh->histogram.distance[i]<histogram->distance[i])fprintf(stderr,"GETLAST ERROR MINUS/D[%3d] %d < %d\n",i,zh->histogram.distance[i],histogram->distance[i]);)
    894965    zh->histogram.distance[i] -= histogram->distance[i];
    895966  } while (++i < Z3B_NBDISTANCECODES);
     
    902973  zh->limitwp = zh->dsize;
    903974  zh->state = z3be_state_end;
     975  if (zh->histogram3 != NULL) {
     976    memset(&z3relref(__u32, (zh)->histogram3)[0], 0, Z3BE_MEMSIZE_EXTRA3);
     977DE(i=0;do{if(z3be_histogram3(zh,0,i)!=0)fprintf(stderr,"GETLAST ERROR UNCLEAR1(%d)\n",i);i++;}while(i<8*256);i=0;do{if(z3be_distances3(zh,i)!=0)fprintf(stderr,"GETLAST ERROR UNCLEAR2(%d)\n",i);i++;}while(i<16);)
     978    i = 0;
     979    while (i < zh->ipos) {
     980      if (zh->mem[i] == (__u8)-1) {
     981        i += 1;
     982      } else {
     983        l = zh->mem[i+2];
     984        if (l == 0) {
     985          z3be_histogram_ref3(zh,
     986              z3be_class_distance((((__u32)zh->mem[i]) << 8) | zh->mem[i+1]),
     987              &z3be_data(zh, i));
     988        }
     989        i += l+3;
     990      }
     991    }
     992DE(if(i!=zh->ipos)fprintf(stderr,"GETLAST ERROR1: i=%lu, wpos=%lu, ipos=%lu\n", i, wpos, zh->ipos);)
     993  }
    904994}
    905995
     
    10391129  case z3be_state_ncdata:
    10401130    if (zh->count >= weighing->wpos) {
     1131D(fprintf(stderr,"GET LAST NC zh.count=%d, w.wpos=%d, zh.dpos=%d, ipos=%d\n",zh->count,weighing->wpos,zh->dpos,zh->ipos);)
    10411132      z3be_get_last(zh, zh->count, &weighing->histogram);
    10421133      return 0;
     
    10871178  case z3be_state_data:
    10881179    if (zh->count < weighing->wpos) {
    1089       if (zh->mem[zh->count] == (__u8)-1) {
     1180      if ((zh->mem[zh->count] == (__u8)-1)
     1181       || ((zh->histogram3 != NULL)
     1182        && (zh->mem[zh->count+2] == 0)
     1183        && (((((__u32)zh->mem[zh->count]) << 8) | zh->mem[zh->count+1])
     1184                  >= weighing->limit3)
     1185        && (zh->mem[zh->count+2] = zh->mem[zh->count+1] = (__u8)-1))) {
    10901186D({char c=z3be_data(zh,zh->count);fprintf(stderr, "encode LIT %08x '%c'\n", c, isprint(c) ? c : '.');})
    10911187        z3be_get_encode(zh, &zh->ll, z3be_data(zh, zh->count));
     
    10991195    } else {
    11001196      z3be_get_encode(zh, &zh->ll, Z3B_CODEENDOFBLOCK);
     1197D(fprintf(stderr,"GET LAST D zh.count=%d, w.wpos=%d, zh.dpos=%d, ipos=%d\n",zh->count,weighing->wpos,zh->dpos,zh->ipos);)
    11011198      z3be_get_last(zh, zh->count, &weighing->histogram);
    11021199    }
     
    15611658      if (!z3bd_buildcodetable(&zh->ll, Z3B_NBCODES)) {
    15621659        zh->error = z3err_bd_codeliteraltable;
    1563         return 0; 
     1660        return 0;
    15641661      }
    15651662      memset(&zh->huff_dc_length[0], 0, Z3B_NBDISTANCECODES);
     
    17171814D(fprintf(stderr, "z3bd_state_distance2: %08x/%d: %d\n", (zh->pbits & ((1 << n) - 1)), n, m);)
    17181815    z3bd_copystring(zh, zh->value, m);
    1719     zh->pbits >>= n; 
     1816    zh->pbits >>= n;
    17201817    zh->pbits_nb -= n;
    17211818    zh->state = z3bd_state_data;
  • z3/z3blib.h

    r108 r137  
    11/*
    2  * z3lib (c)1993,2000,2005/GPL Oskar Schirmer, schirmer@scara.com
     2 * z3lib (c)1993,2000,2005,2006/GPL,BSD Oskar Schirmer, schirmer@scara.com
    33 * combined huffman/lz compression library
    44 * now rfc1951 conformant
     
    2929#define Z3BE_HASHBITS   12
    3030#define Z3BE_HASHSIZE   ((1 << Z3BE_HASHBITS) + (1 << 8))
     31#define Z3BE_REF3TOOLARGE_MAX     8
    3132
    3233enum z3be_state {
     
    7071  __u32 longermatch;
    7172  __u32 longermlen;
     73  __u32 *histogram3; /* when checking short refs for usability: [8][256] */
    7274  __u8 runlength;
    7375  __u8 bfinal;
     
    8890  __u32 wpos; /* number of input bytes taken into account for weighing */
    8991  __u32 len[Z3B_NB_BTYPE]; /* size expected for the three types of coding */
     92  __u32 limit3; /* maximum distance for ref:length=3, longer go literal */
    9093  /* dh sizes: */
    9194  __u16 hlit;
     
    111114  z3bd_state_codeliterals2,
    112115  z3bd_state_codedistances,
    113   z3bd_state_codedistances2, 
     116  z3bd_state_codedistances2,
    114117  z3bd_state_data,
    115118  z3bd_state_data1,
    116119  z3bd_state_literal,
    117   z3bd_state_length,   
    118   z3bd_state_length2,   
     120  z3bd_state_length,
     121  z3bd_state_length2,
    119122  z3bd_state_distance,
    120123  z3bd_state_distance1,
     
    160163#ifndef Z3LIB_DECODE_ONLY
    161164#define Z3BE_MEMSIZE_MIN (sizeof(struct z3be_handle))
     165#define Z3BE_MEMSIZE_EXTRA3 (Z3BE_REF3TOOLARGE_MAX*sizeof(__u32)*((1<<8)+2))
    162166/*
    163167 * start the compression of one or more rfc1951 blocks
    164168 * input:
    165169 *    memory, memsize: memory reserved for the compressor, memsize must
    166  *      not be less than Z3BE_MEMSIZE
     170 *      not be less than Z3BE_MEMSIZE_MIN (plus Z3BE_MEMSIZE_EXTRA3, when
     171 *      limitlength3 is non-zero)
    167172 *    preferlonger: when non-zero, the compressor will try to find a longer
    168173 *      match at n+1 and prefer it over a previous match at n
     174 *    limitlength3: when non-zero, then for codes with length 3 and large
     175 *      distance, check whether coding as literal is better
    169176 * return: handle on success, NULL otherwise
    170177 */
    171178struct z3be_handle *z3be_start(void *memory, unsigned int memsize,
    172                         int preferlonger);
     179                        int preferlonger, int limitlength3);
    173180
    174181/*
  • z3/z3crc32.h

    r108 r137  
    11/*
    22 * cyclic redundancy check 32 bit
    3  * Copyright (C) 1999 Christian Wolff, 2004/2005 Oskar Schirmer
     3 * Copyright (C) 1999 Christian Wolff, 2004,2005 Oskar Schirmer
    44 * for Convergence Integrated Media GmbH (http://www.convergence.de)
    55 *
     
    4848
    4949// generate the tables of CRC-32 remainders for all possible bytes
    50 static inline void gen_crc32_table(__u32 *table) { 
    51   register int i,j; 
     50static inline void gen_crc32_table(__u32 *table) {
     51  register int i,j;
    5252  register __u32 crc32;
    5353  for (i=0; i<256; i++) {
     
    5656      crc32 = (crc32 >> 1) ^ ((crc32 & 1) ? POLYNOMIAL_32_LSBF : 0);
    5757    }
    58     table[i] = crc32; 
     58    table[i] = crc32;
    5959  }
    6060}
  • z3/z3detest.c

    r108 r137  
    55#endif
    66
    7 #include "z3blib.c"
    87#include <unistd.h>
    98#include <stdio.h>
    109#include <stdlib.h>
    1110#include <time.h>
     11
     12#include "z3blib.c"
    1213#define D(x) //x
    1314#include "z3dlib.c"
    1415#include "z3crc32.h"
    15 
    16 #include <unistd.h>
    17 #include <stdio.h>
    18 #include <stdlib.h>
    19 #include <time.h>
    2016
    2117#undef D
     
    2420{
    2521  struct z3de_handle *zh;
    26   int r, i, w, j, preferlonger;
     22  int r, i, w, j, preferlonger, limitlength3;
    2723  __u32 t, g, initialgrant;
    2824  double thrmin, thrmax;
     
    3632  unsigned long crctab[256];
    3733  gen_crc32_table(&crctab[0]);
    38   if (argc != 7) {
    39     fprintf(stderr, "usage: %s <extra memory> <slice size> <threshold(min)> <threshold(max)>\n\t\t<initial grant> <prefer longer>\n", argv[0]);
     34  if (argc != 8) {
     35    fprintf(stderr, "usage: %s <extra memory> <slice size> <threshold(min)> <threshold(max)>\n\t\t<initial grant> <preferlonger> <limitlength3>\n", argv[0]);
    4036    return 1;
    4137  }
     
    5450  initialgrant = atol(argv[5]);
    5551  preferlonger = atol(argv[6]);
    56   mem = malloc(Z3DE_MEMSIZE_MIN + memsize);
     52  limitlength3 = atol(argv[7]);
     53  mem = malloc(Z3DE_MEMSIZE_MIN + memsize
     54                + (limitlength3 ? Z3BE_MEMSIZE_EXTRA3 : 0));
    5755  crc = CRC_INIT_32;
    5856  len = 0;
     
    7876    i += w;
    7977  } while (i < 10);
    80   zh = z3d_encode_init(mem, Z3DE_MEMSIZE_MIN + memsize, slice,
     78  zh = z3d_encode_init(mem, Z3DE_MEMSIZE_MIN + memsize
     79                + (limitlength3 ? Z3BE_MEMSIZE_EXTRA3 : 0), slice,
    8180                thrmin * Z3DE_THRESHOLD_ONE, thrmax * Z3DE_THRESHOLD_ONE,
    82                 initialgrant, preferlonger);
     81                initialgrant, preferlonger, limitlength3);
    8382#ifdef D
    84   fprintf(stderr, "z3d_encode_init(%p, %lu, %lu): %p\n", mem, Z3DE_MEMSIZE_MIN + memsize, slice, zh);
     83  fprintf(stderr, "z3d_encode_init(%p, %lu, %lu): %p\n", mem, Z3DE_MEMSIZE_MIN + memsize + (limitlength3 ? Z3BE_MEMSIZE_EXTRA3 : 0), slice, zh);
    8584#endif
    8685  if (zh == NULL) {
  • z3/z3dlib.c

    r108 r137  
    11/*
    2  * z3lib (c)1993,2000,2005/GPL Oskar Schirmer, schirmer@scara.com
     2 * z3lib (c)1993,2000,2005,2006/GPL,BSD Oskar Schirmer, schirmer@scara.com
    33 * combined huffman/lz compression library
    44 * now rfc1951 conformant
     
    5757                        __u32 tellwhen,
    5858                        __u8 thrmin, __u8 thrmax, __u32 initialgrant,
    59                         int preferlonger)
     59                        int preferlonger, int limitlength3)
    6060{
    6161  struct z3de_handle *zh;
    6262  __u32 t;
    63   if ((memory == NULL) || (memsize < Z3DE_MEMSIZE_MIN)) {
     63  if ((memory == NULL) || (memsize < (limitlength3 ?
     64        (Z3DE_MEMSIZE_MIN + Z3BE_MEMSIZE_EXTRA3) : Z3DE_MEMSIZE_MIN))) {
    6465    return NULL;
    6566  }
     
    6768  if (z3be_start(&zh->z3be,
    6869        memsize - sizeof(struct z3de_handle) + sizeof(struct z3be_handle),
    69         preferlonger)
     70        preferlonger, limitlength3)
    7071      != &zh->z3be) {
    7172    return NULL;
     
    262263  } else {
    263264    *given = 0;
    264   } 
     265  }
    265266  return zh;
    266267}
  • z3/z3dlib.h

    r108 r137  
    11/*
    2  * z3lib (c)1993,2000,2005/GPL Oskar Schirmer, schirmer@scara.com
     2 * z3lib (c)1993,2000,2005,2006/GPL,BSD Oskar Schirmer, schirmer@scara.com
    33 * combined huffman/lz compression library
    44 * now rfc1951 conformant
    55 */
    66
    7 #ifndef __Z3DLIB_H__ 
     7#ifndef __Z3DLIB_H__
    88#define __Z3DLIB_H__
    9  
     9
    1010/* private stuff: */
    1111
     
    7171 *    preferlonger: when non-zero, the compressor will try to find a longer
    7272 *      match at n+1 and prefer it over a previous match at n
     73 *    limitlength3: when non-zero, then for codes with length 3 and large
     74 *      distance, check whether coding as literal is better
    7375 */
    7476struct z3de_handle *z3d_encode_init(void *memory, unsigned int memsize,
    7577                        __u32 tellwhen,
    7678                        __u8 thrmin, __u8 thrmax, __u32 initialgrant,
    77                         int preferlonger);
     79                        int preferlonger, int limitlength3);
    7880
    7981/*
     
    119121 *    code, codesize: a number of bytes that are available to decompress
    120122 * output:
    121  *    error: error code, see z3error.h
     123 *    error: error code, see z3lib.h
    122124 *    pending_bits, pending_nb: a number of bits finally pending
    123125 *    taken: the number of bytes actually taken from code, in range 0..codesize
     
    135137/*
    136138 * for use with garbage collectable systems, one may want to use the
    137  * following decode which returns a relative index instead of the
     139 * following decode function which returns a relative index instead of the
    138140 * absolute data pointer.
    139141 * output:
  • z3/z3fetest.c

    r108 r137  
    2222  int r, i, w;
    2323  gettimeofday(&tv, NULL);
    24   r = z3f_encode_init(STDOUT_FILENO, &zh, 6, tv.tv_sec, 3, 0, NULL,
    25         (argc > 1) ? argv[1] : NULL, NULL);
     24  r = z3f_encode_init(STDOUT_FILENO, &zh, (argc > 1) ? atoi(argv[1]) : 0,
     25        tv.tv_sec, 3, 0, NULL, (argc > 2) ? argv[2] : NULL, NULL);
    2626  if (r < 0) {
    2727    fprintf(stderr, "z3f_encode_init failed: %s\n", strerror(-r));
     
    2929  }
    3030  do {
    31     r = z3f_encode_header(&zh, 0, NULL, (argc > 1) ? argv[1] : NULL, NULL);
     31    r = z3f_encode_header(&zh, 0, NULL, (argc > 2) ? argv[2] : NULL, NULL);
    3232  } while (r == -EAGAIN);
    3333  if (r < 0) {
  • z3/z3flib.3

    r108 r137  
    11.\" Man page for z3lib
    22.\"
    3 .\" Copyright GPL (C) 2006, Oskar Schirmer
     3.\" Copyright GPL,BSD (C) 2006, Oskar Schirmer
    44.\"
    5 .TH z3flib 3 "2006-01-04" "0.13" "de/compression library"
     5.TH z3flib 3 "2006-01-19" "1.0" "de/compression library"
    66.SH NAME
    77z3lib \- compression/decompression library
    88.SH SYNOPSIS
    99.B #include <time.h>
     10.br
     11.B #include <z3lib.h>
     12.br
     13.B #include <z3blib.h>
     14.br
     15.B #include <z3dlib.h>
    1016.br
    1117.B #include <z3flib.h>
     
    99105from the buffer \fIdata\fR (of size \fIcount\fR)
    100106into the compressed file.
     107Note, that \fIcount\fR must not be zero, unless no
     108more data is available. In the latter case, \fIcount\fR
     109must be zero and the function must be called again,
     110until it returns \fI0\fR, too.
    101111Finally close the file.
    102112.SH DECODE
     
    113123.SH "SEE ALSO"
    114124.BR z3lib (3),
     125.BR z3dlib (3),
    115126.BR http://rfc.net/rfc1952.html ,
    116127.BR open (2),
  • z3/z3flib.c

    r108 r137  
    11/*
    2  * z3lib (c)2005,2006/GPL Oskar Schirmer, schirmer@scara.com
     2 * z3lib (c)2005,2006/GPL,BSD Oskar Schirmer, schirmer@scara.com
    33 * combined huffman/lz compression library
    44 * rfc1952 compliant
     
    4343    level = 9;
    4444  }
    45   if (z3d_encode_init(&zh->z.z3de, sizeof(zh->z),
    46                 (level > 3) ? 4096 : 0, 153, 128, 13,
    47                 (level > 6) ? 1 : 0) == NULL) {
     45  if (z3d_encode_init(&zh->z.z3de,
     46        sizeof(zh->z.s.space) + ((level > 5) ? sizeof(zh->z.s.space3) : 0),
     47        (level > 3) ? 4096 : 0, 76, 76, 13,
     48        (level > 7) ? 1 : 0, (level > 5) ? 1 : 0) == NULL) {
    4849    return -EFAULT;
    4950  }
     
    337338      }
    338339      zh->bout += i;
    339       if (zh->given == 0) {
    340         return -EAGAIN;
    341       }
    342340    }
    343341    i = zh->given;
    344342    if (i > count) {
    345343      i = count;
     344    }
     345    if (i == 0) {
     346      return -EAGAIN;
    346347    }
    347348    zh->crc = update_crc_32_block(&crc_32_table[0], zh->crc,
  • z3/z3flib.h

    r108 r137  
    11/*
    2  * z3lib (c)2005,2006/GPL Oskar Schirmer, schirmer@scara.com
     2 * z3lib (c)2005,2006/GPL,BSD Oskar Schirmer, schirmer@scara.com
    33 * combined huffman/lz compression library
    44 * rfc1952 compliant
     
    4141  union {
    4242    struct z3de_handle z3de;
    43     char space[Z3FE_EXTRA_MEMSIZE + sizeof(struct z3de_handle)];
     43    struct {
     44      char space[Z3FE_EXTRA_MEMSIZE + sizeof(struct z3de_handle)];
     45      char space3[Z3BE_MEMSIZE_EXTRA3];
     46    } s;
    4447  } z;
    4548};
     
    120123 * input:
    121124 *    data: a pointer to uncompressed data, to be compressed and written
    122  *    count: number of bytes available at data
     125 *    count: number of bytes available at data, which must be non-zero
     126 *      as long as the file shall not be closed. When no more data is to
     127 *      be written, it must be zero, and the function must be called
     128 *      again, until it returns 0, too
    123129 * return:
    124130 *    number of bytes written from data buffer,
     
    129135int z3f_encode_write(struct z3fe_handle *zh, __u8 *data, __u32 count);
    130136
    131 #endif /* Z3LIB_DECODE_ONLY */ 
     137#endif /* Z3LIB_DECODE_ONLY */
    132138
    133139#ifndef Z3LIB_ENCODE_ONLY
     
    157163int z3f_decode_read(struct z3fd_handle *zh, __u8 *data, __u32 count);
    158164
    159 #endif /* Z3LIB_ENCODE_ONLY */ 
     165#endif /* Z3LIB_ENCODE_ONLY */
    160166#endif /* __Z3FLIB_H__ */
  • z3/z3lib.3

    r108 r137  
    11.\" Man page for z3lib
    22.\"
    3 .\" Copyright GPL (C) 2006, Oskar Schirmer
     3.\" Copyright GPL,BSD (C) 2006, Oskar Schirmer
    44.\"
    5 .TH z3lib 3 "2006-01-04" "0.13" "de/compression library"
     5.TH z3lib 3 "2006-01-19" "1.0" "de/compression library"
    66.SH NAME
    77z3lib \- compression/decompression library
     
    5050e.g. for usage with a bootloader.
    5151.SH "SEE ALSO"
     52.BR z3dlib (3),
    5253.BR z3flib (3),
    5354.BR http://rfc.net/rfc1951.html ,
    5455.BR http://rfc.net/rfc1952.html ,
    5556.BR zlib (3).
     57.P
     58For detailed information on the z3blib layer, please
     59refer to the header file \fBz3blib.h\fR.
    5660.SH AUTHOR
    5761Oskar Schirmer (oskar@scara.com).
  • z3/z3lib.h

    r108 r137  
    11/*
    2  * z3lib (c)1993,2000,2005,2006/GPL Oskar Schirmer, schirmer@scara.com
     2 * z3lib (c)1993,2000,2005,2006/GPL,BSD Oskar Schirmer, schirmer@scara.com
    33 * combined huffman/lz compression library
    44 */
  • z3/z3liblib.h

    r108 r137  
    11/*
    2  * z3lib (c)1993,2000,2005,2006/GPL Oskar Schirmer, schirmer@scara.com
     2 * z3lib (c)1993,2000,2005,2006/GPL,BSD Oskar Schirmer, schirmer@scara.com
    33 * combined huffman/lz compression library
    44 * now rfc1951 conformant
     
    8787
    8888#define z3relref(t,p) ((p)-(t*)0, ((t*)(((__u8*)&(p))+(__u32)(p))))
    89 #define z3relrefset(p,d) (&(d)-(p), p=(void*)(((__u8*)&(d))-((__u8*)&(p))))
     89#define z3relrefset(p,d) (p=(void*)(((__u8*)&(d))-((__u8*)&(p))))
    9090
    9191#endif /* __Z3LIBLIB_H__ */
Note: See TracChangeset for help on using the changeset viewer.