diff options
author | Thomas White <taw@bitwiz.org.uk> | 2010-10-30 21:44:00 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2012-02-22 15:27:04 +0100 |
commit | f1920ffe340a742416d07cb97fcc3eb66f4ed845 (patch) | |
tree | d68d732bebdffd42d5e81f963e64ae6e396509b0 /src | |
parent | 5bdbb162cba5424397a5f912cb9bcc48ca2dea6f (diff) |
indexamajig: Remove the need to rewind(stdin)
Diffstat (limited to 'src')
-rw-r--r-- | src/indexamajig.c | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/src/indexamajig.c b/src/indexamajig.c index 348e3e8b..324e090f 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -102,6 +102,8 @@ struct queue_args int n_indexable; int n_sane; + + char *use_this_one_instead; }; @@ -460,18 +462,31 @@ static void *get_image(void *qp) char *rval; struct queue_args *qargs = qp; - /* Get the next filename */ - rval = fgets(line, 1023, qargs->fh); - if ( rval == NULL ) return NULL; - + /* Initialise new task arguments */ pargs = malloc(sizeof(struct index_args)); - memcpy(&pargs->static_args, &qargs->static_args, sizeof(struct static_index_args)); - chomp(line); - pargs->filename = malloc(strlen(qargs->prefix) + strlen(line) + 1); - snprintf(pargs->filename, 1023, "%s%s", qargs->prefix, line); + /* Get the next filename */ + if ( qargs->use_this_one_instead != NULL ) { + + pargs->filename = malloc(strlen(qargs->prefix) + + strlen(qargs->use_this_one_instead) + 1); + + snprintf(pargs->filename, 1023, "%s%s", qargs->prefix, + qargs->use_this_one_instead); + + qargs->use_this_one_instead = NULL; + + } else { + + rval = fgets(line, 1023, qargs->fh); + if ( rval == NULL ) return NULL; + chomp(line); + pargs->filename = malloc(strlen(qargs->prefix)+strlen(line)+1); + snprintf(pargs->filename, 1023, "%s%s", qargs->prefix, line); + + } return pargs; } @@ -769,21 +784,16 @@ int main(int argc, char *argv[]) } /* Get first filename and use it to set up the indexing */ - if ( fh != stdin ) { - rval = fgets(prepare_line, 1023, fh); - if ( rval == NULL ) { - ERROR("Failed to get filename to prepare indexing.\n"); - return 1; - } - chomp(prepare_line); - snprintf(prepare_filename, 1023, "%s%s", prefix, prepare_line); - rewind(fh); - } else { - STATUS("Reading input filenames from stdin, so can't (yet)"); - STATUS(" use the first file for preparing the indexing.\n"); - STATUS("Stuff might break.\n"); - prepare_filename[0] = '\0'; + rval = fgets(prepare_line, 1023, fh); + if ( rval == NULL ) { + ERROR("Failed to get filename to prepare indexing.\n"); + return 1; } + chomp(prepare_line); + snprintf(prepare_filename, 1023, "%s%s", prefix, prepare_line); + qargs.use_this_one_instead = prepare_line; + + /* Prepare the indexer */ ipriv = prepare_indexing(indm, cell, prepare_filename, det, nominal_photon_energy); if ( ipriv == NULL ) { |