From 50ccdfccce792d5bd013cae9eb93588a16a7ec62 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 6 Apr 2009 14:28:17 +0000 Subject: contrib/lar: - add lar_find_archive() and lar_find_member() to get a member handle from a packagename - extend cli to cover new operations --- contrib/lar/cli.c | 62 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 14 deletions(-) (limited to 'contrib/lar/cli.c') diff --git a/contrib/lar/cli.c b/contrib/lar/cli.c index 2b5e08891..e8daf63a5 100644 --- a/contrib/lar/cli.c +++ b/contrib/lar/cli.c @@ -27,7 +27,28 @@ int do_print_index( lar_archive *ar ) index = index->next; } - return 0; + return 0; +} + +int do_require( const char *package ) +{ + int stat = 1; + lar_archive *ar; + lar_member *mb; + + if( (ar = lar_find_archive(package)) != NULL ) + { + if( (mb = lar_find_member(ar, package)) != NULL ) + { + write(fileno(stdout), mb->data, mb->length); + lar_close_member(mb); + stat = 0; + } + + lar_close(ar); + } + + return stat; } int main( int argc, const char* argv[] ) @@ -37,27 +58,40 @@ int main( int argc, const char* argv[] ) if( argv[1] != NULL ) { - if( (ar = lar_open(argv[1])) != NULL ) + switch(argv[1][0]) { - if( argv[2] ) - stat = do_print_member(ar, argv[2]); - else - stat = do_print_index(ar); + case 's': + if( (ar = lar_open(argv[2])) != NULL ) + { + if( argv[3] != NULL ) + stat = do_print_member(ar, argv[3]); + else + stat = do_print_index(ar); - lar_close(ar); - return stat; - } - else - { - LAR_DIE("Failed to open archive"); + lar_close(ar); + } + else + { + LAR_DIE("Failed to open archive"); + } + + break; + + case 'r': + stat = do_require(argv[2]); + break; } + + return stat; } else { - printf("Usage: lar []\n"); + printf("Usage:\n"); + printf("\tlar show []\n"); + printf("\tlar require \n"); + return 1; } return 0; } - -- cgit v1.2.3