1 /*----------------------------------------------------------------------------
2 * jacu - Just Another Compression Utility
3 *----------------------------------------------------------------------------
4 * This file is part of jacu.
6 * jacu is free software; you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation; either version 2 of the License, or (at your option) any later
11 * jacu is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License along
17 * with jacu; if not, write to the Free Software Foundation, Inc., 59 Temple
18 * Place, Suite 330, Boston, MA 02111-1307 USA
19 *----------------------------------------------------------------------------
25 int no_pertenece(char *z, char c, int len);
27 void pop_front(char *z, unsigned int pos);
29 int get_pos(char *z, int len, char c);
30 /****fin privadas******/
32 void print_z(char *z, int len)
36 fprintf(stderr, "%c", z[i]);
37 fprintf(stderr, "\n");
40 unsigned char *jacu_mtf(unsigned char *datos, int len, unsigned char **_z, int *z_len)
46 pos = (unsigned char *)malloc(len*sizeof(unsigned char));
47 z = jacu_buscar_z(datos, len, &size);
48 *_z = (unsigned char*)malloc(size*sizeof(unsigned char));
49 memcpy(*_z, z, size*sizeof(unsigned char));
51 pos[i] = get_pos(z, size, datos[i]);
60 unsigned char *jacu_mtf_inv(unsigned char *z, unsigned char *pos, int len)
65 datos = (char*)malloc(sizeof(char)*len);
67 datos[i] = z[(unsigned int)pos[i]];
69 pop_front(z, (unsigned int)pos[i]);
74 unsigned char *jacu_buscar_z(unsigned char* datos, int len, int *size)
81 if( no_pertenece(z, datos[i], j) == -1 ){
83 z = realloc(z, j*sizeof(char));
92 int no_pertenece(char *z, char c, int len)
102 void pop_front(char *z, unsigned int pos)
107 if (pos > 255) printf("pos > = %u\n", pos);
108 if (pos < 0u) printf("pos < = %d\n", pos);
115 int get_pos(char *z, int len, char c)
118 if (z==NULL) return -1;
120 for(pos=0; pos<len; pos++)