aboutsummaryrefslogtreecommitdiff
path: root/archival/ar.c
diff options
context:
space:
mode:
Diffstat (limited to 'archival/ar.c')
-rw-r--r--archival/ar.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/archival/ar.c b/archival/ar.c
index 66930f0b8..eb734a685 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -48,19 +48,9 @@
48 48
49//kbuild:lib-$(CONFIG_AR) += ar.o 49//kbuild:lib-$(CONFIG_AR) += ar.o
50 50
51//usage:#define ar_trivial_usage
52//usage: "[-o] [-v] [-p] [-t] [-x] ARCHIVE FILES"
53//usage:#define ar_full_usage "\n\n"
54//usage: "Extract or list FILES from an ar archive\n"
55//usage: "\n -o Preserve original dates"
56//usage: "\n -p Extract to stdout"
57//usage: "\n -t List"
58//usage: "\n -x Extract"
59//usage: "\n -v Verbose"
60
61#include "libbb.h" 51#include "libbb.h"
62#include "bb_archive.h" 52#include "bb_archive.h"
63#include "ar.h" 53#include "ar_.h"
64 54
65#if ENABLE_FEATURE_AR_CREATE 55#if ENABLE_FEATURE_AR_CREATE
66/* filter out entries with same names as specified on the command line */ 56/* filter out entries with same names as specified on the command line */
@@ -236,23 +226,36 @@ static void FAST_FUNC header_verbose_list_ar(const file_header_t *file_header)
236 ); 226 );
237} 227}
238 228
239#define AR_OPT_VERBOSE (1 << 0) 229//usage:#define ar_trivial_usage
240#define AR_OPT_PRESERVE_DATE (1 << 1) 230//usage: "x|p|t"IF_FEATURE_AR_CREATE("|r")" [-ov] ARCHIVE [FILE]..."
241/* "ar r" implies create, but warns about it. c suppresses warning. 231//usage:#define ar_full_usage "\n\n"
242 * bbox accepts but ignores it: */ 232//usage: "Extract or list FILEs from an ar archive"IF_FEATURE_AR_CREATE(", or create it")"\n"
243#define AR_OPT_CREATE (1 << 2) 233//usage: "\n x Extract"
244 234//usage: "\n p Extract to stdout"
245#define AR_CMD_PRINT (1 << 3) 235//usage: "\n t List"
246#define FIRST_CMD AR_CMD_PRINT 236//usage: IF_FEATURE_AR_CREATE(
247#define AR_CMD_LIST (1 << 4) 237//usage: "\n r Create"
248#define AR_CMD_EXTRACT (1 << 5) 238//usage: )
249#define AR_CMD_INSERT (1 << 6) 239//usage: "\n -o Restore mtime"
240//usage: "\n -v Verbose"
250 241
251int ar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 242int ar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
252int ar_main(int argc UNUSED_PARAM, char **argv) 243int ar_main(int argc UNUSED_PARAM, char **argv)
253{ 244{
254 archive_handle_t *archive_handle; 245 archive_handle_t *archive_handle;
255 unsigned opt, t; 246 unsigned opt, t;
247 enum {
248 OPT_VERBOSE = (1 << 0),
249 OPT_PRESERVE_DATE = (1 << 1),
250 /* "ar r" implies create, but warns about it. c suppresses warning.
251 * bbox accepts but ignores it: */
252 OPT_CREATE = (1 << 2),
253 CMD_PRINT = (1 << 3),
254 FIRST_CMD = CMD_PRINT,
255 CMD_LIST = (1 << 4),
256 CMD_EXTRACT = (1 << 5),
257 CMD_INSERT = ((1 << 6) * ENABLE_FEATURE_AR_CREATE),
258 };
256 259
257 archive_handle = init_handle(); 260 archive_handle = init_handle();
258 261
@@ -272,26 +275,26 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
272 if (t & (t-1)) /* more than one of p,t,x[,r] are specified */ 275 if (t & (t-1)) /* more than one of p,t,x[,r] are specified */
273 bb_show_usage(); 276 bb_show_usage();
274 277
275 if (opt & AR_CMD_PRINT) { 278 if (opt & CMD_PRINT) {
276 archive_handle->action_data = data_extract_to_stdout; 279 archive_handle->action_data = data_extract_to_stdout;
277 } 280 }
278 if (opt & AR_CMD_LIST) { 281 if (opt & CMD_LIST) {
279 archive_handle->action_header = header_list; 282 archive_handle->action_header = header_list;
280 } 283 }
281 if (opt & AR_CMD_EXTRACT) { 284 if (opt & CMD_EXTRACT) {
282 archive_handle->action_data = data_extract_all; 285 archive_handle->action_data = data_extract_all;
283 } 286 }
284 if (opt & AR_OPT_PRESERVE_DATE) { 287 if (opt & OPT_PRESERVE_DATE) {
285 archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE; 288 archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
286 } 289 }
287 if (opt & AR_OPT_VERBOSE) { 290 if (opt & OPT_VERBOSE) {
288 archive_handle->action_header = header_verbose_list_ar; 291 archive_handle->action_header = header_verbose_list_ar;
289 } 292 }
290#if ENABLE_FEATURE_AR_CREATE 293#if ENABLE_FEATURE_AR_CREATE
291 archive_handle->ar__name = *argv; 294 archive_handle->ar__name = *argv;
292#endif 295#endif
293 archive_handle->src_fd = xopen(*argv++, 296 archive_handle->src_fd = xopen(*argv++,
294 (opt & AR_CMD_INSERT) 297 (opt & CMD_INSERT)
295 ? O_RDWR | O_CREAT 298 ? O_RDWR | O_CREAT
296 : O_RDONLY 299 : O_RDONLY
297 ); 300 );
@@ -303,7 +306,7 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
303 } 306 }
304 307
305#if ENABLE_FEATURE_AR_CREATE 308#if ENABLE_FEATURE_AR_CREATE
306 if (opt & AR_CMD_INSERT) 309 if (opt & CMD_INSERT)
307 return write_ar_archive(archive_handle); 310 return write_ar_archive(archive_handle);
308#endif 311#endif
309 312