/* Author : Rick van der Zwet * S-number : 0433373 * Version : $Id: compressie.cc 330 2007-11-25 23:31:30Z rick $ * Copyright : FreeBSD Licence */ #include #include #include #include #include "fileio.h" int fetchnumber(FILE * input) { static bool odd = true; static int buffer[3]; int number; if (feof(input)) return(FILE_END); if (odd == true) { buffer[0] = fgetc(input); buffer[1] = fgetc(input); buffer[2] = fgetc(input); number = (buffer[0] << 4) | (buffer[1] >> 4); odd = false; } else { number = ((buffer[1] & 0xF) << 8) | buffer[2]; odd = true; } if (number == FILE_END | number == EOF) return(FILE_END); return(number); } /* XXX: Check fread/fwrite instead of hacking around like this */ void tofile(FILE * output, const int input) { static int stored = 0; static bool instore = false; if (not instore) { stored = input << 12; instore = true; } else { stored = stored | input; fprintf(output,"%c%c%c", ((0x00FF0000 & stored) >> 16), ((0x0000FF00 & stored) >> 8), (0x000000FF & stored)); instore = false; } } /* set closing point, to really make sure we hit the end of the file */ void closefile(FILE * output) { tofile(output, FILE_END); tofile(output, FILE_END); }