]> git.sesse.net Git - mlt/blob - src/albino/albino.c
albino
[mlt] / src / albino / albino.c
1 /*
2  * albino.c -- Local dv1394d Test Util
3  * Copyright (C) 2002-2003 Ushodaya Enterprises Limited
4  * Author: Charles Yates <charles.yates@pandora.be>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 /* System header files */
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 /* Application header files */
27 #include <miracle/miracle_local.h>
28 #include <valerie/valerie_remote.h>
29 #include <valerie/valerie_util.h>
30
31 char *prompt( char *command, int length )
32 {
33         printf( "> " );
34         return fgets( command, length, stdin );
35 }
36
37 void report( valerie_response response )
38 {
39         int index = 0;
40         if ( response != NULL )
41                 for ( index = 0; index < valerie_response_count( response ); index ++ )
42                         printf( "%4d: %s\n", index, valerie_response_get_line( response, index ) );
43 }
44
45 int main( int argc, char **argv  )
46 {
47         valerie_parser parser = NULL;
48         valerie_response response = NULL;
49         char temp[ 1024 ];
50         int index = 1;
51
52         if ( argc > 2 && !strcmp( argv[ 1 ], "-s" ) )
53         {
54                 printf( "DV1394D Client Instance\n" );
55                 parser = valerie_parser_init_remote( argv[ 2 ], 5250 );
56                 response = valerie_parser_connect( parser );
57                 index = 3;
58         }
59         else
60         {
61                 printf( "DV1394D Standalone Instance\n" );
62                 parser = miracle_parser_init_local( );
63                 response = valerie_parser_connect( parser );
64         }
65
66         if ( response != NULL )
67         {
68                 /* process files on command lines before going into console mode */
69                 for ( ; index < argc; index ++ )
70                 {
71                         valerie_response_close( response );
72                         response = valerie_parser_run( parser, argv[ index ] );
73                         report( response );
74                 }
75         
76                 while ( response != NULL && prompt( temp, 1024 ) )
77                 {
78                         valerie_util_trim( valerie_util_chomp( temp ) );
79                         if ( !strcmp( temp, "BYE" ) )
80                         {
81                                 break;
82                         }
83                         else if ( strcmp( temp, "" ) )
84                         {
85                                 valerie_response_close( response );
86                                 response = valerie_parser_execute( parser, temp );
87                                 report( response );
88                         }
89                 }
90         }
91         else
92         {
93                 fprintf( stderr, "Unable to connect to a dv1394 instance.\n" );
94         }
95
96         printf( "\n" );
97         valerie_parser_close( parser );
98
99         return 0;
100 }