1 |
#include <stdlib.h> |
2 |
#include <stdio.h> |
3 |
|
4 |
int main(int argc, char *argv[] ){ |
5 |
|
6 |
FILE *in_file; |
7 |
int nFrames = 0; |
8 |
int i, j, k; |
9 |
int lineNum = 0; |
10 |
char readBuffer[1000]; |
11 |
|
12 |
|
13 |
if( argc != 2 ){ |
14 |
printf( "I need a dump file to read.\n" ); |
15 |
exit(8); |
16 |
} |
17 |
|
18 |
in_file = fopen( argv[1], "r" ); |
19 |
if( in_file == NULL ){ |
20 |
printf( "Error opening \"%s\"\n", argv[1] ); |
21 |
exit(8); |
22 |
} |
23 |
|
24 |
if( feof( in_file ) ){ |
25 |
printf( "File ended unexpectedly at line %d\n", lineNum ); |
26 |
exit(8); |
27 |
} |
28 |
|
29 |
fgets( readBuffer, sizeof( readBuffer ), in_file ); |
30 |
lineNum++; |
31 |
|
32 |
while( !feof( in_file ) ){ |
33 |
|
34 |
i = atoi(readBuffer); |
35 |
|
36 |
if( feof( in_file ) ){ |
37 |
printf( "File ended unexpectedly at line %d, in frame%d\n", lineNum, nFrames+1 ); |
38 |
exit(8); |
39 |
} |
40 |
fgets( readBuffer, sizeof( readBuffer ), in_file ); |
41 |
lineNum++; |
42 |
|
43 |
for(j=0; j<i; j++){ |
44 |
|
45 |
if( feof( in_file ) ){ |
46 |
printf( "File ended unexpectedly at line %d, with atom %d, in frame %d\n", |
47 |
lineNum, j, nFrames+1 ); |
48 |
exit(8); |
49 |
} |
50 |
fgets( readBuffer, sizeof( readBuffer ), in_file ); |
51 |
lineNum++; |
52 |
} |
53 |
|
54 |
nFrames++; |
55 |
|
56 |
fgets( readBuffer, sizeof( readBuffer ), in_file ); |
57 |
lineNum++; |
58 |
} |
59 |
|
60 |
printf( "file \"%s\" has %d frames.\n", argv[1], nFrames ); |
61 |
|
62 |
fclose( in_file ); |
63 |
|
64 |
return 0; |
65 |
} |