aboutsummaryrefslogtreecommitdiff
path: root/src/stream.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-02-12 14:40:16 -0800
committerThomas White <taw@physics.org>2012-02-22 15:27:14 +0100
commit9a2773d90137c51149c254f376237ba18386ee8e (patch)
tree43ed1bc5a5bd8dc54d92163a9be61300ebe476c5 /src/stream.c
parent54ff7acab385a0c524b8f2194e95621e92843db1 (diff)
More stream handling and reflection counting
Diffstat (limited to 'src/stream.c')
-rw-r--r--src/stream.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/stream.c b/src/stream.c
index 69d64bae..ffee4a6c 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -79,10 +79,12 @@ int find_chunk(FILE *fh, UnitCell **cell, char **filename, double *ev)
char *rval = NULL;
int have_ev = 0;
int have_cell = 0;
+ int have_filename = 0;
+ long start_of_chunk = 0;
do {
- long pos = ftell(fh);
+ const long start_of_line = ftell(fh);
rval = fgets(line, 1023, fh);
if ( rval == NULL ) continue;
@@ -96,11 +98,15 @@ int find_chunk(FILE *fh, UnitCell **cell, char **filename, double *ev)
*ev = 0.0;
have_cell = 0;
have_ev = 0;
+ have_filename = 1;
+ start_of_chunk = ftell(fh);
}
+ if ( !have_filename ) continue;
+
if ( strncmp(line, "astar = ", 8) == 0 ) {
- fseek(fh, pos, 0);
+ fseek(fh, start_of_line, 0);
*cell = read_orientation_matrix(fh);
have_cell = 1;
}
@@ -111,8 +117,8 @@ int find_chunk(FILE *fh, UnitCell **cell, char **filename, double *ev)
}
if ( strlen(line) == 0 ) {
- if ( have_cell && have_ev ) {
- fseek(fh, pos, 0);
+ if ( have_filename && have_cell && have_ev ) {
+ fseek(fh, start_of_chunk, 0);
return 0;
}
}