From d69c7c58de649932f607cbfb6e7f44a1364078f5 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 21 Jun 2004 19:57:02 +0000 Subject: [PATCH] =?utf8?q?Primera=20versi=C3=B3n=20del=20ZG,=20todav=C3=AD?= =?utf8?q?a=20no=20est=C3=A1=20el=20"decoder".?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/zerogrouping/Makefile | 60 +++++++++++++++++++++++ src/zerogrouping/zerogrouping.c | 86 +++++++++++++++++++++++++++++++++ src/zerogrouping/zerogrouping.h | 50 +++++++++++++++++++ src/zerogrouping/zg.c | 60 +++++++++++++++++++++++ 4 files changed, 256 insertions(+) create mode 100644 src/zerogrouping/Makefile create mode 100644 src/zerogrouping/zerogrouping.c create mode 100644 src/zerogrouping/zerogrouping.h create mode 100644 src/zerogrouping/zg.c diff --git a/src/zerogrouping/Makefile b/src/zerogrouping/Makefile new file mode 100644 index 0000000..a961153 --- /dev/null +++ b/src/zerogrouping/Makefile @@ -0,0 +1,60 @@ +#---------------------------------------------------------------------------- +# 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: jue jun 17 00:41:52 ART 2004 +# Autores: Leandro Lucarella +#---------------------------------------------------------------------------- +# +# $Id: bufford.c 624 2004-05-30 20:18:04Z llucare $ +# + +TARGETS=zg +COMMON=zerogrouping.o +SRCS=zerogrouping.c zg.c + +#CFLAGS=-O3 -Wall -DNDEBUG +CFLAGS=-ggdb -Wall -DDEBUG + +all: $(TARGETS) + +zg: $(COMMON) zg.o + +#unvol: $(COMMON) unvol.o + +depend: + makedepend -- $(CFLAGS) -- $(SRCS) + +clean: + @$(RM) -f *.o $(TARGETS) + +.PHONY: all clean depend + +# DO NOT DELETE + +zerogrouping.o: zerogrouping.h /usr/include/stdlib.h /usr/include/features.h +zerogrouping.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h +zerogrouping.o: /usr/lib/gcc-lib/i486-linux/3.3.4/include/stddef.h +zg.o: zerogrouping.h /usr/include/stdlib.h /usr/include/features.h +zg.o: /usr/include/sys/cdefs.h /usr/include/gnu/stubs.h +zg.o: /usr/lib/gcc-lib/i486-linux/3.3.4/include/stddef.h /usr/include/stdio.h +zg.o: /usr/include/bits/types.h /usr/include/bits/wordsize.h +zg.o: /usr/include/bits/typesizes.h /usr/include/libio.h +zg.o: /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h +zg.o: /usr/include/gconv.h /usr/lib/gcc-lib/i486-linux/3.3.4/include/stdarg.h +zg.o: /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h diff --git a/src/zerogrouping/zerogrouping.c b/src/zerogrouping/zerogrouping.c new file mode 100644 index 0000000..b7e8c2c --- /dev/null +++ b/src/zerogrouping/zerogrouping.c @@ -0,0 +1,86 @@ +/* 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 05:40:38 ART 2004 + * Autores: Leandro Lucarella + *---------------------------------------------------------------------------- + * + * $Id: vfile.c 748 2004-06-21 00:46:08Z llucare $ + * + */ + +#include "zerogrouping.h" + +/** \file + * + * Agrupador de ceros. + * + * ImplementaciĆ³n del agrupador de ceros. TODO completar doc. + * + */ + +/** FIXME + * El dst se asume que tiene reservada al menos ceil(size/2.0)+size bytes de + * memoria por si se llegara a expandir. size es el tamaƱo a leer de src. Se + * devuelve la cantidad de bytes escritos en dst. */ +size_t zg_group(char* dst, char *src, size_t size) +{ + char count; + size_t i; + size_t total = 0; + int in_zero = 0; + for (i = 0; i < size; ++i) + { + if (src[i] == '\0') + { + if (in_zero) + { + ++count; /* FIXME verificar que no pase 255 */ + } + else + { + in_zero = 1; /* entramos en serie de ceros */ + count = 0; /* reiniciamos contador de ceros */ + } + } + else + { + if (in_zero) + { + in_zero = 0; + dst[total++] = '\0'; + dst[total++] = count; + } + dst[total++] = src[i]; + } + } + if (in_zero) /* si estaba en una serie de ceros, terminamos de escribir. */ + { + dst[total++] = '\0'; + dst[total++] = count; + } + return total; +} + +size_t zg_ungroup(char* dst, char *src, size_t size) +{ + return 0; +} + diff --git a/src/zerogrouping/zerogrouping.h b/src/zerogrouping/zerogrouping.h new file mode 100644 index 0000000..2153bbf --- /dev/null +++ b/src/zerogrouping/zerogrouping.h @@ -0,0 +1,50 @@ +/* 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 05:35:10 ART 2004 + * Autores: Leandro Lucarella + *---------------------------------------------------------------------------- + * + * $Id: vfile.h 742 2004-06-20 22:34:13Z llucare $ + * + */ + +#ifndef _JACU_ZG_H_ +#define _JACU_ZG_H_ + +#include + +/** \file + * + * Agrupador de ceros. + * + * Interfaz del agrupador de ceros. TODO completar doc. + * + */ + +/** Agrupa varios ceros seguis en 2 bytes, el primero es cero y el segundo la + * cantidad. FIXME */ +size_t zg_group(char* dst, char *src, size_t size); + +/** Vuelve al original. FIXME */ +size_t zg_ungroup(char *buffer, size_t size); + +#endif /* _JACU_ZG_H_ */ + diff --git a/src/zerogrouping/zg.c b/src/zerogrouping/zg.c new file mode 100644 index 0000000..a3ef8e2 --- /dev/null +++ b/src/zerogrouping/zg.c @@ -0,0 +1,60 @@ +/* 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 13:55:48 ART 2004 + * Autores: Leandro Lucarella + *---------------------------------------------------------------------------- + * + * $Id: vfile.c 748 2004-06-21 00:46:08Z llucare $ + * + */ + +#include "zerogrouping.h" +#include +#include + +/** \file + * + * Prueba de agrupador de ceros. + * + */ + +int main(int argc, char* argv[]) +{ + size_t pagesize = BUFSIZ; + size_t len; + char* page; + char* pageout; + if (argc > 1) pagesize = atoi(argv[1]); + if (!(page = malloc(pagesize))) return 1; + if (!(pageout = malloc(pagesize/2+pagesize+1))) /* por si se expande */ + { + free(page); + return 1; + } + while ((len = fread(page, 1, pagesize, stdin))) + { + len = zg_group(pageout, page, len); + fwrite(pageout, 1, len, stdout); + } + free(page); + return 0; +} + -- 2.43.0