]> git.sesse.net Git - mlt/blob - src/albino/albino.c
Cleanup license declarations and remove dv1394d references.
[mlt] / src / albino / albino.c
1 /*
2  * albino.c -- Local Valerie/Miracle Test Utility
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 #include <sched.h>
26
27 /* Application header files */
28 #include <miracle/miracle_local.h>
29 #include <valerie/valerie_remote.h>
30 #include <valerie/valerie_util.h>
31
32 char *prompt( char *command, int length )
33 {
34         printf( "> " );
35         return fgets( command, length, stdin );
36 }
37
38 void report( valerie_response response )
39 {
40         int index = 0;
41         if ( response != NULL )
42                 for ( index = 0; index < valerie_response_count( response ); index ++ )
43                         printf( "%4d: %s\n", index, valerie_response_get_line( response, index ) );
44 }
45
46 int main( int argc, char **argv  )
47 {
48         valerie_parser parser = NULL;
49         valerie_response response = NULL;
50         char temp[ 1024 ];
51         int index = 1;
52
53         if ( argc > 2 && !strcmp( argv[ 1 ], "-s" ) )
54         {
55                 printf( "Miracle Client Instance\n" );
56                 parser = valerie_parser_init_remote( argv[ 2 ], 5250 );
57                 response = valerie_parser_connect( parser );
58                 index = 3;
59         }
60         else
61         {
62                 struct sched_param scp;
63         
64                 // Use realtime scheduling if possible
65                 memset( &scp, '\0', sizeof( scp ) );
66                 scp.sched_priority = sched_get_priority_max( SCHED_FIFO ) - 1;
67 #ifndef __DARWIN__
68                 sched_setscheduler( 0, SCHED_FIFO, &scp );
69 #endif
70
71                 printf( "Miracle Standalone Instance\n" );
72                 parser = miracle_parser_init_local( );
73                 response = valerie_parser_connect( parser );
74         }
75
76         if ( response != NULL )
77         {
78                 /* process files on command lines before going into console mode */
79                 for ( ; index < argc; index ++ )
80                 {
81                         valerie_response_close( response );
82                         response = valerie_parser_run( parser, argv[ index ] );
83                         report( response );
84                 }
85         
86                 while ( response != NULL && prompt( temp, 1024 ) )
87                 {
88                         valerie_util_trim( valerie_util_chomp( temp ) );
89                         if ( !strcasecmp( temp, "BYE" ) )
90                         {
91                                 break;
92                         }
93                         else if ( strcmp( temp, "" ) )
94                         {
95                                 valerie_response_close( response );
96                                 response = valerie_parser_execute( parser, temp );
97                                 report( response );
98                         }
99                 }
100         }
101         else
102         {
103                 fprintf( stderr, "Unable to connect to a Miracle instance.\n" );
104         }
105
106         printf( "\n" );
107         valerie_parser_close( parser );
108
109         return 0;
110 }