Ignore:
Timestamp:
May 23, 2007, 5: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/read.c

    r501 r900  
    3838#include <pwd.h>
    3939#else
    40 struct passwd *getpwnam PARAMS ((char *name));
     40struct passwd *getpwnam (char *name);
    4141#endif
    4242#endif
     
    8989/* Default directories to search for include files in  */
    9090
    91 static char *default_include_directories[] =
     91static const char *default_include_directories[] =
    9292  {
    9393#if defined(WINDOWS32) && !defined(INCLUDEDIR)
    94 /*
    95  * This completely up to the user when they install MSVC or other packages.
    96  * This is defined as a placeholder.
    97  */
    98 #define INCLUDEDIR "."
     94/* This completely up to the user when they install MSVC or other packages.
     95   This is defined as a placeholder.  */
     96# define INCLUDEDIR "."
    9997#endif
    10098    INCLUDEDIR,
     
    109107/* List of directories to search for include files in  */
    110108
    111 static char **include_directories;
     109static const char **include_directories;
    112110
    113111/* Maximum length of an element of the above.  */
     
    124122static struct dep *read_makefiles = 0;
    125123
    126 static int eval_makefile PARAMS ((char *filename, int flags));
    127 static int eval PARAMS ((struct ebuffer *buffer, int flags));
    128 
    129 static long readline PARAMS ((struct ebuffer *ebuf));
    130 static void do_define PARAMS ((char *name, unsigned int namelen,
    131                                enum variable_origin origin,
    132                                struct ebuffer *ebuf));
    133 static int conditional_line PARAMS ((char *line, int len, const struct floc *flocp));
    134 static void record_files PARAMS ((struct nameseq *filenames, char *pattern, char *pattern_percent,
    135                         struct dep *deps, unsigned int cmds_started, char *commands,
    136                         unsigned int commands_idx, int two_colon,
    137                         const struct floc *flocp));
    138 static void record_target_var PARAMS ((struct nameseq *filenames, char *defn,
    139                                        enum variable_origin origin,
    140                                        int enabled,
    141                                        const struct floc *flocp));
    142 static enum make_word_type get_next_mword PARAMS ((char *buffer, char *delim,
    143                         char **startp, unsigned int *length));
    144 static void remove_comments PARAMS ((char *line));
    145 static char *find_char_unquote PARAMS ((char *string, int stop1,
    146                                         int stop2, int blank, int ignorevars));
     124static int eval_makefile (const char *filename, int flags);
     125static int eval (struct ebuffer *buffer, int flags);
     126
     127static long readline (struct ebuffer *ebuf);
     128static void do_define (char *name, unsigned int namelen,
     129                       enum variable_origin origin, struct ebuffer *ebuf);
     130static int conditional_line (char *line, int len, const struct floc *flocp);
     131static void record_files (struct nameseq *filenames, const char *pattern,
     132                          const char *pattern_percent, struct dep *deps,
     133                          unsigned int cmds_started, char *commands,
     134                          unsigned int commands_idx, int two_colon,
     135                          const struct floc *flocp);
     136static void record_target_var (struct nameseq *filenames, char *defn,
     137                               enum variable_origin origin, int enabled,
     138                               const struct floc *flocp);
     139static enum make_word_type get_next_mword (char *buffer, char *delim,
     140                                           char **startp, unsigned int *length);
     141static void remove_comments (char *line);
     142static char *find_char_unquote (char *string, int stop1, int stop2,
     143                                int blank, int ignorevars);
    147144
    148145
     
    150147
    151148struct dep *
    152 read_all_makefiles (char **makefiles)
     149read_all_makefiles (const char **makefiles)
    153150{
    154151  unsigned int num_makefiles = 0;
     
    184181    p = value;
    185182
    186     while ((name = find_next_token (&p, &length)) != 0)
     183    while ((name = find_next_token ((const char **)&p, &length)) != 0)
    187184      {
    188185        if (*p != '\0')
     
    251248            {
    252249              struct dep *d = alloc_dep ();
    253               d->file = enter_file (*p);
     250              d->file = enter_file (strcache_add (*p));
    254251              d->file->dontcare = 1;
    255252              /* Tell update_goal_chain to bail out as soon as this file is
     
    278275  struct conditionals *save = conditionals;
    279276
    280   bzero ((char *) new, sizeof (*new));
     277  memset (new, '\0', sizeof (*new));
    281278  conditionals = new;
    282279
     
    301298
    302299static int
    303 eval_makefile (char *filename, int flags)
     300eval_makefile (const char *filename, int flags)
    304301{
    305302  struct dep *deps;
     
    307304  const struct floc *curfile;
    308305  char *expanded = 0;
    309   char *included = 0;
    310306  int makefile_errno;
    311307  int r;
    312308
    313   ebuf.floc.filenm = strcache_add (filename);
     309  filename = strcache_add (filename);
     310  ebuf.floc.filenm = filename;
    314311  ebuf.floc.lineno = 1;
    315312
     
    348345  if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/')
    349346    {
    350       register unsigned int i;
     347      unsigned int i;
    351348      for (i = 0; include_directories[i] != 0; ++i)
    352349        {
    353           included = concat (include_directories[i], "/", filename);
     350          const char *included = concat (include_directories[i], "/", filename);
    354351          ebuf.fp = fopen (included, "r");
    355352          if (ebuf.fp)
    356353            {
    357               filename = included;
     354              filename = strcache_add (included);
    358355              break;
    359356            }
    360           free (included);
    361         }
    362       /* If we're not using it, we already freed it above.  */
    363       if (filename != included)
    364         included = 0;
     357        }
    365358    }
    366359
     
    371364  deps->file = lookup_file (filename);
    372365  if (deps->file == 0)
    373     deps->file = enter_file (xstrdup (filename));
     366    deps->file = enter_file (filename);
    374367  filename = deps->file->name;
    375368  deps->changed = flags;
     
    379372  if (expanded)
    380373    free (expanded);
    381   if (included)
    382     free (included);
    383374
    384375  /* If the makefile can't be found at all, give up entirely.  */
     
    470461  long nlines = 0;
    471462  int two_colon = 0;
    472   char *pattern = 0, *pattern_percent;
     463  const char *pattern = 0;
     464  const char *pattern_percent;
    473465  struct floc *fstart;
    474466  struct floc fi;
     
    487479      commands_idx = 0;                                                       \
    488480      no_targets = 0;                                                         \
    489       if (pattern) { free(pattern); pattern = 0; }                            \
     481      pattern = 0;                                                            \
    490482    } while (0)
    491483
     
    512504      unsigned int linelen;
    513505      char *line;
    514       int len;
     506      unsigned int wlen;
    515507      char *p;
    516508      char *p2;
     
    533525      /* Check for a shell command line first.
    534526         If it is not one, we can stop treating tab specially.  */
    535       if (line[0] == '\t')
     527      if (line[0] == cmd_prefix)
    536528        {
    537529          if (no_targets)
     
    558550                  commands = xrealloc (commands, commands_len);
    559551                }
    560               bcopy (line, &commands[commands_idx], linelen);
     552              memcpy (&commands[commands_idx], line, linelen);
    561553              commands_idx += linelen;
    562554              commands[commands_idx++] = '\n';
     
    574566          collapsed_length = linelen+1;
    575567          if (collapsed)
    576             free ((char *)collapsed);
    577           collapsed = (char *) xmalloc (collapsed_length);
     568            free (collapsed);
     569          collapsed = xmalloc (collapsed_length);
    578570        }
    579571      strcpy (collapsed, line);
     
    583575
    584576      /* Compare a word, both length and contents. */
    585 #define word1eq(s)      (len == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
     577#define word1eq(s)      (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
    586578      p = collapsed;
    587579      while (isspace ((unsigned char)*p))
     
    598590      for (p2 = p+1; *p2 != '\0' && !isspace ((unsigned char)*p2); ++p2)
    599591        ;
    600       len = p2 - p;
     592      wlen = p2 - p;
    601593
    602594      /* Find the start of the second token.  If it looks like a target or
     
    621613      if (!in_ignored_define)
    622614        {
    623           int i = conditional_line (p, len, fstart);
     615          int i = conditional_line (p, wlen, fstart);
    624616          if (i != -2)
    625617            {
     
    713705              else
    714706                {
    715                   unsigned int len;
     707                  unsigned int l;
     708                  const char *cp;
    716709                  char *ap;
    717710
    718711                  /* Expand the line so we can use indirect and constructed
    719712                     variable names in an export command.  */
    720                   p2 = ap = allocated_variable_expand (p2);
    721 
    722                   for (p = find_next_token (&p2, &len); p != 0;
    723                        p = find_next_token (&p2, &len))
     713                  cp = ap = allocated_variable_expand (p2);
     714
     715                  for (p = find_next_token (&cp, &l); p != 0;
     716                       p = find_next_token (&cp, &l))
    724717                    {
    725                       v = lookup_variable (p, len);
     718                      v = lookup_variable (p, l);
    726719                      if (v == 0)
    727                         v = define_variable_loc (p, len, "", o_file, 0,
    728                                                  fstart);
     720                        v = define_variable_loc (p, l, "", o_file, 0, fstart);
    729721                      v->export = v_export;
    730722                    }
     
    742734          else
    743735            {
    744               unsigned int len;
     736              unsigned int l;
    745737              struct variable *v;
     738              const char *cp;
    746739              char *ap;
    747740
    748741              /* Expand the line so we can use indirect and constructed
    749742                 variable names in an unexport command.  */
    750               p2 = ap = allocated_variable_expand (p2);
    751 
    752               for (p = find_next_token (&p2, &len); p != 0;
    753                    p = find_next_token (&p2, &len))
     743              cp = ap = allocated_variable_expand (p2);
     744
     745              for (p = find_next_token (&cp, &l); p != 0;
     746                   p = find_next_token (&cp, &l))
    754747                {
    755                   v = lookup_variable (p, len);
     748                  v = lookup_variable (p, l);
    756749                  if (v == 0)
    757                     v = define_variable_loc (p, len, "", o_file, 0, fstart);
     750                    v = define_variable_loc (p, l, "", o_file, 0, fstart);
    758751
    759752                  v->export = v_noexport;
     
    768761      if (word1eq ("vpath"))
    769762        {
    770           char *pattern;
    771           unsigned int len;
    772           p2 = variable_expand (p2);
    773           p = find_next_token (&p2, &len);
     763          const char *cp;
     764          char *vpat;
     765          unsigned int l;
     766          cp = variable_expand (p2);
     767          p = find_next_token (&cp, &l);
    774768          if (p != 0)
    775769            {
    776               pattern = savestring (p, len);
    777               p = find_next_token (&p2, &len);
     770              vpat = savestring (p, l);
     771              p = find_next_token (&cp, &l);
    778772              /* No searchpath means remove all previous
    779773                 selective VPATH's with the same pattern.  */
     
    781775          else
    782776            /* No pattern means remove all previous selective VPATH's.  */
    783             pattern = 0;
    784           construct_vpath_list (pattern, p);
    785           if (pattern != 0)
    786             free (pattern);
     777            vpat = 0;
     778          construct_vpath_list (vpat, p);
     779          if (vpat != 0)
     780            free (vpat);
    787781
    788782          goto rule_complete;
     
    829823            {
    830824              struct nameseq *next = files->next;
    831               char *name = files->name;
     825              const char *name = files->name;
    832826              int r;
    833827
    834               free ((char *)files);
     828              free (files);
    835829              files = next;
    836830
     
    839833              if (!r && !noerror)
    840834                error (fstart, "%s: %s", name, strerror (errno));
    841               free (name);
    842835            }
    843836
     
    855848         was no preceding target, and the line might have been usable as a
    856849         variable definition.  But now we know it is definitely lossage.  */
    857       if (line[0] == '\t')
     850      if (line[0] == cmd_prefix)
    858851        fatal(fstart, _("commands commence before first target"));
    859852
     
    873866        int exported;
    874867        char *cmdleft, *semip, *lb_next;
    875         unsigned int len, plen = 0;
     868        unsigned int plen = 0;
    876869        char *colonp;
    877870        const char *end, *beg; /* Helpers for whitespace stripping. */
     
    902895           beginning, expanding as we go, and looking for "interesting"
    903896           chars.  The first word is always expandable.  */
    904         wtype = get_next_mword(line, NULL, &lb_next, &len);
     897        wtype = get_next_mword(line, NULL, &lb_next, &wlen);
    905898        switch (wtype)
    906899          {
     
    923916          }
    924917
    925         p2 = variable_expand_string(NULL, lb_next, len);
     918        p2 = variable_expand_string(NULL, lb_next, wlen);
    926919
    927920        while (1)
    928921          {
    929             lb_next += len;
     922            lb_next += wlen;
    930923            if (cmdleft == 0)
    931924              {
     
    972965              break;
    973966
    974             wtype = get_next_mword(lb_next, NULL, &lb_next, &len);
     967            wtype = get_next_mword(lb_next, NULL, &lb_next, &wlen);
    975968            if (wtype == w_eol)
    976969              break;
     
    978971            p2 += strlen(p2);
    979972            *(p2++) = ' ';
    980             p2 = variable_expand_string(p2, lb_next, len);
     973            p2 = variable_expand_string(p2, lb_next, wlen);
    981974            /* We don't need to worry about cmdleft here, because if it was
    982975               found in the variable_buffer the entire buffer has already
     
    10331026            unsigned int l = p2 - variable_buffer;
    10341027            plen = strlen (p2);
    1035             (void) variable_buffer_output (p2+plen,
    1036                                            lb_next, strlen (lb_next)+1);
     1028            variable_buffer_output (p2+plen, lb_next, strlen (lb_next)+1);
    10371029            p2 = variable_buffer + l;
    10381030          }
     
    10411033           comes after it looks like a variable definition.  */
    10421034
    1043         wtype = get_next_mword (p2, NULL, &p, &len);
     1035        wtype = get_next_mword (p2, NULL, &p, &wlen);
    10441036
    10451037        v_origin = o_file;
     
    10501042              {
    10511043                v_origin = o_override;
    1052                 wtype = get_next_mword (p+len, NULL, &p, &len);
     1044                wtype = get_next_mword (p+wlen, NULL, &p, &wlen);
    10531045              }
    10541046            else if (word1eq ("export"))
    10551047              {
    10561048                exported = 1;
    1057                 wtype = get_next_mword (p+len, NULL, &p, &len);
     1049                wtype = get_next_mword (p+wlen, NULL, &p, &wlen);
    10581050              }
    10591051          }
    10601052
    10611053        if (wtype != w_eol)
    1062           wtype = get_next_mword (p+len, NULL, NULL, NULL);
     1054          wtype = get_next_mword (p+wlen, NULL, NULL, NULL);
    10631055
    10641056        if (wtype == w_varassign)
     
    11351127        {
    11361128          int check_again;
    1137 
    11381129          do {
    11391130            check_again = 0;
     
    11571148            else if (target->next != 0)
    11581149              fatal (fstart, _("multiple target patterns"));
     1150            pattern_percent = find_percent_cached (&target->name);
    11591151            pattern = target->name;
    1160             pattern_percent = find_percent (pattern);
    11611152            if (pattern_percent == 0)
    11621153              fatal (fstart, _("target pattern contains no `%%'"));
    1163             free ((char *)target);
     1154            free (target);
    11641155          }
    11651156        else
     
    11751166            /* Put all the prerequisites here; they'll be parsed later.  */
    11761167            deps = alloc_dep ();
    1177             deps->name = savestring (beg, end - beg + 1);
     1168            deps->name = strcache_add_len (beg, end - beg + 1);
    11781169          }
    11791170        else
     
    11841175          {
    11851176            /* Semicolon means rest of line is a command.  */
    1186             unsigned int len = strlen (cmdleft);
     1177            unsigned int l = strlen (cmdleft);
    11871178
    11881179            cmds_started = fstart->lineno;
    11891180
    11901181            /* Add this command line to the buffer.  */
    1191             if (len + 2 > commands_len)
     1182            if (l + 2 > commands_len)
    11921183              {
    1193                 commands_len = (len + 2) * 2;
    1194                 commands = (char *) xrealloc (commands, commands_len);
     1184                commands_len = (l + 2) * 2;
     1185                commands = xrealloc (commands, commands_len);
    11951186              }
    1196             bcopy (cmdleft, commands, len);
    1197             commands_idx += len;
     1187            memcpy (commands, cmdleft, l);
     1188            commands_idx += l;
    11981189            commands[commands_idx++] = '\n';
    11991190          }
     
    12171208        if (**default_goal_name == '\0' && set_default)
    12181209          {
    1219             char* name;
     1210            const char *name;
    12201211            struct dep *d;
    12211212            struct nameseq *t = filenames;
     
    12521243                    for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next)
    12531244                      {
    1254                         register unsigned int len = strlen (dep_name (d2));
    1255                         if (!strneq (name, dep_name (d2), len))
     1245                        unsigned int l = strlen (dep_name (d2));
     1246                        if (!strneq (name, dep_name (d2), l))
    12561247                          continue;
    1257                         if (streq (name + len, dep_name (d)))
     1248                        if (streq (name + l, dep_name (d)))
    12581249                          {
    12591250                            reject = 1;
     
    12941285
    12951286  if (collapsed)
    1296     free ((char *) collapsed);
    1297   free ((char *) commands);
     1287    free (collapsed);
     1288  free (commands);
    12981289
    12991290  return 1;
     
    13291320  int nlevels = 1;
    13301321  unsigned int length = 100;
    1331   char *definition = (char *) xmalloc (length);
     1322  char *definition = xmalloc (length);
    13321323  unsigned int idx = 0;
    13331324  char *p;
    13341325
    13351326  /* Expand the variable name.  */
    1336   char *var = (char *) alloca (namelen + 1);
    1337   bcopy (name, var, namelen);
     1327  char *var = alloca (namelen + 1);
     1328  memcpy (var, name, namelen);
    13381329  var[namelen] = '\0';
    13391330  var = variable_expand (var);
     
    13611352
    13621353      /* Stop if we find an 'endef' */
    1363       if (line[0] != '\t')
     1354      if (line[0] != cmd_prefix)
    13641355        {
    13651356          p = next_token (line);
     
    14041395        {
    14051396          length = (idx + len) * 2;
    1406           definition = (char *) xrealloc (definition, length + 1);
     1397          definition = xrealloc (definition, length + 1);
    14071398        }
    14081399
    1409       bcopy (line, &definition[idx], len);
     1400      memcpy (&definition[idx], line, len);
    14101401      idx += len;
    14111402      /* Separate lines with a newline.  */
     
    15351526    {
    15361527      conditionals->allocated = 5;
    1537       conditionals->ignoring = (char *) xmalloc (conditionals->allocated);
    1538       conditionals->seen_else = (char *) xmalloc (conditionals->allocated);
     1528      conditionals->ignoring = xmalloc (conditionals->allocated);
     1529      conditionals->seen_else = xmalloc (conditionals->allocated);
    15391530    }
    15401531
     
    15431534    {
    15441535      conditionals->allocated += 5;
    1545       conditionals->ignoring = (char *)
    1546         xrealloc (conditionals->ignoring, conditionals->allocated);
    1547       conditionals->seen_else = (char *)
    1548         xrealloc (conditionals->seen_else, conditionals->allocated);
     1536      conditionals->ignoring = xrealloc (conditionals->ignoring,
     1537                                        conditionals->allocated);
     1538      conditionals->seen_else = xrealloc (conditionals->seen_else,
     1539                                          conditionals->allocated);
    15491540    }
    15501541
     
    15901581  else
    15911582    {
    1592       /* "Ifeq" or "ifneq".  */
     1583      /* "ifeq" or "ifneq".  */
    15931584      char *s1, *s2;
    1594       unsigned int len;
     1585      unsigned int l;
    15951586      char termin = *line == '(' ? ',' : *line;
    15961587
     
    16321623      /* We must allocate a new copy of the expanded string because
    16331624         variable_expand re-uses the same buffer.  */
    1634       len = strlen (s2);
    1635       s1 = (char *) alloca (len + 1);
    1636       bcopy (s2, s1, len + 1);
     1625      l = strlen (s2);
     1626      s1 = alloca (l + 1);
     1627      memcpy (s1, s2, l + 1);
    16371628
    16381629      if (termin != ',')
     
    16471638      if (termin == ')')
    16481639        {
    1649           register int count = 0;
     1640          int count = 0;
    16501641          s2 = next_token (line);
    16511642          for (line = s2; *line != '\0'; ++line)
     
    17821773    {
    17831774      struct variable *v;
    1784       register char *name = filenames->name;
    1785       char *fname;
    1786       char *percent;
     1775      const char *name = filenames->name;
     1776      const char *fname;
     1777      const char *percent;
    17871778      struct pattern_var *p;
    17881779
    17891780      nextf = filenames->next;
    1790       free ((char *) filenames);
     1781      free (filenames);
    17911782
    17921783      /* If it's a pattern target, then add it to the pattern-specific
    17931784         variable list.  */
    1794       percent = find_percent (name);
     1785      percent = find_percent_cached (&name);
    17951786      if (percent)
    17961787        {
     
    18201811          f = lookup_file (name);
    18211812          if (!f)
    1822             f = enter_file (name);
     1813            f = enter_file (strcache_add (name));
    18231814          else if (f->double_colon)
    18241815            f = f->double_colon;
     
    18571848            }
    18581849        }
    1859 
    1860       /* Free name if not needed further.  */
    1861       if (name != fname && (name < fname || name > fname + strlen (fname)))
    1862         free (name);
    18631850    }
    18641851}
     
    18771864
    18781865static void
    1879 record_files (struct nameseq *filenames, char *pattern, char *pattern_percent,
    1880               struct dep *deps, unsigned int cmds_started, char *commands,
     1866record_files (struct nameseq *filenames, const char *pattern,
     1867              const char *pattern_percent, struct dep *deps,
     1868              unsigned int cmds_started, char *commands,
    18811869              unsigned int commands_idx, int two_colon,
    18821870              const struct floc *flocp)
     
    18851873  int implicit = 0;
    18861874  unsigned int max_targets = 0, target_idx = 0;
    1887   char **targets = 0, **target_percents = 0;
     1875  const char **targets = 0, **target_percents = 0;
    18881876  struct commands *cmds;
    18891877
     
    18971885  if (commands_idx > 0)
    18981886    {
    1899       cmds = (struct commands *) xmalloc (sizeof (struct commands));
     1887      cmds = xmalloc (sizeof (struct commands));
    19001888      cmds->fileinfo.filenm = flocp->filenm;
    19011889      cmds->fileinfo.lineno = cmds_started;
     
    19081896  for (; filenames != 0; filenames = nextf)
    19091897    {
    1910       char *name = filenames->name;
     1898      const char *name = filenames->name;
    19111899      struct file *f;
    19121900      struct dep *this = 0;
    1913       char *implicit_percent;
     1901      const char *implicit_percent;
    19141902
    19151903      nextf = filenames->next;
     
    19241912        second_expansion = 1;
    19251913
    1926       implicit_percent = find_percent (name);
     1914      implicit_percent = find_percent_cached (&name);
    19271915      implicit |= implicit_percent != 0;
    19281916
    1929       if (implicit && pattern != 0)
    1930         fatal (flocp, _("mixed implicit and static pattern rules"));
    1931 
    1932       if (implicit && implicit_percent == 0)
    1933         fatal (flocp, _("mixed implicit and normal rules"));
    1934 
    19351917      if (implicit)
    1936         {
     1918        {
     1919          if (pattern != 0)
     1920            fatal (flocp, _("mixed implicit and static pattern rules"));
     1921
     1922          if (implicit_percent == 0)
     1923            fatal (flocp, _("mixed implicit and normal rules"));
     1924
    19371925          if (targets == 0)
    19381926            {
    19391927              max_targets = 5;
    1940               targets = (char **) xmalloc (5 * sizeof (char *));
    1941               target_percents = (char **) xmalloc (5 * sizeof (char *));
     1928              targets = xmalloc (5 * sizeof (char *));
     1929              target_percents = xmalloc (5 * sizeof (char *));
    19421930              target_idx = 0;
    19431931            }
     
    19451933            {
    19461934              max_targets += 5;
    1947               targets = (char **) xrealloc ((char *) targets,
    1948                                             max_targets * sizeof (char *));
    1949               target_percents
    1950                 = (char **) xrealloc ((char *) target_percents,
    1951                                       max_targets * sizeof (char *));
     1935              targets = xrealloc (targets, max_targets * sizeof (char *));
     1936              target_percents = xrealloc (target_percents,
     1937                                          max_targets * sizeof (char *));
    19521938            }
    19531939          targets[target_idx] = name;
     
    19761962          /* Single-colon.  Combine these dependencies
    19771963             with others in file's existing record, if any.  */
    1978           f = enter_file (name);
     1964          f = enter_file (strcache_add (name));
    19791965
    19801966          if (f->double_colon)
     
    20822068            fatal (flocp,
    20832069                   _("target file `%s' has both : and :: entries"), f->name);
    2084           f = enter_file (name);
     2070          f = enter_file (strcache_add (name));
    20852071          /* If there was an existing entry and it was a double-colon entry,
    20862072             enter_file will have returned a new one, making it the prev
     
    21012087      if (pattern)
    21022088        {
    2103           static char *percent = "%";
     2089          static const char *percent = "%";
    21042090          char *buffer = variable_expand ("");
    2105           char *o = patsubst_expand (buffer, name, pattern, percent,
    2106                                      pattern_percent+1, percent+1);
    2107           f->stem = savestring (buffer, o - buffer);
     2091          char *o = patsubst_expand_pat (buffer, name, pattern, percent,
     2092                                         pattern_percent+1, percent+1);
     2093          f->stem = strcache_add_len (buffer, o - buffer);
    21082094          if (this)
    21092095            {
    21102096              this->staticpattern = 1;
    2111               this->stem = xstrdup (f->stem);
     2097              this->stem = f->stem;
    21122098            }
    21132099        }
    21142100
    2115       /* Free name if not needed further.  */
    2116       if (f != 0 && name != f->name
    2117           && (name < f->name || name > f->name + strlen (f->name)))
    2118         {
    2119           free (name);
    2120           name = f->name;
    2121         }
     2101      name = f->name;
    21222102
    21232103      /* If this target is a default target, update DEFAULT_GOAL_FILE.  */
     
    21302110  if (implicit)
    21312111    {
    2132       targets[target_idx] = 0;
    2133       target_percents[target_idx] = 0;
    21342112      if (deps)
    21352113        deps->need_2nd_expansion = second_expansion;
    2136       create_pattern_rule (targets, target_percents, two_colon, deps, cmds, 1);
    2137       free ((char *) target_percents);
     2114      create_pattern_rule (targets, target_percents, target_idx,
     2115                           two_colon, deps, cmds, 1);
    21382116    }
    21392117}
     
    21542132{
    21552133  unsigned int string_len = 0;
    2156   register char *p = string;
     2134  char *p = string;
    21572135
    21582136  if (ignorevars)
     
    22132191        {
    22142192          /* Search for more backslashes.  */
    2215           register int i = -2;
     2193          int i = -2;
    22162194          while (&p[i] >= string && p[i] == '\\')
    22172195            --i;
     
    22222200          /* The number of backslashes is now -I.
    22232201             Copy P over itself to swallow half of them.  */
    2224           bcopy (&p[i / 2], &p[i], (string_len - (p - string)) - (i / 2) + 1);
    2225           p += i / 2;
     2202          memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1);
     2203          p += i/2;
    22262204          if (i % 2 == 0)
    22272205            /* All the backslashes quoted each other; the STOPCHAR was
     
    22402218}
    22412219
    2242 /* Search PATTERN for an unquoted %.  */
     2220/* Search PATTERN for an unquoted % and handle quoting.  */
    22432221
    22442222char *
     
    22462224{
    22472225  return find_char_unquote (pattern, '%', 0, 0, 0);
     2226}
     2227
     2228/* Search STRING for an unquoted % and handle quoting.  Returns a pointer to
     2229   the % or NULL if no % was found.
     2230   This version is used with strings in the string cache: if there's a need to
     2231   modify the string a new version will be added to the string cache and
     2232   *STRING will be set to that.  */
     2233
     2234const char *
     2235find_percent_cached (const char **string)
     2236{
     2237  const char *p = *string;
     2238  char *new = 0;
     2239  int slen;
     2240
     2241  /* If the first char is a % return now.  This lets us avoid extra tests
     2242     inside the loop.  */
     2243  if (*p == '%')
     2244    return p;
     2245
     2246  while (1)
     2247    {
     2248      while (*p != '\0' && *p != '%')
     2249        ++p;
     2250
     2251      if (*p == '\0')
     2252        break;
     2253
     2254      /* See if this % is escaped with a backslash; if not we're done.  */
     2255      if (p[-1] != '\\')
     2256        break;
     2257
     2258      {
     2259        /* Search for more backslashes.  */
     2260        char *pv;
     2261        int i = -2;
     2262
     2263        while (&p[i] >= *string && p[i] == '\\')
     2264          --i;
     2265        ++i;
     2266
     2267        /* At this point we know we'll need to allocate a new string.
     2268           Make a copy if we haven't yet done so.  */
     2269        if (! new)
     2270          {
     2271            slen = strlen (*string);
     2272            new = alloca (slen + 1);
     2273            memcpy (new, *string, slen + 1);
     2274            p = new + (p - *string);
     2275            *string = new;
     2276          }
     2277
     2278        /* At this point *string, p, and new all point into the same string.
     2279           Get a non-const version of p so we can modify new.  */
     2280        pv = new + (p - *string);
     2281
     2282        /* The number of backslashes is now -I.
     2283           Copy P over itself to swallow half of them.  */
     2284        memmove (&pv[i], &pv[i/2], (slen - (pv - new)) - (i/2) + 1);
     2285        p += i/2;
     2286
     2287        /* If the backslashes quoted each other; the % was unquoted.  */
     2288        if (i % 2 == 0)
     2289          break;
     2290      }
     2291    }
     2292
     2293  /* If we had to change STRING, add it to the strcache.  */
     2294  if (new)
     2295    {
     2296      *string = strcache_add (*string);
     2297      p = *string + (p - new);
     2298    }
     2299
     2300  /* If we didn't find a %, return NULL.  Otherwise return a ptr to it.  */
     2301  return (*p == '\0') ? NULL : p;
    22482302}
    22492303
     
    22682322  struct nameseq *new1, *lastnew1;
    22692323  char *p = *stringp;
    2270   char *q;
    2271   char *name;
    22722324
    22732325#ifdef VMS
     
    22792331  while (1)
    22802332    {
     2333      const char *name;
     2334      char *q;
     2335
    22812336      /* Skip whitespace; see if any more names are left.  */
    22822337      p = next_token (p);
     
    22862341        break;
    22872342
    2288       /* Yes, find end of next name.  */
     2343      /* There are, so find the end of the next name.  */
    22892344      q = p;
    22902345      p = find_char_unquote (q, stopchar, VMS_COMMA, 1, 0);
     
    22982353          && !(isspace ((unsigned char)p[1]) || !p[1]
    22992354               || isspace ((unsigned char)p[-1])))
    2300       {
    23012355        p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0);
    2302       }
    23032356#endif
    23042357#ifdef HAVE_DOS_PATHS
     
    23342387      if (q == p)
    23352388        /* ".///" was stripped to "". */
    2336 #ifdef VMS
     2389#if defined(VMS)
    23372390        continue;
     2391#elif defined(_AMIGA)
     2392        name = "";
    23382393#else
    2339 #ifdef _AMIGA
    2340         name = savestring ("", 0);
    2341 #else
    2342         name = savestring ("./", 2);
    2343 #endif
     2394        name = "./";
    23442395#endif
    23452396      else
     
    23652416              *q2++ = *q1++;
    23662417            }
    2367           name = savestring (qbase, p1 - qbase);
     2418          name = strcache_add_len (qbase, p1 - qbase);
    23682419          free (qbase);
    23692420        }
    23702421#else
    2371         name = savestring (q, p - q);
     2422        name = strcache_add_len (q, p - q);
    23722423#endif
    23732424
    23742425      /* Add it to the front of the chain.  */
    2375       new1 = (struct nameseq *) xmalloc (size);
     2426      new1 = xmalloc (size);
    23762427      new1->name = name;
    23772428      new1->next = new;
     
    24162467            /* Copy "lib(" into LIBNAME.  */
    24172468            ++paren;
    2418             libname = (char *) alloca (paren - n->name + 1);
    2419             bcopy (n->name, libname, paren - n->name);
     2469            libname = alloca (paren - n->name + 1);
     2470            memcpy (libname, n->name, paren - n->name);
    24202471            libname[paren - n->name] = '\0';
    24212472
     
    24252476                   Edit it out of the chain and free its storage.  */
    24262477                lastn->next = n->next;
    2427                 free (n->name);
    2428                 free ((char *) n);
     2478                free (n);
    24292479                /* LASTN->next is the new stopping elt for the loop below.  */
    24302480                n = lastn->next;
     
    24332483              {
    24342484                /* Replace N's name with the full archive reference.  */
    2435                 name = concat (libname, paren, ")");
    2436                 free (n->name);
    2437                 n->name = name;
     2485                n->name = strcache_add (concat (libname, paren, ")"));
    24382486              }
    24392487
     
    24482496                lastn = new1;
    24492497                new1 = new1->next;
    2450                 free (lastn->name);
    2451                 free ((char *) lastn);
     2498                free (lastn);
    24522499              }
    24532500            else
    24542501              {
    24552502                /* Replace also NEW1->name, which already has closing `)'.  */
    2456                 name = concat (libname, new1->name, "");
    2457                 free (new1->name);
    2458                 new1->name = name;
     2503                new1->name = strcache_add (concat (libname, new1->name, ""));
    24592504                new1 = new1->next;
    24602505              }
     
    24662511            while (new1 != n)
    24672512              {
    2468                 name = concat (libname, new1->name, ")");
    2469                 free (new1->name);
    2470                 new1->name = name;
     2513                new1->name = strcache_add (concat (libname, new1->name, ")"));
    24712514                lastnew1 = new1;
    24722515                new1 = new1->next;
     
    26362679        unsigned long off = p - start;
    26372680        ebuf->size *= 2;
    2638         start = ebuf->buffer = ebuf->bufstart = (char *) xrealloc (start,
    2639                                                                    ebuf->size);
     2681        start = ebuf->buffer = ebuf->bufstart = xrealloc (start, ebuf->size);
    26402682        p = start + off;
    26412683        end = start + ebuf->size;
     
    28402882
    28412883void
    2842 construct_include_path (char **arg_dirs)
     2884construct_include_path (const char **arg_dirs)
    28432885{
    2844   register unsigned int i;
    28452886#ifdef VAXC             /* just don't ask ... */
    28462887  stat_t stbuf;
     
    28482889  struct stat stbuf;
    28492890#endif
    2850   /* Table to hold the dirs.  */
    2851 
    2852   register unsigned int defsize = (sizeof (default_include_directories)
    2853                                    / sizeof (default_include_directories[0]));
    2854   register unsigned int max = 5;
    2855   register char **dirs = (char **) xmalloc ((5 + defsize) * sizeof (char *));
    2856   register unsigned int idx = 0;
     2891  const char **dirs;
     2892  const char **cpp;
     2893  unsigned int idx;
     2894
     2895  /* Compute the number of pointers we need in the table.  */
     2896  idx = sizeof (default_include_directories) / sizeof (const char *);
     2897  if (arg_dirs)
     2898    for (cpp = arg_dirs; *cpp != 0; ++cpp)
     2899      ++idx;
    28572900
    28582901#ifdef  __MSDOS__
    2859   defsize++;
     2902  /* Add one for $DJDIR.  */
     2903  ++idx;
    28602904#endif
    28612905
     2906  dirs = xmalloc (idx * sizeof (const char *));
     2907
     2908  idx = 0;
     2909  max_incl_len = 0;
     2910
    28622911  /* First consider any dirs specified with -I switches.
    2863      Ignore dirs that don't exist.  */
    2864 
    2865   if (arg_dirs != 0)
     2912     Ignore any that don't exist.  Remember the maximum string length.  */
     2913
     2914  if (arg_dirs)
    28662915    while (*arg_dirs != 0)
    28672916      {
    2868         char *dir = *arg_dirs++;
     2917        const char *dir = *(arg_dirs++);
     2918        char *expanded = 0;
    28692919        int e;
    28702920
    28712921        if (dir[0] == '~')
    28722922          {
    2873             char *expanded = tilde_expand (dir);
     2923            expanded = tilde_expand (dir);
    28742924            if (expanded != 0)
    28752925              dir = expanded;
     
    28782928        EINTRLOOP (e, stat (dir, &stbuf));
    28792929        if (e == 0 && S_ISDIR (stbuf.st_mode))
    2880           {
    2881             if (idx == max - 1)
    2882               {
    2883                 max += 5;
    2884                 dirs = (char **)
    2885                   xrealloc ((char *) dirs, (max + defsize) * sizeof (char *));
    2886               }
    2887             dirs[idx++] = dir;
    2888           }
    2889         else if (dir != arg_dirs[-1])
    2890           free (dir);
     2930          {
     2931            unsigned int len = strlen (dir);
     2932            /* If dir name is written with trailing slashes, discard them.  */
     2933            while (len > 1 && dir[len - 1] == '/')
     2934              --len;
     2935            if (len > max_incl_len)
     2936              max_incl_len = len;
     2937            dirs[idx++] = strcache_add_len (dir, len);
     2938          }
     2939
     2940        if (expanded)
     2941          free (expanded);
    28912942      }
    28922943
    2893   /* Now add at the end the standard default dirs.  */
     2944  /* Now add the standard default dirs at the end.  */
    28942945
    28952946#ifdef  __MSDOS__
    28962947  {
    2897     /* The environment variable $DJDIR holds the root of the
    2898        DJGPP directory tree; add ${DJDIR}/include.  */
     2948    /* The environment variable $DJDIR holds the root of the DJGPP directory
     2949       tree; add ${DJDIR}/include.  */
    28992950    struct variable *djdir = lookup_variable ("DJDIR", 5);
    29002951
    29012952    if (djdir)
    29022953      {
    2903         char *defdir = (char *) xmalloc (strlen (djdir->value) + 8 + 1);
     2954        unsigned int len = strlen (djdir->value) + 8;
     2955        char *defdir = alloca (len + 1);
    29042956
    29052957        strcat (strcpy (defdir, djdir->value), "/include");
    2906         dirs[idx++] = defdir;
     2958        dirs[idx++] = strcache_add (defdir);
     2959
     2960        if (len > max_incl_len)
     2961          max_incl_len = len;
    29072962      }
    29082963  }
    29092964#endif
    29102965
    2911   for (i = 0; default_include_directories[i] != 0; ++i)
     2966  for (cpp = default_include_directories; *cpp != 0; ++cpp)
    29122967    {
    29132968      int e;
    29142969
    2915       EINTRLOOP (e, stat (default_include_directories[i], &stbuf));
     2970      EINTRLOOP (e, stat (*cpp, &stbuf));
    29162971      if (e == 0 && S_ISDIR (stbuf.st_mode))
    2917         dirs[idx++] = default_include_directories[i];
     2972        {
     2973          unsigned int len = strlen (*cpp);
     2974          /* If dir name is written with trailing slashes, discard them.  */
     2975          while (len > 1 && (*cpp)[len - 1] == '/')
     2976            --len;
     2977          if (len > max_incl_len)
     2978            max_incl_len = len;
     2979          dirs[idx++] = strcache_add_len (*cpp, len - 1);
     2980        }
    29182981    }
    29192982
    29202983  dirs[idx] = 0;
    29212984
    2922   /* Now compute the maximum length of any name in it. Also add each
    2923      dir to the .INCLUDE_DIRS variable.  */
    2924 
    2925   max_incl_len = 0;
    2926   for (i = 0; i < idx; ++i)
    2927     {
    2928       unsigned int len = strlen (dirs[i]);
    2929       /* If dir name is written with a trailing slash, discard it.  */
    2930       if (dirs[i][len - 1] == '/')
    2931         /* We can't just clobber a null in because it may have come from
    2932            a literal string and literal strings may not be writable.  */
    2933         dirs[i] = savestring (dirs[i], len - 1);
    2934       if (len > max_incl_len)
    2935         max_incl_len = len;
    2936 
    2937       /* Append to .INCLUDE_DIRS.   */
    2938       do_variable_definition (NILF, ".INCLUDE_DIRS", dirs[i],
    2939                               o_default, f_append, 0);
    2940     }
     2985  /* Now add each dir to the .INCLUDE_DIRS variable.  */
     2986
     2987  for (cpp = dirs; *cpp != 0; ++cpp)
     2988    do_variable_definition (NILF, ".INCLUDE_DIRS", *cpp,
     2989                            o_default, f_append, 0);
    29412990
    29422991  include_directories = dirs;
     
    29482997
    29492998char *
    2950 tilde_expand (char *name)
     2999tilde_expand (const char *name)
    29513000{
    29523001#ifndef VMS
     
    29733022          home_dir = getenv ("HOME");
    29743023        }
    2975 #if !defined(_AMIGA) && !defined(WINDOWS32)
     3024# if !defined(_AMIGA) && !defined(WINDOWS32)
    29763025      if (home_dir == 0 || home_dir[0] == '\0')
    29773026        {
     
    29863035            }
    29873036        }
    2988 #endif /* !AMIGA && !WINDOWS32 */
     3037# endif /* !AMIGA && !WINDOWS32 */
    29893038      if (home_dir != 0)
    29903039        {
    2991           char *new = concat (home_dir, "", name + 1);
     3040          char *new = xstrdup (concat (home_dir, "", name + 1));
    29923041          if (is_variable)
    29933042            free (home_dir);
     
    29953044        }
    29963045    }
    2997 #if !defined(_AMIGA) && !defined(WINDOWS32)
     3046# if !defined(_AMIGA) && !defined(WINDOWS32)
    29983047  else
    29993048    {
     
    30083057            return xstrdup (pwent->pw_dir);
    30093058          else
    3010             return concat (pwent->pw_dir, "/", userend + 1);
     3059            return xstrdup (concat (pwent->pw_dir, "/", userend + 1));
    30113060        }
    30123061      else if (userend != 0)
    30133062        *userend = '/';
    30143063    }
    3015 #endif /* !AMIGA && !WINDOWS32 */
     3064# endif /* !AMIGA && !WINDOWS32 */
    30163065#endif /* !VMS */
    30173066  return 0;
     
    30313080multi_glob (struct nameseq *chain, unsigned int size)
    30323081{
    3033   extern void dir_setup_glob ();
    3034   register struct nameseq *new = 0;
    3035   register struct nameseq *old;
     3082  void dir_setup_glob (glob_t *);
     3083  struct nameseq *new = 0;
     3084  struct nameseq *old;
    30363085  struct nameseq *nexto;
    30373086  glob_t gl;
     
    30413090  for (old = chain; old != 0; old = nexto)
    30423091    {
     3092      const char *gname;
    30433093#ifndef NO_ARCHIVES
    3044       char *memname;
     3094      char *arname = 0;
     3095      char *memname = 0;
    30453096#endif
    3046 
    30473097      nexto = old->next;
    3048 
    3049       if (old->name[0] == '~')
     3098      gname = old->name;
     3099
     3100      if (gname[0] == '~')
    30503101        {
    30513102          char *newname = tilde_expand (old->name);
    30523103          if (newname != 0)
    3053             {
    3054               free (old->name);
    3055               old->name = newname;
    3056             }
     3104            gname = newname;
    30573105        }
    30583106
    30593107#ifndef NO_ARCHIVES
    3060       if (ar_name (old->name))
     3108      if (ar_name (gname))
    30613109        {
    3062           /* OLD->name is an archive member reference.
    3063              Replace it with the archive file name,
    3064              and save the member name in MEMNAME.
    3065              We will glob on the archive name and then
    3066              reattach MEMNAME later.  */
    3067           char *arname;
    3068           ar_parse_name (old->name, &arname, &memname);
    3069           free (old->name);
    3070           old->name = arname;
    3071         }
    3072       else
    3073         memname = 0;
     3110          /* OLD->name is an archive member reference.  Replace it with the
     3111             archive file name, and save the member name in MEMNAME.  We will
     3112             glob on the archive name and then reattach MEMNAME later.  */
     3113          ar_parse_name (gname, &arname, &memname);
     3114          gname = arname;
     3115        }
    30743116#endif /* !NO_ARCHIVES */
    30753117
    3076       switch (glob (old->name, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl))
     3118      switch (glob (gname, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl))
    30773119        {
    30783120        case 0:                 /* Success.  */
    30793121          {
    3080             register int i = gl.gl_pathc;
     3122            int i = gl.gl_pathc;
    30813123            while (i-- > 0)
    30823124              {
     
    30873129                    struct nameseq *found
    30883130                      = ar_glob (gl.gl_pathv[i], memname, size);
    3089                     if (found == 0)
     3131                    if (! found)
    30903132                      {
    30913133                        /* No matches.  Use MEMNAME as-is.  */
    30923134                        unsigned int alen = strlen (gl.gl_pathv[i]);
    30933135                        unsigned int mlen = strlen (memname);
    3094                         struct nameseq *elt
    3095                           = (struct nameseq *) xmalloc (size);
    3096                         if (size > sizeof (struct nameseq))
    3097                           bzero (((char *) elt) + sizeof (struct nameseq),
    3098                                  size - sizeof (struct nameseq));
    3099                         elt->name = (char *) xmalloc (alen + 1 + mlen + 2);
    3100                         bcopy (gl.gl_pathv[i], elt->name, alen);
    3101                         elt->name[alen] = '(';
    3102                         bcopy (memname, &elt->name[alen + 1], mlen);
    3103                         elt->name[alen + 1 + mlen] = ')';
    3104                         elt->name[alen + 1 + mlen + 1] = '\0';
     3136                        char *name;
     3137                        struct nameseq *elt = xmalloc (size);
     3138                        memset (elt, '\0', size);
     3139
     3140                        name = alloca (alen + 1 + mlen + 2);
     3141                        memcpy (name, gl.gl_pathv[i], alen);
     3142                        name[alen] = '(';
     3143                        memcpy (name+alen+1, memname, mlen);
     3144                        name[alen + 1 + mlen] = ')';
     3145                        name[alen + 1 + mlen + 1] = '\0';
     3146                        elt->name = strcache_add (name);
    31053147                        elt->next = new;
    31063148                        new = elt;
     
    31183160                        new = found;
    31193161                      }
    3120 
    3121                     free (memname);
    31223162                  }
    31233163                else
    31243164#endif /* !NO_ARCHIVES */
    31253165                  {
    3126                     struct nameseq *elt = (struct nameseq *) xmalloc (size);
    3127                     if (size > sizeof (struct nameseq))
    3128                       bzero (((char *) elt) + sizeof (struct nameseq),
    3129                              size - sizeof (struct nameseq));
    3130                     elt->name = xstrdup (gl.gl_pathv[i]);
     3166                    struct nameseq *elt = xmalloc (size);
     3167                    memset (elt, '\0', size);
     3168                    elt->name = strcache_add (gl.gl_pathv[i]);
    31313169                    elt->next = new;
    31323170                    new = elt;
     
    31343172              }
    31353173            globfree (&gl);
    3136             free (old->name);
    3137             free ((char *)old);
     3174            free (old);
    31383175            break;
    31393176          }
     
    31483185          break;
    31493186        }
     3187
     3188#ifndef NO_ARCHIVES
     3189      if (arname)
     3190        free (arname);
     3191#endif
    31503192    }
    31513193
Note: See TracChangeset for help on using the changeset viewer.