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