From 3de39064591933bc0fbc9141406a206644ced4fd Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sun, 12 Sep 1999 18:14:07 +0000 Subject: 1999-09-12 Donn Terry * ar.c (counted_name_mode): New static variable. (counted_name_counter): New static variable. (map_over_members): Handle counted mode. (usage): Mention N modifier. (main): Handle N modifier. (delete_members): Handle counted mode. * binutils.texi, ar.1: Document N modifier. --- binutils/ar.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 16 deletions(-) (limited to 'binutils/ar.c') diff --git a/binutils/ar.c b/binutils/ar.c index 4fe166a..50d1edc7 100644 --- a/binutils/ar.c +++ b/binutils/ar.c @@ -147,6 +147,11 @@ enum pos static bfd ** get_pos_bfd PARAMS ((bfd **, enum pos, const char *)); +/* For extract/delete only. If COUNTED_NAME_MODE is true, we only + extract the COUNTED_NAME_COUNTER instance of that name. */ +static boolean counted_name_mode = 0; +static int counted_name_counter = 0; + /* Whether to truncate names of files stored in the archive. */ static boolean ar_truncate = false; @@ -176,6 +181,7 @@ map_over_members (arch, function, files, count) int count; { bfd *head; + int match_count; if (count == 0) { @@ -186,6 +192,7 @@ map_over_members (arch, function, files, count) } return; } + /* This may appear to be a baroque way of accomplishing what we want. However we have to iterate over the filenames in order to notice where a filename is requested but does not exist in the archive. Ditto @@ -196,6 +203,7 @@ map_over_members (arch, function, files, count) { boolean found = false; + match_count = 0; for (head = arch->next; head; head = head->next) { PROGRESS (1); @@ -209,6 +217,15 @@ map_over_members (arch, function, files, count) if ((head->filename != NULL) && (!strcmp (normalize (*files, arch), head->filename))) { + ++match_count; + if (counted_name_mode + && match_count != counted_name_counter) + { + /* Counting, and didn't match on count; go on to the + next one. */ + continue; + } + found = true; function (head); } @@ -232,7 +249,8 @@ usage (help) if (! is_ranlib) { /* xgettext:c-format */ - fprintf (s, _("Usage: %s [-]{dmpqrstx}[abcilosSuvV] [member-name] archive-file file...\n"), program_name); + fprintf (s, _("Usage: %s [-]{dmpqrstx}[abcfilNoPsSuvV] [member-name] [count] archive-file file...\n"), + program_name); /* xgettext:c-format */ fprintf (s, _(" %s -M [next); while (*current_ptr_ptr) { - if (strcmp (*files_to_delete, (*current_ptr_ptr)->filename) == 0) - { - found = true; - something_changed = true; - if (verbose) - printf ("d - %s\n", - *files_to_delete); - *current_ptr_ptr = ((*current_ptr_ptr)->next); - goto next_file; - } - else + if (strcmp (normalize (*files_to_delete, arch), + (*current_ptr_ptr)->filename) == 0) { - current_ptr_ptr = &((*current_ptr_ptr)->next); + ++match_count; + if (counted_name_mode + && match_count != counted_name_counter) + { + /* Counting, and didn't match on count; go on to the + next one. */ + } + else + { + found = true; + something_changed = true; + if (verbose) + printf ("d - %s\n", + *files_to_delete); + *current_ptr_ptr = ((*current_ptr_ptr)->next); + goto next_file; + } } + + current_ptr_ptr = &((*current_ptr_ptr)->next); } if (verbose && found == false) -- cgit v1.1