Back to index

cell-binutils  2.17cvs20070401
Classes | Functions | Variables
arsup.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  list

Functions

void maybequit (void)
void prompt (void)
void ar_clear (void)
void ar_replace (struct list *)
void ar_delete (struct list *)
void ar_save (void)
void ar_list (void)
void ar_open (char *, int)
void ar_directory (char *, struct list *, char *)
void ar_addmod (struct list *)
void ar_addlib (char *, struct list *)
void ar_end (void)
void ar_extract (struct list *)
bfdopen_inarch (const char *archive_filename, const char *)
int yylex (void)
int yyparse (void)
void extract_file (bfd *abfd)

Variables

int interactive

Class Documentation

struct list

Definition at line 21 of file arsup.h.

Collaboration diagram for list:
Class Members
char * name
struct list * next

Function Documentation

void ar_addlib ( char *  ,
struct list  
)

Definition at line 223 of file arsup.c.

{
  if (obfd == NULL)
    {
      fprintf (stderr, _("%s: no output archive specified yet\n"), program_name);
      maybequit ();
    }
  else
    {
      bfd *arch;

      arch = open_inarch (name, (char *) NULL);
      if (arch != NULL)
       map_over_list (arch, ar_addlib_doer, list);

      /* Don't close the bfd, since it will make the elements disappear.  */
    }
}

Here is the call graph for this function:

void ar_addmod ( struct list )

Definition at line 243 of file arsup.c.

{
  if (!obfd)
    {
      fprintf (stderr, _("%s: no open output archive\n"), program_name);
      maybequit ();
    }
  else
    {
      while (list)
       {
         bfd *abfd = bfd_openr (list->name, NULL);

         if (!abfd)
           {
             fprintf (stderr, _("%s: can't open file %s\n"),
                     program_name, list->name);
             maybequit ();
           }
         else
           {
             abfd->next = obfd->archive_head;
             obfd->archive_head = abfd;
           }
         list = list->next;
       }
    }
}

Here is the call graph for this function:

void ar_clear ( void  )

Definition at line 274 of file arsup.c.

{
  if (obfd)
    obfd->archive_head = 0;
}
void ar_delete ( struct list )

Definition at line 281 of file arsup.c.

{
  if (!obfd)
    {
      fprintf (stderr, _("%s: no open output archive\n"), program_name);
      maybequit ();
    }
  else
    {
      while (list)
       {
         /* Find this name in the archive.  */
         bfd *member = obfd->archive_head;
         bfd **prev = &(obfd->archive_head);
         int found = 0;

         while (member)
           {
             if (FILENAME_CMP(member->filename, list->name) == 0)
              {
                *prev = member->next;
                found = 1;
              }
             else
              prev = &(member->next);

             member = member->next;
           }

         if (!found)
           {
             fprintf (stderr, _("%s: can't find module file %s\n"),
                     program_name, list->name);
             maybequit ();
           }

         list = list->next;
       }
    }
}

Here is the call graph for this function:

void ar_directory ( char *  ,
struct list ,
char *   
)

Definition at line 101 of file arsup.c.

{
  bfd *arch;

  arch = open_inarch (ar_name, (char *) NULL);
  if (output)
    {
      outfile = fopen(output,"w");
      if (outfile == 0)
       {
         outfile = stdout;
         fprintf (stderr,_("Can't open file %s\n"), output);
         output = 0;
       }
    }
  else
    outfile = stdout;

  map_over_list (arch, ar_directory_doer, list);

  bfd_close (arch);

  if (output)
   fclose (outfile);
}

Here is the call graph for this function:

void ar_end ( void  )

Definition at line 432 of file arsup.c.

{
  if (obfd)
    {
      bfd_cache_close (obfd);
      unlink (bfd_get_filename (obfd));
    }
}

Here is the call graph for this function:

void ar_extract ( struct list )

Definition at line 442 of file arsup.c.

{
  if (!obfd)
    {
      fprintf (stderr, _("%s: no open archive\n"), program_name);
      maybequit ();
    }
  else
    {
      while (list)
       {
         /* Find this name in the archive.  */
         bfd *member = obfd->archive_head;
         int found = 0;

         while (member && !found)
           {
             if (FILENAME_CMP (member->filename, list->name) == 0)
              {
                extract_file (member);
                found = 1;
              }

             member = member->next;
           }

         if (!found)
           {
             bfd_openr (list->name, 0);
             fprintf (stderr, _("%s: can't find module file %s\n"),
                     program_name, list->name);
           }

         list = list->next;
       }
    }
}

Here is the call graph for this function:

void ar_list ( void  )

Definition at line 409 of file arsup.c.

{
  if (!obfd)
    {
      fprintf (stderr, _("%s: no open output archive\n"), program_name);
      maybequit ();
    }
  else
    {
      bfd *abfd;

      outfile = stdout;
      verbose =1 ;
      printf (_("Current open archive is %s\n"), bfd_get_filename (obfd));

      for (abfd = obfd->archive_head;
          abfd != (bfd *)NULL;
          abfd = abfd->next)
       ar_directory_doer (abfd, (bfd *) NULL);
    }
}

Here is the call graph for this function:

void ar_open ( char *  ,
int   
)

Definition at line 148 of file arsup.c.

{
  char *tname = (char *) xmalloc (strlen (name) + 10);
  const char *bname = lbasename (name);
  real_name = name;

  /* Prepend tmp- to the beginning, to avoid file-name clashes after
     truncation on filesystems with limited namespaces (DOS).  */
  sprintf (tname, "%.*stmp-%s", (int) (bname - name), name, bname);
  obfd = bfd_openw (tname, NULL);

  if (!obfd)
    {
      fprintf (stderr,
              _("%s: Can't open output archive %s\n"),
              program_name,  tname);

      maybequit ();
    }
  else
    {
      if (!t)
       {
         bfd **ptr;
         bfd *element;
         bfd *ibfd;

         ibfd = bfd_openr (name, NULL);

         if (!ibfd)
           {
             fprintf (stderr,_("%s: Can't open input archive %s\n"),
                     program_name, name);
             maybequit ();
             return;
           }

         if (!bfd_check_format(ibfd, bfd_archive))
           {
             fprintf (stderr,
                     _("%s: file %s is not an archive\n"),
                     program_name, name);
             maybequit ();
             return;
           }

         ptr = &(obfd->archive_head);
         element = bfd_openr_next_archived_file (ibfd, NULL);

         while (element)
           {
             *ptr = element;
             ptr = &element->next;
             element = bfd_openr_next_archived_file (ibfd, element);
           }
       }

      bfd_set_format (obfd, bfd_archive);

      obfd->has_armap = 1;
    }
}

Here is the call graph for this function:

void ar_replace ( struct list )

Definition at line 343 of file arsup.c.

{
  if (!obfd)
    {
      fprintf (stderr, _("%s: no open output archive\n"), program_name);
      maybequit ();
    }
  else
    {
      while (list)
       {
         /* Find this name in the archive.  */
         bfd *member = obfd->archive_head;
         bfd **prev = &(obfd->archive_head);
         int found = 0;

         while (member)
           {
             if (FILENAME_CMP (member->filename, list->name) == 0)
              {
                /* Found the one to replace.  */
                bfd *abfd = bfd_openr (list->name, 0);

                if (!abfd)
                  {
                    fprintf (stderr, _("%s: can't open file %s\n"),
                            program_name, list->name);
                    maybequit ();
                  }
                else
                  {
                    *prev = abfd;
                    abfd->next = member->next;
                    found = 1;
                  }
              }
             else
              {
                prev = &(member->next);
              }
             member = member->next;
           }

         if (!found)
           {
             bfd *abfd = bfd_openr (list->name, 0);

             fprintf (stderr,_("%s: can't find module file %s\n"),
                     program_name, list->name);
             if (!abfd)
              {
                fprintf (stderr, _("%s: can't open file %s\n"),
                        program_name, list->name);
                maybequit ();
              }
             else
              *prev = abfd;
           }

         list = list->next;
       }
    }
}

Here is the call graph for this function:

void ar_save ( void  )

Definition at line 323 of file arsup.c.

{
  if (!obfd)
    {
      fprintf (stderr, _("%s: no open output archive\n"), program_name);
      maybequit ();
    }
  else
    {
      char *ofilename = xstrdup (bfd_get_filename (obfd));

      bfd_close (obfd);

      smart_rename (ofilename, real_name, 0);
      obfd = 0;
      free (ofilename);
    }
}

Here is the call graph for this function:

void extract_file ( bfd abfd)

Definition at line 830 of file ar.c.

{
  FILE *ostream;
  char *cbuf = xmalloc (BUFSIZE);
  size_t nread, tocopy;
  size_t ncopied = 0;
  size_t size;
  struct stat buf;

  if (bfd_stat_arch_elt (abfd, &buf) != 0)
    /* xgettext:c-format */
    fatal (_("internal stat error on %s"), bfd_get_filename (abfd));
  size = buf.st_size;

  if (verbose)
    printf ("x - %s\n", bfd_get_filename (abfd));

  bfd_seek (abfd, (file_ptr) 0, SEEK_SET);

  ostream = NULL;
  if (size == 0)
    {
      /* Seems like an abstraction violation, eh?  Well it's OK! */
      output_filename = bfd_get_filename (abfd);

      ostream = fopen (bfd_get_filename (abfd), FOPEN_WB);
      if (ostream == NULL)
       {
         perror (bfd_get_filename (abfd));
         xexit (1);
       }

      output_file = ostream;
    }
  else
    while (ncopied < size)
      {
       tocopy = size - ncopied;
       if (tocopy > BUFSIZE)
         tocopy = BUFSIZE;

       nread = bfd_bread (cbuf, (bfd_size_type) tocopy, abfd);
       if (nread != tocopy)
         /* xgettext:c-format */
         fatal (_("%s is not a valid archive"),
               bfd_get_filename (bfd_my_archive (abfd)));

       /* See comment above; this saves disk arm motion */
       if (ostream == NULL)
         {
           /* Seems like an abstraction violation, eh?  Well it's OK! */
           output_filename = bfd_get_filename (abfd);

           ostream = fopen (bfd_get_filename (abfd), FOPEN_WB);
           if (ostream == NULL)
             {
              perror (bfd_get_filename (abfd));
              xexit (1);
             }

           output_file = ostream;
         }

       /* fwrite in mingw32 may return int instead of size_t. Cast
          the return value to size_t to avoid comparison between
          signed and unsigned values.  */
       if ((size_t) fwrite (cbuf, 1, nread, ostream) != nread)
         fatal ("%s: %s", output_filename, strerror (errno));
       ncopied += tocopy;
      }

  if (ostream != NULL)
    fclose (ostream);

  output_file = NULL;
  output_filename = NULL;

  chmod (bfd_get_filename (abfd), buf.st_mode);

  if (preserve_dates)
    {
      /* Set access time to modification time.  Only st_mtime is
        initialized by bfd_stat_arch_elt.  */
      buf.st_atime = buf.st_mtime;
      set_times (bfd_get_filename (abfd), &buf);
    }

  free (cbuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void maybequit ( void  )

Definition at line 140 of file arsup.c.

{
  if (! interactive)
    xexit (9);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bfd* open_inarch ( const char *  archive_filename,
const char *   
)

Definition at line 679 of file ar.c.

{
  const char *target;
  bfd **last_one;
  bfd *next_one;
  struct stat sbuf;
  bfd *arch;
  char **matching;

  bfd_set_error (bfd_error_no_error);

  target = NULL;

  if (stat (archive_filename, &sbuf) != 0)
    {
#if !defined(__GO32__) || defined(__DJGPP__)

      /* FIXME: I don't understand why this fragment was ifndef'ed
        away for __GO32__; perhaps it was in the days of DJGPP v1.x.
        stat() works just fine in v2.x, so I think this should be
        removed.  For now, I enable it for DJGPP v2. -- EZ.  */

/* KLUDGE ALERT! Temporary fix until I figger why
   stat() is wrong ... think it's buried in GO32's IDT - Jax */
      if (errno != ENOENT)
       bfd_fatal (archive_filename);
#endif

      if (!operation_alters_arch)
       {
         fprintf (stderr, "%s: ", program_name);
         perror (archive_filename);
         maybequit ();
         return NULL;
       }

      /* Try to figure out the target to use for the archive from the
         first object on the list.  */
      if (file != NULL)
       {
         bfd *obj;

         obj = bfd_openr (file, NULL);
         if (obj != NULL)
           {
             if (bfd_check_format (obj, bfd_object))
              target = bfd_get_target (obj);
             (void) bfd_close (obj);
           }
       }

      /* Create an empty archive.  */
      arch = bfd_openw (archive_filename, target);
      if (arch == NULL
         || ! bfd_set_format (arch, bfd_archive)
         || ! bfd_close (arch))
       bfd_fatal (archive_filename);
      else if (!silent_create)
        non_fatal (_("creating %s"), archive_filename);

      /* If we die creating a new archive, don't leave it around.  */
      output_filename = archive_filename;
    }

  arch = bfd_openr (archive_filename, target);
  if (arch == NULL)
    {
    bloser:
      bfd_fatal (archive_filename);
    }

  if (! bfd_check_format_matches (arch, bfd_archive, &matching))
    {
      bfd_nonfatal (archive_filename);
      if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
       {
         list_matching_formats (matching);
         free (matching);
       }
      xexit (1);
    }

  last_one = &(arch->next);
  /* Read all the contents right away, regardless.  */
  for (next_one = bfd_openr_next_archived_file (arch, NULL);
       next_one;
       next_one = bfd_openr_next_archived_file (arch, next_one))
    {
      PROGRESS (1);
      *last_one = next_one;
      last_one = &next_one->next;
    }
  *last_one = (bfd *) NULL;
  if (bfd_get_error () != bfd_error_no_more_archived_files)
    goto bloser;
  return arch;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void prompt ( void  )

Definition at line 128 of file arsup.c.

{
  extern int interactive;

  if (interactive)
    {
      printf ("AR >");
      fflush (stdout);
    }
}

Here is the call graph for this function:

int yylex ( void  )
int yyparse ( void  )

Variable Documentation

Definition at line 135 of file ar.c.