[hackers] [flate] -inflate_example -deflate_example || nsz

From: <hg_AT_suckless.org>
Date: Fri, 21 Aug 2009 13:50:16 +0000 (UTC)

changeset: 112:2628fb64f049
user: nsz <nszabolcs_AT_gmail.com>
date: Fri Aug 21 15:39:26 2009 +0200
files: Makefile deflate_example.c inflate_example.c
description:
-inflate_example -deflate_example

diff -r f534b13f0b68 -r 2628fb64f049 Makefile
--- a/Makefile Fri Aug 21 15:27:33 2009 +0200
+++ b/Makefile Fri Aug 21 15:39:26 2009 +0200
@@ -1,21 +1,16 @@
 #CFLAGS=-g -Wall -ansi -pedantic
 CFLAGS=-O3 -Wall -ansi -pedantic
 LDFLAGS=
-SRC=inflate.c inflate_example.c inflate_simple.c \
- deflate.c deflate_example.c \
+SRC=inflate.c inflate_simple.c deflate.c \
     sflate.c crc.c adler.c
 OBJ=${SRC:.c=.o}
-EXE=sflate inflate inflate_simple deflate
+EXE=sflate inflate_simple
 
 all: ${EXE}
 sflate: sflate.o crc.o adler.o inflate.o deflate.o
         ${CC} -o $@ $^ ${LDFLAGS}
-inflate: inflate.o inflate_example.o
- ${CC} -o $@ $^ ${LDFLAGS}
 inflate_simple: inflate_simple.o
         ${CC} -o $@ $^ ${LDFLAGS}
-deflate: deflate.o deflate_example.o
- ${CC} -o $@ $^ ${LDFLAGS}
 ${OBJ}: Makefile flate.h
 .c.o:
         ${CC} -c ${CFLAGS} $<
@@ -24,18 +19,18 @@
 
 prof: profinf profdef
 
-profinf: inflate_example.c inflate.c
+profinf: inflate.c deflate.c sflate.c crc.c adler.c
         gcc -O3 -fprofile-arcs -ftest-coverage -pg -g -Wall $+
- ./a.out <a.z >/dev/null
+ ./a.out -d <a.z >/dev/null
         gcov -b $+ >/dev/null
         gprof a.out >$<.gprof
 # gcc -g -Wall $<
-# valgrind -v --leak-check=yes ./a.out <a.dat >/dev/null 2>a.valgrind
+# valgrind -v --leak-check=yes ./a.out -d <a.z >/dev/null 2>a.valgrind
 # grep ERROR a.valgrind
 # grep alloc a.valgrind
         rm -f a.out a.valgrind *.gcno *.gcda gmon.out
 
-profdef: deflate_example.c deflate.c
+profdef: inflate.c deflate.c sflate.c crc.c adler.c
         gcc -O1 -fprofile-arcs -ftest-coverage -pg -g -Wall $+
         ./a.out <a.u >/dev/null
         gcov -b $+ >/dev/null
diff -r f534b13f0b68 -r 2628fb64f049 deflate_example.c
--- a/deflate_example.c Fri Aug 21 15:27:33 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include "flate.h"
-
-/* compress stream using stream struct interface */
-int compress_stream(FILE *in, FILE *out) {
- FlateStream s;
- int n, nin, nout;
- enum {Nin = 1<<12, Nout = 1<<15};
-
- s.in = malloc(Nin);
- s.out = malloc(Nout);
- s.nout = Nout;
- s.err = 0;
- s.state = 0;
- nin = nout = 0;
-
- for (n = FlateIn; ; n = deflate(&s))
- switch (n) {
- case FlateOk:
- case FlateErr:
- fprintf(stderr, "in: %d out: %d err: %s\n", nin, nout, s.err);
- free(s.in);
- free(s.out);
- return n;
- case FlateIn:
- s.nin = fread(s.in, 1, Nin, in);
- nin += s.nin;
- break;
- case FlateOut:
- if (s.nout != fwrite(s.out, 1, s.nout, out))
- s.err = "write error.";
- nout += s.nout;
- s.nout = Nout;
- break;
- }
-}
-
-/* compress stream using callback interface */
-struct data {
- FILE *f;
- uint n;
-};
-
-int r(void *p, int siz, void *data) {
- struct data *d = data;
- uint n;
-
- n = fread(p, 1, siz, d->f);
- d->n += n;
- return n;
-}
-
-int w(void *p, int siz, void *data) {
- struct data *d = data;
- uint n;
-
- n = fwrite(p, 1, siz, d->f);
- d->n += n;
- return n;
-}
-
-int compress_callback(FILE *in, FILE *out) {
- struct data rr;
- struct data ww;
- int err;
-
- rr.f = in;
- ww.f = out;
- rr.n = ww.n = 0;
- err = deflate_callback(r, &rr, w, &ww);
- fprintf(stderr, "in: %d out: %d err: %d\n", rr.n, ww.n, err);
- return err;
-}
-
-/* in memory compression */
-int compress_mem(void *src, int srclen, void *dst, int dstlen) {
- FlateStream s;
- int n;
-
- s.in = src;
- s.nin = srclen;
- s.out = dst;
- s.nout = dstlen;
- s.err = 0;
- s.state = 0;
-
- while ((n = deflate(&s)) == FlateOut) {
- dstlen -= s.nout;
- s.out += s.nout;
- s.nout = dstlen;
- if (dstlen < 0)
- s.err = "not enough output space.";
- }
- if (n == FlateIn) {
- s.err = "input is not terminated.";
- n = deflate(&s);
- }
- if (n == FlateOk) {
- fprintf(stderr, "in: %d out: %d\n", srclen, (char *)s.out - (char *)dst);
- return (char *)s.out - (char *)dst;
- }
- fprintf(stderr, "in: %d out: %d err: %s\n", srclen, (char *)s.out - (char *)dst, s.err);
- return -1;
-}
-
-int main(void) {
- return compress_stream(stdin, stdout);
-}
diff -r f534b13f0b68 -r 2628fb64f049 inflate_example.c
--- a/inflate_example.c Fri Aug 21 15:27:33 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,111 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include "flate.h"
-
-/* decompress stream using stream struct interface */
-int decompress_stream(FILE *in, FILE *out) {
- FlateStream s;
- int n, nin, nout;
- enum {Nin = 1<<12, Nout = 1<<15};
-
- s.in = malloc(Nin);
- s.out = malloc(Nout);
- s.nout = Nout;
- s.err = 0;
- s.state = 0;
- nin = nout = 0;
-
- for (n = FlateIn; ; n = inflate(&s))
- switch (n) {
- case FlateOk:
- case FlateErr:
- fprintf(stderr, "in: %d out: %d err: %s\n", nin, nout, s.err);
- free(s.in);
- free(s.out);
- return n;
- case FlateIn:
- s.nin = fread(s.in, 1, Nin, in);
- if (s.nin == 0)
- s.err = "read error.";
- nin += s.nin;
- break;
- case FlateOut:
- if (s.nout != fwrite(s.out, 1, s.nout, out))
- s.err = "write error.";
- nout += s.nout;
- s.nout = Nout;
- break;
- }
-}
-
-/* decompress stream using callback interface */
-struct data {
- FILE *f;
- uint n;
-};
-
-int r(void *p, int siz, void *data) {
- struct data *d = data;
- uint n;
-
- n = fread(p, 1, siz, d->f);
- d->n += n;
- return n;
-}
-
-int w(void *p, int siz, void *data) {
- struct data *d = data;
- uint n;
-
- n = fwrite(p, 1, siz, d->f);
- d->n += n;
- return n;
-}
-
-int decompress_callback(FILE *in, FILE *out) {
- struct data rr;
- struct data ww;
- int err;
-
- rr.f = in;
- ww.f = out;
- rr.n = ww.n = 0;
- err = inflate_callback(r, &rr, w, &ww);
- fprintf(stderr, "in: %d out: %d err: %d\n", rr.n, ww.n, err);
- return err;
-}
-
-/* in memory decompression */
-int decompress_mem(void *src, int srclen, void *dst, int dstlen) {
- FlateStream s;
- int n;
-
- s.in = src;
- s.nin = srclen;
- s.out = dst;
- s.nout = dstlen;
- s.err = 0;
- s.state = 0;
-
- while ((n = inflate(&s)) == FlateOut) {
- dstlen -= s.nout;
- s.out += s.nout;
- s.nout = dstlen;
- if (dstlen < 0)
- s.err = "not enough output space.";
- }
- if (n == FlateIn) {
- s.err = "input is not terminated.";
- n = inflate(&s);
- }
- if (n == FlateOk) {
- fprintf(stderr, "in: %d out: %d\n", srclen, (char *)s.out - (char *)dst);
- return (char *)s.out - (char *)dst;
- }
- fprintf(stderr, "in: %d out: %d err: %s\n", srclen, (char *)s.out - (char *)dst, s.err);
- return -1;
-}
-
-int main(void) {
- return decompress_callback(stdin, stdout);
-}
Received on Fri Aug 21 2009 - 13:50:16 UTC

This archive was generated by hypermail 2.2.0 : Fri Aug 21 2009 - 14:00:16 UTC