VirtualBox

Changeset 900 in kBuild for vendor/gnumake/current/file.c


Ignore:
Timestamp:
May 23, 2007 3:13:11 AM (18 years ago)
Author:
bird
Message:

Load /home/bird/src/Gnu/make/2007-05-23 into vendor/gnumake/current.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current/file.c

    r501 r900  
    7070/* Access the hash table of all file records.
    7171   lookup_file  given a name, return the struct file * for that name,
    72            or nil if there is none.
    73    enter_file   similar, but create one if there is none.  */
     72                or nil if there is none.
     73*/
    7474
    7575struct file *
    76 lookup_file (char *name)
    77 {
    78   register struct file *f;
     76lookup_file (const char *name)
     77{
     78  struct file *f;
    7979  struct file file_key;
    8080#if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
    81   register char *lname, *ln;
     81  char *lname;
    8282#endif
    8383
     
    9191  if (*name != '.')
    9292    {
    93       register char *n;
    94       lname = (char *) malloc (strlen (name) + 1);
     93      const char *n;
     94      char *ln;
     95      lname = xstrdup (name);
    9596      for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
    9697        *ln = isupper ((unsigned char)*n) ? tolower ((unsigned char)*n) : *n;
     
    113114  if (*name == '\0')
    114115    /* It was all slashes after a dot.  */
    115 #ifdef VMS
     116#if defined(VMS)
    116117    name = "[]";
    117 #else
    118 #ifdef _AMIGA
     118#elif defined(_AMIGA)
    119119    name = "";
    120120#else
    121121    name = "./";
    122 #endif /* AMIGA */
    123 #endif /* VMS */
     122#endif
    124123
    125124  file_key.hname = name;
    126   f = (struct file *) hash_find_item (&files, &file_key);
     125  f = hash_find_item (&files, &file_key);
    127126#if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
    128127  if (*name != '.')
    129128    free (lname);
    130129#endif
     130
    131131  return f;
    132132}
    133133
     134/* Look up a file record for file NAME and return it.
     135   Create a new record if one doesn't exist.  NAME will be stored in the
     136   new record so it should be constant or in the strcache etc.
     137 */
     138
    134139struct file *
    135 enter_file (char *name)
    136 {
    137   register struct file *f;
    138   register struct file *new;
    139   register struct file **file_slot;
     140enter_file (const char *name)
     141{
     142  struct file *f;
     143  struct file *new;
     144  struct file **file_slot;
    140145  struct file file_key;
    141 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
    142   char *lname, *ln;
    143 #endif
    144146
    145147  assert (*name != '\0');
     148  assert (strcache_iscached (name));
    146149
    147150#if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
    148151  if (*name != '.')
    149152    {
    150       register char *n;
    151       lname = (char *) malloc (strlen (name) + 1);
     153      const char *n;
     154      char *lname, *ln;
     155      lname = xstrdup (name);
    152156      for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
    153         {
    154           if (isupper ((unsigned char)*n))
    155             *ln = tolower ((unsigned char)*n);
    156           else
    157             *ln = *n;
    158         }
    159 
    160       *ln = 0;
    161       /* Creates a possible leak, old value of name is unreachable, but I
    162          currently don't know how to fix it. */
    163       name = lname;
     157        if (isupper ((unsigned char)*n))
     158          *ln = tolower ((unsigned char)*n);
     159        else
     160          *ln = *n;
     161
     162      *ln = '\0';
     163      name = strcache_add (lname);
     164      free (lname);
    164165    }
    165166#endif
     
    169170  f = *file_slot;
    170171  if (! HASH_VACANT (f) && !f->double_colon)
    171     {
    172 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
    173       if (*name != '.')
    174         free (lname);
    175 #endif
    176       return f;
    177     }
    178 
    179   new = (struct file *) xmalloc (sizeof (struct file));
    180   bzero ((char *) new, sizeof (struct file));
     172    return f;
     173
     174  new = xmalloc (sizeof (struct file));
     175  memset (new, '\0', sizeof (struct file));
    181176  new->name = new->hname = name;
    182177  new->update_status = -1;
     
    199194
    200195
    201 /* Rename FILE to NAME.  This is not as simple as resetting
    202    the `name' member, since it must be put in a new hash bucket,
    203    and possibly merged with an existing file called NAME.  */
    204 
    205 void
    206 rename_file (struct file *from_file, char *to_hname)
    207 {
    208   rehash_file (from_file, to_hname);
    209   while (from_file)
    210     {
    211       from_file->name = from_file->hname;
    212       from_file = from_file->prev;
    213     }
    214 }
    215 
    216196/* Rehash FILE to NAME.  This is not as simple as resetting
    217197   the `hname' member, since it must be put in a new hash bucket,
     
    219199
    220200void
    221 rehash_file (struct file *from_file, char *to_hname)
     201rehash_file (struct file *from_file, const char *to_hname)
    222202{
    223203  struct file file_key;
     
    227207  struct file *f;
    228208
     209  /* If it's already that name, we're done.  */
    229210  file_key.hname = to_hname;
    230   if (0 == file_hash_cmp (from_file, &file_key))
     211  if (! file_hash_cmp (from_file, &file_key))
    231212    return;
    232213
     214  /* Find the end of the renamed list for the "from" file.  */
    233215  file_key.hname = from_file->hname;
    234216  while (from_file->renamed != 0)
    235217    from_file = from_file->renamed;
    236218  if (file_hash_cmp (from_file, &file_key))
    237     /* hname changed unexpectedly */
     219    /* hname changed unexpectedly!! */
    238220    abort ();
    239221
     222  /* Remove the "from" file from the hash.  */
    240223  deleted_file = hash_delete (&files, from_file);
    241224  if (deleted_file != from_file)
     
    243226    abort ();
    244227
     228  /* Find where the newly renamed file will go in the hash.  */
    245229  file_key.hname = to_hname;
    246230  file_slot = (struct file **) hash_find_slot (&files, &file_key);
    247231  to_file = *file_slot;
    248232
     233  /* Change the hash name for this file.  */
    249234  from_file->hname = to_hname;
    250235  for (f = from_file->double_colon; f != 0; f = f->prev)
    251236    f->hname = to_hname;
    252237
     238  /* If the new name doesn't exist yet just set it to the renamed file.  */
    253239  if (HASH_VACANT (to_file))
    254     hash_insert_at (&files, from_file, file_slot);
     240    {
     241      hash_insert_at (&files, from_file, file_slot);
     242      return;
     243    }
     244
     245  /* TO_FILE already exists under TO_HNAME.
     246     We must retain TO_FILE and merge FROM_FILE into it.  */
     247
     248  if (from_file->cmds != 0)
     249    {
     250      if (to_file->cmds == 0)
     251        to_file->cmds = from_file->cmds;
     252      else if (from_file->cmds != to_file->cmds)
     253        {
     254          /* We have two sets of commands.  We will go with the
     255             one given in the rule explicitly mentioning this name,
     256             but give a message to let the user know what's going on.  */
     257          if (to_file->cmds->fileinfo.filenm != 0)
     258            error (&from_file->cmds->fileinfo,
     259                   _("Commands were specified for file `%s' at %s:%lu,"),
     260                   from_file->name, to_file->cmds->fileinfo.filenm,
     261                   to_file->cmds->fileinfo.lineno);
     262          else
     263            error (&from_file->cmds->fileinfo,
     264                   _("Commands for file `%s' were found by implicit rule search,"),
     265                   from_file->name);
     266          error (&from_file->cmds->fileinfo,
     267                 _("but `%s' is now considered the same file as `%s'."),
     268                 from_file->name, to_hname);
     269          error (&from_file->cmds->fileinfo,
     270                 _("Commands for `%s' will be ignored in favor of those for `%s'."),
     271                 to_hname, from_file->name);
     272        }
     273    }
     274
     275  /* Merge the dependencies of the two files.  */
     276
     277  if (to_file->deps == 0)
     278    to_file->deps = from_file->deps;
    255279  else
    256280    {
    257       /* TO_FILE already exists under TO_HNAME.
    258          We must retain TO_FILE and merge FROM_FILE into it.  */
    259 
    260       if (from_file->cmds != 0)
    261         {
    262           if (to_file->cmds == 0)
    263             to_file->cmds = from_file->cmds;
    264           else if (from_file->cmds != to_file->cmds)
    265             {
    266               /* We have two sets of commands.  We will go with the
    267                  one given in the rule explicitly mentioning this name,
    268                  but give a message to let the user know what's going on.  */
    269               if (to_file->cmds->fileinfo.filenm != 0)
    270                 error (&from_file->cmds->fileinfo,
    271                        _("Commands were specified for file `%s' at %s:%lu,"),
    272                        from_file->name, to_file->cmds->fileinfo.filenm,
    273                        to_file->cmds->fileinfo.lineno);
    274               else
    275                 error (&from_file->cmds->fileinfo,
    276                        _("Commands for file `%s' were found by implicit rule search,"),
    277                        from_file->name);
    278               error (&from_file->cmds->fileinfo,
    279                      _("but `%s' is now considered the same file as `%s'."),
    280                      from_file->name, to_hname);
    281               error (&from_file->cmds->fileinfo,
    282                      _("Commands for `%s' will be ignored in favor of those for `%s'."),
    283                      to_hname, from_file->name);
    284             }
    285         }
    286 
    287       /* Merge the dependencies of the two files.  */
    288 
    289       if (to_file->deps == 0)
    290         to_file->deps = from_file->deps;
     281      struct dep *deps = to_file->deps;
     282      while (deps->next != 0)
     283        deps = deps->next;
     284      deps->next = from_file->deps;
     285    }
     286
     287  merge_variable_set_lists (&to_file->variables, from_file->variables);
     288
     289  if (to_file->double_colon && from_file->is_target && !from_file->double_colon)
     290    fatal (NILF, _("can't rename single-colon `%s' to double-colon `%s'"),
     291           from_file->name, to_hname);
     292  if (!to_file->double_colon  && from_file->double_colon)
     293    {
     294      if (to_file->is_target)
     295        fatal (NILF, _("can't rename double-colon `%s' to single-colon `%s'"),
     296               from_file->name, to_hname);
    291297      else
    292         {
    293           register struct dep *deps = to_file->deps;
    294           while (deps->next != 0)
    295             deps = deps->next;
    296           deps->next = from_file->deps;
    297         }
    298 
    299       merge_variable_set_lists (&to_file->variables, from_file->variables);
    300 
    301       if (to_file->double_colon && from_file->is_target && !from_file->double_colon)
    302         fatal (NILF, _("can't rename single-colon `%s' to double-colon `%s'"),
    303                from_file->name, to_hname);
    304       if (!to_file->double_colon  && from_file->double_colon)
    305         {
    306           if (to_file->is_target)
    307             fatal (NILF, _("can't rename double-colon `%s' to single-colon `%s'"),
    308                    from_file->name, to_hname);
    309           else
    310             to_file->double_colon = from_file->double_colon;
    311         }
    312 
    313       if (from_file->last_mtime > to_file->last_mtime)
    314         /* %%% Kludge so -W wins on a file that gets vpathized.  */
    315         to_file->last_mtime = from_file->last_mtime;
    316 
    317       to_file->mtime_before_update = from_file->mtime_before_update;
     298        to_file->double_colon = from_file->double_colon;
     299    }
     300
     301  if (from_file->last_mtime > to_file->last_mtime)
     302    /* %%% Kludge so -W wins on a file that gets vpathized.  */
     303    to_file->last_mtime = from_file->last_mtime;
     304
     305  to_file->mtime_before_update = from_file->mtime_before_update;
    318306
    319307#define MERGE(field) to_file->field |= from_file->field
    320       MERGE (precious);
    321       MERGE (tried_implicit);
    322       MERGE (updating);
    323       MERGE (updated);
    324       MERGE (is_target);
    325       MERGE (cmd_target);
    326       MERGE (phony);
    327       MERGE (ignore_vpath);
     308  MERGE (precious);
     309  MERGE (tried_implicit);
     310  MERGE (updating);
     311  MERGE (updated);
     312  MERGE (is_target);
     313  MERGE (cmd_target);
     314  MERGE (phony);
     315  MERGE (ignore_vpath);
    328316#undef MERGE
    329317
    330       from_file->renamed = to_file;
     318  from_file->renamed = to_file;
     319}
     320
     321/* Rename FILE to NAME.  This is not as simple as resetting
     322   the `name' member, since it must be put in a new hash bucket,
     323   and possibly merged with an existing file called NAME.  */
     324
     325void
     326rename_file (struct file *from_file, const char *to_hname)
     327{
     328  rehash_file (from_file, to_hname);
     329  while (from_file)
     330    {
     331      from_file->name = from_file->hname;
     332      from_file = from_file->prev;
    331333    }
    332334}
     
    341343remove_intermediates (int sig)
    342344{
    343   register struct file **file_slot;
    344   register struct file **file_end;
     345  struct file **file_slot;
     346  struct file **file_end;
    345347  int doneany = 0;
    346348
     
    357359    if (! HASH_VACANT (*file_slot))
    358360      {
    359         register struct file *f = *file_slot;
     361        struct file *f = *file_slot;
    360362        /* Is this file eligible for automatic deletion?
    361363           Yes, IFF: it's marked intermediate, it's not secondary, it wasn't
     
    448450}
    449451
    450 
    451452/* Set the intermediate flag.  */
    452453
     
    464465  struct dep *d;
    465466  struct dep *old = f->deps;
    466   char *file_stem = f->stem;
     467  const char *file_stem = f->stem;
    467468  unsigned int last_dep_has_cmds = f->updating;
    468469  int initialized = 0;
     
    480481
    481482      /* Create the dependency list.
    482          If we're not doing 2nd expansion, then it's just the name.  */
     483         If we're not doing 2nd expansion, then it's just the name.  We will
     484         still need to massage it though.  */
    483485      if (! d->need_2nd_expansion)
    484         p = d->name;
     486        {
     487          p = variable_expand ("");
     488          variable_buffer_output (p, d->name, strlen (d->name) + 1);
     489        }
    485490      else
    486491        {
     
    494499              o = subst_expand (buffer, d->name, "%", "$*", 1, 2, 0);
    495500
    496               free (d->name);
    497               d->name = savestring (buffer, o - buffer);
     501              d->name = strcache_add_len (buffer, o - buffer);
    498502              d->staticpattern = 0; /* Clear staticpattern so that we don't
    499503                                       re-expand %s below. */
     
    529533      if (new && d->staticpattern)
    530534        {
    531           char *pattern = "%";
     535          const char *pattern = "%";
    532536          char *buffer = variable_expand ("");
    533537          struct dep *dp = new, *dl = 0;
     
    535539          while (dp != 0)
    536540            {
    537               char *percent = find_percent (dp->name);
     541              char *percent;
     542              int nl = strlen (dp->name) + 1;
     543              char *nm = alloca (nl);
     544              memcpy (nm, dp->name, nl);
     545              percent = find_percent (nm);
    538546              if (percent)
    539547                {
     548                  char *o;
     549
    540550                  /* We have to handle empty stems specially, because that
    541551                     would be equivalent to $(patsubst %,dp->name,) which
    542552                     will always be empty.  */
    543553                  if (d->stem[0] == '\0')
    544                     /* This needs memmove() in ISO C.  */
    545                     bcopy (percent+1, percent, strlen (percent));
     554                    {
     555                      memmove (percent, percent+1, strlen (percent));
     556                      o = variable_buffer_output (buffer, nm, strlen (nm) + 1);
     557                    }
    546558                  else
    547                     {
    548                       char *o = patsubst_expand (buffer, d->stem, pattern,
    549                                                  dp->name, pattern+1,
    550                                                  percent+1);
    551                       if (o == buffer)
    552                         dp->name[0] = '\0';
    553                       else
    554                         {
    555                           free (dp->name);
    556                           dp->name = savestring (buffer, o - buffer);
    557                         }
    558                     }
     559                    o = patsubst_expand_pat (buffer, d->stem, pattern, nm,
     560                                             pattern+1, percent+1);
    559561
    560562                  /* If the name expanded to the empty string, ignore it.  */
    561                   if (dp->name[0] == '\0')
     563                  if (buffer[0] == '\0')
    562564                    {
    563565                      struct dep *df = dp;
     
    566568                      else
    567569                        dp = dl->next = dp->next;
    568                       /* @@ Are we leaking df->name here?  */
    569                       df->name = 0;
    570570                      free_dep (df);
    571571                      continue;
    572572                    }
     573
     574                  /* Save the name.  */
     575                  dp->name = strcache_add_len (buffer, o - buffer);
    573576                }
    574577              dl = dp;
     
    583586          if (d1->file == 0)
    584587            d1->file = enter_file (d1->name);
    585           else
    586             free (d1->name);
    587588          d1->name = 0;
    588589          d1->staticpattern = 0;
     
    639640  struct file **file_end;
    640641
    641   /* Perform second expansion and enter each dependency
    642      name as a file. */
    643 
    644   /* Expand .SUFFIXES first; it's dependencies are used for
    645      $$* calculation. */
     642  /* Perform second expansion and enter each dependency name as a file. */
     643
     644  /* Expand .SUFFIXES first; it's dependencies are used for $$* calculation. */
    646645  for (f = lookup_file (".SUFFIXES"); f != 0; f = f->prev)
    647646    expand_deps (f);
    648647
    649   /* We must use hash_dump (), because within this loop
    650      we might add new files to the table, possibly causing
    651      an in-situ table expansion.  */
     648  /* For every target that's not .SUFFIXES, expand its dependencies.
     649     We must use hash_dump (), because within this loop we might add new files
     650     to the table, possibly causing an in-situ table expansion.  */
    652651  file_slot_0 = (struct file **) hash_dump (&files, 0, 0);
    653652  file_end = file_slot_0 + files.ht_fill;
    654653  for (file_slot = file_slot_0; file_slot < file_end; file_slot++)
    655654    for (f = *file_slot; f != 0; f = f->prev)
    656       {
    657         if (strcmp (f->name, ".SUFFIXES") != 0)
    658           expand_deps (f);
    659       }
     655      if (strcmp (f->name, ".SUFFIXES") != 0)
     656        expand_deps (f);
    660657  free (file_slot_0);
     658
     659  /* Now manage all the special targets.  */
    661660
    662661  for (f = lookup_file (".PRECIOUS"); f != 0; f = f->prev)
     
    682681
    683682  for (f = lookup_file (".INTERMEDIATE"); f != 0; f = f->prev)
    684     {
    685       /* .INTERMEDIATE with deps listed
    686          marks those deps as intermediate files.  */
     683    /* Mark .INTERMEDIATE deps as intermediate files.  */
     684    for (d = f->deps; d != 0; d = d->next)
     685      for (f2 = d->file; f2 != 0; f2 = f2->prev)
     686        f2->intermediate = 1;
     687    /* .INTERMEDIATE with no deps does nothing.
     688       Marking all files as intermediates is useless since the goal targets
     689       would be deleted after they are built.  */
     690
     691  for (f = lookup_file (".SECONDARY"); f != 0; f = f->prev)
     692    /* Mark .SECONDARY deps as both intermediate and secondary.  */
     693    if (f->deps)
    687694      for (d = f->deps; d != 0; d = d->next)
    688         for (f2 = d->file; f2 != 0; f2 = f2->prev)
    689           f2->intermediate = 1;
    690       /* .INTERMEDIATE with no deps does nothing.
    691          Marking all files as intermediates is useless
    692          since the goal targets would be deleted after they are built.  */
    693     }
    694 
    695   for (f = lookup_file (".SECONDARY"); f != 0; f = f->prev)
    696     {
    697       /* .SECONDARY with deps listed
    698          marks those deps as intermediate files
    699          in that they don't get rebuilt if not actually needed;
    700          but unlike real intermediate files,
    701          these are not deleted after make finishes.  */
    702       if (f->deps)
    703         for (d = f->deps; d != 0; d = d->next)
    704           for (f2 = d->file; f2 != 0; f2 = f2->prev)
    705             f2->intermediate = f2->secondary = 1;
    706       /* .SECONDARY with no deps listed marks *all* files that way.  */
    707       else
    708         {
    709           all_secondary = 1;
    710           hash_map (&files, set_intermediate);
    711         }
    712     }
     695        for (f2 = d->file; f2 != 0; f2 = f2->prev)
     696          f2->intermediate = f2->secondary = 1;
     697    /* .SECONDARY with no deps listed marks *all* files that way.  */
     698    else
     699      {
     700        all_secondary = 1;
     701        hash_map (&files, set_intermediate);
     702      }
    713703
    714704  f = lookup_file (".EXPORT_ALL_VARIABLES");
     
    860850  p += strlen (p);
    861851
    862   /* Append nanoseconds as a fraction, but remove trailing zeros.
    863      We don't know the actual timestamp resolution, since clock_getres
    864      applies only to local times, whereas this timestamp might come
    865      from a remote filesystem.  So removing trailing zeros is the
    866      best guess that we can do.  */
     852  /* Append nanoseconds as a fraction, but remove trailing zeros.  We don't
     853     know the actual timestamp resolution, since clock_getres applies only to
     854     local times, whereas this timestamp might come from a remote filesystem.
     855     So removing trailing zeros is the best guess that we can do.  */
    867856  sprintf (p, ".%09d", FILE_TIMESTAMP_NS (ts));
    868857  p += strlen (p) - 1;
     
    880869print_file (const void *item)
    881870{
    882   struct file *f = (struct file *) item;
     871  const struct file *f = item;
    883872  struct dep *d;
    884873  struct dep *ood = 0;
     
    1002991}
    1003992
     993
     994/* Verify the integrity of the data base of files.  */
     995
     996#define VERIFY_CACHED(_p,_n) \
     997    do{\
     998        if (_p->_n && _p->_n[0] && !strcache_iscached (_p->_n)) \
     999          printf ("%s: Field %s not cached: %s\n", _p->name, # _n, _p->_n); \
     1000    }while(0)
     1001
     1002static void
     1003verify_file (const void *item)
     1004{
     1005  const struct file *f = item;
     1006  const struct dep *d;
     1007
     1008  VERIFY_CACHED (f, name);
     1009  VERIFY_CACHED (f, hname);
     1010  VERIFY_CACHED (f, vpath);
     1011  VERIFY_CACHED (f, stem);
     1012
     1013  /* Check the deps.  */
     1014  for (d = f->deps; d != 0; d = d->next)
     1015    {
     1016      VERIFY_CACHED (d, name);
     1017      VERIFY_CACHED (d, stem);
     1018    }
     1019}
     1020
     1021void
     1022verify_file_data_base (void)
     1023{
     1024  hash_map (&files, verify_file);
     1025}
     1026
    10041027#define EXPANSION_INCREMENT(_l)  ((((_l) / 500) + 1) * 500)
    10051028
     
    10381061              }
    10391062
    1040             bcopy (f->name, p, l);
     1063            memcpy (p, f->name, l);
    10411064            p += l;
    10421065            *(p++) = ' ';
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