binemul.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* Binutils emulation layer.
  2. Copyright (C) 2002-2015 Free Software Foundation, Inc.
  3. Written by Tom Rix, Red Hat Inc.
  4. This file is part of GNU Binutils.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #include "binemul.h"
  18. extern bin_emulation_xfer_type bin_dummy_emulation;
  19. void
  20. ar_emul_usage (FILE *fp)
  21. {
  22. if (bin_dummy_emulation.ar_usage)
  23. bin_dummy_emulation.ar_usage (fp);
  24. }
  25. void
  26. ar_emul_default_usage (FILE *fp)
  27. {
  28. AR_EMUL_USAGE_PRINT_OPTION_HEADER (fp);
  29. /* xgettext:c-format */
  30. fprintf (fp, _(" No emulation specific options\n"));
  31. }
  32. bfd_boolean
  33. ar_emul_append (bfd **after_bfd, char *file_name, const char *target,
  34. bfd_boolean verbose, bfd_boolean flatten)
  35. {
  36. if (bin_dummy_emulation.ar_append)
  37. return bin_dummy_emulation.ar_append (after_bfd, file_name, target,
  38. verbose, flatten);
  39. return FALSE;
  40. }
  41. static bfd_boolean
  42. any_ok (bfd *new_bfd ATTRIBUTE_UNUSED)
  43. {
  44. return TRUE;
  45. }
  46. bfd_boolean
  47. do_ar_emul_append (bfd **after_bfd, bfd *new_bfd,
  48. bfd_boolean verbose, bfd_boolean flatten,
  49. bfd_boolean (*check) (bfd *))
  50. {
  51. /* When flattening, add the members of an archive instead of the
  52. archive itself. */
  53. if (flatten && bfd_check_format (new_bfd, bfd_archive))
  54. {
  55. bfd *elt;
  56. bfd_boolean added = FALSE;
  57. for (elt = bfd_openr_next_archived_file (new_bfd, NULL);
  58. elt;
  59. elt = bfd_openr_next_archived_file (new_bfd, elt))
  60. {
  61. if (do_ar_emul_append (after_bfd, elt, verbose, TRUE, check))
  62. {
  63. added = TRUE;
  64. after_bfd = &((*after_bfd)->archive_next);
  65. }
  66. }
  67. return added;
  68. }
  69. if (!check (new_bfd))
  70. return FALSE;
  71. AR_EMUL_APPEND_PRINT_VERBOSE (verbose, new_bfd->filename);
  72. new_bfd->archive_next = *after_bfd;
  73. *after_bfd = new_bfd;
  74. return TRUE;
  75. }
  76. bfd_boolean
  77. ar_emul_default_append (bfd **after_bfd, char *file_name,
  78. const char *target, bfd_boolean verbose,
  79. bfd_boolean flatten)
  80. {
  81. bfd *new_bfd;
  82. new_bfd = bfd_openr (file_name, target);
  83. AR_EMUL_ELEMENT_CHECK (new_bfd, file_name);
  84. return do_ar_emul_append (after_bfd, new_bfd, verbose, flatten, any_ok);
  85. }
  86. bfd_boolean
  87. ar_emul_replace (bfd **after_bfd, char *file_name, const char *target,
  88. bfd_boolean verbose)
  89. {
  90. if (bin_dummy_emulation.ar_replace)
  91. return bin_dummy_emulation.ar_replace (after_bfd, file_name,
  92. target, verbose);
  93. return FALSE;
  94. }
  95. bfd_boolean
  96. ar_emul_default_replace (bfd **after_bfd, char *file_name,
  97. const char *target, bfd_boolean verbose)
  98. {
  99. bfd *new_bfd;
  100. new_bfd = bfd_openr (file_name, target);
  101. AR_EMUL_ELEMENT_CHECK (new_bfd, file_name);
  102. AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, file_name);
  103. new_bfd->archive_next = *after_bfd;
  104. *after_bfd = new_bfd;
  105. return TRUE;
  106. }
  107. bfd_boolean
  108. ar_emul_parse_arg (char *arg)
  109. {
  110. if (bin_dummy_emulation.ar_parse_arg)
  111. return bin_dummy_emulation.ar_parse_arg (arg);
  112. return FALSE;
  113. }
  114. bfd_boolean
  115. ar_emul_default_parse_arg (char *arg ATTRIBUTE_UNUSED)
  116. {
  117. return FALSE;
  118. }