diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-04-06 14:28:17 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-04-06 14:28:17 +0000 |
commit | 50ccdfccce792d5bd013cae9eb93588a16a7ec62 (patch) | |
tree | 4476042099bc0933c82f9339ef50533af41bc5ca /contrib/lar/cli.c | |
parent | 1744f962b0c0d324aa9a5ebbbcfb4f98e312a217 (diff) |
contrib/lar:
- add lar_find_archive() and lar_find_member() to get a member handle from a packagename
- extend cli to cover new operations
Diffstat (limited to 'contrib/lar/cli.c')
-rw-r--r-- | contrib/lar/cli.c | 62 |
1 files changed, 48 insertions, 14 deletions
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 <archive> [<member>]\n"); + printf("Usage:\n"); + printf("\tlar show <archive> [<member>]\n"); + printf("\tlar require <package>\n"); + return 1; } return 0; } - |