2008-12-07 22:37:07 +03:00
/*
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
2009-02-24 16:03:45 +03:00
* Copyright ( C ) 2004 - 2009 Red Hat , Inc . All rights reserved .
2008-12-07 22:37:07 +03:00
*
* This file is part of LVM2 .
*
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License v .2 .1 .
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <readline/readline.h>
2009-02-24 16:03:45 +03:00
# include "lvm.h"
2008-12-07 22:37:07 +03:00
# define MAX_ARGS 64
static int lvm_split ( char * str , int * argc , char * * argv , int max )
{
char * b = str , * e ;
* argc = 0 ;
while ( * b ) {
while ( * b & & isspace ( * b ) )
b + + ;
if ( ( ! * b ) | | ( * b = = ' # ' ) )
break ;
e = b ;
while ( * e & & ! isspace ( * e ) )
e + + ;
argv [ ( * argc ) + + ] = b ;
if ( ! * e )
break ;
* e + + = ' \0 ' ;
b = e ;
if ( * argc = = max )
break ;
}
return * argc ;
}
2009-02-24 16:03:45 +03:00
static int lvmapi_test_shell ( lvm_t libh )
2008-12-07 22:37:07 +03:00
{
int argc , i ;
char * input = NULL , * args [ MAX_ARGS ] , * * argv ;
while ( 1 ) {
free ( input ) ;
input = readline ( " lvm> " ) ;
/* EOF */
if ( ! input ) {
printf ( " \n " ) ;
break ;
}
/* empty line */
if ( ! * input )
continue ;
argv = args ;
if ( lvm_split ( input , & argc , argv , MAX_ARGS ) = = MAX_ARGS ) {
printf ( " Too many arguments, sorry. " ) ;
continue ;
}
if ( ! strcmp ( argv [ 0 ] , " lvm " ) ) {
argv + + ;
argc - - ;
}
if ( ! argc )
continue ;
if ( ! strcmp ( argv [ 0 ] , " quit " ) | | ! strcmp ( argv [ 0 ] , " exit " ) ) {
printf ( " Exiting. \n " ) ;
break ;
} else if ( ! strcmp ( argv [ 0 ] , " ? " ) | | ! strcmp ( argv [ 0 ] , " help " ) ) {
printf ( " No commands defined \n " ) ;
} else if ( ! strcmp ( argv [ 0 ] , " scan " ) ) {
for ( i = 1 ; i < argc ; i + + )
printf ( " Scan a path! \n " ) ;
}
}
free ( input ) ;
return 0 ;
}
int main ( int argc , char * argv [ ] )
{
2009-02-24 16:03:45 +03:00
lvm_t libh ;
2008-12-07 22:37:07 +03:00
2009-02-24 16:03:45 +03:00
libh = lvm_create ( NULL ) ;
if ( ! libh ) {
2008-12-07 22:37:07 +03:00
printf ( " Unable to open lvm library instance \n " ) ;
return 1 ;
}
2009-02-24 16:03:45 +03:00
lvmapi_test_shell ( libh ) ;
2008-12-07 22:37:07 +03:00
2009-02-24 16:03:45 +03:00
lvm_destroy ( libh ) ;
2008-12-07 22:37:07 +03:00
return 0 ;
}