Last change
on this file since 169 was 2, checked in by Rick van der Zwet, 15 years ago |
Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)
|
File size:
1.4 KB
|
Rev | Line | |
---|
[2] | 1 | /* Author : Rick van der Zwet
|
---|
| 2 | * S-number : 0433373
|
---|
| 3 | * Version : $Id: compressie.cc 330 2007-11-25 23:31:30Z rick $
|
---|
| 4 | * Copyright : FreeBSD Licence
|
---|
| 5 | */
|
---|
| 6 | #include <stdio.h>
|
---|
| 7 | #include <errno.h>
|
---|
| 8 | #include <stdlib.h>
|
---|
| 9 | #include <sysexits.h>
|
---|
| 10 |
|
---|
| 11 | #include "fileio.h"
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | int
|
---|
| 16 | fetchnumber(FILE * input) {
|
---|
| 17 | static bool odd = true;
|
---|
| 18 | static int buffer[3];
|
---|
| 19 | int number;
|
---|
| 20 |
|
---|
| 21 | if (feof(input))
|
---|
| 22 | return(FILE_END);
|
---|
| 23 |
|
---|
| 24 | if (odd == true) {
|
---|
| 25 | buffer[0] = fgetc(input);
|
---|
| 26 | buffer[1] = fgetc(input);
|
---|
| 27 | buffer[2] = fgetc(input);
|
---|
| 28 | number = (buffer[0] << 4) | (buffer[1] >> 4);
|
---|
| 29 | odd = false;
|
---|
| 30 | } else {
|
---|
| 31 | number = ((buffer[1] & 0xF) << 8) | buffer[2];
|
---|
| 32 | odd = true;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | if (number == FILE_END | number == EOF)
|
---|
| 36 | return(FILE_END);
|
---|
| 37 |
|
---|
| 38 | return(number);
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | /* XXX: Check fread/fwrite instead of hacking around like this */
|
---|
| 42 | void
|
---|
| 43 | tofile(FILE * output, const int input) {
|
---|
| 44 | static int stored = 0;
|
---|
| 45 | static bool instore = false;
|
---|
| 46 |
|
---|
| 47 | if (not instore) {
|
---|
| 48 | stored = input << 12;
|
---|
| 49 | instore = true;
|
---|
| 50 | } else {
|
---|
| 51 | stored = stored | input;
|
---|
| 52 | fprintf(output,"%c%c%c", ((0x00FF0000 & stored) >> 16),
|
---|
| 53 | ((0x0000FF00 & stored) >> 8),
|
---|
| 54 | (0x000000FF & stored));
|
---|
| 55 | instore = false;
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | /* set closing point, to really make sure we hit the end of the file */
|
---|
| 60 | void
|
---|
| 61 | closefile(FILE * output) {
|
---|
| 62 | tofile(output, FILE_END);
|
---|
| 63 | tofile(output, FILE_END);
|
---|
| 64 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.