Skip to content

Commit

Permalink
Fixed tests, cleaned up a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
thenoviceoof committed Oct 8, 2012
1 parent 8da1249 commit 09cb835
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 21 deletions.
3 changes: 3 additions & 0 deletions c/reconf
@@ -1,4 +1,7 @@
#!/bin/sh
echo "### Running make clean..."
make clean
make dist-clean
echo "### Running aclocal..."
aclocal
echo "### Running autoconf..."
Expand Down
13 changes: 3 additions & 10 deletions c/src/base92.c
Expand Up @@ -6,8 +6,6 @@

#include <base92.h>

#include <stdio.h>

unsigned char ENCODE_MAPPING[256] = (unsigned char[]){
33, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
Expand Down Expand Up @@ -104,7 +102,6 @@ unsigned char* base92encode(unsigned char* str, int len) {
wssize += 8;
if (wssize >= 13) {
tmp = (workspace >> (wssize - 13)) & 8191;
// printf("bd: %d\n", tmp);
c = base92chr_encode(tmp / 91);
if (c == 0) {
// do something, illegal character
Expand Down Expand Up @@ -171,17 +168,13 @@ unsigned char* base92decode(unsigned char* str, int* len) {
return res;
}
// calculate size
*len = ((size/2 * 13) + (size % 2) * 6) % 8;
if (*len == 0) {
*len = ((size/2 * 13) + (size % 2) * 6) / 8;
} else {
*len = ((size/2 * 13) + (size % 2) * 6) / 8 + 1;
}
*len = ((size/2 * 13) + (size%2 * 6)) / 8;
res = (unsigned char *)malloc(sizeof(char) * (*len));
// handle pairs of chars
workspace = 0;
wssize = 0;
for (i = 0; i < size; i += 2) {
j = 0;
for (i = 0; i + 1 < size; i += 2) {
b1 = base92chr_decode(str[i]);
b2 = base92chr_decode(str[i+1]);
workspace = (workspace << 13) | (b1 * 91 + b2);
Expand Down
3 changes: 0 additions & 3 deletions c/tests/binary_string.c
Expand Up @@ -31,12 +31,9 @@ int main() {
str[14] = 195;
str[15] = 0;

printf("MU");
if(strcmp(base92encode(str, 15), "c)L#O2K}%8Vo_OM3kB:") != 0)
exit(1);
printf("MU");
s = base92decode("c)L#O2K}%8Vo_OM3kB:", &i);
printf("MUMU");
if(strcmp(stringify(s, i), str) != 0)
exit(1);
return 0;
Expand Down
1 change: 0 additions & 1 deletion c/tests/hello_world.c
Expand Up @@ -13,7 +13,6 @@ int main() {
if(strcmp(base92encode("hello world", 11), "Fc_$aOTdKnsM*k") != 0)
exit(1);
s = base92decode("Fc_$aOTdKnsM*k", &i);
printf("%s\n", s);
if(strcmp(stringify(s, i), "hello world") != 0)
exit(1);
return 0;
Expand Down
4 changes: 0 additions & 4 deletions c/tests/lengths.c
Expand Up @@ -33,15 +33,11 @@ int main() {
str[0] = 0;

for(i = 0; i < LEN; i++) {
printf("MU %d\n", i);
str[i] = 'a';
str[i+1] = 0;
printf("s1: %s\n", base92encode(str, i+1));
printf("s2: %s\n", strs[i]);
if(strcmp(base92encode(str, i+1), strs[i]) != 0)
exit(1);
s = base92decode(strs[i], &j);
printf("s: %s\n", stringify(s, j));
if(strcmp(stringify(s, j), str) != 0)
exit(1);
}
Expand Down
3 changes: 0 additions & 3 deletions c/tests/utils.h
Expand Up @@ -5,16 +5,13 @@
// - Nathan Hwang (thenoviceoof)

#include <stdlib.h>
#include <stdio.h>

unsigned char *stringify(char *str, int i) {
int j;
unsigned char *s;

printf("i: %d\n", i);
s = (unsigned char*)malloc(sizeof(char) * i + 1);
for (j = 0; j < i; j++) {
printf("j: %d\n", j);
s[j] = str[j];
}
s[j+1] = 0;
Expand Down

0 comments on commit 09cb835

Please sign in to comment.