1 /* arsup.c - Archive support for MRI compatibility */
3 /* Copyright (C) 1992 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* Contributed by Steve Chamberlain
25 This file looks after requests from arparse.y, to provide the MRI
26 style librarian command syntax + 1 word LIST
40 DEFUN(map_over_list
,(function
, list
),
41 void (*function
) () AND
48 for (head
= inarch
->next
; head
; head
= head
->next
){
54 This may appear to be a baroque way of accomplishing what we want.
55 however we have to iterate over the filenames in order to notice where
56 a filename is requested but does not exist in the archive. Ditto
57 mapping over each file each time -- we want to hack multiple
60 struct list
*ptr
= list
;
62 for (ptr
= list
; ptr
; ptr
=ptr
->next
)
64 boolean found
= false;
66 for (head
= inarch
->next
; head
; head
= head
->next
)
68 if ((head
->filename
!= NULL
) &&
69 (!strcmp(ptr
->name
, head
->filename
)))
78 fprintf(stderr
, "No entry %s in archive.\n", ptr
->name
);
86 DEFUN(ar_directory_doer
,(abfd
),
89 print_arelt_descr(outfile
, abfd
, verbose
);
93 DEFUN(ar_directory
,(ar_name
, list
, output
),
100 outfile
= fopen(output
,"w");
103 fprintf(stderr
,"Can't open file %s\n", output
);
110 map_over_list(ar_directory_doer
, list
);
119 extern int interactive
;
128 DEFUN_VOID(maybequit
)
138 DEFUN(ar_open
,(name
, t
),
143 char *tname
= malloc(strlen(name
)+10);
145 sprintf(tname
, "%s-tmp", name
);
146 obfd
= bfd_openw(tname
, NULL
);
149 fprintf(stderr
,"%s: Can't open output archive %s\n", program_name
,
159 ibfd
= bfd_openr(name
, NULL
);
160 if (bfd_check_format(ibfd
, bfd_archive
) != true) {
161 fprintf(stderr
,"%s: file %s is not an archive\n", program_name
,
166 ptr
= &(obfd
->archive_head
);
167 element
= bfd_openr_next_archived_file(ibfd
, NULL
);
171 ptr
= &element
->next
;
172 element
= bfd_openr_next_archived_file(ibfd
, element
);
176 bfd_set_format(obfd
, bfd_archive
);
184 DEFUN(ar_addlib_doer
, (abfd
, prev
),
188 /* Add this module to the output bfd */
190 prev
->next
= abfd
->next
;
191 abfd
->next
= obfd
->archive_head
;
192 obfd
->archive_head
= abfd
;
196 DEFUN(ar_addlib
, (name
, list
),
201 fprintf(stderr
, "%s: no output archive specified yet\n", program_name
);
205 if (open_inarch(name
) ) {
206 map_over_list(ar_addlib_doer
, list
);
208 /* Don't close the bfd, since it will make the elements disasppear */
215 DEFUN(ar_addmod
, (list
),
219 fprintf(stderr
, "%s: no open output archive\n", program_name
);
225 bfd
*abfd
= bfd_openr(list
->name
, NULL
);
227 fprintf(stderr
,"%s: can't open file %s\n", program_name
,
232 abfd
->next
= obfd
->archive_head
;
233 obfd
->archive_head
= abfd
;
246 obfd
->archive_head
= 0;
250 DEFUN(ar_delete
, (list
),
254 fprintf(stderr
, "%s: no open output archive\n", program_name
);
260 /* Find this name in the archive */
261 bfd
*member
= obfd
->archive_head
;
262 bfd
**prev
= &(obfd
->archive_head
);
265 if (strcmp(member
->filename
, list
->name
) == 0) {
266 *prev
= member
->next
;
270 prev
= &(member
->next
);
272 member
= member
->next
;
275 fprintf(stderr
,"%s: can't find module file %s\n", program_name
,
290 fprintf(stderr
, "%s: no open output archive\n", program_name
);
296 link(obfd
->filename
, real_name
);
297 unlink(obfd
->filename
);
305 DEFUN(ar_replace
, (list
),
309 fprintf(stderr
, "%s: no open output archive\n", program_name
);
315 /* Find this name in the archive */
316 bfd
*member
= obfd
->archive_head
;
317 bfd
**prev
= &(obfd
->archive_head
);
321 if (strcmp(member
->filename
, list
->name
) == 0)
323 /* Found the one to replace */
324 bfd
*abfd
= bfd_openr(list
->name
, 0);
327 fprintf(stderr
, "%s: can't open file %s\n", program_name
, list
->name
);
332 abfd
->next
= member
->next
;
337 prev
= &(member
->next
);
339 member
= member
->next
;
342 bfd
*abfd
= bfd_openr(list
->name
, 0);
343 fprintf(stderr
,"%s: can't find module file %s\n", program_name
,
347 fprintf(stderr
, "%s: can't open file %s\n", program_name
, list
->name
);
361 /* And I added this one */
367 fprintf(stderr
, "%s: no open output archive\n", program_name
);
374 printf("Current open archive is %s\n", obfd
->filename
);
375 for (abfd
= obfd
->archive_head
;
379 ar_directory_doer(abfd
);
386 DEFUN(ar_extract
,(list
),
392 fprintf(stderr
, "%s: no open archive\n", program_name
);
398 /* Find this name in the archive */
399 bfd
*member
= obfd
->archive_head
;
401 while (member
&& !found
)
403 if (strcmp(member
->filename
, list
->name
) == 0)
405 extract_file(member
);
409 member
= member
->next
;
412 bfd
*abfd
= bfd_openr(list
->name
, 0);
413 fprintf(stderr
,"%s: can't find module file %s\n", program_name
,
This page took 0.039334 seconds and 4 git commands to generate.