X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmvcp%2Fmvcp_parser.c;h=b199dada6ed637ce3101a911b4ae9326714fb384;hb=2081be0c64376204776c27671cc221401b56cc04;hp=5135d98d00e54603377244ae4a9f525cc51cf55e;hpb=d718bb3ffae348dae7bfc9807de6943b43cd42fa;p=melted diff --git a/src/mvcp/mvcp_parser.c b/src/mvcp/mvcp_parser.c index 5135d98..b199dad 100644 --- a/src/mvcp/mvcp_parser.c +++ b/src/mvcp/mvcp_parser.c @@ -79,50 +79,61 @@ mvcp_response mvcp_parser_executef( mvcp_parser parser, const char *format, ... return response; } -/** Execute the contents of a file. Note the special case mvcp_response returned. +/** Execute the contents of a file descriptor. */ -mvcp_response mvcp_parser_run( mvcp_parser parser, char *filename ) +mvcp_response mvcp_parser_run_file( mvcp_parser parser, FILE *file ) { mvcp_response response = mvcp_response_init( ); if ( response != NULL ) { - FILE *file = fopen( filename, "r" ); - if ( file != NULL ) + char command[ 1024 ]; + mvcp_response_set_error( response, 201, "OK" ); + while ( mvcp_response_get_error_code( response ) == 201 && fgets( command, 1024, file ) ) { - char command[ 1024 ]; - mvcp_response_set_error( response, 201, "OK" ); - while ( mvcp_response_get_error_code( response ) == 201 && fgets( command, 1024, file ) ) + mvcp_util_trim( mvcp_util_chomp( command ) ); + if ( strcmp( command, "" ) && command[ 0 ] != '#' ) { - mvcp_util_trim( mvcp_util_chomp( command ) ); - if ( strcmp( command, "" ) && command[ 0 ] != '#' ) + mvcp_response temp = NULL; + mvcp_response_printf( response, 1024, "%s\n", command ); + temp = mvcp_parser_execute( parser, command ); + if ( temp != NULL ) { - mvcp_response temp = NULL; - mvcp_response_printf( response, 1024, "%s\n", command ); - temp = mvcp_parser_execute( parser, command ); - if ( temp != NULL ) - { - int index = 0; - for ( index = 0; index < mvcp_response_count( temp ); index ++ ) - mvcp_response_printf( response, 10240, "%s\n", mvcp_response_get_line( temp, index ) ); - mvcp_response_close( temp ); - } - else - { - mvcp_response_set_error( response, 500, "Batch execution failed" ); - } + int index = 0; + for ( index = 0; index < mvcp_response_count( temp ); index ++ ) + mvcp_response_printf( response, 10240, "%s\n", mvcp_response_get_line( temp, index ) ); + mvcp_response_close( temp ); + } + else + { + mvcp_response_set_error( response, 500, "Batch execution failed" ); } } - fclose( file ); - } - else - { - mvcp_response_set_error( response, 404, "File not found." ); } } return response; } +/** Execute the contents of a file. Note the special case mvcp_response returned. +*/ + +mvcp_response mvcp_parser_run( mvcp_parser parser, char *filename ) +{ + mvcp_response response; + FILE *file = fopen( filename, "r" ); + if ( file != NULL ) + { + response = mvcp_parser_run_file( parser, file ); + fclose( file ); + } + else + { + response = mvcp_response_init( ); + mvcp_response_set_error( response, 404, "File not found." ); + } + return response; +} + /** Get the notifier associated to the parser. */