static void unget_string( FILE *file, STRING str ) { int len; len = 0; while( str[len] == ' ' || str[len] == '\t' ) ++len; if( str[len] != END_OF_STRING ) (void) unget_character( file, str[len] ); }
VIOAPI Status mni_input_string( FILE *file, STRING *string, char termination_char1, char termination_char2 ) { Status status; char ch; BOOLEAN quoted; *string = create_string( NULL ); status = mni_get_nonwhite_character( file, &ch ); if( status == OK && ch == '"' ) { quoted = TRUE; status = mni_get_nonwhite_character( file, &ch ); termination_char1 = '"'; termination_char2 = '"'; } else quoted = FALSE; while( status == OK && ch != termination_char1 && ch != termination_char2 && ch != '\n' ) { if (ch != '\r') { /* Always ignore carriage returns */ concat_char_to_string( string, ch ); } status = input_character( file, &ch ); } if( !quoted ) (void) unget_character( file, ch ); while( string_length(*string) > 0 && (*string)[string_length(*string)-1] == ' ' ) (*string)[string_length(*string)-1] = END_OF_STRING; if( status != OK ) { delete_string( *string ); *string = NULL; } return( status ); }
static VIO_Status read_one_tag( FILE *file, int n_volumes, VIO_Real tags_volume1_ptr[], VIO_Real tags_volume2_ptr[], VIO_Real *weight_ptr, int *structure_id_ptr, int *patient_id_ptr, VIO_STR *label_ptr ) { VIO_Status status; VIO_STR line; VIO_BOOL last_was_blank, in_quotes; int n_strings, pos, i; VIO_Real x1 = 0.0, y1 = 0.0, z1 = 0.0, x2 = 0.0, y2 = 0.0, z2 = 0.0; int structure_id, patient_id; VIO_Real weight; VIO_STR label; /* parameter checking */ if( file == NULL ) { print_error( "read_one_tag(): passed NULL FILE ptr.\n"); return( VIO_ERROR ); } status = mni_input_real( file, &x1 ); if( status == VIO_OK ) { if( mni_input_real( file, &y1 ) != VIO_OK || mni_input_real( file, &z1 ) != VIO_OK || (n_volumes == 2 && (mni_input_real( file, &x2 ) != VIO_OK || mni_input_real( file, &y2 ) != VIO_OK || mni_input_real( file, &z2 ) != VIO_OK)) ) { print_error( "read_one_tag(): error reading tag point\n" ); return( VIO_ERROR ); } if( tags_volume1_ptr != NULL ) { tags_volume1_ptr[VIO_X] = x1; tags_volume1_ptr[VIO_Y] = y1; tags_volume1_ptr[VIO_Z] = z1; } if( n_volumes == 2 && tags_volume2_ptr != NULL ) { tags_volume2_ptr[VIO_X] = x2; tags_volume2_ptr[VIO_Y] = y2; tags_volume2_ptr[VIO_Z] = z2; } label = NULL; weight = 0.0; structure_id = -1; patient_id = -1; n_strings = 0; if( mni_input_line( file, &line ) == VIO_OK ) { i = 0; last_was_blank = TRUE; in_quotes = FALSE; while( line[i] != VIO_END_OF_STRING ) { if( line[i] == ' ' || line[i] == '\t' ) { last_was_blank = TRUE; } else { if( last_was_blank && !in_quotes ) ++n_strings; last_was_blank = FALSE; if( line[i] == '\"' ) in_quotes = !in_quotes; } ++i; } while( i > 0 && (line[i] == ' ' || line[i] == '\t' || line[i] == VIO_END_OF_STRING) ) --i; if( line[i] == ';' ) { (void) unget_character( file, (char) ';' ); line[i] = VIO_END_OF_STRING; } } if( n_strings != 0 ) { if( n_strings == 1 ) { label = extract_label( line ); } else if( n_strings < 3 || n_strings > 4 || sscanf( line, "%lf %d %d %n", &weight, &structure_id, &patient_id, &pos ) != 3 ) { print_error( "input_tag_points(): error reading tag point\n" ); return( VIO_ERROR ); } else if( n_strings == 4 ) { label = extract_label( &line[pos] ); } } delete_string( line ); if( weight_ptr != NULL ) *weight_ptr = weight; if( structure_id_ptr != NULL ) *structure_id_ptr = structure_id; if( patient_id_ptr != NULL ) *patient_id_ptr = patient_id; if( label_ptr != NULL ) *label_ptr = label; else delete_string( label ); } if( status == VIO_ERROR ) /* --- found no more tag points, should now find ; */ { if( mni_skip_expected_character( file, (char) ';' ) != VIO_OK ) status = VIO_ERROR; else status = VIO_END_OF_FILE; } return( status ); }