daily update
[binutils.git] / binutils / binemul.c
blob6bfcb15a85997f2aa014176e5b04ac8e5e370a93
1 /* Binutils emulation layer.
2 Copyright 2002, 2003, 2005, 2007, 2008, 2010
3 Free Software Foundation, Inc.
4 Written by Tom Rix, Red Hat Inc.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
23 #include "binemul.h"
25 extern bin_emulation_xfer_type bin_dummy_emulation;
27 void
28 ar_emul_usage (FILE *fp)
30 if (bin_dummy_emulation.ar_usage)
31 bin_dummy_emulation.ar_usage (fp);
34 void
35 ar_emul_default_usage (FILE *fp)
37 AR_EMUL_USAGE_PRINT_OPTION_HEADER (fp);
38 /* xgettext:c-format */
39 fprintf (fp, _(" No emulation specific options\n"));
42 bfd_boolean
43 ar_emul_append (bfd **after_bfd, char *file_name, const char *target,
44 bfd_boolean verbose, bfd_boolean flatten)
46 if (bin_dummy_emulation.ar_append)
47 return bin_dummy_emulation.ar_append (after_bfd, file_name, target,
48 verbose, flatten);
50 return FALSE;
53 static bfd_boolean
54 any_ok (bfd *new_bfd ATTRIBUTE_UNUSED)
56 return TRUE;
59 bfd_boolean
60 do_ar_emul_append (bfd **after_bfd, bfd *new_bfd,
61 bfd_boolean verbose, bfd_boolean flatten,
62 bfd_boolean (*check) (bfd *))
64 /* When flattening, add the members of an archive instead of the
65 archive itself. */
66 if (flatten && bfd_check_format (new_bfd, bfd_archive))
68 bfd *elt;
69 bfd_boolean added = FALSE;
71 for (elt = bfd_openr_next_archived_file (new_bfd, NULL);
72 elt;
73 elt = bfd_openr_next_archived_file (new_bfd, elt))
75 if (do_ar_emul_append (after_bfd, elt, verbose, TRUE, check))
77 added = TRUE;
78 after_bfd = &((*after_bfd)->archive_next);
82 return added;
85 if (!check (new_bfd))
86 return FALSE;
88 AR_EMUL_APPEND_PRINT_VERBOSE (verbose, new_bfd->filename);
90 new_bfd->archive_next = *after_bfd;
91 *after_bfd = new_bfd;
93 return TRUE;
96 bfd_boolean
97 ar_emul_default_append (bfd **after_bfd, char *file_name,
98 const char *target, bfd_boolean verbose,
99 bfd_boolean flatten)
101 bfd *new_bfd;
103 new_bfd = bfd_openr (file_name, target);
104 AR_EMUL_ELEMENT_CHECK (new_bfd, file_name);
105 return do_ar_emul_append (after_bfd, new_bfd, verbose, flatten, any_ok);
108 bfd_boolean
109 ar_emul_replace (bfd **after_bfd, char *file_name, const char *target,
110 bfd_boolean verbose)
112 if (bin_dummy_emulation.ar_replace)
113 return bin_dummy_emulation.ar_replace (after_bfd, file_name,
114 target, verbose);
116 return FALSE;
119 bfd_boolean
120 ar_emul_default_replace (bfd **after_bfd, char *file_name,
121 const char *target, bfd_boolean verbose)
123 bfd *new_bfd;
125 new_bfd = bfd_openr (file_name, target);
126 AR_EMUL_ELEMENT_CHECK (new_bfd, file_name);
128 AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, file_name);
130 new_bfd->archive_next = *after_bfd;
131 *after_bfd = new_bfd;
133 return TRUE;
136 bfd_boolean
137 ar_emul_parse_arg (char *arg)
139 if (bin_dummy_emulation.ar_parse_arg)
140 return bin_dummy_emulation.ar_parse_arg (arg);
142 return FALSE;
145 bfd_boolean
146 ar_emul_default_parse_arg (char *arg ATTRIBUTE_UNUSED)
148 return FALSE;