-
Notifications
You must be signed in to change notification settings - Fork 1
/
chunker-rollingaverage.c
78 lines (67 loc) · 1.21 KB
/
chunker-rollingaverage.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc != 2)
{
fprintf(stderr, "Usage: chunker <inputfile>");
exit(1);
}
const int MAX_CHUNK_SIZE=1024*1024; /* 1MB */
const int RH_LENGTH=8;
unsigned int rhData[RH_LENGTH];
unsigned int bytecount=0;
char * mode = "r";
FILE * ifp;
int nulls=0;
unsigned char value='\0';
ifp = fopen (argv[1], mode);
if (ifp == 0x00)
{
fprintf(stderr, "Can't open input file\n");
exit(1);
}
value = fgetc(ifp);
while (! feof(ifp) )
{
if (value == 0x00)
{
nulls++;
if (nulls >= 16)
{
goto printchunk;
}
}
else
{
nulls=0;
}
if (bytecount > MAX_CHUNK_SIZE)
{
goto printchunk;
}
rhData[bytecount % RH_LENGTH]=value;
if (bytecount > RH_LENGTH)
{
unsigned int sum=0;
for (int i=0; i<RH_LENGTH; i++)
{
sum += rhData[i];
}
sum /= RH_LENGTH;
if (sum > 120 && sum < 130)
{
goto printchunk;
}
}
bytecount+=1;
value = fgetc(ifp);
continue;
printchunk:
printf("%li\n",ftell(ifp));
nulls=0;
bytecount=0;
value = fgetc(ifp);
}
fclose(ifp);
}