From: Maksym Veremeyenko Date: Tue, 3 Jul 2012 11:16:45 +0000 (+0300) Subject: factorize mvcp_list line parsing X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=44374162573c8026c0e4541353833a18235e163e;p=melted factorize mvcp_list line parsing --- diff --git a/src/mvcp/mvcp.c b/src/mvcp/mvcp.c index 87b2148..99e086d 100644 --- a/src/mvcp/mvcp.c +++ b/src/mvcp/mvcp.c @@ -706,6 +706,27 @@ mvcp_error_code mvcp_list_get_error_code( mvcp_list list ) return mvcp_malloc_failed; } +static mvcp_error_code mvcp_list_parse( mvcp_list_entry entry, char* line) +{ + mvcp_tokeniser tokeniser = mvcp_tokeniser_init( ); + mvcp_tokeniser_parse_new( tokeniser, line, " " ); + + if ( mvcp_tokeniser_count( tokeniser ) > 0 ) + { + entry->clip = atoi( mvcp_tokeniser_get_string( tokeniser, 0 ) ); + mvcp_util_strip( mvcp_tokeniser_get_string( tokeniser, 1 ), '\"' ); + strcpy( entry->full, mvcp_tokeniser_get_string( tokeniser, 1 ) ); + entry->in = atol( mvcp_tokeniser_get_string( tokeniser, 2 ) ); + entry->out = atol( mvcp_tokeniser_get_string( tokeniser, 3 ) ); + entry->max = atol( mvcp_tokeniser_get_string( tokeniser, 4 ) ); + entry->size = atol( mvcp_tokeniser_get_string( tokeniser, 5 ) ); + entry->fps = atof( mvcp_tokeniser_get_string( tokeniser, 6 ) ); + } + mvcp_tokeniser_close( tokeniser ); + + return mvcp_ok; +} + /** Get a particular file entry in the list. */ @@ -716,21 +737,7 @@ mvcp_error_code mvcp_list_get( mvcp_list list, int index, mvcp_list_entry entry if ( index < mvcp_list_count( list ) ) { char *line = mvcp_response_get_line( list->response, index + 2 ); - mvcp_tokeniser tokeniser = mvcp_tokeniser_init( ); - mvcp_tokeniser_parse_new( tokeniser, line, " " ); - - if ( mvcp_tokeniser_count( tokeniser ) > 0 ) - { - entry->clip = atoi( mvcp_tokeniser_get_string( tokeniser, 0 ) ); - mvcp_util_strip( mvcp_tokeniser_get_string( tokeniser, 1 ), '\"' ); - strcpy( entry->full, mvcp_tokeniser_get_string( tokeniser, 1 ) ); - entry->in = atol( mvcp_tokeniser_get_string( tokeniser, 2 ) ); - entry->out = atol( mvcp_tokeniser_get_string( tokeniser, 3 ) ); - entry->max = atol( mvcp_tokeniser_get_string( tokeniser, 4 ) ); - entry->size = atol( mvcp_tokeniser_get_string( tokeniser, 5 ) ); - entry->fps = atof( mvcp_tokeniser_get_string( tokeniser, 6 ) ); - } - mvcp_tokeniser_close( tokeniser ); + mvcp_list_parse( entry, line ); } return error; }