VirtualBox

Changeset 903 in kBuild for trunk/src/gmakenew/ar.c


Ignore:
Timestamp:
May 23, 2007 5:31:19 AM (18 years ago)
Author:
bird
Message:

Merged with the 2007-05-23 CVS. Added rsort and fixed a couple of windows build issues.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmakenew/ar.c

    r503 r903  
    2525#include <fnmatch.h>
    2626
    27 /* Defined in arscan.c.  */
    28 extern long int ar_scan PARAMS ((char *archive, long int (*function) (), long int arg));
    29 extern int ar_name_equal PARAMS ((char *name, char *mem, int truncated));
    30 #ifndef VMS
    31 extern int ar_member_touch PARAMS ((char *arname, char *memname));
    32 #endif
    33 
    3427/* Return nonzero if NAME is an archive-member reference, zero if not.
    3528   An archive-member reference is a name like `lib(member)'.
     
    3831
    3932int
    40 ar_name (char *name)
    41 {
    42   char *p = strchr (name, '(');
    43   char *end;
     33ar_name (const char *name)
     34{
     35  const char *p = strchr (name, '(');
     36  const char *end;
    4437
    4538  if (p == 0 || p == name)
     
    5851
    5952/* Parse the archive-member reference NAME into the archive and member names.
    60    Put the malloc'd archive name in *ARNAME_P if ARNAME_P is non-nil;
    61    put the malloc'd member name in *MEMNAME_P if MEMNAME_P is non-nil.  */
     53   Creates one allocated string containing both names, pointed to by ARNAME_P.
     54   MEMNAME_P points to the member.  */
    6255
    6356void
    64 ar_parse_name (char *name, char **arname_p, char **memname_p)
    65 {
    66   char *p = strchr (name, '('), *end = name + strlen (name) - 1;
    67 
    68   if (arname_p != 0)
    69     *arname_p = savestring (name, p - name);
    70 
    71   if (memname_p != 0)
    72     *memname_p = savestring (p + 1, end - (p + 1));
    73 }
    74 
    75 
    76 static long int ar_member_date_1 PARAMS ((int desc, char *mem, int truncated, long int hdrpos,
    77         long int datapos, long int size, long int date, int uid, int gid, int mode, char *name));
     57ar_parse_name (const char *name, char **arname_p, char **memname_p)
     58{
     59  char *p;
     60
     61  *arname_p = xstrdup (name);
     62  p = strchr (*arname_p, '(');
     63  *(p++) = '\0';
     64  p[strlen(p) - 1] = '\0';
     65  *memname_p = p;
     66}
     67
     68
     69
     70/* This function is called by `ar_scan' to find which member to look at.  */
     71
     72/* ARGSUSED */
     73static long int
     74ar_member_date_1 (int desc UNUSED, const char *mem, int truncated,
     75                  long int hdrpos UNUSED, long int datapos UNUSED,
     76                  long int size UNUSED, long int date,
     77                  int uid UNUSED, int gid UNUSED, int mode UNUSED,
     78                  const void *name)
     79{
     80  return ar_name_equal (name, mem, truncated) ? date : 0;
     81}
    7882
    7983/* Return the modtime of NAME.  */
    8084
    8185time_t
    82 ar_member_date (char *name)
     86ar_member_date (const char *name)
    8387{
    8488  char *arname;
    85   int arname_used = 0;
    8689  char *memname;
    8790  long int val;
     
    100103    arfile = lookup_file (arname);
    101104    if (arfile == 0 && file_exists_p (arname))
    102       {
    103         arfile = enter_file (arname);
    104         arname_used = 1;
    105       }
     105      arfile = enter_file (strcache_add (arname));
    106106
    107107    if (arfile != 0)
     
    109109  }
    110110
    111   val = ar_scan (arname, ar_member_date_1, (long int) memname);
    112 
    113   if (!arname_used)
    114     free (arname);
    115   free (memname);
     111  val = ar_scan (arname, ar_member_date_1, memname);
     112
     113  free (arname);
    116114
    117115  return (val <= 0 ? (time_t) -1 : (time_t) val);
    118 }
    119 
    120 /* This function is called by `ar_scan' to find which member to look at.  */
    121 
    122 /* ARGSUSED */
    123 static long int
    124 ar_member_date_1 (int desc UNUSED, char *mem, int truncated,
    125                   long int hdrpos UNUSED, long int datapos UNUSED,
    126                   long int size UNUSED, long int date,
    127                   int uid UNUSED, int gid UNUSED, int mode UNUSED, char *name)
    128 {
    129   return ar_name_equal (name, mem, truncated) ? date : 0;
    130116}
    131117
     
    135121#ifdef VMS
    136122int
    137 ar_touch (char *name)
     123ar_touch (const char *name)
    138124{
    139125  error (NILF, _("touch archive member is not available on VMS"));
     
    142128#else
    143129int
    144 ar_touch (char *name)
     130ar_touch (const char *name)
    145131{
    146132  char *arname, *memname;
    147   int arname_used = 0;
    148   register int val;
     133  int val;
    149134
    150135  ar_parse_name (name, &arname, &memname);
    151136
    152137  /* Make sure we know the modtime of the archive itself before we
    153      touch the member, since this will change the archive itself.  */
     138     touch the member, since this will change the archive modtime.  */
    154139  {
    155140    struct file *arfile;
    156     arfile = lookup_file (arname);
    157     if (arfile == 0)
    158       {
    159         arfile = enter_file (arname);
    160         arname_used = 1;
    161       }
    162 
    163     (void) f_mtime (arfile, 0);
     141    arfile = enter_file (strcache_add (arname));
     142    f_mtime (arfile, 0);
    164143  }
    165144
     
    188167    }
    189168
    190   if (!arname_used)
    191     free (arname);
    192   free (memname);
     169  free (arname);
    193170
    194171  return val;
     
    201178struct ar_glob_state
    202179  {
    203     char *arname;
    204     char *pattern;
     180    const char *arname;
     181    const char *pattern;
    205182    unsigned int size;
    206183    struct nameseq *chain;
     
    212189
    213190static long int
    214 ar_glob_match (int desc UNUSED, char *mem, int truncated UNUSED,
     191ar_glob_match (int desc UNUSED, const char *mem, int truncated UNUSED,
    215192               long int hdrpos UNUSED, long int datapos UNUSED,
    216193               long int size UNUSED, long int date UNUSED, int uid UNUSED,
    217                int gid UNUSED, int mode UNUSED, struct ar_glob_state *state)
    218 {
     194               int gid UNUSED, int mode UNUSED, const void *arg)
     195{
     196  struct ar_glob_state *state = (struct ar_glob_state *)arg;
     197
    219198  if (fnmatch (state->pattern, mem, FNM_PATHNAME|FNM_PERIOD) == 0)
    220199    {
    221200      /* We have a match.  Add it to the chain.  */
    222       struct nameseq *new = (struct nameseq *) xmalloc (state->size);
    223       new->name = concat (state->arname, mem, ")");
     201      struct nameseq *new = xmalloc (state->size);
     202      new->name = strcache_add (concat (state->arname, mem, ")"));
    224203      new->next = state->chain;
    225204      state->chain = new;
     
    267246
    268247struct nameseq *
    269 ar_glob (char *arname, char *member_pattern, unsigned int size)
     248ar_glob (const char *arname, const char *member_pattern, unsigned int size)
    270249{
    271250  struct ar_glob_state state;
    272   char **names;
    273251  struct nameseq *n;
     252  const char **names;
     253  char *name;
    274254  unsigned int i;
    275255
     
    280260     ar_glob_match will accumulate them in STATE.chain.  */
    281261  i = strlen (arname);
    282   state.arname = (char *) alloca (i + 2);
    283   bcopy (arname, state.arname, i);
    284   state.arname[i] = '(';
    285   state.arname[i + 1] = '\0';
     262  name = alloca (i + 2);
     263  memcpy (name, arname, i);
     264  name[i] = '(';
     265  name[i + 1] = '\0';
     266  state.arname = name;
    286267  state.pattern = member_pattern;
    287268  state.size = size;
    288269  state.chain = 0;
    289270  state.n = 0;
    290   (void) ar_scan (arname, ar_glob_match, (long int) &state);
     271  ar_scan (arname, ar_glob_match, &state);
    291272
    292273  if (state.chain == 0)
     
    294275
    295276  /* Now put the names into a vector for sorting.  */
    296   names = (char **) alloca (state.n * sizeof (char *));
     277  names = alloca (state.n * sizeof (const char *));
    297278  i = 0;
    298279  for (n = state.chain; n != 0; n = n->next)
     
    300281
    301282  /* Sort them alphabetically.  */
    302   qsort ((char *) names, i, sizeof (*names), alpha_compare);
     283  qsort (names, i, sizeof (*names), alpha_compare);
    303284
    304285  /* Put them back into the chain in the sorted order.  */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette