Add mvcp_parser_run_file().
authorDan Dennedy <dan@dennedy.org>
Sun, 17 Apr 2011 20:05:18 +0000 (13:05 -0700)
committerDan Dennedy <dan@dennedy.org>
Sun, 17 Apr 2011 20:05:18 +0000 (13:05 -0700)
src/mvcp/mvcp_parser.c
src/mvcp/mvcp_parser.h

index 5135d98..b199dad 100644 (file)
@@ -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.
 */
 
index 3e2f465..67d2bba 100644 (file)
@@ -65,6 +65,7 @@ extern mvcp_response mvcp_parser_push( mvcp_parser, char *, mlt_service );
 extern mvcp_response mvcp_parser_received( mvcp_parser, char *, char * );
 extern mvcp_response mvcp_parser_execute( mvcp_parser, char * );
 extern mvcp_response mvcp_parser_executef( mvcp_parser, const char *, ... );
+extern mvcp_response mvcp_parser_run_file( mvcp_parser parser, FILE *file );
 extern mvcp_response mvcp_parser_run( mvcp_parser, char * );
 extern mvcp_notifier mvcp_parser_get_notifier( mvcp_parser );
 extern void mvcp_parser_close( mvcp_parser );