diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-04-13 15:10:01 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-04-13 15:10:01 +0000 |
commit | eb4a870be600f3f8704737278ef75c7d050f7172 (patch) | |
tree | 835c65ea2d5d349e7ec5472f1f9c08a9ffccc388 /contrib/lar/cli.c | |
parent | 725b3862ca1c6b0a960cf48a9e310eb11c0a087d (diff) |
contrib/lar:
- add lua binding for lar library
- introduce mmap() support for lua
Diffstat (limited to 'contrib/lar/cli.c')
-rw-r--r-- | contrib/lar/cli.c | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/contrib/lar/cli.c b/contrib/lar/cli.c index 098f55d9d..36216d46e 100644 --- a/contrib/lar/cli.c +++ b/contrib/lar/cli.c @@ -18,16 +18,24 @@ int do_print_member( lar_archive *ar, const char *name ) int do_print_index( lar_archive *ar ) { lar_index *index = ar->index; - LAR_FNAME(filename); - while(index) + if( ar->has_filenames ) { - lar_get_filename(ar, index, filename); - printf("%s\n", filename); - index = index->next; + while(index) + { + if( index->type == LAR_TYPE_REGULAR ) + { + printf("%s\n", index->filename); + } + + index = index->next; + } + + return 0; } - return 0; + LAR_DIE("The archive contains no file list"); + return 1; } int do_require( const char *package, const char *path ) @@ -36,7 +44,7 @@ int do_require( const char *package, const char *path ) lar_archive *ar; lar_member *mb; - if( (ar = lar_find_archive(package, path)) != NULL ) + if( (ar = lar_find_archive(package, path, 1)) != NULL ) { if( (mb = lar_find_member(ar, package)) != NULL ) { @@ -51,12 +59,33 @@ int do_require( const char *package, const char *path ) return stat; } +int do_findfile( const char *filename, const char *path ) +{ + int stat = 1; + lar_archive *ar; + lar_member *mb; + + if( (ar = lar_find_archive(filename, path, 0)) != NULL ) + { + if( (mb = lar_open_member(ar, filename)) != 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[] ) { lar_archive *ar; int stat = 0; - if( argv[1] != NULL ) + if( argv[1] != NULL && argv[2] != NULL ) { switch(argv[1][0]) { @@ -80,6 +109,10 @@ int main( int argc, const char* argv[] ) case 'r': stat = do_require(argv[2], argv[3]); break; + + case 'f': + stat = do_findfile(argv[2], argv[3]); + break; } return stat; @@ -89,6 +122,7 @@ int main( int argc, const char* argv[] ) printf("Usage:\n"); printf("\tlar show <archive> [<member>]\n"); printf("\tlar require <package> [<path>]\n"); + printf("\tlar find <filename> [<path>]\n"); return 1; } |