From: Leandro Lucarella Date: Mon, 21 Jun 2004 21:07:57 +0000 (+0000) Subject: Se completa el decoder de ZG. X-Git-Tag: svn_import~102 X-Git-Url: https://git.llucax.com/z.facultad/75.06/jacu.git/commitdiff_plain/fb5216062a50b385c738727c34991272e6422128?hp=816b508c140a36259ad9864d1b655b8336e9ac30 Se completa el decoder de ZG. --- diff --git a/src/zerogrouping/Makefile b/src/zerogrouping/Makefile index a961153..191cfc2 100644 --- a/src/zerogrouping/Makefile +++ b/src/zerogrouping/Makefile @@ -21,10 +21,10 @@ # Autores: Leandro Lucarella #---------------------------------------------------------------------------- # -# $Id: bufford.c 624 2004-05-30 20:18:04Z llucare $ +# $Id$ # -TARGETS=zg +TARGETS=zg unzg COMMON=zerogrouping.o SRCS=zerogrouping.c zg.c @@ -35,7 +35,7 @@ all: $(TARGETS) zg: $(COMMON) zg.o -#unvol: $(COMMON) unvol.o +unzg: $(COMMON) unzg.o depend: makedepend -- $(CFLAGS) -- $(SRCS) diff --git a/src/zerogrouping/unzg.c b/src/zerogrouping/unzg.c new file mode 100644 index 0000000..74a32eb --- /dev/null +++ b/src/zerogrouping/unzg.c @@ -0,0 +1,52 @@ +/* vim: set noexpandtab tabstop=4 shiftwidth=4 wrap: + *---------------------------------------------------------------------------- + * jacu + *---------------------------------------------------------------------------- + * This file is part of jacu. + * + * jacu is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * jacu is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along + * with jacu; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + *---------------------------------------------------------------------------- + * Creado: lun jun 21 18:08:25 ART 2004 + * Autores: Leandro Lucarella + *---------------------------------------------------------------------------- + * + * $Id$ + * + */ + +#include "zerogrouping.h" +#include +#include + +/** \file + * + * Prueba de desagrupador de ceros. + * + */ + +int main() +{ + size_t len; + char buff[256]; + int c; + ZG zg; + zg_init(&zg); + while ((c = getchar()) != EOF) + { + if ((len = zg_ungroup(&zg, buff, c))) fwrite(buff, 1, len, stdout); + } + return 0; +} + diff --git a/src/zerogrouping/zerogrouping.c b/src/zerogrouping/zerogrouping.c index 0251725..5310453 100644 --- a/src/zerogrouping/zerogrouping.c +++ b/src/zerogrouping/zerogrouping.c @@ -47,7 +47,7 @@ void zg_init(ZG* zg) * devuelve la cantidad de bytes escritos en dst. */ size_t zg_group(ZG* zg, char *dst, char src) { - if (src == '\0') + if (src == 0) { if (zg->in_zero) { @@ -58,7 +58,7 @@ size_t zg_group(ZG* zg, char *dst, char src) { zg->in_zero = 1; /* entramos en serie de ceros */ zg->count = 0; /* reiniciamos contador de ceros */ - *dst = '\0'; /* devuelvo el cero */ + *dst = 0; /* devuelvo el cero */ return 1; /* indico que hay un caracter */ } } @@ -67,7 +67,7 @@ size_t zg_group(ZG* zg, char *dst, char src) size_t ret = 1; if (zg->in_zero) { - zg->in_zero = 0; /* saldo de serie de ceros */ + zg->in_zero = 0; /* salgo de serie de ceros */ *dst = zg->count; /* devuelvo cantidad de ceros */ dst++; /* me muevo al siguiente caracter */ ret++; /* indico que hay un caracter más */ @@ -76,9 +76,40 @@ size_t zg_group(ZG* zg, char *dst, char src) return ret; /* indico la cantidad de caracteres devueltos */ } } -/* -size_t zg_ungroup(char* dst, char *src, size_t size) + +/** FIXME + * dst debe tener reservado al menos 256 bytes, src es el caracter a desencodear + * y se devuelven la cantidad de bytes desencodeados en dst. */ +size_t zg_ungroup(ZG* zg, char *dst, char src) { - return 0; + if (src == 0) + { + if (zg->in_zero) /* eran 2 ceros seguidos (1 cero orig. expandido) */ + { + zg->in_zero = 0; /* saldo de serie de ceros */ + return 0; /* indico que no hay nada */ + } + else /* empieza serie de ceros */ + { + zg->in_zero = 1; /* entramos en serie de ceros */ + *dst = 0; /* devuelvo el cero */ + return 1; /* indico que hay un caracter */ + } + } + else /* no es un cero */ + { + if (zg->in_zero) /* era una serie de ceros comprimida */ + { + char ret = src; + zg->in_zero = 0; /* salgo de serie de ceros */ + while (src--) dst[src] = 0; /* devuelve src cantidad de ceros */ + return ret; /* indica que se devolvieron src cantidad de ceros */ + } + else + { + *dst = src; /* devuelvo el caracter */ + return 1; /* indico que se devolvió un caracter */ + } + } } -*/ + diff --git a/src/zerogrouping/zerogrouping.h b/src/zerogrouping/zerogrouping.h index 750da9a..b1b9a2e 100644 --- a/src/zerogrouping/zerogrouping.h +++ b/src/zerogrouping/zerogrouping.h @@ -54,8 +54,8 @@ void zg_init(ZG* zg); * cantidad. FIXME */ size_t zg_group(ZG* zg, char *dst, char src); -/** Vuelve al original. FIXME * / -size_t zg_ungroup(char *buffer, size_t size); -*/ +/** Vuelve al original. FIXME */ +size_t zg_ungroup(ZG* zg, char *dst, char src); + #endif /* _JACU_ZG_H_ */