Changeset 609 for branches/GNU/src/binutils/binutils/arsup.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/binutils/arsup.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* arsup.c - Archive support for MRI compatibility 2 Copyright 1992, 1994, 1995, 1996, 1997, 2000 2 Copyright 1992, 1994, 1995, 1996, 1997, 2000, 2002 3 3 Free Software Foundation, Inc. 4 4 5 This file is part of GNU Binutils.6 7 This program is free software; you can redistribute it and/or modify8 it under the terms of the GNU General Public License as published by9 the Free Software Foundation; either version 2 of the License, or10 (at your option) any later version.11 12 This program is distributed in the hope that it will be useful,13 but WITHOUT ANY WARRANTY; without even the implied warranty of14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 GNU General Public License for more details.16 17 You should have received a copy of the GNU General Public License18 along with this program; if not, write to the Free Software19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */5 This file is part of GNU Binutils. 6 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. 11 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. 16 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 20 20 21 21 22 22 /* Contributed by Steve Chamberlain 23 sac@cygnus.com 24 25 This file looks after requests from arparse.y, to provide the MRI 26 style librarian command syntax + 1 word LIST 27 28 */ 23 sac@cygnus.com 24 25 This file looks after requests from arparse.y, to provide the MRI 26 style librarian command syntax + 1 word LIST. */ 29 27 30 28 #include "bfd.h" … … 72 70 for (ptr = list; ptr; ptr = ptr->next) 73 71 { 74 b oolean found = false;72 bfd_boolean found = FALSE; 75 73 bfd *prev = arch; 76 74 77 for (head = arch->next; head; head = head->next) 75 for (head = arch->next; head; head = head->next) 78 76 { 79 77 if (head->filename != NULL 80 78 && FILENAME_CMP (ptr->name, head->filename) == 0) 81 79 { 82 found = true;80 found = TRUE; 83 81 function (head, prev); 84 82 } … … 94 92 FILE *outfile; 95 93 96 /*ARGSUSED*/97 94 static void 98 95 ar_directory_doer (abfd, ignore) … … 100 97 bfd *ignore ATTRIBUTE_UNUSED; 101 98 { 102 99 print_arelt_descr(outfile, abfd, verbose); 103 100 } 104 101 … … 122 119 } 123 120 } 124 else 121 else 125 122 outfile = stdout; 126 123 … … 137 134 { 138 135 extern int interactive; 139 if (interactive) 140 { 141 printf("AR >"); 142 fflush(stdout); 143 } 136 137 if (interactive) 138 { 139 printf ("AR >"); 140 fflush (stdout); 141 } 144 142 } 145 143 … … 147 145 maybequit () 148 146 { 149 if (! interactive) 147 if (! interactive) 150 148 xexit (9); 151 149 } … … 153 151 154 152 bfd *obfd; 155 char *real_name ;156 void 157 DEFUN(ar_open,(name, t), 158 char *name AND 159 int t)160 153 char *real_name; 154 155 void 156 ar_open (name, t) 157 char *name; 158 int t; 161 159 { 162 160 char *tname = (char *) xmalloc (strlen (name) + 10); 161 const char *bname = lbasename (name); 163 162 real_name = name; 163 164 164 /* Prepend tmp- to the beginning, to avoid file-name clashes after 165 165 truncation on filesystems with limited namespaces (DOS). */ 166 sprintf(tname, "tmp-%s", name); 167 obfd = bfd_openw(tname, NULL); 168 169 if (!obfd) { 170 fprintf(stderr,_("%s: Can't open output archive %s\n"), program_name, 171 tname); 172 173 maybequit(); 174 } 175 else { 176 if (!t) { 177 bfd **ptr; 178 bfd *element; 179 bfd *ibfd; 180 ibfd = bfd_openr(name, NULL); 181 if (!ibfd) { 182 fprintf(stderr,_("%s: Can't open input archive %s\n"), 183 program_name, name); 184 maybequit(); 185 return; 186 } 187 if (bfd_check_format(ibfd, bfd_archive) != true) { 188 fprintf(stderr,_("%s: file %s is not an archive\n"), program_name, 189 name); 190 maybequit(); 191 return; 192 } 193 ptr = &(obfd->archive_head); 194 element = bfd_openr_next_archived_file(ibfd, NULL); 195 196 while (element) { 197 *ptr = element; 198 ptr = &element->next; 199 element = bfd_openr_next_archived_file(ibfd, element); 200 } 201 } 202 203 bfd_set_format(obfd, bfd_archive); 204 205 obfd->has_armap = 1; 206 } 207 } 208 166 sprintf (tname, "%.*stmp-%s", (int) (bname - name), name, bname); 167 obfd = bfd_openw (tname, NULL); 168 169 if (!obfd) 170 { 171 fprintf (stderr, 172 _("%s: Can't open output archive %s\n"), 173 program_name, tname); 174 175 maybequit (); 176 } 177 else 178 { 179 if (!t) 180 { 181 bfd **ptr; 182 bfd *element; 183 bfd *ibfd; 184 185 ibfd = bfd_openr (name, NULL); 186 187 if (!ibfd) 188 { 189 fprintf (stderr,_("%s: Can't open input archive %s\n"), 190 program_name, name); 191 maybequit (); 192 return; 193 } 194 195 if (!bfd_check_format(ibfd, bfd_archive)) 196 { 197 fprintf (stderr, 198 _("%s: file %s is not an archive\n"), 199 program_name, name); 200 maybequit (); 201 return; 202 } 203 204 ptr = &(obfd->archive_head); 205 element = bfd_openr_next_archived_file (ibfd, NULL); 206 207 while (element) 208 { 209 *ptr = element; 210 ptr = &element->next; 211 element = bfd_openr_next_archived_file (ibfd, element); 212 } 213 } 214 215 bfd_set_format (obfd, bfd_archive); 216 217 obfd->has_armap = 1; 218 } 219 } 209 220 210 221 static void … … 213 224 bfd *prev; 214 225 { 215 /* Add this module to the output bfd */226 /* Add this module to the output bfd. */ 216 227 if (prev != NULL) 217 228 prev->next = abfd->next; 229 218 230 abfd->next = obfd->archive_head; 219 231 obfd->archive_head = abfd; … … 238 250 map_over_list (arch, ar_addlib_doer, list); 239 251 240 /* Don't close the bfd, since it will make the elements disasppear */ 241 } 242 } 243 244 void 245 DEFUN(ar_addmod, (list), 246 struct list *list) 247 { 248 if (!obfd) { 249 fprintf(stderr, _("%s: no open output archive\n"), program_name); 250 maybequit(); 251 } 252 else 253 { 254 while (list) { 255 bfd *abfd = bfd_openr(list->name, NULL); 256 if (!abfd) { 257 fprintf(stderr,_("%s: can't open file %s\n"), program_name, 258 list->name); 259 maybequit(); 260 } 261 else { 262 abfd->next = obfd->archive_head; 263 obfd->archive_head = abfd; 264 } 265 list = list->next; 266 } 267 } 268 } 269 270 271 272 void 273 DEFUN_VOID(ar_clear) 274 { 275 if (obfd) 276 obfd->archive_head = 0; 277 } 278 279 void 280 DEFUN(ar_delete, (list), 281 struct list *list) 282 { 283 if (!obfd) { 284 fprintf(stderr, _("%s: no open output archive\n"), program_name); 285 maybequit(); 286 } 287 else 288 { 289 while (list) { 290 /* Find this name in the archive */ 291 bfd *member = obfd->archive_head; 292 bfd **prev = &(obfd->archive_head); 293 int found = 0; 294 while (member) { 295 if (FILENAME_CMP(member->filename, list->name) == 0) { 296 *prev = member->next; 297 found = 1; 298 } 299 else { 300 prev = &(member->next); 301 } 302 member = member->next; 303 } 304 if (!found) { 305 fprintf(stderr,_("%s: can't find module file %s\n"), program_name, 306 list->name); 307 maybequit(); 308 } 309 list = list->next; 310 } 311 } 312 } 313 314 315 void 316 DEFUN_VOID(ar_save) 317 { 318 319 if (!obfd) { 320 fprintf(stderr, _("%s: no open output archive\n"), program_name); 321 maybequit(); 322 } 323 else { 324 char *ofilename = xstrdup (bfd_get_filename (obfd)); 325 bfd_close(obfd); 326 327 rename (ofilename, real_name); 328 obfd = 0; 329 free(ofilename); 330 } 331 } 332 333 334 335 void 336 DEFUN(ar_replace, (list), 337 struct list *list) 338 { 339 if (!obfd) { 340 fprintf(stderr, _("%s: no open output archive\n"), program_name); 341 maybequit(); 342 } 343 else 344 { 345 while (list) { 346 /* Find this name in the archive */ 347 bfd *member = obfd->archive_head; 348 bfd **prev = &(obfd->archive_head); 349 int found = 0; 350 while (member) 351 { 352 if (FILENAME_CMP(member->filename, list->name) == 0) 353 { 354 /* Found the one to replace */ 355 bfd *abfd = bfd_openr(list->name, 0); 356 if (!abfd) 357 { 358 fprintf(stderr, _("%s: can't open file %s\n"), program_name, list->name); 359 maybequit(); 360 } 361 else { 362 *prev = abfd; 363 abfd->next = member->next; 364 found = 1; 365 } 366 } 367 else { 368 prev = &(member->next); 369 } 370 member = member->next; 371 } 372 if (!found) { 373 bfd *abfd = bfd_openr(list->name, 0); 374 fprintf(stderr,_("%s: can't find module file %s\n"), program_name, 375 list->name); 376 if (!abfd) 377 { 378 fprintf(stderr, _("%s: can't open file %s\n"), program_name, list->name); 379 maybequit(); 380 } 381 else 382 { 383 *prev = abfd; 384 } 385 } 386 387 list = list->next; 388 } 389 } 390 } 391 392 /* And I added this one */ 393 void 394 DEFUN_VOID(ar_list) 395 { 396 if (!obfd) 397 { 398 fprintf(stderr, _("%s: no open output archive\n"), program_name); 399 maybequit(); 400 } 401 else { 402 bfd *abfd; 403 outfile = stdout; 404 verbose =1 ; 405 printf(_("Current open archive is %s\n"), bfd_get_filename (obfd)); 406 for (abfd = obfd->archive_head; 407 abfd != (bfd *)NULL; 408 abfd = abfd->next) 409 { 410 ar_directory_doer (abfd, (bfd *) NULL); 411 } 412 } 413 } 414 415 416 void 417 DEFUN_VOID(ar_end) 252 /* Don't close the bfd, since it will make the elements disasppear. */ 253 } 254 } 255 256 void 257 ar_addmod (list) 258 struct list *list; 259 { 260 if (!obfd) 261 { 262 fprintf (stderr, _("%s: no open output archive\n"), program_name); 263 maybequit (); 264 } 265 else 266 { 267 while (list) 268 { 269 bfd *abfd = bfd_openr (list->name, NULL); 270 271 if (!abfd) 272 { 273 fprintf (stderr, _("%s: can't open file %s\n"), 274 program_name, list->name); 275 maybequit (); 276 } 277 else 278 { 279 abfd->next = obfd->archive_head; 280 obfd->archive_head = abfd; 281 } 282 list = list->next; 283 } 284 } 285 } 286 287 288 void 289 ar_clear () 418 290 { 419 291 if (obfd) 420 { 421 fclose((FILE *)(obfd->iostream)); 422 unlink(bfd_get_filename (obfd)); 423 } 424 } 425 void 426 DEFUN(ar_extract,(list), 427 struct list *list) 428 { 429 if (!obfd) 430 { 431 432 fprintf(stderr, _("%s: no open archive\n"), program_name); 433 maybequit(); 434 } 435 else 436 { 437 while (list) { 438 /* Find this name in the archive */ 439 bfd *member = obfd->archive_head; 440 int found = 0; 441 while (member && !found) 442 { 443 if (FILENAME_CMP(member->filename, list->name) == 0) 444 { 445 extract_file(member); 446 found = 1; 447 } 448 449 member = member->next; 450 } 451 if (!found) { 452 bfd_openr(list->name, 0); 453 fprintf(stderr,_("%s: can't find module file %s\n"), program_name, 454 list->name); 455 456 } 457 list = list->next; 458 } 459 } 460 } 292 obfd->archive_head = 0; 293 } 294 295 void 296 ar_delete (list) 297 struct list *list; 298 { 299 if (!obfd) 300 { 301 fprintf (stderr, _("%s: no open output archive\n"), program_name); 302 maybequit (); 303 } 304 else 305 { 306 while (list) 307 { 308 /* Find this name in the archive. */ 309 bfd *member = obfd->archive_head; 310 bfd **prev = &(obfd->archive_head); 311 int found = 0; 312 313 while (member) 314 { 315 if (FILENAME_CMP(member->filename, list->name) == 0) 316 { 317 *prev = member->next; 318 found = 1; 319 } 320 else 321 prev = &(member->next); 322 323 member = member->next; 324 } 325 326 if (!found) 327 { 328 fprintf (stderr, _("%s: can't find module file %s\n"), 329 program_name, list->name); 330 maybequit (); 331 } 332 333 list = list->next; 334 } 335 } 336 } 337 338 void 339 ar_save () 340 { 341 if (!obfd) 342 { 343 fprintf (stderr, _("%s: no open output archive\n"), program_name); 344 maybequit (); 345 } 346 else 347 { 348 char *ofilename = xstrdup (bfd_get_filename (obfd)); 349 350 bfd_close (obfd); 351 352 rename (ofilename, real_name); 353 obfd = 0; 354 free (ofilename); 355 } 356 } 357 358 void 359 ar_replace (list) 360 struct list *list; 361 { 362 if (!obfd) 363 { 364 fprintf (stderr, _("%s: no open output archive\n"), program_name); 365 maybequit (); 366 } 367 else 368 { 369 while (list) 370 { 371 /* Find this name in the archive. */ 372 bfd *member = obfd->archive_head; 373 bfd **prev = &(obfd->archive_head); 374 int found = 0; 375 376 while (member) 377 { 378 if (FILENAME_CMP (member->filename, list->name) == 0) 379 { 380 /* Found the one to replace. */ 381 bfd *abfd = bfd_openr (list->name, 0); 382 383 if (!abfd) 384 { 385 fprintf (stderr, _("%s: can't open file %s\n"), 386 program_name, list->name); 387 maybequit (); 388 } 389 else 390 { 391 *prev = abfd; 392 abfd->next = member->next; 393 found = 1; 394 } 395 } 396 else 397 { 398 prev = &(member->next); 399 } 400 member = member->next; 401 } 402 403 if (!found) 404 { 405 bfd *abfd = bfd_openr (list->name, 0); 406 407 fprintf (stderr,_("%s: can't find module file %s\n"), 408 program_name, list->name); 409 if (!abfd) 410 { 411 fprintf (stderr, _("%s: can't open file %s\n"), 412 program_name, list->name); 413 maybequit (); 414 } 415 else 416 *prev = abfd; 417 } 418 419 list = list->next; 420 } 421 } 422 } 423 424 /* And I added this one. */ 425 void 426 ar_list () 427 { 428 if (!obfd) 429 { 430 fprintf (stderr, _("%s: no open output archive\n"), program_name); 431 maybequit (); 432 } 433 else 434 { 435 bfd *abfd; 436 437 outfile = stdout; 438 verbose =1 ; 439 printf (_("Current open archive is %s\n"), bfd_get_filename (obfd)); 440 441 for (abfd = obfd->archive_head; 442 abfd != (bfd *)NULL; 443 abfd = abfd->next) 444 ar_directory_doer (abfd, (bfd *) NULL); 445 } 446 } 447 448 void 449 ar_end () 450 { 451 if (obfd) 452 { 453 fclose ((FILE *)(obfd->iostream)); 454 unlink (bfd_get_filename (obfd)); 455 } 456 } 457 458 void 459 ar_extract (list) 460 struct list *list; 461 { 462 if (!obfd) 463 { 464 fprintf (stderr, _("%s: no open archive\n"), program_name); 465 maybequit (); 466 } 467 else 468 { 469 while (list) 470 { 471 /* Find this name in the archive. */ 472 bfd *member = obfd->archive_head; 473 int found = 0; 474 475 while (member && !found) 476 { 477 if (FILENAME_CMP (member->filename, list->name) == 0) 478 { 479 extract_file (member); 480 found = 1; 481 } 482 483 member = member->next; 484 } 485 486 if (!found) 487 { 488 bfd_openr (list->name, 0); 489 fprintf (stderr, _("%s: can't find module file %s\n"), 490 program_name, list->name); 491 } 492 493 list = list->next; 494 } 495 } 496 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.